From 76766a7cef8c4400657ec0a6ae9b799899fdd3ee Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Wed, 10 Jul 2019 13:21:29 +0200 Subject: [PATCH 001/239] Setup fresh project --- .Package.test.swift | 9 - .swiftlint.yml | 15 - Cartfile.private | 2 - Cartfile.resolved | 2 - Configurations/Base/Common.xcconfig | 221 --- .../Base/Configurations/Debug.xcconfig | 51 - .../Base/Configurations/Profile.xcconfig | 27 - .../Base/Configurations/Release.xcconfig | 34 - .../Base/Configurations/Test.xcconfig | 13 - .../Base/Targets/Application.xcconfig | 12 - .../Base/Targets/Framework.xcconfig | 37 - .../Base/Targets/StaticLibrary.xcconfig | 32 - .../Mac OS X/Mac-Application.xcconfig | 15 - Configurations/Mac OS X/Mac-Base.xcconfig | 19 - .../Mac OS X/Mac-DynamicLibrary.xcconfig | 18 - .../Mac OS X/Mac-Framework.xcconfig | 11 - .../Mac OS X/Mac-StaticLibrary.xcconfig | 11 - Configurations/iOS/iOS-Application.xcconfig | 11 - Configurations/iOS/iOS-Base.xcconfig | 18 - Configurations/iOS/iOS-Framework.xcconfig | 11 - Configurations/iOS/iOS-StaticLibrary.xcconfig | 11 - Configurations/tvOS/tvOS-Application.xcconfig | 11 - Configurations/tvOS/tvOS-Base.xcconfig | 15 - Configurations/tvOS/tvOS-Framework.xcconfig | 11 - .../tvOS/tvOS-StaticLibrary.xcconfig | 11 - .../watchOS/watchOS-Application.xcconfig | 11 - Configurations/watchOS/watchOS-Base.xcconfig | 15 - .../watchOS/watchOS-Framework.xcconfig | 11 - .../watchOS/watchOS-StaticLibrary.xcconfig | 11 - Gemfile | 5 - Gemfile.lock | 76 - Sample-iOS.playground/Contents.swift | 392 ----- Sample-iOS.playground/contents.xcplayground | 4 - Sources/Assembler.swift | 129 -- Sources/Assembly.swift | 32 - Sources/Behavior.swift | 27 - Sources/Container.Arguments.erb | 93 - Sources/Container.Arguments.swift | 512 ------ Sources/Container.Logging.swift | 24 - Sources/Container.TypeForwarding.swift | 35 - Sources/Container.swift | 334 ---- Sources/DebugHelper.swift | 55 - Sources/FunctionType.swift | 10 - Sources/GraphIdentifier.swift | 20 - Sources/Info.plist | 12 +- Sources/InstanceStorage.swift | 133 -- Sources/InstanceWrapper.swift | 81 - Sources/ObjectScope.Standard.swift | 26 - Sources/ObjectScope.swift | 48 - Sources/Resolver.erb | 69 - Sources/Resolver.swift | 270 --- Sources/ServiceEntry.TypeForwarding.erb | 47 - Sources/ServiceEntry.TypeForwarding.swift | 111 -- Sources/ServiceEntry.swift | 105 -- Sources/ServiceKey.swift | 61 - Sources/SpinLock.swift | 19 - Sources/Swinject.h | 6 +- Sources/SynchronizedResolver.Arguments.erb | 46 - Sources/SynchronizedResolver.Arguments.swift | 191 --- Sources/SynchronizedResolver.swift | 42 - Sources/UnavailableItems.swift | 25 - Sources/_Resolver.swift | 28 - Swinject.xcodeproj/project.pbxproj | 1495 +++-------------- .../xcshareddata/swiftpm/Package.resolved | 25 + .../xcschemes/Swinject-OSX.xcscheme | 39 +- .../xcschemes/Swinject-iOS.xcscheme | 100 -- .../xcschemes/Swinject-tvOS.xcscheme | 99 -- .../xcschemes/Swinject-watchOS.xcscheme | 80 - Tests/{SwinjectTests => }/Info.plist | 8 +- Tests/LinuxMain.swift | 24 - Tests/SwinjectTests.swift | 34 + Tests/SwinjectTests/Animal.swift | 49 - Tests/SwinjectTests/AssemblerSpec.swift | 336 ---- Tests/SwinjectTests/BasicAssembly.swift | 47 - Tests/SwinjectTests/BehaviorFakes.swift | 26 - Tests/SwinjectTests/Circularity.swift | 77 - .../ContainerSpec.Arguments.swift | 103 -- .../ContainerSpec.Behavior.swift | 98 -- .../ContainerSpec.Circularity.swift | 138 -- .../ContainerSpec.CustomScope.swift | 92 - ...ontainerSpec.CustomStringConvertible.swift | 78 - .../ContainerSpec.DebugHelper.swift | 74 - .../ContainerSpec.GraphCaching.swift | 132 -- .../ContainerSpec.TypeForwarding.swift | 168 -- Tests/SwinjectTests/ContainerSpec.swift | 382 ----- Tests/SwinjectTests/EmploymentAssembly.swift | 84 - Tests/SwinjectTests/Food.swift | 13 - Tests/SwinjectTests/LazySpec.swift | 112 -- Tests/SwinjectTests/LoadAwareAssembly.swift | 29 - Tests/SwinjectTests/Person.swift | 27 - Tests/SwinjectTests/ProviderSpec.swift | 117 -- Tests/SwinjectTests/ServiceEntrySpec.swift | 30 - Tests/SwinjectTests/ServiceKeySpec.swift | 149 -- .../SynchronizedResolverSpec.swift | 145 -- Tests/SwinjectTests/WeakStorageSpec.swift | 60 - script/gencode | 8 - 96 files changed, 345 insertions(+), 7877 deletions(-) delete mode 100644 .Package.test.swift delete mode 100644 Cartfile.private delete mode 100644 Cartfile.resolved delete mode 100755 Configurations/Base/Common.xcconfig delete mode 100755 Configurations/Base/Configurations/Debug.xcconfig delete mode 100755 Configurations/Base/Configurations/Profile.xcconfig delete mode 100755 Configurations/Base/Configurations/Release.xcconfig delete mode 100755 Configurations/Base/Configurations/Test.xcconfig delete mode 100755 Configurations/Base/Targets/Application.xcconfig delete mode 100755 Configurations/Base/Targets/Framework.xcconfig delete mode 100755 Configurations/Base/Targets/StaticLibrary.xcconfig delete mode 100755 Configurations/Mac OS X/Mac-Application.xcconfig delete mode 100755 Configurations/Mac OS X/Mac-Base.xcconfig delete mode 100755 Configurations/Mac OS X/Mac-DynamicLibrary.xcconfig delete mode 100755 Configurations/Mac OS X/Mac-Framework.xcconfig delete mode 100755 Configurations/Mac OS X/Mac-StaticLibrary.xcconfig delete mode 100755 Configurations/iOS/iOS-Application.xcconfig delete mode 100755 Configurations/iOS/iOS-Base.xcconfig delete mode 100755 Configurations/iOS/iOS-Framework.xcconfig delete mode 100755 Configurations/iOS/iOS-StaticLibrary.xcconfig delete mode 100755 Configurations/tvOS/tvOS-Application.xcconfig delete mode 100755 Configurations/tvOS/tvOS-Base.xcconfig delete mode 100755 Configurations/tvOS/tvOS-Framework.xcconfig delete mode 100755 Configurations/tvOS/tvOS-StaticLibrary.xcconfig delete mode 100755 Configurations/watchOS/watchOS-Application.xcconfig delete mode 100755 Configurations/watchOS/watchOS-Base.xcconfig delete mode 100755 Configurations/watchOS/watchOS-Framework.xcconfig delete mode 100755 Configurations/watchOS/watchOS-StaticLibrary.xcconfig delete mode 100644 Gemfile delete mode 100644 Gemfile.lock delete mode 100644 Sample-iOS.playground/Contents.swift delete mode 100644 Sample-iOS.playground/contents.xcplayground delete mode 100644 Sources/Assembler.swift delete mode 100644 Sources/Assembly.swift delete mode 100644 Sources/Behavior.swift delete mode 100644 Sources/Container.Arguments.erb delete mode 100644 Sources/Container.Arguments.swift delete mode 100644 Sources/Container.Logging.swift delete mode 100644 Sources/Container.TypeForwarding.swift delete mode 100644 Sources/Container.swift delete mode 100644 Sources/DebugHelper.swift delete mode 100644 Sources/FunctionType.swift delete mode 100644 Sources/GraphIdentifier.swift delete mode 100644 Sources/InstanceStorage.swift delete mode 100644 Sources/InstanceWrapper.swift delete mode 100644 Sources/ObjectScope.Standard.swift delete mode 100644 Sources/ObjectScope.swift delete mode 100644 Sources/Resolver.erb delete mode 100644 Sources/Resolver.swift delete mode 100644 Sources/ServiceEntry.TypeForwarding.erb delete mode 100644 Sources/ServiceEntry.TypeForwarding.swift delete mode 100644 Sources/ServiceEntry.swift delete mode 100644 Sources/ServiceKey.swift delete mode 100644 Sources/SpinLock.swift delete mode 100644 Sources/SynchronizedResolver.Arguments.erb delete mode 100644 Sources/SynchronizedResolver.Arguments.swift delete mode 100644 Sources/SynchronizedResolver.swift delete mode 100644 Sources/UnavailableItems.swift delete mode 100644 Sources/_Resolver.swift create mode 100644 Swinject.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved delete mode 100644 Swinject.xcodeproj/xcshareddata/xcschemes/Swinject-iOS.xcscheme delete mode 100644 Swinject.xcodeproj/xcshareddata/xcschemes/Swinject-tvOS.xcscheme delete mode 100644 Swinject.xcodeproj/xcshareddata/xcschemes/Swinject-watchOS.xcscheme rename Tests/{SwinjectTests => }/Info.plist (83%) delete mode 100755 Tests/LinuxMain.swift create mode 100644 Tests/SwinjectTests.swift delete mode 100644 Tests/SwinjectTests/Animal.swift delete mode 100644 Tests/SwinjectTests/AssemblerSpec.swift delete mode 100644 Tests/SwinjectTests/BasicAssembly.swift delete mode 100644 Tests/SwinjectTests/BehaviorFakes.swift delete mode 100644 Tests/SwinjectTests/Circularity.swift delete mode 100644 Tests/SwinjectTests/ContainerSpec.Arguments.swift delete mode 100644 Tests/SwinjectTests/ContainerSpec.Behavior.swift delete mode 100644 Tests/SwinjectTests/ContainerSpec.Circularity.swift delete mode 100644 Tests/SwinjectTests/ContainerSpec.CustomScope.swift delete mode 100644 Tests/SwinjectTests/ContainerSpec.CustomStringConvertible.swift delete mode 100644 Tests/SwinjectTests/ContainerSpec.DebugHelper.swift delete mode 100644 Tests/SwinjectTests/ContainerSpec.GraphCaching.swift delete mode 100644 Tests/SwinjectTests/ContainerSpec.TypeForwarding.swift delete mode 100644 Tests/SwinjectTests/ContainerSpec.swift delete mode 100644 Tests/SwinjectTests/EmploymentAssembly.swift delete mode 100644 Tests/SwinjectTests/Food.swift delete mode 100644 Tests/SwinjectTests/LazySpec.swift delete mode 100644 Tests/SwinjectTests/LoadAwareAssembly.swift delete mode 100644 Tests/SwinjectTests/Person.swift delete mode 100644 Tests/SwinjectTests/ProviderSpec.swift delete mode 100644 Tests/SwinjectTests/ServiceEntrySpec.swift delete mode 100644 Tests/SwinjectTests/ServiceKeySpec.swift delete mode 100644 Tests/SwinjectTests/SynchronizedResolverSpec.swift delete mode 100644 Tests/SwinjectTests/WeakStorageSpec.swift delete mode 100755 script/gencode diff --git a/.Package.test.swift b/.Package.test.swift deleted file mode 100644 index e5b2af16..00000000 --- a/.Package.test.swift +++ /dev/null @@ -1,9 +0,0 @@ -import PackageDescription - -let package = Package( - name: "Swinject", - dependencies: [ - .Package(url: "https://github.com/Quick/Quick", majorVersion: 1, minor: 1), - .Package(url: "https://github.com/Quick/Nimble", majorVersion: 7, minor: 0) - ] -) diff --git a/.swiftlint.yml b/.swiftlint.yml index ebc1693d..e69de29b 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -1,15 +0,0 @@ -disabled_rules: - - force_cast - - type_name -excluded: - - Sources/Container.Arguments.swift - - Sources/SynchronizedResolver.Arguments.swift - - Sources/Resolver.swift - - Sources/ServiceEntry.TypeForwarding.swift - - Sample-iOS.playground - - Carthage - - Packages -variable_name: - min_length: - warning: 1 - error: 1 diff --git a/Cartfile.private b/Cartfile.private deleted file mode 100644 index 5791b6e3..00000000 --- a/Cartfile.private +++ /dev/null @@ -1,2 +0,0 @@ -github "Quick/Quick" ~> 2.0 -github "Quick/Nimble" ~> 8.0 diff --git a/Cartfile.resolved b/Cartfile.resolved deleted file mode 100644 index c49eeaca..00000000 --- a/Cartfile.resolved +++ /dev/null @@ -1,2 +0,0 @@ -github "Quick/Nimble" "v8.0.0" -github "Quick/Quick" "v2.0.0" diff --git a/Configurations/Base/Common.xcconfig b/Configurations/Base/Common.xcconfig deleted file mode 100755 index 9ae14eb6..00000000 --- a/Configurations/Base/Common.xcconfig +++ /dev/null @@ -1,221 +0,0 @@ -// -// This file defines common settings that should be enabled for every new -// project. Typically, you want to use Debug, Release, or a similar variant -// instead. -// - -// Disable legacy-compatible header searching -ALWAYS_SEARCH_USER_PATHS = NO - -// Architectures to build -ARCHS = $(ARCHS_STANDARD) - -// Whether to warn when a floating-point value is used as a loop counter -CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES - -// Whether to warn about use of rand() and random() being used instead of arc4random() -CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES - -// Whether to warn about strcpy() and strcat() -CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES - -// Whether to enable module imports -CLANG_ENABLE_MODULES = YES - -// Enable ARC -CLANG_ENABLE_OBJC_ARC = YES - -// Warn about block captures of implicitly autoreleasing parameters. -CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES - -// Warn about implicit conversions to boolean values that are suspicious. -// For example, writing 'if (foo)' with 'foo' being the name a function will trigger a warning. -CLANG_WARN_BOOL_CONVERSION = YES - -// Warn about suspicious uses of the comma operator. -CLANG_WARN_COMMA = YES - -// Warn about implicit conversions of constant values that cause the constant value to change, -// either through a loss of precision, or entirely in its meaning. -CLANG_WARN_CONSTANT_CONVERSION = YES - -// Whether to warn when overriding deprecated methods -CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES - -// Warn about direct accesses to the Objective-C 'isa' pointer instead of using a runtime API. -CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR - -// Warn about declaring the same method more than once within the same @interface. -CLANG_WARN__DUPLICATE_METHOD_MATCH = YES - -// Warn about loop bodies that are suspiciously empty. -CLANG_WARN_EMPTY_BODY = YES - -// Warn about implicit conversions between different kinds of enum values. -// For example, this can catch issues when using the wrong enum flag as an argument to a function or method. -CLANG_WARN_ENUM_CONVERSION = YES - -// Whether to warn on implicit conversions between signed/unsigned types -CLANG_WARN_IMPLICIT_SIGN_CONVERSION = NO - -// Warn about implicit conversions between pointers and integers. -// For example, this can catch issues when one incorrectly intermixes using NSNumbers and raw integers. -CLANG_WARN_INT_CONVERSION = YES - -// Warn about non-literal expressions that evaluate to zero being treated as a null pointer. -CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES - -// Warn about implicit capture of self (e.g. direct ivar access) -CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES - -// Warn about implicit conversions from Objective-C literals to values of incompatible type. -CLANG_WARN_OBJC_LITERAL_CONVERSION = YES - -// Don't warn about repeatedly using a weak reference without assigning the weak reference to a strong reference. Too many false positives. -CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = NO - -// Warn about classes that unintentionally do not subclass a root class (such as NSObject). -CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR - -// Warn about ranged-based for loops. -CLANG_WARN_RANGE_LOOP_ANALYSIS = YES - -// Whether to warn on suspicious implicit conversions -CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES - -// Warn about non-prototype declarations. -CLANG_WARN_STRICT_PROTOTYPES = YES - -// Warn if an API that is newer than the deployment target is used without "if (@available(...))" guards. -CLANG_WARN_UNGUARDED_AVAILABILITY = YES - -// Warn about incorrect uses of nullable values -CLANG_WARN_NULLABLE_TO_NONNULL_CONVERSION = YES - -// Warn for missing nullability attributes -CLANG_ANALYZER_NONNULL = YES - -// Warn when a non-localized string is passed to a user-interface method expecting a localized string -CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES - -// Warn about potentially unreachable code -CLANG_WARN_UNREACHABLE_CODE = YES - -// The format of debugging symbols -DEBUG_INFORMATION_FORMAT = dwarf-with-dsym - -// Whether to compile assertions in -ENABLE_NS_ASSERTIONS = YES - -// Whether to require objc_msgSend to be cast before invocation -ENABLE_STRICT_OBJC_MSGSEND = YES - -// Which C variant to use -GCC_C_LANGUAGE_STANDARD = gnu99 - -// Whether to enable exceptions for Objective-C -GCC_ENABLE_OBJC_EXCEPTIONS = YES - -// Whether to generate debugging symbols -GCC_GENERATE_DEBUGGING_SYMBOLS = YES - -// Whether to precompile the prefix header (if one is specified) -GCC_PRECOMPILE_PREFIX_HEADER = YES - -// Whether to enable strict aliasing, meaning that two pointers of different -// types (other than void * or any id type) cannot point to the same memory -// location -GCC_STRICT_ALIASING = YES - -// Whether symbols not explicitly exported are hidden by default (this primarily -// only affects C++ code) -GCC_SYMBOLS_PRIVATE_EXTERN = NO - -// Whether static variables are thread-safe by default -GCC_THREADSAFE_STATICS = NO - -// Which compiler to use -GCC_VERSION = com.apple.compilers.llvm.clang.1_0 - -// Whether warnings are treated as errors -GCC_TREAT_WARNINGS_AS_ERRORS = YES -SWIFT_TREAT_WARNINGS_AS_ERRORS = YES - -// Whether to warn about 64-bit values being implicitly shortened to 32 bits -GCC_WARN_64_TO_32_BIT_CONVERSION = YES - -// Whether to warn about fields missing from structure initializers (only if -// designated initializers aren't used) -GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES - -// Whether to warn about missing function prototypes -GCC_WARN_ABOUT_MISSING_PROTOTYPES = NO - -// Whether to warn about implicit conversions in the signedness of the type -// a pointer is pointing to (e.g., 'int *' getting converted to 'unsigned int *') -GCC_WARN_ABOUT_POINTER_SIGNEDNESS = YES - -// Whether to warn when the value returned from a function/method/block does not -// match its return type -GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR - -// Whether to warn on a class not implementing all the required methods of -// a protocol it declares conformance to -GCC_WARN_ALLOW_INCOMPLETE_PROTOCOL = YES - -// Whether to warn when switching on an enum value, and all possibilities are -// not accounted for -GCC_WARN_CHECK_SWITCH_STATEMENTS = YES - -// Whether to warn about the use of four-character constants -GCC_WARN_FOUR_CHARACTER_CONSTANTS = YES - -// Whether to warn about an aggregate data type's initializer not being fully -// bracketed (e.g., array initializer syntax) -GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES - -// Whether to warn about missing braces or parentheses that make the meaning of -// the code ambiguous -GCC_WARN_MISSING_PARENTHESES = YES - -// Whether to warn about unsafe comparisons between values of different -// signedness -GCC_WARN_SIGN_COMPARE = YES - -// Whether to warn about the arguments to printf-style functions not matching -// the format specifiers -GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES - -// Warn if a "@selector(...)" expression referring to an undeclared selector is found -GCC_WARN_UNDECLARED_SELECTOR = YES - -// Warn if a variable might be clobbered by a setjmp call or if an automatic variable is used without prior initialization. -GCC_WARN_UNINITIALIZED_AUTOS = YES - -// Whether to warn about static functions that are unused -GCC_WARN_UNUSED_FUNCTION = YES - -// Whether to warn about labels that are unused -GCC_WARN_UNUSED_LABEL = YES - -// Whether to warn about variables that are never used -GCC_WARN_UNUSED_VARIABLE = YES - -// Whether to run the static analyzer with every build -RUN_CLANG_STATIC_ANALYZER = YES - -// Don't treat unknown warnings as errors, and disable GCC compatibility warnings and unused static const variable warnings -WARNING_CFLAGS = -Wno-error=unknown-warning-option -Wno-gcc-compat -Wno-unused-const-variable - -// This setting is on for new projects as of Xcode ~6.3, though it is still not -// the default. It warns if the same variable is declared in two binaries that -// are linked together. -GCC_NO_COMMON_BLOCKS = YES - -// This warnings detects when a function will recursively call itself on every -// code path though that function. More information can be found here: -// http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20131216/096004.html -CLANG_WARN_INFINITE_RECURSION = YES - -// This warning detects suspicious uses of std::move. -CLANG_WARN_SUSPICIOUS_MOVE = YES diff --git a/Configurations/Base/Configurations/Debug.xcconfig b/Configurations/Base/Configurations/Debug.xcconfig deleted file mode 100755 index a5911f6c..00000000 --- a/Configurations/Base/Configurations/Debug.xcconfig +++ /dev/null @@ -1,51 +0,0 @@ -// -// This file defines the base configuration for a Debug build of any project. -// This should be set at the project level for the Debug configuration. -// - -#include "../Common.xcconfig" - -// Whether to strip debugging symbols when copying resources (like included -// binaries) -COPY_PHASE_STRIP = NO - -// The optimization level (0, 1, 2, 3, s) for the produced binary -GCC_OPTIMIZATION_LEVEL = 0 - -// Preproccessor definitions to apply to each file compiled -GCC_PREPROCESSOR_DEFINITIONS = DEBUG=1 - -// Allow @testable imports -ENABLE_TESTABILITY = YES - -// Whether to enable link-time optimizations (such as inlining across translation -// units) -LLVM_LTO = NO - -// Whether to only build the active architecture -ONLY_ACTIVE_ARCH = YES - -// Other compiler flags -// -// These settings catch some errors in integer arithmetic -OTHER_CFLAGS = -ftrapv - -// Other flags to pass to the Swift compiler -// -// This enables conditional compilation with #if DEBUG -OTHER_SWIFT_FLAGS = -D DEBUG - -// Xcode 8 introduced a new flag for conditional compilation -// -// This enables conditional compilation with #if DEBUG -SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG - -// Whether to strip debugging symbols when copying the built product to its -// final installation location -STRIP_INSTALLED_PRODUCT = NO - -// The optimization level (-Onone, -O, -Ofast) for the produced Swift binary -SWIFT_OPTIMIZATION_LEVEL = -Onone - -// Disable Developer ID timestamping -OTHER_CODE_SIGN_FLAGS = --timestamp=none diff --git a/Configurations/Base/Configurations/Profile.xcconfig b/Configurations/Base/Configurations/Profile.xcconfig deleted file mode 100755 index 0d015531..00000000 --- a/Configurations/Base/Configurations/Profile.xcconfig +++ /dev/null @@ -1,27 +0,0 @@ -// -// This file defines the base configuration for an optional profiling-specific -// build of any project. To use these settings, create a Profile configuration -// in your project, and use this file at the project level for the new -// configuration. -// - -// based on the Release configuration, with some stuff related to debugging -// symbols re-enabled -#include "Release.xcconfig" - -// Whether to strip debugging symbols when copying resources (like included -// binaries) -COPY_PHASE_STRIP = NO - -// Whether to only build the active architecture -ONLY_ACTIVE_ARCH = YES - -// Whether to strip debugging symbols when copying the built product to its -// final installation location -STRIP_INSTALLED_PRODUCT = NO - -// Whether to perform App Store validation checks -VALIDATE_PRODUCT = NO - -// Disable Developer ID timestamping -OTHER_CODE_SIGN_FLAGS = --timestamp=none diff --git a/Configurations/Base/Configurations/Release.xcconfig b/Configurations/Base/Configurations/Release.xcconfig deleted file mode 100755 index c83729b8..00000000 --- a/Configurations/Base/Configurations/Release.xcconfig +++ /dev/null @@ -1,34 +0,0 @@ -// -// This file defines the base configuration for a Release build of any project. -// This should be set at the project level for the Release configuration. -// - -#include "../Common.xcconfig" - -// Whether to strip debugging symbols when copying resources (like included -// binaries) -COPY_PHASE_STRIP = YES - -// The optimization level (0, 1, 2, 3, s) for the produced binary -GCC_OPTIMIZATION_LEVEL = s - -// Preproccessor definitions to apply to each file compiled -GCC_PREPROCESSOR_DEFINITIONS = NDEBUG=1 - -// Whether to enable link-time optimizations (such as inlining across translation -// units) -LLVM_LTO = NO - -// Whether to only build the active architecture -ONLY_ACTIVE_ARCH = NO - -// Whether to strip debugging symbols when copying the built product to its -// final installation location -STRIP_INSTALLED_PRODUCT = YES - -// The optimization level (-Onone, -O, -Owholemodule) for the produced Swift binary -SWIFT_OPTIMIZATION_LEVEL = -Owholemodule - -// Whether to perform App Store validation checks -VALIDATE_PRODUCT = YES - diff --git a/Configurations/Base/Configurations/Test.xcconfig b/Configurations/Base/Configurations/Test.xcconfig deleted file mode 100755 index bf17949a..00000000 --- a/Configurations/Base/Configurations/Test.xcconfig +++ /dev/null @@ -1,13 +0,0 @@ -// -// This file defines the base configuration for a Test build of any project. -// This should be set at the project level for the Test configuration. -// - -#include "Debug.xcconfig" - -// Sandboxed apps can't be unit tested since they can't load some random -// external bundle. So we disable sandboxing for testing. -CODE_SIGN_ENTITLEMENTS = - -// Allow @testable imports -ENABLE_TESTABILITY = YES diff --git a/Configurations/Base/Targets/Application.xcconfig b/Configurations/Base/Targets/Application.xcconfig deleted file mode 100755 index a91feca6..00000000 --- a/Configurations/Base/Targets/Application.xcconfig +++ /dev/null @@ -1,12 +0,0 @@ -// -// This file defines additional configuration options that are appropriate only -// for an application. Typically, you want to use a platform-specific variant -// instead. -// - -// Whether to strip out code that isn't called from anywhere -DEAD_CODE_STRIPPING = NO - -// Sets the @rpath for the application such that it can include frameworks in -// the application bundle (inside the "Frameworks" folder) -LD_RUNPATH_SEARCH_PATHS = @executable_path/../Frameworks @loader_path/../Frameworks @executable_path/Frameworks diff --git a/Configurations/Base/Targets/Framework.xcconfig b/Configurations/Base/Targets/Framework.xcconfig deleted file mode 100755 index c92f57fe..00000000 --- a/Configurations/Base/Targets/Framework.xcconfig +++ /dev/null @@ -1,37 +0,0 @@ -// -// This file defines additional configuration options that are appropriate only -// for a framework. Typically, you want to use a platform-specific variant -// instead. -// - -// Disable code signing for successful device builds with Xcode 8. Frameworks do -// need to be signed, but they don't need to be signed at compile time because -// they'll be re-signed when you include them in your app. -CODE_SIGNING_REQUIRED = NO -CODE_SIGN_IDENTITY = - -// Whether to strip out code that isn't called from anywhere -DEAD_CODE_STRIPPING = NO - -// Whether this framework should define an LLVM module -DEFINES_MODULE = YES - -// Whether function calls should be position-dependent (should always be -// disabled for library code) -GCC_DYNAMIC_NO_PIC = NO - -// Default frameworks to the name of the project, instead of any -// platform-specific target -PRODUCT_NAME = $(PROJECT_NAME) - -// Enables the framework to be included from any location as long as the -// loader’s runpath search paths includes it. For example from an application -// bundle (inside the "Frameworks" folder) or shared folder -INSTALL_PATH = @rpath -LD_DYLIB_INSTALL_NAME = @rpath/$(PRODUCT_NAME).$(WRAPPER_EXTENSION)/$(PRODUCT_NAME) -SKIP_INSTALL = YES - -// Disallows use of APIs that are not available -// to app extensions and linking to frameworks -// that have not been built with this setting enabled. -APPLICATION_EXTENSION_API_ONLY = YES diff --git a/Configurations/Base/Targets/StaticLibrary.xcconfig b/Configurations/Base/Targets/StaticLibrary.xcconfig deleted file mode 100755 index b3b2b87e..00000000 --- a/Configurations/Base/Targets/StaticLibrary.xcconfig +++ /dev/null @@ -1,32 +0,0 @@ -// -// This file defines additional configuration options that are appropriate only -// for a static library. Typically, you want to use a platform-specific variant -// instead. -// - -// Whether to strip out code that isn't called from anywhere -DEAD_CODE_STRIPPING = NO - -// Whether to strip debugging symbols when copying resources (like included -// binaries). -// -// Overrides Release.xcconfig when used at the target level. -COPY_PHASE_STRIP = NO - -// Whether function calls should be position-dependent (should always be -// disabled for library code) -GCC_DYNAMIC_NO_PIC = NO - -// Copy headers to "include/LibraryName" in the build folder by default. This -// lets consumers use #import syntax even for static -// libraries -PUBLIC_HEADERS_FOLDER_PATH = include/$PRODUCT_NAME - -// Don't include in an xcarchive -SKIP_INSTALL = YES - -// Disallows use of APIs that are not available -// to app extensions and linking to frameworks -// that have not been built with this setting enabled. -APPLICATION_EXTENSION_API_ONLY = YES - diff --git a/Configurations/Mac OS X/Mac-Application.xcconfig b/Configurations/Mac OS X/Mac-Application.xcconfig deleted file mode 100755 index 2e552c7f..00000000 --- a/Configurations/Mac OS X/Mac-Application.xcconfig +++ /dev/null @@ -1,15 +0,0 @@ -// -// This file defines additional configuration options that are appropriate only -// for an application on Mac OS X. This should be set at the target level for -// each project configuration. -// - -// Import base application settings -#include "../Base/Targets/Application.xcconfig" - -// Apply common settings specific to Mac OS X -#include "Mac-Base.xcconfig" - -// Whether function calls should be position-dependent (should always be -// disabled for library code) -GCC_DYNAMIC_NO_PIC = YES diff --git a/Configurations/Mac OS X/Mac-Base.xcconfig b/Configurations/Mac OS X/Mac-Base.xcconfig deleted file mode 100755 index 8fdecccb..00000000 --- a/Configurations/Mac OS X/Mac-Base.xcconfig +++ /dev/null @@ -1,19 +0,0 @@ -// -// This file defines additional configuration options that are appropriate only -// for Mac OS X. This file is not standalone -- it is meant to be included into -// a configuration file for a specific type of target. -// - -// Whether to combine multiple image resolutions into a multirepresentational -// TIFF -COMBINE_HIDPI_IMAGES = YES - -// Where to find embedded frameworks -LD_RUNPATH_SEARCH_PATHS = $(inherited) @executable_path/../Frameworks @loader_path/../Frameworks - -// The base SDK to use (if no version is specified, the latest version is -// assumed) -SDKROOT = macosx - -// Supported build architectures -VALID_ARCHS = x86_64 diff --git a/Configurations/Mac OS X/Mac-DynamicLibrary.xcconfig b/Configurations/Mac OS X/Mac-DynamicLibrary.xcconfig deleted file mode 100755 index 1e2a37c0..00000000 --- a/Configurations/Mac OS X/Mac-DynamicLibrary.xcconfig +++ /dev/null @@ -1,18 +0,0 @@ -// -// This file defines additional configuration options that are appropriate only -// for a dynamic library on Mac OS X. This should be set at the target level -// for each project configuration. -// - -// Import common settings specific to Mac OS X -#include "Mac-Base.xcconfig" - -// Whether to strip out code that isn't called from anywhere -DEAD_CODE_STRIPPING = NO - -// Whether function calls should be position-dependent (should always be -// disabled for library code) -GCC_DYNAMIC_NO_PIC = NO - -// Don't include in an xcarchive -SKIP_INSTALL = YES diff --git a/Configurations/Mac OS X/Mac-Framework.xcconfig b/Configurations/Mac OS X/Mac-Framework.xcconfig deleted file mode 100755 index dd987645..00000000 --- a/Configurations/Mac OS X/Mac-Framework.xcconfig +++ /dev/null @@ -1,11 +0,0 @@ -// -// This file defines additional configuration options that are appropriate only -// for a framework on OS X. This should be set at the target level for each -// project configuration. -// - -// Import base framework settings -#include "../Base/Targets/Framework.xcconfig" - -// Import common settings specific to Mac OS X -#include "Mac-Base.xcconfig" diff --git a/Configurations/Mac OS X/Mac-StaticLibrary.xcconfig b/Configurations/Mac OS X/Mac-StaticLibrary.xcconfig deleted file mode 100755 index 97d03188..00000000 --- a/Configurations/Mac OS X/Mac-StaticLibrary.xcconfig +++ /dev/null @@ -1,11 +0,0 @@ -// -// This file defines additional configuration options that are appropriate only -// for a static library on Mac OS X. This should be set at the target level for -// each project configuration. -// - -// Import base static library settings -#include "../Base/Targets/StaticLibrary.xcconfig" - -// Apply common settings specific to Mac OS X -#include "Mac-Base.xcconfig" diff --git a/Configurations/iOS/iOS-Application.xcconfig b/Configurations/iOS/iOS-Application.xcconfig deleted file mode 100755 index a7008683..00000000 --- a/Configurations/iOS/iOS-Application.xcconfig +++ /dev/null @@ -1,11 +0,0 @@ -// -// This file defines additional configuration options that are appropriate only -// for an application on iOS. This should be set at the target level for each -// project configuration. -// - -// Import base application settings -#include "../Base/Targets/Application.xcconfig" - -// Apply common settings specific to iOS -#include "iOS-Base.xcconfig" diff --git a/Configurations/iOS/iOS-Base.xcconfig b/Configurations/iOS/iOS-Base.xcconfig deleted file mode 100755 index f45f9058..00000000 --- a/Configurations/iOS/iOS-Base.xcconfig +++ /dev/null @@ -1,18 +0,0 @@ -// -// This file defines additional configuration options that are appropriate only -// for iOS. This file is not standalone -- it is meant to be included into -// a configuration file for a specific type of target. -// - -// Xcode needs this to find archived headers if SKIP_INSTALL is set -HEADER_SEARCH_PATHS = $(OBJROOT)/UninstalledProducts/include - -// Where to find embedded frameworks -LD_RUNPATH_SEARCH_PATHS = $(inherited) @executable_path/Frameworks @loader_path/Frameworks - -// The base SDK to use (if no version is specified, the latest version is -// assumed) -SDKROOT = iphoneos - -// Supported device families (1 is iPhone, 2 is iPad) -TARGETED_DEVICE_FAMILY = 1,2 diff --git a/Configurations/iOS/iOS-Framework.xcconfig b/Configurations/iOS/iOS-Framework.xcconfig deleted file mode 100755 index e538a7d2..00000000 --- a/Configurations/iOS/iOS-Framework.xcconfig +++ /dev/null @@ -1,11 +0,0 @@ -// -// This file defines additional configuration options that are appropriate only -// for a framework on iOS. This should be set at the target level for each -// project configuration. -// - -// Import base framework settings -#include "../Base/Targets/Framework.xcconfig" - -// Import common settings specific to iOS -#include "iOS-Base.xcconfig" diff --git a/Configurations/iOS/iOS-StaticLibrary.xcconfig b/Configurations/iOS/iOS-StaticLibrary.xcconfig deleted file mode 100755 index 7e3b507e..00000000 --- a/Configurations/iOS/iOS-StaticLibrary.xcconfig +++ /dev/null @@ -1,11 +0,0 @@ -// -// This file defines additional configuration options that are appropriate only -// for a static library on iOS. This should be set at the target level for each -// project configuration. -// - -// Import base static library settings -#include "../Base/Targets/StaticLibrary.xcconfig" - -// Apply common settings specific to iOS -#include "iOS-Base.xcconfig" diff --git a/Configurations/tvOS/tvOS-Application.xcconfig b/Configurations/tvOS/tvOS-Application.xcconfig deleted file mode 100755 index 74f892c7..00000000 --- a/Configurations/tvOS/tvOS-Application.xcconfig +++ /dev/null @@ -1,11 +0,0 @@ -// -// This file defines additional configuration options that are appropriate only -// for an application on tvOS. This should be set at the target level for -// each project configuration. -// - -// Import base application settings -#include "../Base/Targets/Application.xcconfig" - -// Apply common settings specific to tvOS -#include "tvOS-Base.xcconfig" diff --git a/Configurations/tvOS/tvOS-Base.xcconfig b/Configurations/tvOS/tvOS-Base.xcconfig deleted file mode 100755 index e5cb6162..00000000 --- a/Configurations/tvOS/tvOS-Base.xcconfig +++ /dev/null @@ -1,15 +0,0 @@ -// -// This file defines additional configuration options that are appropriate only -// for tvOS. This file is not standalone -- it is meant to be included into -// a configuration file for a specific type of target. -// - -// Where to find embedded frameworks -LD_RUNPATH_SEARCH_PATHS = $(inherited) @executable_path/Frameworks @loader_path/Frameworks - -// The base SDK to use (if no version is specified, the latest version is -// assumed) -SDKROOT = appletvos - -// Supported device families -TARGETED_DEVICE_FAMILY = 3 diff --git a/Configurations/tvOS/tvOS-Framework.xcconfig b/Configurations/tvOS/tvOS-Framework.xcconfig deleted file mode 100755 index cb088208..00000000 --- a/Configurations/tvOS/tvOS-Framework.xcconfig +++ /dev/null @@ -1,11 +0,0 @@ -// -// This file defines additional configuration options that are appropriate only -// for a framework on tvOS. This should be set at the target level for each -// project configuration. -// - -// Import base framework settings -#include "../Base/Targets/Framework.xcconfig" - -// Import common settings specific to iOS -#include "tvOS-Base.xcconfig" diff --git a/Configurations/tvOS/tvOS-StaticLibrary.xcconfig b/Configurations/tvOS/tvOS-StaticLibrary.xcconfig deleted file mode 100755 index 34d0200b..00000000 --- a/Configurations/tvOS/tvOS-StaticLibrary.xcconfig +++ /dev/null @@ -1,11 +0,0 @@ -// -// This file defines additional configuration options that are appropriate only -// for a static library on tvOS. This should be set at the target level for -// each project configuration. -// - -// Import base static library settings -#include "../Base/Targets/StaticLibrary.xcconfig" - -// Apply common settings specific to tvOS -#include "tvOS-Base.xcconfig" diff --git a/Configurations/watchOS/watchOS-Application.xcconfig b/Configurations/watchOS/watchOS-Application.xcconfig deleted file mode 100755 index 5d88df91..00000000 --- a/Configurations/watchOS/watchOS-Application.xcconfig +++ /dev/null @@ -1,11 +0,0 @@ -// -// This file defines additional configuration options that are appropriate only -// for an application on watchOS. This should be set at the target level for -// each project configuration. -// - -// Import base application settings -#include "../Base/Targets/Application.xcconfig" - -// Apply common settings specific to watchOS -#include "watchOS-Base.xcconfig" diff --git a/Configurations/watchOS/watchOS-Base.xcconfig b/Configurations/watchOS/watchOS-Base.xcconfig deleted file mode 100755 index 21e4a82f..00000000 --- a/Configurations/watchOS/watchOS-Base.xcconfig +++ /dev/null @@ -1,15 +0,0 @@ -// -// This file defines additional configuration options that are appropriate only -// for watchOS. This file is not standalone -- it is meant to be included into -// a configuration file for a specific type of target. -// - -// Where to find embedded frameworks -LD_RUNPATH_SEARCH_PATHS = $(inherited) @executable_path/Frameworks @loader_path/Frameworks - -// The base SDK to use (if no version is specified, the latest version is -// assumed) -SDKROOT = watchos - -// Supported device families -TARGETED_DEVICE_FAMILY = 4 diff --git a/Configurations/watchOS/watchOS-Framework.xcconfig b/Configurations/watchOS/watchOS-Framework.xcconfig deleted file mode 100755 index 38934945..00000000 --- a/Configurations/watchOS/watchOS-Framework.xcconfig +++ /dev/null @@ -1,11 +0,0 @@ -// -// This file defines additional configuration options that are appropriate only -// for a framework on watchOS. This should be set at the target level for each -// project configuration. -// - -// Import base framework settings -#include "../Base/Targets/Framework.xcconfig" - -// Import common settings specific to iOS -#include "watchOS-Base.xcconfig" diff --git a/Configurations/watchOS/watchOS-StaticLibrary.xcconfig b/Configurations/watchOS/watchOS-StaticLibrary.xcconfig deleted file mode 100755 index b9f92d8a..00000000 --- a/Configurations/watchOS/watchOS-StaticLibrary.xcconfig +++ /dev/null @@ -1,11 +0,0 @@ -// -// This file defines additional configuration options that are appropriate only -// for a static library on watchOS. This should be set at the target level for -// each project configuration. -// - -// Import base static library settings -#include "../Base/Targets/StaticLibrary.xcconfig" - -// Apply common settings specific to watchOS -#include "watchOS-Base.xcconfig" diff --git a/Gemfile b/Gemfile deleted file mode 100644 index 5b19c5b2..00000000 --- a/Gemfile +++ /dev/null @@ -1,5 +0,0 @@ -# frozen_string_literal: true - -source "https://rubygems.org" - -gem "cocoapods", "1.6.0.beta.1" diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index 1e3fa21a..00000000 --- a/Gemfile.lock +++ /dev/null @@ -1,76 +0,0 @@ -GEM - remote: https://rubygems.org/ - specs: - CFPropertyList (3.0.0) - activesupport (4.2.10) - i18n (~> 0.7) - minitest (~> 5.1) - thread_safe (~> 0.3, >= 0.3.4) - tzinfo (~> 1.1) - atomos (0.1.3) - claide (1.0.2) - cocoapods (1.6.0.beta.1) - activesupport (>= 4.0.2, < 5) - claide (>= 1.0.2, < 2.0) - cocoapods-core (= 1.6.0.beta.1) - cocoapods-deintegrate (>= 1.0.2, < 2.0) - cocoapods-downloader (>= 1.2.1, < 2.0) - cocoapods-plugins (>= 1.0.0, < 2.0) - cocoapods-search (>= 1.0.0, < 2.0) - cocoapods-stats (>= 1.0.0, < 2.0) - cocoapods-trunk (>= 1.3.1, < 2.0) - cocoapods-try (>= 1.1.0, < 2.0) - colored2 (~> 3.1) - escape (~> 0.0.4) - fourflusher (~> 2.0.1) - gh_inspector (~> 1.0) - molinillo (~> 0.6.6) - nap (~> 1.0) - ruby-macho (~> 1.2) - xcodeproj (>= 1.6.0, < 2.0) - cocoapods-core (1.6.0.beta.1) - activesupport (>= 4.0.2, < 6) - fuzzy_match (~> 2.0.4) - nap (~> 1.0) - cocoapods-deintegrate (1.0.2) - cocoapods-downloader (1.2.1) - cocoapods-plugins (1.0.0) - nap - cocoapods-search (1.0.0) - cocoapods-stats (1.0.0) - cocoapods-trunk (1.3.1) - nap (>= 0.8, < 2.0) - netrc (~> 0.11) - cocoapods-try (1.1.0) - colored2 (3.1.2) - concurrent-ruby (1.0.5) - escape (0.0.4) - fourflusher (2.0.1) - fuzzy_match (2.0.4) - gh_inspector (1.1.3) - i18n (0.9.5) - concurrent-ruby (~> 1.0) - minitest (5.11.3) - molinillo (0.6.6) - nanaimo (0.2.6) - nap (1.1.0) - netrc (0.11.0) - ruby-macho (1.2.0) - thread_safe (0.3.6) - tzinfo (1.2.5) - thread_safe (~> 0.1) - xcodeproj (1.6.0) - CFPropertyList (>= 2.3.3, < 4.0) - atomos (~> 0.1.3) - claide (>= 1.0.2, < 2.0) - colored2 (~> 3.1) - nanaimo (~> 0.2.6) - -PLATFORMS - ruby - -DEPENDENCIES - cocoapods (= 1.6.0.beta.1) - -BUNDLED WITH - 1.16.4 diff --git a/Sample-iOS.playground/Contents.swift b/Sample-iOS.playground/Contents.swift deleted file mode 100644 index 3797f0fd..00000000 --- a/Sample-iOS.playground/Contents.swift +++ /dev/null @@ -1,392 +0,0 @@ -/*: -# Swinject Sample for iOS -*/ - -import Swinject - -/*: -## Basic Use -*/ - -protocol Animal { - var name: String? { get set } - func sound() -> String -} - -class Cat: Animal { - var name: String? - - init(name: String?) { - self.name = name - } - - func sound() -> String { - return "Meow!" - } -} - -protocol Person { - func play() -> String -} - -class PetOwner: Person { - let pet: Animal - - init(pet: Animal) { - self.pet = pet - } - - func play() -> String { - let name = pet.name ?? "someone" - return "I'm playing with \(name). \(pet.sound())" - } -} - -// Create a container and register service and component pairs. -let container = Container() -container.register(Animal.self) { _ in Cat(name: "Mimi") } -container.register(Person.self) { r in PetOwner(pet: r.resolve(Animal.self)!) } - -// The person is resolved to a PetOwner with a Cat. -let person = container.resolve(Person.self)! -print(person.play()) - -/*: -## Named Registration -*/ - -class Dog: Animal { - var name: String? - - init(name: String?) { - self.name = name - } - - func sound() -> String { - return "Bow wow!" - } -} - -// Add more registrations to the container already containing the PetOwner with the Cat. -container.register(Animal.self, name: "dog") { _ in Dog(name: "Hachi") } -container.register(Person.self, name: "doggy") { r in PetOwner(pet: r.resolve(Animal.self, name: "dog")!) } - -// Resolve the service with the registration name to differentiate from the cat owner. -let doggyPerson = container.resolve(Person.self, name:"doggy")! -print(doggyPerson.play()) - -/*: -## Initialization Callback -*/ - -// A closure can be registered as an initCompleted callback. -var called = false -container.register(Animal.self, name: "cb") { _ in Cat(name: "Mew") } - .initCompleted { _, _ in called = true } -print(called) - -// The closure is executed when the instance is created. -let catWithCallback = container.resolve(Animal.self, name: "cb") -print(called) - -/*: -## Injection Patterns -*/ - -class InjectablePerson: Person { - var pet: Animal? { - didSet { - log = "Injected by property." - } - } - var log = "" - - init() { } - - init(pet: Animal) { - self.pet = pet - log = "Injected by initializer." - } - - func setPet(_ pet: Animal) { - self.pet = pet - log = "Injected by method." - } - - func play() -> String { - return log - } -} - -// Initializer injection -container.register(Person.self, name: "initializer") { r in - InjectablePerson(pet: r.resolve(Animal.self)!) -} - -let initializerInjection = container.resolve(Person.self, name:"initializer")! -print(initializerInjection.play()) - -// Property injection 1 (in the component factory) -container.register(Person.self, name: "property1") { r in - let person = InjectablePerson() - person.pet = r.resolve(Animal.self) - return person -} - -let propertyInjection1 = container.resolve(Person.self, name:"property1")! -print(propertyInjection1.play()) - -// Property injection 2 (in the initCompleted callback) -container.register(Person.self, name: "property2") { _ in InjectablePerson() } - .initCompleted { r, p in - let injectablePerson = p as! InjectablePerson - injectablePerson.pet = r.resolve(Animal.self) - } - -let propertyInjection2 = container.resolve(Person.self, name:"property2")! -print(propertyInjection2.play()) - -// Method injection 1 (in the component factory) -container.register(Person.self, name: "method1") { r in - let person = InjectablePerson() - person.setPet(r.resolve(Animal.self)!) - return person -} - -let methodInjection1 = container.resolve(Person.self, name:"method1")! -print(methodInjection1.play()) - -// Method injection 2 (in the initCompleted callback) -container.register(Person.self, name: "method2") { _ in InjectablePerson() } - .initCompleted { r, p in - let injectablePerson = p as! InjectablePerson - injectablePerson.setPet(r.resolve(Animal.self)!) - } - -let methodInjection2 = container.resolve(Person.self, name:"method2")! -print(methodInjection2.play()) - -/*: -## Circular Dependency -*/ - -internal protocol ParentProtocol: AnyObject { } -internal protocol ChildProtocol: AnyObject { } - -internal class Parent: ParentProtocol { - let child: ChildProtocol? - - init(child: ChildProtocol?) { - self.child = child - } -} - -internal class Child: ChildProtocol { - weak var parent: ParentProtocol? -} - -// Use initCompleted callback to set the circular dependency to avoid infinite recursion. -container.register(ParentProtocol.self) { r in Parent(child: r.resolve(ChildProtocol.self)!) } -container.register(ChildProtocol.self) { _ in Child() } - .initCompleted { r, c in - let child = c as! Child - child.parent = r.resolve(ParentProtocol.self) - } - -let parent = container.resolve(ParentProtocol.self) as! Parent -let child = parent.child as! Child - -// The parent and child are referencing each other. -print(parent === child.parent) - -/*: -## Injection with Arguments -*/ - -class Horse: Animal { - var name: String? - var running: Bool - - convenience init(name: String) { - self.init(name: name, running: false) - } - - init(name: String, running: Bool) { - self.name = name - self.running = running - } - - func sound() -> String { - return "Whinny!" - } -} - -// The factory closure can take arguments after the `Resolver` parameter (in this example, unused as `_`). -// Note that the container already has an Animal without a registration name, -// but the factory with the arguments is recognized as a different registration to resolve. -container.register(Animal.self) { _, name in Horse(name: name) } -container.register(Animal.self) { _, name, running in Horse(name: name, running: running) } - -// The arguments to the factory are specified on the resolution. -// If you pass an argument, pass it to `argument` parameter. -// If you pass more arguments, pass them as a tuple to `arguments` parameter. -let horse1 = container.resolve(Animal.self, argument: "Spirit") as! Horse -print(horse1.name!) -print(horse1.running) - -let horse2 = container.resolve(Animal.self, arguments: "Lucky", true) as! Horse -print(horse2.name!) -print(horse2.running) - -/*: -## Self-binding -*/ - -protocol MyData { - var data: String { get } -} - -class MyImportantData: MyData { - let data = "Important data" -} - -class MyController { - var myData: MyData? - - func showData() -> String { - return myData.map { $0.data } ?? "" - } -} - -// Register MyController as both service and component s to inject dependency to its property. -container.register(MyController.self) { r in MyController() } - .initCompleted { r, c in c.myData = r.resolve(MyData.self)! } -container.register(MyData.self) { _ in MyImportantData() } - -let myController = container.resolve(MyController.self)! -print(myController.showData()) - -/*: -## Container Hierarchy -*/ - -let parentContainer = Container() -parentContainer.register(Animal.self, name: "cat") { _ in Cat(name: "Mimi") } - -let childContainer = Container(parent: parentContainer) -childContainer.register(Animal.self, name: "dog") { _ in Dog(name: "Hachi") } - -// The registration on the parent container is resolved on the child container. -let cat = childContainer.resolve(Animal.self, name: "cat") -print(cat != nil) - -// The registration on the child container is not resolved on the parent container. -let dog = parentContainer.resolve(Animal.self, name: "dog") -print(dog == nil) - -/*: -## Object Scopes -*/ - -class A { - let b: B - let c: C - - init(b: B, c: C) { - self.b = b - self.c = c - } -} - -class B { - let c: C - - init(c: C) { - self.c = c - } -} - -class C { } - -//: ### ObjectScope.transient - -// New instatnces are created every time. -let container1 = Container() -container1.register(C.self) { _ in C() } - .inObjectScope(.transient) - -let c1 = container1.resolve(C.self) -let c2 = container1.resolve(C.self) -print(c1 !== c2) - -// New instances are created in a object graph. -container1.register(A.self) { r in A(b: r.resolve(B.self)!, c: r.resolve(C.self)!) } -container1.register(B.self) { r in B(c: r.resolve(C.self)!) } - -let a1 = container1.resolve(A.self)! -print(a1.b.c !== a1.c) - -//: ### ObjectScope.graph - -// New instances are created like ObjectScope.transient. -let container2 = Container() -container2.register(C.self) { _ in C() } - .inObjectScope(.graph) // This is the default scope. - -let c3 = container2.resolve(C.self) -let c4 = container2.resolve(C.self) -print(c3 !== c4) - -// But unlike ObjectScope.transient, the same instance is resolved in the object graph. -container2.register(A.self) { r in A(b: r.resolve(B.self)!, c: r.resolve(C.self)!) } -container2.register(B.self) { r in B(c: r.resolve(C.self)!) } - -let a2 = container2.resolve(A.self)! -print(a2.b.c === a2.c) - -//: ### ObjectScope.container - -// The same instance is shared in the container -let container4 = Container() -container4.register(C.self) { _ in C() } - .inObjectScope(.container) - -let c8 = container4.resolve(C.self) -let c9 = container4.resolve(C.self) -print(c8 === c9) - -// The instance in the parent container is shared to its child container. -let childOfContainer4 = Container(parent: container4) -let c10 = childOfContainer4.resolve(C.self) -print(c8 === c10) - -/*: -## Injection of Value s -*/ - -struct Turtle: Animal { - var name: String? - - init(name: String?) { - self.name = name - } - - func sound() -> String { - return "Ninja!" - } -} - -// A value can be registered as a component. -// The object scope is ignored because a value always creates a new instance. -let container5 = Container() -container5.register(Animal.self) { _ in Turtle(name: "Reo") } - .inObjectScope(.container) - -var turtle1 = container5.resolve(Animal.self)! -var turtle2 = container5.resolve(Animal.self)! - -// Still the of turtle1 and turtle2 is Animal protocol, they work as value s. -// (Try editing 'var turtle1' to 'let turtle1', then you see a compilation error!) -turtle1.name = "Laph" -print(turtle1.name!) -print(turtle2.name!) diff --git a/Sample-iOS.playground/contents.xcplayground b/Sample-iOS.playground/contents.xcplayground deleted file mode 100644 index 35968656..00000000 --- a/Sample-iOS.playground/contents.xcplayground +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/Sources/Assembler.swift b/Sources/Assembler.swift deleted file mode 100644 index c53f09d8..00000000 --- a/Sources/Assembler.swift +++ /dev/null @@ -1,129 +0,0 @@ -// -// Assembler.swift -// Swinject -// -// Created by mike.owens on 12/9/15. -// Copyright © 2015 Swinject Contributors. All rights reserved. -// - -/// The `Assembler` provides a means to build a container via `Assembly` instances. -public final class Assembler { - - /// the container that each assembly will build its `Service` definitions into - private let container: Container - - /// expose the container as a resolver so `Service` registration only happens within an assembly - public var resolver: Resolver { - return container - } - - /// Will create an empty `Assembler` - /// - /// - parameter container: the baseline container - /// - public init(container: Container? = Container()) { - self.container = container! - } - - /// Will create an empty `Assembler` - /// - /// - parameter parentAssembler: the baseline assembler - /// - parameter defaultObjectScope: default object scope for container - /// - parameter behaviors: list of behaviors to be added to the container - public init(parentAssembler: Assembler?, defaultObjectScope: ObjectScope = .graph, behaviors: [Behavior] = []) { - container = Container( - parent: parentAssembler?.container, - defaultObjectScope: defaultObjectScope, - behaviors: behaviors - ) - } - - /// Will create a new `Assembler` with the given `Assembly` instances to build a `Container` - /// - /// - parameter assemblies: the list of assemblies to build the container from - /// - parameter container: the baseline container - /// - @available(*, deprecated, message: "Use not throwing alternative: init(_:, container:)") - public convenience init(assemblies: [Assembly], container: Container? = Container()) throws { - if let container = container { - self.init(assemblies, container: container) - } else { - self.init(assemblies) - } - } - - /// Will create a new `Assembler` with the given `Assembly` instances to build a `Container` - /// - /// - parameter assemblies: the list of assemblies to build the container from - /// - parameter container: the baseline container - /// - public init(_ assemblies: [Assembly], container: Container = Container()) { - self.container = container - run(assemblies: assemblies) - } - - /// Will create a new `Assembler` with the given `Assembly` instances to build a `Container` - /// - /// - parameter assemblies: the list of assemblies to build the container from - /// - parameter parentAssembler: the baseline assembler - /// - @available(*, deprecated, message: "Use not throwing alternative: init(_:, parent:)") - public convenience init(assemblies: [Assembly], parentAssembler: Assembler?) throws { - self.init(_: assemblies, parent: parentAssembler) - } - - /// Will create a new `Assembler` with the given `Assembly` instances to build a `Container` - /// - /// - parameter assemblies: the list of assemblies to build the container from - /// - parameter parent: the baseline assembler - /// - parameter defaultObjectScope: default object scope for container - /// - parameter behaviors: list of behaviors to be added to the container - public init( - _ assemblies: [Assembly], - parent: Assembler?, - defaultObjectScope: ObjectScope = .graph, - behaviors: [Behavior] = [] - ) { - container = Container(parent: parent?.container, defaultObjectScope: defaultObjectScope, behaviors: behaviors) - run(assemblies: assemblies) - } - - /// Will apply the assembly to the container. This is useful if you want to lazy load an assembly into the - /// assembler's container. - /// - /// If this assembly type is load aware, the loaded hook will be invoked right after the container has assembled - /// since after each call to `addAssembly` the container is fully loaded in its current state. If you wish to - /// lazy load several assemblies that have interdependencies between each other use `appyAssemblies` - /// - /// - parameter assembly: the assembly to apply to the container - /// - public func apply(assembly: Assembly) { - run(assemblies: [assembly]) - } - - /// Will apply the assemblies to the container. This is useful if you want to lazy load several assemblies into the - /// assembler's container - /// - /// If this assembly type is load aware, the loaded hook will be invoked right after the container has assembled - /// since after each call to `addAssembly` the container is fully loaded in its current state. - /// - /// - parameter assemblies: the assemblies to apply to the container - /// - public func apply(assemblies: [Assembly]) { - run(assemblies: assemblies) - } - - // MARK: Private - - private func run(assemblies: [Assembly]) { - // build the container from each assembly - for assembly in assemblies { - assembly.assemble(container: self.container) - } - - // inform all of the assemblies that the container is loaded - for assembly in assemblies { - assembly.loaded(resolver: self.resolver) - } - } -} diff --git a/Sources/Assembly.swift b/Sources/Assembly.swift deleted file mode 100644 index fcb9a42d..00000000 --- a/Sources/Assembly.swift +++ /dev/null @@ -1,32 +0,0 @@ -// -// Assembly.swift -// Swinject -// -// Created by mike.owens on 12/9/15. -// Copyright © 2015 Swinject Contributors. All rights reserved. -// - -/// The `Assembly` provides a means to organize your `Service` registration in logic groups which allows -/// the user to swap out different implementations of `Services` by providing different `Assembly` instances -/// to the `Assembler` -public protocol Assembly { - - /// Provide hook for `Assembler` to load Services into the provided container - /// - /// - parameter container: the container provided by the `Assembler` - /// - func assemble(container: Container) - - /// Provides a hook to the `Assembly` that will be called once the `Assembler` has loaded all `Assembly` - /// instances into the container. - /// - /// - parameter resolver: the resolver that can resolve instances from the built container - /// - func loaded(resolver: Resolver) -} - -public extension Assembly { - func loaded(resolver: Resolver) { - // no-op - } -} diff --git a/Sources/Behavior.swift b/Sources/Behavior.swift deleted file mode 100644 index 1a9474fe..00000000 --- a/Sources/Behavior.swift +++ /dev/null @@ -1,27 +0,0 @@ -// -// Behavior.swift -// Swinject-iOS -// -// Created by Jakub Vaňo on 16/02/2018. -// Copyright © 2018 Swinject Contributors. All rights reserved. -// - -/// Protocol for adding functionality to the container -public protocol Behavior { - /// This will be invoked on each behavior added to the `container` for each `entry` added to the container using - /// one of the `register()` or type forwading methods - /// - /// - Parameters: - /// - container: container into which an `entry` has been registered - /// - type: Type which will be resolved using the `entry` - /// - entry: ServiceEntry registered to the `container` - /// - name: name under which the service has been registered to the `container` - /// - /// - Remark: `Type` and `Service` can be different types in the case of type forwarding - func container( - _ container: Container, - didRegisterType type: Type.Type, - toService entry: ServiceEntry, - withName name: String? - ) -} diff --git a/Sources/Container.Arguments.erb b/Sources/Container.Arguments.erb deleted file mode 100644 index 4d32c739..00000000 --- a/Sources/Container.Arguments.erb +++ /dev/null @@ -1,93 +0,0 @@ -// -// Container.Arguments.swift -// Swinject -// -// Created by Yoichi Tagaya on 8/18/15. -// Copyright © 2015 Swinject Contributors. All rights reserved. -// - -// -// NOTICE: -// -// Container.Arguments.swift is generated from Container.Arguments.erb by ERB. -// Do NOT modify Container.Arguments.swift directly. -// Instead, modify Container.Arguments.erb and run `script/gencode` at the project root directory to generate the code. -// - -<% arg_count = 9 %> - -import Foundation - -// MARK: - Registeration with Arguments -extension Container { -<% (1..arg_count).each do |i| %> -<% arg_types = (1..i).map { |n| "Arg#{n}" }.join(", ") %> -<% arg_description = i == 1 ? "#{i} argument" : "#{i} arguments" %> - /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. - /// - /// - Parameters: - /// - serviceType: The service type to register. - /// - name: A registration name, which is used to differentiate from other registrations - /// that have the same service and factory types. - /// - factory: The closure to specify how the service type is resolved with the dependencies of the type. - /// It is invoked when the `Container` needs to instantiate the instance. - /// It takes a `Resolver` instance and <%= arg_description %> to inject dependencies to the instance, - /// and returns the instance of the component type for the service. - /// - /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. - @discardableResult - public func register>( - _ serviceType: Service.Type, - name: String? = nil, - factory: @escaping (Resolver, <%= arg_types %>) -> Service) -> ServiceEntry - { - return _register(serviceType, factory: factory, name: name) - } - -<% end %> -} - -// MARK: - Resolver with Arguments -extension Container { -<% (1..arg_count).each do |i| %> -<% arg_types = (1..i).map { |n| "Arg#{n}" }.join(", ") %> -<% arg_param_def = i == 1 ? "argument: Arg1" : "arguments arg1: Arg1, " + (2..i).map{ |n| "_ arg#{n}: Arg#{n}" }.join(", ") %> -<% arg_param_call = i == 1 ? "argument" : (1..i).map{ |n| "arg#{n}" }.join(", ") %> -<% arg_param_name = i == 1 ? "argument" : "arguments" %> -<% arg_param_type = i == 1 ? arg_types : "(" + arg_types + ")" %> -<% arg_param_description = i == 1 ? "#{i} argument" : "list of #{i} arguments" %> - /// Retrieves the instance with the specified service type and <%= arg_param_description %> to the factory closure. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - <%= arg_param_name %>: <%= arg_param_description.capitalize %> to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// and <%= arg_param_description %> is found in the `Container`. - public func resolve>( - _ serviceType: Service.Type, - <%= arg_param_def %>) -> Service? - { - return resolve(serviceType, name: nil, <%= arg_param_name %>: <%= arg_param_call %>) - } - - /// Retrieves the instance with the specified service type, <%= arg_param_description %> to the factory closure and registration name. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - name: The registration name. - /// - <%= arg_param_name %>: <%= arg_param_description.capitalize %> to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type, - /// <%= arg_param_description %> and name is found in the `Container`. - public func resolve>( - _ serviceType: Service.Type, - name: String?, - <%= arg_param_def %>) -> Service? - { - typealias FactoryType = ((Resolver, <%= arg_types %>)) -> Any - return _resolve(name: name) { (factory: FactoryType) in factory((self, <%= arg_param_call %>)) } - } - -<% end %> -} diff --git a/Sources/Container.Arguments.swift b/Sources/Container.Arguments.swift deleted file mode 100644 index 409e72e0..00000000 --- a/Sources/Container.Arguments.swift +++ /dev/null @@ -1,512 +0,0 @@ -// -// Container.Arguments.swift -// Swinject -// -// Created by Yoichi Tagaya on 8/18/15. -// Copyright © 2015 Swinject Contributors. All rights reserved. -// - -// -// NOTICE: -// -// Container.Arguments.swift is generated from Container.Arguments.erb by ERB. -// Do NOT modify Container.Arguments.swift directly. -// Instead, modify Container.Arguments.erb and run `script/gencode` at the project root directory to generate the code. -// - - -import Foundation - -// MARK: - Registeration with Arguments -extension Container { - /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. - /// - /// - Parameters: - /// - serviceType: The service type to register. - /// - name: A registration name, which is used to differentiate from other registrations - /// that have the same service and factory types. - /// - factory: The closure to specify how the service type is resolved with the dependencies of the type. - /// It is invoked when the `Container` needs to instantiate the instance. - /// It takes a `Resolver` instance and 1 argument to inject dependencies to the instance, - /// and returns the instance of the component type for the service. - /// - /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. - @discardableResult - public func register( - _ serviceType: Service.Type, - name: String? = nil, - factory: @escaping (Resolver, Arg1) -> Service) -> ServiceEntry - { - return _register(serviceType, factory: factory, name: name) - } - - /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. - /// - /// - Parameters: - /// - serviceType: The service type to register. - /// - name: A registration name, which is used to differentiate from other registrations - /// that have the same service and factory types. - /// - factory: The closure to specify how the service type is resolved with the dependencies of the type. - /// It is invoked when the `Container` needs to instantiate the instance. - /// It takes a `Resolver` instance and 2 arguments to inject dependencies to the instance, - /// and returns the instance of the component type for the service. - /// - /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. - @discardableResult - public func register( - _ serviceType: Service.Type, - name: String? = nil, - factory: @escaping (Resolver, Arg1, Arg2) -> Service) -> ServiceEntry - { - return _register(serviceType, factory: factory, name: name) - } - - /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. - /// - /// - Parameters: - /// - serviceType: The service type to register. - /// - name: A registration name, which is used to differentiate from other registrations - /// that have the same service and factory types. - /// - factory: The closure to specify how the service type is resolved with the dependencies of the type. - /// It is invoked when the `Container` needs to instantiate the instance. - /// It takes a `Resolver` instance and 3 arguments to inject dependencies to the instance, - /// and returns the instance of the component type for the service. - /// - /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. - @discardableResult - public func register( - _ serviceType: Service.Type, - name: String? = nil, - factory: @escaping (Resolver, Arg1, Arg2, Arg3) -> Service) -> ServiceEntry - { - return _register(serviceType, factory: factory, name: name) - } - - /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. - /// - /// - Parameters: - /// - serviceType: The service type to register. - /// - name: A registration name, which is used to differentiate from other registrations - /// that have the same service and factory types. - /// - factory: The closure to specify how the service type is resolved with the dependencies of the type. - /// It is invoked when the `Container` needs to instantiate the instance. - /// It takes a `Resolver` instance and 4 arguments to inject dependencies to the instance, - /// and returns the instance of the component type for the service. - /// - /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. - @discardableResult - public func register( - _ serviceType: Service.Type, - name: String? = nil, - factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) -> Service) -> ServiceEntry - { - return _register(serviceType, factory: factory, name: name) - } - - /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. - /// - /// - Parameters: - /// - serviceType: The service type to register. - /// - name: A registration name, which is used to differentiate from other registrations - /// that have the same service and factory types. - /// - factory: The closure to specify how the service type is resolved with the dependencies of the type. - /// It is invoked when the `Container` needs to instantiate the instance. - /// It takes a `Resolver` instance and 5 arguments to inject dependencies to the instance, - /// and returns the instance of the component type for the service. - /// - /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. - @discardableResult - public func register( - _ serviceType: Service.Type, - name: String? = nil, - factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) -> Service) -> ServiceEntry - { - return _register(serviceType, factory: factory, name: name) - } - - /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. - /// - /// - Parameters: - /// - serviceType: The service type to register. - /// - name: A registration name, which is used to differentiate from other registrations - /// that have the same service and factory types. - /// - factory: The closure to specify how the service type is resolved with the dependencies of the type. - /// It is invoked when the `Container` needs to instantiate the instance. - /// It takes a `Resolver` instance and 6 arguments to inject dependencies to the instance, - /// and returns the instance of the component type for the service. - /// - /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. - @discardableResult - public func register( - _ serviceType: Service.Type, - name: String? = nil, - factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6) -> Service) -> ServiceEntry - { - return _register(serviceType, factory: factory, name: name) - } - - /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. - /// - /// - Parameters: - /// - serviceType: The service type to register. - /// - name: A registration name, which is used to differentiate from other registrations - /// that have the same service and factory types. - /// - factory: The closure to specify how the service type is resolved with the dependencies of the type. - /// It is invoked when the `Container` needs to instantiate the instance. - /// It takes a `Resolver` instance and 7 arguments to inject dependencies to the instance, - /// and returns the instance of the component type for the service. - /// - /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. - @discardableResult - public func register( - _ serviceType: Service.Type, - name: String? = nil, - factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7) -> Service) -> ServiceEntry - { - return _register(serviceType, factory: factory, name: name) - } - - /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. - /// - /// - Parameters: - /// - serviceType: The service type to register. - /// - name: A registration name, which is used to differentiate from other registrations - /// that have the same service and factory types. - /// - factory: The closure to specify how the service type is resolved with the dependencies of the type. - /// It is invoked when the `Container` needs to instantiate the instance. - /// It takes a `Resolver` instance and 8 arguments to inject dependencies to the instance, - /// and returns the instance of the component type for the service. - /// - /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. - @discardableResult - public func register( - _ serviceType: Service.Type, - name: String? = nil, - factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8) -> Service) -> ServiceEntry - { - return _register(serviceType, factory: factory, name: name) - } - - /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. - /// - /// - Parameters: - /// - serviceType: The service type to register. - /// - name: A registration name, which is used to differentiate from other registrations - /// that have the same service and factory types. - /// - factory: The closure to specify how the service type is resolved with the dependencies of the type. - /// It is invoked when the `Container` needs to instantiate the instance. - /// It takes a `Resolver` instance and 9 arguments to inject dependencies to the instance, - /// and returns the instance of the component type for the service. - /// - /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. - @discardableResult - public func register( - _ serviceType: Service.Type, - name: String? = nil, - factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9) -> Service) -> ServiceEntry - { - return _register(serviceType, factory: factory, name: name) - } - -} - -// MARK: - Resolver with Arguments -extension Container { - /// Retrieves the instance with the specified service type and 1 argument to the factory closure. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - argument: 1 argument to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// and 1 argument is found in the `Container`. - public func resolve( - _ serviceType: Service.Type, - argument: Arg1) -> Service? - { - return resolve(serviceType, name: nil, argument: argument) - } - - /// Retrieves the instance with the specified service type, 1 argument to the factory closure and registration name. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - name: The registration name. - /// - argument: 1 argument to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type, - /// 1 argument and name is found in the `Container`. - public func resolve( - _ serviceType: Service.Type, - name: String?, - argument: Arg1) -> Service? - { - typealias FactoryType = ((Resolver, Arg1)) -> Any - return _resolve(name: name) { (factory: FactoryType) in factory((self, argument)) } - } - - /// Retrieves the instance with the specified service type and list of 2 arguments to the factory closure. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - arguments: List of 2 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// and list of 2 arguments is found in the `Container`. - public func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2) -> Service? - { - return resolve(serviceType, name: nil, arguments: arg1, arg2) - } - - /// Retrieves the instance with the specified service type, list of 2 arguments to the factory closure and registration name. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - name: The registration name. - /// - arguments: List of 2 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type, - /// list of 2 arguments and name is found in the `Container`. - public func resolve( - _ serviceType: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2) -> Service? - { - typealias FactoryType = ((Resolver, Arg1, Arg2)) -> Any - return _resolve(name: name) { (factory: FactoryType) in factory((self, arg1, arg2)) } - } - - /// Retrieves the instance with the specified service type and list of 3 arguments to the factory closure. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - arguments: List of 3 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// and list of 3 arguments is found in the `Container`. - public func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> Service? - { - return resolve(serviceType, name: nil, arguments: arg1, arg2, arg3) - } - - /// Retrieves the instance with the specified service type, list of 3 arguments to the factory closure and registration name. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - name: The registration name. - /// - arguments: List of 3 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type, - /// list of 3 arguments and name is found in the `Container`. - public func resolve( - _ serviceType: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> Service? - { - typealias FactoryType = ((Resolver, Arg1, Arg2, Arg3)) -> Any - return _resolve(name: name) { (factory: FactoryType) in factory((self, arg1, arg2, arg3)) } - } - - /// Retrieves the instance with the specified service type and list of 4 arguments to the factory closure. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - arguments: List of 4 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// and list of 4 arguments is found in the `Container`. - public func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> Service? - { - return resolve(serviceType, name: nil, arguments: arg1, arg2, arg3, arg4) - } - - /// Retrieves the instance with the specified service type, list of 4 arguments to the factory closure and registration name. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - name: The registration name. - /// - arguments: List of 4 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type, - /// list of 4 arguments and name is found in the `Container`. - public func resolve( - _ serviceType: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> Service? - { - typealias FactoryType = ((Resolver, Arg1, Arg2, Arg3, Arg4)) -> Any - return _resolve(name: name) { (factory: FactoryType) in factory((self, arg1, arg2, arg3, arg4)) } - } - - /// Retrieves the instance with the specified service type and list of 5 arguments to the factory closure. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - arguments: List of 5 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// and list of 5 arguments is found in the `Container`. - public func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> Service? - { - return resolve(serviceType, name: nil, arguments: arg1, arg2, arg3, arg4, arg5) - } - - /// Retrieves the instance with the specified service type, list of 5 arguments to the factory closure and registration name. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - name: The registration name. - /// - arguments: List of 5 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type, - /// list of 5 arguments and name is found in the `Container`. - public func resolve( - _ serviceType: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> Service? - { - typealias FactoryType = ((Resolver, Arg1, Arg2, Arg3, Arg4, Arg5)) -> Any - return _resolve(name: name) { (factory: FactoryType) in factory((self, arg1, arg2, arg3, arg4, arg5)) } - } - - /// Retrieves the instance with the specified service type and list of 6 arguments to the factory closure. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - arguments: List of 6 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// and list of 6 arguments is found in the `Container`. - public func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6) -> Service? - { - return resolve(serviceType, name: nil, arguments: arg1, arg2, arg3, arg4, arg5, arg6) - } - - /// Retrieves the instance with the specified service type, list of 6 arguments to the factory closure and registration name. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - name: The registration name. - /// - arguments: List of 6 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type, - /// list of 6 arguments and name is found in the `Container`. - public func resolve( - _ serviceType: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6) -> Service? - { - typealias FactoryType = ((Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6)) -> Any - return _resolve(name: name) { (factory: FactoryType) in factory((self, arg1, arg2, arg3, arg4, arg5, arg6)) } - } - - /// Retrieves the instance with the specified service type and list of 7 arguments to the factory closure. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - arguments: List of 7 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// and list of 7 arguments is found in the `Container`. - public func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7) -> Service? - { - return resolve(serviceType, name: nil, arguments: arg1, arg2, arg3, arg4, arg5, arg6, arg7) - } - - /// Retrieves the instance with the specified service type, list of 7 arguments to the factory closure and registration name. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - name: The registration name. - /// - arguments: List of 7 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type, - /// list of 7 arguments and name is found in the `Container`. - public func resolve( - _ serviceType: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7) -> Service? - { - typealias FactoryType = ((Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7)) -> Any - return _resolve(name: name) { (factory: FactoryType) in factory((self, arg1, arg2, arg3, arg4, arg5, arg6, arg7)) } - } - - /// Retrieves the instance with the specified service type and list of 8 arguments to the factory closure. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - arguments: List of 8 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// and list of 8 arguments is found in the `Container`. - public func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8) -> Service? - { - return resolve(serviceType, name: nil, arguments: arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) - } - - /// Retrieves the instance with the specified service type, list of 8 arguments to the factory closure and registration name. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - name: The registration name. - /// - arguments: List of 8 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type, - /// list of 8 arguments and name is found in the `Container`. - public func resolve( - _ serviceType: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8) -> Service? - { - typealias FactoryType = ((Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8)) -> Any - return _resolve(name: name) { (factory: FactoryType) in factory((self, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)) } - } - - /// Retrieves the instance with the specified service type and list of 9 arguments to the factory closure. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - arguments: List of 9 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// and list of 9 arguments is found in the `Container`. - public func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8, _ arg9: Arg9) -> Service? - { - return resolve(serviceType, name: nil, arguments: arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - } - - /// Retrieves the instance with the specified service type, list of 9 arguments to the factory closure and registration name. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - name: The registration name. - /// - arguments: List of 9 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type, - /// list of 9 arguments and name is found in the `Container`. - public func resolve( - _ serviceType: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8, _ arg9: Arg9) -> Service? - { - typealias FactoryType = ((Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9)) -> Any - return _resolve(name: name) { (factory: FactoryType) in factory((self, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)) } - } - -} diff --git a/Sources/Container.Logging.swift b/Sources/Container.Logging.swift deleted file mode 100644 index 972456dc..00000000 --- a/Sources/Container.Logging.swift +++ /dev/null @@ -1,24 +0,0 @@ -// -// Container.Logging.swift -// Swinject -// -// Created by Jakub Vaňo on 30/09/16. -// Copyright © 2016 Swinject Contributors. All rights reserved. -// - -public typealias LoggingFunctionType = (String) -> Void - -public extension Container { - /// Function to be used for logging debugging data. - /// Default implementation writes to standard output. - static var loggingFunction: LoggingFunctionType? { - get { return _loggingFunction } - set { _loggingFunction = newValue } - } - - internal static func log(_ message: String) { - _loggingFunction?(message) - } -} - -private var _loggingFunction: LoggingFunctionType? = { print($0) } diff --git a/Sources/Container.TypeForwarding.swift b/Sources/Container.TypeForwarding.swift deleted file mode 100644 index f1a49554..00000000 --- a/Sources/Container.TypeForwarding.swift +++ /dev/null @@ -1,35 +0,0 @@ -// -// Container.TypeForwarding.swift -// Swinject -// -// Created by Jakub Vaňo on 15/02/2018. -// Copyright © 2018 Swinject Contributors. All rights reserved. -// - -extension Container { - /// Adds the registration for `type` which resolves in the same way, as would the type - /// used to create the original `service` - i.e. using the same object scope, - /// arguments and `initCompleted` closures. - /// - /// ** Example usage ** - /// - /// let service = container.register(Dog.self) { _ in Dog() } - /// container.forward(Animal.self, to: service) - /// - /// let dogAsAnimal = container.resolve(Animal.self) - /// - /// - Parameters: - /// - type: Type resolution of which should be forwarded - /// - name: A registration name, which is used to differentiate from other registrations of the same `type` - /// - service: ServiceEntry which should be used for resolution of `type` - public func forward(_ type: T.Type, name: String? = nil, to service: ServiceEntry) { - let key = ServiceKey( - serviceType: T.self, - argumentsType: service.argumentsType, - name: name, - option: nil - ) - services[key] = service - behaviors.forEach { $0.container(self, didRegisterType: type, toService: service, withName: name) } - } -} diff --git a/Sources/Container.swift b/Sources/Container.swift deleted file mode 100644 index db33f0a1..00000000 --- a/Sources/Container.swift +++ /dev/null @@ -1,334 +0,0 @@ -// -// Container.swift -// Swinject -// -// Created by Yoichi Tagaya on 7/23/15. -// Copyright © 2015 Swinject Contributors. All rights reserved. -// - -import Foundation - -/// The `Container` class represents a dependency injection container, which stores registrations of services -/// and retrieves registered services with dependencies injected. -/// -/// **Example to register:** -/// -/// let container = Container() -/// container.register(A.self) { _ in B() } -/// container.register(X.self) { r in Y(a: r.resolve(A.self)!) } -/// -/// **Example to retrieve:** -/// -/// let x = container.resolve(X.self)! -/// -/// where `A` and `X` are protocols, `B` is a type conforming `A`, and `Y` is a type conforming `X` -/// and depending on `A`. -public final class Container { - internal var services = [ServiceKey: ServiceEntryProtocol]() - fileprivate let parent: Container? // Used by HierarchyObjectScope - fileprivate var resolutionDepth = 0 - fileprivate let debugHelper: DebugHelper - fileprivate let defaultObjectScope: ObjectScope - internal var currentObjectGraph: GraphIdentifier? - internal let lock: SpinLock // Used by SynchronizedResolver. - internal var behaviors = [Behavior]() - - internal init( - parent: Container? = nil, - debugHelper: DebugHelper, - defaultObjectScope: ObjectScope = .graph) { - self.parent = parent - self.debugHelper = debugHelper - self.lock = parent.map { $0.lock } ?? SpinLock() - self.defaultObjectScope = defaultObjectScope - } - - /// Instantiates a `Container` - /// - /// - Parameters - /// - parent: The optional parent `Container`. - /// - defaultObjectScope: Default object scope (graph if no scope is injected) - /// - behaviors: List of behaviors to be added to the container - /// - registeringClosure: The closure registering services to the new container instance. - /// - /// - Remark: Compile time may be long if you pass a long closure to this initializer. - /// Use `init()` or `init(parent:)` instead. - public convenience init( - parent: Container? = nil, - defaultObjectScope: ObjectScope = .graph, - behaviors: [Behavior] = [], - registeringClosure: (Container) -> Void = { _ in } - ) { - self.init(parent: parent, debugHelper: LoggingDebugHelper(), defaultObjectScope: defaultObjectScope) - behaviors.forEach(addBehavior) - registeringClosure(self) - } - - /// Removes all registrations in the container. - public func removeAll() { - services.removeAll() - } - - /// Discards instances for services registered in the given `ObjectsScopeProtocol`. - /// - /// **Example usage:** - /// container.resetObjectScope(ObjectScope.container) - /// - /// - Parameters: - /// - objectScope: All instances registered in given `ObjectsScopeProtocol` will be discarded. - public func resetObjectScope(_ objectScope: ObjectScopeProtocol) { - services.values - .filter { $0.objectScope === objectScope } - .forEach { $0.storage.instance = nil } - - parent?.resetObjectScope(objectScope) - } - - /// Discards instances for services registered in the given `ObjectsScope`. It performs the same operation - /// as `resetObjectScope(_:ObjectScopeProtocol)`, but provides more convenient usage syntax. - /// - /// **Example usage:** - /// container.resetObjectScope(.container) - /// - /// - Parameters: - /// - objectScope: All instances registered in given `ObjectsScope` will be discarded. - public func resetObjectScope(_ objectScope: ObjectScope) { - resetObjectScope(objectScope as ObjectScopeProtocol) - } - - /// Adds a registration for the specified service with the factory closure to specify how the service is - /// resolved with dependencies. - /// - /// - Parameters: - /// - serviceType: The service type to register. - /// - name: A registration name, which is used to differentiate from other registrations - /// that have the same service and factory types. - /// - factory: The closure to specify how the service type is resolved with the dependencies of the type. - /// It is invoked when the `Container` needs to instantiate the instance. - /// It takes a `Resolver` to inject dependencies to the instance, - /// and returns the instance of the component type for the service. - /// - /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. - @discardableResult - public func register( - _ serviceType: Service.Type, - name: String? = nil, - factory: @escaping (Resolver) -> Service - ) -> ServiceEntry { - return _register(serviceType, factory: factory, name: name) - } - - /// This method is designed for the use to extend Swinject functionality. - /// Do NOT use this method unless you intend to write an extension or plugin to Swinject framework. - /// - /// - Parameters: - /// - serviceType: The service type to register. - /// - factory: The closure to specify how the service type is resolved with the dependencies of the type. - /// It is invoked when the `Container` needs to instantiate the instance. - /// It takes a `Resolver` to inject dependencies to the instance, - /// and returns the instance of the component type for the service. - /// - name: A registration name. - /// - option: A service key option for an extension/plugin. - /// - /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. - @discardableResult - // swiftlint:disable:next identifier_name - public func _register( - _ serviceType: Service.Type, - factory: @escaping (Arguments) -> Any, - name: String? = nil, - option: ServiceKeyOption? = nil - ) -> ServiceEntry { - let key = ServiceKey(serviceType: Service.self, argumentsType: Arguments.self, name: name, option: option) - let entry = ServiceEntry( - serviceType: serviceType, - argumentsType: Arguments.self, - factory: factory, - objectScope: defaultObjectScope - ) - entry.container = self - services[key] = entry - - behaviors.forEach { $0.container(self, didRegisterType: serviceType, toService: entry, withName: name) } - - return entry - } - - /// Returns a synchronized view of the container for thread safety. - /// The returned container is `Resolver` type. Call this method after you finish all service registrations - /// to the original container. - /// - /// - Returns: A synchronized container as `Resolver`. - public func synchronize() -> Resolver { - return SynchronizedResolver(container: self) - } - - /// Adds behavior to the container. `Behavior.container(_:didRegisterService:withName:)` will be invoked for - /// each service registered to the `container` **after** the behavior has been added. - /// - /// - Parameters: - /// - behavior: Behavior to be added to the container - public func addBehavior(_ behavior: Behavior) { - behaviors.append(behavior) - } - - internal func restoreObjectGraph(_ identifier: GraphIdentifier) { - currentObjectGraph = identifier - } -} - -// MARK: - _Resolver -extension Container: _Resolver { - // swiftlint:disable:next identifier_name - public func _resolve( - name: String?, - option: ServiceKeyOption? = nil, - invoker: @escaping ((Arguments) -> Any) -> Any - ) -> Service? { - var resolvedInstance: Service? - let key = ServiceKey(serviceType: Service.self, argumentsType: Arguments.self, name: name, option: option) - - if let entry = getEntry(for: key) { - resolvedInstance = resolve(entry: entry, invoker: invoker) - } - - if resolvedInstance == nil { - resolvedInstance = resolveAsWrapper(name: name, option: option, invoker: invoker) - } - - if resolvedInstance == nil { - debugHelper.resolutionFailed( - serviceType: Service.self, - key: key, - availableRegistrations: getRegistrations() - ) - } - - return resolvedInstance - } - - fileprivate func resolveAsWrapper( - name: String?, - option: ServiceKeyOption?, - invoker: @escaping ((Arguments) -> Any) -> Any - ) -> Wrapper? { - guard let wrapper = Wrapper.self as? InstanceWrapper.Type else { return nil } - - let key = ServiceKey( - serviceType: wrapper.wrappedType, argumentsType: Arguments.self, name: name, option: option - ) - - if let entry = getEntry(for: key) { - let factory = { [weak self] in self?.resolve(entry: entry, invoker: invoker) as Any? } - return wrapper.init(inContainer: self, withInstanceFactory: factory) as? Wrapper - } else { - return wrapper.init(inContainer: self, withInstanceFactory: nil) as? Wrapper - } - } - - fileprivate func getRegistrations() -> [ServiceKey: ServiceEntryProtocol] { - var registrations = parent?.getRegistrations() ?? [:] - services.forEach { key, value in registrations[key] = value } - return registrations - } - - fileprivate var maxResolutionDepth: Int { return 200 } - - fileprivate func incrementResolutionDepth() { - parent?.incrementResolutionDepth() - if resolutionDepth == 0 && currentObjectGraph == nil { - currentObjectGraph = GraphIdentifier() - } - guard resolutionDepth < maxResolutionDepth else { - fatalError("Infinite recursive call for circular dependency has been detected. " + - "To avoid the infinite call, 'initCompleted' handler should be used to inject circular dependency.") - } - resolutionDepth += 1 - } - - fileprivate func decrementResolutionDepth() { - parent?.decrementResolutionDepth() - assert(resolutionDepth > 0, "The depth cannot be negative.") - - resolutionDepth -= 1 - if resolutionDepth == 0 { graphResolutionCompleted() } - } - - fileprivate func graphResolutionCompleted() { - services.values.forEach { $0.storage.graphResolutionCompleted() } - self.currentObjectGraph = nil - } -} - -// MARK: - Resolver -extension Container: Resolver { - /// Retrieves the instance with the specified service type. - /// - /// - Parameter serviceType: The service type to resolve. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// is found in the `Container`. - public func resolve(_ serviceType: Service.Type) -> Service? { - return resolve(serviceType, name: nil) - } - - /// Retrieves the instance with the specified service type and registration name. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - name: The registration name. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type and name - /// is found in the `Container`. - public func resolve(_ serviceType: Service.Type, name: String?) -> Service? { - return _resolve(name: name) { (factory: (Resolver) -> Any) in factory(self) } - } - - fileprivate func getEntry(for key: ServiceKey) -> ServiceEntryProtocol? { - if let entry = services[key] { - return entry - } else { - return parent?.getEntry(for: key) - } - } - - fileprivate func resolve( - entry: ServiceEntryProtocol, - invoker: (Factory) -> Any - ) -> Service? { - incrementResolutionDepth() - defer { decrementResolutionDepth() } - - guard let currentObjectGraph = currentObjectGraph else { - fatalError("If accessing container from multiple threads, make sure to use a synchronized resolver.") - } - - if let persistedInstance = entry.storage.instance(inGraph: currentObjectGraph), let persistedService = persistedInstance as? Service { - return persistedService - } - - let resolvedInstance = invoker(entry.factory as! Factory) - if let persistedInstance = entry.storage.instance(inGraph: currentObjectGraph), let persistedService = persistedInstance as? Service { - // An instance for the key might be added by the factory invocation. - return persistedService - } - entry.storage.setInstance(resolvedInstance as Any, inGraph: currentObjectGraph) - - if let completed = entry.initCompleted as? (Resolver, Any) -> Void, - let resolvedInstance = resolvedInstance as? Service { - - completed(self, resolvedInstance) - } - - return resolvedInstance as? Service - } -} - -// MARK: CustomStringConvertible -extension Container: CustomStringConvertible { - public var description: String { - return "[" - + services.map { "\n { \($1.describeWithKey($0)) }" }.sorted().joined(separator: ",") - + "\n]" - } -} diff --git a/Sources/DebugHelper.swift b/Sources/DebugHelper.swift deleted file mode 100644 index 206721e2..00000000 --- a/Sources/DebugHelper.swift +++ /dev/null @@ -1,55 +0,0 @@ -// -// DebugHelper.swift -// Swinject -// -// Created by Jakub Vaňo on 26/09/16. -// Copyright © 2016 Swinject Contributors. All rights reserved. -// - -internal protocol DebugHelper { - func resolutionFailed( - serviceType: Service.Type, - key: ServiceKey, - availableRegistrations: [ServiceKey: ServiceEntryProtocol] - ) -} - -internal final class LoggingDebugHelper: DebugHelper { - - func resolutionFailed( - serviceType: Service.Type, - key: ServiceKey, - availableRegistrations: [ServiceKey: ServiceEntryProtocol] - ) { - var output = [ - "Swinject: Resolution failed. Expected registration:", - "\t{ \(description(serviceType: serviceType, serviceKey: key)) }", - "Available registrations:" - ] - output += availableRegistrations - .filter { $0.1 is ServiceEntry } - .map { "\t{ " + $0.1.describeWithKey($0.0) + " }" } - - Container.log(output.joined(separator: "\n")) - } -} - -internal func description( - serviceType: Any.Type, - serviceKey: ServiceKey, - objectScope: ObjectScopeProtocol? = nil, - initCompleted: [Any] = [] -) -> String { - // The protocol order in "protocol<>" is non-deterministic. - let nameDescription = serviceKey.name.map { ", Name: \"\($0)\"" } ?? "" - let optionDescription = serviceKey.option.map { ", \($0)" } ?? "" - let initCompletedDescription = initCompleted.isEmpty ? - "" : ", InitCompleted: Specified \(initCompleted.count) closures" - let objectScopeDescription = objectScope.map { ", ObjectScope: \($0)" } ?? "" - return "Service: \(serviceType)" - + nameDescription - + optionDescription - + ", Factory: \(serviceKey.argumentsType) -> \(serviceKey.serviceType)" - + objectScopeDescription - + initCompletedDescription -} diff --git a/Sources/FunctionType.swift b/Sources/FunctionType.swift deleted file mode 100644 index d9af9357..00000000 --- a/Sources/FunctionType.swift +++ /dev/null @@ -1,10 +0,0 @@ -// -// FunctionType.swift -// Swinject -// -// Created by Yoichi Tagaya on 11/28/15. -// Copyright © 2015 Swinject Contributors. All rights reserved. -// - -// Type alias to expect a closure. -internal typealias FunctionType = Any diff --git a/Sources/GraphIdentifier.swift b/Sources/GraphIdentifier.swift deleted file mode 100644 index a033e920..00000000 --- a/Sources/GraphIdentifier.swift +++ /dev/null @@ -1,20 +0,0 @@ -// -// GraphIdentifier.swift -// Swinject -// -// Created by Jakub Vaňo on 08/03/2018. -// Copyright © 2018 Swinject Contributors. All rights reserved. -// - -/// Unique identifier of an object graph during a resolution process. -public final class GraphIdentifier {} - -extension GraphIdentifier: Equatable, Hashable { - public static func == (lhs: GraphIdentifier, rhs: GraphIdentifier) -> Bool { - return lhs === rhs - } - - public func hash(into hasher: inout Hasher) { - hasher.combine(ObjectIdentifier(self).hashValue) - } -} diff --git a/Sources/Info.plist b/Sources/Info.plist index 35cb69f6..3c49e7d7 100644 --- a/Sources/Info.plist +++ b/Sources/Info.plist @@ -3,7 +3,7 @@ CFBundleDevelopmentRegion - en + $(DEVELOPMENT_LANGUAGE) CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier @@ -13,14 +13,12 @@ CFBundleName $(PRODUCT_NAME) CFBundlePackageType - FMWK + $(PRODUCT_BUNDLE_PACKAGE_TYPE) CFBundleShortVersionString - 2.6.2 - CFBundleSignature - ???? + 1.0 CFBundleVersion $(CURRENT_PROJECT_VERSION) - NSPrincipalClass - + NSHumanReadableCopyright + Copyright © 2019 Swinject Contributors. All rights reserved. diff --git a/Sources/InstanceStorage.swift b/Sources/InstanceStorage.swift deleted file mode 100644 index b82e3081..00000000 --- a/Sources/InstanceStorage.swift +++ /dev/null @@ -1,133 +0,0 @@ -// -// InstanceStorage.swift -// Swinject -// -// Created by Jakub Vaňo on 11/11/16. -// Copyright © 2016 Swinject Contributors. All rights reserved. -// - -/// Storage provided by `ObjectScope`. It is used by `Container` to persist resolved instances. -public protocol InstanceStorage: AnyObject { - var instance: Any? { get set } - func graphResolutionCompleted() - func instance(inGraph graph: GraphIdentifier) -> Any? - func setInstance(_ instance: Any?, inGraph graph: GraphIdentifier) -} - -extension InstanceStorage { - public func graphResolutionCompleted() {} - public func instance(inGraph _: GraphIdentifier) -> Any? { return instance } - public func setInstance(_ instance: Any?, inGraph _: GraphIdentifier) { self.instance = instance } -} - -/// Persists storage during the resolution of the object graph -public final class GraphStorage: InstanceStorage { - private var instances = [GraphIdentifier: Weak]() - public var instance: Any? - - public init() {} - - public func graphResolutionCompleted() { - instance = nil - } - - public func instance(inGraph graph: GraphIdentifier) -> Any? { - return instances[graph]?.value - } - - public func setInstance(_ instance: Any?, inGraph graph: GraphIdentifier) { - self.instance = instance - - if instances[graph] == nil { instances[graph] = Weak() } - instances[graph]?.value = instance - } -} - -/// Persists stored instance until it is explicitly discarded. -public final class PermanentStorage: InstanceStorage { - public var instance: Any? - - public init() {} -} - -/// Does not persist stored instance. -public final class TransientStorage: InstanceStorage { - public var instance: Any? { - get { return nil } - set {} - } - - public init() {} -} - -/// Does not persist value types. -/// Persists reference types as long as there are strong references to given instance. -public final class WeakStorage: InstanceStorage { - private var _instance = Weak() - - public var instance: Any? { - get { return _instance.value } - set { _instance.value = newValue } - } - - public init () {} -} - -/// Combines the behavior of multiple instance storages. -/// Instance is persisted as long as at least one of the underlying storages is persisting it. -public final class CompositeStorage: InstanceStorage { - private let components: [InstanceStorage] - - public var instance: Any? { - get { - #if swift(>=4.1) - return components.compactMap { $0.instance } .first - #else - return components.flatMap { $0.instance } .first - #endif - } - set { components.forEach { $0.instance = newValue } } - } - - public init(_ components: [InstanceStorage]) { - self.components = components - } - - public func graphResolutionCompleted() { - components.forEach { $0.graphResolutionCompleted() } - } - - public func setInstance(_ instance: Any?, inGraph graph: GraphIdentifier) { - components.forEach { $0.setInstance(instance, inGraph: graph) } - } - - public func instance(inGraph graph: GraphIdentifier) -> Any? { - #if swift(>=4.1) - return components.compactMap { $0.instance(inGraph: graph) } .first - #else - return components.flatMap { $0.instance(inGraph: graph) } .first - #endif - } -} - -private class Weak { - private weak var object: AnyObject? - -#if os(Linux) - var value: Wrapped? { - get { - guard let object = object else { return nil } - return object as? Wrapped - } - set { object = newValue.flatMap { $0 as? AnyObject } } - } -#else - var value: Wrapped? { - get { - guard let object = object else { return nil } - return object as? Wrapped - } - set { object = newValue as AnyObject? } - } -#endif -} diff --git a/Sources/InstanceWrapper.swift b/Sources/InstanceWrapper.swift deleted file mode 100644 index 2bbe47e8..00000000 --- a/Sources/InstanceWrapper.swift +++ /dev/null @@ -1,81 +0,0 @@ -// -// Lazy.swift -// Swinject -// -// Created by Jakub Vaňo on 07/03/2018. -// Copyright © 2018 Swinject Contributors. All rights reserved. -// - -protocol InstanceWrapper { - static var wrappedType: Any.Type { get } - init?(inContainer container: Container, withInstanceFactory factory: (() -> Any?)?) -} - -/// Wrapper to enable delayed dependency instantiation. -/// `Lazy` does not need to be explicitly registered into the `Container` - resolution will work -/// as long as there is a registration for the `Type`. -public final class Lazy: InstanceWrapper { - static var wrappedType: Any.Type { return Service.self } - - private let factory: () -> Any? - private let graphIdentifier: GraphIdentifier? - private weak var container: Container? - - init?(inContainer container: Container, withInstanceFactory factory: (() -> Any?)?) { - guard let factory = factory else { return nil } - self.factory = factory - self.graphIdentifier = container.currentObjectGraph - self.container = container - } - - private var _instance: Service? - - /// Getter for the wrapped object. - /// It will be resolved from the `Container` when first accessed, all other calls will return the same instance. - public var instance: Service { - if let instance = _instance { - return instance - } else { - _instance = makeInstance() - return _instance! - } - } - - private func makeInstance() -> Service? { - guard let container = container else { - return nil - } - if let graphIdentifier = graphIdentifier { - container.restoreObjectGraph(graphIdentifier) - } - return factory() as? Service - } -} - -/// Wrapper to enable delayed dependency instantiation. -/// `Provider` does not need to be explicitly registered into the `Container` - resolution will work -/// as long as there is a registration for the `Type`. -public final class Provider: InstanceWrapper { - static var wrappedType: Any.Type { return Service.self } - - private let factory: () -> Any? - - init?(inContainer container: Container, withInstanceFactory factory: (() -> Any?)?) { - guard let factory = factory else { return nil } - self.factory = factory - } - - /// Getter for the wrapped object. - /// New instance will be resolved from the `Container` every time it is accessed. - public var instance: Service { - return factory() as! Service - } -} - -extension Optional: InstanceWrapper { - static var wrappedType: Any.Type { return Wrapped.self } - - init?(inContainer container: Container, withInstanceFactory factory: (() -> Any?)?) { - self = factory?() as? Wrapped - } -} diff --git a/Sources/ObjectScope.Standard.swift b/Sources/ObjectScope.Standard.swift deleted file mode 100644 index f3475881..00000000 --- a/Sources/ObjectScope.Standard.swift +++ /dev/null @@ -1,26 +0,0 @@ -// -// ObjectScope.Standard.swift -// Swinject -// -// Created by Jakub Vaňo on 11/11/16. -// Copyright © 2016 Swinject Contributors. All rights reserved. -// - -extension ObjectScope { - /// A new instance is always created by the `Container` when a type is resolved. - /// The instance is not shared. - public static let transient = ObjectScope(storageFactory: TransientStorage.init, description: "transient") - - /// Instances are shared only when an object graph is being created, - /// otherwise a new instance is created by the `Container`. This is the default scope. - public static let graph = ObjectScope(storageFactory: GraphStorage.init, description: "graph") - - /// An instance provided by the `Container` is shared within the `Container` and its child `Containers`. - public static let container = ObjectScope(storageFactory: PermanentStorage.init, description: "container") - - /// An instance provided by the `Container` is shared within the `Container` and its child `Container`s - /// as long as there are strong references to given instance. Otherwise new instance is created - /// when resolving the type. - public static let weak = ObjectScope(storageFactory: WeakStorage.init, description: "weak", - parent: ObjectScope.graph) -} diff --git a/Sources/ObjectScope.swift b/Sources/ObjectScope.swift deleted file mode 100644 index 711e1b2c..00000000 --- a/Sources/ObjectScope.swift +++ /dev/null @@ -1,48 +0,0 @@ -// -// ObjectScope.swift -// Swinject -// -// Created by Yoichi Tagaya on 7/24/15. -// Copyright © 2015 Swinject Contributors. All rights reserved. -// - -/// A configuration how an instance provided by a `Container` is shared in the system. -/// The configuration is ignored if it is applied to a value type. -public protocol ObjectScopeProtocol: AnyObject { - - /// Used to create `InstanceStorage` to persist an instance for single service. - /// Will be invoked once for each service registered in given scope. - func makeStorage() -> InstanceStorage -} - -/// Basic implementation of `ObjectScopeProtocol`. -public class ObjectScope: ObjectScopeProtocol, CustomStringConvertible { - - public private(set) var description: String - private var storageFactory: () -> InstanceStorage - private let parent: ObjectScopeProtocol? - - /// Instantiates an `ObjectScope` with storage factory and description. - /// - Parameters: - /// - storageFactory: Closure for creating an `InstanceStorage` - /// - description: Description of object scope for `CustomStringConvertible` implementation - /// - parent: If provided, its storage will be composed with the result of `storageFactory` - public init( - storageFactory: @escaping () -> InstanceStorage, - description: String = "", - parent: ObjectScopeProtocol? = nil - ) { - self.storageFactory = storageFactory - self.description = description - self.parent = parent - } - - /// Will invoke and return the result of `storageFactory` closure provided during initialisation. - public func makeStorage() -> InstanceStorage { - if let parent = parent { - return CompositeStorage([storageFactory(), parent.makeStorage()]) - } else { - return storageFactory() - } - } -} diff --git a/Sources/Resolver.erb b/Sources/Resolver.erb deleted file mode 100644 index 0eeb0369..00000000 --- a/Sources/Resolver.erb +++ /dev/null @@ -1,69 +0,0 @@ -// -// Resolver.swift -// Swinject -// -// Created by Yoichi Tagaya on 8/18/15. -// Copyright (c) 2015 Swinject Contributors. All rights reserved. -// - -// -// NOTICE: -// -// Resolver.swift is generated from Resolver.erb by ERB. -// Do NOT modify Container.Arguments.swift directly. -// Instead, modify Resolver.erb and run `script/gencode` at the project root directory to generate the code. -// - -<% arg_count = 9 %> - -public protocol Resolver { - /// Retrieves the instance with the specified service type. - /// - /// - Parameter serviceType: The service type to resolve. - /// - /// - Returns: The resolved service type instance, or nil if no service is found. - func resolve(_ serviceType: Service.Type) -> Service? - - /// Retrieves the instance with the specified service type and registration name. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - name: The registration name. - /// - /// - Returns: The resolved service type instance, or nil if no service with the name is found. - func resolve(_ serviceType: Service.Type, name: String?) -> Service? - -<% (1..arg_count).each do |i| %> -<% arg_types = (1..i).map { |n| "Arg#{n}" }.join(", ") %> -<% arg_param = i == 1 ? "argument: Arg1" : "arguments arg1: Arg1, " + (2..i).map{ |n| "_ arg#{n}: Arg#{n}" }.join(", ") %> -<% arg_param_name = i == 1 ? "argument" : "arguments" %> -<% arg_param_description = i == 1 ? "#{i} argument" : "list of #{i} arguments" %> - /// Retrieves the instance with the specified service type and <%= arg_param_description %> to the factory closure. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - <%= arg_param_name %>: <%= arg_param_description.capitalize %> to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// and <%= arg_param_description %> is found. - func resolve>( - _ serviceType: Service.Type, - <%= arg_param %>) -> Service? - - /// Retrieves the instance with the specified service type, <%= arg_param_description %> to the factory closure and registration name. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - name: The registration name. - /// - <%= arg_param_name %>: <%= arg_param_description.capitalize %> to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type, - /// <%= arg_param_description %> and name is found. - func resolve>( - _ serviceType: Service.Type, - name: String?, - <%= arg_param %>) -> Service? - -<% end %> - -} diff --git a/Sources/Resolver.swift b/Sources/Resolver.swift deleted file mode 100644 index 8d9e3e69..00000000 --- a/Sources/Resolver.swift +++ /dev/null @@ -1,270 +0,0 @@ -// -// Resolver.swift -// Swinject -// -// Created by Yoichi Tagaya on 8/18/15. -// Copyright (c) 2015 Swinject Contributors. All rights reserved. -// - -// -// NOTICE: -// -// Resolver.swift is generated from Resolver.erb by ERB. -// Do NOT modify Resolver.swift directly. -// Instead, modify Resolver.erb and run `script/gencode` at the project root directory to generate the code. -// - - -public protocol Resolver { - /// Retrieves the instance with the specified service type. - /// - /// - Parameter serviceType: The service type to resolve. - /// - /// - Returns: The resolved service type instance, or nil if no service is found. - func resolve(_ serviceType: Service.Type) -> Service? - - /// Retrieves the instance with the specified service type and registration name. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - name: The registration name. - /// - /// - Returns: The resolved service type instance, or nil if no service with the name is found. - func resolve(_ serviceType: Service.Type, name: String?) -> Service? - - /// Retrieves the instance with the specified service type and 1 argument to the factory closure. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - argument: 1 argument to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// and 1 argument is found. - func resolve( - _ serviceType: Service.Type, - argument: Arg1) -> Service? - - /// Retrieves the instance with the specified service type, 1 argument to the factory closure and registration name. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - name: The registration name. - /// - argument: 1 argument to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type, - /// 1 argument and name is found. - func resolve( - _ serviceType: Service.Type, - name: String?, - argument: Arg1) -> Service? - - /// Retrieves the instance with the specified service type and list of 2 arguments to the factory closure. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - arguments: List of 2 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// and list of 2 arguments is found. - func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2) -> Service? - - /// Retrieves the instance with the specified service type, list of 2 arguments to the factory closure and registration name. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - name: The registration name. - /// - arguments: List of 2 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type, - /// list of 2 arguments and name is found. - func resolve( - _ serviceType: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2) -> Service? - - /// Retrieves the instance with the specified service type and list of 3 arguments to the factory closure. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - arguments: List of 3 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// and list of 3 arguments is found. - func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> Service? - - /// Retrieves the instance with the specified service type, list of 3 arguments to the factory closure and registration name. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - name: The registration name. - /// - arguments: List of 3 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type, - /// list of 3 arguments and name is found. - func resolve( - _ serviceType: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> Service? - - /// Retrieves the instance with the specified service type and list of 4 arguments to the factory closure. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - arguments: List of 4 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// and list of 4 arguments is found. - func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> Service? - - /// Retrieves the instance with the specified service type, list of 4 arguments to the factory closure and registration name. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - name: The registration name. - /// - arguments: List of 4 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type, - /// list of 4 arguments and name is found. - func resolve( - _ serviceType: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> Service? - - /// Retrieves the instance with the specified service type and list of 5 arguments to the factory closure. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - arguments: List of 5 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// and list of 5 arguments is found. - func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> Service? - - /// Retrieves the instance with the specified service type, list of 5 arguments to the factory closure and registration name. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - name: The registration name. - /// - arguments: List of 5 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type, - /// list of 5 arguments and name is found. - func resolve( - _ serviceType: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> Service? - - /// Retrieves the instance with the specified service type and list of 6 arguments to the factory closure. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - arguments: List of 6 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// and list of 6 arguments is found. - func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6) -> Service? - - /// Retrieves the instance with the specified service type, list of 6 arguments to the factory closure and registration name. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - name: The registration name. - /// - arguments: List of 6 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type, - /// list of 6 arguments and name is found. - func resolve( - _ serviceType: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6) -> Service? - - /// Retrieves the instance with the specified service type and list of 7 arguments to the factory closure. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - arguments: List of 7 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// and list of 7 arguments is found. - func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7) -> Service? - - /// Retrieves the instance with the specified service type, list of 7 arguments to the factory closure and registration name. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - name: The registration name. - /// - arguments: List of 7 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type, - /// list of 7 arguments and name is found. - func resolve( - _ serviceType: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7) -> Service? - - /// Retrieves the instance with the specified service type and list of 8 arguments to the factory closure. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - arguments: List of 8 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// and list of 8 arguments is found. - func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8) -> Service? - - /// Retrieves the instance with the specified service type, list of 8 arguments to the factory closure and registration name. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - name: The registration name. - /// - arguments: List of 8 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type, - /// list of 8 arguments and name is found. - func resolve( - _ serviceType: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8) -> Service? - - /// Retrieves the instance with the specified service type and list of 9 arguments to the factory closure. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - arguments: List of 9 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// and list of 9 arguments is found. - func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8, _ arg9: Arg9) -> Service? - - /// Retrieves the instance with the specified service type, list of 9 arguments to the factory closure and registration name. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - name: The registration name. - /// - arguments: List of 9 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type, - /// list of 9 arguments and name is found. - func resolve( - _ serviceType: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8, _ arg9: Arg9) -> Service? - - -} diff --git a/Sources/ServiceEntry.TypeForwarding.erb b/Sources/ServiceEntry.TypeForwarding.erb deleted file mode 100644 index 6ea81699..00000000 --- a/Sources/ServiceEntry.TypeForwarding.erb +++ /dev/null @@ -1,47 +0,0 @@ -// -// ServiceEntry.TypeForwarding.swift -// Swinject-iOS -// -// Created by Jakub Vaňo on 16/02/2018. -// Copyright © 2018 Swinject Contributors. All rights reserved. -// - -// -// NOTICE: -// -// ServiceEntry.TypeForwarding.swift is generated from ServiceEntry.TypeForwarding.erb by ERB. -// Do NOT modify ServiceEntry.TypeForwarding.swift directly. -// Instead, modify ServiceEntry.TypeForwarding.erb and run `script/gencode` at the project root directory to generate the code. -// - -<% type_count = 9 %> - -extension ServiceEntry { - /// Adds another type which should be resolved using this ServiceEntry - i.e. using the same object scope, - /// arguments and `initCompleted` closures - /// - /// - Parameters: - /// - type: Type resolution of which should be forwarded - /// - name: A registration name, which is used to differentiate from other registrations of the same `type` - @discardableResult - public func implements(_ type: T.Type, name: String? = nil) -> ServiceEntry { - container?.forward(type, name: name, to: self) - return self - } - -<% (2..type_count).each do |i| %> -<% types = (1..i).map { |n| "T#{n}" }.join(", ") %> -<% params = (1..i).map { |n| "_ type#{n}: T#{n}.Type"}.join(", ") %> - /// Adds multiple types which should be resolved using this ServiceEntry - i.e. using the same object scope, - /// arguments and `initCompleted` closures - /// - /// - Parameters: - /// - types: List of <%= i %> types resolution of which should be forwarded - @discardableResult - public func implements<<%= types %>>(<%= params %>) -> ServiceEntry { - return self<% (1..i).each do |k| %>.implements(type<%= k %>)<% end %> - - } - -<% end %> -} diff --git a/Sources/ServiceEntry.TypeForwarding.swift b/Sources/ServiceEntry.TypeForwarding.swift deleted file mode 100644 index a540d22f..00000000 --- a/Sources/ServiceEntry.TypeForwarding.swift +++ /dev/null @@ -1,111 +0,0 @@ -// -// ServiceEntry.TypeForwarding.swift -// Swinject-iOS -// -// Created by Jakub Vaňo on 16/02/2018. -// Copyright © 2018 Swinject Contributors. All rights reserved. -// - -// -// NOTICE: -// -// ServiceEntry.TypeForwarding.swift is generated from ServiceEntry.TypeForwarding.erb by ERB. -// Do NOT modify ServiceEntry.TypeForwarding.swift directly. -// Instead, modify ServiceEntry.TypeForwarding.erb and run `script/gencode` at the project root directory to generate the code. -// - - -extension ServiceEntry { - /// Adds another type which should be resolved using this ServiceEntry - i.e. using the same object scope, - /// arguments and `initCompleted` closures - /// - /// - Parameters: - /// - type: Type resolution of which should be forwarded - /// - name: A registration name, which is used to differentiate from other registrations of the same `type` - @discardableResult - public func implements(_ type: T.Type, name: String? = nil) -> ServiceEntry { - container?.forward(type, name: name, to: self) - return self - } - - /// Adds multiple types which should be resolved using this ServiceEntry - i.e. using the same object scope, - /// arguments and `initCompleted` closures - /// - /// - Parameters: - /// - types: List of 2 types resolution of which should be forwarded - @discardableResult - public func implements(_ type1: T1.Type, _ type2: T2.Type) -> ServiceEntry { - return self.implements(type1).implements(type2) - } - - /// Adds multiple types which should be resolved using this ServiceEntry - i.e. using the same object scope, - /// arguments and `initCompleted` closures - /// - /// - Parameters: - /// - types: List of 3 types resolution of which should be forwarded - @discardableResult - public func implements(_ type1: T1.Type, _ type2: T2.Type, _ type3: T3.Type) -> ServiceEntry { - return self.implements(type1).implements(type2).implements(type3) - } - - /// Adds multiple types which should be resolved using this ServiceEntry - i.e. using the same object scope, - /// arguments and `initCompleted` closures - /// - /// - Parameters: - /// - types: List of 4 types resolution of which should be forwarded - @discardableResult - public func implements(_ type1: T1.Type, _ type2: T2.Type, _ type3: T3.Type, _ type4: T4.Type) -> ServiceEntry { - return self.implements(type1).implements(type2).implements(type3).implements(type4) - } - - /// Adds multiple types which should be resolved using this ServiceEntry - i.e. using the same object scope, - /// arguments and `initCompleted` closures - /// - /// - Parameters: - /// - types: List of 5 types resolution of which should be forwarded - @discardableResult - public func implements(_ type1: T1.Type, _ type2: T2.Type, _ type3: T3.Type, _ type4: T4.Type, _ type5: T5.Type) -> ServiceEntry { - return self.implements(type1).implements(type2).implements(type3).implements(type4).implements(type5) - } - - /// Adds multiple types which should be resolved using this ServiceEntry - i.e. using the same object scope, - /// arguments and `initCompleted` closures - /// - /// - Parameters: - /// - types: List of 6 types resolution of which should be forwarded - @discardableResult - public func implements(_ type1: T1.Type, _ type2: T2.Type, _ type3: T3.Type, _ type4: T4.Type, _ type5: T5.Type, _ type6: T6.Type) -> ServiceEntry { - return self.implements(type1).implements(type2).implements(type3).implements(type4).implements(type5).implements(type6) - } - - /// Adds multiple types which should be resolved using this ServiceEntry - i.e. using the same object scope, - /// arguments and `initCompleted` closures - /// - /// - Parameters: - /// - types: List of 7 types resolution of which should be forwarded - @discardableResult - public func implements(_ type1: T1.Type, _ type2: T2.Type, _ type3: T3.Type, _ type4: T4.Type, _ type5: T5.Type, _ type6: T6.Type, _ type7: T7.Type) -> ServiceEntry { - return self.implements(type1).implements(type2).implements(type3).implements(type4).implements(type5).implements(type6).implements(type7) - } - - /// Adds multiple types which should be resolved using this ServiceEntry - i.e. using the same object scope, - /// arguments and `initCompleted` closures - /// - /// - Parameters: - /// - types: List of 8 types resolution of which should be forwarded - @discardableResult - public func implements(_ type1: T1.Type, _ type2: T2.Type, _ type3: T3.Type, _ type4: T4.Type, _ type5: T5.Type, _ type6: T6.Type, _ type7: T7.Type, _ type8: T8.Type) -> ServiceEntry { - return self.implements(type1).implements(type2).implements(type3).implements(type4).implements(type5).implements(type6).implements(type7).implements(type8) - } - - /// Adds multiple types which should be resolved using this ServiceEntry - i.e. using the same object scope, - /// arguments and `initCompleted` closures - /// - /// - Parameters: - /// - types: List of 9 types resolution of which should be forwarded - @discardableResult - public func implements(_ type1: T1.Type, _ type2: T2.Type, _ type3: T3.Type, _ type4: T4.Type, _ type5: T5.Type, _ type6: T6.Type, _ type7: T7.Type, _ type8: T8.Type, _ type9: T9.Type) -> ServiceEntry { - return self.implements(type1).implements(type2).implements(type3).implements(type4).implements(type5).implements(type6).implements(type7).implements(type8).implements(type9) - } - -} diff --git a/Sources/ServiceEntry.swift b/Sources/ServiceEntry.swift deleted file mode 100644 index 06375c57..00000000 --- a/Sources/ServiceEntry.swift +++ /dev/null @@ -1,105 +0,0 @@ -// -// ServiceEntry.swift -// Swinject -// -// Created by Yoichi Tagaya on 7/24/15. -// Copyright © 2015 Swinject Contributors. All rights reserved. -// - -import Foundation - -// A generic-type-free protocol to be the type of values in a strongly-typed collection. -internal protocol ServiceEntryProtocol: AnyObject { - func describeWithKey(_ serviceKey: ServiceKey) -> String - var objectScope: ObjectScopeProtocol { get } - var storage: InstanceStorage { get } - var factory: FunctionType { get } - var initCompleted: (FunctionType)? { get } - var serviceType: Any.Type { get } -} - -/// The `ServiceEntry` class represents an entry of a registered service type. -/// As a returned instance from a `register` method of a `Container`, some configurations can be added. -public final class ServiceEntry: ServiceEntryProtocol { - fileprivate var initCompletedActions: [(Resolver, Service) -> Void] = [] - internal let serviceType: Any.Type - internal let argumentsType: Any.Type - - internal let factory: FunctionType - internal weak var container: Container? - - internal var objectScope: ObjectScopeProtocol = ObjectScope.graph - internal lazy var storage: InstanceStorage = { [unowned self] in - self.objectScope.makeStorage() - }() - - internal var initCompleted: FunctionType? { - guard !initCompletedActions.isEmpty else { return nil } - - return {[weak self] (resolver: Resolver, service: Any) -> Void in - guard let strongSelf = self else { return } - strongSelf.initCompletedActions.forEach { $0(resolver, service as! Service) } - } - } - - internal init(serviceType: Service.Type, argumentsType: Any.Type, factory: FunctionType) { - self.serviceType = serviceType - self.argumentsType = argumentsType - self.factory = factory - } - - convenience internal init( - serviceType: Service.Type, - argumentsType: Any.Type, - factory: FunctionType, - objectScope: ObjectScope - ) { - self.init(serviceType: serviceType, argumentsType: argumentsType, factory: factory) - self.objectScope = objectScope - } - - /// Specifies the object scope to resolve the service. - /// - /// - Parameter scope: The `ObjectScopeProtocol` value. - /// - /// - Returns: `self` to add another configuration fluently. - @discardableResult - public func inObjectScope(_ objectScope: ObjectScopeProtocol) -> Self { - self.objectScope = objectScope - return self - } - - /// Specifies the object scope to resolve the service. - /// Performs the same functionality as `inObjectScope(_: ObjectScopeProtocol) -> Self`, - /// but provides more convenient usage syntax. - /// - /// - Parameter scope: The `ObjectScope` value. - /// - /// - Returns: `self` to add another configuration fluently. - @discardableResult - public func inObjectScope(_ objectScope: ObjectScope) -> Self { - return inObjectScope(objectScope as ObjectScopeProtocol) - } - - /// Adds the callback to setup the instance after its `init` completes. - /// *Property or method injections* can be performed in the callback. - /// To resolve *circular dependencies*, `initCompleted` must be used. - /// - /// - Parameter completed: The closure to be called after the instantiation of the registered service. - /// - /// - Returns: `self` to add another configuration fluently. - @discardableResult - public func initCompleted(_ completed: @escaping (Resolver, Service) -> Void) -> Self { - initCompletedActions.append(completed) - return self - } - - internal func describeWithKey(_ serviceKey: ServiceKey) -> String { - return description( - serviceType: serviceType, - serviceKey: serviceKey, - objectScope: objectScope, - initCompleted: initCompletedActions - ) - } -} diff --git a/Sources/ServiceKey.swift b/Sources/ServiceKey.swift deleted file mode 100644 index ab692e42..00000000 --- a/Sources/ServiceKey.swift +++ /dev/null @@ -1,61 +0,0 @@ -// -// ServiceKey.swift -// Swinject -// -// Created by Yoichi Tagaya on 7/23/15. -// Copyright © 2015 Swinject Contributors. All rights reserved. -// - -import Foundation - -// MARK: ServiceKeyOption -public protocol ServiceKeyOption: CustomStringConvertible { - func isEqualTo(_ another: ServiceKeyOption) -> Bool - var hashValue: Int { get } -} - -// MARK: - ServiceKey -internal struct ServiceKey { - internal let serviceType: Any.Type - internal let argumentsType: Any.Type - internal let name: String? - internal let option: ServiceKeyOption? // Used for SwinjectStoryboard or other extensions. - - internal init( - serviceType: Any.Type, - argumentsType: Any.Type, - name: String? = nil, - option: ServiceKeyOption? = nil - ) { - self.serviceType = serviceType - self.argumentsType = argumentsType - self.name = name - self.option = option - } -} - -// MARK: Hashable -extension ServiceKey: Hashable { - public func hash(into hasher: inout Hasher) { - hasher.combine(ObjectIdentifier(serviceType)) - hasher.combine(ObjectIdentifier(argumentsType)) - hasher.combine(name?.hashValue ?? 0) - hasher.combine(option?.hashValue ?? 0) - } -} - -// MARK: Equatable -func == (lhs: ServiceKey, rhs: ServiceKey) -> Bool { - return lhs.serviceType == rhs.serviceType - && lhs.argumentsType == rhs.argumentsType - && lhs.name == rhs.name - && equalOptions(opt1: lhs.option, opt2: rhs.option) -} - -private func equalOptions(opt1: ServiceKeyOption?, opt2: ServiceKeyOption?) -> Bool { - switch (opt1, opt2) { - case let (opt1?, opt2?): return opt1.isEqualTo(opt2) - case (nil, nil): return true - default: return false - } -} diff --git a/Sources/SpinLock.swift b/Sources/SpinLock.swift deleted file mode 100644 index a9d1427c..00000000 --- a/Sources/SpinLock.swift +++ /dev/null @@ -1,19 +0,0 @@ -// -// SpinLock.swift -// Swinject -// -// Created by Yoichi Tagaya on 11/26/15. -// Copyright © 2015 Swinject Contributors. All rights reserved. -// - -import Foundation - -internal final class SpinLock { - private let lock = NSRecursiveLock() - - func sync(action: () -> T) -> T { - lock.lock() - defer { lock.unlock() } - return action() - } -} diff --git a/Sources/Swinject.h b/Sources/Swinject.h index edc80b4d..2cf2b0d0 100644 --- a/Sources/Swinject.h +++ b/Sources/Swinject.h @@ -2,8 +2,8 @@ // Swinject.h // Swinject // -// Created by Yoichi Tagaya on 7/22/15. -// Copyright © 2015 Swinject Contributors. All rights reserved. +// Created by Jakub Vano on 10/07/2019. +// Copyright © 2019 Swinject Contributors. All rights reserved. // #import @@ -15,3 +15,5 @@ FOUNDATION_EXPORT double SwinjectVersionNumber; FOUNDATION_EXPORT const unsigned char SwinjectVersionString[]; // In this header, you should import all the public headers of your framework using statements like #import + + diff --git a/Sources/SynchronizedResolver.Arguments.erb b/Sources/SynchronizedResolver.Arguments.erb deleted file mode 100644 index 840aa80f..00000000 --- a/Sources/SynchronizedResolver.Arguments.erb +++ /dev/null @@ -1,46 +0,0 @@ -// -// SynchronizedResolver.Arguments.swift -// Swinject -// -// Created by Yoichi Tagaya on 11/23/15. -// Copyright © 2015 Swinject Contributors. All rights reserved. -// - -// -// NOTICE: -// -// SynchronizedResolver.Arguments.swift is generated from SynchronizedResolver.Arguments.erb by ERB. -// Do NOT modify SynchronizedResolver.Arguments.swift directly. -// Instead, modify SynchronizedResolver.Arguments.erb and run `script/gencode` at the project root directory to generate the code. -// - -<% arg_count = 9 %> - -// MARK: - Resolver with Arguments -extension SynchronizedResolver { -<% (1..arg_count).each do |i| %> -<% arg_types = (1..i).map { |n| "Arg#{n}" }.join(", ") %> -<% arg_param_name = i == 1 ? "argument" : "arguments" %> -<% arg_param_def = i == 1 ? "argument: Arg1" : "arguments arg1: Arg1, " + (2..i).map{ |n| "_ arg#{n}: Arg#{n}" }.join(", ") %> -<% arg_param_call = i == 1 ? "argument" : (1..i).map{ |n| "arg#{n}" }.join(", ") %> - internal func resolve>( - _ serviceType: Service.Type, - <%= arg_param_def %>) -> Service? - { - return container.lock.sync { - return self.container.resolve(serviceType, <%= arg_param_name %>: <%= arg_param_call %>) - } - } - - internal func resolve>( - _ serviceType: Service.Type, - name: String?, - <%= arg_param_def %>) -> Service? - { - return container.lock.sync { - return self.container.resolve(serviceType, name: name, <%= arg_param_name %>: <%= arg_param_call %>) - } - } - -<% end %> -} diff --git a/Sources/SynchronizedResolver.Arguments.swift b/Sources/SynchronizedResolver.Arguments.swift deleted file mode 100644 index 0f435751..00000000 --- a/Sources/SynchronizedResolver.Arguments.swift +++ /dev/null @@ -1,191 +0,0 @@ -// -// SynchronizedResolver.Arguments.swift -// Swinject -// -// Created by Yoichi Tagaya on 11/23/15. -// Copyright © 2015 Swinject Contributors. All rights reserved. -// - -// -// NOTICE: -// -// SynchronizedResolver.Arguments.swift is generated from SynchronizedResolver.Arguments.erb by ERB. -// Do NOT modify SynchronizedResolver.Arguments.swift directly. -// Instead, modify SynchronizedResolver.Arguments.erb and run `script/gencode` at the project root directory to generate the code. -// - - -// MARK: - Resolver with Arguments -extension SynchronizedResolver { - internal func resolve( - _ serviceType: Service.Type, - argument: Arg1) -> Service? - { - return container.lock.sync { - return self.container.resolve(serviceType, argument: argument) - } - } - - internal func resolve( - _ serviceType: Service.Type, - name: String?, - argument: Arg1) -> Service? - { - return container.lock.sync { - return self.container.resolve(serviceType, name: name, argument: argument) - } - } - - internal func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2) -> Service? - { - return container.lock.sync { - return self.container.resolve(serviceType, arguments: arg1, arg2) - } - } - - internal func resolve( - _ serviceType: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2) -> Service? - { - return container.lock.sync { - return self.container.resolve(serviceType, name: name, arguments: arg1, arg2) - } - } - - internal func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> Service? - { - return container.lock.sync { - return self.container.resolve(serviceType, arguments: arg1, arg2, arg3) - } - } - - internal func resolve( - _ serviceType: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> Service? - { - return container.lock.sync { - return self.container.resolve(serviceType, name: name, arguments: arg1, arg2, arg3) - } - } - - internal func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> Service? - { - return container.lock.sync { - return self.container.resolve(serviceType, arguments: arg1, arg2, arg3, arg4) - } - } - - internal func resolve( - _ serviceType: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> Service? - { - return container.lock.sync { - return self.container.resolve(serviceType, name: name, arguments: arg1, arg2, arg3, arg4) - } - } - - internal func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> Service? - { - return container.lock.sync { - return self.container.resolve(serviceType, arguments: arg1, arg2, arg3, arg4, arg5) - } - } - - internal func resolve( - _ serviceType: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> Service? - { - return container.lock.sync { - return self.container.resolve(serviceType, name: name, arguments: arg1, arg2, arg3, arg4, arg5) - } - } - - internal func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6) -> Service? - { - return container.lock.sync { - return self.container.resolve(serviceType, arguments: arg1, arg2, arg3, arg4, arg5, arg6) - } - } - - internal func resolve( - _ serviceType: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6) -> Service? - { - return container.lock.sync { - return self.container.resolve(serviceType, name: name, arguments: arg1, arg2, arg3, arg4, arg5, arg6) - } - } - - internal func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7) -> Service? - { - return container.lock.sync { - return self.container.resolve(serviceType, arguments: arg1, arg2, arg3, arg4, arg5, arg6, arg7) - } - } - - internal func resolve( - _ serviceType: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7) -> Service? - { - return container.lock.sync { - return self.container.resolve(serviceType, name: name, arguments: arg1, arg2, arg3, arg4, arg5, arg6, arg7) - } - } - - internal func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8) -> Service? - { - return container.lock.sync { - return self.container.resolve(serviceType, arguments: arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) - } - } - - internal func resolve( - _ serviceType: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8) -> Service? - { - return container.lock.sync { - return self.container.resolve(serviceType, name: name, arguments: arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) - } - } - - internal func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8, _ arg9: Arg9) -> Service? - { - return container.lock.sync { - return self.container.resolve(serviceType, arguments: arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - } - } - - internal func resolve( - _ serviceType: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8, _ arg9: Arg9) -> Service? - { - return container.lock.sync { - return self.container.resolve(serviceType, name: name, arguments: arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - } - } - -} diff --git a/Sources/SynchronizedResolver.swift b/Sources/SynchronizedResolver.swift deleted file mode 100644 index 6a628da6..00000000 --- a/Sources/SynchronizedResolver.swift +++ /dev/null @@ -1,42 +0,0 @@ -// -// SynchronizedResolver.swift -// Swinject -// -// Created by Yoichi Tagaya on 11/23/15. -// Copyright © 2015 Swinject Contributors. All rights reserved. -// - -internal final class SynchronizedResolver { - internal let container: Container - - internal init(container: Container) { - self.container = container - } -} - -extension SynchronizedResolver: _Resolver { - // swiftlint:disable:next identifier_name - internal func _resolve( - name: String?, - option: ServiceKeyOption?, - invoker: @escaping ((Arguments) -> Any) -> Any - ) -> Service? { - return container.lock.sync { - return self.container._resolve(name: name, option: option, invoker: invoker) - } - } -} - -extension SynchronizedResolver: Resolver { - internal func resolve(_ serviceType: Service.Type) -> Service? { - return container.lock.sync { - return self.container.resolve(serviceType) - } - } - - internal func resolve(_ serviceType: Service.Type, name: String?) -> Service? { - return container.lock.sync { - return self.container.resolve(serviceType, name: name) - } - } -} diff --git a/Sources/UnavailableItems.swift b/Sources/UnavailableItems.swift deleted file mode 100644 index b24ecdac..00000000 --- a/Sources/UnavailableItems.swift +++ /dev/null @@ -1,25 +0,0 @@ -// -// UnavailableItems.swift -// Swinject -// -// Created by Yoichi Tagaya on 11/30/16. -// Copyright © 2016 Swinject Contributors. All rights reserved. -// - -// MARK: For auto migration from Swinject v1 to v2. -extension ObjectScope { - @available(*, unavailable, renamed: "transient") - public static let none = transient - - @available(*, unavailable, renamed: "container") - public static let hierarchy = container -} - -@available(*, unavailable, renamed: "Resolver") -public protocol ResolverType { } - -@available(*, unavailable, renamed: "Assembly") -public protocol AssemblyType { } - -@available(*, unavailable, renamed: "ServiceKeyOption") -public protocol ServiceKeyOptionType { } diff --git a/Sources/_Resolver.swift b/Sources/_Resolver.swift deleted file mode 100644 index 3d19fb88..00000000 --- a/Sources/_Resolver.swift +++ /dev/null @@ -1,28 +0,0 @@ -// -// _Resolver.swift -// Swinject -// -// Created by Yoichi Tagaya on 5/4/16. -// Copyright © 2016 Swinject Contributors. All rights reserved. -// - -/// This protocol is designed for the use to extend Swinject functionality. -/// Do NOT use this protocol unless you intend to write an extension or plugin to Swinject framework. -/// -/// A type conforming Resolver protocol must conform _Resolver protocol too. -public protocol _Resolver { - /// This method is designed for the use to extend Swinject functionality. - /// Do NOT use this method unless you intend to write an extension or plugin to Swinject framework. - /// - /// - Parameter name: The registration name. - /// - Parameter option: A service key option for an extension/plugin. - /// - Parameter invoker: A closure to execute service resolution. - /// - /// - Returns: The resolved service type instance, or nil if no service is found. - // swiftlint:disable:next identifier_name - func _resolve( - name: String?, - option: ServiceKeyOption?, - invoker: @escaping ((Arguments) -> Any) -> Any - ) -> Service? -} diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 03a9f4a6..b808169c 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -3,900 +3,209 @@ archiveVersion = 1; classes = { }; - objectVersion = 46; + objectVersion = 52; objects = { /* Begin PBXBuildFile section */ - 90B029751C18599200A6A521 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90B029741C18599200A6A521 /* Assembly.swift */; }; - 90B029761C18599200A6A521 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90B029741C18599200A6A521 /* Assembly.swift */; }; - 90B029771C18599200A6A521 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90B029741C18599200A6A521 /* Assembly.swift */; }; - 90B029791C185B1600A6A521 /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90B029781C185B1600A6A521 /* Assembler.swift */; }; - 90B0297A1C185B1600A6A521 /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90B029781C185B1600A6A521 /* Assembler.swift */; }; - 90B0297B1C185B1600A6A521 /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90B029781C185B1600A6A521 /* Assembler.swift */; }; - 90B0297C1C185B1600A6A521 /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90B029781C185B1600A6A521 /* Assembler.swift */; }; - 90B0297D1C185B2200A6A521 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90B029741C18599200A6A521 /* Assembly.swift */; }; - 90B0297F1C18666200A6A521 /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90B0297E1C18666200A6A521 /* AssemblerSpec.swift */; }; - 90B029801C18666200A6A521 /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90B0297E1C18666200A6A521 /* AssemblerSpec.swift */; }; - 90B029811C18666200A6A521 /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90B0297E1C18666200A6A521 /* AssemblerSpec.swift */; }; - 90B029831C18670000A6A521 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90B029821C18670000A6A521 /* BasicAssembly.swift */; }; - 90B029841C18670000A6A521 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90B029821C18670000A6A521 /* BasicAssembly.swift */; }; - 90B029851C18670000A6A521 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90B029821C18670000A6A521 /* BasicAssembly.swift */; }; - 90B0298B1C186D5300A6A521 /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90B0298A1C186D5300A6A521 /* LoadAwareAssembly.swift */; }; - 90B0298C1C186D5300A6A521 /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90B0298A1C186D5300A6A521 /* LoadAwareAssembly.swift */; }; - 90B0298D1C186D5300A6A521 /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90B0298A1C186D5300A6A521 /* LoadAwareAssembly.swift */; }; - 981577F11B675B7F00BF686B /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 981577F01B675B7F00BF686B /* Circularity.swift */; }; - 981577F21B675B7F00BF686B /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 981577F01B675B7F00BF686B /* Circularity.swift */; }; - 981899C61B5FE63F00C702D0 /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 981899BC1B5FE63F00C702D0 /* Swinject.framework */; }; - 981899E11B5FF88800C702D0 /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 981899E01B5FF88800C702D0 /* ContainerSpec.swift */; }; - 981899E21B5FF88800C702D0 /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 981899E01B5FF88800C702D0 /* ContainerSpec.swift */; }; - 981899E41B5FFE5800C702D0 /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 981899E31B5FFE5800C702D0 /* Container.swift */; }; - 981899E51B5FFE5800C702D0 /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 981899E31B5FFE5800C702D0 /* Container.swift */; }; - 9819701F1B6145D600EEB942 /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9819701E1B6145D600EEB942 /* ObjectScope.swift */; }; - 981970201B6145D600EEB942 /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9819701E1B6145D600EEB942 /* ObjectScope.swift */; }; - 981ABE8C1B5FC9DF00294975 /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 981ABE811B5FC9DF00294975 /* Swinject.framework */; }; - 983B98311C06ECB2006A23D4 /* SpinLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 983B98301C06ECB2006A23D4 /* SpinLock.swift */; }; - 983B98321C06ECB2006A23D4 /* SpinLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 983B98301C06ECB2006A23D4 /* SpinLock.swift */; }; - 983B98331C06ECB2006A23D4 /* SpinLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 983B98301C06ECB2006A23D4 /* SpinLock.swift */; }; - 983B98341C06ECB2006A23D4 /* SpinLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 983B98301C06ECB2006A23D4 /* SpinLock.swift */; }; - 984774F01C02F25D0092A757 /* SynchronizedResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 984774EF1C02F25D0092A757 /* SynchronizedResolver.swift */; }; - 984774F11C02F25D0092A757 /* SynchronizedResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 984774EF1C02F25D0092A757 /* SynchronizedResolver.swift */; }; - 984774F21C02F25D0092A757 /* SynchronizedResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 984774EF1C02F25D0092A757 /* SynchronizedResolver.swift */; }; - 984774F31C02F25D0092A757 /* SynchronizedResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 984774EF1C02F25D0092A757 /* SynchronizedResolver.swift */; }; - 984774FA1C02F5A50092A757 /* SynchronizedResolver.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 984774F91C02F5A50092A757 /* SynchronizedResolver.Arguments.swift */; }; - 984774FB1C02F5A50092A757 /* SynchronizedResolver.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 984774F91C02F5A50092A757 /* SynchronizedResolver.Arguments.swift */; }; - 984774FC1C02F5A50092A757 /* SynchronizedResolver.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 984774F91C02F5A50092A757 /* SynchronizedResolver.Arguments.swift */; }; - 984774FD1C02F5A50092A757 /* SynchronizedResolver.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 984774F91C02F5A50092A757 /* SynchronizedResolver.Arguments.swift */; }; - 984774FF1C034C5C0092A757 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 984774FE1C034C5C0092A757 /* SynchronizedResolverSpec.swift */; }; - 984775001C034C5C0092A757 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 984774FE1C034C5C0092A757 /* SynchronizedResolverSpec.swift */; }; - 984775011C034C5C0092A757 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 984774FE1C034C5C0092A757 /* SynchronizedResolverSpec.swift */; }; - 9848611C1B6F9B7000C07072 /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9848611B1B6F9B7000C07072 /* ContainerSpec.Arguments.swift */; }; - 9848611D1B6F9B7000C07072 /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9848611B1B6F9B7000C07072 /* ContainerSpec.Arguments.swift */; }; - 984BE3131CDA3FCF00BCF2AC /* _Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 984BE3121CDA3FCF00BCF2AC /* _Resolver.swift */; }; - 984BE3141CDA3FCF00BCF2AC /* _Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 984BE3121CDA3FCF00BCF2AC /* _Resolver.swift */; }; - 984BE3151CDA3FCF00BCF2AC /* _Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 984BE3121CDA3FCF00BCF2AC /* _Resolver.swift */; }; - 984BE3161CDA3FCF00BCF2AC /* _Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 984BE3121CDA3FCF00BCF2AC /* _Resolver.swift */; }; - 984E8A521C317AC90039943D /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 984E8A511C317AC90039943D /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 984E8A531C317AC90039943D /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 984E8A511C317AC90039943D /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 984E8A541C317AC90039943D /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 984E8A511C317AC90039943D /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 984E8A551C317AC90039943D /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 984E8A511C317AC90039943D /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 9850111E1BBE7E8900A2CCFC /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 981899E31B5FFE5800C702D0 /* Container.swift */; }; - 9850111F1BBE7E8900A2CCFC /* ServiceKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9884E2A61B60B77400120259 /* ServiceKey.swift */; }; - 985011201BBE7E8900A2CCFC /* ServiceEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 985BAFA81B625E0F0055F998 /* ServiceEntry.swift */; }; - 985011221BBE7E8900A2CCFC /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9819701E1B6145D600EEB942 /* ObjectScope.swift */; }; - 985011241BBE7E8900A2CCFC /* Container.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98B012B71B82D67300053A32 /* Container.Arguments.swift */; }; - 985011251BBE7E8900A2CCFC /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98B012BE1B82F68E00053A32 /* Resolver.swift */; }; - 9855C5BF1B686F5900DADB0B /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9855C5BE1B686F5900DADB0B /* ContainerSpec.Circularity.swift */; }; - 9855C5C01B686F5900DADB0B /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9855C5BE1B686F5900DADB0B /* ContainerSpec.Circularity.swift */; }; - 9855C5C51B689B7B00DADB0B /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9855C5C41B689B7B00DADB0B /* Food.swift */; }; - 9855C5C61B689B7B00DADB0B /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9855C5C41B689B7B00DADB0B /* Food.swift */; }; - 9855C5C81B689D9000DADB0B /* ServiceEntrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9855C5C71B689D9000DADB0B /* ServiceEntrySpec.swift */; }; - 9855C5C91B689D9000DADB0B /* ServiceEntrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9855C5C71B689D9000DADB0B /* ServiceEntrySpec.swift */; }; - 985BAFA91B625E0F0055F998 /* ServiceEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 985BAFA81B625E0F0055F998 /* ServiceEntry.swift */; }; - 985BAFAA1B625E0F0055F998 /* ServiceEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 985BAFA81B625E0F0055F998 /* ServiceEntry.swift */; }; - 98689C991BBFC7EB0005C6D3 /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 981899E31B5FFE5800C702D0 /* Container.swift */; }; - 98689C9A1BBFC7EB0005C6D3 /* ServiceKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9884E2A61B60B77400120259 /* ServiceKey.swift */; }; - 98689C9B1BBFC7EB0005C6D3 /* ServiceEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 985BAFA81B625E0F0055F998 /* ServiceEntry.swift */; }; - 98689C9D1BBFC7EB0005C6D3 /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9819701E1B6145D600EEB942 /* ObjectScope.swift */; }; - 98689C9F1BBFC7EB0005C6D3 /* Container.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98B012B71B82D67300053A32 /* Container.Arguments.swift */; }; - 98689CA01BBFC7EB0005C6D3 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98B012BE1B82F68E00053A32 /* Resolver.swift */; }; - 98689CB61BBFD5110005C6D3 /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9878C63B1B65CA8700CBEFEF /* Person.swift */; }; - 98689CB71BBFD5110005C6D3 /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9878C6371B65C9E000CBEFEF /* Animal.swift */; }; - 98689CB81BBFD5110005C6D3 /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9855C5C41B689B7B00DADB0B /* Food.swift */; }; - 98689CB91BBFD5110005C6D3 /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 981577F01B675B7F00BF686B /* Circularity.swift */; }; - 98689CBA1BBFD5110005C6D3 /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 981899E01B5FF88800C702D0 /* ContainerSpec.swift */; }; - 98689CBB1BBFD5110005C6D3 /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9848611B1B6F9B7000C07072 /* ContainerSpec.Arguments.swift */; }; - 98689CBC1BBFD5110005C6D3 /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9855C5BE1B686F5900DADB0B /* ContainerSpec.Circularity.swift */; }; - 98689CBD1BBFD5110005C6D3 /* ServiceKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9884E2A91B60C51C00120259 /* ServiceKeySpec.swift */; }; - 98689CBE1BBFD5110005C6D3 /* ServiceEntrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9855C5C71B689D9000DADB0B /* ServiceEntrySpec.swift */; }; - 98689CD51BBFDEBC0005C6D3 /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 98689C7F1BBFC7A50005C6D3 /* Swinject.framework */; }; - 9878C6381B65C9E000CBEFEF /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9878C6371B65C9E000CBEFEF /* Animal.swift */; }; - 9878C6391B65C9E000CBEFEF /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9878C6371B65C9E000CBEFEF /* Animal.swift */; }; - 9878C63C1B65CA8700CBEFEF /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9878C63B1B65CA8700CBEFEF /* Person.swift */; }; - 9878C63D1B65CA8700CBEFEF /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9878C63B1B65CA8700CBEFEF /* Person.swift */; }; - 9880E70E1C09EE2900ED5293 /* FunctionType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9880E70D1C09EE2800ED5293 /* FunctionType.swift */; }; - 9880E70F1C09EE2900ED5293 /* FunctionType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9880E70D1C09EE2800ED5293 /* FunctionType.swift */; }; - 9880E7101C09EE2900ED5293 /* FunctionType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9880E70D1C09EE2800ED5293 /* FunctionType.swift */; }; - 9880E7111C09EE2900ED5293 /* FunctionType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9880E70D1C09EE2800ED5293 /* FunctionType.swift */; }; - 9884E2A71B60B77400120259 /* ServiceKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9884E2A61B60B77400120259 /* ServiceKey.swift */; }; - 9884E2A81B60B77400120259 /* ServiceKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9884E2A61B60B77400120259 /* ServiceKey.swift */; }; - 9884E2AA1B60C51C00120259 /* ServiceKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9884E2A91B60C51C00120259 /* ServiceKeySpec.swift */; }; - 9884E2AB1B60C51C00120259 /* ServiceKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9884E2A91B60C51C00120259 /* ServiceKeySpec.swift */; }; - 98B012B81B82D67300053A32 /* Container.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98B012B71B82D67300053A32 /* Container.Arguments.swift */; }; - 98B012B91B82D67300053A32 /* Container.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98B012B71B82D67300053A32 /* Container.Arguments.swift */; }; - 98B012BF1B82F68E00053A32 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98B012BE1B82F68E00053A32 /* Resolver.swift */; }; - 98B012C01B82F68E00053A32 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98B012BE1B82F68E00053A32 /* Resolver.swift */; }; - 98E550C31DEF066300BE6304 /* UnavailableItems.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98E550C21DEF066300BE6304 /* UnavailableItems.swift */; }; - CD3B32921DD6121500B208A3 /* InstanceStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD3B32911DD6121500B208A3 /* InstanceStorage.swift */; }; - CD3B32931DD6123F00B208A3 /* InstanceStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD3B32911DD6121500B208A3 /* InstanceStorage.swift */; }; - CD3B32941DD6123F00B208A3 /* InstanceStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD3B32911DD6121500B208A3 /* InstanceStorage.swift */; }; - CD3B32951DD6124000B208A3 /* InstanceStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD3B32911DD6121500B208A3 /* InstanceStorage.swift */; }; - CD3B32971DD6126E00B208A3 /* ObjectScope.Standard.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD3B32961DD6126E00B208A3 /* ObjectScope.Standard.swift */; }; - CD3B32981DD6126E00B208A3 /* ObjectScope.Standard.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD3B32961DD6126E00B208A3 /* ObjectScope.Standard.swift */; }; - CD3B32991DD6126E00B208A3 /* ObjectScope.Standard.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD3B32961DD6126E00B208A3 /* ObjectScope.Standard.swift */; }; - CD3B329A1DD6126E00B208A3 /* ObjectScope.Standard.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD3B32961DD6126E00B208A3 /* ObjectScope.Standard.swift */; }; - CD3B329C1DD61F2400B208A3 /* ContainerSpec.CustomScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD3B329B1DD61F2400B208A3 /* ContainerSpec.CustomScope.swift */; }; - CD3B329D1DD61F2400B208A3 /* ContainerSpec.CustomScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD3B329B1DD61F2400B208A3 /* ContainerSpec.CustomScope.swift */; }; - CD3B329E1DD61F2400B208A3 /* ContainerSpec.CustomScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD3B329B1DD61F2400B208A3 /* ContainerSpec.CustomScope.swift */; }; - CD3C2CDF1D98E47000863421 /* DebugHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD3C2CDE1D98E47000863421 /* DebugHelper.swift */; }; - CD3C2CE01D98E47000863421 /* DebugHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD3C2CDE1D98E47000863421 /* DebugHelper.swift */; }; - CD3C2CE11D98E47000863421 /* DebugHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD3C2CDE1D98E47000863421 /* DebugHelper.swift */; }; - CD3C2CE21D98E47000863421 /* DebugHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD3C2CDE1D98E47000863421 /* DebugHelper.swift */; }; - CD3C2CF21D98EF4A00863421 /* ContainerSpec.DebugHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD3C2CF11D98EF4A00863421 /* ContainerSpec.DebugHelper.swift */; }; - CD3C2CF31D98EF4A00863421 /* ContainerSpec.DebugHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD3C2CF11D98EF4A00863421 /* ContainerSpec.DebugHelper.swift */; }; - CD3C2CF41D98EF4A00863421 /* ContainerSpec.DebugHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD3C2CF11D98EF4A00863421 /* ContainerSpec.DebugHelper.swift */; }; - CD5E9A32205157E3009090F9 /* ContainerSpec.GraphCaching.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD5E9A31205157E3009090F9 /* ContainerSpec.GraphCaching.swift */; }; - CD5E9A33205157E3009090F9 /* ContainerSpec.GraphCaching.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD5E9A31205157E3009090F9 /* ContainerSpec.GraphCaching.swift */; }; - CD5E9A34205157E3009090F9 /* ContainerSpec.GraphCaching.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD5E9A31205157E3009090F9 /* ContainerSpec.GraphCaching.swift */; }; - CD5E9A3620515898009090F9 /* GraphIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD5E9A3520515898009090F9 /* GraphIdentifier.swift */; }; - CD5E9A3720515898009090F9 /* GraphIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD5E9A3520515898009090F9 /* GraphIdentifier.swift */; }; - CD5E9A3820515898009090F9 /* GraphIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD5E9A3520515898009090F9 /* GraphIdentifier.swift */; }; - CD5E9A3920515898009090F9 /* GraphIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD5E9A3520515898009090F9 /* GraphIdentifier.swift */; }; - CD65F049205943D400FB43EE /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD65F048205943D400FB43EE /* EmploymentAssembly.swift */; }; - CD65F04A205943D400FB43EE /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD65F048205943D400FB43EE /* EmploymentAssembly.swift */; }; - CD65F04B205943D400FB43EE /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD65F048205943D400FB43EE /* EmploymentAssembly.swift */; }; - CD6A9F821EEFCB7A0087E851 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6A9F811EEFCB7A0087E851 /* ContainerSpec.CustomStringConvertible.swift */; }; - CD6A9F831EEFCB7A0087E851 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6A9F811EEFCB7A0087E851 /* ContainerSpec.CustomStringConvertible.swift */; }; - CD6A9F841EEFCB7A0087E851 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6A9F811EEFCB7A0087E851 /* ContainerSpec.CustomStringConvertible.swift */; }; - CD89E3472036F28300A9ED33 /* ServiceEntry.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD89E3462036F28300A9ED33 /* ServiceEntry.TypeForwarding.swift */; }; - CD89E3492036F2BE00A9ED33 /* ServiceEntry.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD89E3462036F28300A9ED33 /* ServiceEntry.TypeForwarding.swift */; }; - CD89E34A2036F2BF00A9ED33 /* ServiceEntry.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD89E3462036F28300A9ED33 /* ServiceEntry.TypeForwarding.swift */; }; - CD89E34B2036F2C000A9ED33 /* ServiceEntry.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD89E3462036F28300A9ED33 /* ServiceEntry.TypeForwarding.swift */; }; - CD89E34D2037016700A9ED33 /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD89E34C2037016700A9ED33 /* Behavior.swift */; }; - CD89E34E20371C0100A9ED33 /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD89E34C2037016700A9ED33 /* Behavior.swift */; }; - CD89E34F20371C0200A9ED33 /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD89E34C2037016700A9ED33 /* Behavior.swift */; }; - CD89E35020371C0200A9ED33 /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD89E34C2037016700A9ED33 /* Behavior.swift */; }; - CD89E35220371D7900A9ED33 /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD89E35120371D7900A9ED33 /* ContainerSpec.Behavior.swift */; }; - CD89E35320371D7900A9ED33 /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD89E35120371D7900A9ED33 /* ContainerSpec.Behavior.swift */; }; - CD89E35420371D7900A9ED33 /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD89E35120371D7900A9ED33 /* ContainerSpec.Behavior.swift */; }; - CD8E362C20595ACD00F2A5CF /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD8E362B20595ACD00F2A5CF /* ProviderSpec.swift */; }; - CD8E362D20595ACD00F2A5CF /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD8E362B20595ACD00F2A5CF /* ProviderSpec.swift */; }; - CD8E362E20595ACD00F2A5CF /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD8E362B20595ACD00F2A5CF /* ProviderSpec.swift */; }; - CDB19E52204ED97400D67123 /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDB19E51204ED97400D67123 /* BehaviorFakes.swift */; }; - CDB19E53204ED97400D67123 /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDB19E51204ED97400D67123 /* BehaviorFakes.swift */; }; - CDB19E54204ED97400D67123 /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDB19E51204ED97400D67123 /* BehaviorFakes.swift */; }; - CDBBACF61D9EAD60002F5EF9 /* Container.Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDBBACF51D9EAD60002F5EF9 /* Container.Logging.swift */; }; - CDBBACF71D9EAD60002F5EF9 /* Container.Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDBBACF51D9EAD60002F5EF9 /* Container.Logging.swift */; }; - CDBBACF81D9EAD60002F5EF9 /* Container.Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDBBACF51D9EAD60002F5EF9 /* Container.Logging.swift */; }; - CDBBACF91D9EAD60002F5EF9 /* Container.Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDBBACF51D9EAD60002F5EF9 /* Container.Logging.swift */; }; - CDBD0E682035EDF20030F566 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDBD0E672035EDF20030F566 /* ContainerSpec.TypeForwarding.swift */; }; - CDBD0E692035EDF20030F566 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDBD0E672035EDF20030F566 /* ContainerSpec.TypeForwarding.swift */; }; - CDBD0E6A2035EDF20030F566 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDBD0E672035EDF20030F566 /* ContainerSpec.TypeForwarding.swift */; }; - CDBD0E6F2035EEBF0030F566 /* Container.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDBD0E6B2035EEBB0030F566 /* Container.TypeForwarding.swift */; }; - CDBD0E702035EEC00030F566 /* Container.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDBD0E6B2035EEBB0030F566 /* Container.TypeForwarding.swift */; }; - CDBD0E712035EEC20030F566 /* Container.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDBD0E6B2035EEBB0030F566 /* Container.TypeForwarding.swift */; }; - CDBD0E722035EEC20030F566 /* Container.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDBD0E6B2035EEBB0030F566 /* Container.TypeForwarding.swift */; }; - CDC4FCF4205028B00021C60F /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDC4FCF3205028B00021C60F /* InstanceWrapper.swift */; }; - CDC4FCF5205028B00021C60F /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDC4FCF3205028B00021C60F /* InstanceWrapper.swift */; }; - CDC4FCF6205028B00021C60F /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDC4FCF3205028B00021C60F /* InstanceWrapper.swift */; }; - CDC4FCF7205028B00021C60F /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDC4FCF3205028B00021C60F /* InstanceWrapper.swift */; }; - CDC4FCFD20502A9F0021C60F /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDC4FCF820502A9A0021C60F /* LazySpec.swift */; }; - CDC4FCFE20502AA00021C60F /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDC4FCF820502A9A0021C60F /* LazySpec.swift */; }; - CDC4FCFF20502AA10021C60F /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDC4FCF820502A9A0021C60F /* LazySpec.swift */; }; - CDD44AD71DEEED1000916595 /* WeakStorageSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD44AD61DEEED1000916595 /* WeakStorageSpec.swift */; }; - CDD44AD81DEEED1000916595 /* WeakStorageSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD44AD61DEEED1000916595 /* WeakStorageSpec.swift */; }; - CDD44AD91DEEED1000916595 /* WeakStorageSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD44AD61DEEED1000916595 /* WeakStorageSpec.swift */; }; - FF15F7831EDCE81B00F96686 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FF15F77F1EDCE81600F96686 /* Nimble.framework */; }; - FF15F7841EDCE81B00F96686 /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FF15F7801EDCE81600F96686 /* Quick.framework */; }; - FF15F7871EDCE82600F96686 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FF15F7851EDCE82600F96686 /* Nimble.framework */; }; - FF15F7881EDCE82600F96686 /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FF15F7861EDCE82600F96686 /* Quick.framework */; }; - FF15F78B1EDCE83100F96686 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FF15F7891EDCE83100F96686 /* Nimble.framework */; }; - FF15F78C1EDCE83100F96686 /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FF15F78A1EDCE83100F96686 /* Quick.framework */; }; - FF15F7901EDD99DB00F96686 /* Nimble.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = FF15F77F1EDCE81600F96686 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - FF15F7911EDD99DB00F96686 /* Quick.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = FF15F7801EDCE81600F96686 /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - FF15F7961EDD9A1900F96686 /* Nimble.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = FF15F7851EDCE82600F96686 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - FF15F7971EDD9A1900F96686 /* Quick.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = FF15F7861EDCE82600F96686 /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - FF15F7991EDD9A2B00F96686 /* Nimble.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = FF15F7891EDCE83100F96686 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - FF15F79A1EDD9A2B00F96686 /* Quick.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = FF15F78A1EDCE83100F96686 /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 771BFC7A22D5F83E00AFB237 /* Swinject_OSX.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 771BFC7022D5F83E00AFB237 /* Swinject_OSX.framework */; }; + 771BFC7F22D5F83E00AFB237 /* SwinjectTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 771BFC7E22D5F83E00AFB237 /* SwinjectTests.swift */; }; + 771BFC8122D5F83E00AFB237 /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 771BFC7322D5F83E00AFB237 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 771BFC9122D600B700AFB237 /* Nimble in Frameworks */ = {isa = PBXBuildFile; productRef = 771BFC9022D600B700AFB237 /* Nimble */; }; + 771BFC9422D600CC00AFB237 /* Quick in Frameworks */ = {isa = PBXBuildFile; productRef = 771BFC9322D600CC00AFB237 /* Quick */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ - 981899C71B5FE63F00C702D0 /* PBXContainerItemProxy */ = { + 771BFC7B22D5F83E00AFB237 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; - containerPortal = 981ABE781B5FC9DF00294975 /* Project object */; + containerPortal = 771BFC6722D5F83E00AFB237 /* Project object */; proxyType = 1; - remoteGlobalIDString = 981899BB1B5FE63F00C702D0; - remoteInfo = "Swinject-OSX"; - }; - 981ABE8D1B5FC9DF00294975 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 981ABE781B5FC9DF00294975 /* Project object */; - proxyType = 1; - remoteGlobalIDString = 981ABE801B5FC9DF00294975; + remoteGlobalIDString = 771BFC6F22D5F83E00AFB237; remoteInfo = Swinject; }; - 98689C8A1BBFC7A60005C6D3 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 981ABE781B5FC9DF00294975 /* Project object */; - proxyType = 1; - remoteGlobalIDString = 98689C7E1BBFC7A50005C6D3; - remoteInfo = "Swinject-tvOS"; - }; /* End PBXContainerItemProxy section */ -/* Begin PBXCopyFilesBuildPhase section */ - FF15F78F1EDD99B500F96686 /* CopyFiles */ = { - isa = PBXCopyFilesBuildPhase; - buildActionMask = 2147483647; - dstPath = ""; - dstSubfolderSpec = 10; - files = ( - FF15F7901EDD99DB00F96686 /* Nimble.framework in CopyFiles */, - FF15F7911EDD99DB00F96686 /* Quick.framework in CopyFiles */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - FF15F7951EDD9A0B00F96686 /* CopyFiles */ = { - isa = PBXCopyFilesBuildPhase; - buildActionMask = 2147483647; - dstPath = ""; - dstSubfolderSpec = 10; - files = ( - FF15F7961EDD9A1900F96686 /* Nimble.framework in CopyFiles */, - FF15F7971EDD9A1900F96686 /* Quick.framework in CopyFiles */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - FF15F7981EDD9A1F00F96686 /* CopyFiles */ = { - isa = PBXCopyFilesBuildPhase; - buildActionMask = 2147483647; - dstPath = ""; - dstSubfolderSpec = 10; - files = ( - FF15F7991EDD9A2B00F96686 /* Nimble.framework in CopyFiles */, - FF15F79A1EDD9A2B00F96686 /* Quick.framework in CopyFiles */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXCopyFilesBuildPhase section */ - /* Begin PBXFileReference section */ - 90B029741C18599200A6A521 /* Assembly.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Assembly.swift; sourceTree = ""; }; - 90B029781C185B1600A6A521 /* Assembler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Assembler.swift; sourceTree = ""; }; - 90B0297E1C18666200A6A521 /* AssemblerSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssemblerSpec.swift; sourceTree = ""; }; - 90B029821C18670000A6A521 /* BasicAssembly.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicAssembly.swift; sourceTree = ""; }; - 90B0298A1C186D5300A6A521 /* LoadAwareAssembly.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = LoadAwareAssembly.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; - 981577F01B675B7F00BF686B /* Circularity.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Circularity.swift; sourceTree = ""; }; - 981899BC1B5FE63F00C702D0 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 981899C51B5FE63F00C702D0 /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - 981899E01B5FF88800C702D0 /* ContainerSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContainerSpec.swift; sourceTree = ""; }; - 981899E31B5FFE5800C702D0 /* Container.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Container.swift; sourceTree = ""; }; - 9819701E1B6145D600EEB942 /* ObjectScope.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObjectScope.swift; sourceTree = ""; }; - 981ABE811B5FC9DF00294975 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 981ABE861B5FC9DF00294975 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 981ABE8B1B5FC9DF00294975 /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - 981ABE921B5FC9DF00294975 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 983B98301C06ECB2006A23D4 /* SpinLock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpinLock.swift; sourceTree = ""; }; - 984774EF1C02F25D0092A757 /* SynchronizedResolver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SynchronizedResolver.swift; sourceTree = ""; }; - 984774F41C02F4EA0092A757 /* SynchronizedResolver.Arguments.erb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = SynchronizedResolver.Arguments.erb; sourceTree = ""; }; - 984774F91C02F5A50092A757 /* SynchronizedResolver.Arguments.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SynchronizedResolver.Arguments.swift; sourceTree = ""; }; - 984774FE1C034C5C0092A757 /* SynchronizedResolverSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SynchronizedResolverSpec.swift; sourceTree = ""; }; - 9848611A1B6F21EC00C07072 /* Sample-iOS.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = "Sample-iOS.playground"; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; - 9848611B1B6F9B7000C07072 /* ContainerSpec.Arguments.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Arguments.swift; sourceTree = ""; }; - 984BE3121CDA3FCF00BCF2AC /* _Resolver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = _Resolver.swift; sourceTree = ""; }; - 984E8A511C317AC90039943D /* Swinject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Swinject.h; sourceTree = ""; }; - 985010BD1BBE76AB00A2CCFC /* watchOS-Application.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "watchOS-Application.xcconfig"; sourceTree = ""; }; - 985010BE1BBE76AB00A2CCFC /* watchOS-Base.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "watchOS-Base.xcconfig"; sourceTree = ""; }; - 985010BF1BBE76AB00A2CCFC /* watchOS-Framework.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "watchOS-Framework.xcconfig"; sourceTree = ""; }; - 985010C01BBE76AB00A2CCFC /* watchOS-StaticLibrary.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "watchOS-StaticLibrary.xcconfig"; sourceTree = ""; }; - 985010C61BBE76D400A2CCFC /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 9855C5BE1B686F5900DADB0B /* ContainerSpec.Circularity.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Circularity.swift; sourceTree = ""; }; - 9855C5C41B689B7B00DADB0B /* Food.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Food.swift; sourceTree = ""; }; - 9855C5C71B689D9000DADB0B /* ServiceEntrySpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ServiceEntrySpec.swift; sourceTree = ""; }; - 985BAFA81B625E0F0055F998 /* ServiceEntry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ServiceEntry.swift; sourceTree = ""; }; - 98689C761BBFC77F0005C6D3 /* tvOS-Application.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "tvOS-Application.xcconfig"; sourceTree = ""; }; - 98689C771BBFC77F0005C6D3 /* tvOS-Base.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "tvOS-Base.xcconfig"; sourceTree = ""; }; - 98689C781BBFC77F0005C6D3 /* tvOS-Framework.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "tvOS-Framework.xcconfig"; sourceTree = ""; }; - 98689C791BBFC77F0005C6D3 /* tvOS-StaticLibrary.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "tvOS-StaticLibrary.xcconfig"; sourceTree = ""; }; - 98689C7F1BBFC7A50005C6D3 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 98689C881BBFC7A60005C6D3 /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - 9878C6371B65C9E000CBEFEF /* Animal.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Animal.swift; sourceTree = ""; }; - 9878C63B1B65CA8700CBEFEF /* Person.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Person.swift; sourceTree = ""; }; - 9880E70D1C09EE2800ED5293 /* FunctionType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FunctionType.swift; sourceTree = ""; }; - 9884E2A61B60B77400120259 /* ServiceKey.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ServiceKey.swift; sourceTree = ""; }; - 9884E2A91B60C51C00120259 /* ServiceKeySpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ServiceKeySpec.swift; sourceTree = ""; }; - 98AA74461BB70CBB00E2F48A /* Common.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Common.xcconfig; sourceTree = ""; }; - 98AA74481BB70CBB00E2F48A /* Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = ""; }; - 98AA74491BB70CBB00E2F48A /* Profile.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Profile.xcconfig; sourceTree = ""; }; - 98AA744A1BB70CBB00E2F48A /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Release.xcconfig; sourceTree = ""; }; - 98AA744B1BB70CBB00E2F48A /* Test.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Test.xcconfig; sourceTree = ""; }; - 98AA744D1BB70CBB00E2F48A /* Application.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Application.xcconfig; sourceTree = ""; }; - 98AA744E1BB70CBB00E2F48A /* Framework.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Framework.xcconfig; sourceTree = ""; }; - 98AA744F1BB70CBB00E2F48A /* StaticLibrary.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = StaticLibrary.xcconfig; sourceTree = ""; }; - 98AA74511BB70CBB00E2F48A /* iOS-Application.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "iOS-Application.xcconfig"; sourceTree = ""; }; - 98AA74521BB70CBB00E2F48A /* iOS-Base.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "iOS-Base.xcconfig"; sourceTree = ""; }; - 98AA74531BB70CBB00E2F48A /* iOS-Framework.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "iOS-Framework.xcconfig"; sourceTree = ""; }; - 98AA74541BB70CBB00E2F48A /* iOS-StaticLibrary.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "iOS-StaticLibrary.xcconfig"; sourceTree = ""; }; - 98AA74561BB70CBB00E2F48A /* Mac-Application.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Mac-Application.xcconfig"; sourceTree = ""; }; - 98AA74571BB70CBB00E2F48A /* Mac-Base.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Mac-Base.xcconfig"; sourceTree = ""; }; - 98AA74581BB70CBB00E2F48A /* Mac-DynamicLibrary.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Mac-DynamicLibrary.xcconfig"; sourceTree = ""; }; - 98AA74591BB70CBB00E2F48A /* Mac-Framework.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Mac-Framework.xcconfig"; sourceTree = ""; }; - 98AA745A1BB70CBB00E2F48A /* Mac-StaticLibrary.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Mac-StaticLibrary.xcconfig"; sourceTree = ""; }; - 98B012B71B82D67300053A32 /* Container.Arguments.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Container.Arguments.swift; sourceTree = ""; }; - 98B012BA1B82D6A400053A32 /* Container.Arguments.erb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Container.Arguments.erb; sourceTree = ""; }; - 98B012BE1B82F68E00053A32 /* Resolver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Resolver.swift; sourceTree = ""; }; - 98B012C11B82F70A00053A32 /* Resolver.erb */ = {isa = PBXFileReference; lastKnownFileType = text; path = Resolver.erb; sourceTree = ""; }; - 98E550C21DEF066300BE6304 /* UnavailableItems.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UnavailableItems.swift; sourceTree = ""; }; - CD3B32911DD6121500B208A3 /* InstanceStorage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InstanceStorage.swift; sourceTree = ""; }; - CD3B32961DD6126E00B208A3 /* ObjectScope.Standard.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObjectScope.Standard.swift; sourceTree = ""; }; - CD3B329B1DD61F2400B208A3 /* ContainerSpec.CustomScope.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContainerSpec.CustomScope.swift; sourceTree = ""; }; - CD3C2CDE1D98E47000863421 /* DebugHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DebugHelper.swift; sourceTree = ""; }; - CD3C2CF11D98EF4A00863421 /* ContainerSpec.DebugHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContainerSpec.DebugHelper.swift; sourceTree = ""; }; - CD5E9A31205157E3009090F9 /* ContainerSpec.GraphCaching.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.GraphCaching.swift; sourceTree = ""; }; - CD5E9A3520515898009090F9 /* GraphIdentifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphIdentifier.swift; sourceTree = ""; }; - CD65F048205943D400FB43EE /* EmploymentAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmploymentAssembly.swift; sourceTree = ""; }; - CD6A9F811EEFCB7A0087E851 /* ContainerSpec.CustomStringConvertible.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContainerSpec.CustomStringConvertible.swift; sourceTree = ""; }; - CD89E3462036F28300A9ED33 /* ServiceEntry.TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServiceEntry.TypeForwarding.swift; sourceTree = ""; }; - CD89E3482036F2A800A9ED33 /* ServiceEntry.TypeForwarding.erb */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = ServiceEntry.TypeForwarding.erb; sourceTree = ""; }; - CD89E34C2037016700A9ED33 /* Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Behavior.swift; sourceTree = ""; }; - CD89E35120371D7900A9ED33 /* ContainerSpec.Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Behavior.swift; sourceTree = ""; }; - CD8E362B20595ACD00F2A5CF /* ProviderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProviderSpec.swift; sourceTree = ""; }; - CDB19E51204ED97400D67123 /* BehaviorFakes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BehaviorFakes.swift; sourceTree = ""; }; - CDBBACF51D9EAD60002F5EF9 /* Container.Logging.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Container.Logging.swift; sourceTree = ""; }; - CDBD0E672035EDF20030F566 /* ContainerSpec.TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.TypeForwarding.swift; sourceTree = ""; }; - CDBD0E6B2035EEBB0030F566 /* Container.TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.TypeForwarding.swift; sourceTree = ""; }; - CDC4FCF3205028B00021C60F /* InstanceWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceWrapper.swift; sourceTree = ""; }; - CDC4FCF820502A9A0021C60F /* LazySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LazySpec.swift; sourceTree = ""; }; - CDD44AD61DEEED1000916595 /* WeakStorageSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WeakStorageSpec.swift; sourceTree = ""; }; - FF15F77F1EDCE81600F96686 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nimble.framework; path = Carthage/Build/iOS/Nimble.framework; sourceTree = ""; }; - FF15F7801EDCE81600F96686 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quick.framework; path = Carthage/Build/iOS/Quick.framework; sourceTree = ""; }; - FF15F7851EDCE82600F96686 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nimble.framework; path = Carthage/Build/Mac/Nimble.framework; sourceTree = ""; }; - FF15F7861EDCE82600F96686 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quick.framework; path = Carthage/Build/Mac/Quick.framework; sourceTree = ""; }; - FF15F7891EDCE83100F96686 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nimble.framework; path = Carthage/Build/tvOS/Nimble.framework; sourceTree = ""; }; - FF15F78A1EDCE83100F96686 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quick.framework; path = Carthage/Build/tvOS/Quick.framework; sourceTree = ""; }; + 771BFC7022D5F83E00AFB237 /* Swinject_OSX.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject_OSX.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 771BFC7322D5F83E00AFB237 /* Swinject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Swinject.h; sourceTree = ""; }; + 771BFC7422D5F83E00AFB237 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 771BFC7922D5F83E00AFB237 /* SwinjectTests-OSX.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SwinjectTests-OSX.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; + 771BFC7E22D5F83E00AFB237 /* SwinjectTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTests.swift; sourceTree = ""; }; + 771BFC8022D5F83E00AFB237 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 771BFC8B22D5FAAE00AFB237 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nimble.framework; path = Carthage/Build/Mac/Nimble.framework; sourceTree = ""; }; + 771BFC8C22D5FAAE00AFB237 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quick.framework; path = Carthage/Build/Mac/Quick.framework; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ - 981899B81B5FE63F00C702D0 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 981899C21B5FE63F00C702D0 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - 981899C61B5FE63F00C702D0 /* Swinject.framework in Frameworks */, - FF15F7871EDCE82600F96686 /* Nimble.framework in Frameworks */, - FF15F7881EDCE82600F96686 /* Quick.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 981ABE7D1B5FC9DF00294975 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 981ABE881B5FC9DF00294975 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - FF15F7841EDCE81B00F96686 /* Quick.framework in Frameworks */, - FF15F7831EDCE81B00F96686 /* Nimble.framework in Frameworks */, - 981ABE8C1B5FC9DF00294975 /* Swinject.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 985010C21BBE76D400A2CCFC /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 98689C7B1BBFC7A50005C6D3 /* Frameworks */ = { + 771BFC6D22D5F83E00AFB237 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( ); runOnlyForDeploymentPostprocessing = 0; }; - 98689C851BBFC7A60005C6D3 /* Frameworks */ = { + 771BFC7622D5F83E00AFB237 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - FF15F78C1EDCE83100F96686 /* Quick.framework in Frameworks */, - FF15F78B1EDCE83100F96686 /* Nimble.framework in Frameworks */, - 98689CD51BBFDEBC0005C6D3 /* Swinject.framework in Frameworks */, + 771BFC7A22D5F83E00AFB237 /* Swinject_OSX.framework in Frameworks */, + 771BFC9422D600CC00AFB237 /* Quick in Frameworks */, + 771BFC9122D600B700AFB237 /* Nimble in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 9802C9B11B5FD7E80088018E /* Frameworks */ = { - isa = PBXGroup; - children = ( - FF15F77F1EDCE81600F96686 /* Nimble.framework */, - FF15F7801EDCE81600F96686 /* Quick.framework */, - FF15F7851EDCE82600F96686 /* Nimble.framework */, - FF15F7861EDCE82600F96686 /* Quick.framework */, - FF15F7891EDCE83100F96686 /* Nimble.framework */, - FF15F78A1EDCE83100F96686 /* Quick.framework */, - ); - name = Frameworks; - sourceTree = ""; - }; - 981ABE771B5FC9DF00294975 = { + 771BFC6622D5F83E00AFB237 = { isa = PBXGroup; children = ( - 9848611A1B6F21EC00C07072 /* Sample-iOS.playground */, - 981ABE831B5FC9DF00294975 /* Sources */, - 981ABE8F1B5FC9DF00294975 /* SwinjectTests */, - 981ABE821B5FC9DF00294975 /* Products */, - 98AA74441BB70C8C00E2F48A /* Configuration */, - 9802C9B11B5FD7E80088018E /* Frameworks */, + 771BFC7222D5F83E00AFB237 /* Sources */, + 771BFC7D22D5F83E00AFB237 /* Tests */, + 771BFC7122D5F83E00AFB237 /* Products */, + 771BFC8A22D5FAAE00AFB237 /* Frameworks */, ); sourceTree = ""; }; - 981ABE821B5FC9DF00294975 /* Products */ = { + 771BFC7122D5F83E00AFB237 /* Products */ = { isa = PBXGroup; children = ( - 981ABE811B5FC9DF00294975 /* Swinject.framework */, - 981ABE8B1B5FC9DF00294975 /* SwinjectTests.xctest */, - 981899BC1B5FE63F00C702D0 /* Swinject.framework */, - 981899C51B5FE63F00C702D0 /* SwinjectTests.xctest */, - 985010C61BBE76D400A2CCFC /* Swinject.framework */, - 98689C7F1BBFC7A50005C6D3 /* Swinject.framework */, - 98689C881BBFC7A60005C6D3 /* SwinjectTests.xctest */, + 771BFC7022D5F83E00AFB237 /* Swinject_OSX.framework */, + 771BFC7922D5F83E00AFB237 /* SwinjectTests-OSX.xctest */, ); name = Products; sourceTree = ""; }; - 981ABE831B5FC9DF00294975 /* Sources */ = { + 771BFC7222D5F83E00AFB237 /* Sources */ = { isa = PBXGroup; children = ( - 90B029781C185B1600A6A521 /* Assembler.swift */, - 90B029741C18599200A6A521 /* Assembly.swift */, - 981899E31B5FFE5800C702D0 /* Container.swift */, - CDBD0E6B2035EEBB0030F566 /* Container.TypeForwarding.swift */, - 98B012BA1B82D6A400053A32 /* Container.Arguments.erb */, - CD89E3482036F2A800A9ED33 /* ServiceEntry.TypeForwarding.erb */, - CD3C2CDE1D98E47000863421 /* DebugHelper.swift */, - CDBBACF51D9EAD60002F5EF9 /* Container.Logging.swift */, - 984774EF1C02F25D0092A757 /* SynchronizedResolver.swift */, - 984774F41C02F4EA0092A757 /* SynchronizedResolver.Arguments.erb */, - 9880E70D1C09EE2800ED5293 /* FunctionType.swift */, - 9884E2A61B60B77400120259 /* ServiceKey.swift */, - 985BAFA81B625E0F0055F998 /* ServiceEntry.swift */, - 9819701E1B6145D600EEB942 /* ObjectScope.swift */, - CD3B32961DD6126E00B208A3 /* ObjectScope.Standard.swift */, - CD3B32911DD6121500B208A3 /* InstanceStorage.swift */, - 984BE3121CDA3FCF00BCF2AC /* _Resolver.swift */, - 98B012C11B82F70A00053A32 /* Resolver.erb */, - 983B98301C06ECB2006A23D4 /* SpinLock.swift */, - 98E550C21DEF066300BE6304 /* UnavailableItems.swift */, - CD89E34C2037016700A9ED33 /* Behavior.swift */, - 98B012BD1B82D6B000053A32 /* GeneratedCode */, - 984E8A511C317AC90039943D /* Swinject.h */, - 981ABE861B5FC9DF00294975 /* Info.plist */, - CDC4FCF3205028B00021C60F /* InstanceWrapper.swift */, - CD5E9A3520515898009090F9 /* GraphIdentifier.swift */, + 771BFC7322D5F83E00AFB237 /* Swinject.h */, + 771BFC7422D5F83E00AFB237 /* Info.plist */, ); path = Sources; sourceTree = ""; }; - 981ABE8F1B5FC9DF00294975 /* SwinjectTests */ = { - isa = PBXGroup; - children = ( - 9878C63A1B65CA0600CBEFEF /* Fakes */, - 90B0297E1C18666200A6A521 /* AssemblerSpec.swift */, - 981899E01B5FF88800C702D0 /* ContainerSpec.swift */, - 9848611B1B6F9B7000C07072 /* ContainerSpec.Arguments.swift */, - 9855C5BE1B686F5900DADB0B /* ContainerSpec.Circularity.swift */, - CD3C2CF11D98EF4A00863421 /* ContainerSpec.DebugHelper.swift */, - CD3B329B1DD61F2400B208A3 /* ContainerSpec.CustomScope.swift */, - CD6A9F811EEFCB7A0087E851 /* ContainerSpec.CustomStringConvertible.swift */, - CD89E35120371D7900A9ED33 /* ContainerSpec.Behavior.swift */, - CDBD0E672035EDF20030F566 /* ContainerSpec.TypeForwarding.swift */, - 984774FE1C034C5C0092A757 /* SynchronizedResolverSpec.swift */, - 9884E2A91B60C51C00120259 /* ServiceKeySpec.swift */, - 9855C5C71B689D9000DADB0B /* ServiceEntrySpec.swift */, - CDD44AD61DEEED1000916595 /* WeakStorageSpec.swift */, - 981ABE921B5FC9DF00294975 /* Info.plist */, - CDC4FCF820502A9A0021C60F /* LazySpec.swift */, - CD5E9A31205157E3009090F9 /* ContainerSpec.GraphCaching.swift */, - CD8E362B20595ACD00F2A5CF /* ProviderSpec.swift */, - ); - name = SwinjectTests; - path = Tests/SwinjectTests; - sourceTree = ""; - }; - 985010BC1BBE76AB00A2CCFC /* watchOS */ = { + 771BFC7D22D5F83E00AFB237 /* Tests */ = { isa = PBXGroup; children = ( - 985010BD1BBE76AB00A2CCFC /* watchOS-Application.xcconfig */, - 985010BE1BBE76AB00A2CCFC /* watchOS-Base.xcconfig */, - 985010BF1BBE76AB00A2CCFC /* watchOS-Framework.xcconfig */, - 985010C01BBE76AB00A2CCFC /* watchOS-StaticLibrary.xcconfig */, + 771BFC7E22D5F83E00AFB237 /* SwinjectTests.swift */, + 771BFC8022D5F83E00AFB237 /* Info.plist */, ); - path = watchOS; + path = Tests; sourceTree = ""; }; - 98689C751BBFC77F0005C6D3 /* tvOS */ = { - isa = PBXGroup; - children = ( - 98689C761BBFC77F0005C6D3 /* tvOS-Application.xcconfig */, - 98689C771BBFC77F0005C6D3 /* tvOS-Base.xcconfig */, - 98689C781BBFC77F0005C6D3 /* tvOS-Framework.xcconfig */, - 98689C791BBFC77F0005C6D3 /* tvOS-StaticLibrary.xcconfig */, - ); - name = tvOS; - path = Configurations/tvOS; - sourceTree = SOURCE_ROOT; - }; - 9878C63A1B65CA0600CBEFEF /* Fakes */ = { + 771BFC8A22D5FAAE00AFB237 /* Frameworks */ = { isa = PBXGroup; children = ( - 9878C63B1B65CA8700CBEFEF /* Person.swift */, - 9878C6371B65C9E000CBEFEF /* Animal.swift */, - 9855C5C41B689B7B00DADB0B /* Food.swift */, - 981577F01B675B7F00BF686B /* Circularity.swift */, - 90B029821C18670000A6A521 /* BasicAssembly.swift */, - 90B0298A1C186D5300A6A521 /* LoadAwareAssembly.swift */, - CD65F048205943D400FB43EE /* EmploymentAssembly.swift */, - CDB19E51204ED97400D67123 /* BehaviorFakes.swift */, + 771BFC8B22D5FAAE00AFB237 /* Nimble.framework */, + 771BFC8C22D5FAAE00AFB237 /* Quick.framework */, ); - name = Fakes; - sourceTree = ""; - }; - 98AA74441BB70C8C00E2F48A /* Configuration */ = { - isa = PBXGroup; - children = ( - 98AA74451BB70CBB00E2F48A /* Base */, - 98AA74501BB70CBB00E2F48A /* iOS */, - 98AA74551BB70CBB00E2F48A /* Mac OS X */, - 98689C751BBFC77F0005C6D3 /* tvOS */, - 985010BC1BBE76AB00A2CCFC /* watchOS */, - ); - name = Configuration; - path = Configurations; - sourceTree = ""; - }; - 98AA74451BB70CBB00E2F48A /* Base */ = { - isa = PBXGroup; - children = ( - 98AA74461BB70CBB00E2F48A /* Common.xcconfig */, - 98AA74471BB70CBB00E2F48A /* Configurations */, - 98AA744C1BB70CBB00E2F48A /* Targets */, - ); - path = Base; - sourceTree = ""; - }; - 98AA74471BB70CBB00E2F48A /* Configurations */ = { - isa = PBXGroup; - children = ( - 98AA74481BB70CBB00E2F48A /* Debug.xcconfig */, - 98AA74491BB70CBB00E2F48A /* Profile.xcconfig */, - 98AA744A1BB70CBB00E2F48A /* Release.xcconfig */, - 98AA744B1BB70CBB00E2F48A /* Test.xcconfig */, - ); - path = Configurations; - sourceTree = ""; - }; - 98AA744C1BB70CBB00E2F48A /* Targets */ = { - isa = PBXGroup; - children = ( - 98AA744D1BB70CBB00E2F48A /* Application.xcconfig */, - 98AA744E1BB70CBB00E2F48A /* Framework.xcconfig */, - 98AA744F1BB70CBB00E2F48A /* StaticLibrary.xcconfig */, - ); - path = Targets; - sourceTree = ""; - }; - 98AA74501BB70CBB00E2F48A /* iOS */ = { - isa = PBXGroup; - children = ( - 98AA74511BB70CBB00E2F48A /* iOS-Application.xcconfig */, - 98AA74521BB70CBB00E2F48A /* iOS-Base.xcconfig */, - 98AA74531BB70CBB00E2F48A /* iOS-Framework.xcconfig */, - 98AA74541BB70CBB00E2F48A /* iOS-StaticLibrary.xcconfig */, - ); - path = iOS; - sourceTree = ""; - }; - 98AA74551BB70CBB00E2F48A /* Mac OS X */ = { - isa = PBXGroup; - children = ( - 98AA74561BB70CBB00E2F48A /* Mac-Application.xcconfig */, - 98AA74571BB70CBB00E2F48A /* Mac-Base.xcconfig */, - 98AA74581BB70CBB00E2F48A /* Mac-DynamicLibrary.xcconfig */, - 98AA74591BB70CBB00E2F48A /* Mac-Framework.xcconfig */, - 98AA745A1BB70CBB00E2F48A /* Mac-StaticLibrary.xcconfig */, - ); - path = "Mac OS X"; - sourceTree = ""; - }; - 98B012BD1B82D6B000053A32 /* GeneratedCode */ = { - isa = PBXGroup; - children = ( - 98B012B71B82D67300053A32 /* Container.Arguments.swift */, - 984774F91C02F5A50092A757 /* SynchronizedResolver.Arguments.swift */, - 98B012BE1B82F68E00053A32 /* Resolver.swift */, - CD89E3462036F28300A9ED33 /* ServiceEntry.TypeForwarding.swift */, - ); - name = GeneratedCode; + name = Frameworks; sourceTree = ""; }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ - 981899B91B5FE63F00C702D0 /* Headers */ = { - isa = PBXHeadersBuildPhase; - buildActionMask = 2147483647; - files = ( - 984E8A531C317AC90039943D /* Swinject.h in Headers */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 981ABE7E1B5FC9DF00294975 /* Headers */ = { - isa = PBXHeadersBuildPhase; - buildActionMask = 2147483647; - files = ( - 984E8A521C317AC90039943D /* Swinject.h in Headers */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 985010C31BBE76D400A2CCFC /* Headers */ = { + 771BFC6B22D5F83E00AFB237 /* Headers */ = { isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( - 984E8A541C317AC90039943D /* Swinject.h in Headers */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 98689C7C1BBFC7A50005C6D3 /* Headers */ = { - isa = PBXHeadersBuildPhase; - buildActionMask = 2147483647; - files = ( - 984E8A551C317AC90039943D /* Swinject.h in Headers */, + 771BFC8122D5F83E00AFB237 /* Swinject.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXHeadersBuildPhase section */ /* Begin PBXNativeTarget section */ - 981899BB1B5FE63F00C702D0 /* Swinject-OSX */ = { + 771BFC6F22D5F83E00AFB237 /* Swinject-OSX */ = { isa = PBXNativeTarget; - buildConfigurationList = 981899D11B5FE64000C702D0 /* Build configuration list for PBXNativeTarget "Swinject-OSX" */; + buildConfigurationList = 771BFC8422D5F83E00AFB237 /* Build configuration list for PBXNativeTarget "Swinject-OSX" */; buildPhases = ( - 981899B71B5FE63F00C702D0 /* Sources */, - 981899B81B5FE63F00C702D0 /* Frameworks */, - 981899B91B5FE63F00C702D0 /* Headers */, - 981899BA1B5FE63F00C702D0 /* Resources */, - 98AEB3B51BE7848C0009F188 /* Run SwiftLint */, + 771BFC6B22D5F83E00AFB237 /* Headers */, + 771BFC6C22D5F83E00AFB237 /* Sources */, + 771BFC6D22D5F83E00AFB237 /* Frameworks */, + 771BFC6E22D5F83E00AFB237 /* Resources */, ); buildRules = ( ); dependencies = ( ); name = "Swinject-OSX"; - productName = "Swinject-OSX"; - productReference = 981899BC1B5FE63F00C702D0 /* Swinject.framework */; - productType = "com.apple.product-type.framework"; - }; - 981899C41B5FE63F00C702D0 /* Swinject-OSXTests */ = { - isa = PBXNativeTarget; - buildConfigurationList = 981899D21B5FE64000C702D0 /* Build configuration list for PBXNativeTarget "Swinject-OSXTests" */; - buildPhases = ( - 981899C11B5FE63F00C702D0 /* Sources */, - 981899C21B5FE63F00C702D0 /* Frameworks */, - 981899C31B5FE63F00C702D0 /* Resources */, - FF15F7951EDD9A0B00F96686 /* CopyFiles */, - ); - buildRules = ( - ); - dependencies = ( - 981899C81B5FE63F00C702D0 /* PBXTargetDependency */, - ); - name = "Swinject-OSXTests"; - productName = "Swinject-OSXTests"; - productReference = 981899C51B5FE63F00C702D0 /* SwinjectTests.xctest */; - productType = "com.apple.product-type.bundle.unit-test"; - }; - 981ABE801B5FC9DF00294975 /* Swinject-iOS */ = { - isa = PBXNativeTarget; - buildConfigurationList = 981ABE951B5FC9DF00294975 /* Build configuration list for PBXNativeTarget "Swinject-iOS" */; - buildPhases = ( - 981ABE7C1B5FC9DF00294975 /* Sources */, - 981ABE7D1B5FC9DF00294975 /* Frameworks */, - 981ABE7E1B5FC9DF00294975 /* Headers */, - 981ABE7F1B5FC9DF00294975 /* Resources */, - 98AEB3B11BE783DC0009F188 /* Run SwiftLint */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = "Swinject-iOS"; productName = Swinject; - productReference = 981ABE811B5FC9DF00294975 /* Swinject.framework */; + productReference = 771BFC7022D5F83E00AFB237 /* Swinject_OSX.framework */; productType = "com.apple.product-type.framework"; }; - 981ABE8A1B5FC9DF00294975 /* Swinject-iOSTests */ = { + 771BFC7822D5F83E00AFB237 /* SwinjectTests-OSX */ = { isa = PBXNativeTarget; - buildConfigurationList = 981ABE981B5FC9DF00294975 /* Build configuration list for PBXNativeTarget "Swinject-iOSTests" */; + buildConfigurationList = 771BFC8722D5F83E00AFB237 /* Build configuration list for PBXNativeTarget "SwinjectTests-OSX" */; buildPhases = ( - 981ABE871B5FC9DF00294975 /* Sources */, - 981ABE881B5FC9DF00294975 /* Frameworks */, - 981ABE891B5FC9DF00294975 /* Resources */, - FF15F78F1EDD99B500F96686 /* CopyFiles */, + 771BFC7522D5F83E00AFB237 /* Sources */, + 771BFC7622D5F83E00AFB237 /* Frameworks */, + 771BFC7722D5F83E00AFB237 /* Resources */, ); buildRules = ( ); dependencies = ( - 981ABE8E1B5FC9DF00294975 /* PBXTargetDependency */, + 771BFC7C22D5F83E00AFB237 /* PBXTargetDependency */, ); - name = "Swinject-iOSTests"; - productName = SwinjectTests; - productReference = 981ABE8B1B5FC9DF00294975 /* SwinjectTests.xctest */; - productType = "com.apple.product-type.bundle.unit-test"; - }; - 985010C51BBE76D400A2CCFC /* Swinject-watchOS */ = { - isa = PBXNativeTarget; - buildConfigurationList = 985010CB1BBE76D400A2CCFC /* Build configuration list for PBXNativeTarget "Swinject-watchOS" */; - buildPhases = ( - 985010C11BBE76D400A2CCFC /* Sources */, - 985010C21BBE76D400A2CCFC /* Frameworks */, - 985010C31BBE76D400A2CCFC /* Headers */, - 985010C41BBE76D400A2CCFC /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = "Swinject-watchOS"; - productName = "Swinject-watchOS"; - productReference = 985010C61BBE76D400A2CCFC /* Swinject.framework */; - productType = "com.apple.product-type.framework"; - }; - 98689C7E1BBFC7A50005C6D3 /* Swinject-tvOS */ = { - isa = PBXNativeTarget; - buildConfigurationList = 98689C901BBFC7A60005C6D3 /* Build configuration list for PBXNativeTarget "Swinject-tvOS" */; - buildPhases = ( - 98689C7A1BBFC7A50005C6D3 /* Sources */, - 98689C7B1BBFC7A50005C6D3 /* Frameworks */, - 98689C7C1BBFC7A50005C6D3 /* Headers */, - 98689C7D1BBFC7A50005C6D3 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = "Swinject-tvOS"; - productName = "Swinject-tvOS"; - productReference = 98689C7F1BBFC7A50005C6D3 /* Swinject.framework */; - productType = "com.apple.product-type.framework"; - }; - 98689C871BBFC7A60005C6D3 /* Swinject-tvOSTests */ = { - isa = PBXNativeTarget; - buildConfigurationList = 98689C941BBFC7A60005C6D3 /* Build configuration list for PBXNativeTarget "Swinject-tvOSTests" */; - buildPhases = ( - 98689C841BBFC7A60005C6D3 /* Sources */, - 98689C851BBFC7A60005C6D3 /* Frameworks */, - 98689C861BBFC7A60005C6D3 /* Resources */, - FF15F7981EDD9A1F00F96686 /* CopyFiles */, - ); - buildRules = ( + name = "SwinjectTests-OSX"; + packageProductDependencies = ( + 771BFC9022D600B700AFB237 /* Nimble */, + 771BFC9322D600CC00AFB237 /* Quick */, ); - dependencies = ( - 98689C8B1BBFC7A60005C6D3 /* PBXTargetDependency */, - ); - name = "Swinject-tvOSTests"; - productName = "Swinject-tvOSTests"; - productReference = 98689C881BBFC7A60005C6D3 /* SwinjectTests.xctest */; + productName = SwinjectTests; + productReference = 771BFC7922D5F83E00AFB237 /* SwinjectTests-OSX.xctest */; productType = "com.apple.product-type.bundle.unit-test"; }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ - 981ABE781B5FC9DF00294975 /* Project object */ = { + 771BFC6722D5F83E00AFB237 /* Project object */ = { isa = PBXProject; attributes = { - LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0930; + LastSwiftUpdateCheck = 1100; + LastUpgradeCheck = 1100; ORGANIZATIONNAME = "Swinject Contributors"; TargetAttributes = { - 981899BB1B5FE63F00C702D0 = { - CreatedOnToolsVersion = 7.0; - LastSwiftMigration = 0920; - }; - 981899C41B5FE63F00C702D0 = { - CreatedOnToolsVersion = 7.0; - LastSwiftMigration = 0920; - }; - 981ABE801B5FC9DF00294975 = { - CreatedOnToolsVersion = 7.0; - LastSwiftMigration = 0920; - }; - 981ABE8A1B5FC9DF00294975 = { - CreatedOnToolsVersion = 7.0; - LastSwiftMigration = 0920; + 771BFC6F22D5F83E00AFB237 = { + CreatedOnToolsVersion = 11.0; }; - 985010C51BBE76D400A2CCFC = { - CreatedOnToolsVersion = 7.0.1; - LastSwiftMigration = 0920; - }; - 98689C7E1BBFC7A50005C6D3 = { - CreatedOnToolsVersion = 7.1; - LastSwiftMigration = 0920; - }; - 98689C871BBFC7A60005C6D3 = { - CreatedOnToolsVersion = 7.1; - LastSwiftMigration = 0920; + 771BFC7822D5F83E00AFB237 = { + CreatedOnToolsVersion = 11.0; }; }; }; - buildConfigurationList = 981ABE7B1B5FC9DF00294975 /* Build configuration list for PBXProject "Swinject" */; - compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; + buildConfigurationList = 771BFC6A22D5F83E00AFB237 /* Build configuration list for PBXProject "Swinject" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( en, + Base, + ); + mainGroup = 771BFC6622D5F83E00AFB237; + packageReferences = ( + 771BFC8F22D600B700AFB237 /* XCRemoteSwiftPackageReference "Nimble" */, + 771BFC9222D600CC00AFB237 /* XCRemoteSwiftPackageReference "Quick" */, ); - mainGroup = 981ABE771B5FC9DF00294975; - productRefGroup = 981ABE821B5FC9DF00294975 /* Products */; + productRefGroup = 771BFC7122D5F83E00AFB237 /* Products */; projectDirPath = ""; projectRoot = ""; targets = ( - 981ABE801B5FC9DF00294975 /* Swinject-iOS */, - 981ABE8A1B5FC9DF00294975 /* Swinject-iOSTests */, - 981899BB1B5FE63F00C702D0 /* Swinject-OSX */, - 981899C41B5FE63F00C702D0 /* Swinject-OSXTests */, - 985010C51BBE76D400A2CCFC /* Swinject-watchOS */, - 98689C7E1BBFC7A50005C6D3 /* Swinject-tvOS */, - 98689C871BBFC7A60005C6D3 /* Swinject-tvOSTests */, + 771BFC6F22D5F83E00AFB237 /* Swinject-OSX */, + 771BFC7822D5F83E00AFB237 /* SwinjectTests-OSX */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ - 981899BA1B5FE63F00C702D0 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 981899C31B5FE63F00C702D0 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 981ABE7F1B5FC9DF00294975 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 981ABE891B5FC9DF00294975 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 985010C41BBE76D400A2CCFC /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 98689C7D1BBFC7A50005C6D3 /* Resources */ = { + 771BFC6E22D5F83E00AFB237 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( ); runOnlyForDeploymentPostprocessing = 0; }; - 98689C861BBFC7A60005C6D3 /* Resources */ = { + 771BFC7722D5F83E00AFB237 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( @@ -905,573 +214,301 @@ }; /* End PBXResourcesBuildPhase section */ -/* Begin PBXShellScriptBuildPhase section */ - 98AEB3B11BE783DC0009F188 /* Run SwiftLint */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "Run SwiftLint"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "if [ \"${CONFIGURATION}\" = \"Debug\" ]; then\n if which swiftlint >/dev/null; then\n swiftlint\n fi\nfi\n"; - }; - 98AEB3B51BE7848C0009F188 /* Run SwiftLint */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "Run SwiftLint"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "if [ \"${CONFIGURATION}\" = \"Debug\" ]; then\n if which swiftlint >/dev/null; then\n swiftlint\n fi\nfi\n"; - }; -/* End PBXShellScriptBuildPhase section */ - /* Begin PBXSourcesBuildPhase section */ - 981899B71B5FE63F00C702D0 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 983B98321C06ECB2006A23D4 /* SpinLock.swift in Sources */, - CD89E34E20371C0100A9ED33 /* Behavior.swift in Sources */, - 985BAFAA1B625E0F0055F998 /* ServiceEntry.swift in Sources */, - CD3B32981DD6126E00B208A3 /* ObjectScope.Standard.swift in Sources */, - 9880E70F1C09EE2900ED5293 /* FunctionType.swift in Sources */, - 98B012C01B82F68E00053A32 /* Resolver.swift in Sources */, - CD3C2CE01D98E47000863421 /* DebugHelper.swift in Sources */, - 90B0297A1C185B1600A6A521 /* Assembler.swift in Sources */, - CDC4FCF5205028B00021C60F /* InstanceWrapper.swift in Sources */, - CD5E9A3720515898009090F9 /* GraphIdentifier.swift in Sources */, - 90B029761C18599200A6A521 /* Assembly.swift in Sources */, - CD3B32931DD6123F00B208A3 /* InstanceStorage.swift in Sources */, - 984774F11C02F25D0092A757 /* SynchronizedResolver.swift in Sources */, - 981899E51B5FFE5800C702D0 /* Container.swift in Sources */, - 98B012B91B82D67300053A32 /* Container.Arguments.swift in Sources */, - 9884E2A81B60B77400120259 /* ServiceKey.swift in Sources */, - CDBD0E702035EEC00030F566 /* Container.TypeForwarding.swift in Sources */, - 984BE3141CDA3FCF00BCF2AC /* _Resolver.swift in Sources */, - 981970201B6145D600EEB942 /* ObjectScope.swift in Sources */, - CDBBACF71D9EAD60002F5EF9 /* Container.Logging.swift in Sources */, - 984774FB1C02F5A50092A757 /* SynchronizedResolver.Arguments.swift in Sources */, - CD89E3492036F2BE00A9ED33 /* ServiceEntry.TypeForwarding.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 981899C11B5FE63F00C702D0 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 90B029841C18670000A6A521 /* BasicAssembly.swift in Sources */, - 9855C5C61B689B7B00DADB0B /* Food.swift in Sources */, - 9855C5C91B689D9000DADB0B /* ServiceEntrySpec.swift in Sources */, - CD8E362D20595ACD00F2A5CF /* ProviderSpec.swift in Sources */, - CD5E9A33205157E3009090F9 /* ContainerSpec.GraphCaching.swift in Sources */, - CD3C2CF31D98EF4A00863421 /* ContainerSpec.DebugHelper.swift in Sources */, - CDC4FCFE20502AA00021C60F /* LazySpec.swift in Sources */, - 984775001C034C5C0092A757 /* SynchronizedResolverSpec.swift in Sources */, - CD6A9F831EEFCB7A0087E851 /* ContainerSpec.CustomStringConvertible.swift in Sources */, - CD3B329D1DD61F2400B208A3 /* ContainerSpec.CustomScope.swift in Sources */, - 9848611D1B6F9B7000C07072 /* ContainerSpec.Arguments.swift in Sources */, - 9878C63D1B65CA8700CBEFEF /* Person.swift in Sources */, - CD89E35320371D7900A9ED33 /* ContainerSpec.Behavior.swift in Sources */, - CDD44AD81DEEED1000916595 /* WeakStorageSpec.swift in Sources */, - 9884E2AB1B60C51C00120259 /* ServiceKeySpec.swift in Sources */, - 90B0298C1C186D5300A6A521 /* LoadAwareAssembly.swift in Sources */, - 90B029801C18666200A6A521 /* AssemblerSpec.swift in Sources */, - CD65F04A205943D400FB43EE /* EmploymentAssembly.swift in Sources */, - 9878C6391B65C9E000CBEFEF /* Animal.swift in Sources */, - 981899E21B5FF88800C702D0 /* ContainerSpec.swift in Sources */, - 981577F21B675B7F00BF686B /* Circularity.swift in Sources */, - CDB19E53204ED97400D67123 /* BehaviorFakes.swift in Sources */, - CDBD0E692035EDF20030F566 /* ContainerSpec.TypeForwarding.swift in Sources */, - 9855C5C01B686F5900DADB0B /* ContainerSpec.Circularity.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 981ABE7C1B5FC9DF00294975 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - CD5E9A3620515898009090F9 /* GraphIdentifier.swift in Sources */, - 983B98311C06ECB2006A23D4 /* SpinLock.swift in Sources */, - 90B029791C185B1600A6A521 /* Assembler.swift in Sources */, - CDC4FCF4205028B00021C60F /* InstanceWrapper.swift in Sources */, - CD89E3472036F28300A9ED33 /* ServiceEntry.TypeForwarding.swift in Sources */, - 9880E70E1C09EE2900ED5293 /* FunctionType.swift in Sources */, - CD3B32971DD6126E00B208A3 /* ObjectScope.Standard.swift in Sources */, - 985BAFA91B625E0F0055F998 /* ServiceEntry.swift in Sources */, - CD89E34D2037016700A9ED33 /* Behavior.swift in Sources */, - 984774F01C02F25D0092A757 /* SynchronizedResolver.swift in Sources */, - CD3C2CDF1D98E47000863421 /* DebugHelper.swift in Sources */, - 98B012BF1B82F68E00053A32 /* Resolver.swift in Sources */, - CD3B32921DD6121500B208A3 /* InstanceStorage.swift in Sources */, - 981899E41B5FFE5800C702D0 /* Container.swift in Sources */, - 98B012B81B82D67300053A32 /* Container.Arguments.swift in Sources */, - 9884E2A71B60B77400120259 /* ServiceKey.swift in Sources */, - 9819701F1B6145D600EEB942 /* ObjectScope.swift in Sources */, - 984BE3131CDA3FCF00BCF2AC /* _Resolver.swift in Sources */, - 984774FA1C02F5A50092A757 /* SynchronizedResolver.Arguments.swift in Sources */, - CDBD0E6F2035EEBF0030F566 /* Container.TypeForwarding.swift in Sources */, - CDBBACF61D9EAD60002F5EF9 /* Container.Logging.swift in Sources */, - 98E550C31DEF066300BE6304 /* UnavailableItems.swift in Sources */, - 90B029751C18599200A6A521 /* Assembly.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 981ABE871B5FC9DF00294975 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 9855C5C51B689B7B00DADB0B /* Food.swift in Sources */, - 9855C5C81B689D9000DADB0B /* ServiceEntrySpec.swift in Sources */, - 9878C63C1B65CA8700CBEFEF /* Person.swift in Sources */, - CD8E362C20595ACD00F2A5CF /* ProviderSpec.swift in Sources */, - CD5E9A32205157E3009090F9 /* ContainerSpec.GraphCaching.swift in Sources */, - CD3C2CF21D98EF4A00863421 /* ContainerSpec.DebugHelper.swift in Sources */, - CDC4FCFD20502A9F0021C60F /* LazySpec.swift in Sources */, - 90B0298B1C186D5300A6A521 /* LoadAwareAssembly.swift in Sources */, - CD6A9F821EEFCB7A0087E851 /* ContainerSpec.CustomStringConvertible.swift in Sources */, - CD3B329C1DD61F2400B208A3 /* ContainerSpec.CustomScope.swift in Sources */, - 9848611C1B6F9B7000C07072 /* ContainerSpec.Arguments.swift in Sources */, - 90B0297F1C18666200A6A521 /* AssemblerSpec.swift in Sources */, - CD89E35220371D7900A9ED33 /* ContainerSpec.Behavior.swift in Sources */, - CDD44AD71DEEED1000916595 /* WeakStorageSpec.swift in Sources */, - 9884E2AA1B60C51C00120259 /* ServiceKeySpec.swift in Sources */, - 984774FF1C034C5C0092A757 /* SynchronizedResolverSpec.swift in Sources */, - 9878C6381B65C9E000CBEFEF /* Animal.swift in Sources */, - CD65F049205943D400FB43EE /* EmploymentAssembly.swift in Sources */, - 90B029831C18670000A6A521 /* BasicAssembly.swift in Sources */, - 981899E11B5FF88800C702D0 /* ContainerSpec.swift in Sources */, - 981577F11B675B7F00BF686B /* Circularity.swift in Sources */, - CDB19E52204ED97400D67123 /* BehaviorFakes.swift in Sources */, - CDBD0E682035EDF20030F566 /* ContainerSpec.TypeForwarding.swift in Sources */, - 9855C5BF1B686F5900DADB0B /* ContainerSpec.Circularity.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 985010C11BBE76D400A2CCFC /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 983B98331C06ECB2006A23D4 /* SpinLock.swift in Sources */, - CD89E34F20371C0200A9ED33 /* Behavior.swift in Sources */, - 9880E7101C09EE2900ED5293 /* FunctionType.swift in Sources */, - 985011221BBE7E8900A2CCFC /* ObjectScope.swift in Sources */, - CD3B32991DD6126E00B208A3 /* ObjectScope.Standard.swift in Sources */, - 985011251BBE7E8900A2CCFC /* Resolver.swift in Sources */, - 9850111E1BBE7E8900A2CCFC /* Container.swift in Sources */, - CD3C2CE11D98E47000863421 /* DebugHelper.swift in Sources */, - CDC4FCF6205028B00021C60F /* InstanceWrapper.swift in Sources */, - CD5E9A3820515898009090F9 /* GraphIdentifier.swift in Sources */, - 9850111F1BBE7E8900A2CCFC /* ServiceKey.swift in Sources */, - CD3B32941DD6123F00B208A3 /* InstanceStorage.swift in Sources */, - 90B0297B1C185B1600A6A521 /* Assembler.swift in Sources */, - 985011201BBE7E8900A2CCFC /* ServiceEntry.swift in Sources */, - 984BE3151CDA3FCF00BCF2AC /* _Resolver.swift in Sources */, - 985011241BBE7E8900A2CCFC /* Container.Arguments.swift in Sources */, - CDBD0E712035EEC20030F566 /* Container.TypeForwarding.swift in Sources */, - 984774F21C02F25D0092A757 /* SynchronizedResolver.swift in Sources */, - 90B029771C18599200A6A521 /* Assembly.swift in Sources */, - CDBBACF81D9EAD60002F5EF9 /* Container.Logging.swift in Sources */, - 984774FC1C02F5A50092A757 /* SynchronizedResolver.Arguments.swift in Sources */, - CD89E34A2036F2BF00A9ED33 /* ServiceEntry.TypeForwarding.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 98689C7A1BBFC7A50005C6D3 /* Sources */ = { + 771BFC6C22D5F83E00AFB237 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 90B0297D1C185B2200A6A521 /* Assembly.swift in Sources */, - CD89E35020371C0200A9ED33 /* Behavior.swift in Sources */, - 983B98341C06ECB2006A23D4 /* SpinLock.swift in Sources */, - 9880E7111C09EE2900ED5293 /* FunctionType.swift in Sources */, - CD3B329A1DD6126E00B208A3 /* ObjectScope.Standard.swift in Sources */, - 98689C9D1BBFC7EB0005C6D3 /* ObjectScope.swift in Sources */, - 984774F31C02F25D0092A757 /* SynchronizedResolver.swift in Sources */, - CD3C2CE21D98E47000863421 /* DebugHelper.swift in Sources */, - CDC4FCF7205028B00021C60F /* InstanceWrapper.swift in Sources */, - CD5E9A3920515898009090F9 /* GraphIdentifier.swift in Sources */, - 98689CA01BBFC7EB0005C6D3 /* Resolver.swift in Sources */, - 98689C991BBFC7EB0005C6D3 /* Container.swift in Sources */, - CD3B32951DD6124000B208A3 /* InstanceStorage.swift in Sources */, - 98689C9A1BBFC7EB0005C6D3 /* ServiceKey.swift in Sources */, - 90B0297C1C185B1600A6A521 /* Assembler.swift in Sources */, - 98689C9B1BBFC7EB0005C6D3 /* ServiceEntry.swift in Sources */, - CDBD0E722035EEC20030F566 /* Container.TypeForwarding.swift in Sources */, - 984BE3161CDA3FCF00BCF2AC /* _Resolver.swift in Sources */, - 98689C9F1BBFC7EB0005C6D3 /* Container.Arguments.swift in Sources */, - CDBBACF91D9EAD60002F5EF9 /* Container.Logging.swift in Sources */, - 984774FD1C02F5A50092A757 /* SynchronizedResolver.Arguments.swift in Sources */, - CD89E34B2036F2C000A9ED33 /* ServiceEntry.TypeForwarding.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; - 98689C841BBFC7A60005C6D3 /* Sources */ = { + 771BFC7522D5F83E00AFB237 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 98689CBB1BBFD5110005C6D3 /* ContainerSpec.Arguments.swift in Sources */, - 98689CBE1BBFD5110005C6D3 /* ServiceEntrySpec.swift in Sources */, - 98689CBC1BBFD5110005C6D3 /* ContainerSpec.Circularity.swift in Sources */, - CD8E362E20595ACD00F2A5CF /* ProviderSpec.swift in Sources */, - CD5E9A34205157E3009090F9 /* ContainerSpec.GraphCaching.swift in Sources */, - CD3C2CF41D98EF4A00863421 /* ContainerSpec.DebugHelper.swift in Sources */, - CDC4FCFF20502AA10021C60F /* LazySpec.swift in Sources */, - 98689CB61BBFD5110005C6D3 /* Person.swift in Sources */, - CD6A9F841EEFCB7A0087E851 /* ContainerSpec.CustomStringConvertible.swift in Sources */, - CD3B329E1DD61F2400B208A3 /* ContainerSpec.CustomScope.swift in Sources */, - 90B0298D1C186D5300A6A521 /* LoadAwareAssembly.swift in Sources */, - 98689CBA1BBFD5110005C6D3 /* ContainerSpec.swift in Sources */, - CD89E35420371D7900A9ED33 /* ContainerSpec.Behavior.swift in Sources */, - CDD44AD91DEEED1000916595 /* WeakStorageSpec.swift in Sources */, - 90B029811C18666200A6A521 /* AssemblerSpec.swift in Sources */, - 98689CBD1BBFD5110005C6D3 /* ServiceKeySpec.swift in Sources */, - 984775011C034C5C0092A757 /* SynchronizedResolverSpec.swift in Sources */, - CD65F04B205943D400FB43EE /* EmploymentAssembly.swift in Sources */, - 98689CB81BBFD5110005C6D3 /* Food.swift in Sources */, - 90B029851C18670000A6A521 /* BasicAssembly.swift in Sources */, - 98689CB71BBFD5110005C6D3 /* Animal.swift in Sources */, - CDB19E54204ED97400D67123 /* BehaviorFakes.swift in Sources */, - CDBD0E6A2035EDF20030F566 /* ContainerSpec.TypeForwarding.swift in Sources */, - 98689CB91BBFD5110005C6D3 /* Circularity.swift in Sources */, + 771BFC7F22D5F83E00AFB237 /* SwinjectTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ - 981899C81B5FE63F00C702D0 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = 981899BB1B5FE63F00C702D0 /* Swinject-OSX */; - targetProxy = 981899C71B5FE63F00C702D0 /* PBXContainerItemProxy */; - }; - 981ABE8E1B5FC9DF00294975 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = 981ABE801B5FC9DF00294975 /* Swinject-iOS */; - targetProxy = 981ABE8D1B5FC9DF00294975 /* PBXContainerItemProxy */; - }; - 98689C8B1BBFC7A60005C6D3 /* PBXTargetDependency */ = { + 771BFC7C22D5F83E00AFB237 /* PBXTargetDependency */ = { isa = PBXTargetDependency; - target = 98689C7E1BBFC7A50005C6D3 /* Swinject-tvOS */; - targetProxy = 98689C8A1BBFC7A60005C6D3 /* PBXContainerItemProxy */; + target = 771BFC6F22D5F83E00AFB237 /* Swinject-OSX */; + targetProxy = 771BFC7B22D5F83E00AFB237 /* PBXContainerItemProxy */; }; /* End PBXTargetDependency section */ /* Begin XCBuildConfiguration section */ - 981899CD1B5FE64000C702D0 /* Debug */ = { + 771BFC8222D5F83E00AFB237 /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 98AA74591BB70CBB00E2F48A /* Mac-Framework.xcconfig */; - buildSettings = { - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - INFOPLIST_FILE = Sources/Info.plist; - PRODUCT_BUNDLE_IDENTIFIER = "com.el-eleven.Swinject"; - }; - name = Debug; - }; - 981899CE1B5FE64000C702D0 /* Release */ = { - isa = XCBuildConfiguration; - baseConfigurationReference = 98AA74591BB70CBB00E2F48A /* Mac-Framework.xcconfig */; - buildSettings = { - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - INFOPLIST_FILE = Sources/Info.plist; - PRODUCT_BUNDLE_IDENTIFIER = "com.el-eleven.Swinject"; - }; - name = Release; - }; - 981899CF1B5FE64000C702D0 /* Debug */ = { - isa = XCBuildConfiguration; - baseConfigurationReference = 98AA74561BB70CBB00E2F48A /* Mac-Application.xcconfig */; - buildSettings = { - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)/Carthage/Build/Mac", - ); - INFOPLIST_FILE = Tests/SwinjectTests/Info.plist; - PRODUCT_BUNDLE_IDENTIFIER = "com.el-eleven.SwinjectTests"; - PRODUCT_NAME = "$(PROJECT_NAME)Tests"; - }; - name = Debug; - }; - 981899D01B5FE64000C702D0 /* Release */ = { - isa = XCBuildConfiguration; - baseConfigurationReference = 98AA74561BB70CBB00E2F48A /* Mac-Application.xcconfig */; - buildSettings = { - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)/Carthage/Build/Mac", - ); - INFOPLIST_FILE = Tests/SwinjectTests/Info.plist; - PRODUCT_BUNDLE_IDENTIFIER = "com.el-eleven.SwinjectTests"; - PRODUCT_NAME = "$(PROJECT_NAME)Tests"; - }; - name = Release; - }; - 981ABE931B5FC9DF00294975 /* Debug */ = { - isa = XCBuildConfiguration; - baseConfigurationReference = 98AA74481BB70CBB00E2F48A /* Debug.xcconfig */; buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; CURRENT_PROJECT_VERSION = 1; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; - MACOSX_DEPLOYMENT_TARGET = 10.10; - MTL_ENABLE_DEBUG_INFO = YES; - SWIFT_VERSION = 4.2; - TARGETED_DEVICE_FAMILY = "1,2"; - TVOS_DEPLOYMENT_TARGET = 9.0; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.14; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; - WATCHOS_DEPLOYMENT_TARGET = 2.0; }; name = Debug; }; - 981ABE941B5FC9DF00294975 /* Release */ = { + 771BFC8322D5F83E00AFB237 /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 98AA744A1BB70CBB00E2F48A /* Release.xcconfig */; buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; CURRENT_PROJECT_VERSION = 1; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; - MACOSX_DEPLOYMENT_TARGET = 10.10; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.14; MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = macosx; SWIFT_COMPILATION_MODE = wholemodule; - SWIFT_VERSION = 4.2; - TARGETED_DEVICE_FAMILY = "1,2"; - TVOS_DEPLOYMENT_TARGET = 9.0; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + SWIFT_VERSION = 5.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; - WATCHOS_DEPLOYMENT_TARGET = 2.0; }; name = Release; }; - 981ABE961B5FC9DF00294975 /* Debug */ = { + 771BFC8522D5F83E00AFB237 /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 98AA74531BB70CBB00E2F48A /* iOS-Framework.xcconfig */; buildSettings = { + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; - FRAMEWORK_SEARCH_PATHS = ( + DYLIB_INSTALL_NAME_BASE = "@rpath"; + INFOPLIST_FILE = "$(SRCROOT)/Sources/Info.plist"; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", - "$(PROJECT_DIR)/Carthage/Build/iOS", + "@executable_path/../Frameworks", + "@loader_path/Frameworks", ); - INFOPLIST_FILE = Sources/Info.plist; PRODUCT_BUNDLE_IDENTIFIER = "com.el-eleven.Swinject"; + PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SKIP_INSTALL = YES; }; name = Debug; }; - 981ABE971B5FC9DF00294975 /* Release */ = { + 771BFC8622D5F83E00AFB237 /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 98AA74531BB70CBB00E2F48A /* iOS-Framework.xcconfig */; buildSettings = { + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; - FRAMEWORK_SEARCH_PATHS = ( + DYLIB_INSTALL_NAME_BASE = "@rpath"; + INFOPLIST_FILE = "$(SRCROOT)/Sources/Info.plist"; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", - "$(PROJECT_DIR)/Carthage/Build/iOS", + "@executable_path/../Frameworks", + "@loader_path/Frameworks", ); - INFOPLIST_FILE = Sources/Info.plist; PRODUCT_BUNDLE_IDENTIFIER = "com.el-eleven.Swinject"; + PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SKIP_INSTALL = YES; }; name = Release; }; - 981ABE991B5FC9DF00294975 /* Debug */ = { + 771BFC8822D5F83E00AFB237 /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 98AA74511BB70CBB00E2F48A /* iOS-Application.xcconfig */; buildSettings = { + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", - "$(PROJECT_DIR)/Carthage/Build/iOS", + "$(PROJECT_DIR)/Carthage/Build/Mac", ); - INFOPLIST_FILE = Tests/SwinjectTests/Info.plist; - PRODUCT_BUNDLE_IDENTIFIER = "com.el-eleven.SwinjectTests"; - PRODUCT_NAME = "$(PROJECT_NAME)Tests"; - }; - name = Debug; - }; - 981ABE9A1B5FC9DF00294975 /* Release */ = { - isa = XCBuildConfiguration; - baseConfigurationReference = 98AA74511BB70CBB00E2F48A /* iOS-Application.xcconfig */; - buildSettings = { - FRAMEWORK_SEARCH_PATHS = ( + INFOPLIST_FILE = Tests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", - "$(PROJECT_DIR)/Carthage/Build/iOS", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", ); - INFOPLIST_FILE = Tests/SwinjectTests/Info.plist; PRODUCT_BUNDLE_IDENTIFIER = "com.el-eleven.SwinjectTests"; - PRODUCT_NAME = "$(PROJECT_NAME)Tests"; - }; - name = Release; - }; - 985010CC1BBE76D400A2CCFC /* Debug */ = { - isa = XCBuildConfiguration; - baseConfigurationReference = 985010BF1BBE76AB00A2CCFC /* watchOS-Framework.xcconfig */; - buildSettings = { - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - INFOPLIST_FILE = Sources/Info.plist; - PRODUCT_BUNDLE_IDENTIFIER = "com.el-eleven.Swinject"; - TARGETED_DEVICE_FAMILY = 4; + PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Debug; }; - 985010CD1BBE76D400A2CCFC /* Release */ = { - isa = XCBuildConfiguration; - baseConfigurationReference = 985010BF1BBE76AB00A2CCFC /* watchOS-Framework.xcconfig */; - buildSettings = { - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - INFOPLIST_FILE = Sources/Info.plist; - PRODUCT_BUNDLE_IDENTIFIER = "com.el-eleven.Swinject"; - TARGETED_DEVICE_FAMILY = 4; - }; - name = Release; - }; - 98689C911BBFC7A60005C6D3 /* Debug */ = { + 771BFC8922D5F83E00AFB237 /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 98689C781BBFC77F0005C6D3 /* tvOS-Framework.xcconfig */; - buildSettings = { - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - INFOPLIST_FILE = Sources/Info.plist; - PRODUCT_BUNDLE_IDENTIFIER = "com.el-eleven.Swinject"; - TARGETED_DEVICE_FAMILY = 3; - }; - name = Debug; - }; - 98689C921BBFC7A60005C6D3 /* Release */ = { - isa = XCBuildConfiguration; - baseConfigurationReference = 98689C781BBFC77F0005C6D3 /* tvOS-Framework.xcconfig */; - buildSettings = { - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - INFOPLIST_FILE = Sources/Info.plist; - PRODUCT_BUNDLE_IDENTIFIER = "com.el-eleven.Swinject"; - TARGETED_DEVICE_FAMILY = 3; - }; - name = Release; - }; - 98689C951BBFC7A60005C6D3 /* Debug */ = { - isa = XCBuildConfiguration; - baseConfigurationReference = 98689C761BBFC77F0005C6D3 /* tvOS-Application.xcconfig */; buildSettings = { + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", - "$(PROJECT_DIR)/Carthage/Build/tvOS", + "$(PROJECT_DIR)/Carthage/Build/Mac", ); - INFOPLIST_FILE = Tests/SwinjectTests/Info.plist; - PRODUCT_BUNDLE_IDENTIFIER = "com.el-eleven.SwinjectTests"; - PRODUCT_NAME = "$(PROJECT_NAME)Tests"; - }; - name = Debug; - }; - 98689C961BBFC7A60005C6D3 /* Release */ = { - isa = XCBuildConfiguration; - baseConfigurationReference = 98689C761BBFC77F0005C6D3 /* tvOS-Application.xcconfig */; - buildSettings = { - FRAMEWORK_SEARCH_PATHS = ( + INFOPLIST_FILE = Tests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", - "$(PROJECT_DIR)/Carthage/Build/tvOS", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", ); - INFOPLIST_FILE = Tests/SwinjectTests/Info.plist; PRODUCT_BUNDLE_IDENTIFIER = "com.el-eleven.SwinjectTests"; - PRODUCT_NAME = "$(PROJECT_NAME)Tests"; + PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ - 981899D11B5FE64000C702D0 /* Build configuration list for PBXNativeTarget "Swinject-OSX" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 981899CD1B5FE64000C702D0 /* Debug */, - 981899CE1B5FE64000C702D0 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 981899D21B5FE64000C702D0 /* Build configuration list for PBXNativeTarget "Swinject-OSXTests" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 981899CF1B5FE64000C702D0 /* Debug */, - 981899D01B5FE64000C702D0 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 981ABE7B1B5FC9DF00294975 /* Build configuration list for PBXProject "Swinject" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 981ABE931B5FC9DF00294975 /* Debug */, - 981ABE941B5FC9DF00294975 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 981ABE951B5FC9DF00294975 /* Build configuration list for PBXNativeTarget "Swinject-iOS" */ = { + 771BFC6A22D5F83E00AFB237 /* Build configuration list for PBXProject "Swinject" */ = { isa = XCConfigurationList; buildConfigurations = ( - 981ABE961B5FC9DF00294975 /* Debug */, - 981ABE971B5FC9DF00294975 /* Release */, + 771BFC8222D5F83E00AFB237 /* Debug */, + 771BFC8322D5F83E00AFB237 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - 981ABE981B5FC9DF00294975 /* Build configuration list for PBXNativeTarget "Swinject-iOSTests" */ = { + 771BFC8422D5F83E00AFB237 /* Build configuration list for PBXNativeTarget "Swinject-OSX" */ = { isa = XCConfigurationList; buildConfigurations = ( - 981ABE991B5FC9DF00294975 /* Debug */, - 981ABE9A1B5FC9DF00294975 /* Release */, + 771BFC8522D5F83E00AFB237 /* Debug */, + 771BFC8622D5F83E00AFB237 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - 985010CB1BBE76D400A2CCFC /* Build configuration list for PBXNativeTarget "Swinject-watchOS" */ = { + 771BFC8722D5F83E00AFB237 /* Build configuration list for PBXNativeTarget "SwinjectTests-OSX" */ = { isa = XCConfigurationList; buildConfigurations = ( - 985010CC1BBE76D400A2CCFC /* Debug */, - 985010CD1BBE76D400A2CCFC /* Release */, + 771BFC8822D5F83E00AFB237 /* Debug */, + 771BFC8922D5F83E00AFB237 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - 98689C901BBFC7A60005C6D3 /* Build configuration list for PBXNativeTarget "Swinject-tvOS" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 98689C911BBFC7A60005C6D3 /* Debug */, - 98689C921BBFC7A60005C6D3 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; +/* End XCConfigurationList section */ + +/* Begin XCRemoteSwiftPackageReference section */ + 771BFC8F22D600B700AFB237 /* XCRemoteSwiftPackageReference "Nimble" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/Quick/Nimble"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 8.0.2; + }; }; - 98689C941BBFC7A60005C6D3 /* Build configuration list for PBXNativeTarget "Swinject-tvOSTests" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 98689C951BBFC7A60005C6D3 /* Debug */, - 98689C961BBFC7A60005C6D3 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; + 771BFC9222D600CC00AFB237 /* XCRemoteSwiftPackageReference "Quick" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/Quick/Quick"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 2.1.0; + }; }; -/* End XCConfigurationList section */ +/* End XCRemoteSwiftPackageReference section */ + +/* Begin XCSwiftPackageProductDependency section */ + 771BFC9022D600B700AFB237 /* Nimble */ = { + isa = XCSwiftPackageProductDependency; + package = 771BFC8F22D600B700AFB237 /* XCRemoteSwiftPackageReference "Nimble" */; + productName = Nimble; + }; + 771BFC9322D600CC00AFB237 /* Quick */ = { + isa = XCSwiftPackageProductDependency; + package = 771BFC9222D600CC00AFB237 /* XCRemoteSwiftPackageReference "Quick" */; + productName = Quick; + }; +/* End XCSwiftPackageProductDependency section */ }; - rootObject = 981ABE781B5FC9DF00294975 /* Project object */; + rootObject = 771BFC6722D5F83E00AFB237 /* Project object */; } diff --git a/Swinject.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Swinject.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved new file mode 100644 index 00000000..9c4b5d95 --- /dev/null +++ b/Swinject.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -0,0 +1,25 @@ +{ + "object": { + "pins": [ + { + "package": "Nimble", + "repositoryURL": "https://github.com/Quick/Nimble", + "state": { + "branch": null, + "revision": "f8657642dfdec9973efc79cc68bcef43a653a2bc", + "version": "8.0.2" + } + }, + { + "package": "Quick", + "repositoryURL": "https://github.com/Quick/Quick", + "state": { + "branch": null, + "revision": "94df9b449508344667e5afc7e80f8bcbff1e4c37", + "version": "2.1.0" + } + } + ] + }, + "version": 1 +} diff --git a/Swinject.xcodeproj/xcshareddata/xcschemes/Swinject-OSX.xcscheme b/Swinject.xcodeproj/xcshareddata/xcschemes/Swinject-OSX.xcscheme index 0ce4c3fc..aa8790d9 100644 --- a/Swinject.xcodeproj/xcshareddata/xcschemes/Swinject-OSX.xcscheme +++ b/Swinject.xcodeproj/xcshareddata/xcschemes/Swinject-OSX.xcscheme @@ -1,6 +1,6 @@ @@ -26,31 +26,19 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - codeCoverageEnabled = "YES" shouldUseLaunchSchemeArgsEnv = "YES"> - - - - - - - - - - - - diff --git a/Swinject.xcodeproj/xcshareddata/xcschemes/Swinject-iOS.xcscheme b/Swinject.xcodeproj/xcshareddata/xcschemes/Swinject-iOS.xcscheme deleted file mode 100644 index 5cde3a43..00000000 --- a/Swinject.xcodeproj/xcshareddata/xcschemes/Swinject-iOS.xcscheme +++ /dev/null @@ -1,100 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Swinject.xcodeproj/xcshareddata/xcschemes/Swinject-tvOS.xcscheme b/Swinject.xcodeproj/xcshareddata/xcschemes/Swinject-tvOS.xcscheme deleted file mode 100644 index dcb3f794..00000000 --- a/Swinject.xcodeproj/xcshareddata/xcschemes/Swinject-tvOS.xcscheme +++ /dev/null @@ -1,99 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Swinject.xcodeproj/xcshareddata/xcschemes/Swinject-watchOS.xcscheme b/Swinject.xcodeproj/xcshareddata/xcschemes/Swinject-watchOS.xcscheme deleted file mode 100644 index ff392abd..00000000 --- a/Swinject.xcodeproj/xcshareddata/xcschemes/Swinject-watchOS.xcscheme +++ /dev/null @@ -1,80 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Tests/SwinjectTests/Info.plist b/Tests/Info.plist similarity index 83% rename from Tests/SwinjectTests/Info.plist rename to Tests/Info.plist index 88467e4f..64d65ca4 100644 --- a/Tests/SwinjectTests/Info.plist +++ b/Tests/Info.plist @@ -3,7 +3,7 @@ CFBundleDevelopmentRegion - en + $(DEVELOPMENT_LANGUAGE) CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier @@ -13,11 +13,9 @@ CFBundleName $(PRODUCT_NAME) CFBundlePackageType - BNDL + $(PRODUCT_BUNDLE_PACKAGE_TYPE) CFBundleShortVersionString - 2.6.2 - CFBundleSignature - ???? + 1.0 CFBundleVersion 1 diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift deleted file mode 100755 index 3c4f3bba..00000000 --- a/Tests/LinuxMain.swift +++ /dev/null @@ -1,24 +0,0 @@ -// -// LinuxMain.swift -// Swinject -// -// Created by Yoichi Tagaya on 11/25/16. -// Copyright © 2016 Swinject Contributors. All rights reserved. -// - -import XCTest -import Quick - -@testable import SwinjectTests - -Quick.QCKMain([ - AssemblerSpec.self, - ContainerSpec.self, - ContainerSpec_Arguments.self, - ContainerSpec_Circularity.self, - ContainerSpec_DebugHelper.self, - ContainerSpec_CustomScope.self, - SynchronizedResolverSpec.self, - ServiceKeySpec.self, - ServiceEntrySpec.self -]) diff --git a/Tests/SwinjectTests.swift b/Tests/SwinjectTests.swift new file mode 100644 index 00000000..8b983cb6 --- /dev/null +++ b/Tests/SwinjectTests.swift @@ -0,0 +1,34 @@ +// +// SwinjectTests.swift +// SwinjectTests +// +// Created by Jakub Vano on 10/07/2019. +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +import XCTest +@testable import Swinject + +class SwinjectTests: XCTestCase { + + override func setUp() { + // Put setup code here. This method is called before the invocation of each test method in the class. + } + + override func tearDown() { + // Put teardown code here. This method is called after the invocation of each test method in the class. + } + + func testExample() { + // This is an example of a functional test case. + // Use XCTAssert and related functions to verify your tests produce the correct results. + } + + func testPerformanceExample() { + // This is an example of a performance test case. + self.measure { + // Put the code you want to measure the time of here. + } + } + +} diff --git a/Tests/SwinjectTests/Animal.swift b/Tests/SwinjectTests/Animal.swift deleted file mode 100644 index c4347372..00000000 --- a/Tests/SwinjectTests/Animal.swift +++ /dev/null @@ -1,49 +0,0 @@ -// -// Animal.swift -// Swinject -// -// Created by Yoichi Tagaya on 7/27/15. -// Copyright © 2015 Swinject Contributors. All rights reserved. -// - -import Foundation - -internal protocol Animal { - var name: String? { get set } -} - -internal class Cat: Animal { - var name: String? - var sleeping = false - var favoriteFood: Food? - - init() { - } - - init(name: String) { - self.name = name - } - - init(name: String, sleeping: Bool) { - self.name = name - self.sleeping = sleeping - } -} - -internal class Siamese: Cat { -} - -internal class Dog: Animal { - var name: String? - - init() { - } - - init(name: String) { - self.name = name - } -} - -internal struct Turtle: Animal { - var name: String? -} diff --git a/Tests/SwinjectTests/AssemblerSpec.swift b/Tests/SwinjectTests/AssemblerSpec.swift deleted file mode 100644 index ea429f4f..00000000 --- a/Tests/SwinjectTests/AssemblerSpec.swift +++ /dev/null @@ -1,336 +0,0 @@ -// -// AssemblerSpec.swift -// Swinject -// -// Created by mike.owens on 12/9/15. -// Copyright © 2015 Swinject Contributors. All rights reserved. -// -// swiftlint:disable function_body_length -// swiftlint:disable type_body_length - -import Foundation -import Quick -import Nimble -@testable import Swinject - -class AssemblerSpec: QuickSpec { - override func spec() { - - describe("Assembler basic init") { - it("can assembly a single container") { - let assembler = Assembler([ - AnimalAssembly() - ]) - let cat = assembler.resolver.resolve(Animal.self) - expect(cat).toNot(beNil()) - expect(cat!.name) == "Whiskers" - - let sushi = assembler.resolver.resolve(Food.self) - expect(sushi).to(beNil()) - } - - it("can assembly a container with nil parent") { - let assembler = Assembler(parentAssembler: nil) - - let sushi = assembler.resolver.resolve(Food.self) - expect(sushi).to(beNil()) - } - - it("can assembly a container with nil parent and assemblies") { - let assembler = Assembler([ - AnimalAssembly() - ], parent: nil) - let cat = assembler.resolver.resolve(Animal.self) - expect(cat).toNot(beNil()) - expect(cat!.name) == "Whiskers" - - let sushi = assembler.resolver.resolve(Food.self) - expect(sushi).to(beNil()) - } - - it("uses injected default object scope") { - let assembler = Assembler([], parent: nil, defaultObjectScope: ObjectScope.container) - - assembler.apply(assembly: ContainerSpyAssembly()) - let container = assembler.resolver.resolve(Container.self) - let serviceEntry = container?.register(Animal.self) { _ in Siamese(name: "Siam") } - - expect(serviceEntry?.objectScope) === ObjectScope.container - } - - it("uses graph scope if no default object scope is injected") { - let assembler = Assembler([], parent: nil) - - assembler.apply(assembly: ContainerSpyAssembly()) - let container = assembler.resolver.resolve(Container.self) - let serviceEntry = container?.register(Animal.self) { _ in Siamese(name: "Siam") } - - expect(serviceEntry?.objectScope) === ObjectScope.graph - } - - it("can assembly a multiple container") { - let assembler = Assembler([ - AnimalAssembly(), - FoodAssembly() - ]) - let cat = assembler.resolver.resolve(Animal.self) - expect(cat).toNot(beNil()) - expect(cat!.name) == "Whiskers" - - let sushi = assembler.resolver.resolve(Food.self) - expect(sushi).toNot(beNil()) - expect(sushi is Sushi) == true - } - - it("can assembly a multiple container with inter dependencies") { - let assembler = Assembler([ - AnimalAssembly(), - FoodAssembly(), - PersonAssembly() - ]) - let petOwner = assembler.resolver.resolve(PetOwner.self) - expect(petOwner).toNot(beNil()) - - let cat = petOwner!.pet - expect(cat).toNot(beNil()) - expect(cat!.name) == "Whiskers" - - let sushi = petOwner!.favoriteFood - expect(sushi).toNot(beNil()) - expect(sushi is Sushi) == true - } - - it("can assembly a multiple container with inter dependencies in any order") { - let assembler = Assembler([ - PersonAssembly(), - AnimalAssembly(), - FoodAssembly() - ]) - let petOwner = assembler.resolver.resolve(PetOwner.self) - expect(petOwner).toNot(beNil()) - - let cat = petOwner!.pet - expect(cat).toNot(beNil()) - expect(cat!.name) == "Whiskers" - - let sushi = petOwner!.favoriteFood - expect(sushi).toNot(beNil()) - expect(sushi is Sushi) == true - } - } - - describe("Assembler lazy build") { - it("can assembly a single container") { - let assembler = Assembler([]) - var cat = assembler.resolver.resolve(Animal.self) - expect(cat).to(beNil()) - - assembler.apply(assembly: AnimalAssembly()) - - cat = assembler.resolver.resolve(Animal.self) - expect(cat).toNot(beNil()) - expect(cat!.name) == "Whiskers" - } - - it("can assembly a single load aware container") { - let assembler = Assembler([]) - var cat = assembler.resolver.resolve(Animal.self) - expect(cat).to(beNil()) - - let loadAwareAssembly = LoadAwareAssembly { resolver in - let cat = resolver.resolve(Animal.self) - expect(cat).toNot(beNil()) - expect(cat!.name) == "Bojangles" - } - - expect(loadAwareAssembly.loaded) == false - assembler.apply(assembly: loadAwareAssembly) - expect(loadAwareAssembly.loaded) == true - - cat = assembler.resolver.resolve(Animal.self) - expect(cat).toNot(beNil()) - expect(cat!.name) == "Bojangles" - } - - it("can assembly a multiple containers 1 by 1") { - let assembler = Assembler([]) - var cat = assembler.resolver.resolve(Animal.self) - expect(cat).to(beNil()) - - var sushi = assembler.resolver.resolve(Food.self) - expect(sushi).to(beNil()) - - assembler.apply(assembly: AnimalAssembly()) - - cat = assembler.resolver.resolve(Animal.self) - expect(cat).toNot(beNil()) - expect(cat!.name) == "Whiskers" - - sushi = assembler.resolver.resolve(Food.self) - expect(sushi).to(beNil()) - - assembler.apply(assembly: FoodAssembly()) - - sushi = assembler.resolver.resolve(Food.self) - expect(sushi).toNot(beNil()) - } - - it("can assembly a multiple containers at once") { - let assembler = Assembler([]) - var cat = assembler.resolver.resolve(Animal.self) - expect(cat).to(beNil()) - - var sushi = assembler.resolver.resolve(Food.self) - expect(sushi).to(beNil()) - - assembler.apply(assemblies: [ - AnimalAssembly(), - FoodAssembly() - ]) - - cat = assembler.resolver.resolve(Animal.self) - expect(cat).toNot(beNil()) - expect(cat!.name) == "Whiskers" - - sushi = assembler.resolver.resolve(Food.self) - expect(sushi).toNot(beNil()) - } - } - - describe("Assembler load aware") { - it("can assembly a single container") { - let loadAwareAssembly = LoadAwareAssembly { resolver in - let cat = resolver.resolve(Animal.self) - expect(cat).toNot(beNil()) - expect(cat!.name) == "Bojangles" - } - - expect(loadAwareAssembly.loaded) == false - let assembler = Assembler([ - loadAwareAssembly - ]) - expect(loadAwareAssembly.loaded) == true - - let cat = assembler.resolver.resolve(Animal.self) - expect(cat).toNot(beNil()) - expect(cat!.name) == "Bojangles" - } - - it("can assembly a multiple container") { - let loadAwareAssembly = LoadAwareAssembly { resolver in - let cat = resolver.resolve(Animal.self) - expect(cat).toNot(beNil()) - expect(cat!.name) == "Bojangles" - - let sushi = resolver.resolve(Food.self) - expect(sushi).toNot(beNil()) - } - - expect(loadAwareAssembly.loaded) == false - let assembler = Assembler([ - loadAwareAssembly, - FoodAssembly() - ]) - expect(loadAwareAssembly.loaded) == true - - let cat = assembler.resolver.resolve(Animal.self) - expect(cat).toNot(beNil()) - expect(cat!.name) == "Bojangles" - - let sushi = assembler.resolver.resolve(Food.self) - expect(sushi).toNot(beNil()) - } - } - - describe("Empty Assembler") { - it("can create an empty assembler and build it") { - let assembler = Assembler() - - var cat = assembler.resolver.resolve(Animal.self) - expect(cat).to(beNil()) - - assembler.apply(assembly: AnimalAssembly()) - - cat = assembler.resolver.resolve(Animal.self) - expect(cat).toNot(beNil()) - expect(cat!.name) == "Whiskers" - } - } - - describe("Child Assembler") { - it("can be empty") { - let assembler = Assembler([ - AnimalAssembly() - ]) - - let childAssembler = Assembler(parentAssembler: assembler) - - let cat = assembler.resolver.resolve(Animal.self) - expect(cat).toNot(beNil()) - - let sushi = assembler.resolver.resolve(Food.self) - expect(sushi).to(beNil()) - - let childCat = childAssembler.resolver.resolve(Animal.self) - expect(childCat).toNot(beNil()) - - let childSushi = childAssembler.resolver.resolve(Food.self) - expect(childSushi).to(beNil()) - } - - it("can't give entities to parent") { - let assembler = Assembler() - let childAssembler = Assembler([ - AnimalAssembly() - ], parent: assembler) - - let cat = assembler.resolver.resolve(Animal.self) - expect(cat).to(beNil()) - - let childCat = childAssembler.resolver.resolve(Animal.self) - expect(childCat).toNot(beNil()) - } - - it("uses injected default object scope") { - let parentContainer = Container() - let parentAssembler = Assembler(container: parentContainer) - let childAssembler = Assembler(parentAssembler: parentAssembler, - defaultObjectScope: ObjectScope.container) - - childAssembler.apply(assembly: ContainerSpyAssembly()) - let container = childAssembler.resolver.resolve(Container.self) - let serviceEntry = container?.register(Animal.self) { _ in Siamese(name: "Siam") } - - expect(serviceEntry?.objectScope) === ObjectScope.container - } - - it("has default object scope of graph type") { - let parentContainer = Container() - let parentAssembler = Assembler(container: parentContainer) - let childAssembler = Assembler(parentAssembler: parentAssembler) - - childAssembler.apply(assembly: ContainerSpyAssembly()) - let container = childAssembler.resolver.resolve(Container.self) - let serviceEntry = container?.register(Animal.self) { _ in Siamese(name: "Siam") } - - expect(serviceEntry?.objectScope) === ObjectScope.graph - } - - it("uses given list of behaviors to container") { - let spy = BehaviorSpy() - let assembler = Assembler(parentAssembler: Assembler(), behaviors: [spy]) - - assembler.apply(assembly: ContainerSpyAssembly()) - - expect(spy.entries).to(haveCount(1)) - } - - it("uses given list of behaviors before applying assemblies") { - let spy = BehaviorSpy() - _ = Assembler([ContainerSpyAssembly()], parent: Assembler(), behaviors: [spy]) - - expect(spy.entries).to(haveCount(1)) - } - } - } -} diff --git a/Tests/SwinjectTests/BasicAssembly.swift b/Tests/SwinjectTests/BasicAssembly.swift deleted file mode 100644 index 799f32e3..00000000 --- a/Tests/SwinjectTests/BasicAssembly.swift +++ /dev/null @@ -1,47 +0,0 @@ -// -// BasicAssembly.swift -// Swinject -// -// Created by mike.owens on 12/9/15. -// Copyright © 2015 Swinject Contributors. All rights reserved. -// - -import Swinject - -class AnimalAssembly: Assembly { - - func assemble(container: Container) { - container.register(Animal.self) { _ in - return Cat(name: "Whiskers") - } - } -} - -class FoodAssembly: Assembly { - - func assemble(container: Container) { - container.register(Food.self) { _ in - return Sushi() - } - } -} - -class PersonAssembly: Assembly { - - func assemble(container: Container) { - container.register(PetOwner.self) { r in - let definition = PetOwner() - definition.favoriteFood = r.resolve(Food.self) - definition.pet = r.resolve(Animal.self) - return definition - } - } -} - -class ContainerSpyAssembly: Assembly { - func assemble(container: Container) { - container.register(Container.self) { _ in - return container - } - } -} diff --git a/Tests/SwinjectTests/BehaviorFakes.swift b/Tests/SwinjectTests/BehaviorFakes.swift deleted file mode 100644 index 92404911..00000000 --- a/Tests/SwinjectTests/BehaviorFakes.swift +++ /dev/null @@ -1,26 +0,0 @@ -// -// BehaviorFakes.swift -// Swinject -// -// Created by Jakub Vaňo on 06/03/2018. -// Copyright © 2018 Swinject Contributors. All rights reserved. -// - -@testable import Swinject - -class BehaviorSpy: Behavior { - var entries = [ServiceEntryProtocol]() - var names = [String?]() - var types = [Any.Type]() - - func container( - _ container: Container, - didRegisterType type: Type.Type, - toService entry: ServiceEntry, - withName name: String? - ) { - entries.append(entry) - names.append(name) - types.append(type) - } -} diff --git a/Tests/SwinjectTests/Circularity.swift b/Tests/SwinjectTests/Circularity.swift deleted file mode 100644 index 762c6108..00000000 --- a/Tests/SwinjectTests/Circularity.swift +++ /dev/null @@ -1,77 +0,0 @@ -// -// Circularity.swift -// Swinject -// -// Created by Yoichi Tagaya on 7/28/15. -// Copyright (c) 2015 Swinject Contributors. All rights reserved. -// - -import Foundation - -// MARK: Circular dependency of two objects -internal protocol ParentProtocol: AnyObject { } -internal protocol ChildProtocol: AnyObject { } - -internal class Parent: ParentProtocol { - var child: ChildProtocol? - - init() { - } - - init(child: ChildProtocol) { - self.child = child - } -} - -internal class Child: ChildProtocol { - weak var parent: ParentProtocol? -} - -// MARK: - Circular dependency of more than two objects -internal protocol A: AnyObject { } -internal protocol B: AnyObject { } -internal protocol C: AnyObject { } -internal protocol D: AnyObject { } - -internal class ADependingOnB: A { - var b: B? - - init() { - } - - init(b: B) { - self.b = b - } -} - -internal class BDependingOnC: B { - var c: C? - - init() { - } - - init(c: C) { - self.c = c - } -} - -internal class CDependingOnAD: C { - weak var a: A? - var d: D? - - init() { - } - - init(d: D) { - self.d = d - } -} - -internal class DDependingOnBC: D { - weak var b: B? - weak var c: C? -} - -internal class CDependingOnWeakB: C { - weak var b: B? -} diff --git a/Tests/SwinjectTests/ContainerSpec.Arguments.swift b/Tests/SwinjectTests/ContainerSpec.Arguments.swift deleted file mode 100644 index 404ab47f..00000000 --- a/Tests/SwinjectTests/ContainerSpec.Arguments.swift +++ /dev/null @@ -1,103 +0,0 @@ -// -// ContainerSpec.Arguments.swift -// Swinject -// -// Created by Yoichi Tagaya on 8/3/15. -// Copyright © 2015 Swinject Contributors. All rights reserved. -// -// swiftlint:disable function_body_length line_length - -import Quick -import Nimble -@testable import Swinject - -class ContainerSpec_Arguments: QuickSpec { - override func spec() { - var container: Container! - beforeEach { - container = Container() - } - - it("accepts 1 argument.") { - container.register(Animal.self) { _, arg1 in - Cat(name: arg1) - } - let animal = container.resolve( - Animal.self, - argument: "1") - expect(animal?.name) == "1" - } - it("accepts 2 arguments.") { - container.register(Animal.self) { _, arg1, arg2 in - Cat(name: arg1 + arg2) - } - let animal = container.resolve( - Animal.self, - arguments: "1", "2") - expect(animal?.name) == "12" - } - it("accepts 3 arguments.") { - container.register(Animal.self) { _, arg1, arg2, arg3 in - Cat(name: arg1 + arg2 + arg3) - } - let animal = container.resolve( - Animal.self, - arguments: "1", "2", "3") - expect(animal?.name) == "123" - } - it("accepts 4 arguments.") { - container.register(Animal.self) { _, arg1, arg2, arg3, arg4 in - Cat(name: arg1 + arg2 + arg3 + arg4) - } - let animal = container.resolve( - Animal.self, - arguments: "1", "2", "3", "4") - expect(animal?.name) == "1234" - } - it("accepts 5 arguments.") { - container.register(Animal.self) { (_, arg1: String, arg2: String, arg3: String, arg4: String, arg5: String) in - Cat(name: arg1 + arg2 + arg3 + arg4 + arg5) - } - let animal = container.resolve( - Animal.self, - arguments: "1", "2", "3", "4", "5") - expect(animal?.name) == "12345" - } - it("accepts 6 arguments.") { - container.register(Animal.self) { (_, arg1: String, arg2: String, arg3: String, arg4: String, arg5: String, arg6: String) in - Cat(name: arg1 + arg2 + arg3 + arg4 + arg5 + arg6) - } - let animal = container.resolve( - Animal.self, - arguments: "1", "2", "3", "4", "5", "6") - expect(animal?.name) == "123456" - } - it("accepts 7 arguments.") { - container.register(Animal.self) { (_, arg1: String, arg2: String, arg3: String, arg4: String, arg5: String, arg6: String, arg7: String) in - Cat(name: arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7) - } - let animal = container.resolve( - Animal.self, - arguments: "1", "2", "3", "4", "5", "6", "7") - expect(animal?.name) == "1234567" - } - it("accepts 8 arguments.") { - container.register(Animal.self) { (_, arg1: String, arg2: String, arg3: String, arg4: String, arg5: String, arg6: String, arg7: String, arg8: String) in - Cat(name: arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8) - } - let animal = container.resolve( - Animal.self, - arguments: "1", "2", "3", "4", "5", "6", "7", "8") - expect(animal?.name) == "12345678" - } - it("accepts 9 arguments.") { - container.register(Animal.self) { (_, arg1: String, arg2: String, arg3: String, arg4: String, arg5: String, arg6: String, arg7: String, arg8: String, arg9: String) in - Cat(name: arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9) - } - let animal = container.resolve( - Animal.self, - arguments: "1", "2", "3", "4", "5", "6", "7", "8", "9") - expect(animal?.name) == "123456789" - } - } -} diff --git a/Tests/SwinjectTests/ContainerSpec.Behavior.swift b/Tests/SwinjectTests/ContainerSpec.Behavior.swift deleted file mode 100644 index 2f41deac..00000000 --- a/Tests/SwinjectTests/ContainerSpec.Behavior.swift +++ /dev/null @@ -1,98 +0,0 @@ -// -// ContainerSpec.Behavior.swift -// Swinject -// -// Created by Jakub Vaňo on 16/02/2018. -// Copyright © 2018 Swinject Contributors. All rights reserved. -// -// swiftlint:disable function_body_length - -import Quick -import Nimble -@testable import Swinject - -class ContainerSpec_Behavior: QuickSpec { - override func spec() { - var container: Container! - beforeEach { - container = Container() - } - describe("adding service") { - it("should be invoked") { - let spy1 = BehaviorSpy() - let spy2 = BehaviorSpy() - container.addBehavior(spy1) - container.addBehavior(spy2) - - container.register(Dog.self) { _ in Dog() } - - expect(spy1.entries).to(haveCount(1)) - expect(spy2.entries).to(haveCount(1)) - } - it("should be invoked using proper name") { - let spy = BehaviorSpy() - container.addBehavior(spy) - - container.register(Dog.self, name: "Hachi") { _ in Dog() } - container.register(Cat.self) { _ in Cat() } - - expect(spy.names[0]).to(equal("Hachi")) - expect(spy.names[1]).to(beNil()) - } - it("should be invoked using proper type") { - let spy = BehaviorSpy() - container.addBehavior(spy) - - container.register(Animal.self) { _ in Dog() } - - expect(spy.types.first == Animal.self).to(beTrue()) - } - } - describe("forwarding service") { - it("should be invoked") { - let spy1 = BehaviorSpy() - let spy2 = BehaviorSpy() - container.addBehavior(spy1) - container.addBehavior(spy2) - - container.register(Dog.self) { _ in Dog() } - .implements(Animal.self) - - expect(spy1.entries).to(haveCount(2)) - expect(spy2.entries).to(haveCount(2)) - } - it("should be invoked using proper name") { - let spy = BehaviorSpy() - container.addBehavior(spy) - - container.register(Dog.self, name: "Hachi") { _ in Dog() } - .implements(Animal.self) - - expect(spy.names[0]).to(equal("Hachi")) - expect(spy.names[1]).to(beNil()) - } - it("should be invoked using proper type") { - let spy = BehaviorSpy() - container.addBehavior(spy) - - container.register(Dog.self, name: "Hachi") { _ in Dog() } - .implements(Animal.self) - - expect(spy.types[0] == Dog.self).to(beTrue()) - expect(spy.types[1] == Animal.self).to(beTrue()) - } - } - describe("convenience initialiser") { - it("adds behaviors to the container") { - let spy1 = BehaviorSpy() - let spy2 = BehaviorSpy() - container = Container(behaviors: [spy1, spy2]) - - container.register(Dog.self) { _ in Dog() } - - expect(spy1.entries).to(haveCount(1)) - expect(spy2.entries).to(haveCount(1)) - } - } - } -} diff --git a/Tests/SwinjectTests/ContainerSpec.Circularity.swift b/Tests/SwinjectTests/ContainerSpec.Circularity.swift deleted file mode 100644 index e06b85a6..00000000 --- a/Tests/SwinjectTests/ContainerSpec.Circularity.swift +++ /dev/null @@ -1,138 +0,0 @@ -// -// ContainerSpec.Circularity.swift -// Swinject -// -// Created by Yoichi Tagaya on 7/29/15. -// Copyright © 2015 Swinject Contributors. All rights reserved. -// -// swiftlint:disable function_body_length - -import Quick -import Nimble -@testable import Swinject - -class ContainerSpec_Circularity: QuickSpec { - override func spec() { - var container: Container! - beforeEach { - container = Container() - } - - describe("Two objects") { - it("resolves circular dependency on each property.") { - let runInObjectScope: (ObjectScope) -> Void = { scope in - container.removeAll() - container.register(ParentProtocol.self) { _ in Parent() } - .initCompleted { r, s in - let parent = s as! Parent - parent.child = r.resolve(ChildProtocol.self) - } - .inObjectScope(scope) - container.register(ChildProtocol.self) { _ in Child() } - .initCompleted { r, s in - let child = s as! Child - child.parent = r.resolve(ParentProtocol.self)! - } - .inObjectScope(scope) - - let parent = container.resolve(ParentProtocol.self) as! Parent - let child = parent.child as! Child - expect(child.parent as? Parent === parent).to(beTrue()) // Workaround for crash in Nimble - } - - runInObjectScope(.graph) - runInObjectScope(.container) - } - it("resolves circular dependency on the initializer and property.") { - let runInObjectScope: (ObjectScope) -> Void = { scope in - container.removeAll() - container.register(ParentProtocol.self) { r in Parent(child: r.resolve(ChildProtocol.self)!) } - .inObjectScope(scope) - container.register(ChildProtocol.self) { _ in Child() } - .initCompleted { r, s in - let child = s as! Child - child.parent = r.resolve(ParentProtocol.self) - } - .inObjectScope(scope) - - let parent = container.resolve(ParentProtocol.self) as! Parent - let child = parent.child as! Child - expect(child.parent as? Parent === parent).to(beTrue()) // Workaround for crash in Nimble - } - - runInObjectScope(.graph) - runInObjectScope(.container) - } - } - describe("More than two objects") { - it("resolves circular dependency on properties.") { - container.register(A.self) { _ in ADependingOnB() } - .initCompleted { - let a = $1 as! ADependingOnB - a.b = $0.resolve(B.self) - } - container.register(B.self) { _ in BDependingOnC() } - .initCompleted { - let b = $1 as! BDependingOnC - b.c = $0.resolve(C.self) - } - container.register(C.self) { _ in CDependingOnAD() } - .initCompleted { - let c = $1 as! CDependingOnAD - c.a = $0.resolve(A.self) - c.d = $0.resolve(D.self) - } - container.register(D.self) { _ in DDependingOnBC() } - .initCompleted { - let d = $1 as! DDependingOnBC - d.b = $0.resolve(B.self) - d.c = $0.resolve(C.self) - } - - let a = container.resolve(A.self) as! ADependingOnB - let b = a.b as! BDependingOnC - let c = b.c as! CDependingOnAD - let d = c.d as! DDependingOnBC - expect(c.a as? ADependingOnB === a).to(beTrue()) // Workaround for crash in Nimble - expect(d.b as? BDependingOnC === b).to(beTrue()) // Workaround for crash in Nimble - expect(d.c as? CDependingOnAD === c).to(beTrue()) // Workaround for crash in Nimble - } - it("resolves circular dependency on initializers and properties.") { - container.register(A.self) { r in ADependingOnB(b: r.resolve(B.self)!) } - container.register(B.self) { r in BDependingOnC(c: r.resolve(C.self)!) } - container.register(C.self) { r in CDependingOnAD(d: r.resolve(D.self)!) } - .initCompleted { - let c = $1 as! CDependingOnAD - c.a = $0.resolve(A.self) - } - container.register(D.self) { _ in DDependingOnBC() } - .initCompleted { - let d = $1 as! DDependingOnBC - d.b = $0.resolve(B.self) - d.c = $0.resolve(C.self) - } - - let a = container.resolve(A.self) as! ADependingOnB - let b = a.b as! BDependingOnC - let c = b.c as! CDependingOnAD - let d = c.d as! DDependingOnBC - expect(c.a as? ADependingOnB === a).to(beTrue()) // Workaround for crash in Nimble - expect(d.b as? BDependingOnC === b).to(beTrue()) // Workaround for crash in Nimble - expect(d.c as? CDependingOnAD === c).to(beTrue()) // Workaround for crash in Nimble - } - } - describe("Graph root is in weak object scope") { - it("does not deallocate during graph resolution") { - container.register(B.self) { r in BDependingOnC(c: r.resolve(C.self)!) } - .inObjectScope(.weak) - container.register(C.self) { _ in CDependingOnWeakB() } - .initCompleted { r, c in (c as! CDependingOnWeakB).b = r.resolve(B.self) } - - let b = container.resolve(B.self) as? BDependingOnC - let c = b?.c as? CDependingOnWeakB - - expect(c?.b).notTo(beNil()) - } - } - } -} diff --git a/Tests/SwinjectTests/ContainerSpec.CustomScope.swift b/Tests/SwinjectTests/ContainerSpec.CustomScope.swift deleted file mode 100644 index 4de9b115..00000000 --- a/Tests/SwinjectTests/ContainerSpec.CustomScope.swift +++ /dev/null @@ -1,92 +0,0 @@ -// -// ContainerSpec.CustomScope.swift -// Swinject -// -// Created by Jakub Vaňo on 11/11/16. -// Copyright © 2016 Swinject Contributors. All rights reserved. -// -// swiftlint:disable function_body_length - -import Quick -import Nimble -@testable import Swinject - -class ContainerSpec_CustomScope: QuickSpec { - override func spec() { - var container: Container! - beforeEach { - container = Container() - } - - describe("Resolving from custom scope") { - it("creates new instance storage for each service") { - var instances = 0 - let custom = ObjectScope(storageFactory: { instances += 1; return FakeStorage() }) - - container.register(Int.self) { _ in 0 }.inObjectScope(custom) - container.register(Double.self) { _ in 0}.inObjectScope(custom) - _ = container.resolve(Int.self) - _ = container.resolve(Double.self) - - expect(instances) == 2 - } - it("stores instance to storage during resolution") { - let storage = FakeStorage() - let custom = ObjectScope(storageFactory: { storage }) - - container.register(Int.self) { _ in 42 }.inObjectScope(custom) - _ = container.resolve(Int.self) - - expect(storage.instance as? Int) == 42 - } - it("returns stored instance if storage is not empty") { - let storage = FakeStorage() - let custom = ObjectScope(storageFactory: { storage }) - - container.register(Int.self) { _ in 0 }.inObjectScope(custom) - storage.instance = 42 - let result = container.resolve(Int.self) - - expect(result) == 42 - } - } - describe("Resetting scope") { - it("removes instance from services in given scope") { - let storage = FakeStorage() - let custom = ObjectScope(storageFactory: { storage }) - - container.register(Int.self) { _ in 0}.inObjectScope(custom) - storage.instance = 42 - container.resetObjectScope(custom) - - expect(storage.instance).to(beNil()) - } - it("does not remove instances from other scopes") { - let storage = FakeStorage() - let custom1 = ObjectScope(storageFactory: { storage }) - let custom2 = ObjectScope(storageFactory: FakeStorage.init) - - container.register(Int.self) { _ in 0}.inObjectScope(custom1) - storage.instance = 42 - container.resetObjectScope(custom2) - - expect(storage.instance as? Int) == 42 - } - it("removes instance from service registered in parent container") { - let storage = FakeStorage() - let custom = ObjectScope(storageFactory: { storage }) - let child = Container(parent: container) - - container.register(Int.self) { _ in 0 }.inObjectScope(custom) - storage.instance = 42 - child.resetObjectScope(custom) - - expect(storage.instance).to(beNil()) - } - } - } -} - -private class FakeStorage: InstanceStorage { - var instance: Any? -} diff --git a/Tests/SwinjectTests/ContainerSpec.CustomStringConvertible.swift b/Tests/SwinjectTests/ContainerSpec.CustomStringConvertible.swift deleted file mode 100644 index e89e8f3c..00000000 --- a/Tests/SwinjectTests/ContainerSpec.CustomStringConvertible.swift +++ /dev/null @@ -1,78 +0,0 @@ -// -// ContainerSpec.CustomStringConvertible.swift -// Swinject -// -// Created by Jakub Vaňo on 13/06/2017. -// Copyright © 2017 Swinject Contributors. All rights reserved. -// -// swiftlint:disable function_body_length - -import Quick -import Nimble -@testable import Swinject - -class ContainerSpec_CustomStringConvertible: QuickSpec { - override func spec() { - var container: Container! - beforeEach { - container = Container() - } - - it("describes empty description without service registrations.") { - expect(container.description) == "[\n]" - } - it("describes a registration.") { - container.register(Animal.self) { _ in Cat() } - - expect(container.description) == - "[\n" - + " { Service: Animal, Factory: Resolver -> Animal, ObjectScope: graph }\n" - + "]" - } - it("describes a registration with name.") { - container.register(Animal.self, name: "My Cat") { _ in Cat() } - - expect(container.description) == - "[\n" - + " { Service: Animal, Name: \"My Cat\", Factory: Resolver -> Animal, ObjectScope: graph }\n" - + "]" - } - it("describes a registration with arguments.") { - container.register(Animal.self) { _, arg1, arg2 in Cat(name: arg1, sleeping: arg2) } - - expect(container.description) == - "[\n" - + " { Service: Animal, Factory: (Resolver, String, Bool) -> Animal, ObjectScope: graph }\n" - + "]" - } - it("describes a registration with a specified object scope.") { - container.register(Animal.self) { _ in Cat() } - .inObjectScope(.container) - - expect(container.description) == - "[\n" - + " { Service: Animal, Factory: Resolver -> Animal, ObjectScope: container }\n" - + "]" - } - it("describes a registration with initCompleted.") { - container.register(Animal.self) { _ in Cat() } - .initCompleted { _, _ in } - - expect(container.description) == - "[\n" - + " { Service: Animal, Factory: Resolver -> Animal, ObjectScope: graph, " - + "InitCompleted: Specified 1 closures }\n" - + "]" - } - it("describes multiple registrations.") { - container.register(Animal.self, name: "1") { _ in Cat() } - container.register(Animal.self, name: "2") { _ in Cat() } - - expect(container.description) == - "[\n" - + " { Service: Animal, Name: \"1\", Factory: Resolver -> Animal, ObjectScope: graph },\n" - + " { Service: Animal, Name: \"2\", Factory: Resolver -> Animal, ObjectScope: graph }\n" - + "]" - } - } -} diff --git a/Tests/SwinjectTests/ContainerSpec.DebugHelper.swift b/Tests/SwinjectTests/ContainerSpec.DebugHelper.swift deleted file mode 100644 index cd0906dc..00000000 --- a/Tests/SwinjectTests/ContainerSpec.DebugHelper.swift +++ /dev/null @@ -1,74 +0,0 @@ -// -// ContainerSpec.DebugHelper.swift -// Swinject -// -// Created by Jakub Vaňo on 26/09/16. -// Copyright © 2016 Swinject Contributors. All rights reserved. -// - -import Quick -import Nimble -@testable import Swinject - -class ContainerSpec_DebugHelper: QuickSpec { - override func spec() { - var spy: DebugHelperSpy! - beforeEach { spy = DebugHelperSpy() } - - describe("resolution fails") { - it("should call debug helper with failing service and key") { - let container = Container(debugHelper: spy) - - _ = container._resolve(name: "name") { (_: (Int) -> Any) in return 1 as Double } as Double? - - expect("\(spy.serviceType)") == "Double" - expect(spy.key) == ServiceKey( - serviceType: Double.self, - argumentsType: Int.self, - name: "name", - option: nil - ) - } - - it("should call helper with all registrations") { - let container = Container(debugHelper: spy) - container.register(Int.self) { _ in 0 } - container.register(Double.self) { _ in 0} - - _ = container.resolve(String.self) - - expect(spy.availableRegistrations?.count) == 2 - } - - context("has parent container") { - it("should call helper with parent registrations") { - let parent = Container() - parent.register(Int.self) { _ in 0 } - let container = Container(parent: parent, debugHelper: spy) - container.register(Double.self) { _ in 0 } - - _ = container.resolve(String.self) - - expect(spy.availableRegistrations?.count) == 2 - } - } - } - } -} - -private class DebugHelperSpy: DebugHelper { - - var serviceType: Any = "" - var key: ServiceKey? - var availableRegistrations: [ServiceKey: ServiceEntryProtocol]? - - func resolutionFailed( - serviceType: Service.Type, - key: ServiceKey, - availableRegistrations: [ServiceKey: ServiceEntryProtocol] - ) { - self.serviceType = serviceType - self.key = key - self.availableRegistrations = availableRegistrations - } -} diff --git a/Tests/SwinjectTests/ContainerSpec.GraphCaching.swift b/Tests/SwinjectTests/ContainerSpec.GraphCaching.swift deleted file mode 100644 index b584c3cb..00000000 --- a/Tests/SwinjectTests/ContainerSpec.GraphCaching.swift +++ /dev/null @@ -1,132 +0,0 @@ -// -// ContainerSpec.GraphCaching.swift -// Swinject -// -// Created by Jakub Vaňo on 08/03/2018. -// Copyright © 2018 Swinject Contributors. All rights reserved. -// -// swiftlint:disable function_body_length - -import Quick -import Nimble -@testable import Swinject - -class ContainerSpec_GraphCaching: QuickSpec { - override func spec() { - var container: Container! - beforeEach { - container = Container() - } - - it("has a method for restoring a graph") { - container.restoreObjectGraph(GraphIdentifier()) - } - - describe("current object graph") { - it("is not nil during graph resolution") { - var identifier: GraphIdentifier? - container.register(Dog.self) { - identifier = ($0 as? Container)?.currentObjectGraph - return Dog() - } - - _ = container.resolve(Dog.self) - - expect(identifier).notTo(beNil()) - } - it("is different for separate graph resolutions") { - var identifiers = [GraphIdentifier?]() - container.register(Dog.self) { - identifiers.append(($0 as? Container)?.currentObjectGraph) - return Dog() - } - - _ = container.resolve(Dog.self) - _ = container.resolve(Dog.self) - - expect(identifiers).to(haveCount(2)) - expect(identifiers[0]) != identifiers[1] - } - it("is the same during graph resolution") { - var identifiers = [GraphIdentifier?]() - container.register(Dog.self) { - identifiers.append(($0 as? Container)?.currentObjectGraph) - _ = $0.resolve(Cat.self) - return Dog() - } - container.register(Cat.self) { - identifiers.append(($0 as? Container)?.currentObjectGraph) - return Cat() - } - - _ = container.resolve(Dog.self) - - expect(identifiers).to(haveCount(2)) - expect(identifiers[0]) == identifiers[1] - } - it("is nil outside the graph resolution") { - container.register(Dog.self) { _ in Dog() } - - expect(container.currentObjectGraph).to(beNil()) - _ = container.resolve(Dog.self) - expect(container.currentObjectGraph).to(beNil()) - } - } - describe("object graph restoration") { - it("uses restored identifier during graph resolution") { - let restoredIdentifier = GraphIdentifier() - var identifier: GraphIdentifier? - container.register(Dog.self) { - identifier = ($0 as? Container)?.currentObjectGraph - return Dog() - } - - container.restoreObjectGraph(restoredIdentifier) - _ = container.resolve(Dog.self) - - expect(identifier) == restoredIdentifier - } - } - describe("instance storage interaction") { - it("uses current graph identifier when manipulating instances") { - let spy = StorageSpy() - let graph = GraphIdentifier() - let scope = ObjectScope(storageFactory: { spy }) - container.register(Dog.self) { _ in Dog() }.inObjectScope(scope) - container.restoreObjectGraph(graph) - - _ = container.resolve(Dog.self) - - expect(spy.setterGraphs.last) == graph - expect(spy.getterGraphs.last) == graph - } - it("restores instances from previous graphs if available") { - var graph: GraphIdentifier! - container.register(Dog.self) { - graph = ($0 as? Container)?.currentObjectGraph - return Dog() - }.inObjectScope(.graph) - - let dog1 = container.resolve(Dog.self)! - container.restoreObjectGraph(graph) - let dog2 = container.resolve(Dog.self)! - - expect(dog1) === dog2 - } - } - } -} - -private class StorageSpy: InstanceStorage { - var setterGraphs = [GraphIdentifier]() - var getterGraphs = [GraphIdentifier]() - - var instance: Any? - func setInstance(_ instance: Any?, inGraph graph: GraphIdentifier) { - setterGraphs.append(graph) - } - func instance(inGraph graph: GraphIdentifier) -> Any? { - getterGraphs.append(graph) - return nil - } -} diff --git a/Tests/SwinjectTests/ContainerSpec.TypeForwarding.swift b/Tests/SwinjectTests/ContainerSpec.TypeForwarding.swift deleted file mode 100644 index b601699a..00000000 --- a/Tests/SwinjectTests/ContainerSpec.TypeForwarding.swift +++ /dev/null @@ -1,168 +0,0 @@ -// -// ContainerSpec.TypeForwarding.swift -// Swinject -// -// Created by Jakub Vaňo on 15/02/2018. -// Copyright © 2018 Swinject Contributors. All rights reserved. -// -// swiftlint:disable function_body_length - -import Quick -import Nimble -@testable import Swinject - -class ContainerSpec_TypeForwarding: QuickSpec { - override func spec() { - var container: Container! - beforeEach { - container = Container() - } - - describe("container method") { - it("resolves forwarded type") { - let service = container.register(Dog.self) { _ in Dog() } - container.forward(Animal.self, to: service) - - let animal = container.resolve(Animal.self) - - expect(animal).notTo(beNil()) - } - it("resolves forwarded type with arguments") { - let service = container.register(Cat.self) { _, name, sleeping in Cat(name: name, sleeping: sleeping) } - container.forward(Animal.self, to: service) - - let animal = container.resolve(Animal.self, arguments: "Mimi", true) as? Cat - - expect(animal?.name) == "Mimi" - expect(animal?.sleeping).to(beTrue()) - } - it("resolves forwarded type given correct name") { - let service = container.register(Dog.self) { _ in Dog() } - container.forward(Animal.self, name: "Hachi", to: service) - - let animal = container.resolve(Animal.self, name: "Hachi") - - expect(animal).notTo(beNil()) - } - it("does not resolve forwarded type given incorrect name") { - let service = container.register(Dog.self) { _ in Dog() } - container.forward(Animal.self, name: "Hachi", to: service) - - let animal = container.resolve(Animal.self, name: "Mimi") - - expect(animal).to(beNil()) - } - it("does not resolve when forwarding incompatible types") { - let service = container.register(Dog.self) { _ in Dog() } - container.forward(Cat.self, to: service) - - let cat = container.resolve(Cat.self) - - expect(cat).to(beNil()) - } - it("does not resolve when forwarding incompatible types with arguments") { - let service = container.register(Dog.self) { (_, _: String) in Dog() } - container.forward(Cat.self, to: service) - - let cat = container.resolve(Cat.self, argument: "") - - expect(cat).to(beNil()) - } - it("resolves forwarded type even if only implementation type conforms to it") { - let service = container.register(Animal.self) { _ in Dog() } - container.forward(Dog.self, to: service) - let dog = container.resolve(Dog.self) - expect(dog).notTo(beNil()) - } - } - describe("service entry method") { - it("resolves forwarded type") { - container.register(Dog.self) { _ in Dog() } - .implements(Animal.self) - - let animal = container.resolve(Animal.self) - - expect(animal).notTo(beNil()) - } - it("suports multiple forwarding definitions") { - container.register(Dog.self) { _ in Dog() } - .implements(DogProtocol1.self) - .implements(DogProtocol2.self) - .implements(DogProtocol3.self) - - let dog1 = container.resolve(DogProtocol1.self) - let dog2 = container.resolve(DogProtocol2.self) - let dog3 = container.resolve(DogProtocol3.self) - - expect(dog1).notTo(beNil()) - expect(dog2).notTo(beNil()) - expect(dog3).notTo(beNil()) - } - it("resolves forwarded types only when correct name is given") { - container.register(Dog.self) { _ in Dog() } - .implements(DogProtocol1.self, name: "1") - .implements(DogProtocol2.self, name: "2") - .implements(DogProtocol3.self, name: "3") - - let dog1 = container.resolve(DogProtocol1.self, name: "1") - let dog2 = container.resolve(DogProtocol2.self) - let dog3 = container.resolve(DogProtocol3.self, name: "2") - - expect(dog1).notTo(beNil()) - expect(dog2).to(beNil()) - expect(dog3).to(beNil()) - } - it("supports defining multiple types at once") { - container.register(Dog.self) { _ in Dog() } - .implements(DogProtocol1.self, DogProtocol2.self, DogProtocol3.self) - - let dog1 = container.resolve(DogProtocol1.self) - let dog2 = container.resolve(DogProtocol2.self) - let dog3 = container.resolve(DogProtocol3.self) - - expect(dog1).notTo(beNil()) - expect(dog2).notTo(beNil()) - expect(dog3).notTo(beNil()) - } - } - describe("Optional resolving") { - it("resolves optional when wrapped type is registered") { - container.register(Dog.self) { _ in Dog() } - let optionalDog = container.resolve(Dog?.self) - expect(optionalDog ?? nil).notTo(beNil()) - } - it("resolves optional to nil when wrapped type is not registered") { - let optionalDog = container.resolve(Dog?.self) - expect(optionalDog).notTo(beNil()) - } - it("resolves optional with name") { - container.register(Dog.self, name: "Hachi") { _ in Dog() } - let optionalDog = container.resolve(Dog?.self, name: "Hachi") - expect(optionalDog ?? nil).notTo(beNil()) - } - it("resolves optional to nil with wrong name") { - container.register(Dog.self, name: "Hachi") { _ in Dog() } - let optionalDog = container.resolve(Dog?.self, name: "Mimi") - expect(optionalDog ?? nil).to(beNil()) - expect(optionalDog).notTo(beNil()) - } - it("resolves optional with arguments") { - container.register(Dog.self) { _, name in Dog(name: name) } - let optionalDog = container.resolve(Dog?.self, argument: "Hachi") - expect(optionalDog ?? nil).notTo(beNil()) - } - it("resolves optional of fowrarded type") { - container.register(Dog.self) { _ in Dog() }.implements(Animal.self) - let optionalAnimal = container.resolve(Animal?.self) - let unwrappedAnimal = container.resolve(Animal?.self) - expect(optionalAnimal ?? nil).notTo(beNil()) - expect(unwrappedAnimal ?? nil).notTo(beNil()) - } - } - } -} - -private protocol DogProtocol1 {} -private protocol DogProtocol2 {} -private protocol DogProtocol3 {} -extension Dog: DogProtocol1, DogProtocol2, DogProtocol3 {} diff --git a/Tests/SwinjectTests/ContainerSpec.swift b/Tests/SwinjectTests/ContainerSpec.swift deleted file mode 100644 index 0495c0f1..00000000 --- a/Tests/SwinjectTests/ContainerSpec.swift +++ /dev/null @@ -1,382 +0,0 @@ -// -// ContainerSpec.swift -// Swinject -// -// Created by Yoichi Tagaya on 7/23/15. -// Copyright © 2015 Swinject Contributors. All rights reserved. -// -// swiftlint:disable type_body_length -// swiftlint:disable function_body_length - -import Quick -import Nimble -@testable import Swinject - -class ContainerSpec: QuickSpec { - override func spec() { - var container: Container! - beforeEach { - container = Container() - } - - describe("Resolution of a non-registered service") { - it("returns nil.") { - let animal = container.resolve(Animal.self) - expect(animal).to(beNil()) - } - } - describe("Resolution of the same service") { - it("resolves by arguments.") { - container.register(Animal.self) { _ in Cat() } - container.register(Animal.self) { _, arg in Cat(name: arg) } - container.register(Animal.self) { _, arg1, arg2 in Cat(name: arg1, sleeping: arg2) } - - let noname = container.resolve(Animal.self) as? Cat - let mimi = container.resolve(Animal.self, argument: "Mimi") as? Cat - let mew = container.resolve(Animal.self, arguments: "Mew", true) as? Cat - expect(noname?.name).to(beNil()) - expect(mimi?.name) == "Mimi" - expect(mew?.name) == "Mew" - expect(mew?.sleeping) == true - } - it("resolves by the registered name.") { - container.register(Animal.self, name: "RegMimi") { _ in Cat(name: "Mimi") } - container.register(Animal.self, name: "RegMew") { _ in Cat(name: "Mew") } - container.register(Animal.self) { _ in Cat() } - - let mimi = container.resolve(Animal.self, name: "RegMimi") as? Cat - let mew = container.resolve(Animal.self, name: "RegMew") as? Cat - let noname = container.resolve(Animal.self) as? Cat - expect(mimi?.name) == "Mimi" - expect(mew?.name) == "Mew" - expect(noname?.name).to(beNil()) - } - } - describe("Removal of registered services") { - it("can remove all registered services.") { - container.register(Animal.self, name: "RegMimi") { _ in Cat(name: "Mimi") } - container.register(Animal.self, name: "RegMew") { _ in Cat(name: "Mew") } - container.removeAll() - - let mimi = container.resolve(Animal.self, name: "RegMimi") - let mew = container.resolve(Animal.self, name: "RegMew") - expect(mimi).to(beNil()) - expect(mew).to(beNil()) - } - } - describe("Container hierarchy") { - var child: Container! - var parent: Container! - beforeEach { - parent = Container() - child = Container(parent: parent) - } - it("resolves a service registered on the parent container.") { - parent.register(Animal.self) { _ in Cat() } - let cat = child.resolve(Animal.self) - expect(cat).notTo(beNil()) - } - it("does not resolve a service registred on the child container.") { - child.register(Animal.self) { _ in Cat() } - let cat = parent.resolve(Animal.self) - expect(cat).to(beNil()) - } - it("does not create zombies") { - parent.register(Cat.self) { _ in Cat() } - weak var weakCat = child.resolve(Cat.self) - expect(weakCat).to(beNil()) - } - #if !SWIFT_PACKAGE - it("does not terminate graph prematurely") { - child.register(Animal.self) { _ in Cat() } - parent.register(Food.self) { _ in Sushi() } - parent.register(PetOwner.self) { - let owner = PetOwner(pet: child.resolve(Animal.self)!) - owner.favoriteFood = $0.resolve(Food.self) - return owner - } - expect { _ = parent.resolve(PetOwner.self) } .notTo(throwAssertion()) - } - #endif - } - describe("Scope") { - let registerCatAndPetOwnerDependingOnFood: (Container) -> Void = { - $0.register(Animal.self) { - let cat = Cat() - cat.favoriteFood = $0.resolve(Food.self) - return cat - } - $0.register(Person.self) { - let owner = PetOwner(pet: $0.resolve(Animal.self)!) - owner.favoriteFood = $0.resolve(Food.self) - return owner - } - } - - context("in transient scope") { - it("does not have a shared object in a container.") { - container.register(Animal.self) { _ in Cat() } - .inObjectScope(.transient) - - let cat1 = container.resolve(Animal.self) as? Cat - let cat2 = container.resolve(Animal.self) as? Cat - expect(cat1 !== cat2).to(beTrue()) // Workaround for crash in Nimble. - } - it("resolves a service to new objects in a graph") { - registerCatAndPetOwnerDependingOnFood(container) - container.register(Food.self) { _ in Sushi() } - .inObjectScope(.transient) - - let owner = container.resolve(Person.self) as? PetOwner - let ownersSushi = owner?.favoriteFood as? Sushi - let catsSushi = (owner?.pet as? Cat)?.favoriteFood as? Sushi - expect(ownersSushi !== catsSushi).to(beTrue()) // Workaround for crash in Nimble. - } - } - context("in graph scope") { - it("does not have a shared object in a container.") { - container.register(Animal.self) { _ in Cat() } - .inObjectScope(.graph) - - let cat1 = container.resolve(Animal.self) as? Cat - let cat2 = container.resolve(Animal.self) as? Cat - expect(cat1 !== cat2).to(beTrue()) // Workaround for crash in Nimble. - } - it("resolves a service to the same object in a graph") { - registerCatAndPetOwnerDependingOnFood(container) - container.register(Food.self) { _ in Sushi() } - .inObjectScope(.graph) - - let owner = container.resolve(Person.self) as? PetOwner - let ownersSushi = owner?.favoriteFood as? Sushi - let catsSushi = (owner?.pet as? Cat)?.favoriteFood as? Sushi - expect(ownersSushi === catsSushi).to(beTrue()) // Workaround for crash in Nimble. - } - } - context("in container scope") { - it("shares an object in the own container.") { - container.register(Animal.self) { _ in Cat() } - .inObjectScope(.container) - - let cat1 = container.resolve(Animal.self) as? Cat - let cat2 = container.resolve(Animal.self) as? Cat - expect(cat1 === cat2).to(beTrue()) // Workaround for crash in Nimble. - } - it("shares an object from a parent container to its child.") { - let parent = Container() - parent.register(Animal.self) { _ in Cat() } - .inObjectScope(.container) - parent.register(Animal.self, name: "dog") { _ in Dog() } - .inObjectScope(.container) - let child = Container(parent: parent) - - // Case resolving on the parent first. - let cat1 = parent.resolve(Animal.self) as? Cat - let cat2 = child.resolve(Animal.self) as? Cat - expect(cat1 === cat2).to(beTrue()) // Workaround for crash in Nimble. - - // Case resolving on the child first. - let dog1 = child.resolve(Animal.self, name: "dog") as? Dog - let dog2 = parent.resolve(Animal.self, name: "dog") as? Dog - expect(dog1 === dog2).to(beTrue()) // Workaround for crash in Nimble. - } - it("resolves a service in the parent container to the same object in a graph") { - let parent = Container() - parent.register(Food.self) { _ in Sushi() } - .inObjectScope(.container) - let child = Container(parent: parent) - registerCatAndPetOwnerDependingOnFood(child) - - let owner = child.resolve(Person.self) as? PetOwner - let ownersSushi = owner?.favoriteFood as? Sushi - let catsSushi = (owner?.pet as? Cat)?.favoriteFood as? Sushi - expect(ownersSushi === catsSushi).to(beTrue()) // Workaround for crash in Nimble. - } - } - context("in weak scope") { - it("shares the object in the container") { - container.register(Animal.self) { _ in Cat() } - .inObjectScope(.weak) - - let cat1 = container.resolve(Animal.self) as? Cat - let cat2 = container.resolve(Animal.self) as? Cat - expect(cat1).notTo(beNil()) - expect(cat1 === cat2).to(beTrue()) // Workaround for crash in Nimble. - } - it("does not maintain a strong reference to the object") { - container.register(Animal.self) { _ in Cat() } - .inObjectScope(.weak) - - weak var cat = container.resolve(Animal.self) as? Cat - expect(cat).to(beNil()) - } - } - } - describe("Init completed event") { - it("raises the event when a new instance is created.") { - var eventRaised = false - container.register(Animal.self) { _ in Cat() } - .initCompleted { _, _ in eventRaised = true } - - let cat = container.resolve(Animal.self) - expect(cat).notTo(beNil()) - expect(eventRaised) == true - } - } - describe("Multiple init completed event") { - it("raises the event for all subscribed closures when a new instance is created.") { - var eventsRaised = 0 - container.register(Animal.self) { _ in Cat() } - .initCompleted { _, _ in eventsRaised += 1 } - .initCompleted { _, _ in eventsRaised += 1 } - .initCompleted { _, _ in eventsRaised += 1 } - .initCompleted { _, _ in eventsRaised += 1 } - - let cat = container.resolve(Animal.self) - expect(cat).notTo(beNil()) - expect(eventsRaised) == 4 - } - } - describe("Injection types") { - it("accepts initializer injection.") { - container.register(Animal.self) { _ in Cat() } - container.register(Person.self) { r in PetOwner(pet: r.resolve(Animal.self)!) } - - let owner = container.resolve(Person.self) as? PetOwner - expect(owner?.pet).notTo(beNil()) - } - it("accepts property injection in registration.") { - container.register(Animal.self) { _ in Cat() } - container.register(Person.self) { r in - let owner = PetOwner() - owner.pet = r.resolve(Animal.self)! - return owner - } - - let owner = container.resolve(Person.self) as? PetOwner - expect(owner?.pet).notTo(beNil()) - } - it("accepts property injection in initCompleted event.") { - container.register(Animal.self) { _ in Cat() } - container.register(Person.self) { _ in PetOwner() } - .initCompleted { r, s in - let owner = s as? PetOwner - owner?.pet = r.resolve(Animal.self)! - } - - let owner = container.resolve(Person.self) as? PetOwner - expect(owner?.pet).notTo(beNil()) - } - it("accepts method injection in registration.") { - container.register(Animal.self) { _ in Cat() } - container.register(Person.self) { r in - let owner = PetOwner() - owner.injectAnimal(r.resolve(Animal.self)!) - return owner - } - - let owner = container.resolve(Person.self) as? PetOwner - expect(owner?.pet).notTo(beNil()) - } - it("accepts method injection in initCompleted event.") { - container.register(Animal.self) { _ in Cat() } - container.register(Person.self) { _ in PetOwner() } - .initCompleted { r, s in - let owner = s as? PetOwner - owner?.injectAnimal(r.resolve(Animal.self)!) - } - - let owner = container.resolve(Person.self) as? PetOwner - expect(owner?.pet).notTo(beNil()) - } - } - describe("Value type resolution") { - it("resolves struct instances ignoring object scopes.") { - let runInObjectScope: (ObjectScope) -> Void = { scope in - container.removeAll() - container.register(Animal.self) { _ in Turtle(name: "Ninja") } - .inObjectScope(scope) - var turtle1 = container.resolve(Animal.self)! - var turtle2 = container.resolve(Animal.self)! - turtle1.name = "Samurai" - expect(turtle1.name) == "Samurai" - expect(turtle2.name) == "Ninja" - } - - runInObjectScope(.transient) - runInObjectScope(.graph) - runInObjectScope(.container) - } - it("resolves struct instances defined in the parent container ignoring object scopes.") { - let runInObjectScope: (ObjectScope) -> Void = { scope in - container.removeAll() - container.register(Animal.self) { _ in Turtle(name: "Ninja") } - .inObjectScope(scope) - let childContainer = Container(parent: container) - - var turtle1 = childContainer.resolve(Animal.self)! - var turtle2 = childContainer.resolve(Animal.self)! - turtle1.name = "Samurai" - expect(turtle1.name) == "Samurai" - expect(turtle2.name) == "Ninja" - } - - runInObjectScope(.transient) - runInObjectScope(.graph) - runInObjectScope(.container) - } - context("object scope is container or hierarchy") { - it("resolves only once to simulate singleton (instantiation only once).") { - let runInObjectScope: (ObjectScope, Int) -> Void = { scope, expectation in - var invokedCount = 0 - container.removeAll() - container.register(Animal.self) { _ in - invokedCount += 1 - return Turtle(name: "Ninja") - }.inObjectScope(scope) - _ = container.resolve(Animal.self)! - _ = container.resolve(Animal.self)! - expect(invokedCount) == expectation - } - - runInObjectScope(.transient, 2) - runInObjectScope(.graph, 2) - runInObjectScope(.container, 1) - } - } - } - describe("Class as a service type") { - it("resolves a registred subclass of a service type class.") { - container.register(Cat.self) { _ in Siamese(name: "Siam") } - - let siam = container.resolve(Cat.self) as? Siamese - expect(siam?.name) == "Siam" - } - it("resolves a self-binding with dependency injected.") { - container.register(PetOwner.self) { r in PetOwner(pet: r.resolve(Animal.self)!) } - container.register(Animal.self) { _ in Siamese(name: "Siam") } - - let owner = container.resolve(PetOwner.self)! - let siam = owner.pet as? Siamese - expect(siam?.name) == "Siam" - } - } - describe("Convenience initializers") { - it("takes a closure registering services.") { - let container = Container { - $0.register(Animal.self) { _ in Cat() } - } - - expect(container.resolve(Animal.self) as? Cat).notTo(beNil()) - } - } - describe("Default object scope") { - it("registers services with given object scope") { - let container = Container(parent: nil, debugHelper: LoggingDebugHelper(), defaultObjectScope: .weak) - - let serviceEntry = container.register(Animal.self) { _ in Siamese(name: "Siam") } - expect(serviceEntry.objectScope) === ObjectScope.weak - } - } -} -} diff --git a/Tests/SwinjectTests/EmploymentAssembly.swift b/Tests/SwinjectTests/EmploymentAssembly.swift deleted file mode 100644 index 4b7d633b..00000000 --- a/Tests/SwinjectTests/EmploymentAssembly.swift +++ /dev/null @@ -1,84 +0,0 @@ -// -// Employment.swift -// Swinject -// -// Created by Jakub Vaňo on 14/03/2018. -// Copyright © 2018 Swinject Contributors. All rights reserved. -// - -import Swinject - -class Customer {} - -class Employee { - let customer: Customer - let lazyCustomer: Lazy - let providedCustomer: Provider - var employer: Employer? - - init(customer: Customer, lazyCustomer: Lazy, providedCustomer: Provider) { - self.customer = customer - self.lazyCustomer = lazyCustomer - self.providedCustomer = providedCustomer - } -} - -class Employer { - let customer: Customer - let lazyCustomer: Lazy - let providedCustomer: Provider - let employee: Employee - let lazyEmployee: Lazy - let providedEmployee: Provider - - init( - customer: Customer, - lazyCustomer: Lazy, - providedCustomer: Provider, - employee: Employee, - lazyEmployee: Lazy, - providedEmployee: Provider - ) { - self.customer = customer - self.lazyCustomer = lazyCustomer - self.providedCustomer = providedCustomer - self.employee = employee - self.lazyEmployee = lazyEmployee - self.providedEmployee = providedEmployee - } -} - -final class EmploymentAssembly: Assembly { - private let scope: ObjectScope - - init(scope: ObjectScope) { - self.scope = scope - } - - func assemble(container: Container) { - container.register(Customer.self) { _ in Customer() }.inObjectScope(scope) - - container.register(Employee.self) { - Employee( - customer: $0.resolve(Customer.self)!, - lazyCustomer: $0.resolve(Lazy.self)!, - providedCustomer: $0.resolve(Provider.self)! - ) - }.initCompleted { - if self.scope !== ObjectScope.transient { - $1.employer = $0.resolve(Employer.self) - } - }.inObjectScope(scope) - - container.register(Employer.self) { - Employer( - customer: $0.resolve(Customer.self)!, - lazyCustomer: $0.resolve(Lazy.self)!, - providedCustomer: $0.resolve(Provider.self)!, - employee: $0.resolve(Employee.self)!, - lazyEmployee: $0.resolve(Lazy.self)!, - providedEmployee: $0.resolve(Provider.self)! - ) - }.inObjectScope(scope) - } -} diff --git a/Tests/SwinjectTests/Food.swift b/Tests/SwinjectTests/Food.swift deleted file mode 100644 index 3eec9319..00000000 --- a/Tests/SwinjectTests/Food.swift +++ /dev/null @@ -1,13 +0,0 @@ -// -// Food.swift -// Swinject -// -// Created by Yoichi Tagaya on 7/29/15. -// Copyright © 2015 Swinject Contributors. All rights reserved. -// - -import Foundation - -internal protocol Food { } - -internal class Sushi: Food { } diff --git a/Tests/SwinjectTests/LazySpec.swift b/Tests/SwinjectTests/LazySpec.swift deleted file mode 100644 index 13e9cc8d..00000000 --- a/Tests/SwinjectTests/LazySpec.swift +++ /dev/null @@ -1,112 +0,0 @@ -// -// LazySpec.swift -// Swinject -// -// Created by Jakub Vaňo on 07/03/2018. -// Copyright © 2018 Swinject Contributors. All rights reserved. -// swiftlint:disable function_body_length - -import Quick -import Nimble -import Swinject - -class LazySpec: QuickSpec { - override func spec() { - var container: Container! - beforeEach { - container = Container() - } - - describe("instance production") { - it("provides instance from container") { - container.register(Animal.self) { _ in Dog() } - let lazy = container.resolve(Lazy.self) - expect(lazy?.instance is Dog).to(beTrue()) - } - it("does not create instance until requested") { - var created = false - container.register(Animal.self) { _ in created = true; return Dog() } - - _ = container.resolve(Lazy.self) - - expect(created).to(beFalse()) - } - it("resolves instance from container only once") { - var created = 0 - container.register(Animal.self) { _ in created += 1; return Dog() } - - let lazy = container.resolve(Lazy.self) - _ = lazy?.instance - _ = lazy?.instance - - expect(created) == 1 - } - it("does not resolve lazy if base type is not registered") { - let lazy = container.resolve(Lazy.self) - expect(lazy).to(beNil()) - } - } - describe("object scopes") { - context("in transient scope") { - it("always produces different instance for related objects") { - EmploymentAssembly(scope: .transient).assemble(container: container) - let employer = container.resolve(Employer.self)! - expect(employer.lazyCustomer.instance).notTo(beIdenticalTo(employer.employee.lazyCustomer.instance)) - expect(employer.lazyCustomer.instance).notTo(beIdenticalTo(employer.customer)) - } - } - context("in container scope") { - it("always produces the same instance for related objects") { - EmploymentAssembly(scope: .container).assemble(container: container) - let employer = container.resolve(Employer.self)! - expect(employer.lazyCustomer.instance).to(beIdenticalTo(employer.employee.lazyCustomer.instance)) - expect(employer.lazyCustomer.instance).to(beIdenticalTo(employer.customer)) - } - } - context("in graph scope") { - it("always produces the same instance for related objects") { - EmploymentAssembly(scope: .graph).assemble(container: container) - let employer = container.resolve(Employer.self)! - expect(employer.lazyCustomer.instance).to(beIdenticalTo(employer.employee.lazyCustomer.instance)) - expect(employer.lazyCustomer.instance).to(beIdenticalTo(employer.customer)) - } - } - } - describe("complex registrations") { - it("resolves lazy with arguments") { - container.register(Dog.self) { (_, name, _: Int) in Dog(name: name) } - let lazy = container.resolve(Lazy.self, arguments: "Hachi", 42) - expect(lazy?.instance.name) == "Hachi" - } - it("resolves lazy with name") { - container.register(Dog.self, name: "Hachi") { _ in Dog() } - let lazy = container.resolve(Lazy.self, name: "Hachi") - expect(lazy).notTo(beNil()) - } - it("does not resolve lazy with wrong name") { - container.register(Dog.self, name: "Hachi") { _ in Dog() } - let lazy = container.resolve(Lazy.self, name: "Mimi") - expect(lazy).to(beNil()) - } - it("does resolve forwarded lazy type") { - container.register(Dog.self) { _ in Dog() }.implements(Animal.self) - let lazy = container.resolve(Lazy.self) - expect(lazy).notTo(beNil()) - } - } - describe("circular dependencies") { - beforeEach { - EmploymentAssembly(scope: .graph).assemble(container: container) - } - it("resolves dependencies to same instance") { - let employer = container.resolve(Employer.self) - expect(employer?.employee.employer) === employer - expect(employer?.lazyEmployee.instance.employer) === employer - } - it("resolves circular dependencies for lazy instance") { - let employee = container.resolve(Lazy.self) - expect(employee?.instance.employer).notTo(beNil()) - } - } - } -} diff --git a/Tests/SwinjectTests/LoadAwareAssembly.swift b/Tests/SwinjectTests/LoadAwareAssembly.swift deleted file mode 100644 index b79bc2a5..00000000 --- a/Tests/SwinjectTests/LoadAwareAssembly.swift +++ /dev/null @@ -1,29 +0,0 @@ -// -// LoadAwareAssembly.swift -// Swinject -// -// Created by mike.owens on 12/9/15. -// Copyright © 2015 Swinject Contributors. All rights reserved. -// - -import Swinject - -class LoadAwareAssembly: Assembly { - var onLoad: (Resolver) -> Void - var loaded = false - - init(onLoad: @escaping (Resolver) -> Void) { - self.onLoad = onLoad - } - - func assemble(container: Container) { - container.register(Animal.self) { _ in - return Cat(name: "Bojangles") - } - } - - func loaded(resolver: Resolver) { - onLoad(resolver) - loaded = true - } -} diff --git a/Tests/SwinjectTests/Person.swift b/Tests/SwinjectTests/Person.swift deleted file mode 100644 index c3406efe..00000000 --- a/Tests/SwinjectTests/Person.swift +++ /dev/null @@ -1,27 +0,0 @@ -// -// Person.swift -// Swinject -// -// Created by Yoichi Tagaya on 7/27/15. -// Copyright © 2015 Swinject Contributors. All rights reserved. -// - -import Foundation - -internal protocol Person { } - -internal class PetOwner: Person { - var pet: Animal? - var favoriteFood: Food? - - init() { - } - - init(pet: Animal) { - self.pet = pet - } - - func injectAnimal(_ animal: Animal) { - self.pet = animal - } -} diff --git a/Tests/SwinjectTests/ProviderSpec.swift b/Tests/SwinjectTests/ProviderSpec.swift deleted file mode 100644 index efbeb1a2..00000000 --- a/Tests/SwinjectTests/ProviderSpec.swift +++ /dev/null @@ -1,117 +0,0 @@ -// -// ProviderSpec.swift -// Swinject -// -// Created by Jakub Vaňo on 07/03/2018. -// Copyright © 2018 Swinject Contributors. All rights reserved. -// swiftlint:disable function_body_length - -import Quick -import Nimble -import Swinject - -class ProviderSpec: QuickSpec { - override func spec() { - var container: Container! - beforeEach { - container = Container() - } - - describe("instance production") { - it("provides instance from container") { - container.register(Animal.self) { _ in Dog() } - let provider = container.resolve(Provider.self) - expect(provider?.instance is Dog).to(beTrue()) - } - it("does not create instance until requested") { - var created = false - container.register(Animal.self) { _ in created = true; return Dog() } - - _ = container.resolve(Provider.self) - - expect(created).to(beFalse()) - } - it("resolves instance from the container each time") { - var created = 0 - container.register(Animal.self) { _ in created += 1; return Dog() } - - let provider = container.resolve(Provider.self) - _ = provider?.instance - _ = provider?.instance - - expect(created) == 2 - } - it("does not resolve provider if base type is not registered") { - let provider = container.resolve(Provider.self) - expect(provider).to(beNil()) - } - } - describe("object scopes") { - context("in transient scope") { - beforeEach { - EmploymentAssembly(scope: .transient).assemble(container: container) - } - it("always produces different instance") { - let employer = container.resolve(Employer.self)! - expect(employer.providedEmployee.instance) !== employer.providedEmployee.instance - expect(employer.employee.providedCustomer.instance) !== employer.providedCustomer.instance - } - } - context("in graph scope") { - beforeEach { - EmploymentAssembly(scope: .graph).assemble(container: container) - } - it("always produces different instance") { - let employer = container.resolve(Employer.self)! - expect(employer.providedEmployee.instance) !== employer.providedEmployee.instance - expect(employer.employee.providedCustomer.instance) !== employer.providedCustomer.instance - } - } - context("in container scope") { - beforeEach { - EmploymentAssembly(scope: .container).assemble(container: container) - } - it("always produces the same instance") { - let employer = container.resolve(Employer.self)! - expect(employer.providedEmployee.instance) === employer.providedEmployee.instance - expect(employer.employee.providedCustomer.instance) === employer.providedCustomer.instance - } - } - } - describe("complex registrations") { - it("resolves provider with arguments") { - container.register(Dog.self) { (_, name, _: Int) in Dog(name: name) } - let provider = container.resolve(Provider.self, arguments: "Hachi", 42) - expect(provider?.instance.name) == "Hachi" - } - it("resolves provider with name") { - container.register(Dog.self, name: "Hachi") { _ in Dog() } - let provider = container.resolve(Provider.self, name: "Hachi") - expect(provider).notTo(beNil()) - } - it("does not resolve provider with wrong name") { - container.register(Dog.self, name: "Hachi") { _ in Dog() } - let provider = container.resolve(Provider.self, name: "Mimi") - expect(provider).to(beNil()) - } - it("does resolve forwarded provider type") { - container.register(Dog.self) { _ in Dog() }.implements(Animal.self) - let provider = container.resolve(Provider.self) - expect(provider).notTo(beNil()) - } - } - describe("circular dependencies") { - beforeEach { - EmploymentAssembly(scope: .graph).assemble(container: container) - } - it("resolves non-provided dependencies to the same instance") { - let employer = container.resolve(Provider.self)?.instance - expect(employer?.employee.employer) === employer - } - it("resolves provided dependencies to different instances") { - let employer = container.resolve(Employer.self) - expect(employer?.providedEmployee.instance.employer) !== employer - } - } - } -} diff --git a/Tests/SwinjectTests/ServiceEntrySpec.swift b/Tests/SwinjectTests/ServiceEntrySpec.swift deleted file mode 100644 index 04390868..00000000 --- a/Tests/SwinjectTests/ServiceEntrySpec.swift +++ /dev/null @@ -1,30 +0,0 @@ -// -// ServiceEntrySpec.swift -// Swinject -// -// Created by Yoichi Tagaya on 7/29/15. -// Copyright © 2015 Swinject Contributors. All rights reserved. -// - -import Quick -import Nimble -@testable import Swinject - -class ServiceEntrySpec: QuickSpec { - override func spec() { - it("has ObjectScope.graph as a default value of scope property.") { - let entry = ServiceEntry(serviceType: Int.self, argumentsType: Any.self, factory: { return 0 }) - expect(entry.objectScope) === ObjectScope.graph - } - - it("has ObjectScope set to value from init.") { - let entry = ServiceEntry( - serviceType: Int.self, - argumentsType: Any.self, - factory: { return 0 }, - objectScope: .weak - ) - expect(entry.objectScope) === ObjectScope.weak - } - } -} diff --git a/Tests/SwinjectTests/ServiceKeySpec.swift b/Tests/SwinjectTests/ServiceKeySpec.swift deleted file mode 100644 index a347dde8..00000000 --- a/Tests/SwinjectTests/ServiceKeySpec.swift +++ /dev/null @@ -1,149 +0,0 @@ -// -// ServiceKeySpec.swift -// Swinject -// -// Created by Yoichi Tagaya on 7/23/15. -// Copyright © 2015 Swinject Contributors. All rights reserved. -// -// swiftlint:disable function_body_length - -import Quick -import Nimble -@testable import Swinject - -// MARK: Option -private struct Option: ServiceKeyOption { - let option: Int - - func isEqualTo(_ another: ServiceKeyOption) -> Bool { - guard let another = another as? Option else { - return false - } - - return self.option == another.option - } - - var hashValue: Int { - return option.hashValue - } - - var description: String { - return "" - } -} - -// MARK: ServiceKeySpec -class ServiceKeySpec: QuickSpec { - override func spec() { - describe("Without name") { - it("equals with the same factory type.") { - let key1 = ServiceKey(serviceType: Animal.self, argumentsType: Resolver.self) - let key2 = ServiceKey(serviceType: Animal.self, argumentsType: Resolver.self) - expect(key1) == key2 - expect(key1.hashValue) == key2.hashValue - - let key3 = ServiceKey(serviceType: Animal.self, argumentsType: (Resolver, String, Bool).self) - let key4 = ServiceKey(serviceType: Animal.self, argumentsType: (Resolver, String, Bool).self) - expect(key3) == key4 - expect(key3.hashValue) == key4.hashValue - } - it("does not equal with different service types in factory types.") { - let key1 = ServiceKey(serviceType: Person.self, argumentsType: Resolver.self) - let key2 = ServiceKey(serviceType: Animal.self, argumentsType: Resolver.self) - expect(key1) != key2 - expect(key1.hashValue) != key2.hashValue - } - it("does not equal with different arg types in factory types.") { - let key1 = ServiceKey(serviceType: Animal.self, argumentsType: (Resolver, String).self) - let key2 = ServiceKey(serviceType: Animal.self, argumentsType: (Resolver, String, Bool).self) - expect(key1) != key2 - expect(key1.hashValue) != key2.hashValue - - let key3 = ServiceKey(serviceType: Animal.self, argumentsType: (Resolver, String, Bool).self) - let key4 = ServiceKey(serviceType: Animal.self, argumentsType: (Resolver, String, Int).self) - expect(key3) != key4 - expect(key3.hashValue) != key4.hashValue - } - } - describe("With name") { - it("equals with the same name.") { - let key1 = ServiceKey(serviceType: Animal.self, argumentsType: Resolver.self, name: "my factory") - let key2 = ServiceKey(serviceType: Animal.self, argumentsType: Resolver.self, name: "my factory") - expect(key1) == key2 - expect(key1.hashValue) == key2.hashValue - - let key3 = ServiceKey( - serviceType: Animal.self, - argumentsType: (Resolver, String, Bool).self, - name: "my factory" - ) - let key4 = ServiceKey( - serviceType: Animal.self, - argumentsType: (Resolver, String, Bool).self, - name: "my factory" - ) - expect(key3) == key4 - expect(key3.hashValue) == key4.hashValue - } - it("does not equal with different names.") { - let key1 = ServiceKey(serviceType: Animal.self, argumentsType: Resolver.self, name: "my factory") - let key2 = ServiceKey(serviceType: Animal.self, argumentsType: Resolver.self, name: "your factory") - expect(key1) != key2 - expect(key1.hashValue) != key2.hashValue - - let key3 = ServiceKey( - serviceType: Animal.self, - argumentsType: (Resolver, String, Bool).self, - name: "my factory" - ) - let key4 = ServiceKey( - serviceType: Animal.self, - argumentsType: (Resolver, String, Bool).self, - name: "your factory" - ) - expect(key3) != key4 - expect(key3.hashValue) != key4.hashValue - } - } - describe("With option") { - it("equals with the same option.") { - let key1 = ServiceKey(serviceType: Animal.self, argumentsType: Resolver.self, option: Option(option: 1)) - let key2 = ServiceKey(serviceType: Animal.self, argumentsType: Resolver.self, option: Option(option: 1)) - expect(key1) == key2 - expect(key1.hashValue) == key2.hashValue - - let key3 = ServiceKey( - serviceType: Animal.self, - argumentsType: (Resolver, String, Bool).self, - option: Option(option: 1) - ) - let key4 = ServiceKey( - serviceType: Animal.self, - argumentsType: (Resolver, String, Bool).self, - option: Option(option: 1) - ) - expect(key3) == key4 - expect(key3.hashValue) == key4.hashValue - } - it("does not equal with different options.") { - let key1 = ServiceKey(serviceType: Animal.self, argumentsType: Resolver.self, option: Option(option: 1)) - let key2 = ServiceKey(serviceType: Animal.self, argumentsType: Resolver.self, option: Option(option: 2)) - expect(key1) != key2 - expect(key1.hashValue) != key2.hashValue - - let key3 = ServiceKey( - serviceType: Animal.self, - argumentsType: (Resolver, String, Bool).self, - option: Option(option: 1) - ) - let key4 = ServiceKey( - serviceType: Animal.self, - argumentsType: (Resolver, String, Bool).self, - option: Option(option: 2) - ) - expect(key3) != key4 - expect(key3.hashValue) != key4.hashValue - } - } - } -} diff --git a/Tests/SwinjectTests/SynchronizedResolverSpec.swift b/Tests/SwinjectTests/SynchronizedResolverSpec.swift deleted file mode 100644 index 704bb92c..00000000 --- a/Tests/SwinjectTests/SynchronizedResolverSpec.swift +++ /dev/null @@ -1,145 +0,0 @@ -// -// SynchronizedResolverSpec.swift -// Swinject -// -// Created by Yoichi Tagaya on 11/23/15. -// Copyright © 2015 Swinject Contributors. All rights reserved. -// - -import Dispatch -import Quick -import Nimble -@testable import Swinject - -class SynchronizedResolverSpec: QuickSpec { - override func spec() { - describe("Multiple threads") { - it("can resolve circular dependencies.") { - let container = Container { container in - container.register(ParentProtocol.self) { _ in Parent() } - .initCompleted { r, s in - let parent = s as! Parent - parent.child = r.resolve(ChildProtocol.self) - } - .inObjectScope(.graph) - container.register(ChildProtocol.self) { _ in Child() } - .initCompleted { r, s in - let child = s as! Child - child.parent = r.resolve(ParentProtocol.self)! - } - .inObjectScope(.graph) - }.synchronize() - - onMultipleThreads { - let parent = container.resolve(ParentProtocol.self) as! Parent - let child = parent.child as! Child - expect(child.parent as? Parent === parent).to(beTrue()) // Workaround for crash in Nimble - } - } - it("can access parent and child containers without dead lock.") { - let runInObjectScope = { (scope: ObjectScope) in - let parentContainer = Container { container in - container.register(Animal.self) { _ in Cat() } - .inObjectScope(scope) - } - let parentResolver = parentContainer.synchronize() - let childResolver = Container(parent: parentContainer).synchronize() - - onMultipleThreads(actions: [ - { _ = parentResolver.resolve(Animal.self) as! Cat }, // swiftlint:disable:this opening_brace - { _ = childResolver.resolve(Animal.self) as! Cat } - ]) - } - - runInObjectScope(.transient) - runInObjectScope(.graph) - runInObjectScope(.container) - } - it("uses distinct graph identifier") { - var graphs = Set() - let container = Container { - $0.register(Dog.self) { - graphs.insert(($0 as! Container).currentObjectGraph!) - return Dog() - } - }.synchronize() - - onMultipleThreads { _ = container.resolve(Dog.self) } - - expect(graphs.count) == totalThreads - } - } - describe("Nested resolve") { - it("can make it without deadlock") { - let container = Container() - let threadSafeResolver = container.synchronize() - container.register(ChildProtocol.self) { _ in Child() } - container.register(ParentProtocol.self) { _ in - Parent(child: threadSafeResolver.resolve(ChildProtocol.self)!) - } - - let queue = DispatchQueue( - label: "SwinjectTests.SynchronizedContainerSpec.Queue", attributes: .concurrent - ) - waitUntil(timeout: 2.0) { done in - queue.async { - _ = threadSafeResolver.resolve(ParentProtocol.self) - done() - } - } - } - } - } -} - -fileprivate final class Counter { - enum Status { - case underMax, reachedMax - } - - private var max: Int - private let lock = DispatchQueue(label: "SwinjectTests.SynchronizedContainerSpec.Counter.Lock", attributes: []) - var count = 0 - - init(max: Int) { - self.max = max - } - - @discardableResult - func increment() -> Status { - var status = Status.underMax - lock.sync { - self.count += 1 - if self.count >= self.max { - status = .reachedMax - } - } - return status - } -} - -private let totalThreads = 500 // 500 threads are enough to get fail unless the container is thread safe. - -private func onMultipleThreads(action: @escaping () -> Void) { - onMultipleThreads(actions: [action]) -} - -private func onMultipleThreads(actions: [() -> Void]) { - waitUntil(timeout: 2.0) { done in - let queue = DispatchQueue( - label: "SwinjectTests.SynchronizedContainerSpec.Queue", - attributes: .concurrent - ) - let counter = Counter(max: actions.count * totalThreads) - for _ in 0.. $file.swift -done From 30d0a15a91e246c10173db20f8bcbbb9adc2afed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sat, 13 Jul 2019 17:27:40 +0200 Subject: [PATCH 002/239] Implement module builder --- Sources/ModuleBuilder.swift | 34 +++++++++++ Swinject.xcodeproj/project.pbxproj | 59 +++++++++++++++---- .../xcshareddata/swiftpm/Package.resolved | 9 +++ .../xcschemes/Swinject-OSX.xcscheme | 4 +- Tests/ModuleBuilderSpec.swift | 58 ++++++++++++++++++ Tests/SwinjectTests.swift | 34 ----------- 6 files changed, 151 insertions(+), 47 deletions(-) create mode 100644 Sources/ModuleBuilder.swift create mode 100644 Tests/ModuleBuilderSpec.swift delete mode 100644 Tests/SwinjectTests.swift diff --git a/Sources/ModuleBuilder.swift b/Sources/ModuleBuilder.swift new file mode 100644 index 00000000..7a7f6ce6 --- /dev/null +++ b/Sources/ModuleBuilder.swift @@ -0,0 +1,34 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +public protocol ModuleEntry {} + +@_functionBuilder +public enum ModuleBuilder { + public typealias Entry = ModuleEntry + + public static func buildBlock(_ input: Entry ...) -> [Entry] { + input.flatMap(unpack) + } + + public static func buildIf(_ input: [Entry]?) -> Entry { + Composed(parts: input ?? []) + } + + public static func buildEither(first input: [Entry]) -> Entry { + Composed(parts: input) + } + + public static func buildEither(second input: [Entry]) -> Entry { + Composed(parts: input) + } + + private struct Composed: Entry { + let parts: [Entry] + } + + private static func unpack(entry: Entry) -> [Entry] { + if let entry = entry as? Composed { return entry.parts } else { return [entry] } + } +} diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index b808169c..fc1ea2db 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -7,11 +7,13 @@ objects = { /* Begin PBXBuildFile section */ - 771BFC7A22D5F83E00AFB237 /* Swinject_OSX.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 771BFC7022D5F83E00AFB237 /* Swinject_OSX.framework */; }; - 771BFC7F22D5F83E00AFB237 /* SwinjectTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 771BFC7E22D5F83E00AFB237 /* SwinjectTests.swift */; }; + 771BFC7A22D5F83E00AFB237 /* Swinject3.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 771BFC7022D5F83E00AFB237 /* Swinject3.framework */; }; 771BFC8122D5F83E00AFB237 /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 771BFC7322D5F83E00AFB237 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; 771BFC9122D600B700AFB237 /* Nimble in Frameworks */ = {isa = PBXBuildFile; productRef = 771BFC9022D600B700AFB237 /* Nimble */; }; 771BFC9422D600CC00AFB237 /* Quick in Frameworks */ = {isa = PBXBuildFile; productRef = 771BFC9322D600CC00AFB237 /* Quick */; }; + CDD837FF22DA279C003E9909 /* Swinject in Frameworks */ = {isa = PBXBuildFile; productRef = CDD837FE22DA279C003E9909 /* Swinject */; }; + CDD8380122DA27EE003E9909 /* ModuleBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380022DA27EE003E9909 /* ModuleBuilder.swift */; }; + CDD8380322DA2B67003E9909 /* ModuleBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380222DA2B67003E9909 /* ModuleBuilderSpec.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -25,14 +27,15 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 771BFC7022D5F83E00AFB237 /* Swinject_OSX.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject_OSX.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 771BFC7022D5F83E00AFB237 /* Swinject3.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject3.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 771BFC7322D5F83E00AFB237 /* Swinject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Swinject.h; sourceTree = ""; }; 771BFC7422D5F83E00AFB237 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 771BFC7922D5F83E00AFB237 /* SwinjectTests-OSX.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SwinjectTests-OSX.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; - 771BFC7E22D5F83E00AFB237 /* SwinjectTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTests.swift; sourceTree = ""; }; 771BFC8022D5F83E00AFB237 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 771BFC8B22D5FAAE00AFB237 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nimble.framework; path = Carthage/Build/Mac/Nimble.framework; sourceTree = ""; }; 771BFC8C22D5FAAE00AFB237 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quick.framework; path = Carthage/Build/Mac/Quick.framework; sourceTree = ""; }; + CDD8380022DA27EE003E9909 /* ModuleBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModuleBuilder.swift; sourceTree = ""; }; + CDD8380222DA2B67003E9909 /* ModuleBuilderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModuleBuilderSpec.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -40,6 +43,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + CDD837FF22DA279C003E9909 /* Swinject in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -47,7 +51,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 771BFC7A22D5F83E00AFB237 /* Swinject_OSX.framework in Frameworks */, + 771BFC7A22D5F83E00AFB237 /* Swinject3.framework in Frameworks */, 771BFC9422D600CC00AFB237 /* Quick in Frameworks */, 771BFC9122D600B700AFB237 /* Nimble in Frameworks */, ); @@ -69,7 +73,7 @@ 771BFC7122D5F83E00AFB237 /* Products */ = { isa = PBXGroup; children = ( - 771BFC7022D5F83E00AFB237 /* Swinject_OSX.framework */, + 771BFC7022D5F83E00AFB237 /* Swinject3.framework */, 771BFC7922D5F83E00AFB237 /* SwinjectTests-OSX.xctest */, ); name = Products; @@ -80,6 +84,7 @@ children = ( 771BFC7322D5F83E00AFB237 /* Swinject.h */, 771BFC7422D5F83E00AFB237 /* Info.plist */, + CDD8380022DA27EE003E9909 /* ModuleBuilder.swift */, ); path = Sources; sourceTree = ""; @@ -87,8 +92,8 @@ 771BFC7D22D5F83E00AFB237 /* Tests */ = { isa = PBXGroup; children = ( - 771BFC7E22D5F83E00AFB237 /* SwinjectTests.swift */, 771BFC8022D5F83E00AFB237 /* Info.plist */, + CDD8380222DA2B67003E9909 /* ModuleBuilderSpec.swift */, ); path = Tests; sourceTree = ""; @@ -130,8 +135,11 @@ dependencies = ( ); name = "Swinject-OSX"; + packageProductDependencies = ( + CDD837FE22DA279C003E9909 /* Swinject */, + ); productName = Swinject; - productReference = 771BFC7022D5F83E00AFB237 /* Swinject_OSX.framework */; + productReference = 771BFC7022D5F83E00AFB237 /* Swinject3.framework */; productType = "com.apple.product-type.framework"; }; 771BFC7822D5F83E00AFB237 /* SwinjectTests-OSX */ = { @@ -168,9 +176,11 @@ TargetAttributes = { 771BFC6F22D5F83E00AFB237 = { CreatedOnToolsVersion = 11.0; + LastSwiftMigration = 1100; }; 771BFC7822D5F83E00AFB237 = { CreatedOnToolsVersion = 11.0; + LastSwiftMigration = 1100; }; }; }; @@ -186,6 +196,7 @@ packageReferences = ( 771BFC8F22D600B700AFB237 /* XCRemoteSwiftPackageReference "Nimble" */, 771BFC9222D600CC00AFB237 /* XCRemoteSwiftPackageReference "Quick" */, + CDD837FD22DA279C003E9909 /* XCRemoteSwiftPackageReference "swinject" */, ); productRefGroup = 771BFC7122D5F83E00AFB237 /* Products */; projectDirPath = ""; @@ -219,6 +230,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + CDD8380122DA27EE003E9909 /* ModuleBuilder.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -226,7 +238,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 771BFC7F22D5F83E00AFB237 /* SwinjectTests.swift in Sources */, + CDD8380322DA2B67003E9909 /* ModuleBuilderSpec.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -365,6 +377,7 @@ 771BFC8522D5F83E00AFB237 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; DEFINES_MODULE = YES; @@ -379,14 +392,17 @@ "@loader_path/Frameworks", ); PRODUCT_BUNDLE_IDENTIFIER = "com.el-eleven.Swinject"; - PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + PRODUCT_NAME = Swinject3; SKIP_INSTALL = YES; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; }; name = Debug; }; 771BFC8622D5F83E00AFB237 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; DEFINES_MODULE = YES; @@ -401,14 +417,17 @@ "@loader_path/Frameworks", ); PRODUCT_BUNDLE_IDENTIFIER = "com.el-eleven.Swinject"; - PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + PRODUCT_NAME = Swinject3; SKIP_INSTALL = YES; + SWIFT_VERSION = 5.0; }; name = Release; }; 771BFC8822D5F83E00AFB237 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; FRAMEWORK_SEARCH_PATHS = ( @@ -423,12 +442,16 @@ ); PRODUCT_BUNDLE_IDENTIFIER = "com.el-eleven.SwinjectTests"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; }; name = Debug; }; 771BFC8922D5F83E00AFB237 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; FRAMEWORK_SEARCH_PATHS = ( @@ -443,6 +466,7 @@ ); PRODUCT_BUNDLE_IDENTIFIER = "com.el-eleven.SwinjectTests"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -495,6 +519,14 @@ minimumVersion = 2.1.0; }; }; + CDD837FD22DA279C003E9909 /* XCRemoteSwiftPackageReference "swinject" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/swinject/swinject"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 2.6.2; + }; + }; /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ @@ -508,6 +540,11 @@ package = 771BFC9222D600CC00AFB237 /* XCRemoteSwiftPackageReference "Quick" */; productName = Quick; }; + CDD837FE22DA279C003E9909 /* Swinject */ = { + isa = XCSwiftPackageProductDependency; + package = CDD837FD22DA279C003E9909 /* XCRemoteSwiftPackageReference "swinject" */; + productName = Swinject; + }; /* End XCSwiftPackageProductDependency section */ }; rootObject = 771BFC6722D5F83E00AFB237 /* Project object */; diff --git a/Swinject.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Swinject.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 9c4b5d95..6a9f290e 100644 --- a/Swinject.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Swinject.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -18,6 +18,15 @@ "revision": "94df9b449508344667e5afc7e80f8bcbff1e4c37", "version": "2.1.0" } + }, + { + "package": "Swinject", + "repositoryURL": "https://github.com/swinject/swinject", + "state": { + "branch": null, + "revision": "1b7527c74d59e22843bf2f5041cac4d18ad9df8e", + "version": "2.6.2" + } } ] }, diff --git a/Swinject.xcodeproj/xcshareddata/xcschemes/Swinject-OSX.xcscheme b/Swinject.xcodeproj/xcshareddata/xcschemes/Swinject-OSX.xcscheme index aa8790d9..d77f50d1 100644 --- a/Swinject.xcodeproj/xcshareddata/xcschemes/Swinject-OSX.xcscheme +++ b/Swinject.xcodeproj/xcshareddata/xcschemes/Swinject-OSX.xcscheme @@ -15,7 +15,7 @@ @@ -61,7 +61,7 @@ diff --git a/Tests/ModuleBuilderSpec.swift b/Tests/ModuleBuilderSpec.swift new file mode 100644 index 00000000..592f865f --- /dev/null +++ b/Tests/ModuleBuilderSpec.swift @@ -0,0 +1,58 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +import Quick +import Nimble +import Swinject3 + +class ModuleBuilderSpec: QuickSpec { override func spec() { + it("builds empty function") { + @ModuleBuilder func build() -> [ModuleEntry] { + + } + expect(build().count) == 0 + } + it("builds function with single entry") { + @ModuleBuilder func build() -> [ModuleEntry] { + AnyEntry() + } + expect(build().count) == 1 + } + it("builds function with multiple entries") { + @ModuleBuilder func build() -> [ModuleEntry] { + AnyEntry(); AnyEntry(); AnyEntry(); AnyEntry(); AnyEntry() + } + expect(build().count) == 5 + } + it("builds function with if statement") { + @ModuleBuilder func build(_ flag: Bool) -> [ModuleEntry] { + if flag { AnyEntry() } + } + expect(build(true).count) == 1 + expect(build(false).count) == 0 + } + it("builds function with nested if statement") { + @ModuleBuilder func build(_ flag1: Bool, _ flag2: Bool) -> [ModuleEntry] { + if flag1 { + AnyEntry() + if flag2 { AnyEntry() } + } + } + expect(build(true, true).count) == 2 + expect(build(true, false).count) == 1 + } + it("builds function with if else statement") { + @ModuleBuilder func build(_ flag: Bool) -> [ModuleEntry] { + if flag { + AnyEntry() + } else { + AnyEntry(); AnyEntry() + } + } + expect(build(true).count) == 1 + expect(build(false).count) == 2 + } +}} + +struct AnyEntry: ModuleEntry {} diff --git a/Tests/SwinjectTests.swift b/Tests/SwinjectTests.swift deleted file mode 100644 index 8b983cb6..00000000 --- a/Tests/SwinjectTests.swift +++ /dev/null @@ -1,34 +0,0 @@ -// -// SwinjectTests.swift -// SwinjectTests -// -// Created by Jakub Vano on 10/07/2019. -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -import XCTest -@testable import Swinject - -class SwinjectTests: XCTestCase { - - override func setUp() { - // Put setup code here. This method is called before the invocation of each test method in the class. - } - - override func tearDown() { - // Put teardown code here. This method is called after the invocation of each test method in the class. - } - - func testExample() { - // This is an example of a functional test case. - // Use XCTAssert and related functions to verify your tests produce the correct results. - } - - func testPerformanceExample() { - // This is an example of a performance test case. - self.measure { - // Put the code you want to measure the time of here. - } - } - -} From 7e4592fdcc536a9e3cb21b4a80e780467de57030 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sat, 13 Jul 2019 18:13:18 +0200 Subject: [PATCH 003/239] Implement binding request definition --- Sources/BindingRequest.swift | 23 +++++++++++++++++++++++ Sources/TypeDescriptor.swift | 23 +++++++++++++++++++++++ Swinject.xcodeproj/project.pbxproj | 12 ++++++++++++ Tests/BindingRequestSpec.swift | 29 +++++++++++++++++++++++++++++ Tests/ModuleBuilderSpec.swift | 2 +- 5 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 Sources/BindingRequest.swift create mode 100644 Sources/TypeDescriptor.swift create mode 100644 Tests/BindingRequestSpec.swift diff --git a/Sources/BindingRequest.swift b/Sources/BindingRequest.swift new file mode 100644 index 00000000..1fdcb6d0 --- /dev/null +++ b/Sources/BindingRequest.swift @@ -0,0 +1,23 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +public struct BindingRequest { + let typeDescriptor: AnyTypeDescriptor + + init(typeDescriptor: Descriptor) where Descriptor: TypeDescriptor, Descriptor.BaseType == BaseType { + self.typeDescriptor = typeDescriptor + } +} + +public func bind(_: Type.Type) -> BindingRequest { + BindingRequest(typeDescriptor: plain(Type.self)) +} + +public func bind(_: Type.Type, tagged tag: Tag) -> BindingRequest where Tag: Equatable { + BindingRequest(typeDescriptor: tagged(Type.self, with: tag)) +} + +public func bind(_ descriptor: Descriptor) -> BindingRequest where Descriptor: TypeDescriptor { + BindingRequest(typeDescriptor: descriptor) +} diff --git a/Sources/TypeDescriptor.swift b/Sources/TypeDescriptor.swift new file mode 100644 index 00000000..b721151a --- /dev/null +++ b/Sources/TypeDescriptor.swift @@ -0,0 +1,23 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +public protocol AnyTypeDescriptor {} + +public protocol TypeDescriptor: AnyTypeDescriptor { + associatedtype BaseType +} + +struct NoTag: Equatable {} + +struct Tagged: TypeDescriptor where Tag: Equatable{ + let tag: Tag +} + +func tagged(_: Type.Type, with tag: Tag) -> Tagged where Tag: Equatable { + Tagged(tag: tag) +} + +func plain(_: Type.Type) -> Tagged { + Tagged(tag: NoTag()) +} diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index fc1ea2db..7d573311 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -14,6 +14,9 @@ CDD837FF22DA279C003E9909 /* Swinject in Frameworks */ = {isa = PBXBuildFile; productRef = CDD837FE22DA279C003E9909 /* Swinject */; }; CDD8380122DA27EE003E9909 /* ModuleBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380022DA27EE003E9909 /* ModuleBuilder.swift */; }; CDD8380322DA2B67003E9909 /* ModuleBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380222DA2B67003E9909 /* ModuleBuilderSpec.swift */; }; + CDD8380522DA307F003E9909 /* BindingRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380422DA307F003E9909 /* BindingRequest.swift */; }; + CDD8380722DA30C6003E9909 /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380622DA30C6003E9909 /* TypeDescriptor.swift */; }; + CDD8380A22DA31D9003E9909 /* BindingRequestSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380822DA31C6003E9909 /* BindingRequestSpec.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -36,6 +39,9 @@ 771BFC8C22D5FAAE00AFB237 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quick.framework; path = Carthage/Build/Mac/Quick.framework; sourceTree = ""; }; CDD8380022DA27EE003E9909 /* ModuleBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModuleBuilder.swift; sourceTree = ""; }; CDD8380222DA2B67003E9909 /* ModuleBuilderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModuleBuilderSpec.swift; sourceTree = ""; }; + CDD8380422DA307F003E9909 /* BindingRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingRequest.swift; sourceTree = ""; }; + CDD8380622DA30C6003E9909 /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; + CDD8380822DA31C6003E9909 /* BindingRequestSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingRequestSpec.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -85,6 +91,8 @@ 771BFC7322D5F83E00AFB237 /* Swinject.h */, 771BFC7422D5F83E00AFB237 /* Info.plist */, CDD8380022DA27EE003E9909 /* ModuleBuilder.swift */, + CDD8380422DA307F003E9909 /* BindingRequest.swift */, + CDD8380622DA30C6003E9909 /* TypeDescriptor.swift */, ); path = Sources; sourceTree = ""; @@ -94,6 +102,7 @@ children = ( 771BFC8022D5F83E00AFB237 /* Info.plist */, CDD8380222DA2B67003E9909 /* ModuleBuilderSpec.swift */, + CDD8380822DA31C6003E9909 /* BindingRequestSpec.swift */, ); path = Tests; sourceTree = ""; @@ -230,7 +239,9 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + CDD8380722DA30C6003E9909 /* TypeDescriptor.swift in Sources */, CDD8380122DA27EE003E9909 /* ModuleBuilder.swift in Sources */, + CDD8380522DA307F003E9909 /* BindingRequest.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -238,6 +249,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + CDD8380A22DA31D9003E9909 /* BindingRequestSpec.swift in Sources */, CDD8380322DA2B67003E9909 /* ModuleBuilderSpec.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Tests/BindingRequestSpec.swift b/Tests/BindingRequestSpec.swift new file mode 100644 index 00000000..ef4e6f1b --- /dev/null +++ b/Tests/BindingRequestSpec.swift @@ -0,0 +1,29 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +import Quick +import Nimble +@testable import Swinject3 + +class BindingRequestSpec: QuickSpec { override func spec() { + describe("type descriptor") { + it("is correct for simple type") { + let request = Swinject3.bind(Int.self) + let descriptor = request.typeDescriptor as? Tagged + expect(descriptor).notTo(beNil()) + } + it("has correct tag for tagged type") { + let request = Swinject3.bind(Int.self, tagged: "Foo") + let descriptor = request.typeDescriptor as? Tagged + expect(descriptor?.tag) == "Foo" + } + it("is used if given as parameter") { + struct Descriptor: TypeDescriptor { typealias BaseType = Int } + let request = Swinject3.bind(Descriptor()) + expect(request.typeDescriptor is Descriptor).to(beTrue()) + } + } +}} + + diff --git a/Tests/ModuleBuilderSpec.swift b/Tests/ModuleBuilderSpec.swift index 592f865f..bd889b04 100644 --- a/Tests/ModuleBuilderSpec.swift +++ b/Tests/ModuleBuilderSpec.swift @@ -4,7 +4,7 @@ import Quick import Nimble -import Swinject3 +@testable import Swinject3 class ModuleBuilderSpec: QuickSpec { override func spec() { it("builds empty function") { From 5f3064e94dbeb431dbc5404d5f705f9a9e498efb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sat, 13 Jul 2019 18:36:47 +0200 Subject: [PATCH 004/239] Implement binding creation --- Sources/Binding.swift | 8 +++++++ Sources/BindingRequest.swift | 18 ++++++++++----- Sources/TypeManipulator.swift | 9 ++++++++ Swinject.xcodeproj/project.pbxproj | 8 +++++++ Tests/BindingRequestSpec.swift | 37 ++++++++++++++++++++++-------- 5 files changed, 65 insertions(+), 15 deletions(-) create mode 100644 Sources/Binding.swift create mode 100644 Sources/TypeManipulator.swift diff --git a/Sources/Binding.swift b/Sources/Binding.swift new file mode 100644 index 00000000..2784ba96 --- /dev/null +++ b/Sources/Binding.swift @@ -0,0 +1,8 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +public struct Binding { + let descriptor: AnyTypeDescriptor + let manipulator: AnyTypeManipulator +} diff --git a/Sources/BindingRequest.swift b/Sources/BindingRequest.swift index 1fdcb6d0..200b034e 100644 --- a/Sources/BindingRequest.swift +++ b/Sources/BindingRequest.swift @@ -3,21 +3,27 @@ // public struct BindingRequest { - let typeDescriptor: AnyTypeDescriptor + let descriptor: AnyTypeDescriptor - init(typeDescriptor: Descriptor) where Descriptor: TypeDescriptor, Descriptor.BaseType == BaseType { - self.typeDescriptor = typeDescriptor + init(descriptor: Descriptor) where Descriptor: TypeDescriptor, Descriptor.BaseType == BaseType { + self.descriptor = descriptor } } public func bind(_: Type.Type) -> BindingRequest { - BindingRequest(typeDescriptor: plain(Type.self)) + BindingRequest(descriptor: plain(Type.self)) } public func bind(_: Type.Type, tagged tag: Tag) -> BindingRequest where Tag: Equatable { - BindingRequest(typeDescriptor: tagged(Type.self, with: tag)) + BindingRequest(descriptor: tagged(Type.self, with: tag)) } public func bind(_ descriptor: Descriptor) -> BindingRequest where Descriptor: TypeDescriptor { - BindingRequest(typeDescriptor: descriptor) + BindingRequest(descriptor: descriptor) +} + +public extension BindingRequest { + func with(_ manipulator: Manipulator) -> Binding where Manipulator: TypeManipulator, Manipulator.ManipulatedType == BaseType { + Binding(descriptor: descriptor, manipulator: manipulator) + } } diff --git a/Sources/TypeManipulator.swift b/Sources/TypeManipulator.swift new file mode 100644 index 00000000..1e93bdd0 --- /dev/null +++ b/Sources/TypeManipulator.swift @@ -0,0 +1,9 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +public protocol AnyTypeManipulator {} + +public protocol TypeManipulator: AnyTypeManipulator { + associatedtype ManipulatedType +} diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 7d573311..80213651 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -17,6 +17,8 @@ CDD8380522DA307F003E9909 /* BindingRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380422DA307F003E9909 /* BindingRequest.swift */; }; CDD8380722DA30C6003E9909 /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380622DA30C6003E9909 /* TypeDescriptor.swift */; }; CDD8380A22DA31D9003E9909 /* BindingRequestSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380822DA31C6003E9909 /* BindingRequestSpec.swift */; }; + CDD8380C22DA3AD8003E9909 /* TypeManipulator.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380B22DA3AD8003E9909 /* TypeManipulator.swift */; }; + CDD8380E22DA3B0D003E9909 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380D22DA3B0D003E9909 /* Binding.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -42,6 +44,8 @@ CDD8380422DA307F003E9909 /* BindingRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingRequest.swift; sourceTree = ""; }; CDD8380622DA30C6003E9909 /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; CDD8380822DA31C6003E9909 /* BindingRequestSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingRequestSpec.swift; sourceTree = ""; }; + CDD8380B22DA3AD8003E9909 /* TypeManipulator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeManipulator.swift; sourceTree = ""; }; + CDD8380D22DA3B0D003E9909 /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -93,6 +97,8 @@ CDD8380022DA27EE003E9909 /* ModuleBuilder.swift */, CDD8380422DA307F003E9909 /* BindingRequest.swift */, CDD8380622DA30C6003E9909 /* TypeDescriptor.swift */, + CDD8380B22DA3AD8003E9909 /* TypeManipulator.swift */, + CDD8380D22DA3B0D003E9909 /* Binding.swift */, ); path = Sources; sourceTree = ""; @@ -239,9 +245,11 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + CDD8380C22DA3AD8003E9909 /* TypeManipulator.swift in Sources */, CDD8380722DA30C6003E9909 /* TypeDescriptor.swift in Sources */, CDD8380122DA27EE003E9909 /* ModuleBuilder.swift in Sources */, CDD8380522DA307F003E9909 /* BindingRequest.swift in Sources */, + CDD8380E22DA3B0D003E9909 /* Binding.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Tests/BindingRequestSpec.swift b/Tests/BindingRequestSpec.swift index ef4e6f1b..f4a46b02 100644 --- a/Tests/BindingRequestSpec.swift +++ b/Tests/BindingRequestSpec.swift @@ -7,23 +7,42 @@ import Nimble @testable import Swinject3 class BindingRequestSpec: QuickSpec { override func spec() { - describe("type descriptor") { - it("is correct for simple type") { + describe("creation") { + it("descriptor is correct for simple type") { let request = Swinject3.bind(Int.self) - let descriptor = request.typeDescriptor as? Tagged + let descriptor = request.descriptor as? Tagged expect(descriptor).notTo(beNil()) } - it("has correct tag for tagged type") { + it("descriptor has correct tag for tagged type") { let request = Swinject3.bind(Int.self, tagged: "Foo") - let descriptor = request.typeDescriptor as? Tagged + let descriptor = request.descriptor as? Tagged expect(descriptor?.tag) == "Foo" } - it("is used if given as parameter") { - struct Descriptor: TypeDescriptor { typealias BaseType = Int } - let request = Swinject3.bind(Descriptor()) - expect(request.typeDescriptor is Descriptor).to(beTrue()) + it("descriptor is used if given as parameter") { + let descriptor = IntDescriptor() + let request = Swinject3.bind(descriptor) + expect(request.descriptor) === descriptor + } + } + describe("binding") { + it("produces binding with correct descriptor") { + let descriptor = IntDescriptor() + let binding = Swinject3.bind(descriptor).with(IntManipulator()) + expect(binding.descriptor) === descriptor + } + it("produces binding with correct manipulator") { + let manipulator = IntManipulator() + let binding = Swinject3.bind(Int.self).with(manipulator) + expect(binding.manipulator) === manipulator } } }} +// FIXME: generate with sourcery +class IntManipulator: TypeManipulator { + typealias ManipulatedType = Int +} +class IntDescriptor: TypeDescriptor { + typealias BaseType = Int +} From 9f084ee3442c8f5101c8042786f73a750532cc8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sat, 13 Jul 2019 18:45:33 +0200 Subject: [PATCH 005/239] Implement binding operator --- Sources/BindingRequest.swift | 4 ++++ Tests/BindingRequestSpec.swift | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Sources/BindingRequest.swift b/Sources/BindingRequest.swift index 200b034e..8a5b8b9c 100644 --- a/Sources/BindingRequest.swift +++ b/Sources/BindingRequest.swift @@ -27,3 +27,7 @@ public extension BindingRequest { Binding(descriptor: descriptor, manipulator: manipulator) } } + +public func & (lhs: BindingRequest, rhs: Manipulator) -> Binding where Manipulator: TypeManipulator, Manipulator.ManipulatedType == BaseType { + lhs.with(rhs) +} diff --git a/Tests/BindingRequestSpec.swift b/Tests/BindingRequestSpec.swift index f4a46b02..fed529e6 100644 --- a/Tests/BindingRequestSpec.swift +++ b/Tests/BindingRequestSpec.swift @@ -7,7 +7,7 @@ import Nimble @testable import Swinject3 class BindingRequestSpec: QuickSpec { override func spec() { - describe("creation") { + describe("`bind` method") { it("descriptor is correct for simple type") { let request = Swinject3.bind(Int.self) let descriptor = request.descriptor as? Tagged @@ -24,7 +24,7 @@ class BindingRequestSpec: QuickSpec { override func spec() { expect(request.descriptor) === descriptor } } - describe("binding") { + describe("`with` method") { it("produces binding with correct descriptor") { let descriptor = IntDescriptor() let binding = Swinject3.bind(descriptor).with(IntManipulator()) @@ -36,6 +36,18 @@ class BindingRequestSpec: QuickSpec { override func spec() { expect(binding.manipulator) === manipulator } } + describe("binding operator") { + it("produces binding with correct descriptor") { + let descriptor = IntDescriptor() + let binding = Swinject3.bind(descriptor) & IntManipulator() + expect(binding.descriptor) === descriptor + } + it("produces binding with correct manipulator") { + let manipulator = IntManipulator() + let binding = Swinject3.bind(Int.self) & manipulator + expect(binding.manipulator) === manipulator + } + } }} // FIXME: generate with sourcery From 1928d82251237d77834cf3b9a823b201d48df417 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sat, 13 Jul 2019 19:16:34 +0200 Subject: [PATCH 006/239] Implement property injector --- Sources/Binding.swift | 2 +- Sources/BindingRequest.swift | 8 ++++---- Sources/PropertyInjector.swift | 25 +++++++++++++++++++++++++ Sources/Provider.swift | 7 +++++++ Swinject.xcodeproj/project.pbxproj | 12 ++++++++++++ Tests/PropertyInjectorSpec.swift | 29 +++++++++++++++++++++++++++++ 6 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 Sources/PropertyInjector.swift create mode 100644 Sources/Provider.swift create mode 100644 Tests/PropertyInjectorSpec.swift diff --git a/Sources/Binding.swift b/Sources/Binding.swift index 2784ba96..694be8d4 100644 --- a/Sources/Binding.swift +++ b/Sources/Binding.swift @@ -2,7 +2,7 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -public struct Binding { +public struct Binding { let descriptor: AnyTypeDescriptor let manipulator: AnyTypeManipulator } diff --git a/Sources/BindingRequest.swift b/Sources/BindingRequest.swift index 8a5b8b9c..167ee3ab 100644 --- a/Sources/BindingRequest.swift +++ b/Sources/BindingRequest.swift @@ -2,10 +2,10 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -public struct BindingRequest { +public struct BindingRequest { let descriptor: AnyTypeDescriptor - init(descriptor: Descriptor) where Descriptor: TypeDescriptor, Descriptor.BaseType == BaseType { + init(descriptor: Descriptor) where Descriptor: TypeDescriptor, Descriptor.BaseType == Type { self.descriptor = descriptor } } @@ -23,11 +23,11 @@ public func bind(_ descriptor: Descriptor) -> BindingRequest(_ manipulator: Manipulator) -> Binding where Manipulator: TypeManipulator, Manipulator.ManipulatedType == BaseType { + func with(_ manipulator: Manipulator) -> Binding where Manipulator: TypeManipulator, Manipulator.ManipulatedType == Type { Binding(descriptor: descriptor, manipulator: manipulator) } } -public func & (lhs: BindingRequest, rhs: Manipulator) -> Binding where Manipulator: TypeManipulator, Manipulator.ManipulatedType == BaseType { +public func & (lhs: BindingRequest, rhs: Manipulator) -> Binding where Manipulator: TypeManipulator, Manipulator.ManipulatedType == Type { lhs.with(rhs) } diff --git a/Sources/PropertyInjector.swift b/Sources/PropertyInjector.swift new file mode 100644 index 00000000..dc3113f9 --- /dev/null +++ b/Sources/PropertyInjector.swift @@ -0,0 +1,25 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +public struct PropertyInjector: TypeManipulator { + public typealias ManipulatedType = Type + + private let injectionMethod: (Type, Provider) throws -> Void + + init(_ injectionMethod: @escaping (Type, Provider) throws -> Void) { + self.injectionMethod = injectionMethod + } + + func inject(_ instance: Type, using provider: Provider) throws { + try injectionMethod(instance, provider) + } +} + +public func injector(of: Type.Type, injectionMethod: @escaping (Type) throws -> Void) -> PropertyInjector { + PropertyInjector { instance, _ in try injectionMethod(instance) } +} + +public func injector(of: Type.Type, injectionMethod: @escaping (Type, Provider) throws -> Void) -> PropertyInjector { + PropertyInjector(injectionMethod) +} diff --git a/Sources/Provider.swift b/Sources/Provider.swift new file mode 100644 index 00000000..e33766a2 --- /dev/null +++ b/Sources/Provider.swift @@ -0,0 +1,7 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +public protocol Provider { + func instance(_ type: Descriptor) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor +} diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 80213651..3345082a 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -19,6 +19,9 @@ CDD8380A22DA31D9003E9909 /* BindingRequestSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380822DA31C6003E9909 /* BindingRequestSpec.swift */; }; CDD8380C22DA3AD8003E9909 /* TypeManipulator.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380B22DA3AD8003E9909 /* TypeManipulator.swift */; }; CDD8380E22DA3B0D003E9909 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380D22DA3B0D003E9909 /* Binding.swift */; }; + CDD8381022DA429F003E9909 /* Provider.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380F22DA429F003E9909 /* Provider.swift */; }; + CDD8381222DA43D7003E9909 /* PropertyInjector.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381122DA43D7003E9909 /* PropertyInjector.swift */; }; + CDD8381422DA45D8003E9909 /* PropertyInjectorSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381322DA45D8003E9909 /* PropertyInjectorSpec.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -46,6 +49,9 @@ CDD8380822DA31C6003E9909 /* BindingRequestSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingRequestSpec.swift; sourceTree = ""; }; CDD8380B22DA3AD8003E9909 /* TypeManipulator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeManipulator.swift; sourceTree = ""; }; CDD8380D22DA3B0D003E9909 /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; + CDD8380F22DA429F003E9909 /* Provider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Provider.swift; sourceTree = ""; }; + CDD8381122DA43D7003E9909 /* PropertyInjector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PropertyInjector.swift; sourceTree = ""; }; + CDD8381322DA45D8003E9909 /* PropertyInjectorSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PropertyInjectorSpec.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -98,6 +104,8 @@ CDD8380422DA307F003E9909 /* BindingRequest.swift */, CDD8380622DA30C6003E9909 /* TypeDescriptor.swift */, CDD8380B22DA3AD8003E9909 /* TypeManipulator.swift */, + CDD8381122DA43D7003E9909 /* PropertyInjector.swift */, + CDD8380F22DA429F003E9909 /* Provider.swift */, CDD8380D22DA3B0D003E9909 /* Binding.swift */, ); path = Sources; @@ -109,6 +117,7 @@ 771BFC8022D5F83E00AFB237 /* Info.plist */, CDD8380222DA2B67003E9909 /* ModuleBuilderSpec.swift */, CDD8380822DA31C6003E9909 /* BindingRequestSpec.swift */, + CDD8381322DA45D8003E9909 /* PropertyInjectorSpec.swift */, ); path = Tests; sourceTree = ""; @@ -246,6 +255,8 @@ buildActionMask = 2147483647; files = ( CDD8380C22DA3AD8003E9909 /* TypeManipulator.swift in Sources */, + CDD8381022DA429F003E9909 /* Provider.swift in Sources */, + CDD8381222DA43D7003E9909 /* PropertyInjector.swift in Sources */, CDD8380722DA30C6003E9909 /* TypeDescriptor.swift in Sources */, CDD8380122DA27EE003E9909 /* ModuleBuilder.swift in Sources */, CDD8380522DA307F003E9909 /* BindingRequest.swift in Sources */, @@ -258,6 +269,7 @@ buildActionMask = 2147483647; files = ( CDD8380A22DA31D9003E9909 /* BindingRequestSpec.swift in Sources */, + CDD8381422DA45D8003E9909 /* PropertyInjectorSpec.swift in Sources */, CDD8380322DA2B67003E9909 /* ModuleBuilderSpec.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Tests/PropertyInjectorSpec.swift b/Tests/PropertyInjectorSpec.swift new file mode 100644 index 00000000..300cdb88 --- /dev/null +++ b/Tests/PropertyInjectorSpec.swift @@ -0,0 +1,29 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +import Quick +import Nimble +@testable import Swinject3 + +class PropertyInjectorSpec: QuickSpec { override func spec() { + it("calls injection method with given instance") { + var passedInstance: Int? + let it = injector(of: Int.self) { passedInstance = $0 } + try? it.inject(42, using: FakeProvider()) + expect(passedInstance) == 42 + } + it("calls injection method with given provider") { + var passedProvider: Provider? + let provider = FakeProvider() + let it = injector(of: Int.self) { passedProvider = $1 } + try? it.inject(0, using: provider) + expect(passedProvider) === provider + } +}} + +class FakeProvider: Provider { + func instance(_ type: Descriptor) throws -> Descriptor.BaseType where Descriptor : TypeDescriptor { + fatalError() + } +} From 4baeb38ee050f644fe647cba3e9e5715e5e9884f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sat, 13 Jul 2019 20:16:38 +0200 Subject: [PATCH 007/239] Draft API for injecting instances --- Sources/Binding.swift | 2 +- Sources/Container.swift | 38 +++++++++++++++ Sources/Injector.swift | 13 +++++ Sources/ModuleBuilder.swift | 2 + Sources/Provider.swift | 6 +++ Sources/SwinjectError.swift | 13 +++++ ...pertyInjector.swift => TypeInjector.swift} | 10 ++-- Swinject.xcodeproj/project.pbxproj | 36 ++++++++++---- Tests/SwinjectApiSpec.swift | 47 +++++++++++++++++++ ...ectorSpec.swift => TypeInjectorSpec.swift} | 2 +- Tests/Utils.swift | 18 +++++++ 11 files changed, 172 insertions(+), 15 deletions(-) create mode 100644 Sources/Container.swift create mode 100644 Sources/Injector.swift create mode 100644 Sources/SwinjectError.swift rename Sources/{PropertyInjector.swift => TypeInjector.swift} (51%) create mode 100644 Tests/SwinjectApiSpec.swift rename Tests/{PropertyInjectorSpec.swift => TypeInjectorSpec.swift} (93%) create mode 100644 Tests/Utils.swift diff --git a/Sources/Binding.swift b/Sources/Binding.swift index 694be8d4..523f4834 100644 --- a/Sources/Binding.swift +++ b/Sources/Binding.swift @@ -2,7 +2,7 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -public struct Binding { +public struct Binding: ModuleEntry { let descriptor: AnyTypeDescriptor let manipulator: AnyTypeManipulator } diff --git a/Sources/Container.swift b/Sources/Container.swift new file mode 100644 index 00000000..f3218b23 --- /dev/null +++ b/Sources/Container.swift @@ -0,0 +1,38 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +public func container(@ModuleBuilder builder: () -> [ModuleEntry]) -> Injector { + Container(entries: builder()) +} + +public func container(@ModuleBuilder builder: () -> ModuleEntry) -> Injector { + Container(entries: [builder()]) +} + +public func container(@ModuleBuilder builder: () -> Void) -> Injector { + Container(entries: []) +} + +struct Container { + let entries: [ModuleEntry] +} + +extension Container: Injector { + func inject(_ instance: Descriptor.BaseType, descriptor: Descriptor) throws where Descriptor : TypeDescriptor { + let injectors = entries.compactMap { + ($0 as? Binding)?.manipulator as? TypeInjector + } + if let injector = injectors.first { + try injector.inject(instance, using: NoProvider()) + } else { + throw SwinjectError() + } + } +} + +private struct NoProvider: Provider { + func instance(_ type: Descriptor) throws -> Descriptor.BaseType where Descriptor : TypeDescriptor { + throw SwinjectError() + } +} diff --git a/Sources/Injector.swift b/Sources/Injector.swift new file mode 100644 index 00000000..e16f7a13 --- /dev/null +++ b/Sources/Injector.swift @@ -0,0 +1,13 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +public protocol Injector { + func inject(_ instance: Descriptor.BaseType, descriptor: Descriptor) throws where Descriptor: TypeDescriptor +} + +public extension Injector { + func inject(_ instance: Type) throws { + try inject(instance, descriptor: plain(Type.self)) + } +} diff --git a/Sources/ModuleBuilder.swift b/Sources/ModuleBuilder.swift index 7a7f6ce6..bbce796e 100644 --- a/Sources/ModuleBuilder.swift +++ b/Sources/ModuleBuilder.swift @@ -8,6 +8,8 @@ public protocol ModuleEntry {} public enum ModuleBuilder { public typealias Entry = ModuleEntry + public static func buildBlock() -> Void {} + public static func buildBlock(_ input: Entry ...) -> [Entry] { input.flatMap(unpack) } diff --git a/Sources/Provider.swift b/Sources/Provider.swift index e33766a2..e6ca9a22 100644 --- a/Sources/Provider.swift +++ b/Sources/Provider.swift @@ -5,3 +5,9 @@ public protocol Provider { func instance(_ type: Descriptor) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor } + +public extension Provider { + func instance() throws -> Type { + try instance(plain(Type.self)) + } +} diff --git a/Sources/SwinjectError.swift b/Sources/SwinjectError.swift new file mode 100644 index 00000000..048a4b20 --- /dev/null +++ b/Sources/SwinjectError.swift @@ -0,0 +1,13 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +struct SwinjectError: Error { + let file: String + let line: Int + + init(file: String = #file, line: Int = #line) { + self.file = file + self.line = line + } +} diff --git a/Sources/PropertyInjector.swift b/Sources/TypeInjector.swift similarity index 51% rename from Sources/PropertyInjector.swift rename to Sources/TypeInjector.swift index dc3113f9..28ca967b 100644 --- a/Sources/PropertyInjector.swift +++ b/Sources/TypeInjector.swift @@ -2,7 +2,7 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -public struct PropertyInjector: TypeManipulator { +public struct TypeInjector: TypeManipulator { public typealias ManipulatedType = Type private let injectionMethod: (Type, Provider) throws -> Void @@ -16,10 +16,10 @@ public struct PropertyInjector: TypeManipulator { } } -public func injector(of: Type.Type, injectionMethod: @escaping (Type) throws -> Void) -> PropertyInjector { - PropertyInjector { instance, _ in try injectionMethod(instance) } +public func injector(of: Type.Type = Type.self, injectionMethod: @escaping (Type) throws -> Void) -> TypeInjector { + TypeInjector { instance, _ in try injectionMethod(instance) } } -public func injector(of: Type.Type, injectionMethod: @escaping (Type, Provider) throws -> Void) -> PropertyInjector { - PropertyInjector(injectionMethod) +public func injector(of: Type.Type = Type.self, injectionMethod: @escaping (Type, Provider) throws -> Void) -> TypeInjector { + TypeInjector(injectionMethod) } diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 3345082a..bc3f132f 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -11,6 +11,7 @@ 771BFC8122D5F83E00AFB237 /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 771BFC7322D5F83E00AFB237 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; 771BFC9122D600B700AFB237 /* Nimble in Frameworks */ = {isa = PBXBuildFile; productRef = 771BFC9022D600B700AFB237 /* Nimble */; }; 771BFC9422D600CC00AFB237 /* Quick in Frameworks */ = {isa = PBXBuildFile; productRef = 771BFC9322D600CC00AFB237 /* Quick */; }; + CD85AF0C22DA574D00A8B7CA /* TypeInjectorSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF0A22DA574800A8B7CA /* TypeInjectorSpec.swift */; }; CDD837FF22DA279C003E9909 /* Swinject in Frameworks */ = {isa = PBXBuildFile; productRef = CDD837FE22DA279C003E9909 /* Swinject */; }; CDD8380122DA27EE003E9909 /* ModuleBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380022DA27EE003E9909 /* ModuleBuilder.swift */; }; CDD8380322DA2B67003E9909 /* ModuleBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380222DA2B67003E9909 /* ModuleBuilderSpec.swift */; }; @@ -20,8 +21,12 @@ CDD8380C22DA3AD8003E9909 /* TypeManipulator.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380B22DA3AD8003E9909 /* TypeManipulator.swift */; }; CDD8380E22DA3B0D003E9909 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380D22DA3B0D003E9909 /* Binding.swift */; }; CDD8381022DA429F003E9909 /* Provider.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380F22DA429F003E9909 /* Provider.swift */; }; - CDD8381222DA43D7003E9909 /* PropertyInjector.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381122DA43D7003E9909 /* PropertyInjector.swift */; }; - CDD8381422DA45D8003E9909 /* PropertyInjectorSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381322DA45D8003E9909 /* PropertyInjectorSpec.swift */; }; + CDD8381222DA43D7003E9909 /* TypeInjector.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381122DA43D7003E9909 /* TypeInjector.swift */; }; + CDD8381622DA4B55003E9909 /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381522DA4B55003E9909 /* Container.swift */; }; + CDD8381822DA4B74003E9909 /* Injector.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381722DA4B74003E9909 /* Injector.swift */; }; + CDD8381B22DA4CBE003E9909 /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381922DA4C9F003E9909 /* SwinjectApiSpec.swift */; }; + CDD8381D22DA4E02003E9909 /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381C22DA4E02003E9909 /* SwinjectError.swift */; }; + CDD8381F22DA4F6F003E9909 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381E22DA4F6F003E9909 /* Utils.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -42,6 +47,7 @@ 771BFC8022D5F83E00AFB237 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 771BFC8B22D5FAAE00AFB237 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nimble.framework; path = Carthage/Build/Mac/Nimble.framework; sourceTree = ""; }; 771BFC8C22D5FAAE00AFB237 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quick.framework; path = Carthage/Build/Mac/Quick.framework; sourceTree = ""; }; + CD85AF0A22DA574800A8B7CA /* TypeInjectorSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TypeInjectorSpec.swift; sourceTree = ""; }; CDD8380022DA27EE003E9909 /* ModuleBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModuleBuilder.swift; sourceTree = ""; }; CDD8380222DA2B67003E9909 /* ModuleBuilderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModuleBuilderSpec.swift; sourceTree = ""; }; CDD8380422DA307F003E9909 /* BindingRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingRequest.swift; sourceTree = ""; }; @@ -50,8 +56,12 @@ CDD8380B22DA3AD8003E9909 /* TypeManipulator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeManipulator.swift; sourceTree = ""; }; CDD8380D22DA3B0D003E9909 /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; CDD8380F22DA429F003E9909 /* Provider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Provider.swift; sourceTree = ""; }; - CDD8381122DA43D7003E9909 /* PropertyInjector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PropertyInjector.swift; sourceTree = ""; }; - CDD8381322DA45D8003E9909 /* PropertyInjectorSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PropertyInjectorSpec.swift; sourceTree = ""; }; + CDD8381122DA43D7003E9909 /* TypeInjector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeInjector.swift; sourceTree = ""; }; + CDD8381522DA4B55003E9909 /* Container.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.swift; sourceTree = ""; }; + CDD8381722DA4B74003E9909 /* Injector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Injector.swift; sourceTree = ""; }; + CDD8381922DA4C9F003E9909 /* SwinjectApiSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectApiSpec.swift; sourceTree = ""; }; + CDD8381C22DA4E02003E9909 /* SwinjectError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectError.swift; sourceTree = ""; }; + CDD8381E22DA4F6F003E9909 /* Utils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -104,9 +114,12 @@ CDD8380422DA307F003E9909 /* BindingRequest.swift */, CDD8380622DA30C6003E9909 /* TypeDescriptor.swift */, CDD8380B22DA3AD8003E9909 /* TypeManipulator.swift */, - CDD8381122DA43D7003E9909 /* PropertyInjector.swift */, + CDD8381122DA43D7003E9909 /* TypeInjector.swift */, CDD8380F22DA429F003E9909 /* Provider.swift */, + CDD8381722DA4B74003E9909 /* Injector.swift */, CDD8380D22DA3B0D003E9909 /* Binding.swift */, + CDD8381522DA4B55003E9909 /* Container.swift */, + CDD8381C22DA4E02003E9909 /* SwinjectError.swift */, ); path = Sources; sourceTree = ""; @@ -117,7 +130,9 @@ 771BFC8022D5F83E00AFB237 /* Info.plist */, CDD8380222DA2B67003E9909 /* ModuleBuilderSpec.swift */, CDD8380822DA31C6003E9909 /* BindingRequestSpec.swift */, - CDD8381322DA45D8003E9909 /* PropertyInjectorSpec.swift */, + CD85AF0A22DA574800A8B7CA /* TypeInjectorSpec.swift */, + CDD8381922DA4C9F003E9909 /* SwinjectApiSpec.swift */, + CDD8381E22DA4F6F003E9909 /* Utils.swift */, ); path = Tests; sourceTree = ""; @@ -256,9 +271,12 @@ files = ( CDD8380C22DA3AD8003E9909 /* TypeManipulator.swift in Sources */, CDD8381022DA429F003E9909 /* Provider.swift in Sources */, - CDD8381222DA43D7003E9909 /* PropertyInjector.swift in Sources */, + CDD8381222DA43D7003E9909 /* TypeInjector.swift in Sources */, + CDD8381D22DA4E02003E9909 /* SwinjectError.swift in Sources */, CDD8380722DA30C6003E9909 /* TypeDescriptor.swift in Sources */, + CDD8381822DA4B74003E9909 /* Injector.swift in Sources */, CDD8380122DA27EE003E9909 /* ModuleBuilder.swift in Sources */, + CDD8381622DA4B55003E9909 /* Container.swift in Sources */, CDD8380522DA307F003E9909 /* BindingRequest.swift in Sources */, CDD8380E22DA3B0D003E9909 /* Binding.swift in Sources */, ); @@ -268,9 +286,11 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + CDD8381F22DA4F6F003E9909 /* Utils.swift in Sources */, + CDD8381B22DA4CBE003E9909 /* SwinjectApiSpec.swift in Sources */, CDD8380A22DA31D9003E9909 /* BindingRequestSpec.swift in Sources */, - CDD8381422DA45D8003E9909 /* PropertyInjectorSpec.swift in Sources */, CDD8380322DA2B67003E9909 /* ModuleBuilderSpec.swift in Sources */, + CD85AF0C22DA574D00A8B7CA /* TypeInjectorSpec.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Tests/SwinjectApiSpec.swift b/Tests/SwinjectApiSpec.swift new file mode 100644 index 00000000..d47b421b --- /dev/null +++ b/Tests/SwinjectApiSpec.swift @@ -0,0 +1,47 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +import Quick +import Nimble +import Swinject3 + +class SwinjectApiSpec: QuickSpec { override func spec() { + describe("property injection") { + it("throws for empty container") { + let container = Swinject3.container { } + expect { try container.inject(42) }.to(throwError()) + } + it("does not throw if has required injector") { + let container = Swinject3.container { + bbind(Int.self) & injector { _ in } + } + expect { try container.inject(42) }.notTo(throwError()) + } + it("trows if does not have required injector") { + let container = Swinject3.container { + bbind(Double.self) & injector { _ in } + bbind(Int.self) & IntManipulator() + } + expect { try container.inject(42) }.to(throwError()) + } + it("injects intance using provided injector") { + let container = Swinject3.container { + bbind(Person.self) & injector { $0.age = 42 } + } + let person = Person() + try? container.inject(person) + expect(person.age) == 42 + } + it("throws if injecting type with missing dependency") { + let container = Swinject3.container { + bbind(Person.self) & injector { $0.age = try $1.instance() } + } + expect { try container.inject(Person()) }.to(throwError()) + } + } +}} + +class Person { + var age = 0 +} diff --git a/Tests/PropertyInjectorSpec.swift b/Tests/TypeInjectorSpec.swift similarity index 93% rename from Tests/PropertyInjectorSpec.swift rename to Tests/TypeInjectorSpec.swift index 300cdb88..2dcb0b4f 100644 --- a/Tests/PropertyInjectorSpec.swift +++ b/Tests/TypeInjectorSpec.swift @@ -6,7 +6,7 @@ import Quick import Nimble @testable import Swinject3 -class PropertyInjectorSpec: QuickSpec { override func spec() { +class TypeInjectorSpec: QuickSpec { override func spec() { it("calls injection method with given instance") { var passedInstance: Int? let it = injector(of: Int.self) { passedInstance = $0 } diff --git a/Tests/Utils.swift b/Tests/Utils.swift new file mode 100644 index 00000000..19efa12e --- /dev/null +++ b/Tests/Utils.swift @@ -0,0 +1,18 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +import Swinject3 + +// Original `bind` function conflicts with QuickSpec's instance method +func bbind(_: Type.Type) -> BindingRequest { + Swinject3.bind(Type.self) +} + +func bbind(_: Type.Type, tagged tag: Tag) -> BindingRequest where Tag: Equatable { + Swinject3.bind(Type.self, tagged: tag) +} + +func bbind(_ descriptor: Descriptor) -> BindingRequest where Descriptor: TypeDescriptor { + Swinject3.bind(descriptor) +} From 2ebeb76fe1787e8d0200000501a255e1019c1bf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sat, 13 Jul 2019 20:42:15 +0200 Subject: [PATCH 008/239] Implement factory & value type provider --- Sources/TypeProvider.swift | 25 +++++++++++++++++++ Swinject.xcodeproj/project.pbxproj | 12 +++++++++ Tests/BindingRequestSpec.swift | 9 ------- Tests/Fakes.swift | 19 +++++++++++++++ Tests/TypeInjectorSpec.swift | 9 +++---- Tests/TypeProviderSpec.swift | 39 ++++++++++++++++++++++++++++++ 6 files changed, 99 insertions(+), 14 deletions(-) create mode 100644 Sources/TypeProvider.swift create mode 100644 Tests/Fakes.swift create mode 100644 Tests/TypeProviderSpec.swift diff --git a/Sources/TypeProvider.swift b/Sources/TypeProvider.swift new file mode 100644 index 00000000..f4df01a1 --- /dev/null +++ b/Sources/TypeProvider.swift @@ -0,0 +1,25 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +public struct TypeProvider: TypeManipulator { + public typealias ManipulatedType = Type + + let factoryMethod: (Provider) throws -> Type + + func instance(using provider: Provider) throws -> Type { + try factoryMethod(provider) + } +} + +public func value(_ it: Type) -> TypeProvider { + TypeProvider { _ in it } +} + +public func factory(_ factoryMethod: @escaping () throws -> Type) -> TypeProvider { + TypeProvider { _ in try factoryMethod() } +} + +public func factory(_ factoryMethod: @escaping (Provider) throws -> Type) -> TypeProvider { + TypeProvider(factoryMethod: factoryMethod) +} diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index bc3f132f..cff188f6 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -12,6 +12,9 @@ 771BFC9122D600B700AFB237 /* Nimble in Frameworks */ = {isa = PBXBuildFile; productRef = 771BFC9022D600B700AFB237 /* Nimble */; }; 771BFC9422D600CC00AFB237 /* Quick in Frameworks */ = {isa = PBXBuildFile; productRef = 771BFC9322D600CC00AFB237 /* Quick */; }; CD85AF0C22DA574D00A8B7CA /* TypeInjectorSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF0A22DA574800A8B7CA /* TypeInjectorSpec.swift */; }; + CD85AF0E22DA57AD00A8B7CA /* TypeProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF0D22DA57AD00A8B7CA /* TypeProvider.swift */; }; + CD85AF1022DA586D00A8B7CA /* TypeProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF0F22DA586D00A8B7CA /* TypeProviderSpec.swift */; }; + CD85AF1222DA5A8F00A8B7CA /* Fakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF1122DA5A8F00A8B7CA /* Fakes.swift */; }; CDD837FF22DA279C003E9909 /* Swinject in Frameworks */ = {isa = PBXBuildFile; productRef = CDD837FE22DA279C003E9909 /* Swinject */; }; CDD8380122DA27EE003E9909 /* ModuleBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380022DA27EE003E9909 /* ModuleBuilder.swift */; }; CDD8380322DA2B67003E9909 /* ModuleBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380222DA2B67003E9909 /* ModuleBuilderSpec.swift */; }; @@ -48,6 +51,9 @@ 771BFC8B22D5FAAE00AFB237 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nimble.framework; path = Carthage/Build/Mac/Nimble.framework; sourceTree = ""; }; 771BFC8C22D5FAAE00AFB237 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quick.framework; path = Carthage/Build/Mac/Quick.framework; sourceTree = ""; }; CD85AF0A22DA574800A8B7CA /* TypeInjectorSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TypeInjectorSpec.swift; sourceTree = ""; }; + CD85AF0D22DA57AD00A8B7CA /* TypeProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeProvider.swift; sourceTree = ""; }; + CD85AF0F22DA586D00A8B7CA /* TypeProviderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeProviderSpec.swift; sourceTree = ""; }; + CD85AF1122DA5A8F00A8B7CA /* Fakes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Fakes.swift; sourceTree = ""; }; CDD8380022DA27EE003E9909 /* ModuleBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModuleBuilder.swift; sourceTree = ""; }; CDD8380222DA2B67003E9909 /* ModuleBuilderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModuleBuilderSpec.swift; sourceTree = ""; }; CDD8380422DA307F003E9909 /* BindingRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingRequest.swift; sourceTree = ""; }; @@ -115,6 +121,7 @@ CDD8380622DA30C6003E9909 /* TypeDescriptor.swift */, CDD8380B22DA3AD8003E9909 /* TypeManipulator.swift */, CDD8381122DA43D7003E9909 /* TypeInjector.swift */, + CD85AF0D22DA57AD00A8B7CA /* TypeProvider.swift */, CDD8380F22DA429F003E9909 /* Provider.swift */, CDD8381722DA4B74003E9909 /* Injector.swift */, CDD8380D22DA3B0D003E9909 /* Binding.swift */, @@ -131,8 +138,10 @@ CDD8380222DA2B67003E9909 /* ModuleBuilderSpec.swift */, CDD8380822DA31C6003E9909 /* BindingRequestSpec.swift */, CD85AF0A22DA574800A8B7CA /* TypeInjectorSpec.swift */, + CD85AF0F22DA586D00A8B7CA /* TypeProviderSpec.swift */, CDD8381922DA4C9F003E9909 /* SwinjectApiSpec.swift */, CDD8381E22DA4F6F003E9909 /* Utils.swift */, + CD85AF1122DA5A8F00A8B7CA /* Fakes.swift */, ); path = Tests; sourceTree = ""; @@ -278,6 +287,7 @@ CDD8380122DA27EE003E9909 /* ModuleBuilder.swift in Sources */, CDD8381622DA4B55003E9909 /* Container.swift in Sources */, CDD8380522DA307F003E9909 /* BindingRequest.swift in Sources */, + CD85AF0E22DA57AD00A8B7CA /* TypeProvider.swift in Sources */, CDD8380E22DA3B0D003E9909 /* Binding.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -289,6 +299,8 @@ CDD8381F22DA4F6F003E9909 /* Utils.swift in Sources */, CDD8381B22DA4CBE003E9909 /* SwinjectApiSpec.swift in Sources */, CDD8380A22DA31D9003E9909 /* BindingRequestSpec.swift in Sources */, + CD85AF1222DA5A8F00A8B7CA /* Fakes.swift in Sources */, + CD85AF1022DA586D00A8B7CA /* TypeProviderSpec.swift in Sources */, CDD8380322DA2B67003E9909 /* ModuleBuilderSpec.swift in Sources */, CD85AF0C22DA574D00A8B7CA /* TypeInjectorSpec.swift in Sources */, ); diff --git a/Tests/BindingRequestSpec.swift b/Tests/BindingRequestSpec.swift index fed529e6..6bed2fb6 100644 --- a/Tests/BindingRequestSpec.swift +++ b/Tests/BindingRequestSpec.swift @@ -49,12 +49,3 @@ class BindingRequestSpec: QuickSpec { override func spec() { } } }} - -// FIXME: generate with sourcery -class IntManipulator: TypeManipulator { - typealias ManipulatedType = Int -} - -class IntDescriptor: TypeDescriptor { - typealias BaseType = Int -} diff --git a/Tests/Fakes.swift b/Tests/Fakes.swift new file mode 100644 index 00000000..9fb58752 --- /dev/null +++ b/Tests/Fakes.swift @@ -0,0 +1,19 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +import Swinject3 + +class FakeProvider: Provider { + func instance(_ type: Descriptor) throws -> Descriptor.BaseType where Descriptor : TypeDescriptor { + fatalError() + } +} + +class IntManipulator: TypeManipulator { + typealias ManipulatedType = Int +} + +class IntDescriptor: TypeDescriptor { + typealias BaseType = Int +} diff --git a/Tests/TypeInjectorSpec.swift b/Tests/TypeInjectorSpec.swift index 2dcb0b4f..7596620f 100644 --- a/Tests/TypeInjectorSpec.swift +++ b/Tests/TypeInjectorSpec.swift @@ -20,10 +20,9 @@ class TypeInjectorSpec: QuickSpec { override func spec() { try? it.inject(0, using: provider) expect(passedProvider) === provider } + it("rethrows injection method error") { + let it = injector(of: Int.self) { _ in throw SwinjectError() } + expect { try it.inject(0, using: FakeProvider()) }.to(throwError()) + } }} -class FakeProvider: Provider { - func instance(_ type: Descriptor) throws -> Descriptor.BaseType where Descriptor : TypeDescriptor { - fatalError() - } -} diff --git a/Tests/TypeProviderSpec.swift b/Tests/TypeProviderSpec.swift new file mode 100644 index 00000000..184b76d8 --- /dev/null +++ b/Tests/TypeProviderSpec.swift @@ -0,0 +1,39 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +import Quick +import Nimble +@testable import Swinject3 + +class TypeProviderSpec: QuickSpec { override func spec() { + describe("value") { + it("returns given value") { + let it = Swinject3.value(42) + expect { try it.instance(using: FakeProvider()) } == 42 + } + } + describe("factory") { + it("returns instance made by factory method") { + let it = Swinject3.factory { 42 } + expect { try it.instance(using: FakeProvider()) } == 42 + } + it("does not call factory method until instance is requested") { + var called = false + _ = Swinject3.factory { called = true } + expect(called).to(beFalse()) + } + it("calls facrory method with given provider") { + var passedProvider: Provider? + let provider = FakeProvider() + let it = Swinject3.factory { passedProvider = $0 } + _ = try? it.instance(using: provider) + expect(passedProvider) === provider + } + it("rethrows error from factory method") { + let it = Swinject3.factory { throw SwinjectError() } + expect { try it.instance(using: FakeProvider()) }.to(throwError()) + } + } + // TODO: Initializer +}} From e4c804e61ae20d9b4794cf860589177d3a8b6d64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sat, 13 Jul 2019 21:19:25 +0200 Subject: [PATCH 009/239] Describe API for instance provision --- Sources/BindingRequest.swift | 8 ++++++ Sources/Container.swift | 19 +++++++++----- Sources/Provider.swift | 2 +- Sources/SwinjectError.swift | 2 ++ Sources/TypeProvider.swift | 8 ++++-- Tests/BindingRequestSpec.swift | 8 ++++++ Tests/SwinjectApiSpec.swift | 46 ++++++++++++++++++++++++++++++++++ Tests/Utils.swift | 7 +++++- 8 files changed, 90 insertions(+), 10 deletions(-) diff --git a/Sources/BindingRequest.swift b/Sources/BindingRequest.swift index 167ee3ab..48aad387 100644 --- a/Sources/BindingRequest.swift +++ b/Sources/BindingRequest.swift @@ -26,8 +26,16 @@ public extension BindingRequest { func with(_ manipulator: Manipulator) -> Binding where Manipulator: TypeManipulator, Manipulator.ManipulatedType == Type { Binding(descriptor: descriptor, manipulator: manipulator) } + + func with(_ it: Type) -> Binding { + Binding(descriptor: descriptor, manipulator: value(it)) + } } public func & (lhs: BindingRequest, rhs: Manipulator) -> Binding where Manipulator: TypeManipulator, Manipulator.ManipulatedType == Type { lhs.with(rhs) } + +public func & (lhs: BindingRequest, rhs: Type) -> Binding { + lhs.with(rhs) +} diff --git a/Sources/Container.swift b/Sources/Container.swift index f3218b23..8809ebda 100644 --- a/Sources/Container.swift +++ b/Sources/Container.swift @@ -2,15 +2,15 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -public func container(@ModuleBuilder builder: () -> [ModuleEntry]) -> Injector { +public func container(@ModuleBuilder builder: () -> [ModuleEntry]) -> Injector & Provider { Container(entries: builder()) } -public func container(@ModuleBuilder builder: () -> ModuleEntry) -> Injector { +public func container(@ModuleBuilder builder: () -> ModuleEntry) -> Injector & Provider { Container(entries: [builder()]) } -public func container(@ModuleBuilder builder: () -> Void) -> Injector { +public func container(@ModuleBuilder builder: () -> Void) -> Injector & Provider { Container(entries: []) } @@ -24,15 +24,22 @@ extension Container: Injector { ($0 as? Binding)?.manipulator as? TypeInjector } if let injector = injectors.first { - try injector.inject(instance, using: NoProvider()) + try injector.inject(instance, using: self) } else { throw SwinjectError() } } } -private struct NoProvider: Provider { +extension Container: Provider { func instance(_ type: Descriptor) throws -> Descriptor.BaseType where Descriptor : TypeDescriptor { - throw SwinjectError() + let providers = entries.compactMap { + ($0 as? Binding)?.manipulator as? TypeProvider + } + if let provider = providers.first { + return try provider.instance(using: self) + } else { + throw SwinjectError() + } } } diff --git a/Sources/Provider.swift b/Sources/Provider.swift index e6ca9a22..ed526f42 100644 --- a/Sources/Provider.swift +++ b/Sources/Provider.swift @@ -7,7 +7,7 @@ public protocol Provider { } public extension Provider { - func instance() throws -> Type { + func instance(of: Type.Type = Type.self) throws -> Type { try instance(plain(Type.self)) } } diff --git a/Sources/SwinjectError.swift b/Sources/SwinjectError.swift index 048a4b20..2bed412e 100644 --- a/Sources/SwinjectError.swift +++ b/Sources/SwinjectError.swift @@ -11,3 +11,5 @@ struct SwinjectError: Error { self.line = line } } + +// TODO: Debugging error description diff --git a/Sources/TypeProvider.swift b/Sources/TypeProvider.swift index f4df01a1..1cb8ea8f 100644 --- a/Sources/TypeProvider.swift +++ b/Sources/TypeProvider.swift @@ -5,7 +5,11 @@ public struct TypeProvider: TypeManipulator { public typealias ManipulatedType = Type - let factoryMethod: (Provider) throws -> Type + private let factoryMethod: (Provider) throws -> Type + + init(_ factoryMethod: @escaping (Provider) throws -> Type) { + self.factoryMethod = factoryMethod + } func instance(using provider: Provider) throws -> Type { try factoryMethod(provider) @@ -21,5 +25,5 @@ public func factory(_ factoryMethod: @escaping () throws -> Type) -> TypeP } public func factory(_ factoryMethod: @escaping (Provider) throws -> Type) -> TypeProvider { - TypeProvider(factoryMethod: factoryMethod) + TypeProvider(factoryMethod) } diff --git a/Tests/BindingRequestSpec.swift b/Tests/BindingRequestSpec.swift index 6bed2fb6..46eda945 100644 --- a/Tests/BindingRequestSpec.swift +++ b/Tests/BindingRequestSpec.swift @@ -35,6 +35,10 @@ class BindingRequestSpec: QuickSpec { override func spec() { let binding = Swinject3.bind(Int.self).with(manipulator) expect(binding.manipulator) === manipulator } + it("produces type provider if given value of descriptor type") { + let binding = Swinject3.bind(Int.self).with(42) + expect(binding.manipulator is TypeProvider).to(beTrue()) + } } describe("binding operator") { it("produces binding with correct descriptor") { @@ -47,5 +51,9 @@ class BindingRequestSpec: QuickSpec { override func spec() { let binding = Swinject3.bind(Int.self) & manipulator expect(binding.manipulator) === manipulator } + it("produces type provider if given value of descriptor type") { + let binding = Swinject3.bind(Int.self) & 42 + expect(binding.manipulator is TypeProvider).to(beTrue()) + } } }} diff --git a/Tests/SwinjectApiSpec.swift b/Tests/SwinjectApiSpec.swift index d47b421b..e7d6f81e 100644 --- a/Tests/SwinjectApiSpec.swift +++ b/Tests/SwinjectApiSpec.swift @@ -39,9 +39,55 @@ class SwinjectApiSpec: QuickSpec { override func spec() { } expect { try container.inject(Person()) }.to(throwError()) } + it("injects dependency with defined provider") { + let container = Swinject3.container { + bbind(Person.self) & injector { $0.age = try $1.instance() } + bbind(Int.self).with(42) + } + let person = Person() + try? container.inject(person) + expect(person.age) == 42 + } + // TODO: Tags + // TODO: Multiple type injectors + // TODO: Arguments + } + describe("type provision") { + it("throws for empty container") { + let container = Swinject3.container { } + expect { try container.instance(of: Int.self) }.to(throwError()) + } + it("returns instance if provider is defined") { + let container = Swinject3.container { + bbind(Int.self).with(42) + } + expect { try container.instance(of: Int.self) } == 42 + } + it("throws if providing type with missing dependency") { + let container = Swinject3.container { + bbind(Pet.self) & factory { Pet(owner: try $0.instance()) } + } + expect { try container.instance(of: Pet.self) }.to(throwError()) + } + it("returns instance with defined dependency provider") { + let person = Person() + let container = Swinject3.container { + bbind(Pet.self) & factory { Pet(owner: try $0.instance()) } + bbind(Person.self) & person + } + expect { try container.instance(of: Pet.self).owner } === person + } + // TODO: injectors during intantiation + // TODO: Tags + // TODO: Multiple type providers + // TODO: Arguments } }} class Person { var age = 0 } + +struct Pet { + let owner: Person +} diff --git a/Tests/Utils.swift b/Tests/Utils.swift index 19efa12e..0477cdf8 100644 --- a/Tests/Utils.swift +++ b/Tests/Utils.swift @@ -4,7 +4,7 @@ import Swinject3 -// Original `bind` function conflicts with QuickSpec's instance method +// Original Swinject3 functions conflict with QuickSpec's instance methods func bbind(_: Type.Type) -> BindingRequest { Swinject3.bind(Type.self) } @@ -16,3 +16,8 @@ func bbind(_: Type.Type, tagged tag: Tag) -> BindingRequest whe func bbind(_ descriptor: Descriptor) -> BindingRequest where Descriptor: TypeDescriptor { Swinject3.bind(descriptor) } + +func vvalue(_ it: Type) -> TypeProvider { + Swinject3.value(it) +} + From 242d18d92d407042c18453b4405ee5a4ce853423 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sat, 13 Jul 2019 22:46:25 +0200 Subject: [PATCH 010/239] Define behavior for tagging & multiple manipulators --- Sources/Container.swift | 28 +++++++++++---------- Sources/Injector.swift | 4 +++ Sources/Provider.swift | 6 ++++- Sources/TypeDescriptor.swift | 9 ++++++- Tests/Fakes.swift | 4 +++ Tests/SwinjectApiSpec.swift | 49 ++++++++++++++++++++++++++++++------ 6 files changed, 78 insertions(+), 22 deletions(-) diff --git a/Sources/Container.swift b/Sources/Container.swift index 8809ebda..e4506feb 100644 --- a/Sources/Container.swift +++ b/Sources/Container.swift @@ -20,26 +20,28 @@ struct Container { extension Container: Injector { func inject(_ instance: Descriptor.BaseType, descriptor: Descriptor) throws where Descriptor : TypeDescriptor { - let injectors = entries.compactMap { - ($0 as? Binding)?.manipulator as? TypeInjector - } - if let injector = injectors.first { - try injector.inject(instance, using: self) - } else { + let injectors = entries + .compactMap { $0 as? Binding } + .filter { $0.descriptor.matches(descriptor) } + .compactMap { $0.manipulator as? TypeInjector } + if injectors.isEmpty { throw SwinjectError() + } else { + try injectors.forEach { try $0.inject(instance, using: self) } } } } extension Container: Provider { - func instance(_ type: Descriptor) throws -> Descriptor.BaseType where Descriptor : TypeDescriptor { - let providers = entries.compactMap { - ($0 as? Binding)?.manipulator as? TypeProvider - } - if let provider = providers.first { - return try provider.instance(using: self) - } else { + func instance(_ descriptor: Descriptor) throws -> Descriptor.BaseType where Descriptor : TypeDescriptor { + let providers = entries + .compactMap { $0 as? Binding } + .filter { $0.descriptor.matches(descriptor) } + .compactMap { $0.manipulator as? TypeProvider } + if providers.count != 1 { throw SwinjectError() + } else { + return try providers[0].instance(using: self) } } } diff --git a/Sources/Injector.swift b/Sources/Injector.swift index e16f7a13..8ec32ea3 100644 --- a/Sources/Injector.swift +++ b/Sources/Injector.swift @@ -10,4 +10,8 @@ public extension Injector { func inject(_ instance: Type) throws { try inject(instance, descriptor: plain(Type.self)) } + + func inject(_ instance: Type, tagged tag: Tag) throws { + try inject(instance, descriptor: tagged(Type.self, with: tag)) + } } diff --git a/Sources/Provider.swift b/Sources/Provider.swift index ed526f42..0e0e9dc3 100644 --- a/Sources/Provider.swift +++ b/Sources/Provider.swift @@ -3,11 +3,15 @@ // public protocol Provider { - func instance(_ type: Descriptor) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor + func instance(_ descriptor: Descriptor) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor } public extension Provider { func instance(of: Type.Type = Type.self) throws -> Type { try instance(plain(Type.self)) } + + func instance(of: Type.Type = Type.self, tagged tag: Tag) throws -> Type { + try instance(tagged(Type.self, with: tag)) + } } diff --git a/Sources/TypeDescriptor.swift b/Sources/TypeDescriptor.swift index b721151a..71362d75 100644 --- a/Sources/TypeDescriptor.swift +++ b/Sources/TypeDescriptor.swift @@ -2,7 +2,9 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -public protocol AnyTypeDescriptor {} +public protocol AnyTypeDescriptor { + func matches(_ other: Descriptor) -> Bool where Descriptor: TypeDescriptor +} public protocol TypeDescriptor: AnyTypeDescriptor { associatedtype BaseType @@ -12,6 +14,11 @@ struct NoTag: Equatable {} struct Tagged: TypeDescriptor where Tag: Equatable{ let tag: Tag + + func matches(_ other: Descriptor) -> Bool where Descriptor : TypeDescriptor { + guard let other = other as? Tagged else { return false } + return tag == other.tag + } } func tagged(_: Type.Type, with tag: Tag) -> Tagged where Tag: Equatable { diff --git a/Tests/Fakes.swift b/Tests/Fakes.swift index 9fb58752..a64602a5 100644 --- a/Tests/Fakes.swift +++ b/Tests/Fakes.swift @@ -16,4 +16,8 @@ class IntManipulator: TypeManipulator { class IntDescriptor: TypeDescriptor { typealias BaseType = Int + + func matches(_ other: Descriptor) -> Bool where Descriptor : TypeDescriptor { + false + } } diff --git a/Tests/SwinjectApiSpec.swift b/Tests/SwinjectApiSpec.swift index e7d6f81e..2cd585b1 100644 --- a/Tests/SwinjectApiSpec.swift +++ b/Tests/SwinjectApiSpec.swift @@ -8,6 +8,10 @@ import Swinject3 class SwinjectApiSpec: QuickSpec { override func spec() { describe("property injection") { + var person = Person() + beforeEach { + person = Person() + } it("throws for empty container") { let container = Swinject3.container { } expect { try container.inject(42) }.to(throwError()) @@ -29,7 +33,6 @@ class SwinjectApiSpec: QuickSpec { override func spec() { let container = Swinject3.container { bbind(Person.self) & injector { $0.age = 42 } } - let person = Person() try? container.inject(person) expect(person.age) == 42 } @@ -44,12 +47,28 @@ class SwinjectApiSpec: QuickSpec { override func spec() { bbind(Person.self) & injector { $0.age = try $1.instance() } bbind(Int.self).with(42) } - let person = Person() try? container.inject(person) expect(person.age) == 42 } - // TODO: Tags - // TODO: Multiple type injectors + it("injects instance using all defined injectors") { + let container = Swinject3.container { + bbind(Person.self) & injector { $0.age = 42 } + bbind(Person.self) & injector { $0.height = 123.4 } + bbind(Person.self) & injector { $0.name = "name" } + } + try? container.inject(person) + expect(person.age) == 42 + expect(person.height) == 123.4 + expect(person.name) == "name" + } + it("throws if injecting type with wrong tag") { + let container = Swinject3.container { + bbind(Person.self, tagged: "Tag") & injector { $0.age = 42 } + } + expect { try container.inject(person) }.to(throwError()) + expect { try container.inject(person, tagged: 42) }.to(throwError()) + expect { try container.inject(person, tagged: "OtherTag") }.to(throwError()) + } // TODO: Arguments } describe("type provision") { @@ -77,15 +96,31 @@ class SwinjectApiSpec: QuickSpec { override func spec() { } expect { try container.instance(of: Pet.self).owner } === person } - // TODO: injectors during intantiation - // TODO: Tags - // TODO: Multiple type providers + it("throws if multiple providers are defined") { + let container = Swinject3.container { + bbind(Int.self) & 42 + bbind(Int.self) & factory { 17 + 25 } + } + expect { try container.instance(of: Int.self) }.to(throwError()) + } + it("throws if requesting instance with wrong tag") { + let container = Swinject3.container { + bbind(Int.self, tagged: "Tag") & 42 + } + expect { try container.instance(of: Int.self) }.to(throwError()) + expect { try container.instance(of: Int.self, tagged: 42) }.to(throwError()) + expect { try container.instance(of: Int.self, tagged: "OtherTag") }.to(throwError()) + } + // TODO: Injectors during intantiation + // TODO: Reuse provider for multiple type descriptors // TODO: Arguments } }} class Person { var age = 0 + var height = 0.0 + var name = "" } struct Pet { From 593fced3b8b3df646deda2e9d54d11c1635e11f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sat, 13 Jul 2019 23:28:38 +0200 Subject: [PATCH 011/239] Use bound injectors when providing instance --- Sources/Container.swift | 6 +++-- Sources/SwinjectError.swift | 10 ++++++++ Tests/SwinjectApiSpec.swift | 47 ++++++++++++++++++++++++++----------- 3 files changed, 47 insertions(+), 16 deletions(-) diff --git a/Sources/Container.swift b/Sources/Container.swift index e4506feb..5ea59a94 100644 --- a/Sources/Container.swift +++ b/Sources/Container.swift @@ -25,7 +25,7 @@ extension Container: Injector { .filter { $0.descriptor.matches(descriptor) } .compactMap { $0.manipulator as? TypeInjector } if injectors.isEmpty { - throw SwinjectError() + throw MissingTypeInjector() } else { try injectors.forEach { try $0.inject(instance, using: self) } } @@ -41,7 +41,9 @@ extension Container: Provider { if providers.count != 1 { throw SwinjectError() } else { - return try providers[0].instance(using: self) + let instance = try providers[0].instance(using: self) + do { try inject(instance, descriptor: descriptor) } catch _ as MissingTypeInjector {} + return instance } } } diff --git a/Sources/SwinjectError.swift b/Sources/SwinjectError.swift index 2bed412e..03a895c9 100644 --- a/Sources/SwinjectError.swift +++ b/Sources/SwinjectError.swift @@ -12,4 +12,14 @@ struct SwinjectError: Error { } } +struct MissingTypeInjector: Error { + let file: String + let line: Int + + init(file: String = #file, line: Int = #line) { + self.file = file + self.line = line + } +} + // TODO: Debugging error description diff --git a/Tests/SwinjectApiSpec.swift b/Tests/SwinjectApiSpec.swift index 2cd585b1..0043128e 100644 --- a/Tests/SwinjectApiSpec.swift +++ b/Tests/SwinjectApiSpec.swift @@ -7,29 +7,29 @@ import Nimble import Swinject3 class SwinjectApiSpec: QuickSpec { override func spec() { + var person = Person() + beforeEach { + person = Person() + } describe("property injection") { - var person = Person() - beforeEach { - person = Person() - } it("throws for empty container") { let container = Swinject3.container { } expect { try container.inject(42) }.to(throwError()) } - it("does not throw if has required injector") { + it("does not throw if has bound injector") { let container = Swinject3.container { bbind(Int.self) & injector { _ in } } expect { try container.inject(42) }.notTo(throwError()) } - it("trows if does not have required injector") { + it("trows if does not have bound injector") { let container = Swinject3.container { bbind(Double.self) & injector { _ in } bbind(Int.self) & IntManipulator() } expect { try container.inject(42) }.to(throwError()) } - it("injects intance using provided injector") { + it("injects intance using bound injector") { let container = Swinject3.container { bbind(Person.self) & injector { $0.age = 42 } } @@ -42,7 +42,7 @@ class SwinjectApiSpec: QuickSpec { override func spec() { } expect { try container.inject(Person()) }.to(throwError()) } - it("injects dependency with defined provider") { + it("injects dependency with bound provider") { let container = Swinject3.container { bbind(Person.self) & injector { $0.age = try $1.instance() } bbind(Int.self).with(42) @@ -50,7 +50,7 @@ class SwinjectApiSpec: QuickSpec { override func spec() { try? container.inject(person) expect(person.age) == 42 } - it("injects instance using all defined injectors") { + it("injects instance using all bound injectors") { let container = Swinject3.container { bbind(Person.self) & injector { $0.age = 42 } bbind(Person.self) & injector { $0.height = 123.4 } @@ -76,7 +76,7 @@ class SwinjectApiSpec: QuickSpec { override func spec() { let container = Swinject3.container { } expect { try container.instance(of: Int.self) }.to(throwError()) } - it("returns instance if provider is defined") { + it("returns instance if provider is bound") { let container = Swinject3.container { bbind(Int.self).with(42) } @@ -88,15 +88,14 @@ class SwinjectApiSpec: QuickSpec { override func spec() { } expect { try container.instance(of: Pet.self) }.to(throwError()) } - it("returns instance with defined dependency provider") { - let person = Person() + it("returns instance from bound dependency provider") { let container = Swinject3.container { bbind(Pet.self) & factory { Pet(owner: try $0.instance()) } bbind(Person.self) & person } expect { try container.instance(of: Pet.self).owner } === person } - it("throws if multiple providers are defined") { + it("throws if multiple providers are bound") { let container = Swinject3.container { bbind(Int.self) & 42 bbind(Int.self) & factory { 17 + 25 } @@ -111,9 +110,29 @@ class SwinjectApiSpec: QuickSpec { override func spec() { expect { try container.instance(of: Int.self, tagged: 42) }.to(throwError()) expect { try container.instance(of: Int.self, tagged: "OtherTag") }.to(throwError()) } - // TODO: Injectors during intantiation // TODO: Reuse provider for multiple type descriptors + it("injects provided instance using bound injectors") { + let container = Swinject3.container { + bbind(Person.self) & Person() + bbind(Person.self) & injector { $0.age = 42 } + bbind(Person.self) & injector { $0.height = 123.4 } + bbind(Person.self) & injector { $0.name = "Name" } + } + let person = try? container.instance() as Person + expect(person?.age) == 42 + expect(person?.height) == 123.4 + expect(person?.name) == "Name" + } + it("throws if type has bound injector with missing dependency") { + let container = Swinject3.container { + bbind(Person.self) & Person() + bbind(Person.self) & injector { $0.age = try $1.instance() } + } + expect { try container.instance(of: Person.self) }.to(throwError()) + } + // TODO: Reuse binding request for multiple manipulators? // TODO: Arguments + // TODO: Less verbose type forwading API? } }} From c370d1e2dd65c0a0b17f0b5d8af4e3c6a67c069e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sat, 13 Jul 2019 23:29:11 +0200 Subject: [PATCH 012/239] Enable reuse of instance provider for multiple descriptors --- Sources/TypeProvider.swift | 6 ++++++ Tests/SwinjectApiSpec.swift | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Sources/TypeProvider.swift b/Sources/TypeProvider.swift index 1cb8ea8f..6c25a13f 100644 --- a/Sources/TypeProvider.swift +++ b/Sources/TypeProvider.swift @@ -27,3 +27,9 @@ public func factory(_ factoryMethod: @escaping () throws -> Type) -> TypeP public func factory(_ factoryMethod: @escaping (Provider) throws -> Type) -> TypeProvider { TypeProvider(factoryMethod) } + +public extension TypeProvider { + func map(_ transform: @escaping (Type) -> OtherType) -> TypeProvider { + TypeProvider { try transform(self.instance(using: $0)) } + } +} diff --git a/Tests/SwinjectApiSpec.swift b/Tests/SwinjectApiSpec.swift index 0043128e..da090798 100644 --- a/Tests/SwinjectApiSpec.swift +++ b/Tests/SwinjectApiSpec.swift @@ -110,7 +110,6 @@ class SwinjectApiSpec: QuickSpec { override func spec() { expect { try container.instance(of: Int.self, tagged: 42) }.to(throwError()) expect { try container.instance(of: Int.self, tagged: "OtherTag") }.to(throwError()) } - // TODO: Reuse provider for multiple type descriptors it("injects provided instance using bound injectors") { let container = Swinject3.container { bbind(Person.self) & Person() @@ -130,6 +129,15 @@ class SwinjectApiSpec: QuickSpec { override func spec() { } expect { try container.instance(of: Person.self) }.to(throwError()) } + it("can reuse provider for multiple descriptors") { + let personProvider = vvalue(person) // @functionBuilder does not support declarations in closures yet + let container = Swinject3.container { + bbind(Person.self) & personProvider + bbind(AnyObject.self) & personProvider.map { $0 as AnyObject } + } + expect { try container.instance(of: Person.self) } === person + expect { try container.instance(of: AnyObject.self) } === person + } // TODO: Reuse binding request for multiple manipulators? // TODO: Arguments // TODO: Less verbose type forwading API? From 8d7df316ef8c7419d41fac6a81630c17f8dbd503 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 14 Jul 2019 01:21:46 +0200 Subject: [PATCH 013/239] Implement support for explicit provision dependency --- Sources/Container.swift | 32 ++++++++++++++++++++++++-------- Sources/Provider.swift | 10 +++++++--- Tests/Fakes.swift | 2 +- Tests/SwinjectApiSpec.swift | 33 ++++++++++++++++++++++++++++++++- 4 files changed, 64 insertions(+), 13 deletions(-) diff --git a/Sources/Container.swift b/Sources/Container.swift index 5ea59a94..227b49a2 100644 --- a/Sources/Container.swift +++ b/Sources/Container.swift @@ -18,11 +18,21 @@ struct Container { let entries: [ModuleEntry] } -extension Container: Injector { - func inject(_ instance: Descriptor.BaseType, descriptor: Descriptor) throws where Descriptor : TypeDescriptor { - let injectors = entries +extension Container { + private func bindings(for descriptor: Descriptor) -> [Binding] where Descriptor : TypeDescriptor { + return entries .compactMap { $0 as? Binding } .filter { $0.descriptor.matches(descriptor) } + } + + private func matches(_ entry: ModuleEntry, _ descriptor: Descriptor) -> Bool where Descriptor: TypeDescriptor { + (entry as? Binding)?.descriptor.matches(descriptor) ?? false + } +} + +extension Container: Injector { + func inject(_ instance: Descriptor.BaseType, descriptor: Descriptor) throws where Descriptor : TypeDescriptor { + let injectors = bindings(for: descriptor) .compactMap { $0.manipulator as? TypeInjector } if injectors.isEmpty { throw MissingTypeInjector() @@ -33,17 +43,23 @@ extension Container: Injector { } extension Container: Provider { - func instance(_ descriptor: Descriptor) throws -> Descriptor.BaseType where Descriptor : TypeDescriptor { - let providers = entries - .compactMap { $0 as? Binding } - .filter { $0.descriptor.matches(descriptor) } + func instance(_ descriptor: Descriptor, with dependency: Dependency) throws -> Descriptor.BaseType where Descriptor : TypeDescriptor { + let providers = bindings(for: descriptor) .compactMap { $0.manipulator as? TypeProvider } if providers.count != 1 { throw SwinjectError() } else { - let instance = try providers[0].instance(using: self) + let instance = try providers[0].instance(using: provider(with: dependency)) do { try inject(instance, descriptor: descriptor) } catch _ as MissingTypeInjector {} return instance } } + + private func provider(with dependency: Dependency) -> Provider { + guard !(dependency is Void) else { return self } + return Container(entries: entries + .filter { !matches($0, plain(Dependency.self)) } + + [bind(Dependency.self) & dependency] + ) + } } diff --git a/Sources/Provider.swift b/Sources/Provider.swift index 0e0e9dc3..d54af8cd 100644 --- a/Sources/Provider.swift +++ b/Sources/Provider.swift @@ -3,15 +3,19 @@ // public protocol Provider { - func instance(_ descriptor: Descriptor) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor + func instance(_ descriptor: Descriptor, with dependency: Dependency) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor } public extension Provider { func instance(of: Type.Type = Type.self) throws -> Type { - try instance(plain(Type.self)) + try instance(plain(Type.self), with: ()) } func instance(of: Type.Type = Type.self, tagged tag: Tag) throws -> Type { - try instance(tagged(Type.self, with: tag)) + try instance(tagged(Type.self, with: tag), with: ()) + } + + func instance(of: Type.Type = Type.self, with dependency: Dependency) throws -> Type { + try instance(plain(Type.self), with: dependency) } } diff --git a/Tests/Fakes.swift b/Tests/Fakes.swift index a64602a5..dd37fa12 100644 --- a/Tests/Fakes.swift +++ b/Tests/Fakes.swift @@ -5,7 +5,7 @@ import Swinject3 class FakeProvider: Provider { - func instance(_ type: Descriptor) throws -> Descriptor.BaseType where Descriptor : TypeDescriptor { + func instance(_ type: Descriptor, with dependency: Dependency) throws -> Descriptor.BaseType where Descriptor : TypeDescriptor { fatalError() } } diff --git a/Tests/SwinjectApiSpec.swift b/Tests/SwinjectApiSpec.swift index da090798..a9e17189 100644 --- a/Tests/SwinjectApiSpec.swift +++ b/Tests/SwinjectApiSpec.swift @@ -138,8 +138,39 @@ class SwinjectApiSpec: QuickSpec { override func spec() { expect { try container.instance(of: Person.self) } === person expect { try container.instance(of: AnyObject.self) } === person } + it("provides passed dependency during instance provision") { + let container = Swinject3.container { + bbind(Pet.self) & factory { try Pet(owner: $0.instance()) } + } + let pet = try? container.instance(with: person) as Pet + expect(pet?.owner) === person + } + it("does not throw if passed dependency type already has a bound provider") { + let container = Swinject3.container { + bbind(Pet.self) & factory { try Pet(owner: $0.instance()) } + bbind(Person.self) & person + } + expect { try container.instance(of: Pet.self, with: person) }.notTo(throwError()) + } + it("uses passed dependency if type already has a bound provider") { + let container = Swinject3.container { + bbind(Pet.self) & factory { try Pet(owner: $0.instance()) } + bbind(Person.self) & factory { Person() } + } + let pet = try? container.instance(with: person) as Pet + expect(pet?.owner) === person + } + it("does not inject passed dependency") { + let container = Swinject3.container { + bbind(Pet.self) & factory { try Pet(owner: $0.instance()) } + bbind(Person.self) & factory { Person() } + bbind(Person.self) & injector { $0.age = 42 } + } + let pet = try? container.instance(with: person) as Pet + expect(pet?.owner.age) == 0 + } + // TODO: Multiple dependencies // TODO: Reuse binding request for multiple manipulators? - // TODO: Arguments // TODO: Less verbose type forwading API? } }} From b51af8bb6d7c3b4526a0b5eab70d8f99eb200f18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 14 Jul 2019 12:03:06 +0200 Subject: [PATCH 014/239] Rename Container to Swinject --- Sources/{Container.swift => Swinject.swift} | 38 ++++---- Swinject.xcodeproj/project.pbxproj | 8 +- Tests/SwinjectApiSpec.swift | 98 ++++++++++----------- 3 files changed, 75 insertions(+), 69 deletions(-) rename Sources/{Container.swift => Swinject.swift} (66%) diff --git a/Sources/Container.swift b/Sources/Swinject.swift similarity index 66% rename from Sources/Container.swift rename to Sources/Swinject.swift index 227b49a2..16152093 100644 --- a/Sources/Container.swift +++ b/Sources/Swinject.swift @@ -2,23 +2,29 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -public func container(@ModuleBuilder builder: () -> [ModuleEntry]) -> Injector & Provider { - Container(entries: builder()) -} +public struct Swinject { + let entries: [ModuleEntry] -public func container(@ModuleBuilder builder: () -> ModuleEntry) -> Injector & Provider { - Container(entries: [builder()]) + init(entries: [ModuleEntry]) { + self.entries = entries + } } -public func container(@ModuleBuilder builder: () -> Void) -> Injector & Provider { - Container(entries: []) -} +public extension Swinject { + init(@ModuleBuilder builder: () -> [ModuleEntry]) { + self.init(entries: builder()) + } -struct Container { - let entries: [ModuleEntry] + init(@ModuleBuilder builder: () -> ModuleEntry) { + self.init(entries: [builder()]) + } + + init(@ModuleBuilder builder: () -> Void) { + self.init(entries: []) + } } -extension Container { +extension Swinject { private func bindings(for descriptor: Descriptor) -> [Binding] where Descriptor : TypeDescriptor { return entries .compactMap { $0 as? Binding } @@ -30,8 +36,8 @@ extension Container { } } -extension Container: Injector { - func inject(_ instance: Descriptor.BaseType, descriptor: Descriptor) throws where Descriptor : TypeDescriptor { +extension Swinject: Injector { + public func inject(_ instance: Descriptor.BaseType, descriptor: Descriptor) throws where Descriptor : TypeDescriptor { let injectors = bindings(for: descriptor) .compactMap { $0.manipulator as? TypeInjector } if injectors.isEmpty { @@ -42,8 +48,8 @@ extension Container: Injector { } } -extension Container: Provider { - func instance(_ descriptor: Descriptor, with dependency: Dependency) throws -> Descriptor.BaseType where Descriptor : TypeDescriptor { +extension Swinject: Provider { + public func instance(_ descriptor: Descriptor, with dependency: Dependency) throws -> Descriptor.BaseType where Descriptor : TypeDescriptor { let providers = bindings(for: descriptor) .compactMap { $0.manipulator as? TypeProvider } if providers.count != 1 { @@ -57,7 +63,7 @@ extension Container: Provider { private func provider(with dependency: Dependency) -> Provider { guard !(dependency is Void) else { return self } - return Container(entries: entries + return Swinject(entries: entries .filter { !matches($0, plain(Dependency.self)) } + [bind(Dependency.self) & dependency] ) diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index cff188f6..c84cc300 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -25,7 +25,7 @@ CDD8380E22DA3B0D003E9909 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380D22DA3B0D003E9909 /* Binding.swift */; }; CDD8381022DA429F003E9909 /* Provider.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380F22DA429F003E9909 /* Provider.swift */; }; CDD8381222DA43D7003E9909 /* TypeInjector.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381122DA43D7003E9909 /* TypeInjector.swift */; }; - CDD8381622DA4B55003E9909 /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381522DA4B55003E9909 /* Container.swift */; }; + CDD8381622DA4B55003E9909 /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381522DA4B55003E9909 /* Swinject.swift */; }; CDD8381822DA4B74003E9909 /* Injector.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381722DA4B74003E9909 /* Injector.swift */; }; CDD8381B22DA4CBE003E9909 /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381922DA4C9F003E9909 /* SwinjectApiSpec.swift */; }; CDD8381D22DA4E02003E9909 /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381C22DA4E02003E9909 /* SwinjectError.swift */; }; @@ -63,7 +63,7 @@ CDD8380D22DA3B0D003E9909 /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; CDD8380F22DA429F003E9909 /* Provider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Provider.swift; sourceTree = ""; }; CDD8381122DA43D7003E9909 /* TypeInjector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeInjector.swift; sourceTree = ""; }; - CDD8381522DA4B55003E9909 /* Container.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.swift; sourceTree = ""; }; + CDD8381522DA4B55003E9909 /* Swinject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Swinject.swift; sourceTree = ""; }; CDD8381722DA4B74003E9909 /* Injector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Injector.swift; sourceTree = ""; }; CDD8381922DA4C9F003E9909 /* SwinjectApiSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectApiSpec.swift; sourceTree = ""; }; CDD8381C22DA4E02003E9909 /* SwinjectError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectError.swift; sourceTree = ""; }; @@ -125,7 +125,7 @@ CDD8380F22DA429F003E9909 /* Provider.swift */, CDD8381722DA4B74003E9909 /* Injector.swift */, CDD8380D22DA3B0D003E9909 /* Binding.swift */, - CDD8381522DA4B55003E9909 /* Container.swift */, + CDD8381522DA4B55003E9909 /* Swinject.swift */, CDD8381C22DA4E02003E9909 /* SwinjectError.swift */, ); path = Sources; @@ -285,7 +285,7 @@ CDD8380722DA30C6003E9909 /* TypeDescriptor.swift in Sources */, CDD8381822DA4B74003E9909 /* Injector.swift in Sources */, CDD8380122DA27EE003E9909 /* ModuleBuilder.swift in Sources */, - CDD8381622DA4B55003E9909 /* Container.swift in Sources */, + CDD8381622DA4B55003E9909 /* Swinject.swift in Sources */, CDD8380522DA307F003E9909 /* BindingRequest.swift in Sources */, CD85AF0E22DA57AD00A8B7CA /* TypeProvider.swift in Sources */, CDD8380E22DA3B0D003E9909 /* Binding.swift in Sources */, diff --git a/Tests/SwinjectApiSpec.swift b/Tests/SwinjectApiSpec.swift index a9e17189..422d590e 100644 --- a/Tests/SwinjectApiSpec.swift +++ b/Tests/SwinjectApiSpec.swift @@ -12,161 +12,161 @@ class SwinjectApiSpec: QuickSpec { override func spec() { person = Person() } describe("property injection") { - it("throws for empty container") { - let container = Swinject3.container { } - expect { try container.inject(42) }.to(throwError()) + it("throws for empty swinject") { + let swinject = Swinject { } + expect { try swinject.inject(42) }.to(throwError()) } it("does not throw if has bound injector") { - let container = Swinject3.container { + let swinject = Swinject { bbind(Int.self) & injector { _ in } } - expect { try container.inject(42) }.notTo(throwError()) + expect { try swinject.inject(42) }.notTo(throwError()) } it("trows if does not have bound injector") { - let container = Swinject3.container { + let swinject = Swinject { bbind(Double.self) & injector { _ in } bbind(Int.self) & IntManipulator() } - expect { try container.inject(42) }.to(throwError()) + expect { try swinject.inject(42) }.to(throwError()) } it("injects intance using bound injector") { - let container = Swinject3.container { + let swinject = Swinject { bbind(Person.self) & injector { $0.age = 42 } } - try? container.inject(person) + try? swinject.inject(person) expect(person.age) == 42 } it("throws if injecting type with missing dependency") { - let container = Swinject3.container { + let swinject = Swinject { bbind(Person.self) & injector { $0.age = try $1.instance() } } - expect { try container.inject(Person()) }.to(throwError()) + expect { try swinject.inject(Person()) }.to(throwError()) } it("injects dependency with bound provider") { - let container = Swinject3.container { + let swinject = Swinject { bbind(Person.self) & injector { $0.age = try $1.instance() } bbind(Int.self).with(42) } - try? container.inject(person) + try? swinject.inject(person) expect(person.age) == 42 } it("injects instance using all bound injectors") { - let container = Swinject3.container { + let swinject = Swinject { bbind(Person.self) & injector { $0.age = 42 } bbind(Person.self) & injector { $0.height = 123.4 } bbind(Person.self) & injector { $0.name = "name" } } - try? container.inject(person) + try? swinject.inject(person) expect(person.age) == 42 expect(person.height) == 123.4 expect(person.name) == "name" } it("throws if injecting type with wrong tag") { - let container = Swinject3.container { + let swinject = Swinject { bbind(Person.self, tagged: "Tag") & injector { $0.age = 42 } } - expect { try container.inject(person) }.to(throwError()) - expect { try container.inject(person, tagged: 42) }.to(throwError()) - expect { try container.inject(person, tagged: "OtherTag") }.to(throwError()) + expect { try swinject.inject(person) }.to(throwError()) + expect { try swinject.inject(person, tagged: 42) }.to(throwError()) + expect { try swinject.inject(person, tagged: "OtherTag") }.to(throwError()) } // TODO: Arguments } describe("type provision") { - it("throws for empty container") { - let container = Swinject3.container { } - expect { try container.instance(of: Int.self) }.to(throwError()) + it("throws for empty swinject") { + let swinject = Swinject { } + expect { try swinject.instance(of: Int.self) }.to(throwError()) } it("returns instance if provider is bound") { - let container = Swinject3.container { + let swinject = Swinject { bbind(Int.self).with(42) } - expect { try container.instance(of: Int.self) } == 42 + expect { try swinject.instance(of: Int.self) } == 42 } it("throws if providing type with missing dependency") { - let container = Swinject3.container { + let swinject = Swinject { bbind(Pet.self) & factory { Pet(owner: try $0.instance()) } } - expect { try container.instance(of: Pet.self) }.to(throwError()) + expect { try swinject.instance(of: Pet.self) }.to(throwError()) } it("returns instance from bound dependency provider") { - let container = Swinject3.container { + let swinject = Swinject { bbind(Pet.self) & factory { Pet(owner: try $0.instance()) } bbind(Person.self) & person } - expect { try container.instance(of: Pet.self).owner } === person + expect { try swinject.instance(of: Pet.self).owner } === person } it("throws if multiple providers are bound") { - let container = Swinject3.container { + let swinject = Swinject { bbind(Int.self) & 42 bbind(Int.self) & factory { 17 + 25 } } - expect { try container.instance(of: Int.self) }.to(throwError()) + expect { try swinject.instance(of: Int.self) }.to(throwError()) } it("throws if requesting instance with wrong tag") { - let container = Swinject3.container { + let swinject = Swinject { bbind(Int.self, tagged: "Tag") & 42 } - expect { try container.instance(of: Int.self) }.to(throwError()) - expect { try container.instance(of: Int.self, tagged: 42) }.to(throwError()) - expect { try container.instance(of: Int.self, tagged: "OtherTag") }.to(throwError()) + expect { try swinject.instance(of: Int.self) }.to(throwError()) + expect { try swinject.instance(of: Int.self, tagged: 42) }.to(throwError()) + expect { try swinject.instance(of: Int.self, tagged: "OtherTag") }.to(throwError()) } it("injects provided instance using bound injectors") { - let container = Swinject3.container { + let swinject = Swinject { bbind(Person.self) & Person() bbind(Person.self) & injector { $0.age = 42 } bbind(Person.self) & injector { $0.height = 123.4 } bbind(Person.self) & injector { $0.name = "Name" } } - let person = try? container.instance() as Person + let person = try? swinject.instance() as Person expect(person?.age) == 42 expect(person?.height) == 123.4 expect(person?.name) == "Name" } it("throws if type has bound injector with missing dependency") { - let container = Swinject3.container { + let swinject = Swinject { bbind(Person.self) & Person() bbind(Person.self) & injector { $0.age = try $1.instance() } } - expect { try container.instance(of: Person.self) }.to(throwError()) + expect { try swinject.instance(of: Person.self) }.to(throwError()) } it("can reuse provider for multiple descriptors") { let personProvider = vvalue(person) // @functionBuilder does not support declarations in closures yet - let container = Swinject3.container { + let swinject = Swinject { bbind(Person.self) & personProvider bbind(AnyObject.self) & personProvider.map { $0 as AnyObject } } - expect { try container.instance(of: Person.self) } === person - expect { try container.instance(of: AnyObject.self) } === person + expect { try swinject.instance(of: Person.self) } === person + expect { try swinject.instance(of: AnyObject.self) } === person } it("provides passed dependency during instance provision") { - let container = Swinject3.container { + let swinject = Swinject { bbind(Pet.self) & factory { try Pet(owner: $0.instance()) } } - let pet = try? container.instance(with: person) as Pet + let pet = try? swinject.instance(with: person) as Pet expect(pet?.owner) === person } it("does not throw if passed dependency type already has a bound provider") { - let container = Swinject3.container { + let swinject = Swinject { bbind(Pet.self) & factory { try Pet(owner: $0.instance()) } bbind(Person.self) & person } - expect { try container.instance(of: Pet.self, with: person) }.notTo(throwError()) + expect { try swinject.instance(of: Pet.self, with: person) }.notTo(throwError()) } it("uses passed dependency if type already has a bound provider") { - let container = Swinject3.container { + let swinject = Swinject { bbind(Pet.self) & factory { try Pet(owner: $0.instance()) } bbind(Person.self) & factory { Person() } } - let pet = try? container.instance(with: person) as Pet + let pet = try? swinject.instance(with: person) as Pet expect(pet?.owner) === person } it("does not inject passed dependency") { - let container = Swinject3.container { + let swinject = Swinject { bbind(Pet.self) & factory { try Pet(owner: $0.instance()) } bbind(Person.self) & factory { Person() } bbind(Person.self) & injector { $0.age = 42 } } - let pet = try? container.instance(with: person) as Pet + let pet = try? swinject.instance(with: person) as Pet expect(pet?.owner.age) == 0 } // TODO: Multiple dependencies From 65b10410b1d2b28e8bc5cf6712dce4b5fbc5bf79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 14 Jul 2019 12:08:08 +0200 Subject: [PATCH 015/239] Scrap injector functionality --- Sources/Injector.swift | 17 ------ Sources/Swinject.swift | 16 +----- Sources/SwinjectError.swift | 10 ---- Sources/TypeInjector.swift | 25 --------- Swinject.xcodeproj/project.pbxproj | 12 ---- Tests/SwinjectApiSpec.swift | 90 +----------------------------- Tests/TypeInjectorSpec.swift | 28 ---------- 7 files changed, 2 insertions(+), 196 deletions(-) delete mode 100644 Sources/Injector.swift delete mode 100644 Sources/TypeInjector.swift delete mode 100644 Tests/TypeInjectorSpec.swift diff --git a/Sources/Injector.swift b/Sources/Injector.swift deleted file mode 100644 index 8ec32ea3..00000000 --- a/Sources/Injector.swift +++ /dev/null @@ -1,17 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -public protocol Injector { - func inject(_ instance: Descriptor.BaseType, descriptor: Descriptor) throws where Descriptor: TypeDescriptor -} - -public extension Injector { - func inject(_ instance: Type) throws { - try inject(instance, descriptor: plain(Type.self)) - } - - func inject(_ instance: Type, tagged tag: Tag) throws { - try inject(instance, descriptor: tagged(Type.self, with: tag)) - } -} diff --git a/Sources/Swinject.swift b/Sources/Swinject.swift index 16152093..2aa7c5e8 100644 --- a/Sources/Swinject.swift +++ b/Sources/Swinject.swift @@ -36,18 +36,6 @@ extension Swinject { } } -extension Swinject: Injector { - public func inject(_ instance: Descriptor.BaseType, descriptor: Descriptor) throws where Descriptor : TypeDescriptor { - let injectors = bindings(for: descriptor) - .compactMap { $0.manipulator as? TypeInjector } - if injectors.isEmpty { - throw MissingTypeInjector() - } else { - try injectors.forEach { try $0.inject(instance, using: self) } - } - } -} - extension Swinject: Provider { public func instance(_ descriptor: Descriptor, with dependency: Dependency) throws -> Descriptor.BaseType where Descriptor : TypeDescriptor { let providers = bindings(for: descriptor) @@ -55,9 +43,7 @@ extension Swinject: Provider { if providers.count != 1 { throw SwinjectError() } else { - let instance = try providers[0].instance(using: provider(with: dependency)) - do { try inject(instance, descriptor: descriptor) } catch _ as MissingTypeInjector {} - return instance + return try providers[0].instance(using: provider(with: dependency)) } } diff --git a/Sources/SwinjectError.swift b/Sources/SwinjectError.swift index 03a895c9..2bed412e 100644 --- a/Sources/SwinjectError.swift +++ b/Sources/SwinjectError.swift @@ -12,14 +12,4 @@ struct SwinjectError: Error { } } -struct MissingTypeInjector: Error { - let file: String - let line: Int - - init(file: String = #file, line: Int = #line) { - self.file = file - self.line = line - } -} - // TODO: Debugging error description diff --git a/Sources/TypeInjector.swift b/Sources/TypeInjector.swift deleted file mode 100644 index 28ca967b..00000000 --- a/Sources/TypeInjector.swift +++ /dev/null @@ -1,25 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -public struct TypeInjector: TypeManipulator { - public typealias ManipulatedType = Type - - private let injectionMethod: (Type, Provider) throws -> Void - - init(_ injectionMethod: @escaping (Type, Provider) throws -> Void) { - self.injectionMethod = injectionMethod - } - - func inject(_ instance: Type, using provider: Provider) throws { - try injectionMethod(instance, provider) - } -} - -public func injector(of: Type.Type = Type.self, injectionMethod: @escaping (Type) throws -> Void) -> TypeInjector { - TypeInjector { instance, _ in try injectionMethod(instance) } -} - -public func injector(of: Type.Type = Type.self, injectionMethod: @escaping (Type, Provider) throws -> Void) -> TypeInjector { - TypeInjector(injectionMethod) -} diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index c84cc300..bb6ca856 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -11,7 +11,6 @@ 771BFC8122D5F83E00AFB237 /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 771BFC7322D5F83E00AFB237 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; 771BFC9122D600B700AFB237 /* Nimble in Frameworks */ = {isa = PBXBuildFile; productRef = 771BFC9022D600B700AFB237 /* Nimble */; }; 771BFC9422D600CC00AFB237 /* Quick in Frameworks */ = {isa = PBXBuildFile; productRef = 771BFC9322D600CC00AFB237 /* Quick */; }; - CD85AF0C22DA574D00A8B7CA /* TypeInjectorSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF0A22DA574800A8B7CA /* TypeInjectorSpec.swift */; }; CD85AF0E22DA57AD00A8B7CA /* TypeProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF0D22DA57AD00A8B7CA /* TypeProvider.swift */; }; CD85AF1022DA586D00A8B7CA /* TypeProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF0F22DA586D00A8B7CA /* TypeProviderSpec.swift */; }; CD85AF1222DA5A8F00A8B7CA /* Fakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF1122DA5A8F00A8B7CA /* Fakes.swift */; }; @@ -24,9 +23,7 @@ CDD8380C22DA3AD8003E9909 /* TypeManipulator.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380B22DA3AD8003E9909 /* TypeManipulator.swift */; }; CDD8380E22DA3B0D003E9909 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380D22DA3B0D003E9909 /* Binding.swift */; }; CDD8381022DA429F003E9909 /* Provider.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380F22DA429F003E9909 /* Provider.swift */; }; - CDD8381222DA43D7003E9909 /* TypeInjector.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381122DA43D7003E9909 /* TypeInjector.swift */; }; CDD8381622DA4B55003E9909 /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381522DA4B55003E9909 /* Swinject.swift */; }; - CDD8381822DA4B74003E9909 /* Injector.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381722DA4B74003E9909 /* Injector.swift */; }; CDD8381B22DA4CBE003E9909 /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381922DA4C9F003E9909 /* SwinjectApiSpec.swift */; }; CDD8381D22DA4E02003E9909 /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381C22DA4E02003E9909 /* SwinjectError.swift */; }; CDD8381F22DA4F6F003E9909 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381E22DA4F6F003E9909 /* Utils.swift */; }; @@ -50,7 +47,6 @@ 771BFC8022D5F83E00AFB237 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 771BFC8B22D5FAAE00AFB237 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nimble.framework; path = Carthage/Build/Mac/Nimble.framework; sourceTree = ""; }; 771BFC8C22D5FAAE00AFB237 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quick.framework; path = Carthage/Build/Mac/Quick.framework; sourceTree = ""; }; - CD85AF0A22DA574800A8B7CA /* TypeInjectorSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TypeInjectorSpec.swift; sourceTree = ""; }; CD85AF0D22DA57AD00A8B7CA /* TypeProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeProvider.swift; sourceTree = ""; }; CD85AF0F22DA586D00A8B7CA /* TypeProviderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeProviderSpec.swift; sourceTree = ""; }; CD85AF1122DA5A8F00A8B7CA /* Fakes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Fakes.swift; sourceTree = ""; }; @@ -62,9 +58,7 @@ CDD8380B22DA3AD8003E9909 /* TypeManipulator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeManipulator.swift; sourceTree = ""; }; CDD8380D22DA3B0D003E9909 /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; CDD8380F22DA429F003E9909 /* Provider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Provider.swift; sourceTree = ""; }; - CDD8381122DA43D7003E9909 /* TypeInjector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeInjector.swift; sourceTree = ""; }; CDD8381522DA4B55003E9909 /* Swinject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Swinject.swift; sourceTree = ""; }; - CDD8381722DA4B74003E9909 /* Injector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Injector.swift; sourceTree = ""; }; CDD8381922DA4C9F003E9909 /* SwinjectApiSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectApiSpec.swift; sourceTree = ""; }; CDD8381C22DA4E02003E9909 /* SwinjectError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectError.swift; sourceTree = ""; }; CDD8381E22DA4F6F003E9909 /* Utils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = ""; }; @@ -120,10 +114,8 @@ CDD8380422DA307F003E9909 /* BindingRequest.swift */, CDD8380622DA30C6003E9909 /* TypeDescriptor.swift */, CDD8380B22DA3AD8003E9909 /* TypeManipulator.swift */, - CDD8381122DA43D7003E9909 /* TypeInjector.swift */, CD85AF0D22DA57AD00A8B7CA /* TypeProvider.swift */, CDD8380F22DA429F003E9909 /* Provider.swift */, - CDD8381722DA4B74003E9909 /* Injector.swift */, CDD8380D22DA3B0D003E9909 /* Binding.swift */, CDD8381522DA4B55003E9909 /* Swinject.swift */, CDD8381C22DA4E02003E9909 /* SwinjectError.swift */, @@ -137,7 +129,6 @@ 771BFC8022D5F83E00AFB237 /* Info.plist */, CDD8380222DA2B67003E9909 /* ModuleBuilderSpec.swift */, CDD8380822DA31C6003E9909 /* BindingRequestSpec.swift */, - CD85AF0A22DA574800A8B7CA /* TypeInjectorSpec.swift */, CD85AF0F22DA586D00A8B7CA /* TypeProviderSpec.swift */, CDD8381922DA4C9F003E9909 /* SwinjectApiSpec.swift */, CDD8381E22DA4F6F003E9909 /* Utils.swift */, @@ -280,10 +271,8 @@ files = ( CDD8380C22DA3AD8003E9909 /* TypeManipulator.swift in Sources */, CDD8381022DA429F003E9909 /* Provider.swift in Sources */, - CDD8381222DA43D7003E9909 /* TypeInjector.swift in Sources */, CDD8381D22DA4E02003E9909 /* SwinjectError.swift in Sources */, CDD8380722DA30C6003E9909 /* TypeDescriptor.swift in Sources */, - CDD8381822DA4B74003E9909 /* Injector.swift in Sources */, CDD8380122DA27EE003E9909 /* ModuleBuilder.swift in Sources */, CDD8381622DA4B55003E9909 /* Swinject.swift in Sources */, CDD8380522DA307F003E9909 /* BindingRequest.swift in Sources */, @@ -302,7 +291,6 @@ CD85AF1222DA5A8F00A8B7CA /* Fakes.swift in Sources */, CD85AF1022DA586D00A8B7CA /* TypeProviderSpec.swift in Sources */, CDD8380322DA2B67003E9909 /* ModuleBuilderSpec.swift in Sources */, - CD85AF0C22DA574D00A8B7CA /* TypeInjectorSpec.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Tests/SwinjectApiSpec.swift b/Tests/SwinjectApiSpec.swift index 422d590e..f00ec684 100644 --- a/Tests/SwinjectApiSpec.swift +++ b/Tests/SwinjectApiSpec.swift @@ -11,67 +11,7 @@ class SwinjectApiSpec: QuickSpec { override func spec() { beforeEach { person = Person() } - describe("property injection") { - it("throws for empty swinject") { - let swinject = Swinject { } - expect { try swinject.inject(42) }.to(throwError()) - } - it("does not throw if has bound injector") { - let swinject = Swinject { - bbind(Int.self) & injector { _ in } - } - expect { try swinject.inject(42) }.notTo(throwError()) - } - it("trows if does not have bound injector") { - let swinject = Swinject { - bbind(Double.self) & injector { _ in } - bbind(Int.self) & IntManipulator() - } - expect { try swinject.inject(42) }.to(throwError()) - } - it("injects intance using bound injector") { - let swinject = Swinject { - bbind(Person.self) & injector { $0.age = 42 } - } - try? swinject.inject(person) - expect(person.age) == 42 - } - it("throws if injecting type with missing dependency") { - let swinject = Swinject { - bbind(Person.self) & injector { $0.age = try $1.instance() } - } - expect { try swinject.inject(Person()) }.to(throwError()) - } - it("injects dependency with bound provider") { - let swinject = Swinject { - bbind(Person.self) & injector { $0.age = try $1.instance() } - bbind(Int.self).with(42) - } - try? swinject.inject(person) - expect(person.age) == 42 - } - it("injects instance using all bound injectors") { - let swinject = Swinject { - bbind(Person.self) & injector { $0.age = 42 } - bbind(Person.self) & injector { $0.height = 123.4 } - bbind(Person.self) & injector { $0.name = "name" } - } - try? swinject.inject(person) - expect(person.age) == 42 - expect(person.height) == 123.4 - expect(person.name) == "name" - } - it("throws if injecting type with wrong tag") { - let swinject = Swinject { - bbind(Person.self, tagged: "Tag") & injector { $0.age = 42 } - } - expect { try swinject.inject(person) }.to(throwError()) - expect { try swinject.inject(person, tagged: 42) }.to(throwError()) - expect { try swinject.inject(person, tagged: "OtherTag") }.to(throwError()) - } - // TODO: Arguments - } - describe("type provision") { + describe("injection") { it("throws for empty swinject") { let swinject = Swinject { } expect { try swinject.instance(of: Int.self) }.to(throwError()) @@ -110,25 +50,6 @@ class SwinjectApiSpec: QuickSpec { override func spec() { expect { try swinject.instance(of: Int.self, tagged: 42) }.to(throwError()) expect { try swinject.instance(of: Int.self, tagged: "OtherTag") }.to(throwError()) } - it("injects provided instance using bound injectors") { - let swinject = Swinject { - bbind(Person.self) & Person() - bbind(Person.self) & injector { $0.age = 42 } - bbind(Person.self) & injector { $0.height = 123.4 } - bbind(Person.self) & injector { $0.name = "Name" } - } - let person = try? swinject.instance() as Person - expect(person?.age) == 42 - expect(person?.height) == 123.4 - expect(person?.name) == "Name" - } - it("throws if type has bound injector with missing dependency") { - let swinject = Swinject { - bbind(Person.self) & Person() - bbind(Person.self) & injector { $0.age = try $1.instance() } - } - expect { try swinject.instance(of: Person.self) }.to(throwError()) - } it("can reuse provider for multiple descriptors") { let personProvider = vvalue(person) // @functionBuilder does not support declarations in closures yet let swinject = Swinject { @@ -160,15 +81,6 @@ class SwinjectApiSpec: QuickSpec { override func spec() { let pet = try? swinject.instance(with: person) as Pet expect(pet?.owner) === person } - it("does not inject passed dependency") { - let swinject = Swinject { - bbind(Pet.self) & factory { try Pet(owner: $0.instance()) } - bbind(Person.self) & factory { Person() } - bbind(Person.self) & injector { $0.age = 42 } - } - let pet = try? swinject.instance(with: person) as Pet - expect(pet?.owner.age) == 0 - } // TODO: Multiple dependencies // TODO: Reuse binding request for multiple manipulators? // TODO: Less verbose type forwading API? diff --git a/Tests/TypeInjectorSpec.swift b/Tests/TypeInjectorSpec.swift deleted file mode 100644 index 7596620f..00000000 --- a/Tests/TypeInjectorSpec.swift +++ /dev/null @@ -1,28 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -import Quick -import Nimble -@testable import Swinject3 - -class TypeInjectorSpec: QuickSpec { override func spec() { - it("calls injection method with given instance") { - var passedInstance: Int? - let it = injector(of: Int.self) { passedInstance = $0 } - try? it.inject(42, using: FakeProvider()) - expect(passedInstance) == 42 - } - it("calls injection method with given provider") { - var passedProvider: Provider? - let provider = FakeProvider() - let it = injector(of: Int.self) { passedProvider = $1 } - try? it.inject(0, using: provider) - expect(passedProvider) === provider - } - it("rethrows injection method error") { - let it = injector(of: Int.self) { _ in throw SwinjectError() } - expect { try it.inject(0, using: FakeProvider()) }.to(throwError()) - } -}} - From 1e72c7ae7176d5202a84d172b73cd2243c45dad7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 14 Jul 2019 12:13:37 +0200 Subject: [PATCH 016/239] Rename binding request to type binder --- Sources/BindingRequest.swift | 41 ------------------- Sources/TypeBinder.swift | 41 +++++++++++++++++++ Swinject.xcodeproj/project.pbxproj | 16 ++++---- ...RequestSpec.swift => TypeBinderSpec.swift} | 2 +- Tests/Utils.swift | 6 +-- 5 files changed, 53 insertions(+), 53 deletions(-) delete mode 100644 Sources/BindingRequest.swift create mode 100644 Sources/TypeBinder.swift rename Tests/{BindingRequestSpec.swift => TypeBinderSpec.swift} (97%) diff --git a/Sources/BindingRequest.swift b/Sources/BindingRequest.swift deleted file mode 100644 index 48aad387..00000000 --- a/Sources/BindingRequest.swift +++ /dev/null @@ -1,41 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -public struct BindingRequest { - let descriptor: AnyTypeDescriptor - - init(descriptor: Descriptor) where Descriptor: TypeDescriptor, Descriptor.BaseType == Type { - self.descriptor = descriptor - } -} - -public func bind(_: Type.Type) -> BindingRequest { - BindingRequest(descriptor: plain(Type.self)) -} - -public func bind(_: Type.Type, tagged tag: Tag) -> BindingRequest where Tag: Equatable { - BindingRequest(descriptor: tagged(Type.self, with: tag)) -} - -public func bind(_ descriptor: Descriptor) -> BindingRequest where Descriptor: TypeDescriptor { - BindingRequest(descriptor: descriptor) -} - -public extension BindingRequest { - func with(_ manipulator: Manipulator) -> Binding where Manipulator: TypeManipulator, Manipulator.ManipulatedType == Type { - Binding(descriptor: descriptor, manipulator: manipulator) - } - - func with(_ it: Type) -> Binding { - Binding(descriptor: descriptor, manipulator: value(it)) - } -} - -public func & (lhs: BindingRequest, rhs: Manipulator) -> Binding where Manipulator: TypeManipulator, Manipulator.ManipulatedType == Type { - lhs.with(rhs) -} - -public func & (lhs: BindingRequest, rhs: Type) -> Binding { - lhs.with(rhs) -} diff --git a/Sources/TypeBinder.swift b/Sources/TypeBinder.swift new file mode 100644 index 00000000..816ac1c2 --- /dev/null +++ b/Sources/TypeBinder.swift @@ -0,0 +1,41 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +public struct TypeBinder { + let descriptor: AnyTypeDescriptor + + init(descriptor: Descriptor) where Descriptor: TypeDescriptor, Descriptor.BaseType == Type { + self.descriptor = descriptor + } +} + +public func bind(_: Type.Type) -> TypeBinder { + TypeBinder(descriptor: plain(Type.self)) +} + +public func bind(_: Type.Type, tagged tag: Tag) -> TypeBinder where Tag: Equatable { + TypeBinder(descriptor: tagged(Type.self, with: tag)) +} + +public func bind(_ descriptor: Descriptor) -> TypeBinder where Descriptor: TypeDescriptor { + TypeBinder(descriptor: descriptor) +} + +public extension TypeBinder { + func with(_ manipulator: Manipulator) -> Binding where Manipulator: TypeManipulator, Manipulator.ManipulatedType == Type { + Binding(descriptor: descriptor, manipulator: manipulator) + } + + func with(_ it: Type) -> Binding { + Binding(descriptor: descriptor, manipulator: value(it)) + } +} + +public func & (lhs: TypeBinder, rhs: Manipulator) -> Binding where Manipulator: TypeManipulator, Manipulator.ManipulatedType == Type { + lhs.with(rhs) +} + +public func & (lhs: TypeBinder, rhs: Type) -> Binding { + lhs.with(rhs) +} diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index bb6ca856..6e291935 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -17,9 +17,9 @@ CDD837FF22DA279C003E9909 /* Swinject in Frameworks */ = {isa = PBXBuildFile; productRef = CDD837FE22DA279C003E9909 /* Swinject */; }; CDD8380122DA27EE003E9909 /* ModuleBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380022DA27EE003E9909 /* ModuleBuilder.swift */; }; CDD8380322DA2B67003E9909 /* ModuleBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380222DA2B67003E9909 /* ModuleBuilderSpec.swift */; }; - CDD8380522DA307F003E9909 /* BindingRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380422DA307F003E9909 /* BindingRequest.swift */; }; + CDD8380522DA307F003E9909 /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380422DA307F003E9909 /* TypeBinder.swift */; }; CDD8380722DA30C6003E9909 /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380622DA30C6003E9909 /* TypeDescriptor.swift */; }; - CDD8380A22DA31D9003E9909 /* BindingRequestSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380822DA31C6003E9909 /* BindingRequestSpec.swift */; }; + CDD8380A22DA31D9003E9909 /* TypeBinderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380822DA31C6003E9909 /* TypeBinderSpec.swift */; }; CDD8380C22DA3AD8003E9909 /* TypeManipulator.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380B22DA3AD8003E9909 /* TypeManipulator.swift */; }; CDD8380E22DA3B0D003E9909 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380D22DA3B0D003E9909 /* Binding.swift */; }; CDD8381022DA429F003E9909 /* Provider.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380F22DA429F003E9909 /* Provider.swift */; }; @@ -52,9 +52,9 @@ CD85AF1122DA5A8F00A8B7CA /* Fakes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Fakes.swift; sourceTree = ""; }; CDD8380022DA27EE003E9909 /* ModuleBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModuleBuilder.swift; sourceTree = ""; }; CDD8380222DA2B67003E9909 /* ModuleBuilderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModuleBuilderSpec.swift; sourceTree = ""; }; - CDD8380422DA307F003E9909 /* BindingRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingRequest.swift; sourceTree = ""; }; + CDD8380422DA307F003E9909 /* TypeBinder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinder.swift; sourceTree = ""; }; CDD8380622DA30C6003E9909 /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; - CDD8380822DA31C6003E9909 /* BindingRequestSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingRequestSpec.swift; sourceTree = ""; }; + CDD8380822DA31C6003E9909 /* TypeBinderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinderSpec.swift; sourceTree = ""; }; CDD8380B22DA3AD8003E9909 /* TypeManipulator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeManipulator.swift; sourceTree = ""; }; CDD8380D22DA3B0D003E9909 /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; CDD8380F22DA429F003E9909 /* Provider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Provider.swift; sourceTree = ""; }; @@ -111,7 +111,7 @@ 771BFC7322D5F83E00AFB237 /* Swinject.h */, 771BFC7422D5F83E00AFB237 /* Info.plist */, CDD8380022DA27EE003E9909 /* ModuleBuilder.swift */, - CDD8380422DA307F003E9909 /* BindingRequest.swift */, + CDD8380422DA307F003E9909 /* TypeBinder.swift */, CDD8380622DA30C6003E9909 /* TypeDescriptor.swift */, CDD8380B22DA3AD8003E9909 /* TypeManipulator.swift */, CD85AF0D22DA57AD00A8B7CA /* TypeProvider.swift */, @@ -128,7 +128,7 @@ children = ( 771BFC8022D5F83E00AFB237 /* Info.plist */, CDD8380222DA2B67003E9909 /* ModuleBuilderSpec.swift */, - CDD8380822DA31C6003E9909 /* BindingRequestSpec.swift */, + CDD8380822DA31C6003E9909 /* TypeBinderSpec.swift */, CD85AF0F22DA586D00A8B7CA /* TypeProviderSpec.swift */, CDD8381922DA4C9F003E9909 /* SwinjectApiSpec.swift */, CDD8381E22DA4F6F003E9909 /* Utils.swift */, @@ -275,7 +275,7 @@ CDD8380722DA30C6003E9909 /* TypeDescriptor.swift in Sources */, CDD8380122DA27EE003E9909 /* ModuleBuilder.swift in Sources */, CDD8381622DA4B55003E9909 /* Swinject.swift in Sources */, - CDD8380522DA307F003E9909 /* BindingRequest.swift in Sources */, + CDD8380522DA307F003E9909 /* TypeBinder.swift in Sources */, CD85AF0E22DA57AD00A8B7CA /* TypeProvider.swift in Sources */, CDD8380E22DA3B0D003E9909 /* Binding.swift in Sources */, ); @@ -287,7 +287,7 @@ files = ( CDD8381F22DA4F6F003E9909 /* Utils.swift in Sources */, CDD8381B22DA4CBE003E9909 /* SwinjectApiSpec.swift in Sources */, - CDD8380A22DA31D9003E9909 /* BindingRequestSpec.swift in Sources */, + CDD8380A22DA31D9003E9909 /* TypeBinderSpec.swift in Sources */, CD85AF1222DA5A8F00A8B7CA /* Fakes.swift in Sources */, CD85AF1022DA586D00A8B7CA /* TypeProviderSpec.swift in Sources */, CDD8380322DA2B67003E9909 /* ModuleBuilderSpec.swift in Sources */, diff --git a/Tests/BindingRequestSpec.swift b/Tests/TypeBinderSpec.swift similarity index 97% rename from Tests/BindingRequestSpec.swift rename to Tests/TypeBinderSpec.swift index 46eda945..aca18a67 100644 --- a/Tests/BindingRequestSpec.swift +++ b/Tests/TypeBinderSpec.swift @@ -6,7 +6,7 @@ import Quick import Nimble @testable import Swinject3 -class BindingRequestSpec: QuickSpec { override func spec() { +class TypeBinderSpec: QuickSpec { override func spec() { describe("`bind` method") { it("descriptor is correct for simple type") { let request = Swinject3.bind(Int.self) diff --git a/Tests/Utils.swift b/Tests/Utils.swift index 0477cdf8..d2682d22 100644 --- a/Tests/Utils.swift +++ b/Tests/Utils.swift @@ -5,15 +5,15 @@ import Swinject3 // Original Swinject3 functions conflict with QuickSpec's instance methods -func bbind(_: Type.Type) -> BindingRequest { +func bbind(_: Type.Type) -> TypeBinder { Swinject3.bind(Type.self) } -func bbind(_: Type.Type, tagged tag: Tag) -> BindingRequest where Tag: Equatable { +func bbind(_: Type.Type, tagged tag: Tag) -> TypeBinder where Tag: Equatable { Swinject3.bind(Type.self, tagged: tag) } -func bbind(_ descriptor: Descriptor) -> BindingRequest where Descriptor: TypeDescriptor { +func bbind(_ descriptor: Descriptor) -> TypeBinder where Descriptor: TypeDescriptor { Swinject3.bind(descriptor) } From bc7f26e366f866a31339c88f27d5ddb02412554a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 14 Jul 2019 12:29:19 +0200 Subject: [PATCH 017/239] Rename module builder to tree builder --- Sources/Binding.swift | 2 +- Sources/ModuleBuilder.swift | 36 ----------------- Sources/Swinject.swift | 12 +++--- Sources/SwinjectTree.swift | 40 +++++++++++++++++++ Swinject.xcodeproj/project.pbxproj | 16 ++++---- ...ec.swift => SwinjectTreeBuilderSpec.swift} | 16 ++++---- 6 files changed, 63 insertions(+), 59 deletions(-) delete mode 100644 Sources/ModuleBuilder.swift create mode 100644 Sources/SwinjectTree.swift rename Tests/{ModuleBuilderSpec.swift => SwinjectTreeBuilderSpec.swift} (69%) diff --git a/Sources/Binding.swift b/Sources/Binding.swift index 523f4834..bad8c8ba 100644 --- a/Sources/Binding.swift +++ b/Sources/Binding.swift @@ -2,7 +2,7 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -public struct Binding: ModuleEntry { +public struct Binding: SwinjectEntry { let descriptor: AnyTypeDescriptor let manipulator: AnyTypeManipulator } diff --git a/Sources/ModuleBuilder.swift b/Sources/ModuleBuilder.swift deleted file mode 100644 index bbce796e..00000000 --- a/Sources/ModuleBuilder.swift +++ /dev/null @@ -1,36 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -public protocol ModuleEntry {} - -@_functionBuilder -public enum ModuleBuilder { - public typealias Entry = ModuleEntry - - public static func buildBlock() -> Void {} - - public static func buildBlock(_ input: Entry ...) -> [Entry] { - input.flatMap(unpack) - } - - public static func buildIf(_ input: [Entry]?) -> Entry { - Composed(parts: input ?? []) - } - - public static func buildEither(first input: [Entry]) -> Entry { - Composed(parts: input) - } - - public static func buildEither(second input: [Entry]) -> Entry { - Composed(parts: input) - } - - private struct Composed: Entry { - let parts: [Entry] - } - - private static func unpack(entry: Entry) -> [Entry] { - if let entry = entry as? Composed { return entry.parts } else { return [entry] } - } -} diff --git a/Sources/Swinject.swift b/Sources/Swinject.swift index 2aa7c5e8..bbe68b58 100644 --- a/Sources/Swinject.swift +++ b/Sources/Swinject.swift @@ -3,23 +3,23 @@ // public struct Swinject { - let entries: [ModuleEntry] + let entries: [SwinjectEntry] - init(entries: [ModuleEntry]) { + init(entries: [SwinjectEntry]) { self.entries = entries } } public extension Swinject { - init(@ModuleBuilder builder: () -> [ModuleEntry]) { + init(@SwinjectTreeBuilder builder: () -> [SwinjectEntry]) { self.init(entries: builder()) } - init(@ModuleBuilder builder: () -> ModuleEntry) { + init(@SwinjectTreeBuilder builder: () -> SwinjectEntry) { self.init(entries: [builder()]) } - init(@ModuleBuilder builder: () -> Void) { + init(@SwinjectTreeBuilder builder: () -> Void) { self.init(entries: []) } } @@ -31,7 +31,7 @@ extension Swinject { .filter { $0.descriptor.matches(descriptor) } } - private func matches(_ entry: ModuleEntry, _ descriptor: Descriptor) -> Bool where Descriptor: TypeDescriptor { + private func matches(_ entry: SwinjectEntry, _ descriptor: Descriptor) -> Bool where Descriptor: TypeDescriptor { (entry as? Binding)?.descriptor.matches(descriptor) ?? false } } diff --git a/Sources/SwinjectTree.swift b/Sources/SwinjectTree.swift new file mode 100644 index 00000000..353433af --- /dev/null +++ b/Sources/SwinjectTree.swift @@ -0,0 +1,40 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +struct SwinjectTree { + +} + +public protocol SwinjectEntry {} + +@_functionBuilder +public enum SwinjectTreeBuilder { + public static func buildBlock() -> Void {} + + public static func buildBlock(_ input: SwinjectEntry ...) -> [SwinjectEntry] { + input.flatMap(unpack) + } + + public static func buildIf(_ input: [SwinjectEntry]?) -> SwinjectEntry { + Composed(parts: input ?? []) + } + + public static func buildEither(first input: [SwinjectEntry]) -> SwinjectEntry { + Composed(parts: input) + } + + public static func buildEither(second input: [SwinjectEntry]) -> SwinjectEntry { + Composed(parts: input) + } +} + +extension SwinjectTreeBuilder { + private struct Composed: SwinjectEntry { + let parts: [SwinjectEntry] + } + + private static func unpack(entry: SwinjectEntry) -> [SwinjectEntry] { + if let entry = entry as? Composed { return entry.parts } else { return [entry] } + } +} diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 6e291935..95589042 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -14,9 +14,9 @@ CD85AF0E22DA57AD00A8B7CA /* TypeProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF0D22DA57AD00A8B7CA /* TypeProvider.swift */; }; CD85AF1022DA586D00A8B7CA /* TypeProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF0F22DA586D00A8B7CA /* TypeProviderSpec.swift */; }; CD85AF1222DA5A8F00A8B7CA /* Fakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF1122DA5A8F00A8B7CA /* Fakes.swift */; }; + CDADF32122DB38C600C5D8DB /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDADF32022DB38C600C5D8DB /* SwinjectTree.swift */; }; CDD837FF22DA279C003E9909 /* Swinject in Frameworks */ = {isa = PBXBuildFile; productRef = CDD837FE22DA279C003E9909 /* Swinject */; }; - CDD8380122DA27EE003E9909 /* ModuleBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380022DA27EE003E9909 /* ModuleBuilder.swift */; }; - CDD8380322DA2B67003E9909 /* ModuleBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380222DA2B67003E9909 /* ModuleBuilderSpec.swift */; }; + CDD8380322DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380222DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift */; }; CDD8380522DA307F003E9909 /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380422DA307F003E9909 /* TypeBinder.swift */; }; CDD8380722DA30C6003E9909 /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380622DA30C6003E9909 /* TypeDescriptor.swift */; }; CDD8380A22DA31D9003E9909 /* TypeBinderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380822DA31C6003E9909 /* TypeBinderSpec.swift */; }; @@ -50,8 +50,8 @@ CD85AF0D22DA57AD00A8B7CA /* TypeProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeProvider.swift; sourceTree = ""; }; CD85AF0F22DA586D00A8B7CA /* TypeProviderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeProviderSpec.swift; sourceTree = ""; }; CD85AF1122DA5A8F00A8B7CA /* Fakes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Fakes.swift; sourceTree = ""; }; - CDD8380022DA27EE003E9909 /* ModuleBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModuleBuilder.swift; sourceTree = ""; }; - CDD8380222DA2B67003E9909 /* ModuleBuilderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModuleBuilderSpec.swift; sourceTree = ""; }; + CDADF32022DB38C600C5D8DB /* SwinjectTree.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTree.swift; sourceTree = ""; }; + CDD8380222DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTreeBuilderSpec.swift; sourceTree = ""; }; CDD8380422DA307F003E9909 /* TypeBinder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinder.swift; sourceTree = ""; }; CDD8380622DA30C6003E9909 /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; CDD8380822DA31C6003E9909 /* TypeBinderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinderSpec.swift; sourceTree = ""; }; @@ -110,7 +110,7 @@ children = ( 771BFC7322D5F83E00AFB237 /* Swinject.h */, 771BFC7422D5F83E00AFB237 /* Info.plist */, - CDD8380022DA27EE003E9909 /* ModuleBuilder.swift */, + CDADF32022DB38C600C5D8DB /* SwinjectTree.swift */, CDD8380422DA307F003E9909 /* TypeBinder.swift */, CDD8380622DA30C6003E9909 /* TypeDescriptor.swift */, CDD8380B22DA3AD8003E9909 /* TypeManipulator.swift */, @@ -127,7 +127,7 @@ isa = PBXGroup; children = ( 771BFC8022D5F83E00AFB237 /* Info.plist */, - CDD8380222DA2B67003E9909 /* ModuleBuilderSpec.swift */, + CDD8380222DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift */, CDD8380822DA31C6003E9909 /* TypeBinderSpec.swift */, CD85AF0F22DA586D00A8B7CA /* TypeProviderSpec.swift */, CDD8381922DA4C9F003E9909 /* SwinjectApiSpec.swift */, @@ -271,9 +271,9 @@ files = ( CDD8380C22DA3AD8003E9909 /* TypeManipulator.swift in Sources */, CDD8381022DA429F003E9909 /* Provider.swift in Sources */, + CDADF32122DB38C600C5D8DB /* SwinjectTree.swift in Sources */, CDD8381D22DA4E02003E9909 /* SwinjectError.swift in Sources */, CDD8380722DA30C6003E9909 /* TypeDescriptor.swift in Sources */, - CDD8380122DA27EE003E9909 /* ModuleBuilder.swift in Sources */, CDD8381622DA4B55003E9909 /* Swinject.swift in Sources */, CDD8380522DA307F003E9909 /* TypeBinder.swift in Sources */, CD85AF0E22DA57AD00A8B7CA /* TypeProvider.swift in Sources */, @@ -290,7 +290,7 @@ CDD8380A22DA31D9003E9909 /* TypeBinderSpec.swift in Sources */, CD85AF1222DA5A8F00A8B7CA /* Fakes.swift in Sources */, CD85AF1022DA586D00A8B7CA /* TypeProviderSpec.swift in Sources */, - CDD8380322DA2B67003E9909 /* ModuleBuilderSpec.swift in Sources */, + CDD8380322DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Tests/ModuleBuilderSpec.swift b/Tests/SwinjectTreeBuilderSpec.swift similarity index 69% rename from Tests/ModuleBuilderSpec.swift rename to Tests/SwinjectTreeBuilderSpec.swift index bd889b04..5407e053 100644 --- a/Tests/ModuleBuilderSpec.swift +++ b/Tests/SwinjectTreeBuilderSpec.swift @@ -6,34 +6,34 @@ import Quick import Nimble @testable import Swinject3 -class ModuleBuilderSpec: QuickSpec { override func spec() { +class SwinjectTreeBuilderSpec: QuickSpec { override func spec() { it("builds empty function") { - @ModuleBuilder func build() -> [ModuleEntry] { + @SwinjectTreeBuilder func build() -> [SwinjectEntry] { } expect(build().count) == 0 } it("builds function with single entry") { - @ModuleBuilder func build() -> [ModuleEntry] { + @SwinjectTreeBuilder func build() -> [SwinjectEntry] { AnyEntry() } expect(build().count) == 1 } it("builds function with multiple entries") { - @ModuleBuilder func build() -> [ModuleEntry] { + @SwinjectTreeBuilder func build() -> [SwinjectEntry] { AnyEntry(); AnyEntry(); AnyEntry(); AnyEntry(); AnyEntry() } expect(build().count) == 5 } it("builds function with if statement") { - @ModuleBuilder func build(_ flag: Bool) -> [ModuleEntry] { + @SwinjectTreeBuilder func build(_ flag: Bool) -> [SwinjectEntry] { if flag { AnyEntry() } } expect(build(true).count) == 1 expect(build(false).count) == 0 } it("builds function with nested if statement") { - @ModuleBuilder func build(_ flag1: Bool, _ flag2: Bool) -> [ModuleEntry] { + @SwinjectTreeBuilder func build(_ flag1: Bool, _ flag2: Bool) -> [SwinjectEntry] { if flag1 { AnyEntry() if flag2 { AnyEntry() } @@ -43,7 +43,7 @@ class ModuleBuilderSpec: QuickSpec { override func spec() { expect(build(true, false).count) == 1 } it("builds function with if else statement") { - @ModuleBuilder func build(_ flag: Bool) -> [ModuleEntry] { + @SwinjectTreeBuilder func build(_ flag: Bool) -> [SwinjectEntry] { if flag { AnyEntry() } else { @@ -55,4 +55,4 @@ class ModuleBuilderSpec: QuickSpec { override func spec() { } }} -struct AnyEntry: ModuleEntry {} +struct AnyEntry: SwinjectEntry {} From a8f55ef0db121fa60279c6efebd20eb8385a9522 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 14 Jul 2019 12:42:05 +0200 Subject: [PATCH 018/239] Rename stuff --- Sources/Binding.swift | 7 ++- Sources/BindingEntry.swift | 8 +++ Sources/ProviderBinding.swift | 36 +++++++++++ Sources/Swinject.swift | 8 +-- Sources/TypeBinder.swift | 12 ++-- Sources/TypeManipulator.swift | 9 --- Sources/TypeProvider.swift | 35 ----------- Swinject.xcodeproj/project.pbxproj | 63 +++++++------------ .../xcshareddata/swiftpm/Package.resolved | 9 --- Tests/Fakes.swift | 6 +- Tests/ProviderBindingSpec.swift | 39 ++++++++++++ Tests/SwinjectApiSpec.swift | 8 +-- Tests/SwinjectTreeBuilderSpec.swift | 2 +- Tests/TypeBinderSpec.swift | 40 ++++++------ Tests/TypeProviderSpec.swift | 39 ------------ Tests/Utils.swift | 18 +++--- 16 files changed, 159 insertions(+), 180 deletions(-) create mode 100644 Sources/BindingEntry.swift create mode 100644 Sources/ProviderBinding.swift delete mode 100644 Sources/TypeManipulator.swift delete mode 100644 Sources/TypeProvider.swift create mode 100644 Tests/ProviderBindingSpec.swift delete mode 100644 Tests/TypeProviderSpec.swift diff --git a/Sources/Binding.swift b/Sources/Binding.swift index bad8c8ba..58d3b056 100644 --- a/Sources/Binding.swift +++ b/Sources/Binding.swift @@ -2,7 +2,8 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -public struct Binding: SwinjectEntry { - let descriptor: AnyTypeDescriptor - let manipulator: AnyTypeManipulator +public protocol AnyBinding {} + +public protocol Binding: AnyBinding { + associatedtype BoundType } diff --git a/Sources/BindingEntry.swift b/Sources/BindingEntry.swift new file mode 100644 index 00000000..db567fdf --- /dev/null +++ b/Sources/BindingEntry.swift @@ -0,0 +1,8 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +public struct BindingEntry: SwinjectEntry { + let descriptor: AnyTypeDescriptor + let binding: AnyBinding // TODO: Rename to binding +} diff --git a/Sources/ProviderBinding.swift b/Sources/ProviderBinding.swift new file mode 100644 index 00000000..29caff02 --- /dev/null +++ b/Sources/ProviderBinding.swift @@ -0,0 +1,36 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +public struct ProviderBinding: Binding { + public typealias BoundType = Type + + private let builder: (Provider) throws -> Type + + init(_ builder: @escaping (Provider) throws -> Type) { + self.builder = builder + } + + func instance(using provider: Provider) throws -> Type { + try builder(provider) + } +} + +// FIXME: Create InstanceBinding for this +public func value(_ it: Type) -> ProviderBinding { + ProviderBinding { _ in it } +} + +public func provider(_ builder: @escaping () throws -> Type) -> ProviderBinding { + ProviderBinding { _ in try builder() } +} + +public func factory(_ builder: @escaping (Provider) throws -> Type) -> ProviderBinding { + ProviderBinding(builder) +} + +public extension ProviderBinding { + func map(_ transform: @escaping (Type) -> OtherType) -> ProviderBinding { + ProviderBinding { try transform(self.instance(using: $0)) } + } +} diff --git a/Sources/Swinject.swift b/Sources/Swinject.swift index bbe68b58..0cef8d01 100644 --- a/Sources/Swinject.swift +++ b/Sources/Swinject.swift @@ -25,21 +25,21 @@ public extension Swinject { } extension Swinject { - private func bindings(for descriptor: Descriptor) -> [Binding] where Descriptor : TypeDescriptor { + private func bindings(for descriptor: Descriptor) -> [BindingEntry] where Descriptor : TypeDescriptor { return entries - .compactMap { $0 as? Binding } + .compactMap { $0 as? BindingEntry } .filter { $0.descriptor.matches(descriptor) } } private func matches(_ entry: SwinjectEntry, _ descriptor: Descriptor) -> Bool where Descriptor: TypeDescriptor { - (entry as? Binding)?.descriptor.matches(descriptor) ?? false + (entry as? BindingEntry)?.descriptor.matches(descriptor) ?? false } } extension Swinject: Provider { public func instance(_ descriptor: Descriptor, with dependency: Dependency) throws -> Descriptor.BaseType where Descriptor : TypeDescriptor { let providers = bindings(for: descriptor) - .compactMap { $0.manipulator as? TypeProvider } + .compactMap { $0.binding as? ProviderBinding } if providers.count != 1 { throw SwinjectError() } else { diff --git a/Sources/TypeBinder.swift b/Sources/TypeBinder.swift index 816ac1c2..1230e0de 100644 --- a/Sources/TypeBinder.swift +++ b/Sources/TypeBinder.swift @@ -23,19 +23,19 @@ public func bind(_ descriptor: Descriptor) -> TypeBinder(_ manipulator: Manipulator) -> Binding where Manipulator: TypeManipulator, Manipulator.ManipulatedType == Type { - Binding(descriptor: descriptor, manipulator: manipulator) + func with(_ binding: SomeBinding) -> BindingEntry where SomeBinding: Binding, SomeBinding.BoundType == Type { + BindingEntry(descriptor: descriptor, binding: binding) } - func with(_ it: Type) -> Binding { - Binding(descriptor: descriptor, manipulator: value(it)) + func with(_ it: Type) -> BindingEntry { + BindingEntry(descriptor: descriptor, binding: value(it)) } } -public func & (lhs: TypeBinder, rhs: Manipulator) -> Binding where Manipulator: TypeManipulator, Manipulator.ManipulatedType == Type { +public func & (lhs: TypeBinder, rhs: SomeBinding) -> BindingEntry where SomeBinding: Binding, SomeBinding.BoundType == Type { lhs.with(rhs) } -public func & (lhs: TypeBinder, rhs: Type) -> Binding { +public func & (lhs: TypeBinder, rhs: Type) -> BindingEntry { lhs.with(rhs) } diff --git a/Sources/TypeManipulator.swift b/Sources/TypeManipulator.swift deleted file mode 100644 index 1e93bdd0..00000000 --- a/Sources/TypeManipulator.swift +++ /dev/null @@ -1,9 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -public protocol AnyTypeManipulator {} - -public protocol TypeManipulator: AnyTypeManipulator { - associatedtype ManipulatedType -} diff --git a/Sources/TypeProvider.swift b/Sources/TypeProvider.swift deleted file mode 100644 index 6c25a13f..00000000 --- a/Sources/TypeProvider.swift +++ /dev/null @@ -1,35 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -public struct TypeProvider: TypeManipulator { - public typealias ManipulatedType = Type - - private let factoryMethod: (Provider) throws -> Type - - init(_ factoryMethod: @escaping (Provider) throws -> Type) { - self.factoryMethod = factoryMethod - } - - func instance(using provider: Provider) throws -> Type { - try factoryMethod(provider) - } -} - -public func value(_ it: Type) -> TypeProvider { - TypeProvider { _ in it } -} - -public func factory(_ factoryMethod: @escaping () throws -> Type) -> TypeProvider { - TypeProvider { _ in try factoryMethod() } -} - -public func factory(_ factoryMethod: @escaping (Provider) throws -> Type) -> TypeProvider { - TypeProvider(factoryMethod) -} - -public extension TypeProvider { - func map(_ transform: @escaping (Type) -> OtherType) -> TypeProvider { - TypeProvider { try transform(self.instance(using: $0)) } - } -} diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 95589042..173f3215 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -7,21 +7,20 @@ objects = { /* Begin PBXBuildFile section */ - 771BFC7A22D5F83E00AFB237 /* Swinject3.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 771BFC7022D5F83E00AFB237 /* Swinject3.framework */; }; + 771BFC7A22D5F83E00AFB237 /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 771BFC7022D5F83E00AFB237 /* Swinject.framework */; }; 771BFC8122D5F83E00AFB237 /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 771BFC7322D5F83E00AFB237 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; 771BFC9122D600B700AFB237 /* Nimble in Frameworks */ = {isa = PBXBuildFile; productRef = 771BFC9022D600B700AFB237 /* Nimble */; }; 771BFC9422D600CC00AFB237 /* Quick in Frameworks */ = {isa = PBXBuildFile; productRef = 771BFC9322D600CC00AFB237 /* Quick */; }; - CD85AF0E22DA57AD00A8B7CA /* TypeProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF0D22DA57AD00A8B7CA /* TypeProvider.swift */; }; - CD85AF1022DA586D00A8B7CA /* TypeProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF0F22DA586D00A8B7CA /* TypeProviderSpec.swift */; }; + CD85AF0E22DA57AD00A8B7CA /* ProviderBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF0D22DA57AD00A8B7CA /* ProviderBinding.swift */; }; + CD85AF1022DA586D00A8B7CA /* ProviderBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF0F22DA586D00A8B7CA /* ProviderBindingSpec.swift */; }; CD85AF1222DA5A8F00A8B7CA /* Fakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF1122DA5A8F00A8B7CA /* Fakes.swift */; }; CDADF32122DB38C600C5D8DB /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDADF32022DB38C600C5D8DB /* SwinjectTree.swift */; }; - CDD837FF22DA279C003E9909 /* Swinject in Frameworks */ = {isa = PBXBuildFile; productRef = CDD837FE22DA279C003E9909 /* Swinject */; }; CDD8380322DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380222DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift */; }; CDD8380522DA307F003E9909 /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380422DA307F003E9909 /* TypeBinder.swift */; }; CDD8380722DA30C6003E9909 /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380622DA30C6003E9909 /* TypeDescriptor.swift */; }; CDD8380A22DA31D9003E9909 /* TypeBinderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380822DA31C6003E9909 /* TypeBinderSpec.swift */; }; - CDD8380C22DA3AD8003E9909 /* TypeManipulator.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380B22DA3AD8003E9909 /* TypeManipulator.swift */; }; - CDD8380E22DA3B0D003E9909 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380D22DA3B0D003E9909 /* Binding.swift */; }; + CDD8380C22DA3AD8003E9909 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380B22DA3AD8003E9909 /* Binding.swift */; }; + CDD8380E22DA3B0D003E9909 /* BindingEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380D22DA3B0D003E9909 /* BindingEntry.swift */; }; CDD8381022DA429F003E9909 /* Provider.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380F22DA429F003E9909 /* Provider.swift */; }; CDD8381622DA4B55003E9909 /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381522DA4B55003E9909 /* Swinject.swift */; }; CDD8381B22DA4CBE003E9909 /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381922DA4C9F003E9909 /* SwinjectApiSpec.swift */; }; @@ -40,23 +39,23 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 771BFC7022D5F83E00AFB237 /* Swinject3.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject3.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 771BFC7022D5F83E00AFB237 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 771BFC7322D5F83E00AFB237 /* Swinject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Swinject.h; sourceTree = ""; }; 771BFC7422D5F83E00AFB237 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 771BFC7922D5F83E00AFB237 /* SwinjectTests-OSX.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SwinjectTests-OSX.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 771BFC8022D5F83E00AFB237 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 771BFC8B22D5FAAE00AFB237 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nimble.framework; path = Carthage/Build/Mac/Nimble.framework; sourceTree = ""; }; 771BFC8C22D5FAAE00AFB237 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quick.framework; path = Carthage/Build/Mac/Quick.framework; sourceTree = ""; }; - CD85AF0D22DA57AD00A8B7CA /* TypeProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeProvider.swift; sourceTree = ""; }; - CD85AF0F22DA586D00A8B7CA /* TypeProviderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeProviderSpec.swift; sourceTree = ""; }; + CD85AF0D22DA57AD00A8B7CA /* ProviderBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProviderBinding.swift; sourceTree = ""; }; + CD85AF0F22DA586D00A8B7CA /* ProviderBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProviderBindingSpec.swift; sourceTree = ""; }; CD85AF1122DA5A8F00A8B7CA /* Fakes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Fakes.swift; sourceTree = ""; }; CDADF32022DB38C600C5D8DB /* SwinjectTree.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTree.swift; sourceTree = ""; }; CDD8380222DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTreeBuilderSpec.swift; sourceTree = ""; }; CDD8380422DA307F003E9909 /* TypeBinder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinder.swift; sourceTree = ""; }; CDD8380622DA30C6003E9909 /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; CDD8380822DA31C6003E9909 /* TypeBinderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinderSpec.swift; sourceTree = ""; }; - CDD8380B22DA3AD8003E9909 /* TypeManipulator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeManipulator.swift; sourceTree = ""; }; - CDD8380D22DA3B0D003E9909 /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; + CDD8380B22DA3AD8003E9909 /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; + CDD8380D22DA3B0D003E9909 /* BindingEntry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingEntry.swift; sourceTree = ""; }; CDD8380F22DA429F003E9909 /* Provider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Provider.swift; sourceTree = ""; }; CDD8381522DA4B55003E9909 /* Swinject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Swinject.swift; sourceTree = ""; }; CDD8381922DA4C9F003E9909 /* SwinjectApiSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectApiSpec.swift; sourceTree = ""; }; @@ -69,7 +68,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - CDD837FF22DA279C003E9909 /* Swinject in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -77,7 +75,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 771BFC7A22D5F83E00AFB237 /* Swinject3.framework in Frameworks */, + 771BFC7A22D5F83E00AFB237 /* Swinject.framework in Frameworks */, 771BFC9422D600CC00AFB237 /* Quick in Frameworks */, 771BFC9122D600B700AFB237 /* Nimble in Frameworks */, ); @@ -99,7 +97,7 @@ 771BFC7122D5F83E00AFB237 /* Products */ = { isa = PBXGroup; children = ( - 771BFC7022D5F83E00AFB237 /* Swinject3.framework */, + 771BFC7022D5F83E00AFB237 /* Swinject.framework */, 771BFC7922D5F83E00AFB237 /* SwinjectTests-OSX.xctest */, ); name = Products; @@ -113,10 +111,10 @@ CDADF32022DB38C600C5D8DB /* SwinjectTree.swift */, CDD8380422DA307F003E9909 /* TypeBinder.swift */, CDD8380622DA30C6003E9909 /* TypeDescriptor.swift */, - CDD8380B22DA3AD8003E9909 /* TypeManipulator.swift */, - CD85AF0D22DA57AD00A8B7CA /* TypeProvider.swift */, + CDD8380B22DA3AD8003E9909 /* Binding.swift */, + CD85AF0D22DA57AD00A8B7CA /* ProviderBinding.swift */, CDD8380F22DA429F003E9909 /* Provider.swift */, - CDD8380D22DA3B0D003E9909 /* Binding.swift */, + CDD8380D22DA3B0D003E9909 /* BindingEntry.swift */, CDD8381522DA4B55003E9909 /* Swinject.swift */, CDD8381C22DA4E02003E9909 /* SwinjectError.swift */, ); @@ -129,7 +127,7 @@ 771BFC8022D5F83E00AFB237 /* Info.plist */, CDD8380222DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift */, CDD8380822DA31C6003E9909 /* TypeBinderSpec.swift */, - CD85AF0F22DA586D00A8B7CA /* TypeProviderSpec.swift */, + CD85AF0F22DA586D00A8B7CA /* ProviderBindingSpec.swift */, CDD8381922DA4C9F003E9909 /* SwinjectApiSpec.swift */, CDD8381E22DA4F6F003E9909 /* Utils.swift */, CD85AF1122DA5A8F00A8B7CA /* Fakes.swift */, @@ -175,10 +173,9 @@ ); name = "Swinject-OSX"; packageProductDependencies = ( - CDD837FE22DA279C003E9909 /* Swinject */, ); productName = Swinject; - productReference = 771BFC7022D5F83E00AFB237 /* Swinject3.framework */; + productReference = 771BFC7022D5F83E00AFB237 /* Swinject.framework */; productType = "com.apple.product-type.framework"; }; 771BFC7822D5F83E00AFB237 /* SwinjectTests-OSX */ = { @@ -235,7 +232,6 @@ packageReferences = ( 771BFC8F22D600B700AFB237 /* XCRemoteSwiftPackageReference "Nimble" */, 771BFC9222D600CC00AFB237 /* XCRemoteSwiftPackageReference "Quick" */, - CDD837FD22DA279C003E9909 /* XCRemoteSwiftPackageReference "swinject" */, ); productRefGroup = 771BFC7122D5F83E00AFB237 /* Products */; projectDirPath = ""; @@ -269,15 +265,15 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - CDD8380C22DA3AD8003E9909 /* TypeManipulator.swift in Sources */, + CDD8380C22DA3AD8003E9909 /* Binding.swift in Sources */, CDD8381022DA429F003E9909 /* Provider.swift in Sources */, CDADF32122DB38C600C5D8DB /* SwinjectTree.swift in Sources */, CDD8381D22DA4E02003E9909 /* SwinjectError.swift in Sources */, CDD8380722DA30C6003E9909 /* TypeDescriptor.swift in Sources */, CDD8381622DA4B55003E9909 /* Swinject.swift in Sources */, CDD8380522DA307F003E9909 /* TypeBinder.swift in Sources */, - CD85AF0E22DA57AD00A8B7CA /* TypeProvider.swift in Sources */, - CDD8380E22DA3B0D003E9909 /* Binding.swift in Sources */, + CD85AF0E22DA57AD00A8B7CA /* ProviderBinding.swift in Sources */, + CDD8380E22DA3B0D003E9909 /* BindingEntry.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -289,7 +285,7 @@ CDD8381B22DA4CBE003E9909 /* SwinjectApiSpec.swift in Sources */, CDD8380A22DA31D9003E9909 /* TypeBinderSpec.swift in Sources */, CD85AF1222DA5A8F00A8B7CA /* Fakes.swift in Sources */, - CD85AF1022DA586D00A8B7CA /* TypeProviderSpec.swift in Sources */, + CD85AF1022DA586D00A8B7CA /* ProviderBindingSpec.swift in Sources */, CDD8380322DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -444,7 +440,7 @@ "@loader_path/Frameworks", ); PRODUCT_BUNDLE_IDENTIFIER = "com.el-eleven.Swinject"; - PRODUCT_NAME = Swinject3; + PRODUCT_NAME = Swinject; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; @@ -469,7 +465,7 @@ "@loader_path/Frameworks", ); PRODUCT_BUNDLE_IDENTIFIER = "com.el-eleven.Swinject"; - PRODUCT_NAME = Swinject3; + PRODUCT_NAME = Swinject; SKIP_INSTALL = YES; SWIFT_VERSION = 5.0; }; @@ -571,14 +567,6 @@ minimumVersion = 2.1.0; }; }; - CDD837FD22DA279C003E9909 /* XCRemoteSwiftPackageReference "swinject" */ = { - isa = XCRemoteSwiftPackageReference; - repositoryURL = "https://github.com/swinject/swinject"; - requirement = { - kind = upToNextMajorVersion; - minimumVersion = 2.6.2; - }; - }; /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ @@ -592,11 +580,6 @@ package = 771BFC9222D600CC00AFB237 /* XCRemoteSwiftPackageReference "Quick" */; productName = Quick; }; - CDD837FE22DA279C003E9909 /* Swinject */ = { - isa = XCSwiftPackageProductDependency; - package = CDD837FD22DA279C003E9909 /* XCRemoteSwiftPackageReference "swinject" */; - productName = Swinject; - }; /* End XCSwiftPackageProductDependency section */ }; rootObject = 771BFC6722D5F83E00AFB237 /* Project object */; diff --git a/Swinject.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Swinject.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 6a9f290e..9c4b5d95 100644 --- a/Swinject.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Swinject.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -18,15 +18,6 @@ "revision": "94df9b449508344667e5afc7e80f8bcbff1e4c37", "version": "2.1.0" } - }, - { - "package": "Swinject", - "repositoryURL": "https://github.com/swinject/swinject", - "state": { - "branch": null, - "revision": "1b7527c74d59e22843bf2f5041cac4d18ad9df8e", - "version": "2.6.2" - } } ] }, diff --git a/Tests/Fakes.swift b/Tests/Fakes.swift index dd37fa12..22d55902 100644 --- a/Tests/Fakes.swift +++ b/Tests/Fakes.swift @@ -2,7 +2,7 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -import Swinject3 +import Swinject class FakeProvider: Provider { func instance(_ type: Descriptor, with dependency: Dependency) throws -> Descriptor.BaseType where Descriptor : TypeDescriptor { @@ -10,8 +10,8 @@ class FakeProvider: Provider { } } -class IntManipulator: TypeManipulator { - typealias ManipulatedType = Int +class IntBinding: Binding { + typealias BoundType = Int } class IntDescriptor: TypeDescriptor { diff --git a/Tests/ProviderBindingSpec.swift b/Tests/ProviderBindingSpec.swift new file mode 100644 index 00000000..3a8d0613 --- /dev/null +++ b/Tests/ProviderBindingSpec.swift @@ -0,0 +1,39 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +import Quick +import Nimble +@testable import Swinject + +class ProviderBindingSpec: QuickSpec { override func spec() { + describe("value") { + it("returns given value") { + let binding = vvalue(42) + expect { try binding.instance(using: FakeProvider()) } == 42 + } + } + describe("provider") { + it("returns instance made by provider method") { + let binding = provider { 42 } + expect { try binding.instance(using: FakeProvider()) } == 42 + } + it("does not call provider method until instance is requested") { + var called = false + _ = provider { called = true } + expect(called).to(beFalse()) + } + it("calls facrory method with given provider") { + var passedProvider: Provider? + let provider = FakeProvider() + let binding = factory { passedProvider = $0 } + _ = try? binding.instance(using: provider) + expect(passedProvider) === provider + } + it("rethrows error from provider method") { + let binding = provider { throw SwinjectError() } + expect { try binding.instance(using: FakeProvider()) }.to(throwError()) + } + } + // TODO: Initializer +}} diff --git a/Tests/SwinjectApiSpec.swift b/Tests/SwinjectApiSpec.swift index f00ec684..b189900f 100644 --- a/Tests/SwinjectApiSpec.swift +++ b/Tests/SwinjectApiSpec.swift @@ -4,7 +4,7 @@ import Quick import Nimble -import Swinject3 +import Swinject class SwinjectApiSpec: QuickSpec { override func spec() { var person = Person() @@ -38,7 +38,7 @@ class SwinjectApiSpec: QuickSpec { override func spec() { it("throws if multiple providers are bound") { let swinject = Swinject { bbind(Int.self) & 42 - bbind(Int.self) & factory { 17 + 25 } + bbind(Int.self) & provider { 17 + 25 } } expect { try swinject.instance(of: Int.self) }.to(throwError()) } @@ -76,13 +76,13 @@ class SwinjectApiSpec: QuickSpec { override func spec() { it("uses passed dependency if type already has a bound provider") { let swinject = Swinject { bbind(Pet.self) & factory { try Pet(owner: $0.instance()) } - bbind(Person.self) & factory { Person() } + bbind(Person.self) & provider { Person() } } let pet = try? swinject.instance(with: person) as Pet expect(pet?.owner) === person } // TODO: Multiple dependencies - // TODO: Reuse binding request for multiple manipulators? + // TODO: Reuse binding request for multiple bindings? // TODO: Less verbose type forwading API? } }} diff --git a/Tests/SwinjectTreeBuilderSpec.swift b/Tests/SwinjectTreeBuilderSpec.swift index 5407e053..a26aa80e 100644 --- a/Tests/SwinjectTreeBuilderSpec.swift +++ b/Tests/SwinjectTreeBuilderSpec.swift @@ -4,7 +4,7 @@ import Quick import Nimble -@testable import Swinject3 +@testable import Swinject class SwinjectTreeBuilderSpec: QuickSpec { override func spec() { it("builds empty function") { diff --git a/Tests/TypeBinderSpec.swift b/Tests/TypeBinderSpec.swift index aca18a67..fde0f50e 100644 --- a/Tests/TypeBinderSpec.swift +++ b/Tests/TypeBinderSpec.swift @@ -4,56 +4,56 @@ import Quick import Nimble -@testable import Swinject3 +@testable import Swinject class TypeBinderSpec: QuickSpec { override func spec() { describe("`bind` method") { it("descriptor is correct for simple type") { - let request = Swinject3.bind(Int.self) + let request = bbind(Int.self) let descriptor = request.descriptor as? Tagged expect(descriptor).notTo(beNil()) } it("descriptor has correct tag for tagged type") { - let request = Swinject3.bind(Int.self, tagged: "Foo") + let request = bbind(Int.self, tagged: "Foo") let descriptor = request.descriptor as? Tagged expect(descriptor?.tag) == "Foo" } it("descriptor is used if given as parameter") { let descriptor = IntDescriptor() - let request = Swinject3.bind(descriptor) + let request = bbind(descriptor) expect(request.descriptor) === descriptor } } describe("`with` method") { it("produces binding with correct descriptor") { let descriptor = IntDescriptor() - let binding = Swinject3.bind(descriptor).with(IntManipulator()) - expect(binding.descriptor) === descriptor + let entry = bbind(descriptor).with(IntBinding()) + expect(entry.descriptor) === descriptor } - it("produces binding with correct manipulator") { - let manipulator = IntManipulator() - let binding = Swinject3.bind(Int.self).with(manipulator) - expect(binding.manipulator) === manipulator + it("produces binding with correct binding") { + let binding = IntBinding() + let entry = bbind(Int.self).with(binding) + expect(entry.binding) === binding } it("produces type provider if given value of descriptor type") { - let binding = Swinject3.bind(Int.self).with(42) - expect(binding.manipulator is TypeProvider).to(beTrue()) + let entry = bbind(Int.self).with(42) + expect(entry.binding is ProviderBinding).to(beTrue()) } } describe("binding operator") { it("produces binding with correct descriptor") { let descriptor = IntDescriptor() - let binding = Swinject3.bind(descriptor) & IntManipulator() - expect(binding.descriptor) === descriptor + let entry = bbind(descriptor) & IntBinding() + expect(entry.descriptor) === descriptor } - it("produces binding with correct manipulator") { - let manipulator = IntManipulator() - let binding = Swinject3.bind(Int.self) & manipulator - expect(binding.manipulator) === manipulator + it("produces binding with correct binding") { + let binding = IntBinding() + let entry = bbind(Int.self) & binding + expect(entry.binding) === binding } it("produces type provider if given value of descriptor type") { - let binding = Swinject3.bind(Int.self) & 42 - expect(binding.manipulator is TypeProvider).to(beTrue()) + let entry = bbind(Int.self) & 42 + expect(entry.binding is ProviderBinding).to(beTrue()) } } }} diff --git a/Tests/TypeProviderSpec.swift b/Tests/TypeProviderSpec.swift deleted file mode 100644 index 184b76d8..00000000 --- a/Tests/TypeProviderSpec.swift +++ /dev/null @@ -1,39 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -import Quick -import Nimble -@testable import Swinject3 - -class TypeProviderSpec: QuickSpec { override func spec() { - describe("value") { - it("returns given value") { - let it = Swinject3.value(42) - expect { try it.instance(using: FakeProvider()) } == 42 - } - } - describe("factory") { - it("returns instance made by factory method") { - let it = Swinject3.factory { 42 } - expect { try it.instance(using: FakeProvider()) } == 42 - } - it("does not call factory method until instance is requested") { - var called = false - _ = Swinject3.factory { called = true } - expect(called).to(beFalse()) - } - it("calls facrory method with given provider") { - var passedProvider: Provider? - let provider = FakeProvider() - let it = Swinject3.factory { passedProvider = $0 } - _ = try? it.instance(using: provider) - expect(passedProvider) === provider - } - it("rethrows error from factory method") { - let it = Swinject3.factory { throw SwinjectError() } - expect { try it.instance(using: FakeProvider()) }.to(throwError()) - } - } - // TODO: Initializer -}} diff --git a/Tests/Utils.swift b/Tests/Utils.swift index d2682d22..4aaba67c 100644 --- a/Tests/Utils.swift +++ b/Tests/Utils.swift @@ -2,22 +2,26 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -import Swinject3 +import protocol Swinject.TypeDescriptor +import struct Swinject.TypeBinder +import struct Swinject.ProviderBinding +import func Swinject.bind +import func Swinject.value -// Original Swinject3 functions conflict with QuickSpec's instance methods +// Original Swinject functions conflict with QuickSpec's instance methods func bbind(_: Type.Type) -> TypeBinder { - Swinject3.bind(Type.self) + Swinject.bind(Type.self) } func bbind(_: Type.Type, tagged tag: Tag) -> TypeBinder where Tag: Equatable { - Swinject3.bind(Type.self, tagged: tag) + Swinject.bind(Type.self, tagged: tag) } func bbind(_ descriptor: Descriptor) -> TypeBinder where Descriptor: TypeDescriptor { - Swinject3.bind(descriptor) + Swinject.bind(descriptor) } -func vvalue(_ it: Type) -> TypeProvider { - Swinject3.value(it) +func vvalue(_ it: Type) -> ProviderBinding { + Swinject.value(it) } From e04a9974384f14a5937f1a0e364e98a140c975bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 14 Jul 2019 13:13:34 +0200 Subject: [PATCH 019/239] Implement InstanceBinding --- Sources/Binding.swift | 11 +++- Sources/BindingEntry.swift | 2 +- Sources/{Provider.swift => Injector.swift} | 4 +- Sources/InstanceBinding.swift | 22 ++++++++ Sources/ProviderBinding.swift | 20 ++------ Sources/Swinject.swift | 13 +++-- Sources/TypeBinder.swift | 2 +- Swinject.xcodeproj/project.pbxproj | 16 ++++-- .../xcschemes/Swinject-OSX.xcscheme | 4 +- Tests/Fakes.swift | 4 +- Tests/InstanceBindingSpec.swift | 14 +++++ Tests/ProviderBindingSpec.swift | 51 +++++++++---------- Tests/SwinjectApiSpec.swift | 22 +++----- Tests/TypeBinderSpec.swift | 20 ++++---- Tests/Utils.swift | 6 --- 15 files changed, 118 insertions(+), 93 deletions(-) rename Sources/{Provider.swift => Injector.swift} (92%) create mode 100644 Sources/InstanceBinding.swift create mode 100644 Tests/InstanceBindingSpec.swift diff --git a/Sources/Binding.swift b/Sources/Binding.swift index 58d3b056..bf7c9078 100644 --- a/Sources/Binding.swift +++ b/Sources/Binding.swift @@ -2,8 +2,17 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -public protocol AnyBinding {} +public protocol AnyBinding { + func instance(using provider: Injector) throws -> Any +} public protocol Binding: AnyBinding { associatedtype BoundType + func instance(using provider: Injector) throws -> BoundType +} + +public extension AnyBinding where Self: Binding { + func instance(using provider: Injector) throws -> Any { + try instance(using: provider) as BoundType + } } diff --git a/Sources/BindingEntry.swift b/Sources/BindingEntry.swift index db567fdf..c95b7f1b 100644 --- a/Sources/BindingEntry.swift +++ b/Sources/BindingEntry.swift @@ -4,5 +4,5 @@ public struct BindingEntry: SwinjectEntry { let descriptor: AnyTypeDescriptor - let binding: AnyBinding // TODO: Rename to binding + let binding: AnyBinding } diff --git a/Sources/Provider.swift b/Sources/Injector.swift similarity index 92% rename from Sources/Provider.swift rename to Sources/Injector.swift index d54af8cd..6408e16d 100644 --- a/Sources/Provider.swift +++ b/Sources/Injector.swift @@ -2,11 +2,11 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -public protocol Provider { +public protocol Injector { func instance(_ descriptor: Descriptor, with dependency: Dependency) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor } -public extension Provider { +public extension Injector { func instance(of: Type.Type = Type.self) throws -> Type { try instance(plain(Type.self), with: ()) } diff --git a/Sources/InstanceBinding.swift b/Sources/InstanceBinding.swift new file mode 100644 index 00000000..1a51c9bd --- /dev/null +++ b/Sources/InstanceBinding.swift @@ -0,0 +1,22 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +// TODO: Make internal +public struct InstanceBinding: Binding { + public typealias BoundType = Type + + private let _instance: Type + + init(_ instance: Type) { + _instance = instance + } + + public func instance(using provider: Injector) throws -> Type { + _instance + } +} + +public func instance(_ instance: Type) -> InstanceBinding { + InstanceBinding(instance) +} diff --git a/Sources/ProviderBinding.swift b/Sources/ProviderBinding.swift index 29caff02..9a28127a 100644 --- a/Sources/ProviderBinding.swift +++ b/Sources/ProviderBinding.swift @@ -2,35 +2,25 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // +// TODO: Make internal public struct ProviderBinding: Binding { public typealias BoundType = Type - private let builder: (Provider) throws -> Type + private let builder: (Injector) throws -> Type - init(_ builder: @escaping (Provider) throws -> Type) { + init(_ builder: @escaping (Injector) throws -> Type) { self.builder = builder } - func instance(using provider: Provider) throws -> Type { + public func instance(using provider: Injector) throws -> Type { try builder(provider) } } -// FIXME: Create InstanceBinding for this -public func value(_ it: Type) -> ProviderBinding { - ProviderBinding { _ in it } -} - public func provider(_ builder: @escaping () throws -> Type) -> ProviderBinding { ProviderBinding { _ in try builder() } } -public func factory(_ builder: @escaping (Provider) throws -> Type) -> ProviderBinding { +public func provider(_ builder: @escaping (Injector) throws -> Type) -> ProviderBinding { ProviderBinding(builder) } - -public extension ProviderBinding { - func map(_ transform: @escaping (Type) -> OtherType) -> ProviderBinding { - ProviderBinding { try transform(self.instance(using: $0)) } - } -} diff --git a/Sources/Swinject.swift b/Sources/Swinject.swift index 0cef8d01..41666421 100644 --- a/Sources/Swinject.swift +++ b/Sources/Swinject.swift @@ -25,7 +25,7 @@ public extension Swinject { } extension Swinject { - private func bindings(for descriptor: Descriptor) -> [BindingEntry] where Descriptor : TypeDescriptor { + private func entries(for descriptor: Descriptor) -> [BindingEntry] where Descriptor : TypeDescriptor { return entries .compactMap { $0 as? BindingEntry } .filter { $0.descriptor.matches(descriptor) } @@ -36,18 +36,17 @@ extension Swinject { } } -extension Swinject: Provider { +extension Swinject: Injector { public func instance(_ descriptor: Descriptor, with dependency: Dependency) throws -> Descriptor.BaseType where Descriptor : TypeDescriptor { - let providers = bindings(for: descriptor) - .compactMap { $0.binding as? ProviderBinding } - if providers.count != 1 { + let matchingEntries = entries(for: descriptor) + if matchingEntries.count != 1 { throw SwinjectError() } else { - return try providers[0].instance(using: provider(with: dependency)) + return try matchingEntries[0].binding.instance(using: provider(with: dependency)) as! Descriptor.BaseType } } - private func provider(with dependency: Dependency) -> Provider { + private func provider(with dependency: Dependency) -> Injector { guard !(dependency is Void) else { return self } return Swinject(entries: entries .filter { !matches($0, plain(Dependency.self)) } diff --git a/Sources/TypeBinder.swift b/Sources/TypeBinder.swift index 1230e0de..966480c2 100644 --- a/Sources/TypeBinder.swift +++ b/Sources/TypeBinder.swift @@ -28,7 +28,7 @@ public extension TypeBinder { } func with(_ it: Type) -> BindingEntry { - BindingEntry(descriptor: descriptor, binding: value(it)) + BindingEntry(descriptor: descriptor, binding: instance(it)) } } diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 173f3215..1f3d0476 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -15,13 +15,15 @@ CD85AF1022DA586D00A8B7CA /* ProviderBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF0F22DA586D00A8B7CA /* ProviderBindingSpec.swift */; }; CD85AF1222DA5A8F00A8B7CA /* Fakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF1122DA5A8F00A8B7CA /* Fakes.swift */; }; CDADF32122DB38C600C5D8DB /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDADF32022DB38C600C5D8DB /* SwinjectTree.swift */; }; + CDADF32322DB416C00C5D8DB /* InstanceBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDADF32222DB416C00C5D8DB /* InstanceBinding.swift */; }; + CDADF33322DB4C1800C5D8DB /* InstanceBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDADF33122DB4C1200C5D8DB /* InstanceBindingSpec.swift */; }; CDD8380322DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380222DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift */; }; CDD8380522DA307F003E9909 /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380422DA307F003E9909 /* TypeBinder.swift */; }; CDD8380722DA30C6003E9909 /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380622DA30C6003E9909 /* TypeDescriptor.swift */; }; CDD8380A22DA31D9003E9909 /* TypeBinderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380822DA31C6003E9909 /* TypeBinderSpec.swift */; }; CDD8380C22DA3AD8003E9909 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380B22DA3AD8003E9909 /* Binding.swift */; }; CDD8380E22DA3B0D003E9909 /* BindingEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380D22DA3B0D003E9909 /* BindingEntry.swift */; }; - CDD8381022DA429F003E9909 /* Provider.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380F22DA429F003E9909 /* Provider.swift */; }; + CDD8381022DA429F003E9909 /* Injector.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380F22DA429F003E9909 /* Injector.swift */; }; CDD8381622DA4B55003E9909 /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381522DA4B55003E9909 /* Swinject.swift */; }; CDD8381B22DA4CBE003E9909 /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381922DA4C9F003E9909 /* SwinjectApiSpec.swift */; }; CDD8381D22DA4E02003E9909 /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381C22DA4E02003E9909 /* SwinjectError.swift */; }; @@ -50,13 +52,15 @@ CD85AF0F22DA586D00A8B7CA /* ProviderBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProviderBindingSpec.swift; sourceTree = ""; }; CD85AF1122DA5A8F00A8B7CA /* Fakes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Fakes.swift; sourceTree = ""; }; CDADF32022DB38C600C5D8DB /* SwinjectTree.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTree.swift; sourceTree = ""; }; + CDADF32222DB416C00C5D8DB /* InstanceBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceBinding.swift; sourceTree = ""; }; + CDADF33122DB4C1200C5D8DB /* InstanceBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceBindingSpec.swift; sourceTree = ""; }; CDD8380222DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTreeBuilderSpec.swift; sourceTree = ""; }; CDD8380422DA307F003E9909 /* TypeBinder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinder.swift; sourceTree = ""; }; CDD8380622DA30C6003E9909 /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; CDD8380822DA31C6003E9909 /* TypeBinderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinderSpec.swift; sourceTree = ""; }; CDD8380B22DA3AD8003E9909 /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; CDD8380D22DA3B0D003E9909 /* BindingEntry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingEntry.swift; sourceTree = ""; }; - CDD8380F22DA429F003E9909 /* Provider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Provider.swift; sourceTree = ""; }; + CDD8380F22DA429F003E9909 /* Injector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Injector.swift; sourceTree = ""; }; CDD8381522DA4B55003E9909 /* Swinject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Swinject.swift; sourceTree = ""; }; CDD8381922DA4C9F003E9909 /* SwinjectApiSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectApiSpec.swift; sourceTree = ""; }; CDD8381C22DA4E02003E9909 /* SwinjectError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectError.swift; sourceTree = ""; }; @@ -113,7 +117,8 @@ CDD8380622DA30C6003E9909 /* TypeDescriptor.swift */, CDD8380B22DA3AD8003E9909 /* Binding.swift */, CD85AF0D22DA57AD00A8B7CA /* ProviderBinding.swift */, - CDD8380F22DA429F003E9909 /* Provider.swift */, + CDADF32222DB416C00C5D8DB /* InstanceBinding.swift */, + CDD8380F22DA429F003E9909 /* Injector.swift */, CDD8380D22DA3B0D003E9909 /* BindingEntry.swift */, CDD8381522DA4B55003E9909 /* Swinject.swift */, CDD8381C22DA4E02003E9909 /* SwinjectError.swift */, @@ -128,6 +133,7 @@ CDD8380222DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift */, CDD8380822DA31C6003E9909 /* TypeBinderSpec.swift */, CD85AF0F22DA586D00A8B7CA /* ProviderBindingSpec.swift */, + CDADF33122DB4C1200C5D8DB /* InstanceBindingSpec.swift */, CDD8381922DA4C9F003E9909 /* SwinjectApiSpec.swift */, CDD8381E22DA4F6F003E9909 /* Utils.swift */, CD85AF1122DA5A8F00A8B7CA /* Fakes.swift */, @@ -266,7 +272,8 @@ buildActionMask = 2147483647; files = ( CDD8380C22DA3AD8003E9909 /* Binding.swift in Sources */, - CDD8381022DA429F003E9909 /* Provider.swift in Sources */, + CDD8381022DA429F003E9909 /* Injector.swift in Sources */, + CDADF32322DB416C00C5D8DB /* InstanceBinding.swift in Sources */, CDADF32122DB38C600C5D8DB /* SwinjectTree.swift in Sources */, CDD8381D22DA4E02003E9909 /* SwinjectError.swift in Sources */, CDD8380722DA30C6003E9909 /* TypeDescriptor.swift in Sources */, @@ -285,6 +292,7 @@ CDD8381B22DA4CBE003E9909 /* SwinjectApiSpec.swift in Sources */, CDD8380A22DA31D9003E9909 /* TypeBinderSpec.swift in Sources */, CD85AF1222DA5A8F00A8B7CA /* Fakes.swift in Sources */, + CDADF33322DB4C1800C5D8DB /* InstanceBindingSpec.swift in Sources */, CD85AF1022DA586D00A8B7CA /* ProviderBindingSpec.swift in Sources */, CDD8380322DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift in Sources */, ); diff --git a/Swinject.xcodeproj/xcshareddata/xcschemes/Swinject-OSX.xcscheme b/Swinject.xcodeproj/xcshareddata/xcschemes/Swinject-OSX.xcscheme index d77f50d1..ed0a2882 100644 --- a/Swinject.xcodeproj/xcshareddata/xcschemes/Swinject-OSX.xcscheme +++ b/Swinject.xcodeproj/xcshareddata/xcschemes/Swinject-OSX.xcscheme @@ -15,7 +15,7 @@ @@ -61,7 +61,7 @@ diff --git a/Tests/Fakes.swift b/Tests/Fakes.swift index 22d55902..3d47b28d 100644 --- a/Tests/Fakes.swift +++ b/Tests/Fakes.swift @@ -4,14 +4,14 @@ import Swinject -class FakeProvider: Provider { +class FakeInjector: Injector { func instance(_ type: Descriptor, with dependency: Dependency) throws -> Descriptor.BaseType where Descriptor : TypeDescriptor { fatalError() } } class IntBinding: Binding { - typealias BoundType = Int + func instance(using provider: Injector) throws -> Int { 0 } } class IntDescriptor: TypeDescriptor { diff --git a/Tests/InstanceBindingSpec.swift b/Tests/InstanceBindingSpec.swift new file mode 100644 index 00000000..1eebfa02 --- /dev/null +++ b/Tests/InstanceBindingSpec.swift @@ -0,0 +1,14 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +import Quick +import Nimble +@testable import Swinject + +class InstanceBindingSpec: QuickSpec { override func spec() { + it("returns given instance") { + let binding = instance(42) + expect { try binding.instance(using: FakeInjector()) } == 42 + } +}} diff --git a/Tests/ProviderBindingSpec.swift b/Tests/ProviderBindingSpec.swift index 3a8d0613..340b634a 100644 --- a/Tests/ProviderBindingSpec.swift +++ b/Tests/ProviderBindingSpec.swift @@ -7,33 +7,30 @@ import Nimble @testable import Swinject class ProviderBindingSpec: QuickSpec { override func spec() { - describe("value") { - it("returns given value") { - let binding = vvalue(42) - expect { try binding.instance(using: FakeProvider()) } == 42 - } + it("returns instance made by provider method") { + let binding = provider { 42 } + expect { try binding.instance(using: FakeInjector()) } == 42 } - describe("provider") { - it("returns instance made by provider method") { - let binding = provider { 42 } - expect { try binding.instance(using: FakeProvider()) } == 42 - } - it("does not call provider method until instance is requested") { - var called = false - _ = provider { called = true } - expect(called).to(beFalse()) - } - it("calls facrory method with given provider") { - var passedProvider: Provider? - let provider = FakeProvider() - let binding = factory { passedProvider = $0 } - _ = try? binding.instance(using: provider) - expect(passedProvider) === provider - } - it("rethrows error from provider method") { - let binding = provider { throw SwinjectError() } - expect { try binding.instance(using: FakeProvider()) }.to(throwError()) - } + it("does not call builder until instance is requested") { + var called = false + _ = provider { called = true } + expect(called).to(beFalse()) + } + it("calls builder with given provider") { + var passedProvider: Injector? + let fake = FakeInjector() + let binding = provider { passedProvider = $0 } + _ = try? binding.instance(using: fake) + expect(passedProvider) === fake + } + it("rethrows error from builder") { + let binding = provider { throw SwinjectError() } + expect { try binding.instance(using: FakeInjector()) }.to(throwError()) + } + it("does not reuse instance") { + let binding = provider { Person() } + let instance1 = try? binding.instance(using: FakeInjector()) + let instance2 = try? binding.instance(using: FakeInjector()) + expect(instance1) !== instance2 } - // TODO: Initializer }} diff --git a/Tests/SwinjectApiSpec.swift b/Tests/SwinjectApiSpec.swift index b189900f..4e101ded 100644 --- a/Tests/SwinjectApiSpec.swift +++ b/Tests/SwinjectApiSpec.swift @@ -24,13 +24,13 @@ class SwinjectApiSpec: QuickSpec { override func spec() { } it("throws if providing type with missing dependency") { let swinject = Swinject { - bbind(Pet.self) & factory { Pet(owner: try $0.instance()) } + bbind(Pet.self) & provider { Pet(owner: try $0.instance()) } } expect { try swinject.instance(of: Pet.self) }.to(throwError()) } it("returns instance from bound dependency provider") { let swinject = Swinject { - bbind(Pet.self) & factory { Pet(owner: try $0.instance()) } + bbind(Pet.self) & provider { Pet(owner: try $0.instance()) } bbind(Person.self) & person } expect { try swinject.instance(of: Pet.self).owner } === person @@ -50,39 +50,31 @@ class SwinjectApiSpec: QuickSpec { override func spec() { expect { try swinject.instance(of: Int.self, tagged: 42) }.to(throwError()) expect { try swinject.instance(of: Int.self, tagged: "OtherTag") }.to(throwError()) } - it("can reuse provider for multiple descriptors") { - let personProvider = vvalue(person) // @functionBuilder does not support declarations in closures yet - let swinject = Swinject { - bbind(Person.self) & personProvider - bbind(AnyObject.self) & personProvider.map { $0 as AnyObject } - } - expect { try swinject.instance(of: Person.self) } === person - expect { try swinject.instance(of: AnyObject.self) } === person - } it("provides passed dependency during instance provision") { let swinject = Swinject { - bbind(Pet.self) & factory { try Pet(owner: $0.instance()) } + bbind(Pet.self) & provider { try Pet(owner: $0.instance()) } } let pet = try? swinject.instance(with: person) as Pet expect(pet?.owner) === person } it("does not throw if passed dependency type already has a bound provider") { let swinject = Swinject { - bbind(Pet.self) & factory { try Pet(owner: $0.instance()) } + bbind(Pet.self) & provider { try Pet(owner: $0.instance()) } bbind(Person.self) & person } expect { try swinject.instance(of: Pet.self, with: person) }.notTo(throwError()) } it("uses passed dependency if type already has a bound provider") { let swinject = Swinject { - bbind(Pet.self) & factory { try Pet(owner: $0.instance()) } + bbind(Pet.self) & provider { try Pet(owner: $0.instance()) } bbind(Person.self) & provider { Person() } } let pet = try? swinject.instance(with: person) as Pet expect(pet?.owner) === person } // TODO: Multiple dependencies - // TODO: Reuse binding request for multiple bindings? + // TODO: Reuse descriptor for multiple bindings? + // TODO: Reuse binding for multiple descriptors // TODO: Less verbose type forwading API? } }} diff --git a/Tests/TypeBinderSpec.swift b/Tests/TypeBinderSpec.swift index fde0f50e..ca466d2f 100644 --- a/Tests/TypeBinderSpec.swift +++ b/Tests/TypeBinderSpec.swift @@ -7,7 +7,7 @@ import Nimble @testable import Swinject class TypeBinderSpec: QuickSpec { override func spec() { - describe("`bind` method") { + describe("bind") { it("descriptor is correct for simple type") { let request = bbind(Int.self) let descriptor = request.descriptor as? Tagged @@ -25,35 +25,35 @@ class TypeBinderSpec: QuickSpec { override func spec() { } } describe("`with` method") { - it("produces binding with correct descriptor") { + it("produces entry with correct descriptor") { let descriptor = IntDescriptor() let entry = bbind(descriptor).with(IntBinding()) expect(entry.descriptor) === descriptor } - it("produces binding with correct binding") { + it("produces entry with correct binding") { let binding = IntBinding() let entry = bbind(Int.self).with(binding) expect(entry.binding) === binding } - it("produces type provider if given value of descriptor type") { + it("produces entry if given value of descriptor type") { let entry = bbind(Int.self).with(42) - expect(entry.binding is ProviderBinding).to(beTrue()) + expect(entry.binding is InstanceBinding).to(beTrue()) } } - describe("binding operator") { - it("produces binding with correct descriptor") { + describe("& operator") { + it("produces entry with correct descriptor") { let descriptor = IntDescriptor() let entry = bbind(descriptor) & IntBinding() expect(entry.descriptor) === descriptor } - it("produces binding with correct binding") { + it("produces entry with correct binding") { let binding = IntBinding() let entry = bbind(Int.self) & binding expect(entry.binding) === binding } - it("produces type provider if given value of descriptor type") { + it("produces entry provider if given value of descriptor type") { let entry = bbind(Int.self) & 42 - expect(entry.binding is ProviderBinding).to(beTrue()) + expect(entry.binding is InstanceBinding).to(beTrue()) } } }} diff --git a/Tests/Utils.swift b/Tests/Utils.swift index 4aaba67c..692f3ab8 100644 --- a/Tests/Utils.swift +++ b/Tests/Utils.swift @@ -6,7 +6,6 @@ import protocol Swinject.TypeDescriptor import struct Swinject.TypeBinder import struct Swinject.ProviderBinding import func Swinject.bind -import func Swinject.value // Original Swinject functions conflict with QuickSpec's instance methods func bbind(_: Type.Type) -> TypeBinder { @@ -20,8 +19,3 @@ func bbind(_: Type.Type, tagged tag: Tag) -> TypeBinder where T func bbind(_ descriptor: Descriptor) -> TypeBinder where Descriptor: TypeDescriptor { Swinject.bind(descriptor) } - -func vvalue(_ it: Type) -> ProviderBinding { - Swinject.value(it) -} - From 69736d8c3fa815b9441b6f4c37bc2716b4023daa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 14 Jul 2019 15:58:32 +0200 Subject: [PATCH 020/239] Refactor tree builder spec --- Sources/BindingEntry.swift | 8 ++- Sources/Swinject.swift | 36 ++++-------- Sources/SwinjectModule.swift | 7 +++ Sources/SwinjectTree.swift | 19 +++++-- Swinject.xcodeproj/project.pbxproj | 4 ++ Tests/Fakes.swift | 8 ++- Tests/SwinjectApiSpec.swift | 22 -------- Tests/SwinjectTreeBuilderSpec.swift | 86 ++++++++++++++++------------- 8 files changed, 100 insertions(+), 90 deletions(-) create mode 100644 Sources/SwinjectModule.swift diff --git a/Sources/BindingEntry.swift b/Sources/BindingEntry.swift index c95b7f1b..b956e281 100644 --- a/Sources/BindingEntry.swift +++ b/Sources/BindingEntry.swift @@ -2,7 +2,13 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -public struct BindingEntry: SwinjectEntry { +protocol AnyBindingEntry: SwinjectEntry { + var descriptor: AnyTypeDescriptor { get } + var binding: AnyBinding { get } +} + +// TODO: Make this internal +public struct BindingEntry: AnyBindingEntry { let descriptor: AnyTypeDescriptor let binding: AnyBinding } diff --git a/Sources/Swinject.swift b/Sources/Swinject.swift index 41666421..1e444a65 100644 --- a/Sources/Swinject.swift +++ b/Sources/Swinject.swift @@ -3,54 +3,42 @@ // public struct Swinject { - let entries: [SwinjectEntry] + let tree: SwinjectTree - init(entries: [SwinjectEntry]) { - self.entries = entries + init(tree: SwinjectTree) { + self.tree = tree } } public extension Swinject { init(@SwinjectTreeBuilder builder: () -> [SwinjectEntry]) { - self.init(entries: builder()) + self.init(tree: SwinjectTreeBuilder.buildFunction(builder())) } init(@SwinjectTreeBuilder builder: () -> SwinjectEntry) { - self.init(entries: [builder()]) + self.init(tree: SwinjectTreeBuilder.buildFunction([builder()])) } init(@SwinjectTreeBuilder builder: () -> Void) { - self.init(entries: []) + self.init(tree: SwinjectTreeBuilder.buildFunction([])) } } extension Swinject { - private func entries(for descriptor: Descriptor) -> [BindingEntry] where Descriptor : TypeDescriptor { - return entries - .compactMap { $0 as? BindingEntry } + private func findBindings(for descriptor: Descriptor) -> [AnyBinding] where Descriptor : TypeDescriptor { + return tree.bindingEntries .filter { $0.descriptor.matches(descriptor) } - } - - private func matches(_ entry: SwinjectEntry, _ descriptor: Descriptor) -> Bool where Descriptor: TypeDescriptor { - (entry as? BindingEntry)?.descriptor.matches(descriptor) ?? false + .map { $0.binding } } } extension Swinject: Injector { public func instance(_ descriptor: Descriptor, with dependency: Dependency) throws -> Descriptor.BaseType where Descriptor : TypeDescriptor { - let matchingEntries = entries(for: descriptor) - if matchingEntries.count != 1 { + let bindings = findBindings(for: descriptor) + if bindings.count != 1 { throw SwinjectError() } else { - return try matchingEntries[0].binding.instance(using: provider(with: dependency)) as! Descriptor.BaseType + return try bindings[0].instance(using: self) as! Descriptor.BaseType } } - - private func provider(with dependency: Dependency) -> Injector { - guard !(dependency is Void) else { return self } - return Swinject(entries: entries - .filter { !matches($0, plain(Dependency.self)) } - + [bind(Dependency.self) & dependency] - ) - } } diff --git a/Sources/SwinjectModule.swift b/Sources/SwinjectModule.swift new file mode 100644 index 00000000..686d2e52 --- /dev/null +++ b/Sources/SwinjectModule.swift @@ -0,0 +1,7 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +protocol SwinjectModule {} + +protocol ModuleIncludeEntry: SwinjectEntry {} diff --git a/Sources/SwinjectTree.swift b/Sources/SwinjectTree.swift index 353433af..7e6979fd 100644 --- a/Sources/SwinjectTree.swift +++ b/Sources/SwinjectTree.swift @@ -2,12 +2,13 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -struct SwinjectTree { - -} - public protocol SwinjectEntry {} +public struct SwinjectTree { + let bindingEntries: [AnyBindingEntry] + let includeEntries: [ModuleIncludeEntry] +} + @_functionBuilder public enum SwinjectTreeBuilder { public static func buildBlock() -> Void {} @@ -27,6 +28,16 @@ public enum SwinjectTreeBuilder { public static func buildEither(second input: [SwinjectEntry]) -> SwinjectEntry { Composed(parts: input) } + + // This is not used by compiler implicitly yet + public static func buildFunction(_ input: [SwinjectEntry]) -> SwinjectTree { + let entries = input.flatMap(unpack) + return SwinjectTree( + bindingEntries: entries.compactMap { $0 as? AnyBindingEntry }, + includeEntries: entries.compactMap { $0 as? ModuleIncludeEntry } + ) + // TODO: Validate + } } extension SwinjectTreeBuilder { diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 1f3d0476..6869de27 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -17,6 +17,7 @@ CDADF32122DB38C600C5D8DB /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDADF32022DB38C600C5D8DB /* SwinjectTree.swift */; }; CDADF32322DB416C00C5D8DB /* InstanceBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDADF32222DB416C00C5D8DB /* InstanceBinding.swift */; }; CDADF33322DB4C1800C5D8DB /* InstanceBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDADF33122DB4C1200C5D8DB /* InstanceBindingSpec.swift */; }; + CDADF33522DB521400C5D8DB /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDADF33422DB521400C5D8DB /* SwinjectModule.swift */; }; CDD8380322DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380222DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift */; }; CDD8380522DA307F003E9909 /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380422DA307F003E9909 /* TypeBinder.swift */; }; CDD8380722DA30C6003E9909 /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380622DA30C6003E9909 /* TypeDescriptor.swift */; }; @@ -54,6 +55,7 @@ CDADF32022DB38C600C5D8DB /* SwinjectTree.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTree.swift; sourceTree = ""; }; CDADF32222DB416C00C5D8DB /* InstanceBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceBinding.swift; sourceTree = ""; }; CDADF33122DB4C1200C5D8DB /* InstanceBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceBindingSpec.swift; sourceTree = ""; }; + CDADF33422DB521400C5D8DB /* SwinjectModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectModule.swift; sourceTree = ""; }; CDD8380222DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTreeBuilderSpec.swift; sourceTree = ""; }; CDD8380422DA307F003E9909 /* TypeBinder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinder.swift; sourceTree = ""; }; CDD8380622DA30C6003E9909 /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; @@ -122,6 +124,7 @@ CDD8380D22DA3B0D003E9909 /* BindingEntry.swift */, CDD8381522DA4B55003E9909 /* Swinject.swift */, CDD8381C22DA4E02003E9909 /* SwinjectError.swift */, + CDADF33422DB521400C5D8DB /* SwinjectModule.swift */, ); path = Sources; sourceTree = ""; @@ -272,6 +275,7 @@ buildActionMask = 2147483647; files = ( CDD8380C22DA3AD8003E9909 /* Binding.swift in Sources */, + CDADF33522DB521400C5D8DB /* SwinjectModule.swift in Sources */, CDD8381022DA429F003E9909 /* Injector.swift in Sources */, CDADF32322DB416C00C5D8DB /* InstanceBinding.swift in Sources */, CDADF32122DB38C600C5D8DB /* SwinjectTree.swift in Sources */, diff --git a/Tests/Fakes.swift b/Tests/Fakes.swift index 3d47b28d..00f14bb6 100644 --- a/Tests/Fakes.swift +++ b/Tests/Fakes.swift @@ -2,7 +2,7 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -import Swinject +@testable import Swinject class FakeInjector: Injector { func instance(_ type: Descriptor, with dependency: Dependency) throws -> Descriptor.BaseType where Descriptor : TypeDescriptor { @@ -21,3 +21,9 @@ class IntDescriptor: TypeDescriptor { false } } + +struct DummyBindingEntry: AnyBindingEntry { + var binding: AnyBinding { fatalError() } + var descriptor: AnyTypeDescriptor { fatalError() } +} +struct DummyIncludeEntry: ModuleIncludeEntry {} diff --git a/Tests/SwinjectApiSpec.swift b/Tests/SwinjectApiSpec.swift index 4e101ded..f11f167a 100644 --- a/Tests/SwinjectApiSpec.swift +++ b/Tests/SwinjectApiSpec.swift @@ -50,28 +50,6 @@ class SwinjectApiSpec: QuickSpec { override func spec() { expect { try swinject.instance(of: Int.self, tagged: 42) }.to(throwError()) expect { try swinject.instance(of: Int.self, tagged: "OtherTag") }.to(throwError()) } - it("provides passed dependency during instance provision") { - let swinject = Swinject { - bbind(Pet.self) & provider { try Pet(owner: $0.instance()) } - } - let pet = try? swinject.instance(with: person) as Pet - expect(pet?.owner) === person - } - it("does not throw if passed dependency type already has a bound provider") { - let swinject = Swinject { - bbind(Pet.self) & provider { try Pet(owner: $0.instance()) } - bbind(Person.self) & person - } - expect { try swinject.instance(of: Pet.self, with: person) }.notTo(throwError()) - } - it("uses passed dependency if type already has a bound provider") { - let swinject = Swinject { - bbind(Pet.self) & provider { try Pet(owner: $0.instance()) } - bbind(Person.self) & provider { Person() } - } - let pet = try? swinject.instance(with: person) as Pet - expect(pet?.owner) === person - } // TODO: Multiple dependencies // TODO: Reuse descriptor for multiple bindings? // TODO: Reuse binding for multiple descriptors diff --git a/Tests/SwinjectTreeBuilderSpec.swift b/Tests/SwinjectTreeBuilderSpec.swift index a26aa80e..d7aa7e3d 100644 --- a/Tests/SwinjectTreeBuilderSpec.swift +++ b/Tests/SwinjectTreeBuilderSpec.swift @@ -7,52 +7,62 @@ import Nimble @testable import Swinject class SwinjectTreeBuilderSpec: QuickSpec { override func spec() { - it("builds empty function") { - @SwinjectTreeBuilder func build() -> [SwinjectEntry] { - + describe("allowed syntax") { + it("builds empty closure") { + let tree = makeTree { } + expect(tree.bindingEntries).to(beEmpty()) } - expect(build().count) == 0 - } - it("builds function with single entry") { - @SwinjectTreeBuilder func build() -> [SwinjectEntry] { - AnyEntry() + it("builds closure with single entry") { + let tree = makeTree { DummyBindingEntry() } + expect(tree.bindingEntries.count) == 1 } - expect(build().count) == 1 - } - it("builds function with multiple entries") { - @SwinjectTreeBuilder func build() -> [SwinjectEntry] { - AnyEntry(); AnyEntry(); AnyEntry(); AnyEntry(); AnyEntry() + it("builds closure with multiple entries") { + let tree = makeTree { + DummyBindingEntry(); DummyBindingEntry(); DummyBindingEntry(); DummyBindingEntry(); DummyBindingEntry() + } + expect(tree.bindingEntries.count) == 5 } - expect(build().count) == 5 - } - it("builds function with if statement") { - @SwinjectTreeBuilder func build(_ flag: Bool) -> [SwinjectEntry] { - if flag { AnyEntry() } + it("builds closure with if statement") { + let tree = makeTree { + if true { DummyBindingEntry() } + } + expect(tree.bindingEntries.count) == 1 } - expect(build(true).count) == 1 - expect(build(false).count) == 0 - } - it("builds function with nested if statement") { - @SwinjectTreeBuilder func build(_ flag1: Bool, _ flag2: Bool) -> [SwinjectEntry] { - if flag1 { - AnyEntry() - if flag2 { AnyEntry() } + it("builds closure with nested if statement") { + let tree = makeTree { + if true { DummyBindingEntry(); if true { DummyBindingEntry() } } } + expect(tree.bindingEntries.count) == 2 } - expect(build(true, true).count) == 2 - expect(build(true, false).count) == 1 - } - it("builds function with if else statement") { - @SwinjectTreeBuilder func build(_ flag: Bool) -> [SwinjectEntry] { - if flag { - AnyEntry() - } else { - AnyEntry(); AnyEntry() + it("builds closure with if else statement") { + let tree = makeTree { + if false { } else { DummyBindingEntry(); DummyBindingEntry() } + } + expect(tree.bindingEntries.count) == 2 + } + it("builds closure with binding & include entries") { + let tree = makeTree { + DummyIncludeEntry() + DummyIncludeEntry() + DummyBindingEntry() + DummyBindingEntry() + DummyBindingEntry() } + expect(tree.includeEntries.count) == 2 + expect(tree.bindingEntries.count) == 3 } - expect(build(true).count) == 1 - expect(build(false).count) == 2 } }} -struct AnyEntry: SwinjectEntry {} +// TODO: Return SwinjectTree directly from builder once full support for @functionBuilder is available +func makeTree(@SwinjectTreeBuilder builder: () -> [SwinjectEntry]) -> SwinjectTree { + SwinjectTreeBuilder.buildFunction(builder()) +} + +func makeTree(@SwinjectTreeBuilder builder: () -> SwinjectEntry) -> SwinjectTree { + SwinjectTreeBuilder.buildFunction([builder()]) +} + +func makeTree(@SwinjectTreeBuilder builder: () -> Void) -> SwinjectTree { + SwinjectTreeBuilder.buildFunction([]) +} From 574561e03c4ee53641b32ba9e7f78ced3b33c6b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 14 Jul 2019 17:23:49 +0200 Subject: [PATCH 021/239] Reimplement Swinject injection [WIP] --- Sources/Injector.swift | 10 ++--- Sources/Swinject.swift | 23 +++++----- Sources/TypeBinder.swift | 4 +- Swinject.xcodeproj/project.pbxproj | 12 ++++-- Tests/Fakes.swift | 27 +++++++++++- Tests/SwinjectApiSpec.swift | 68 ------------------------------ Tests/SwinjectSpec.swift | 60 ++++++++++++++++++++++++++ Tests/TestModels.swift | 15 +++++++ 8 files changed, 124 insertions(+), 95 deletions(-) delete mode 100644 Tests/SwinjectApiSpec.swift create mode 100644 Tests/SwinjectSpec.swift create mode 100644 Tests/TestModels.swift diff --git a/Sources/Injector.swift b/Sources/Injector.swift index 6408e16d..9834b9cc 100644 --- a/Sources/Injector.swift +++ b/Sources/Injector.swift @@ -3,19 +3,15 @@ // public protocol Injector { - func instance(_ descriptor: Descriptor, with dependency: Dependency) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor + func instance(_ descriptor: Descriptor) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor } public extension Injector { func instance(of: Type.Type = Type.self) throws -> Type { - try instance(plain(Type.self), with: ()) + try instance(plain(Type.self)) } func instance(of: Type.Type = Type.self, tagged tag: Tag) throws -> Type { - try instance(tagged(Type.self, with: tag), with: ()) - } - - func instance(of: Type.Type = Type.self, with dependency: Dependency) throws -> Type { - try instance(plain(Type.self), with: dependency) + try instance(tagged(Type.self, with: tag)) } } diff --git a/Sources/Swinject.swift b/Sources/Swinject.swift index 1e444a65..331f1d56 100644 --- a/Sources/Swinject.swift +++ b/Sources/Swinject.swift @@ -24,21 +24,18 @@ public extension Swinject { } } -extension Swinject { - private func findBindings(for descriptor: Descriptor) -> [AnyBinding] where Descriptor : TypeDescriptor { - return tree.bindingEntries - .filter { $0.descriptor.matches(descriptor) } - .map { $0.binding } +extension Swinject: Injector { + public func instance(_ descriptor: Descriptor) throws -> Descriptor.BaseType where Descriptor : TypeDescriptor { + guard + let entry = tree.bindingEntries.first, + entry.descriptor.matches(descriptor) + else { throw SwinjectError() } + return try entry.binding.instance(using: NoInjector()) as? Descriptor.BaseType ?? { throw SwinjectError() }() } } -extension Swinject: Injector { - public func instance(_ descriptor: Descriptor, with dependency: Dependency) throws -> Descriptor.BaseType where Descriptor : TypeDescriptor { - let bindings = findBindings(for: descriptor) - if bindings.count != 1 { - throw SwinjectError() - } else { - return try bindings[0].instance(using: self) as! Descriptor.BaseType - } +private struct NoInjector: Injector { + func instance(_ descriptor: Descriptor) throws -> Descriptor.BaseType where Descriptor : TypeDescriptor { + fatalError() } } diff --git a/Sources/TypeBinder.swift b/Sources/TypeBinder.swift index 966480c2..ea3ce389 100644 --- a/Sources/TypeBinder.swift +++ b/Sources/TypeBinder.swift @@ -11,11 +11,11 @@ public struct TypeBinder { } public func bind(_: Type.Type) -> TypeBinder { - TypeBinder(descriptor: plain(Type.self)) + bind(plain(Type.self)) } public func bind(_: Type.Type, tagged tag: Tag) -> TypeBinder where Tag: Equatable { - TypeBinder(descriptor: tagged(Type.self, with: tag)) + bind(tagged(Type.self, with: tag)) } public func bind(_ descriptor: Descriptor) -> TypeBinder where Descriptor: TypeDescriptor { diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 6869de27..aa70d8ec 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -18,6 +18,7 @@ CDADF32322DB416C00C5D8DB /* InstanceBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDADF32222DB416C00C5D8DB /* InstanceBinding.swift */; }; CDADF33322DB4C1800C5D8DB /* InstanceBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDADF33122DB4C1200C5D8DB /* InstanceBindingSpec.swift */; }; CDADF33522DB521400C5D8DB /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDADF33422DB521400C5D8DB /* SwinjectModule.swift */; }; + CDADF33722DB753800C5D8DB /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDADF33622DB753800C5D8DB /* TestModels.swift */; }; CDD8380322DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380222DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift */; }; CDD8380522DA307F003E9909 /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380422DA307F003E9909 /* TypeBinder.swift */; }; CDD8380722DA30C6003E9909 /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380622DA30C6003E9909 /* TypeDescriptor.swift */; }; @@ -26,7 +27,7 @@ CDD8380E22DA3B0D003E9909 /* BindingEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380D22DA3B0D003E9909 /* BindingEntry.swift */; }; CDD8381022DA429F003E9909 /* Injector.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380F22DA429F003E9909 /* Injector.swift */; }; CDD8381622DA4B55003E9909 /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381522DA4B55003E9909 /* Swinject.swift */; }; - CDD8381B22DA4CBE003E9909 /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381922DA4C9F003E9909 /* SwinjectApiSpec.swift */; }; + CDD8381B22DA4CBE003E9909 /* SwinjectSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381922DA4C9F003E9909 /* SwinjectSpec.swift */; }; CDD8381D22DA4E02003E9909 /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381C22DA4E02003E9909 /* SwinjectError.swift */; }; CDD8381F22DA4F6F003E9909 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381E22DA4F6F003E9909 /* Utils.swift */; }; /* End PBXBuildFile section */ @@ -56,6 +57,7 @@ CDADF32222DB416C00C5D8DB /* InstanceBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceBinding.swift; sourceTree = ""; }; CDADF33122DB4C1200C5D8DB /* InstanceBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceBindingSpec.swift; sourceTree = ""; }; CDADF33422DB521400C5D8DB /* SwinjectModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectModule.swift; sourceTree = ""; }; + CDADF33622DB753800C5D8DB /* TestModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestModels.swift; sourceTree = ""; }; CDD8380222DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTreeBuilderSpec.swift; sourceTree = ""; }; CDD8380422DA307F003E9909 /* TypeBinder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinder.swift; sourceTree = ""; }; CDD8380622DA30C6003E9909 /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; @@ -64,7 +66,7 @@ CDD8380D22DA3B0D003E9909 /* BindingEntry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingEntry.swift; sourceTree = ""; }; CDD8380F22DA429F003E9909 /* Injector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Injector.swift; sourceTree = ""; }; CDD8381522DA4B55003E9909 /* Swinject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Swinject.swift; sourceTree = ""; }; - CDD8381922DA4C9F003E9909 /* SwinjectApiSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectApiSpec.swift; sourceTree = ""; }; + CDD8381922DA4C9F003E9909 /* SwinjectSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectSpec.swift; sourceTree = ""; }; CDD8381C22DA4E02003E9909 /* SwinjectError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectError.swift; sourceTree = ""; }; CDD8381E22DA4F6F003E9909 /* Utils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -137,9 +139,10 @@ CDD8380822DA31C6003E9909 /* TypeBinderSpec.swift */, CD85AF0F22DA586D00A8B7CA /* ProviderBindingSpec.swift */, CDADF33122DB4C1200C5D8DB /* InstanceBindingSpec.swift */, - CDD8381922DA4C9F003E9909 /* SwinjectApiSpec.swift */, + CDD8381922DA4C9F003E9909 /* SwinjectSpec.swift */, CDD8381E22DA4F6F003E9909 /* Utils.swift */, CD85AF1122DA5A8F00A8B7CA /* Fakes.swift */, + CDADF33622DB753800C5D8DB /* TestModels.swift */, ); path = Tests; sourceTree = ""; @@ -293,12 +296,13 @@ buildActionMask = 2147483647; files = ( CDD8381F22DA4F6F003E9909 /* Utils.swift in Sources */, - CDD8381B22DA4CBE003E9909 /* SwinjectApiSpec.swift in Sources */, + CDD8381B22DA4CBE003E9909 /* SwinjectSpec.swift in Sources */, CDD8380A22DA31D9003E9909 /* TypeBinderSpec.swift in Sources */, CD85AF1222DA5A8F00A8B7CA /* Fakes.swift in Sources */, CDADF33322DB4C1800C5D8DB /* InstanceBindingSpec.swift in Sources */, CD85AF1022DA586D00A8B7CA /* ProviderBindingSpec.swift in Sources */, CDD8380322DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift in Sources */, + CDADF33722DB753800C5D8DB /* TestModels.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Tests/Fakes.swift b/Tests/Fakes.swift index 00f14bb6..aa31cf3c 100644 --- a/Tests/Fakes.swift +++ b/Tests/Fakes.swift @@ -5,7 +5,7 @@ @testable import Swinject class FakeInjector: Injector { - func instance(_ type: Descriptor, with dependency: Dependency) throws -> Descriptor.BaseType where Descriptor : TypeDescriptor { + func instance(_ type: Descriptor) throws -> Descriptor.BaseType where Descriptor : TypeDescriptor { fatalError() } } @@ -26,4 +26,29 @@ struct DummyBindingEntry: AnyBindingEntry { var binding: AnyBinding { fatalError() } var descriptor: AnyTypeDescriptor { fatalError() } } + struct DummyIncludeEntry: ModuleIncludeEntry {} + +class FakeBinding: Binding { + var instance: Type + var error: Error? + var instanceRequestCount = 0 + + init(_ instance: Type) { + self.instance = instance + } + + func instance(using provider: Injector) throws -> Type { + instanceRequestCount += 1 + if let error = error { throw error } + return instance + } +} + +class FakeDescriptor: TypeDescriptor { + var shouldMatch: (Any) -> Bool = { _ in false } + + func matches(_ other: Descriptor) -> Bool where Descriptor : TypeDescriptor { + return shouldMatch(other) + } +} diff --git a/Tests/SwinjectApiSpec.swift b/Tests/SwinjectApiSpec.swift deleted file mode 100644 index f11f167a..00000000 --- a/Tests/SwinjectApiSpec.swift +++ /dev/null @@ -1,68 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -import Quick -import Nimble -import Swinject - -class SwinjectApiSpec: QuickSpec { override func spec() { - var person = Person() - beforeEach { - person = Person() - } - describe("injection") { - it("throws for empty swinject") { - let swinject = Swinject { } - expect { try swinject.instance(of: Int.self) }.to(throwError()) - } - it("returns instance if provider is bound") { - let swinject = Swinject { - bbind(Int.self).with(42) - } - expect { try swinject.instance(of: Int.self) } == 42 - } - it("throws if providing type with missing dependency") { - let swinject = Swinject { - bbind(Pet.self) & provider { Pet(owner: try $0.instance()) } - } - expect { try swinject.instance(of: Pet.self) }.to(throwError()) - } - it("returns instance from bound dependency provider") { - let swinject = Swinject { - bbind(Pet.self) & provider { Pet(owner: try $0.instance()) } - bbind(Person.self) & person - } - expect { try swinject.instance(of: Pet.self).owner } === person - } - it("throws if multiple providers are bound") { - let swinject = Swinject { - bbind(Int.self) & 42 - bbind(Int.self) & provider { 17 + 25 } - } - expect { try swinject.instance(of: Int.self) }.to(throwError()) - } - it("throws if requesting instance with wrong tag") { - let swinject = Swinject { - bbind(Int.self, tagged: "Tag") & 42 - } - expect { try swinject.instance(of: Int.self) }.to(throwError()) - expect { try swinject.instance(of: Int.self, tagged: 42) }.to(throwError()) - expect { try swinject.instance(of: Int.self, tagged: "OtherTag") }.to(throwError()) - } - // TODO: Multiple dependencies - // TODO: Reuse descriptor for multiple bindings? - // TODO: Reuse binding for multiple descriptors - // TODO: Less verbose type forwading API? - } -}} - -class Person { - var age = 0 - var height = 0.0 - var name = "" -} - -struct Pet { - let owner: Person -} diff --git a/Tests/SwinjectSpec.swift b/Tests/SwinjectSpec.swift new file mode 100644 index 00000000..5494e11f --- /dev/null +++ b/Tests/SwinjectSpec.swift @@ -0,0 +1,60 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +import Quick +import Nimble +import Swinject + +class SwinjectSpec: QuickSpec { override func spec() { + describe("injection") { + context("no bindings") { + it("throws") { + let swinject = Swinject { } + expect { try swinject.instance(of: Int.self) }.to(throwError()) + } + } + context("single binding") { + var swinject: Swinject! + var fakeBinding: FakeBinding! + var fakeDescriptor: FakeDescriptor! + beforeEach { + fakeBinding = FakeBinding(0) + fakeDescriptor = FakeDescriptor() + swinject = Swinject { bbind(fakeDescriptor) & fakeBinding } + } + it("request instance from matching binding") { + fakeDescriptor.shouldMatch = { _ in true } + _ = try? swinject.instance(of: Int.self) + expect(fakeBinding.instanceRequestCount) == 1 + } + it("does not request instance from matching binding until instance is required") { + fakeDescriptor.shouldMatch = { _ in true } + expect(fakeBinding.instanceRequestCount) == 0 + } + it("only requests instance from matching binding") { + fakeDescriptor.shouldMatch = { _ in false } + _ = try? swinject.instance(of: Int.self) + expect(fakeBinding.instanceRequestCount) == 0 + } + it("returns instance produced by binding") { + fakeDescriptor.shouldMatch = { _ in true } + fakeBinding.instance = 42 + expect { try swinject.instance(of: Int.self) } == 42 + } + it("rethrows error from binding") { + fakeDescriptor.shouldMatch = { _ in true } + fakeBinding.error = TestError() + expect { try swinject.instance(of: Int.self) }.to(throwError(errorType: TestError.self)) + } + it("throws if bound type does not match requested type") { + fakeDescriptor.shouldMatch = { _ in true } + expect { try swinject.instance(of: Double.self) }.to(throwError()) + } + it("does not throw if bound type conforms to the requested type") { + fakeDescriptor.shouldMatch = { _ in true } + expect { try swinject.instance(of: CustomStringConvertible.self) }.notTo(throwError()) + } + } + } +}} diff --git a/Tests/TestModels.swift b/Tests/TestModels.swift new file mode 100644 index 00000000..f778c870 --- /dev/null +++ b/Tests/TestModels.swift @@ -0,0 +1,15 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +class Person { + var age = 0 + var height = 0.0 + var name = "" +} + +struct Pet { + let owner: Person +} + +struct TestError: Error, Equatable {} From f45cb914a29e9e3d2ff4ffb2d74ed69778c3a502 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 14 Jul 2019 17:40:49 +0200 Subject: [PATCH 022/239] Integrate swift format --- .swiftformat | 1 + .swiftlint.yml | 0 Package.swift | 17 +++++++++++------ Sources/Injector.swift | 4 ++-- Sources/InstanceBinding.swift | 2 +- Sources/Swinject.swift | 6 +++--- Sources/SwinjectTree.swift | 2 +- Sources/TypeDescriptor.swift | 4 ++-- Swinject.xcodeproj/project.pbxproj | 22 ++++++++++++++++++++++ Tests/Fakes.swift | 10 +++++----- Tests/InstanceBindingSpec.swift | 4 ++-- Tests/ProviderBindingSpec.swift | 4 ++-- Tests/SwinjectSpec.swift | 6 +++--- Tests/SwinjectTreeBuilderSpec.swift | 12 ++++++------ Tests/TypeBinderSpec.swift | 4 ++-- Tests/Utils.swift | 6 +++--- 16 files changed, 66 insertions(+), 38 deletions(-) create mode 100644 .swiftformat delete mode 100644 .swiftlint.yml diff --git a/.swiftformat b/.swiftformat new file mode 100644 index 00000000..feb75c31 --- /dev/null +++ b/.swiftformat @@ -0,0 +1 @@ +--header "\n Copyright © {created.year} Swinject Contributors. All rights reserved.\n" diff --git a/.swiftlint.yml b/.swiftlint.yml deleted file mode 100644 index e69de29b..00000000 diff --git a/Package.swift b/Package.swift index 3afda38e..07bdcbeb 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,6 @@ -// swift-tools-version:5.0 +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// import PackageDescription @@ -7,23 +9,26 @@ let package = Package( products: [ .library( name: "Swinject", - targets: ["Swinject"]) + targets: ["Swinject"] + ), ], dependencies: [ .package(url: "https://github.com/Quick/Quick", from: "2.1.0"), - .package(url: "https://github.com/Quick/Nimble", from: "8.0.1") + .package(url: "https://github.com/Quick/Nimble", from: "8.0.1"), ], targets: [ .target( name: "Swinject", dependencies: [], - path: "Sources"), + path: "Sources" + ), .testTarget( name: "SwinjectTests", dependencies: [ "Quick", "Nimble", - "Swinject" - ]) + "Swinject", + ] + ), ] ) diff --git a/Sources/Injector.swift b/Sources/Injector.swift index 9834b9cc..ca6a32ce 100644 --- a/Sources/Injector.swift +++ b/Sources/Injector.swift @@ -7,11 +7,11 @@ public protocol Injector { } public extension Injector { - func instance(of: Type.Type = Type.self) throws -> Type { + func instance(of _: Type.Type = Type.self) throws -> Type { try instance(plain(Type.self)) } - func instance(of: Type.Type = Type.self, tagged tag: Tag) throws -> Type { + func instance(of _: Type.Type = Type.self, tagged tag: Tag) throws -> Type { try instance(tagged(Type.self, with: tag)) } } diff --git a/Sources/InstanceBinding.swift b/Sources/InstanceBinding.swift index 1a51c9bd..43ff8946 100644 --- a/Sources/InstanceBinding.swift +++ b/Sources/InstanceBinding.swift @@ -12,7 +12,7 @@ public struct InstanceBinding: Binding { _instance = instance } - public func instance(using provider: Injector) throws -> Type { + public func instance(using _: Injector) throws -> Type { _instance } } diff --git a/Sources/Swinject.swift b/Sources/Swinject.swift index 331f1d56..992d49eb 100644 --- a/Sources/Swinject.swift +++ b/Sources/Swinject.swift @@ -19,13 +19,13 @@ public extension Swinject { self.init(tree: SwinjectTreeBuilder.buildFunction([builder()])) } - init(@SwinjectTreeBuilder builder: () -> Void) { + init(@SwinjectTreeBuilder _: () -> Void) { self.init(tree: SwinjectTreeBuilder.buildFunction([])) } } extension Swinject: Injector { - public func instance(_ descriptor: Descriptor) throws -> Descriptor.BaseType where Descriptor : TypeDescriptor { + public func instance(_ descriptor: Descriptor) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { guard let entry = tree.bindingEntries.first, entry.descriptor.matches(descriptor) @@ -35,7 +35,7 @@ extension Swinject: Injector { } private struct NoInjector: Injector { - func instance(_ descriptor: Descriptor) throws -> Descriptor.BaseType where Descriptor : TypeDescriptor { + func instance(_: Descriptor) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { fatalError() } } diff --git a/Sources/SwinjectTree.swift b/Sources/SwinjectTree.swift index 7e6979fd..8f5eb493 100644 --- a/Sources/SwinjectTree.swift +++ b/Sources/SwinjectTree.swift @@ -11,7 +11,7 @@ public struct SwinjectTree { @_functionBuilder public enum SwinjectTreeBuilder { - public static func buildBlock() -> Void {} + public static func buildBlock() {} public static func buildBlock(_ input: SwinjectEntry ...) -> [SwinjectEntry] { input.flatMap(unpack) diff --git a/Sources/TypeDescriptor.swift b/Sources/TypeDescriptor.swift index 71362d75..7d7f8c72 100644 --- a/Sources/TypeDescriptor.swift +++ b/Sources/TypeDescriptor.swift @@ -12,10 +12,10 @@ public protocol TypeDescriptor: AnyTypeDescriptor { struct NoTag: Equatable {} -struct Tagged: TypeDescriptor where Tag: Equatable{ +struct Tagged: TypeDescriptor where Tag: Equatable { let tag: Tag - func matches(_ other: Descriptor) -> Bool where Descriptor : TypeDescriptor { + func matches(_ other: Descriptor) -> Bool where Descriptor: TypeDescriptor { guard let other = other as? Tagged else { return false } return tag == other.tag } diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index aa70d8ec..a1150c55 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -197,6 +197,7 @@ 771BFC7522D5F83E00AFB237 /* Sources */, 771BFC7622D5F83E00AFB237 /* Frameworks */, 771BFC7722D5F83E00AFB237 /* Resources */, + CDADF33922DB831F00C5D8DB /* Run SwiftFormat */, ); buildRules = ( ); @@ -272,6 +273,27 @@ }; /* End PBXResourcesBuildPhase section */ +/* Begin PBXShellScriptBuildPhase section */ + CDADF33922DB831F00C5D8DB /* Run SwiftFormat */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + name = "Run SwiftFormat"; + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "if which swiftformat >/dev/null; then\n swiftformat .\nelse\n echo \"warning: SwiftFormat not installed, download from https://github.com/nicklockwood/SwiftFormat\"\nfi\n"; + }; +/* End PBXShellScriptBuildPhase section */ + /* Begin PBXSourcesBuildPhase section */ 771BFC6C22D5F83E00AFB237 /* Sources */ = { isa = PBXSourcesBuildPhase; diff --git a/Tests/Fakes.swift b/Tests/Fakes.swift index aa31cf3c..64edaf34 100644 --- a/Tests/Fakes.swift +++ b/Tests/Fakes.swift @@ -5,19 +5,19 @@ @testable import Swinject class FakeInjector: Injector { - func instance(_ type: Descriptor) throws -> Descriptor.BaseType where Descriptor : TypeDescriptor { + func instance(_: Descriptor) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { fatalError() } } class IntBinding: Binding { - func instance(using provider: Injector) throws -> Int { 0 } + func instance(using _: Injector) throws -> Int { 0 } } class IntDescriptor: TypeDescriptor { typealias BaseType = Int - func matches(_ other: Descriptor) -> Bool where Descriptor : TypeDescriptor { + func matches(_: Descriptor) -> Bool where Descriptor: TypeDescriptor { false } } @@ -38,7 +38,7 @@ class FakeBinding: Binding { self.instance = instance } - func instance(using provider: Injector) throws -> Type { + func instance(using _: Injector) throws -> Type { instanceRequestCount += 1 if let error = error { throw error } return instance @@ -48,7 +48,7 @@ class FakeBinding: Binding { class FakeDescriptor: TypeDescriptor { var shouldMatch: (Any) -> Bool = { _ in false } - func matches(_ other: Descriptor) -> Bool where Descriptor : TypeDescriptor { + func matches(_ other: Descriptor) -> Bool where Descriptor: TypeDescriptor { return shouldMatch(other) } } diff --git a/Tests/InstanceBindingSpec.swift b/Tests/InstanceBindingSpec.swift index 1eebfa02..3fedabc9 100644 --- a/Tests/InstanceBindingSpec.swift +++ b/Tests/InstanceBindingSpec.swift @@ -2,8 +2,8 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -import Quick import Nimble +import Quick @testable import Swinject class InstanceBindingSpec: QuickSpec { override func spec() { @@ -11,4 +11,4 @@ class InstanceBindingSpec: QuickSpec { override func spec() { let binding = instance(42) expect { try binding.instance(using: FakeInjector()) } == 42 } -}} +} } diff --git a/Tests/ProviderBindingSpec.swift b/Tests/ProviderBindingSpec.swift index 340b634a..7373620e 100644 --- a/Tests/ProviderBindingSpec.swift +++ b/Tests/ProviderBindingSpec.swift @@ -2,8 +2,8 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -import Quick import Nimble +import Quick @testable import Swinject class ProviderBindingSpec: QuickSpec { override func spec() { @@ -33,4 +33,4 @@ class ProviderBindingSpec: QuickSpec { override func spec() { let instance2 = try? binding.instance(using: FakeInjector()) expect(instance1) !== instance2 } -}} +} } diff --git a/Tests/SwinjectSpec.swift b/Tests/SwinjectSpec.swift index 5494e11f..e7b72bf4 100644 --- a/Tests/SwinjectSpec.swift +++ b/Tests/SwinjectSpec.swift @@ -2,15 +2,15 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -import Quick import Nimble +import Quick import Swinject class SwinjectSpec: QuickSpec { override func spec() { describe("injection") { context("no bindings") { it("throws") { - let swinject = Swinject { } + let swinject = Swinject {} expect { try swinject.instance(of: Int.self) }.to(throwError()) } } @@ -57,4 +57,4 @@ class SwinjectSpec: QuickSpec { override func spec() { } } } -}} +} } diff --git a/Tests/SwinjectTreeBuilderSpec.swift b/Tests/SwinjectTreeBuilderSpec.swift index d7aa7e3d..7c495d40 100644 --- a/Tests/SwinjectTreeBuilderSpec.swift +++ b/Tests/SwinjectTreeBuilderSpec.swift @@ -2,14 +2,14 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -import Quick import Nimble +import Quick @testable import Swinject class SwinjectTreeBuilderSpec: QuickSpec { override func spec() { describe("allowed syntax") { it("builds empty closure") { - let tree = makeTree { } + let tree = makeTree {} expect(tree.bindingEntries).to(beEmpty()) } it("builds closure with single entry") { @@ -23,7 +23,7 @@ class SwinjectTreeBuilderSpec: QuickSpec { override func spec() { expect(tree.bindingEntries.count) == 5 } it("builds closure with if statement") { - let tree = makeTree { + let tree = makeTree { if true { DummyBindingEntry() } } expect(tree.bindingEntries.count) == 1 @@ -36,7 +36,7 @@ class SwinjectTreeBuilderSpec: QuickSpec { override func spec() { } it("builds closure with if else statement") { let tree = makeTree { - if false { } else { DummyBindingEntry(); DummyBindingEntry() } + if false {} else { DummyBindingEntry(); DummyBindingEntry() } } expect(tree.bindingEntries.count) == 2 } @@ -52,7 +52,7 @@ class SwinjectTreeBuilderSpec: QuickSpec { override func spec() { expect(tree.bindingEntries.count) == 3 } } -}} +} } // TODO: Return SwinjectTree directly from builder once full support for @functionBuilder is available func makeTree(@SwinjectTreeBuilder builder: () -> [SwinjectEntry]) -> SwinjectTree { @@ -63,6 +63,6 @@ func makeTree(@SwinjectTreeBuilder builder: () -> SwinjectEntry) -> SwinjectTree SwinjectTreeBuilder.buildFunction([builder()]) } -func makeTree(@SwinjectTreeBuilder builder: () -> Void) -> SwinjectTree { +func makeTree(@SwinjectTreeBuilder _: () -> Void) -> SwinjectTree { SwinjectTreeBuilder.buildFunction([]) } diff --git a/Tests/TypeBinderSpec.swift b/Tests/TypeBinderSpec.swift index ca466d2f..39e1440b 100644 --- a/Tests/TypeBinderSpec.swift +++ b/Tests/TypeBinderSpec.swift @@ -2,8 +2,8 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -import Quick import Nimble +import Quick @testable import Swinject class TypeBinderSpec: QuickSpec { override func spec() { @@ -56,4 +56,4 @@ class TypeBinderSpec: QuickSpec { override func spec() { expect(entry.binding is InstanceBinding).to(beTrue()) } } -}} +} } diff --git a/Tests/Utils.swift b/Tests/Utils.swift index 692f3ab8..5e9ced85 100644 --- a/Tests/Utils.swift +++ b/Tests/Utils.swift @@ -2,10 +2,10 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -import protocol Swinject.TypeDescriptor -import struct Swinject.TypeBinder -import struct Swinject.ProviderBinding import func Swinject.bind +import struct Swinject.ProviderBinding +import struct Swinject.TypeBinder +import protocol Swinject.TypeDescriptor // Original Swinject functions conflict with QuickSpec's instance methods func bbind(_: Type.Type) -> TypeBinder { From 9fb96eb08791ba0cc68a9653fccf4a708275a3dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 14 Jul 2019 17:57:26 +0200 Subject: [PATCH 023/239] Integrate sourcery --- .sourcery.yml | 6 ++ Swinject.xcodeproj/project.pbxproj | 33 ++++++++ Templates/AutoMockable.stencil | 120 +++++++++++++++++++++++++++++ Tests/GeneratedCode.swift | 13 ++++ 4 files changed, 172 insertions(+) create mode 100644 .sourcery.yml create mode 100644 Templates/AutoMockable.stencil create mode 100644 Tests/GeneratedCode.swift diff --git a/.sourcery.yml b/.sourcery.yml new file mode 100644 index 00000000..c4f5cc14 --- /dev/null +++ b/.sourcery.yml @@ -0,0 +1,6 @@ +sources: + - Sources +templates: + - Templates +output: + Tests/GeneratedCode.swift diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index a1150c55..7fc46508 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -19,6 +19,7 @@ CDADF33322DB4C1800C5D8DB /* InstanceBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDADF33122DB4C1200C5D8DB /* InstanceBindingSpec.swift */; }; CDADF33522DB521400C5D8DB /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDADF33422DB521400C5D8DB /* SwinjectModule.swift */; }; CDADF33722DB753800C5D8DB /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDADF33622DB753800C5D8DB /* TestModels.swift */; }; + CDADF34022DB883A00C5D8DB /* GeneratedCode.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDADF33F22DB883A00C5D8DB /* GeneratedCode.swift */; }; CDD8380322DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380222DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift */; }; CDD8380522DA307F003E9909 /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380422DA307F003E9909 /* TypeBinder.swift */; }; CDD8380722DA30C6003E9909 /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380622DA30C6003E9909 /* TypeDescriptor.swift */; }; @@ -58,6 +59,8 @@ CDADF33122DB4C1200C5D8DB /* InstanceBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceBindingSpec.swift; sourceTree = ""; }; CDADF33422DB521400C5D8DB /* SwinjectModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectModule.swift; sourceTree = ""; }; CDADF33622DB753800C5D8DB /* TestModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestModels.swift; sourceTree = ""; }; + CDADF33E22DB881D00C5D8DB /* AutoMockable.stencil */ = {isa = PBXFileReference; lastKnownFileType = text; path = AutoMockable.stencil; sourceTree = ""; }; + CDADF33F22DB883A00C5D8DB /* GeneratedCode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeneratedCode.swift; sourceTree = ""; }; CDD8380222DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTreeBuilderSpec.swift; sourceTree = ""; }; CDD8380422DA307F003E9909 /* TypeBinder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinder.swift; sourceTree = ""; }; CDD8380622DA30C6003E9909 /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; @@ -97,6 +100,7 @@ children = ( 771BFC7222D5F83E00AFB237 /* Sources */, 771BFC7D22D5F83E00AFB237 /* Tests */, + CDADF33B22DB878C00C5D8DB /* Templates */, 771BFC7122D5F83E00AFB237 /* Products */, 771BFC8A22D5FAAE00AFB237 /* Frameworks */, ); @@ -134,6 +138,7 @@ 771BFC7D22D5F83E00AFB237 /* Tests */ = { isa = PBXGroup; children = ( + CDADF33F22DB883A00C5D8DB /* GeneratedCode.swift */, 771BFC8022D5F83E00AFB237 /* Info.plist */, CDD8380222DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift */, CDD8380822DA31C6003E9909 /* TypeBinderSpec.swift */, @@ -156,6 +161,14 @@ name = Frameworks; sourceTree = ""; }; + CDADF33B22DB878C00C5D8DB /* Templates */ = { + isa = PBXGroup; + children = ( + CDADF33E22DB881D00C5D8DB /* AutoMockable.stencil */, + ); + path = Templates; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ @@ -194,6 +207,7 @@ isa = PBXNativeTarget; buildConfigurationList = 771BFC8722D5F83E00AFB237 /* Build configuration list for PBXNativeTarget "SwinjectTests-OSX" */; buildPhases = ( + CDADF33A22DB866900C5D8DB /* Run Sourcery */, 771BFC7522D5F83E00AFB237 /* Sources */, 771BFC7622D5F83E00AFB237 /* Frameworks */, 771BFC7722D5F83E00AFB237 /* Resources */, @@ -292,6 +306,24 @@ shellPath = /bin/sh; shellScript = "if which swiftformat >/dev/null; then\n swiftformat .\nelse\n echo \"warning: SwiftFormat not installed, download from https://github.com/nicklockwood/SwiftFormat\"\nfi\n"; }; + CDADF33A22DB866900C5D8DB /* Run Sourcery */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + name = "Run Sourcery"; + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "sourcery\n"; + }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ @@ -319,6 +351,7 @@ files = ( CDD8381F22DA4F6F003E9909 /* Utils.swift in Sources */, CDD8381B22DA4CBE003E9909 /* SwinjectSpec.swift in Sources */, + CDADF34022DB883A00C5D8DB /* GeneratedCode.swift in Sources */, CDD8380A22DA31D9003E9909 /* TypeBinderSpec.swift in Sources */, CD85AF1222DA5A8F00A8B7CA /* Fakes.swift in Sources */, CDADF33322DB4C1800C5D8DB /* InstanceBindingSpec.swift in Sources */, diff --git a/Templates/AutoMockable.stencil b/Templates/AutoMockable.stencil new file mode 100644 index 00000000..7b6d6dd0 --- /dev/null +++ b/Templates/AutoMockable.stencil @@ -0,0 +1,120 @@ +// swiftlint:disable line_length +// swiftlint:disable variable_name + +import Foundation +#if os(iOS) || os(tvOS) || os(watchOS) +import UIKit +#elseif os(OSX) +import AppKit +#endif + +{% macro swiftifyMethodName name %}{{ name | replace:"(","_" | replace:")","" | replace:":","_" | replace:"`","" | snakeToCamelCase | lowerFirstWord }}{% endmacro %} + +{% macro methodThrowableErrorDeclaration method %} + var {% call swiftifyMethodName method.selectorName %}ThrowableError: Error? +{% endmacro %} + +{% macro methodThrowableErrorUsage method %} + if let error = {% call swiftifyMethodName method.selectorName %}ThrowableError { + throw error + } +{% endmacro %} + +{% macro methodReceivedParameters method %} + {%if method.parameters.count == 1 %} + {% call swiftifyMethodName method.selectorName %}Received{% for param in method.parameters %}{{ param.name|upperFirstLetter }} = {{ param.name }}{% endfor %} + {% call swiftifyMethodName method.selectorName %}ReceivedInvocations.append({% for param in method.parameters %}{{ param.name }}){% endfor %} + {% else %} + {% if not method.parameters.count == 0 %} + {% call swiftifyMethodName method.selectorName %}ReceivedArguments = ({% for param in method.parameters %}{{ param.name }}: {{ param.name }}{% if not forloop.last%}, {% endif %}{% endfor %}) + {% call swiftifyMethodName method.selectorName %}ReceivedInvocations.append(({% for param in method.parameters %}{{ param.name }}: {{ param.name }}{% if not forloop.last%}, {% endif %}{% endfor %})) + {% endif %} + {% endif %} +{% endmacro %} + +{% macro methodClosureName method %}{% call swiftifyMethodName method.selectorName %}Closure{% endmacro %} + +{% macro closureReturnTypeName method %}{% if method.isOptionalReturnType %}{{ method.unwrappedReturnTypeName }}?{% else %}{{ method.returnTypeName }}{% endif %}{% endmacro %} + +{% macro methodClosureDeclaration method %} + var {% call methodClosureName method %}: (({% for param in method.parameters %}{{ param.typeName }}{% if not forloop.last %}, {% endif %}{% endfor %}) {% if method.throws %}throws {% endif %}-> {% if method.isInitializer %}Void{% else %}{% call closureReturnTypeName method %}{% endif %})? +{% endmacro %} + +{% macro methodClosureCallParameters method %}{% for param in method.parameters %}{{ param.name }}{% if not forloop.last %}, {% endif %}{% endfor %}{% endmacro %} + +{% macro mockMethod method %} + //MARK: - {{ method.shortName }} + + {% if method.throws %} + {% call methodThrowableErrorDeclaration method %} + {% endif %} + {% if not method.isInitializer %} + var {% call swiftifyMethodName method.selectorName %}CallsCount = 0 + var {% call swiftifyMethodName method.selectorName %}Called: Bool { + return {% call swiftifyMethodName method.selectorName %}CallsCount > 0 + } + {% endif %} + {% if method.parameters.count == 1 %} + var {% call swiftifyMethodName method.selectorName %}Received{% for param in method.parameters %}{{ param.name|upperFirstLetter }}: {{ '(' if param.isClosure }}{{ param.typeName.unwrappedTypeName }}{{ ')' if param.isClosure }}?{% endfor %} + var {% call swiftifyMethodName method.selectorName %}ReceivedInvocations{% for param in method.parameters %}: [{{ '(' if param.isClosure }}{{ param.typeName.unwrappedTypeName }}{{ ')' if param.isClosure }}{%if param.typeName.isOptional%}?{%endif%}]{% endfor %} = [] + {% elif not method.parameters.count == 0 %} + var {% call swiftifyMethodName method.selectorName %}ReceivedArguments: ({% for param in method.parameters %}{{ param.name }}: {{ param.unwrappedTypeName if param.typeAttributes.escaping else param.typeName }}{{ ', ' if not forloop.last }}{% endfor %})? + var {% call swiftifyMethodName method.selectorName %}ReceivedInvocations: [({% for param in method.parameters %}{{ param.name }}: {{ param.unwrappedTypeName if param.typeAttributes.escaping else param.typeName }}{{ ', ' if not forloop.last }}{% endfor %})] = [] + {% endif %} + {% if not method.returnTypeName.isVoid and not method.isInitializer %} + var {% call swiftifyMethodName method.selectorName %}ReturnValue: {{ method.returnTypeName }}{{ '!' if not method.isOptionalReturnType }} + {% endif %} + {% call methodClosureDeclaration method %} + +{% if method.isInitializer %} + required {{ method.name }} { + {% call methodReceivedParameters method %} + {% call methodClosureName method %}?({% call methodClosureCallParameters method %}) + } +{% else %} + func {{ method.name }}{{ ' throws' if method.throws }}{% if not method.returnTypeName.isVoid %} -> {{ method.returnTypeName }}{% endif %} { + {% if method.throws %} + {% call methodThrowableErrorUsage method %} + {% endif %} + {% call swiftifyMethodName method.selectorName %}CallsCount += 1 + {% call methodReceivedParameters method %} + {% if method.returnTypeName.isVoid %} + {% if method.throws %}try {% endif %}{% call methodClosureName method %}?({% call methodClosureCallParameters method %}) + {% else %} + return {{ 'try ' if method.throws }}{% call methodClosureName method %}.map({ {{ 'try ' if method.throws }}$0({% call methodClosureCallParameters method %}) }) ?? {% call swiftifyMethodName method.selectorName %}ReturnValue + {% endif %} + } + +{% endif %} +{% endmacro %} + +{% macro mockOptionalVariable variable %} + var {% call mockedVariableName variable %}: {{ variable.typeName }} +{% endmacro %} + +{% macro mockNonOptionalArrayOrDictionaryVariable variable %} + var {% call mockedVariableName variable %}: {{ variable.typeName }} = {% if variable.isArray %}[]{% elif variable.isDictionary %}[:]{% endif %} +{% endmacro %} + +{% macro mockNonOptionalVariable variable %} + var {% call mockedVariableName variable %}: {{ variable.typeName }} { + get { return {% call underlyingMockedVariableName variable %} } + set(value) { {% call underlyingMockedVariableName variable %} = value } + } + var {% call underlyingMockedVariableName variable %}: {{ variable.typeName }}! +{% endmacro %} + +{% macro underlyingMockedVariableName variable %}underlying{{ variable.name|upperFirstLetter }}{% endmacro %} +{% macro mockedVariableName variable %}{{ variable.name }}{% endmacro %} + +{% for type in types.protocols where type.based.AutoMockable or type|annotated:"AutoMockable" %}{% if type.name != "AutoMockable" %} +class {{ type.name }}Mock: {{ type.name }} { +{% for variable in type.allVariables|!definedInExtension %} + {% if variable.isOptional %}{% call mockOptionalVariable variable %}{% elif variable.isArray or variable.isDictionary %}{% call mockNonOptionalArrayOrDictionaryVariable variable %}{% else %}{% call mockNonOptionalVariable variable %}{% endif %} +{% endfor %} + +{% for method in type.allMethods|!definedInExtension %} + {% call mockMethod method %} +{% endfor %} +} +{% endif %}{% endfor %} diff --git a/Tests/GeneratedCode.swift b/Tests/GeneratedCode.swift new file mode 100644 index 00000000..32699aae --- /dev/null +++ b/Tests/GeneratedCode.swift @@ -0,0 +1,13 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +// swiftlint:disable line_length +// swiftlint:disable variable_name + +import Foundation +#if os(iOS) || os(tvOS) || os(watchOS) + import UIKit +#elseif os(OSX) + import AppKit +#endif From cbf63c2125c16aca36cf73e4ca15d1828a41ffa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 14 Jul 2019 23:34:25 +0200 Subject: [PATCH 024/239] Use sourcery generated mocks --- .sourcery.yml | 2 +- Sources/Binding.swift | 1 + Sources/BindingEntry.swift | 1 + Sources/SwinjectModule.swift | 1 + Sources/TypeDescriptor.swift | 5 +- Swinject.xcodeproj/project.pbxproj | 16 +++---- Templates/AutoMockable.stencil | 7 +-- Tests/Fakes.swift | 54 ---------------------- Tests/GeneratedCode.swift | 13 ------ Tests/GeneratedMocks.swift | 71 +++++++++++++++++++++++++++++ Tests/NonGeneratedMocks.swift | 17 +++++++ Tests/SwinjectSpec.swift | 46 ++++++++++--------- Tests/SwinjectTreeBuilderSpec.swift | 20 ++++---- Tests/TypeBinderSpec.swift | 18 ++++---- 14 files changed, 147 insertions(+), 125 deletions(-) delete mode 100644 Tests/Fakes.swift delete mode 100644 Tests/GeneratedCode.swift create mode 100644 Tests/GeneratedMocks.swift create mode 100644 Tests/NonGeneratedMocks.swift diff --git a/.sourcery.yml b/.sourcery.yml index c4f5cc14..990dbeb2 100644 --- a/.sourcery.yml +++ b/.sourcery.yml @@ -3,4 +3,4 @@ sources: templates: - Templates output: - Tests/GeneratedCode.swift + Tests/GeneratedMocks.swift diff --git a/Sources/Binding.swift b/Sources/Binding.swift index bf7c9078..07516ce6 100644 --- a/Sources/Binding.swift +++ b/Sources/Binding.swift @@ -2,6 +2,7 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // +// sourcery: AutoMockable public protocol AnyBinding { func instance(using provider: Injector) throws -> Any } diff --git a/Sources/BindingEntry.swift b/Sources/BindingEntry.swift index b956e281..2e7bb493 100644 --- a/Sources/BindingEntry.swift +++ b/Sources/BindingEntry.swift @@ -2,6 +2,7 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // +// sourcery: AutoMockable protocol AnyBindingEntry: SwinjectEntry { var descriptor: AnyTypeDescriptor { get } var binding: AnyBinding { get } diff --git a/Sources/SwinjectModule.swift b/Sources/SwinjectModule.swift index 686d2e52..2e0d4043 100644 --- a/Sources/SwinjectModule.swift +++ b/Sources/SwinjectModule.swift @@ -4,4 +4,5 @@ protocol SwinjectModule {} +// sourcery: AutoMockable protocol ModuleIncludeEntry: SwinjectEntry {} diff --git a/Sources/TypeDescriptor.swift b/Sources/TypeDescriptor.swift index 7d7f8c72..f583a036 100644 --- a/Sources/TypeDescriptor.swift +++ b/Sources/TypeDescriptor.swift @@ -2,8 +2,9 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // +// sourcery: AutoMockable public protocol AnyTypeDescriptor { - func matches(_ other: Descriptor) -> Bool where Descriptor: TypeDescriptor + func matches(_ other: AnyTypeDescriptor) -> Bool } public protocol TypeDescriptor: AnyTypeDescriptor { @@ -15,7 +16,7 @@ struct NoTag: Equatable {} struct Tagged: TypeDescriptor where Tag: Equatable { let tag: Tag - func matches(_ other: Descriptor) -> Bool where Descriptor: TypeDescriptor { + func matches(_ other: AnyTypeDescriptor) -> Bool { guard let other = other as? Tagged else { return false } return tag == other.tag } diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 7fc46508..e5472809 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -13,13 +13,13 @@ 771BFC9422D600CC00AFB237 /* Quick in Frameworks */ = {isa = PBXBuildFile; productRef = 771BFC9322D600CC00AFB237 /* Quick */; }; CD85AF0E22DA57AD00A8B7CA /* ProviderBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF0D22DA57AD00A8B7CA /* ProviderBinding.swift */; }; CD85AF1022DA586D00A8B7CA /* ProviderBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF0F22DA586D00A8B7CA /* ProviderBindingSpec.swift */; }; - CD85AF1222DA5A8F00A8B7CA /* Fakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF1122DA5A8F00A8B7CA /* Fakes.swift */; }; + CD85AF1222DA5A8F00A8B7CA /* NonGeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF1122DA5A8F00A8B7CA /* NonGeneratedMocks.swift */; }; CDADF32122DB38C600C5D8DB /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDADF32022DB38C600C5D8DB /* SwinjectTree.swift */; }; CDADF32322DB416C00C5D8DB /* InstanceBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDADF32222DB416C00C5D8DB /* InstanceBinding.swift */; }; CDADF33322DB4C1800C5D8DB /* InstanceBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDADF33122DB4C1200C5D8DB /* InstanceBindingSpec.swift */; }; CDADF33522DB521400C5D8DB /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDADF33422DB521400C5D8DB /* SwinjectModule.swift */; }; CDADF33722DB753800C5D8DB /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDADF33622DB753800C5D8DB /* TestModels.swift */; }; - CDADF34022DB883A00C5D8DB /* GeneratedCode.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDADF33F22DB883A00C5D8DB /* GeneratedCode.swift */; }; + CDADF34022DB883A00C5D8DB /* GeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDADF33F22DB883A00C5D8DB /* GeneratedMocks.swift */; }; CDD8380322DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380222DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift */; }; CDD8380522DA307F003E9909 /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380422DA307F003E9909 /* TypeBinder.swift */; }; CDD8380722DA30C6003E9909 /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380622DA30C6003E9909 /* TypeDescriptor.swift */; }; @@ -53,14 +53,14 @@ 771BFC8C22D5FAAE00AFB237 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quick.framework; path = Carthage/Build/Mac/Quick.framework; sourceTree = ""; }; CD85AF0D22DA57AD00A8B7CA /* ProviderBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProviderBinding.swift; sourceTree = ""; }; CD85AF0F22DA586D00A8B7CA /* ProviderBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProviderBindingSpec.swift; sourceTree = ""; }; - CD85AF1122DA5A8F00A8B7CA /* Fakes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Fakes.swift; sourceTree = ""; }; + CD85AF1122DA5A8F00A8B7CA /* NonGeneratedMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonGeneratedMocks.swift; sourceTree = ""; }; CDADF32022DB38C600C5D8DB /* SwinjectTree.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTree.swift; sourceTree = ""; }; CDADF32222DB416C00C5D8DB /* InstanceBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceBinding.swift; sourceTree = ""; }; CDADF33122DB4C1200C5D8DB /* InstanceBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceBindingSpec.swift; sourceTree = ""; }; CDADF33422DB521400C5D8DB /* SwinjectModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectModule.swift; sourceTree = ""; }; CDADF33622DB753800C5D8DB /* TestModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestModels.swift; sourceTree = ""; }; CDADF33E22DB881D00C5D8DB /* AutoMockable.stencil */ = {isa = PBXFileReference; lastKnownFileType = text; path = AutoMockable.stencil; sourceTree = ""; }; - CDADF33F22DB883A00C5D8DB /* GeneratedCode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeneratedCode.swift; sourceTree = ""; }; + CDADF33F22DB883A00C5D8DB /* GeneratedMocks.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeneratedMocks.swift; sourceTree = ""; }; CDD8380222DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTreeBuilderSpec.swift; sourceTree = ""; }; CDD8380422DA307F003E9909 /* TypeBinder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinder.swift; sourceTree = ""; }; CDD8380622DA30C6003E9909 /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; @@ -138,7 +138,8 @@ 771BFC7D22D5F83E00AFB237 /* Tests */ = { isa = PBXGroup; children = ( - CDADF33F22DB883A00C5D8DB /* GeneratedCode.swift */, + CDADF33F22DB883A00C5D8DB /* GeneratedMocks.swift */, + CD85AF1122DA5A8F00A8B7CA /* NonGeneratedMocks.swift */, 771BFC8022D5F83E00AFB237 /* Info.plist */, CDD8380222DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift */, CDD8380822DA31C6003E9909 /* TypeBinderSpec.swift */, @@ -146,7 +147,6 @@ CDADF33122DB4C1200C5D8DB /* InstanceBindingSpec.swift */, CDD8381922DA4C9F003E9909 /* SwinjectSpec.swift */, CDD8381E22DA4F6F003E9909 /* Utils.swift */, - CD85AF1122DA5A8F00A8B7CA /* Fakes.swift */, CDADF33622DB753800C5D8DB /* TestModels.swift */, ); path = Tests; @@ -351,9 +351,9 @@ files = ( CDD8381F22DA4F6F003E9909 /* Utils.swift in Sources */, CDD8381B22DA4CBE003E9909 /* SwinjectSpec.swift in Sources */, - CDADF34022DB883A00C5D8DB /* GeneratedCode.swift in Sources */, + CDADF34022DB883A00C5D8DB /* GeneratedMocks.swift in Sources */, CDD8380A22DA31D9003E9909 /* TypeBinderSpec.swift in Sources */, - CD85AF1222DA5A8F00A8B7CA /* Fakes.swift in Sources */, + CD85AF1222DA5A8F00A8B7CA /* NonGeneratedMocks.swift in Sources */, CDADF33322DB4C1800C5D8DB /* InstanceBindingSpec.swift in Sources */, CD85AF1022DA586D00A8B7CA /* ProviderBindingSpec.swift in Sources */, CDD8380322DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift in Sources */, diff --git a/Templates/AutoMockable.stencil b/Templates/AutoMockable.stencil index 7b6d6dd0..37510cd6 100644 --- a/Templates/AutoMockable.stencil +++ b/Templates/AutoMockable.stencil @@ -1,12 +1,7 @@ // swiftlint:disable line_length // swiftlint:disable variable_name -import Foundation -#if os(iOS) || os(tvOS) || os(watchOS) -import UIKit -#elseif os(OSX) -import AppKit -#endif +@testable import Swinject {% macro swiftifyMethodName name %}{{ name | replace:"(","_" | replace:")","" | replace:":","_" | replace:"`","" | snakeToCamelCase | lowerFirstWord }}{% endmacro %} diff --git a/Tests/Fakes.swift b/Tests/Fakes.swift deleted file mode 100644 index 64edaf34..00000000 --- a/Tests/Fakes.swift +++ /dev/null @@ -1,54 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -@testable import Swinject - -class FakeInjector: Injector { - func instance(_: Descriptor) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { - fatalError() - } -} - -class IntBinding: Binding { - func instance(using _: Injector) throws -> Int { 0 } -} - -class IntDescriptor: TypeDescriptor { - typealias BaseType = Int - - func matches(_: Descriptor) -> Bool where Descriptor: TypeDescriptor { - false - } -} - -struct DummyBindingEntry: AnyBindingEntry { - var binding: AnyBinding { fatalError() } - var descriptor: AnyTypeDescriptor { fatalError() } -} - -struct DummyIncludeEntry: ModuleIncludeEntry {} - -class FakeBinding: Binding { - var instance: Type - var error: Error? - var instanceRequestCount = 0 - - init(_ instance: Type) { - self.instance = instance - } - - func instance(using _: Injector) throws -> Type { - instanceRequestCount += 1 - if let error = error { throw error } - return instance - } -} - -class FakeDescriptor: TypeDescriptor { - var shouldMatch: (Any) -> Bool = { _ in false } - - func matches(_ other: Descriptor) -> Bool where Descriptor: TypeDescriptor { - return shouldMatch(other) - } -} diff --git a/Tests/GeneratedCode.swift b/Tests/GeneratedCode.swift deleted file mode 100644 index 32699aae..00000000 --- a/Tests/GeneratedCode.swift +++ /dev/null @@ -1,13 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -// swiftlint:disable line_length -// swiftlint:disable variable_name - -import Foundation -#if os(iOS) || os(tvOS) || os(watchOS) - import UIKit -#elseif os(OSX) - import AppKit -#endif diff --git a/Tests/GeneratedMocks.swift b/Tests/GeneratedMocks.swift new file mode 100644 index 00000000..cff8ac3c --- /dev/null +++ b/Tests/GeneratedMocks.swift @@ -0,0 +1,71 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +// swiftlint:disable line_length +// swiftlint:disable variable_name + +@testable import Swinject + +class AnyBindingMock: AnyBinding { + // MARK: - instance + + var instanceUsingThrowableError: Error? + var instanceUsingCallsCount = 0 + var instanceUsingCalled: Bool { + return instanceUsingCallsCount > 0 + } + + var instanceUsingReceivedProvider: Injector? + var instanceUsingReceivedInvocations: [Injector] = [] + var instanceUsingReturnValue: Any! + var instanceUsingClosure: ((Injector) throws -> Any)? + + func instance(using provider: Injector) throws -> Any { + if let error = instanceUsingThrowableError { + throw error + } + instanceUsingCallsCount += 1 + instanceUsingReceivedProvider = provider + instanceUsingReceivedInvocations.append(provider) + return try instanceUsingClosure.map { try $0(provider) } ?? instanceUsingReturnValue + } +} + +class AnyBindingEntryMock: AnyBindingEntry { + var descriptor: AnyTypeDescriptor { + get { return underlyingDescriptor } + set(value) { underlyingDescriptor = value } + } + + var underlyingDescriptor: AnyTypeDescriptor! + var binding: AnyBinding { + get { return underlyingBinding } + set(value) { underlyingBinding = value } + } + + var underlyingBinding: AnyBinding! +} + +class AnyTypeDescriptorMock: AnyTypeDescriptor { + // MARK: - matches + + var matchesCallsCount = 0 + var matchesCalled: Bool { + return matchesCallsCount > 0 + } + + var matchesReceivedOther: AnyTypeDescriptor? + var matchesReceivedInvocations: [AnyTypeDescriptor] = [] + var matchesReturnValue: Bool! + var matchesClosure: ((AnyTypeDescriptor) -> Bool)? + + func matches(_ other: AnyTypeDescriptor) -> Bool { + matchesCallsCount += 1 + matchesReceivedOther = other + matchesReceivedInvocations.append(other) + return matchesClosure.map { $0(other) } ?? matchesReturnValue + } +} + +class ModuleIncludeEntryMock: ModuleIncludeEntry {} diff --git a/Tests/NonGeneratedMocks.swift b/Tests/NonGeneratedMocks.swift new file mode 100644 index 00000000..fccec11d --- /dev/null +++ b/Tests/NonGeneratedMocks.swift @@ -0,0 +1,17 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +@testable import Swinject + +class FakeInjector: Injector { + func instance(_: Descriptor) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { + fatalError() + } +} + +extension AnyTypeDescriptorMock: TypeDescriptor { + typealias BaseType = Any +} + +extension AnyBindingMock: Binding {} diff --git a/Tests/SwinjectSpec.swift b/Tests/SwinjectSpec.swift index e7b72bf4..024549ea 100644 --- a/Tests/SwinjectSpec.swift +++ b/Tests/SwinjectSpec.swift @@ -16,44 +16,46 @@ class SwinjectSpec: QuickSpec { override func spec() { } context("single binding") { var swinject: Swinject! - var fakeBinding: FakeBinding! - var fakeDescriptor: FakeDescriptor! + var binding = AnyBindingMock() + var descriptor = AnyTypeDescriptorMock() beforeEach { - fakeBinding = FakeBinding(0) - fakeDescriptor = FakeDescriptor() - swinject = Swinject { bbind(fakeDescriptor) & fakeBinding } + binding = AnyBindingMock() + descriptor = AnyTypeDescriptorMock() + swinject = Swinject { bbind(descriptor) & binding } } it("request instance from matching binding") { - fakeDescriptor.shouldMatch = { _ in true } - _ = try? swinject.instance(of: Int.self) - expect(fakeBinding.instanceRequestCount) == 1 + descriptor.matchesReturnValue = true + _ = try? swinject.instance(of: Any.self) + expect(binding.instanceUsingCallsCount) == 1 } it("does not request instance from matching binding until instance is required") { - fakeDescriptor.shouldMatch = { _ in true } - expect(fakeBinding.instanceRequestCount) == 0 + descriptor.matchesReturnValue = true + expect(binding.instanceUsingCallsCount) == 0 } it("only requests instance from matching binding") { - fakeDescriptor.shouldMatch = { _ in false } - _ = try? swinject.instance(of: Int.self) - expect(fakeBinding.instanceRequestCount) == 0 + descriptor.matchesReturnValue = false + _ = try? swinject.instance(of: Any.self) + expect(binding.instanceUsingCallsCount) == 0 } it("returns instance produced by binding") { - fakeDescriptor.shouldMatch = { _ in true } - fakeBinding.instance = 42 - expect { try swinject.instance(of: Int.self) } == 42 + descriptor.matchesReturnValue = true + binding.instanceUsingReturnValue = 42 + expect { try swinject.instance(of: Any.self) as? Int } == 42 } it("rethrows error from binding") { - fakeDescriptor.shouldMatch = { _ in true } - fakeBinding.error = TestError() - expect { try swinject.instance(of: Int.self) }.to(throwError(errorType: TestError.self)) + descriptor.matchesReturnValue = true + binding.instanceUsingThrowableError = TestError() + expect { try swinject.instance(of: Any.self) }.to(throwError(errorType: TestError.self)) } it("throws if bound type does not match requested type") { - fakeDescriptor.shouldMatch = { _ in true } + descriptor.matchesReturnValue = true + binding.instanceUsingReturnValue = "" expect { try swinject.instance(of: Double.self) }.to(throwError()) } it("does not throw if bound type conforms to the requested type") { - fakeDescriptor.shouldMatch = { _ in true } - expect { try swinject.instance(of: CustomStringConvertible.self) }.notTo(throwError()) + descriptor.matchesReturnValue = true + binding.instanceUsingReturnValue = 42 + expect { try swinject.instance(of: CustomStringConvertible?.self) }.notTo(throwError()) } } } diff --git a/Tests/SwinjectTreeBuilderSpec.swift b/Tests/SwinjectTreeBuilderSpec.swift index 7c495d40..2a4cdc32 100644 --- a/Tests/SwinjectTreeBuilderSpec.swift +++ b/Tests/SwinjectTreeBuilderSpec.swift @@ -13,40 +13,40 @@ class SwinjectTreeBuilderSpec: QuickSpec { override func spec() { expect(tree.bindingEntries).to(beEmpty()) } it("builds closure with single entry") { - let tree = makeTree { DummyBindingEntry() } + let tree = makeTree { AnyBindingEntryMock() } expect(tree.bindingEntries.count) == 1 } it("builds closure with multiple entries") { let tree = makeTree { - DummyBindingEntry(); DummyBindingEntry(); DummyBindingEntry(); DummyBindingEntry(); DummyBindingEntry() + AnyBindingEntryMock(); AnyBindingEntryMock(); AnyBindingEntryMock(); AnyBindingEntryMock(); AnyBindingEntryMock() } expect(tree.bindingEntries.count) == 5 } it("builds closure with if statement") { let tree = makeTree { - if true { DummyBindingEntry() } + if true { AnyBindingEntryMock() } } expect(tree.bindingEntries.count) == 1 } it("builds closure with nested if statement") { let tree = makeTree { - if true { DummyBindingEntry(); if true { DummyBindingEntry() } } + if true { AnyBindingEntryMock(); if true { AnyBindingEntryMock() } } } expect(tree.bindingEntries.count) == 2 } it("builds closure with if else statement") { let tree = makeTree { - if false {} else { DummyBindingEntry(); DummyBindingEntry() } + if false {} else { AnyBindingEntryMock(); AnyBindingEntryMock() } } expect(tree.bindingEntries.count) == 2 } it("builds closure with binding & include entries") { let tree = makeTree { - DummyIncludeEntry() - DummyIncludeEntry() - DummyBindingEntry() - DummyBindingEntry() - DummyBindingEntry() + ModuleIncludeEntryMock() + ModuleIncludeEntryMock() + AnyBindingEntryMock() + AnyBindingEntryMock() + AnyBindingEntryMock() } expect(tree.includeEntries.count) == 2 expect(tree.bindingEntries.count) == 3 diff --git a/Tests/TypeBinderSpec.swift b/Tests/TypeBinderSpec.swift index 39e1440b..36bb54a4 100644 --- a/Tests/TypeBinderSpec.swift +++ b/Tests/TypeBinderSpec.swift @@ -19,20 +19,20 @@ class TypeBinderSpec: QuickSpec { override func spec() { expect(descriptor?.tag) == "Foo" } it("descriptor is used if given as parameter") { - let descriptor = IntDescriptor() + let descriptor = AnyTypeDescriptorMock() let request = bbind(descriptor) expect(request.descriptor) === descriptor } } describe("`with` method") { it("produces entry with correct descriptor") { - let descriptor = IntDescriptor() - let entry = bbind(descriptor).with(IntBinding()) + let descriptor = AnyTypeDescriptorMock() + let entry = bbind(descriptor).with(AnyBindingMock()) expect(entry.descriptor) === descriptor } it("produces entry with correct binding") { - let binding = IntBinding() - let entry = bbind(Int.self).with(binding) + let binding = AnyBindingMock() + let entry = bbind(Any.self).with(binding) expect(entry.binding) === binding } it("produces entry if given value of descriptor type") { @@ -42,13 +42,13 @@ class TypeBinderSpec: QuickSpec { override func spec() { } describe("& operator") { it("produces entry with correct descriptor") { - let descriptor = IntDescriptor() - let entry = bbind(descriptor) & IntBinding() + let descriptor = AnyTypeDescriptorMock() + let entry = bbind(descriptor) & AnyBindingMock() expect(entry.descriptor) === descriptor } it("produces entry with correct binding") { - let binding = IntBinding() - let entry = bbind(Int.self) & binding + let binding = AnyBindingMock() + let entry = bbind(Any.self) & binding expect(entry.binding) === binding } it("produces entry provider if given value of descriptor type") { From db70b9625069b61b9778106fe79ff3332a674a77 Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Mon, 15 Jul 2019 16:29:07 +0200 Subject: [PATCH 025/239] Extend Swinject spec --- Sources/Binding.swift | 8 ++++---- Sources/Swinject.swift | 18 +++++++++--------- Tests/GeneratedMocks.swift | 10 +++++----- Tests/SwinjectSpec.swift | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 18 deletions(-) diff --git a/Sources/Binding.swift b/Sources/Binding.swift index 07516ce6..ab67b5ce 100644 --- a/Sources/Binding.swift +++ b/Sources/Binding.swift @@ -4,16 +4,16 @@ // sourcery: AutoMockable public protocol AnyBinding { - func instance(using provider: Injector) throws -> Any + func instance(using injector: Injector) throws -> Any } public protocol Binding: AnyBinding { associatedtype BoundType - func instance(using provider: Injector) throws -> BoundType + func instance(using injector: Injector) throws -> BoundType } public extension AnyBinding where Self: Binding { - func instance(using provider: Injector) throws -> Any { - try instance(using: provider) as BoundType + func instance(using injector: Injector) throws -> Any { + try instance(using: injector) as BoundType } } diff --git a/Sources/Swinject.swift b/Sources/Swinject.swift index 992d49eb..eb29d017 100644 --- a/Sources/Swinject.swift +++ b/Sources/Swinject.swift @@ -26,16 +26,16 @@ public extension Swinject { extension Swinject: Injector { public func instance(_ descriptor: Descriptor) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { - guard - let entry = tree.bindingEntries.first, - entry.descriptor.matches(descriptor) - else { throw SwinjectError() } - return try entry.binding.instance(using: NoInjector()) as? Descriptor.BaseType ?? { throw SwinjectError() }() + try instance(from: findBinding(for: descriptor)) + } + + private func findBinding(for descriptor: AnyTypeDescriptor) throws -> AnyBinding { + let entries = tree.bindingEntries.filter { $0.descriptor.matches(descriptor) } + guard entries.count == 1 else { throw SwinjectError() } + return entries[0].binding } -} -private struct NoInjector: Injector { - func instance(_: Descriptor) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { - fatalError() + private func instance(from binding: AnyBinding) throws -> Type { + try binding.instance(using: self) as? Type ?? { throw SwinjectError() }() } } diff --git a/Tests/GeneratedMocks.swift b/Tests/GeneratedMocks.swift index cff8ac3c..706ce384 100644 --- a/Tests/GeneratedMocks.swift +++ b/Tests/GeneratedMocks.swift @@ -16,19 +16,19 @@ class AnyBindingMock: AnyBinding { return instanceUsingCallsCount > 0 } - var instanceUsingReceivedProvider: Injector? + var instanceUsingReceivedInjector: Injector? var instanceUsingReceivedInvocations: [Injector] = [] var instanceUsingReturnValue: Any! var instanceUsingClosure: ((Injector) throws -> Any)? - func instance(using provider: Injector) throws -> Any { + func instance(using injector: Injector) throws -> Any { if let error = instanceUsingThrowableError { throw error } instanceUsingCallsCount += 1 - instanceUsingReceivedProvider = provider - instanceUsingReceivedInvocations.append(provider) - return try instanceUsingClosure.map { try $0(provider) } ?? instanceUsingReturnValue + instanceUsingReceivedInjector = injector + instanceUsingReceivedInvocations.append(injector) + return try instanceUsingClosure.map { try $0(injector) } ?? instanceUsingReturnValue } } diff --git a/Tests/SwinjectSpec.swift b/Tests/SwinjectSpec.swift index 024549ea..83c5f99b 100644 --- a/Tests/SwinjectSpec.swift +++ b/Tests/SwinjectSpec.swift @@ -57,6 +57,39 @@ class SwinjectSpec: QuickSpec { override func spec() { binding.instanceUsingReturnValue = 42 expect { try swinject.instance(of: CustomStringConvertible?.self) }.notTo(throwError()) } + it("passes swinject as injector") { + descriptor.matchesReturnValue = true + _ = try? swinject.instance(of: Any.self) + expect(binding.instanceUsingReceivedInjector is Swinject).to(beTrue()) + } + } + context("multipleBindings") { + var swinject: Swinject! + var bindings = [AnyBindingMock]() + var descriptors = [AnyTypeDescriptorMock]() + beforeEach { + descriptors = Array(0 ..< 3).map { _ in AnyTypeDescriptorMock() } + descriptors.forEach { $0.matchesReturnValue = false } + bindings = descriptors.map { _ in AnyBindingMock() } + swinject = Swinject { + bbind(descriptors[0]) & bindings[0] + bbind(descriptors[1]) & bindings[1] + bbind(descriptors[2]) & bindings[2] + } + } + it("throws if multiple entries match requested type") { + descriptors.forEach { $0.matchesReturnValue = true } + expect { try swinject.instance(of: Any.self) }.to(throwError()) + } + it("does not throw if single entry matches requested type") { + descriptors[1].matchesReturnValue = true + expect { try swinject.instance(of: Any.self) }.notTo(throwError()) + } + it("returns instance from matching binding") { + descriptors[1].matchesReturnValue = true + bindings[1].instanceUsingReturnValue = 42 + expect { try swinject.instance(of: Int.self) } == 42 + } } } } } From 6f3c2a2d35cda01288e40a15e3c6ed6183d51986 Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Mon, 15 Jul 2019 16:32:42 +0200 Subject: [PATCH 026/239] Restructure tests --- .sourcery.yml | 2 +- Swinject.xcodeproj/project.pbxproj | 40 +++++++++++++++---- Tests/{ => Support}/GeneratedMocks.swift | 0 Tests/{ => Support}/NonGeneratedMocks.swift | 0 Tests/{ => Support}/TestModels.swift | 0 Tests/{ => Support}/Utils.swift | 0 .../{ => UnitSpecs}/InstanceBindingSpec.swift | 0 .../{ => UnitSpecs}/ProviderBindingSpec.swift | 0 Tests/{ => UnitSpecs}/SwinjectSpec.swift | 0 .../SwinjectTreeBuilderSpec.swift | 0 Tests/{ => UnitSpecs}/TypeBinderSpec.swift | 0 11 files changed, 33 insertions(+), 9 deletions(-) rename Tests/{ => Support}/GeneratedMocks.swift (100%) rename Tests/{ => Support}/NonGeneratedMocks.swift (100%) rename Tests/{ => Support}/TestModels.swift (100%) rename Tests/{ => Support}/Utils.swift (100%) rename Tests/{ => UnitSpecs}/InstanceBindingSpec.swift (100%) rename Tests/{ => UnitSpecs}/ProviderBindingSpec.swift (100%) rename Tests/{ => UnitSpecs}/SwinjectSpec.swift (100%) rename Tests/{ => UnitSpecs}/SwinjectTreeBuilderSpec.swift (100%) rename Tests/{ => UnitSpecs}/TypeBinderSpec.swift (100%) diff --git a/.sourcery.yml b/.sourcery.yml index 990dbeb2..6a171f32 100644 --- a/.sourcery.yml +++ b/.sourcery.yml @@ -3,4 +3,4 @@ sources: templates: - Templates output: - Tests/GeneratedMocks.swift + Tests/Support/GeneratedMocks.swift diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index e5472809..2da246f8 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -138,27 +138,51 @@ 771BFC7D22D5F83E00AFB237 /* Tests */ = { isa = PBXGroup; children = ( + 77729C9822DCC623005C3281 /* ApiSpecs */, + 77729C9622DCC597005C3281 /* UnitSpecs */, + 77729C9422DCC56D005C3281 /* Support */, + 771BFC8022D5F83E00AFB237 /* Info.plist */, + ); + path = Tests; + sourceTree = ""; + }; + 771BFC8A22D5FAAE00AFB237 /* Frameworks */ = { + isa = PBXGroup; + children = ( + 771BFC8B22D5FAAE00AFB237 /* Nimble.framework */, + 771BFC8C22D5FAAE00AFB237 /* Quick.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; + 77729C9422DCC56D005C3281 /* Support */ = { + isa = PBXGroup; + children = ( + CDD8381E22DA4F6F003E9909 /* Utils.swift */, + CDADF33622DB753800C5D8DB /* TestModels.swift */, CDADF33F22DB883A00C5D8DB /* GeneratedMocks.swift */, CD85AF1122DA5A8F00A8B7CA /* NonGeneratedMocks.swift */, - 771BFC8022D5F83E00AFB237 /* Info.plist */, + ); + path = Support; + sourceTree = ""; + }; + 77729C9622DCC597005C3281 /* UnitSpecs */ = { + isa = PBXGroup; + children = ( CDD8380222DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift */, CDD8380822DA31C6003E9909 /* TypeBinderSpec.swift */, CD85AF0F22DA586D00A8B7CA /* ProviderBindingSpec.swift */, CDADF33122DB4C1200C5D8DB /* InstanceBindingSpec.swift */, CDD8381922DA4C9F003E9909 /* SwinjectSpec.swift */, - CDD8381E22DA4F6F003E9909 /* Utils.swift */, - CDADF33622DB753800C5D8DB /* TestModels.swift */, ); - path = Tests; + path = UnitSpecs; sourceTree = ""; }; - 771BFC8A22D5FAAE00AFB237 /* Frameworks */ = { + 77729C9822DCC623005C3281 /* ApiSpecs */ = { isa = PBXGroup; children = ( - 771BFC8B22D5FAAE00AFB237 /* Nimble.framework */, - 771BFC8C22D5FAAE00AFB237 /* Quick.framework */, ); - name = Frameworks; + name = ApiSpecs; sourceTree = ""; }; CDADF33B22DB878C00C5D8DB /* Templates */ = { diff --git a/Tests/GeneratedMocks.swift b/Tests/Support/GeneratedMocks.swift similarity index 100% rename from Tests/GeneratedMocks.swift rename to Tests/Support/GeneratedMocks.swift diff --git a/Tests/NonGeneratedMocks.swift b/Tests/Support/NonGeneratedMocks.swift similarity index 100% rename from Tests/NonGeneratedMocks.swift rename to Tests/Support/NonGeneratedMocks.swift diff --git a/Tests/TestModels.swift b/Tests/Support/TestModels.swift similarity index 100% rename from Tests/TestModels.swift rename to Tests/Support/TestModels.swift diff --git a/Tests/Utils.swift b/Tests/Support/Utils.swift similarity index 100% rename from Tests/Utils.swift rename to Tests/Support/Utils.swift diff --git a/Tests/InstanceBindingSpec.swift b/Tests/UnitSpecs/InstanceBindingSpec.swift similarity index 100% rename from Tests/InstanceBindingSpec.swift rename to Tests/UnitSpecs/InstanceBindingSpec.swift diff --git a/Tests/ProviderBindingSpec.swift b/Tests/UnitSpecs/ProviderBindingSpec.swift similarity index 100% rename from Tests/ProviderBindingSpec.swift rename to Tests/UnitSpecs/ProviderBindingSpec.swift diff --git a/Tests/SwinjectSpec.swift b/Tests/UnitSpecs/SwinjectSpec.swift similarity index 100% rename from Tests/SwinjectSpec.swift rename to Tests/UnitSpecs/SwinjectSpec.swift diff --git a/Tests/SwinjectTreeBuilderSpec.swift b/Tests/UnitSpecs/SwinjectTreeBuilderSpec.swift similarity index 100% rename from Tests/SwinjectTreeBuilderSpec.swift rename to Tests/UnitSpecs/SwinjectTreeBuilderSpec.swift diff --git a/Tests/TypeBinderSpec.swift b/Tests/UnitSpecs/TypeBinderSpec.swift similarity index 100% rename from Tests/TypeBinderSpec.swift rename to Tests/UnitSpecs/TypeBinderSpec.swift From 02a05f937e9ce707388599b9093c211120df765b Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Mon, 15 Jul 2019 16:40:09 +0200 Subject: [PATCH 027/239] Define Injection API --- Swinject.xcodeproj/project.pbxproj | 10 ++-- Tests/ApiSpecs/InjectionApiSpec.swift | 66 +++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 Tests/ApiSpecs/InjectionApiSpec.swift diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 2da246f8..9ab0d4e0 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -11,6 +11,7 @@ 771BFC8122D5F83E00AFB237 /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 771BFC7322D5F83E00AFB237 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; 771BFC9122D600B700AFB237 /* Nimble in Frameworks */ = {isa = PBXBuildFile; productRef = 771BFC9022D600B700AFB237 /* Nimble */; }; 771BFC9422D600CC00AFB237 /* Quick in Frameworks */ = {isa = PBXBuildFile; productRef = 771BFC9322D600CC00AFB237 /* Quick */; }; + 77729C9E22DCCA20005C3281 /* InjectionApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77729C9D22DCCA20005C3281 /* InjectionApiSpec.swift */; }; CD85AF0E22DA57AD00A8B7CA /* ProviderBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF0D22DA57AD00A8B7CA /* ProviderBinding.swift */; }; CD85AF1022DA586D00A8B7CA /* ProviderBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF0F22DA586D00A8B7CA /* ProviderBindingSpec.swift */; }; CD85AF1222DA5A8F00A8B7CA /* NonGeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF1122DA5A8F00A8B7CA /* NonGeneratedMocks.swift */; }; @@ -51,6 +52,7 @@ 771BFC8022D5F83E00AFB237 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 771BFC8B22D5FAAE00AFB237 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nimble.framework; path = Carthage/Build/Mac/Nimble.framework; sourceTree = ""; }; 771BFC8C22D5FAAE00AFB237 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quick.framework; path = Carthage/Build/Mac/Quick.framework; sourceTree = ""; }; + 77729C9D22DCCA20005C3281 /* InjectionApiSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InjectionApiSpec.swift; sourceTree = ""; }; CD85AF0D22DA57AD00A8B7CA /* ProviderBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProviderBinding.swift; sourceTree = ""; }; CD85AF0F22DA586D00A8B7CA /* ProviderBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProviderBindingSpec.swift; sourceTree = ""; }; CD85AF1122DA5A8F00A8B7CA /* NonGeneratedMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonGeneratedMocks.swift; sourceTree = ""; }; @@ -138,7 +140,7 @@ 771BFC7D22D5F83E00AFB237 /* Tests */ = { isa = PBXGroup; children = ( - 77729C9822DCC623005C3281 /* ApiSpecs */, + 77729C9C22DCCA20005C3281 /* ApiSpecs */, 77729C9622DCC597005C3281 /* UnitSpecs */, 77729C9422DCC56D005C3281 /* Support */, 771BFC8022D5F83E00AFB237 /* Info.plist */, @@ -178,11 +180,12 @@ path = UnitSpecs; sourceTree = ""; }; - 77729C9822DCC623005C3281 /* ApiSpecs */ = { + 77729C9C22DCCA20005C3281 /* ApiSpecs */ = { isa = PBXGroup; children = ( + 77729C9D22DCCA20005C3281 /* InjectionApiSpec.swift */, ); - name = ApiSpecs; + path = ApiSpecs; sourceTree = ""; }; CDADF33B22DB878C00C5D8DB /* Templates */ = { @@ -382,6 +385,7 @@ CD85AF1022DA586D00A8B7CA /* ProviderBindingSpec.swift in Sources */, CDD8380322DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift in Sources */, CDADF33722DB753800C5D8DB /* TestModels.swift in Sources */, + 77729C9E22DCCA20005C3281 /* InjectionApiSpec.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Tests/ApiSpecs/InjectionApiSpec.swift b/Tests/ApiSpecs/InjectionApiSpec.swift new file mode 100644 index 00000000..177e1fdd --- /dev/null +++ b/Tests/ApiSpecs/InjectionApiSpec.swift @@ -0,0 +1,66 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +import Nimble +import Quick +import Swinject + +class InjectionApiSpec: QuickSpec { override func spec() { + var person = Person() + beforeEach { + person = Person() + } + it("throws for empty swinject") { + let swinject = Swinject {} + expect { try swinject.instance(of: Int.self) }.to(throwError()) + } + it("returns instance if provider is bound") { + let swinject = Swinject { + bbind(Int.self).with(42) + } + expect { try swinject.instance(of: Int.self) } == 42 + } + it("can infer the requested type") { + let swinject = Swinject { + bbind(Int.self) & 42 + } + expect { try swinject.instance() as Int } == 42 + } + it("throws if providing type with missing dependency") { + let swinject = Swinject { + bbind(Pet.self) & provider { Pet(owner: try $0.instance()) } + } + expect { try swinject.instance(of: Pet.self) }.to(throwError()) + } + it("returns instance from bound dependency provider") { + let swinject = Swinject { + bbind(Pet.self) & provider { Pet(owner: try $0.instance()) } + bbind(Person.self) & instance(person) + } + expect { try swinject.instance(of: Pet.self).owner } === person + } + it("throws if multiple providers are bound") { + let swinject = Swinject { + bbind(Int.self) & 42 + bbind(Int.self) & provider { 17 + 25 } + } + expect { try swinject.instance(of: Int.self) }.to(throwError()) + } + it("throws if requesting instance with wrong tag") { + let swinject = Swinject { + bbind(Int.self, tagged: "Tag") & 42 + } + expect { try swinject.instance(of: Int.self) }.to(throwError()) + expect { try swinject.instance(of: Int.self, tagged: 42) }.to(throwError()) + expect { try swinject.instance(of: Int.self, tagged: "OtherTag") }.to(throwError()) + } + it("returns isntance with correct tag") { + let swinject = Swinject { + bbind(String.self) & "Plain" + bbind(String.self, tagged: "Tag") & "Tagged" + } + expect { try swinject.instance(of: String.self) } == "Plain" + expect { try swinject.instance(of: String.self, tagged: "Tag") } == "Tagged" + } +} } From 1609ce7867732a254b59fe5506ae7339bafa96f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Mon, 15 Jul 2019 20:59:30 +0200 Subject: [PATCH 028/239] Implement provider injection --- Sources/Injector.swift | 9 +++++ Sources/Swinject.swift | 5 +++ Tests/Support/NonGeneratedMocks.swift | 4 +++ Tests/UnitSpecs/SwinjectSpec.swift | 49 +++++++++++++++++++++++---- 4 files changed, 60 insertions(+), 7 deletions(-) diff --git a/Sources/Injector.swift b/Sources/Injector.swift index ca6a32ce..7eaa3e5e 100644 --- a/Sources/Injector.swift +++ b/Sources/Injector.swift @@ -4,6 +4,7 @@ public protocol Injector { func instance(_ descriptor: Descriptor) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor + func provider(_ descriptor: Descriptor) throws -> () throws -> Descriptor.BaseType where Descriptor: TypeDescriptor } public extension Injector { @@ -14,4 +15,12 @@ public extension Injector { func instance(of _: Type.Type = Type.self, tagged tag: Tag) throws -> Type { try instance(tagged(Type.self, with: tag)) } + + func provider(of _: Type.Type = Type.self) throws -> () throws -> Type { + try provider(plain(Type.self)) + } + + func provider(of _: Type.Type = Type.self, tagged tag: Tag) throws -> () throws -> Type { + try provider(tagged(Type.self, with: tag)) + } } diff --git a/Sources/Swinject.swift b/Sources/Swinject.swift index eb29d017..23ecf51f 100644 --- a/Sources/Swinject.swift +++ b/Sources/Swinject.swift @@ -29,6 +29,11 @@ extension Swinject: Injector { try instance(from: findBinding(for: descriptor)) } + public func provider(_ descriptor: Descriptor) throws -> () throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { + let binding = try findBinding(for: descriptor) + return { try self.instance(from: binding) } + } + private func findBinding(for descriptor: AnyTypeDescriptor) throws -> AnyBinding { let entries = tree.bindingEntries.filter { $0.descriptor.matches(descriptor) } guard entries.count == 1 else { throw SwinjectError() } diff --git a/Tests/Support/NonGeneratedMocks.swift b/Tests/Support/NonGeneratedMocks.swift index fccec11d..5d3f74b7 100644 --- a/Tests/Support/NonGeneratedMocks.swift +++ b/Tests/Support/NonGeneratedMocks.swift @@ -8,6 +8,10 @@ class FakeInjector: Injector { func instance(_: Descriptor) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { fatalError() } + + func provider(_: Descriptor) throws -> () throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { + fatalError() + } } extension AnyTypeDescriptorMock: TypeDescriptor { diff --git a/Tests/UnitSpecs/SwinjectSpec.swift b/Tests/UnitSpecs/SwinjectSpec.swift index 83c5f99b..4b97fab4 100644 --- a/Tests/UnitSpecs/SwinjectSpec.swift +++ b/Tests/UnitSpecs/SwinjectSpec.swift @@ -4,10 +4,10 @@ import Nimble import Quick -import Swinject +@testable import Swinject class SwinjectSpec: QuickSpec { override func spec() { - describe("injection") { + describe("instance injection") { context("no bindings") { it("throws") { let swinject = Swinject {} @@ -47,15 +47,15 @@ class SwinjectSpec: QuickSpec { override func spec() { binding.instanceUsingThrowableError = TestError() expect { try swinject.instance(of: Any.self) }.to(throwError(errorType: TestError.self)) } - it("throws if bound type does not match requested type") { + it("crashes if bound type does not match requested type") { descriptor.matchesReturnValue = true binding.instanceUsingReturnValue = "" - expect { try swinject.instance(of: Double.self) }.to(throwError()) + expect { _ = try swinject.instance(of: Double.self) }.to(throwError()) } - it("does not throw if bound type conforms to the requested type") { + it("does not crash if bound type conforms to the requested type") { descriptor.matchesReturnValue = true binding.instanceUsingReturnValue = 42 - expect { try swinject.instance(of: CustomStringConvertible?.self) }.notTo(throwError()) + expect { _ = try swinject.instance(of: CustomStringConvertible?.self) }.notTo(throwError()) } it("passes swinject as injector") { descriptor.matchesReturnValue = true @@ -63,7 +63,7 @@ class SwinjectSpec: QuickSpec { override func spec() { expect(binding.instanceUsingReceivedInjector is Swinject).to(beTrue()) } } - context("multipleBindings") { + context("multiple bindings") { var swinject: Swinject! var bindings = [AnyBindingMock]() var descriptors = [AnyTypeDescriptorMock]() @@ -92,4 +92,39 @@ class SwinjectSpec: QuickSpec { override func spec() { } } } + describe("provider injection") { + var swinject: Swinject! + var binding = AnyBindingMock() + var descriptor = AnyTypeDescriptorMock() + beforeEach { + binding = AnyBindingMock() + descriptor = AnyTypeDescriptorMock() + swinject = Swinject { bbind(descriptor) & binding } + } + it("does not throw if binding matches provided type") { + descriptor.matchesReturnValue = true + binding.instanceUsingReturnValue = 42 + expect { try swinject.provider(of: Int.self) }.notTo(throwError()) + } + it("throws if missing binding for provided type") { + descriptor.matchesReturnValue = false + expect { try swinject.provider(of: Int.self) }.to(throwError()) + } + it("does not request provided type until provider is called") { + descriptor.matchesReturnValue = true + binding.instanceUsingReturnValue = 42 + _ = try? swinject.provider(of: Int.self) + expect(binding.instanceUsingCallsCount) == 0 + } + it("returns instance from binding") { + descriptor.matchesReturnValue = true + binding.instanceUsingReturnValue = 42 + expect { try swinject.provider(of: Int.self)() } == 42 + } + it("rethrows binding error from provider") { + descriptor.matchesReturnValue = true + binding.instanceUsingThrowableError = TestError() + expect { try swinject.provider(of: Int.self)() }.to(throwError(errorType: TestError.self)) + } + } } } From 760272ff9018c0147328cd2f909c610db9e7fdb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Mon, 15 Jul 2019 21:20:29 +0200 Subject: [PATCH 029/239] Wrap type descriptor into binding key --- Sources/BindingEntry.swift | 8 ++++++-- Sources/Swinject.swift | 2 +- Sources/TypeBinder.swift | 6 +++--- Tests/Support/GeneratedMocks.swift | 8 ++++---- Tests/UnitSpecs/TypeBinderSpec.swift | 4 ++-- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Sources/BindingEntry.swift b/Sources/BindingEntry.swift index 2e7bb493..17e49190 100644 --- a/Sources/BindingEntry.swift +++ b/Sources/BindingEntry.swift @@ -4,12 +4,16 @@ // sourcery: AutoMockable protocol AnyBindingEntry: SwinjectEntry { - var descriptor: AnyTypeDescriptor { get } + var key: BindingKey { get } var binding: AnyBinding { get } } // TODO: Make this internal public struct BindingEntry: AnyBindingEntry { - let descriptor: AnyTypeDescriptor + let key: BindingKey let binding: AnyBinding } + +struct BindingKey { + let descriptor: AnyTypeDescriptor +} diff --git a/Sources/Swinject.swift b/Sources/Swinject.swift index 23ecf51f..c215b423 100644 --- a/Sources/Swinject.swift +++ b/Sources/Swinject.swift @@ -35,7 +35,7 @@ extension Swinject: Injector { } private func findBinding(for descriptor: AnyTypeDescriptor) throws -> AnyBinding { - let entries = tree.bindingEntries.filter { $0.descriptor.matches(descriptor) } + let entries = tree.bindingEntries.filter { $0.key.descriptor.matches(descriptor) } guard entries.count == 1 else { throw SwinjectError() } return entries[0].binding } diff --git a/Sources/TypeBinder.swift b/Sources/TypeBinder.swift index ea3ce389..b5fdaa01 100644 --- a/Sources/TypeBinder.swift +++ b/Sources/TypeBinder.swift @@ -24,11 +24,11 @@ public func bind(_ descriptor: Descriptor) -> TypeBinder(_ binding: SomeBinding) -> BindingEntry where SomeBinding: Binding, SomeBinding.BoundType == Type { - BindingEntry(descriptor: descriptor, binding: binding) + BindingEntry(key: BindingKey(descriptor: descriptor), binding: binding) } - func with(_ it: Type) -> BindingEntry { - BindingEntry(descriptor: descriptor, binding: instance(it)) + func with(_ anInstance: Type) -> BindingEntry { + with(instance(anInstance)) } } diff --git a/Tests/Support/GeneratedMocks.swift b/Tests/Support/GeneratedMocks.swift index 706ce384..4a6aa61e 100644 --- a/Tests/Support/GeneratedMocks.swift +++ b/Tests/Support/GeneratedMocks.swift @@ -33,12 +33,12 @@ class AnyBindingMock: AnyBinding { } class AnyBindingEntryMock: AnyBindingEntry { - var descriptor: AnyTypeDescriptor { - get { return underlyingDescriptor } - set(value) { underlyingDescriptor = value } + var key: BindingKey { + get { return underlyingKey } + set(value) { underlyingKey = value } } - var underlyingDescriptor: AnyTypeDescriptor! + var underlyingKey: BindingKey! var binding: AnyBinding { get { return underlyingBinding } set(value) { underlyingBinding = value } diff --git a/Tests/UnitSpecs/TypeBinderSpec.swift b/Tests/UnitSpecs/TypeBinderSpec.swift index 36bb54a4..dc6e67b1 100644 --- a/Tests/UnitSpecs/TypeBinderSpec.swift +++ b/Tests/UnitSpecs/TypeBinderSpec.swift @@ -28,7 +28,7 @@ class TypeBinderSpec: QuickSpec { override func spec() { it("produces entry with correct descriptor") { let descriptor = AnyTypeDescriptorMock() let entry = bbind(descriptor).with(AnyBindingMock()) - expect(entry.descriptor) === descriptor + expect(entry.key.descriptor) === descriptor } it("produces entry with correct binding") { let binding = AnyBindingMock() @@ -44,7 +44,7 @@ class TypeBinderSpec: QuickSpec { override func spec() { it("produces entry with correct descriptor") { let descriptor = AnyTypeDescriptorMock() let entry = bbind(descriptor) & AnyBindingMock() - expect(entry.descriptor) === descriptor + expect(entry.key.descriptor) === descriptor } it("produces entry with correct binding") { let binding = AnyBindingMock() From ecc423f6849e107a12c1220bd580380fa9ca8693 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Mon, 15 Jul 2019 21:24:39 +0200 Subject: [PATCH 030/239] Add argument type to the binding --- Sources/Binding.swift | 4 ++++ Sources/InstanceBinding.swift | 1 + Sources/ProviderBinding.swift | 1 + Tests/Support/GeneratedMocks.swift | 7 +++++++ Tests/Support/NonGeneratedMocks.swift | 4 +++- 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Sources/Binding.swift b/Sources/Binding.swift index ab67b5ce..c3b4c36c 100644 --- a/Sources/Binding.swift +++ b/Sources/Binding.swift @@ -4,15 +4,19 @@ // sourcery: AutoMockable public protocol AnyBinding { + var argumentType: Any.Type { get } func instance(using injector: Injector) throws -> Any } public protocol Binding: AnyBinding { associatedtype BoundType + associatedtype Argument func instance(using injector: Injector) throws -> BoundType } public extension AnyBinding where Self: Binding { + var argumentType: Any.Type { return Argument.self } + func instance(using injector: Injector) throws -> Any { try instance(using: injector) as BoundType } diff --git a/Sources/InstanceBinding.swift b/Sources/InstanceBinding.swift index 43ff8946..5a8ea981 100644 --- a/Sources/InstanceBinding.swift +++ b/Sources/InstanceBinding.swift @@ -5,6 +5,7 @@ // TODO: Make internal public struct InstanceBinding: Binding { public typealias BoundType = Type + public typealias Argument = Void private let _instance: Type diff --git a/Sources/ProviderBinding.swift b/Sources/ProviderBinding.swift index 9a28127a..2d8d43d0 100644 --- a/Sources/ProviderBinding.swift +++ b/Sources/ProviderBinding.swift @@ -5,6 +5,7 @@ // TODO: Make internal public struct ProviderBinding: Binding { public typealias BoundType = Type + public typealias Argument = Void private let builder: (Injector) throws -> Type diff --git a/Tests/Support/GeneratedMocks.swift b/Tests/Support/GeneratedMocks.swift index 4a6aa61e..b105f925 100644 --- a/Tests/Support/GeneratedMocks.swift +++ b/Tests/Support/GeneratedMocks.swift @@ -8,6 +8,13 @@ @testable import Swinject class AnyBindingMock: AnyBinding { + var argumentType: Any.Type { + get { return underlyingArgumentType } + set(value) { underlyingArgumentType = value } + } + + var underlyingArgumentType: Any.Type! + // MARK: - instance var instanceUsingThrowableError: Error? diff --git a/Tests/Support/NonGeneratedMocks.swift b/Tests/Support/NonGeneratedMocks.swift index 5d3f74b7..cbd68b1a 100644 --- a/Tests/Support/NonGeneratedMocks.swift +++ b/Tests/Support/NonGeneratedMocks.swift @@ -18,4 +18,6 @@ extension AnyTypeDescriptorMock: TypeDescriptor { typealias BaseType = Any } -extension AnyBindingMock: Binding {} +extension AnyBindingMock: Binding { + typealias Argument = Any +} From 72cdc67f8a5272590d23750ee41a1616f1195852 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Mon, 15 Jul 2019 21:42:24 +0200 Subject: [PATCH 031/239] Add argument type to the binding key --- Sources/Binding.swift | 3 --- Sources/BindingEntry.swift | 12 +++++++--- Sources/TypeBinder.swift | 24 ++++++++----------- Sources/TypeDescriptor.swift | 6 ++--- Tests/Support/GeneratedMocks.swift | 11 ++------- Tests/Support/NonGeneratedMocks.swift | 2 ++ Tests/Support/Utils.swift | 14 +++++++----- Tests/UnitSpecs/TypeBinderSpec.swift | 33 +++++++++++++++------------ 8 files changed, 52 insertions(+), 53 deletions(-) diff --git a/Sources/Binding.swift b/Sources/Binding.swift index c3b4c36c..f9e52b30 100644 --- a/Sources/Binding.swift +++ b/Sources/Binding.swift @@ -4,7 +4,6 @@ // sourcery: AutoMockable public protocol AnyBinding { - var argumentType: Any.Type { get } func instance(using injector: Injector) throws -> Any } @@ -15,8 +14,6 @@ public protocol Binding: AnyBinding { } public extension AnyBinding where Self: Binding { - var argumentType: Any.Type { return Argument.self } - func instance(using injector: Injector) throws -> Any { try instance(using: injector) as BoundType } diff --git a/Sources/BindingEntry.swift b/Sources/BindingEntry.swift index 17e49190..f52edc8a 100644 --- a/Sources/BindingEntry.swift +++ b/Sources/BindingEntry.swift @@ -4,16 +4,22 @@ // sourcery: AutoMockable protocol AnyBindingEntry: SwinjectEntry { - var key: BindingKey { get } + var key: AnyBindingKey { get } var binding: AnyBinding { get } } // TODO: Make this internal public struct BindingEntry: AnyBindingEntry { - let key: BindingKey + let key: AnyBindingKey let binding: AnyBinding } -struct BindingKey { +protocol AnyBindingKey { + var descriptor: AnyTypeDescriptor { get } + var argumentType: Any.Type { get } +} + +struct BindingKey: AnyBindingKey where Descriptor: TypeDescriptor { + let argumentType: Any.Type = Argument.self let descriptor: AnyTypeDescriptor } diff --git a/Sources/TypeBinder.swift b/Sources/TypeBinder.swift index b5fdaa01..69f21042 100644 --- a/Sources/TypeBinder.swift +++ b/Sources/TypeBinder.swift @@ -2,40 +2,36 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -public struct TypeBinder { - let descriptor: AnyTypeDescriptor - - init(descriptor: Descriptor) where Descriptor: TypeDescriptor, Descriptor.BaseType == Type { - self.descriptor = descriptor - } +public struct TypeBinder where Descriptor: TypeDescriptor { + let descriptor: Descriptor } -public func bind(_: Type.Type) -> TypeBinder { +public func bind(_: Type.Type) -> TypeBinder> { bind(plain(Type.self)) } -public func bind(_: Type.Type, tagged tag: Tag) -> TypeBinder where Tag: Equatable { +public func bind(_: Type.Type, tagged tag: Tag) -> TypeBinder> where Tag: Equatable { bind(tagged(Type.self, with: tag)) } -public func bind(_ descriptor: Descriptor) -> TypeBinder where Descriptor: TypeDescriptor { +public func bind(_ descriptor: Descriptor) -> TypeBinder where Descriptor: TypeDescriptor { TypeBinder(descriptor: descriptor) } public extension TypeBinder { - func with(_ binding: SomeBinding) -> BindingEntry where SomeBinding: Binding, SomeBinding.BoundType == Type { - BindingEntry(key: BindingKey(descriptor: descriptor), binding: binding) + func with(_ binding: SomeBinding) -> BindingEntry where SomeBinding: Binding, SomeBinding.BoundType == Descriptor.BaseType { + BindingEntry(key: BindingKey(descriptor: descriptor), binding: binding) } - func with(_ anInstance: Type) -> BindingEntry { + func with(_ anInstance: Descriptor.BaseType) -> BindingEntry { with(instance(anInstance)) } } -public func & (lhs: TypeBinder, rhs: SomeBinding) -> BindingEntry where SomeBinding: Binding, SomeBinding.BoundType == Type { +public func & (lhs: TypeBinder, rhs: SomeBinding) -> BindingEntry where SomeBinding: Binding, SomeBinding.BoundType == Descriptor.BaseType { lhs.with(rhs) } -public func & (lhs: TypeBinder, rhs: Type) -> BindingEntry { +public func & (lhs: TypeBinder, rhs: Descriptor.BaseType) -> BindingEntry { lhs.with(rhs) } diff --git a/Sources/TypeDescriptor.swift b/Sources/TypeDescriptor.swift index f583a036..41a394b7 100644 --- a/Sources/TypeDescriptor.swift +++ b/Sources/TypeDescriptor.swift @@ -11,12 +11,12 @@ public protocol TypeDescriptor: AnyTypeDescriptor { associatedtype BaseType } -struct NoTag: Equatable {} +public struct NoTag: Equatable {} -struct Tagged: TypeDescriptor where Tag: Equatable { +public struct Tagged: TypeDescriptor where Tag: Equatable { let tag: Tag - func matches(_ other: AnyTypeDescriptor) -> Bool { + public func matches(_ other: AnyTypeDescriptor) -> Bool { guard let other = other as? Tagged else { return false } return tag == other.tag } diff --git a/Tests/Support/GeneratedMocks.swift b/Tests/Support/GeneratedMocks.swift index b105f925..74474c02 100644 --- a/Tests/Support/GeneratedMocks.swift +++ b/Tests/Support/GeneratedMocks.swift @@ -8,13 +8,6 @@ @testable import Swinject class AnyBindingMock: AnyBinding { - var argumentType: Any.Type { - get { return underlyingArgumentType } - set(value) { underlyingArgumentType = value } - } - - var underlyingArgumentType: Any.Type! - // MARK: - instance var instanceUsingThrowableError: Error? @@ -40,12 +33,12 @@ class AnyBindingMock: AnyBinding { } class AnyBindingEntryMock: AnyBindingEntry { - var key: BindingKey { + var key: AnyBindingKey { get { return underlyingKey } set(value) { underlyingKey = value } } - var underlyingKey: BindingKey! + var underlyingKey: AnyBindingKey! var binding: AnyBinding { get { return underlyingBinding } set(value) { underlyingBinding = value } diff --git a/Tests/Support/NonGeneratedMocks.swift b/Tests/Support/NonGeneratedMocks.swift index cbd68b1a..2320c326 100644 --- a/Tests/Support/NonGeneratedMocks.swift +++ b/Tests/Support/NonGeneratedMocks.swift @@ -21,3 +21,5 @@ extension AnyTypeDescriptorMock: TypeDescriptor { extension AnyBindingMock: Binding { typealias Argument = Any } + +class DummyBinding: Binding {} diff --git a/Tests/Support/Utils.swift b/Tests/Support/Utils.swift index 5e9ced85..dc2a42e2 100644 --- a/Tests/Support/Utils.swift +++ b/Tests/Support/Utils.swift @@ -3,19 +3,21 @@ // import func Swinject.bind +import struct Swinject.NoTag import struct Swinject.ProviderBinding +import struct Swinject.Tagged import struct Swinject.TypeBinder import protocol Swinject.TypeDescriptor // Original Swinject functions conflict with QuickSpec's instance methods -func bbind(_: Type.Type) -> TypeBinder { - Swinject.bind(Type.self) +func bbind(_: Type.Type) -> TypeBinder> { + bind(Type.self) } -func bbind(_: Type.Type, tagged tag: Tag) -> TypeBinder where Tag: Equatable { - Swinject.bind(Type.self, tagged: tag) +func bbind(_: Type.Type, tagged tag: Tag) -> TypeBinder> where Tag: Equatable { + bind(Type.self, tagged: tag) } -func bbind(_ descriptor: Descriptor) -> TypeBinder where Descriptor: TypeDescriptor { - Swinject.bind(descriptor) +func bbind(_ descriptor: Descriptor) -> TypeBinder where Descriptor: TypeDescriptor { + bind(descriptor) } diff --git a/Tests/UnitSpecs/TypeBinderSpec.swift b/Tests/UnitSpecs/TypeBinderSpec.swift index dc6e67b1..44e1d68c 100644 --- a/Tests/UnitSpecs/TypeBinderSpec.swift +++ b/Tests/UnitSpecs/TypeBinderSpec.swift @@ -7,31 +7,32 @@ import Quick @testable import Swinject class TypeBinderSpec: QuickSpec { override func spec() { + var descriptor = AnyTypeDescriptorMock() + var binding = AnyBindingMock() + beforeEach { + descriptor = AnyTypeDescriptorMock() + binding = AnyBindingMock() + } describe("bind") { - it("descriptor is correct for simple type") { - let request = bbind(Int.self) - let descriptor = request.descriptor as? Tagged - expect(descriptor).notTo(beNil()) - } it("descriptor has correct tag for tagged type") { - let request = bbind(Int.self, tagged: "Foo") - let descriptor = request.descriptor as? Tagged - expect(descriptor?.tag) == "Foo" + let descriptor = bbind(Int.self, tagged: "Foo").descriptor + expect(descriptor.tag) == "Foo" } it("descriptor is used if given as parameter") { - let descriptor = AnyTypeDescriptorMock() let request = bbind(descriptor) expect(request.descriptor) === descriptor } } describe("`with` method") { it("produces entry with correct descriptor") { - let descriptor = AnyTypeDescriptorMock() - let entry = bbind(descriptor).with(AnyBindingMock()) + let entry = bbind(descriptor).with(binding) expect(entry.key.descriptor) === descriptor } + it("produces entry with correct argument type") { + let entry = bbind(Any.self).with(DummyBinding()) + expect(entry.key.argumentType is Int.Type).to(beTrue()) + } it("produces entry with correct binding") { - let binding = AnyBindingMock() let entry = bbind(Any.self).with(binding) expect(entry.binding) === binding } @@ -42,12 +43,14 @@ class TypeBinderSpec: QuickSpec { override func spec() { } describe("& operator") { it("produces entry with correct descriptor") { - let descriptor = AnyTypeDescriptorMock() - let entry = bbind(descriptor) & AnyBindingMock() + let entry = bbind(descriptor) & binding expect(entry.key.descriptor) === descriptor } + it("produces entry with correct argument type") { + let entry = bbind(Any.self) & DummyBinding() + expect(entry.key.argumentType is Int.Type).to(beTrue()) + } it("produces entry with correct binding") { - let binding = AnyBindingMock() let entry = bbind(Any.self) & binding expect(entry.binding) === binding } From 6b170d5ce9cad444d230563e55909e26de1838da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Mon, 15 Jul 2019 22:23:44 +0200 Subject: [PATCH 032/239] Extend injector interface --- Sources/BindingEntry.swift | 7 ++++++- Sources/Injector.swift | 12 ++++++++++-- Sources/Swinject.swift | 8 ++++---- Tests/Support/NonGeneratedMocks.swift | 6 +++--- Tests/UnitSpecs/InstanceBindingSpec.swift | 2 +- Tests/UnitSpecs/ProviderBindingSpec.swift | 10 +++++----- 6 files changed, 29 insertions(+), 16 deletions(-) diff --git a/Sources/BindingEntry.swift b/Sources/BindingEntry.swift index f52edc8a..112d651e 100644 --- a/Sources/BindingEntry.swift +++ b/Sources/BindingEntry.swift @@ -19,7 +19,12 @@ protocol AnyBindingKey { var argumentType: Any.Type { get } } -struct BindingKey: AnyBindingKey where Descriptor: TypeDescriptor { +public struct BindingKey: AnyBindingKey where Descriptor: TypeDescriptor { let argumentType: Any.Type = Argument.self let descriptor: AnyTypeDescriptor } + +public struct BindingRequest where Descriptor: TypeDescriptor { + let key: BindingKey + let argument: Argument +} diff --git a/Sources/Injector.swift b/Sources/Injector.swift index 7eaa3e5e..403aa5fb 100644 --- a/Sources/Injector.swift +++ b/Sources/Injector.swift @@ -3,11 +3,15 @@ // public protocol Injector { - func instance(_ descriptor: Descriptor) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor - func provider(_ descriptor: Descriptor) throws -> () throws -> Descriptor.BaseType where Descriptor: TypeDescriptor + func instance(for request: BindingRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor + func provider(for request: BindingRequest) throws -> () throws -> Descriptor.BaseType where Descriptor: TypeDescriptor } public extension Injector { + func instance(_ descriptor: Descriptor) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { + try instance(for: BindingRequest(key: BindingKey(descriptor: descriptor), argument: ())) + } + func instance(of _: Type.Type = Type.self) throws -> Type { try instance(plain(Type.self)) } @@ -16,6 +20,10 @@ public extension Injector { try instance(tagged(Type.self, with: tag)) } + func provider(_ descriptor: Descriptor) throws -> () throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { + try provider(for: BindingRequest(key: BindingKey(descriptor: descriptor), argument: ())) + } + func provider(of _: Type.Type = Type.self) throws -> () throws -> Type { try provider(plain(Type.self)) } diff --git a/Sources/Swinject.swift b/Sources/Swinject.swift index c215b423..587d2ec5 100644 --- a/Sources/Swinject.swift +++ b/Sources/Swinject.swift @@ -25,12 +25,12 @@ public extension Swinject { } extension Swinject: Injector { - public func instance(_ descriptor: Descriptor) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { - try instance(from: findBinding(for: descriptor)) + public func instance(for request: BindingRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { + try instance(from: findBinding(for: request.key.descriptor)) } - public func provider(_ descriptor: Descriptor) throws -> () throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { - let binding = try findBinding(for: descriptor) + public func provider(for request: BindingRequest) throws -> () throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { + let binding = try findBinding(for: request.key.descriptor) return { try self.instance(from: binding) } } diff --git a/Tests/Support/NonGeneratedMocks.swift b/Tests/Support/NonGeneratedMocks.swift index 2320c326..20e816b3 100644 --- a/Tests/Support/NonGeneratedMocks.swift +++ b/Tests/Support/NonGeneratedMocks.swift @@ -4,12 +4,12 @@ @testable import Swinject -class FakeInjector: Injector { - func instance(_: Descriptor) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { +class DummyInjector: Injector { + func instance(for _: BindingRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { fatalError() } - func provider(_: Descriptor) throws -> () throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { + func provider(for _: BindingRequest) throws -> () throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { fatalError() } } diff --git a/Tests/UnitSpecs/InstanceBindingSpec.swift b/Tests/UnitSpecs/InstanceBindingSpec.swift index 3fedabc9..4e0e1646 100644 --- a/Tests/UnitSpecs/InstanceBindingSpec.swift +++ b/Tests/UnitSpecs/InstanceBindingSpec.swift @@ -9,6 +9,6 @@ import Quick class InstanceBindingSpec: QuickSpec { override func spec() { it("returns given instance") { let binding = instance(42) - expect { try binding.instance(using: FakeInjector()) } == 42 + expect { try binding.instance(using: DummyInjector()) } == 42 } } } diff --git a/Tests/UnitSpecs/ProviderBindingSpec.swift b/Tests/UnitSpecs/ProviderBindingSpec.swift index 7373620e..24dc5d42 100644 --- a/Tests/UnitSpecs/ProviderBindingSpec.swift +++ b/Tests/UnitSpecs/ProviderBindingSpec.swift @@ -9,7 +9,7 @@ import Quick class ProviderBindingSpec: QuickSpec { override func spec() { it("returns instance made by provider method") { let binding = provider { 42 } - expect { try binding.instance(using: FakeInjector()) } == 42 + expect { try binding.instance(using: DummyInjector()) } == 42 } it("does not call builder until instance is requested") { var called = false @@ -18,19 +18,19 @@ class ProviderBindingSpec: QuickSpec { override func spec() { } it("calls builder with given provider") { var passedProvider: Injector? - let fake = FakeInjector() + let fake = DummyInjector() let binding = provider { passedProvider = $0 } _ = try? binding.instance(using: fake) expect(passedProvider) === fake } it("rethrows error from builder") { let binding = provider { throw SwinjectError() } - expect { try binding.instance(using: FakeInjector()) }.to(throwError()) + expect { try binding.instance(using: DummyInjector()) }.to(throwError()) } it("does not reuse instance") { let binding = provider { Person() } - let instance1 = try? binding.instance(using: FakeInjector()) - let instance2 = try? binding.instance(using: FakeInjector()) + let instance1 = try? binding.instance(using: DummyInjector()) + let instance2 = try? binding.instance(using: DummyInjector()) expect(instance1) !== instance2 } } } From 3e4e9a756b79e71377d618404b752c116982b362 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Mon, 15 Jul 2019 23:18:11 +0200 Subject: [PATCH 033/239] Implement binding key matching --- Sources/BindingEntry.swift | 15 --------- Sources/BindingKey.swift | 20 ++++++++++++ Sources/BindingRequest.swift | 8 +++++ Sources/Injector.swift | 2 ++ Swinject.xcodeproj/project.pbxproj | 12 +++++++ Tests/Support/GeneratedMocks.swift | 34 ++++++++++++++++++++ Tests/UnitSpecs/BindingKeySpec.swift | 48 ++++++++++++++++++++++++++++ 7 files changed, 124 insertions(+), 15 deletions(-) create mode 100644 Sources/BindingKey.swift create mode 100644 Sources/BindingRequest.swift create mode 100644 Tests/UnitSpecs/BindingKeySpec.swift diff --git a/Sources/BindingEntry.swift b/Sources/BindingEntry.swift index 112d651e..116bb4fe 100644 --- a/Sources/BindingEntry.swift +++ b/Sources/BindingEntry.swift @@ -13,18 +13,3 @@ public struct BindingEntry: AnyBindingEntry { let key: AnyBindingKey let binding: AnyBinding } - -protocol AnyBindingKey { - var descriptor: AnyTypeDescriptor { get } - var argumentType: Any.Type { get } -} - -public struct BindingKey: AnyBindingKey where Descriptor: TypeDescriptor { - let argumentType: Any.Type = Argument.self - let descriptor: AnyTypeDescriptor -} - -public struct BindingRequest where Descriptor: TypeDescriptor { - let key: BindingKey - let argument: Argument -} diff --git a/Sources/BindingKey.swift b/Sources/BindingKey.swift new file mode 100644 index 00000000..a95349b1 --- /dev/null +++ b/Sources/BindingKey.swift @@ -0,0 +1,20 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +// sourcery: AutoMockable +protocol AnyBindingKey { + var descriptor: AnyTypeDescriptor { get } + var argumentType: Any.Type { get } + + func matches(_ other: AnyBindingKey) -> Bool +} + +public struct BindingKey: AnyBindingKey where Descriptor: TypeDescriptor { + let argumentType: Any.Type = Argument.self + let descriptor: AnyTypeDescriptor + + func matches(_ other: AnyBindingKey) -> Bool { + descriptor.matches(other.descriptor) && argumentType == other.argumentType + } +} diff --git a/Sources/BindingRequest.swift b/Sources/BindingRequest.swift new file mode 100644 index 00000000..5e53d81b --- /dev/null +++ b/Sources/BindingRequest.swift @@ -0,0 +1,8 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +public struct BindingRequest where Descriptor: TypeDescriptor { + let key: BindingKey + let argument: Argument +} diff --git a/Sources/Injector.swift b/Sources/Injector.swift index 403aa5fb..7849ec52 100644 --- a/Sources/Injector.swift +++ b/Sources/Injector.swift @@ -4,6 +4,8 @@ public protocol Injector { func instance(for request: BindingRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor + + // TODO: Move this to extension? func provider(for request: BindingRequest) throws -> () throws -> Descriptor.BaseType where Descriptor: TypeDescriptor } diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 9ab0d4e0..07ce2a00 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -12,6 +12,9 @@ 771BFC9122D600B700AFB237 /* Nimble in Frameworks */ = {isa = PBXBuildFile; productRef = 771BFC9022D600B700AFB237 /* Nimble */; }; 771BFC9422D600CC00AFB237 /* Quick in Frameworks */ = {isa = PBXBuildFile; productRef = 771BFC9322D600CC00AFB237 /* Quick */; }; 77729C9E22DCCA20005C3281 /* InjectionApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77729C9D22DCCA20005C3281 /* InjectionApiSpec.swift */; }; + CD6DE53522DD1C7300532D08 /* BindingKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53322DD1C6800532D08 /* BindingKeySpec.swift */; }; + CD6DE53722DD1CE900532D08 /* BindingKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53622DD1CE900532D08 /* BindingKey.swift */; }; + CD6DE53922DD1D0A00532D08 /* BindingRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53822DD1D0A00532D08 /* BindingRequest.swift */; }; CD85AF0E22DA57AD00A8B7CA /* ProviderBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF0D22DA57AD00A8B7CA /* ProviderBinding.swift */; }; CD85AF1022DA586D00A8B7CA /* ProviderBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF0F22DA586D00A8B7CA /* ProviderBindingSpec.swift */; }; CD85AF1222DA5A8F00A8B7CA /* NonGeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF1122DA5A8F00A8B7CA /* NonGeneratedMocks.swift */; }; @@ -53,6 +56,9 @@ 771BFC8B22D5FAAE00AFB237 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nimble.framework; path = Carthage/Build/Mac/Nimble.framework; sourceTree = ""; }; 771BFC8C22D5FAAE00AFB237 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quick.framework; path = Carthage/Build/Mac/Quick.framework; sourceTree = ""; }; 77729C9D22DCCA20005C3281 /* InjectionApiSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InjectionApiSpec.swift; sourceTree = ""; }; + CD6DE53322DD1C6800532D08 /* BindingKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingKeySpec.swift; sourceTree = ""; }; + CD6DE53622DD1CE900532D08 /* BindingKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingKey.swift; sourceTree = ""; }; + CD6DE53822DD1D0A00532D08 /* BindingRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingRequest.swift; sourceTree = ""; }; CD85AF0D22DA57AD00A8B7CA /* ProviderBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProviderBinding.swift; sourceTree = ""; }; CD85AF0F22DA586D00A8B7CA /* ProviderBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProviderBindingSpec.swift; sourceTree = ""; }; CD85AF1122DA5A8F00A8B7CA /* NonGeneratedMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonGeneratedMocks.swift; sourceTree = ""; }; @@ -130,6 +136,8 @@ CDADF32222DB416C00C5D8DB /* InstanceBinding.swift */, CDD8380F22DA429F003E9909 /* Injector.swift */, CDD8380D22DA3B0D003E9909 /* BindingEntry.swift */, + CD6DE53622DD1CE900532D08 /* BindingKey.swift */, + CD6DE53822DD1D0A00532D08 /* BindingRequest.swift */, CDD8381522DA4B55003E9909 /* Swinject.swift */, CDD8381C22DA4E02003E9909 /* SwinjectError.swift */, CDADF33422DB521400C5D8DB /* SwinjectModule.swift */, @@ -176,6 +184,7 @@ CD85AF0F22DA586D00A8B7CA /* ProviderBindingSpec.swift */, CDADF33122DB4C1200C5D8DB /* InstanceBindingSpec.swift */, CDD8381922DA4C9F003E9909 /* SwinjectSpec.swift */, + CD6DE53322DD1C6800532D08 /* BindingKeySpec.swift */, ); path = UnitSpecs; sourceTree = ""; @@ -361,6 +370,8 @@ CDD8380C22DA3AD8003E9909 /* Binding.swift in Sources */, CDADF33522DB521400C5D8DB /* SwinjectModule.swift in Sources */, CDD8381022DA429F003E9909 /* Injector.swift in Sources */, + CD6DE53722DD1CE900532D08 /* BindingKey.swift in Sources */, + CD6DE53922DD1D0A00532D08 /* BindingRequest.swift in Sources */, CDADF32322DB416C00C5D8DB /* InstanceBinding.swift in Sources */, CDADF32122DB38C600C5D8DB /* SwinjectTree.swift in Sources */, CDD8381D22DA4E02003E9909 /* SwinjectError.swift in Sources */, @@ -384,6 +395,7 @@ CDADF33322DB4C1800C5D8DB /* InstanceBindingSpec.swift in Sources */, CD85AF1022DA586D00A8B7CA /* ProviderBindingSpec.swift in Sources */, CDD8380322DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift in Sources */, + CD6DE53522DD1C7300532D08 /* BindingKeySpec.swift in Sources */, CDADF33722DB753800C5D8DB /* TestModels.swift in Sources */, 77729C9E22DCCA20005C3281 /* InjectionApiSpec.swift in Sources */, ); diff --git a/Tests/Support/GeneratedMocks.swift b/Tests/Support/GeneratedMocks.swift index 74474c02..3c10aa6e 100644 --- a/Tests/Support/GeneratedMocks.swift +++ b/Tests/Support/GeneratedMocks.swift @@ -47,6 +47,40 @@ class AnyBindingEntryMock: AnyBindingEntry { var underlyingBinding: AnyBinding! } +class AnyBindingKeyMock: AnyBindingKey { + var descriptor: AnyTypeDescriptor { + get { return underlyingDescriptor } + set(value) { underlyingDescriptor = value } + } + + var underlyingDescriptor: AnyTypeDescriptor! + var argumentType: Any.Type { + get { return underlyingArgumentType } + set(value) { underlyingArgumentType = value } + } + + var underlyingArgumentType: Any.Type! + + // MARK: - matches + + var matchesCallsCount = 0 + var matchesCalled: Bool { + return matchesCallsCount > 0 + } + + var matchesReceivedOther: AnyBindingKey? + var matchesReceivedInvocations: [AnyBindingKey] = [] + var matchesReturnValue: Bool! + var matchesClosure: ((AnyBindingKey) -> Bool)? + + func matches(_ other: AnyBindingKey) -> Bool { + matchesCallsCount += 1 + matchesReceivedOther = other + matchesReceivedInvocations.append(other) + return matchesClosure.map { $0(other) } ?? matchesReturnValue + } +} + class AnyTypeDescriptorMock: AnyTypeDescriptor { // MARK: - matches diff --git a/Tests/UnitSpecs/BindingKeySpec.swift b/Tests/UnitSpecs/BindingKeySpec.swift new file mode 100644 index 00000000..48d9ede4 --- /dev/null +++ b/Tests/UnitSpecs/BindingKeySpec.swift @@ -0,0 +1,48 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +import Nimble +import Quick +@testable import Swinject + +class BindingKeySpec: QuickSpec { override func spec() { + typealias AnyBindingKey = BindingKey + + describe("matching") { + var key: AnyBindingKey! + var descriptor = AnyTypeDescriptorMock() + var otherKey = AnyBindingKeyMock() + beforeEach { + descriptor = AnyTypeDescriptorMock() + descriptor.matchesReturnValue = true + key = AnyBindingKey(descriptor: descriptor) + otherKey = AnyBindingKeyMock() + otherKey.descriptor = AnyTypeDescriptorMock() + otherKey.argumentType = Void.self + } + it("does not match if descriptors don't match") { + descriptor.matchesReturnValue = false + expect { key.matches(otherKey) }.to(beFalse()) + } + it("it checks if descriptors match") { + let otherDescriptor = AnyTypeDescriptorMock() + _ = key.matches(AnyBindingKey(descriptor: otherDescriptor)) + expect(descriptor.matchesReceivedOther) === otherDescriptor + } + it("matches if descriptors match") { + descriptor.matchesReturnValue = true + expect { key.matches(otherKey) }.to(beTrue()) + } + it("does not match if argument types are different") { + let key = AnyBindingKey(descriptor: descriptor) + otherKey.argumentType = Double.self + expect(key.matches(otherKey)).to(beFalse()) + } + it("matches if argument types are the same") { + let key = AnyBindingKey(descriptor: descriptor) + otherKey.argumentType = Int.self + expect(key.matches(otherKey)).to(beTrue()) + } + } +} } From f33e47427488808e60fbbbb16b31d04103748968 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Mon, 15 Jul 2019 23:28:33 +0200 Subject: [PATCH 034/239] Update swinject to match keys instead of descriptors --- Sources/Swinject.swift | 8 ++--- Tests/UnitSpecs/SwinjectSpec.swift | 58 +++++++++++++++--------------- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/Sources/Swinject.swift b/Sources/Swinject.swift index 587d2ec5..ffbb2b0d 100644 --- a/Sources/Swinject.swift +++ b/Sources/Swinject.swift @@ -26,16 +26,16 @@ public extension Swinject { extension Swinject: Injector { public func instance(for request: BindingRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { - try instance(from: findBinding(for: request.key.descriptor)) + try instance(from: findBinding(for: request.key)) } public func provider(for request: BindingRequest) throws -> () throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { - let binding = try findBinding(for: request.key.descriptor) + let binding = try findBinding(for: request.key) return { try self.instance(from: binding) } } - private func findBinding(for descriptor: AnyTypeDescriptor) throws -> AnyBinding { - let entries = tree.bindingEntries.filter { $0.key.descriptor.matches(descriptor) } + private func findBinding(for key: AnyBindingKey) throws -> AnyBinding { + let entries = tree.bindingEntries.filter { $0.key.matches(key) } guard entries.count == 1 else { throw SwinjectError() } return entries[0].binding } diff --git a/Tests/UnitSpecs/SwinjectSpec.swift b/Tests/UnitSpecs/SwinjectSpec.swift index 4b97fab4..d114ec8b 100644 --- a/Tests/UnitSpecs/SwinjectSpec.swift +++ b/Tests/UnitSpecs/SwinjectSpec.swift @@ -17,48 +17,48 @@ class SwinjectSpec: QuickSpec { override func spec() { context("single binding") { var swinject: Swinject! var binding = AnyBindingMock() - var descriptor = AnyTypeDescriptorMock() + var key = AnyBindingKeyMock() beforeEach { binding = AnyBindingMock() - descriptor = AnyTypeDescriptorMock() - swinject = Swinject { bbind(descriptor) & binding } + key = AnyBindingKeyMock() + swinject = Swinject { BindingEntry(key: key, binding: binding) } } it("request instance from matching binding") { - descriptor.matchesReturnValue = true + key.matchesReturnValue = true _ = try? swinject.instance(of: Any.self) expect(binding.instanceUsingCallsCount) == 1 } it("does not request instance from matching binding until instance is required") { - descriptor.matchesReturnValue = true + key.matchesReturnValue = true expect(binding.instanceUsingCallsCount) == 0 } it("only requests instance from matching binding") { - descriptor.matchesReturnValue = false + key.matchesReturnValue = false _ = try? swinject.instance(of: Any.self) expect(binding.instanceUsingCallsCount) == 0 } it("returns instance produced by binding") { - descriptor.matchesReturnValue = true + key.matchesReturnValue = true binding.instanceUsingReturnValue = 42 expect { try swinject.instance(of: Any.self) as? Int } == 42 } it("rethrows error from binding") { - descriptor.matchesReturnValue = true + key.matchesReturnValue = true binding.instanceUsingThrowableError = TestError() expect { try swinject.instance(of: Any.self) }.to(throwError(errorType: TestError.self)) } it("crashes if bound type does not match requested type") { - descriptor.matchesReturnValue = true + key.matchesReturnValue = true binding.instanceUsingReturnValue = "" expect { _ = try swinject.instance(of: Double.self) }.to(throwError()) } it("does not crash if bound type conforms to the requested type") { - descriptor.matchesReturnValue = true + key.matchesReturnValue = true binding.instanceUsingReturnValue = 42 expect { _ = try swinject.instance(of: CustomStringConvertible?.self) }.notTo(throwError()) } it("passes swinject as injector") { - descriptor.matchesReturnValue = true + key.matchesReturnValue = true _ = try? swinject.instance(of: Any.self) expect(binding.instanceUsingReceivedInjector is Swinject).to(beTrue()) } @@ -66,27 +66,27 @@ class SwinjectSpec: QuickSpec { override func spec() { context("multiple bindings") { var swinject: Swinject! var bindings = [AnyBindingMock]() - var descriptors = [AnyTypeDescriptorMock]() + var keys = [AnyBindingKeyMock]() beforeEach { - descriptors = Array(0 ..< 3).map { _ in AnyTypeDescriptorMock() } - descriptors.forEach { $0.matchesReturnValue = false } - bindings = descriptors.map { _ in AnyBindingMock() } + keys = Array(0 ..< 3).map { _ in AnyBindingKeyMock() } + keys.forEach { $0.matchesReturnValue = false } + bindings = keys.map { _ in AnyBindingMock() } swinject = Swinject { - bbind(descriptors[0]) & bindings[0] - bbind(descriptors[1]) & bindings[1] - bbind(descriptors[2]) & bindings[2] + BindingEntry(key: keys[0], binding: bindings[0]) + BindingEntry(key: keys[1], binding: bindings[1]) + BindingEntry(key: keys[2], binding: bindings[2]) } } it("throws if multiple entries match requested type") { - descriptors.forEach { $0.matchesReturnValue = true } + keys.forEach { $0.matchesReturnValue = true } expect { try swinject.instance(of: Any.self) }.to(throwError()) } it("does not throw if single entry matches requested type") { - descriptors[1].matchesReturnValue = true + keys[1].matchesReturnValue = true expect { try swinject.instance(of: Any.self) }.notTo(throwError()) } it("returns instance from matching binding") { - descriptors[1].matchesReturnValue = true + keys[1].matchesReturnValue = true bindings[1].instanceUsingReturnValue = 42 expect { try swinject.instance(of: Int.self) } == 42 } @@ -95,34 +95,34 @@ class SwinjectSpec: QuickSpec { override func spec() { describe("provider injection") { var swinject: Swinject! var binding = AnyBindingMock() - var descriptor = AnyTypeDescriptorMock() + var key = AnyBindingKeyMock() beforeEach { binding = AnyBindingMock() - descriptor = AnyTypeDescriptorMock() - swinject = Swinject { bbind(descriptor) & binding } + key = AnyBindingKeyMock() + swinject = Swinject { BindingEntry(key: key, binding: binding) } } it("does not throw if binding matches provided type") { - descriptor.matchesReturnValue = true + key.matchesReturnValue = true binding.instanceUsingReturnValue = 42 expect { try swinject.provider(of: Int.self) }.notTo(throwError()) } it("throws if missing binding for provided type") { - descriptor.matchesReturnValue = false + key.matchesReturnValue = false expect { try swinject.provider(of: Int.self) }.to(throwError()) } it("does not request provided type until provider is called") { - descriptor.matchesReturnValue = true + key.matchesReturnValue = true binding.instanceUsingReturnValue = 42 _ = try? swinject.provider(of: Int.self) expect(binding.instanceUsingCallsCount) == 0 } it("returns instance from binding") { - descriptor.matchesReturnValue = true + key.matchesReturnValue = true binding.instanceUsingReturnValue = 42 expect { try swinject.provider(of: Int.self)() } == 42 } it("rethrows binding error from provider") { - descriptor.matchesReturnValue = true + key.matchesReturnValue = true binding.instanceUsingThrowableError = TestError() expect { try swinject.provider(of: Int.self)() }.to(throwError(errorType: TestError.self)) } From 87959467383e71e6fabbe9d65496e82409326eac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Mon, 15 Jul 2019 23:45:30 +0200 Subject: [PATCH 035/239] Extend binding interface --- Sources/Binding.swift | 15 +++++++--- Sources/Injector.swift | 34 ++++++++++++++++------- Sources/InstanceBinding.swift | 3 +- Sources/ProviderBinding.swift | 3 +- Sources/Swinject.swift | 8 +++--- Tests/Support/GeneratedMocks.swift | 28 +++++++++---------- Tests/Support/NonGeneratedMocks.swift | 6 +++- Tests/UnitSpecs/InstanceBindingSpec.swift | 2 +- Tests/UnitSpecs/ProviderBindingSpec.swift | 10 +++---- Tests/UnitSpecs/SwinjectSpec.swift | 33 ++++++++++++---------- 10 files changed, 85 insertions(+), 57 deletions(-) diff --git a/Sources/Binding.swift b/Sources/Binding.swift index f9e52b30..a4673ecb 100644 --- a/Sources/Binding.swift +++ b/Sources/Binding.swift @@ -4,17 +4,24 @@ // sourcery: AutoMockable public protocol AnyBinding { - func instance(using injector: Injector) throws -> Any + func instance(arg: Any, injector: Injector) throws -> Any } public protocol Binding: AnyBinding { associatedtype BoundType associatedtype Argument - func instance(using injector: Injector) throws -> BoundType + func instance(arg: Argument, injector: Injector) throws -> BoundType +} + +public extension Binding where Argument == Void { + func instance(injector: Injector) throws -> BoundType { + try instance(arg: (), injector: injector) + } } public extension AnyBinding where Self: Binding { - func instance(using injector: Injector) throws -> Any { - try instance(using: injector) as BoundType + func instance(arg: Any, injector: Injector) throws -> Any { + guard let arg = arg as? Argument else { throw SwinjectError() } + return try instance(arg: arg, injector: injector) as BoundType } } diff --git a/Sources/Injector.swift b/Sources/Injector.swift index 7849ec52..b19ff8cb 100644 --- a/Sources/Injector.swift +++ b/Sources/Injector.swift @@ -10,27 +10,41 @@ public protocol Injector { } public extension Injector { - func instance(_ descriptor: Descriptor) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { - try instance(for: BindingRequest(key: BindingKey(descriptor: descriptor), argument: ())) - } - func instance(of _: Type.Type = Type.self) throws -> Type { - try instance(plain(Type.self)) + try instance(arg: ()) } func instance(of _: Type.Type = Type.self, tagged tag: Tag) throws -> Type { - try instance(tagged(Type.self, with: tag)) + try instance(tagged: tag, arg: ()) + } + + func instance(of _: Type.Type = Type.self, arg: Argument) throws -> Type { + try instance(tagged: NoTag(), arg: arg) } - func provider(_ descriptor: Descriptor) throws -> () throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { - try provider(for: BindingRequest(key: BindingKey(descriptor: descriptor), argument: ())) + func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg: Argument) throws -> Type { + try instance(for: BindingRequest, Argument>( + key: BindingKey(descriptor: tagged(Type.self, with: tag)), + argument: arg + )) } func provider(of _: Type.Type = Type.self) throws -> () throws -> Type { - try provider(plain(Type.self)) + try provider(arg: ()) } func provider(of _: Type.Type = Type.self, tagged tag: Tag) throws -> () throws -> Type { - try provider(tagged(Type.self, with: tag)) + try provider(tagged: tag, arg: ()) + } + + func provider(of _: Type.Type = Type.self, arg: Argument) throws -> () throws -> Type { + try provider(tagged: NoTag(), arg: arg) + } + + func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg: Argument) throws -> () throws -> Type { + try provider(for: BindingRequest, Argument>( + key: BindingKey(descriptor: tagged(Type.self, with: tag)), + argument: arg + )) } } diff --git a/Sources/InstanceBinding.swift b/Sources/InstanceBinding.swift index 5a8ea981..1316f001 100644 --- a/Sources/InstanceBinding.swift +++ b/Sources/InstanceBinding.swift @@ -5,7 +5,6 @@ // TODO: Make internal public struct InstanceBinding: Binding { public typealias BoundType = Type - public typealias Argument = Void private let _instance: Type @@ -13,7 +12,7 @@ public struct InstanceBinding: Binding { _instance = instance } - public func instance(using _: Injector) throws -> Type { + public func instance(arg _: Void, injector _: Injector) throws -> Type { _instance } } diff --git a/Sources/ProviderBinding.swift b/Sources/ProviderBinding.swift index 2d8d43d0..0d1ac86c 100644 --- a/Sources/ProviderBinding.swift +++ b/Sources/ProviderBinding.swift @@ -5,7 +5,6 @@ // TODO: Make internal public struct ProviderBinding: Binding { public typealias BoundType = Type - public typealias Argument = Void private let builder: (Injector) throws -> Type @@ -13,7 +12,7 @@ public struct ProviderBinding: Binding { self.builder = builder } - public func instance(using provider: Injector) throws -> Type { + public func instance(arg _: Void, injector provider: Injector) throws -> Type { try builder(provider) } } diff --git a/Sources/Swinject.swift b/Sources/Swinject.swift index ffbb2b0d..30392626 100644 --- a/Sources/Swinject.swift +++ b/Sources/Swinject.swift @@ -26,12 +26,12 @@ public extension Swinject { extension Swinject: Injector { public func instance(for request: BindingRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { - try instance(from: findBinding(for: request.key)) + try instance(from: findBinding(for: request.key), arg: request.argument) } public func provider(for request: BindingRequest) throws -> () throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { let binding = try findBinding(for: request.key) - return { try self.instance(from: binding) } + return { try self.instance(from: binding, arg: request.argument) } } private func findBinding(for key: AnyBindingKey) throws -> AnyBinding { @@ -40,7 +40,7 @@ extension Swinject: Injector { return entries[0].binding } - private func instance(from binding: AnyBinding) throws -> Type { - try binding.instance(using: self) as? Type ?? { throw SwinjectError() }() + private func instance(from binding: AnyBinding, arg: Argument) throws -> Type { + try binding.instance(arg: arg, injector: self) as? Type ?? { throw SwinjectError() }() } } diff --git a/Tests/Support/GeneratedMocks.swift b/Tests/Support/GeneratedMocks.swift index 3c10aa6e..0d8a4482 100644 --- a/Tests/Support/GeneratedMocks.swift +++ b/Tests/Support/GeneratedMocks.swift @@ -10,25 +10,25 @@ class AnyBindingMock: AnyBinding { // MARK: - instance - var instanceUsingThrowableError: Error? - var instanceUsingCallsCount = 0 - var instanceUsingCalled: Bool { - return instanceUsingCallsCount > 0 + var instanceArgInjectorThrowableError: Error? + var instanceArgInjectorCallsCount = 0 + var instanceArgInjectorCalled: Bool { + return instanceArgInjectorCallsCount > 0 } - var instanceUsingReceivedInjector: Injector? - var instanceUsingReceivedInvocations: [Injector] = [] - var instanceUsingReturnValue: Any! - var instanceUsingClosure: ((Injector) throws -> Any)? + var instanceArgInjectorReceivedArguments: (arg: Any, injector: Injector)? + var instanceArgInjectorReceivedInvocations: [(arg: Any, injector: Injector)] = [] + var instanceArgInjectorReturnValue: Any! + var instanceArgInjectorClosure: ((Any, Injector) throws -> Any)? - func instance(using injector: Injector) throws -> Any { - if let error = instanceUsingThrowableError { + func instance(arg: Any, injector: Injector) throws -> Any { + if let error = instanceArgInjectorThrowableError { throw error } - instanceUsingCallsCount += 1 - instanceUsingReceivedInjector = injector - instanceUsingReceivedInvocations.append(injector) - return try instanceUsingClosure.map { try $0(injector) } ?? instanceUsingReturnValue + instanceArgInjectorCallsCount += 1 + instanceArgInjectorReceivedArguments = (arg: arg, injector: injector) + instanceArgInjectorReceivedInvocations.append((arg: arg, injector: injector)) + return try instanceArgInjectorClosure.map { try $0(arg, injector) } ?? instanceArgInjectorReturnValue } } diff --git a/Tests/Support/NonGeneratedMocks.swift b/Tests/Support/NonGeneratedMocks.swift index 20e816b3..4532f367 100644 --- a/Tests/Support/NonGeneratedMocks.swift +++ b/Tests/Support/NonGeneratedMocks.swift @@ -22,4 +22,8 @@ extension AnyBindingMock: Binding { typealias Argument = Any } -class DummyBinding: Binding {} +class DummyBinding: Binding { + func instance(arg _: Argument, injector _: Injector) throws -> Any { + fatalError() + } +} diff --git a/Tests/UnitSpecs/InstanceBindingSpec.swift b/Tests/UnitSpecs/InstanceBindingSpec.swift index 4e0e1646..45d4299c 100644 --- a/Tests/UnitSpecs/InstanceBindingSpec.swift +++ b/Tests/UnitSpecs/InstanceBindingSpec.swift @@ -9,6 +9,6 @@ import Quick class InstanceBindingSpec: QuickSpec { override func spec() { it("returns given instance") { let binding = instance(42) - expect { try binding.instance(using: DummyInjector()) } == 42 + expect { try binding.instance(injector: DummyInjector()) } == 42 } } } diff --git a/Tests/UnitSpecs/ProviderBindingSpec.swift b/Tests/UnitSpecs/ProviderBindingSpec.swift index 24dc5d42..3d6fb39f 100644 --- a/Tests/UnitSpecs/ProviderBindingSpec.swift +++ b/Tests/UnitSpecs/ProviderBindingSpec.swift @@ -9,7 +9,7 @@ import Quick class ProviderBindingSpec: QuickSpec { override func spec() { it("returns instance made by provider method") { let binding = provider { 42 } - expect { try binding.instance(using: DummyInjector()) } == 42 + expect { try binding.instance(injector: DummyInjector()) } == 42 } it("does not call builder until instance is requested") { var called = false @@ -20,17 +20,17 @@ class ProviderBindingSpec: QuickSpec { override func spec() { var passedProvider: Injector? let fake = DummyInjector() let binding = provider { passedProvider = $0 } - _ = try? binding.instance(using: fake) + _ = try? binding.instance(injector: fake) expect(passedProvider) === fake } it("rethrows error from builder") { let binding = provider { throw SwinjectError() } - expect { try binding.instance(using: DummyInjector()) }.to(throwError()) + expect { try binding.instance(injector: DummyInjector()) }.to(throwError()) } it("does not reuse instance") { let binding = provider { Person() } - let instance1 = try? binding.instance(using: DummyInjector()) - let instance2 = try? binding.instance(using: DummyInjector()) + let instance1 = try? binding.instance(injector: DummyInjector()) + let instance2 = try? binding.instance(injector: DummyInjector()) expect(instance1) !== instance2 } } } diff --git a/Tests/UnitSpecs/SwinjectSpec.swift b/Tests/UnitSpecs/SwinjectSpec.swift index d114ec8b..4252474a 100644 --- a/Tests/UnitSpecs/SwinjectSpec.swift +++ b/Tests/UnitSpecs/SwinjectSpec.swift @@ -26,41 +26,46 @@ class SwinjectSpec: QuickSpec { override func spec() { it("request instance from matching binding") { key.matchesReturnValue = true _ = try? swinject.instance(of: Any.self) - expect(binding.instanceUsingCallsCount) == 1 + expect(binding.instanceArgInjectorCallsCount) == 1 } it("does not request instance from matching binding until instance is required") { key.matchesReturnValue = true - expect(binding.instanceUsingCallsCount) == 0 + expect(binding.instanceArgInjectorCallsCount) == 0 } it("only requests instance from matching binding") { key.matchesReturnValue = false _ = try? swinject.instance(of: Any.self) - expect(binding.instanceUsingCallsCount) == 0 + expect(binding.instanceArgInjectorCallsCount) == 0 } it("returns instance produced by binding") { key.matchesReturnValue = true - binding.instanceUsingReturnValue = 42 + binding.instanceArgInjectorReturnValue = 42 expect { try swinject.instance(of: Any.self) as? Int } == 42 } it("rethrows error from binding") { key.matchesReturnValue = true - binding.instanceUsingThrowableError = TestError() + binding.instanceArgInjectorThrowableError = TestError() expect { try swinject.instance(of: Any.self) }.to(throwError(errorType: TestError.self)) } it("crashes if bound type does not match requested type") { key.matchesReturnValue = true - binding.instanceUsingReturnValue = "" + binding.instanceArgInjectorReturnValue = "" expect { _ = try swinject.instance(of: Double.self) }.to(throwError()) } it("does not crash if bound type conforms to the requested type") { key.matchesReturnValue = true - binding.instanceUsingReturnValue = 42 + binding.instanceArgInjectorReturnValue = 42 expect { _ = try swinject.instance(of: CustomStringConvertible?.self) }.notTo(throwError()) } it("passes swinject as injector") { key.matchesReturnValue = true _ = try? swinject.instance(of: Any.self) - expect(binding.instanceUsingReceivedInjector is Swinject).to(beTrue()) + expect(binding.instanceArgInjectorReceivedArguments?.injector is Swinject).to(beTrue()) + } + it("passes given argument to binding") { + key.matchesReturnValue = true + _ = try? swinject.instance(of: Any.self, arg: 42) + expect(binding.instanceArgInjectorReceivedArguments?.arg as? Int) == 42 } } context("multiple bindings") { @@ -87,7 +92,7 @@ class SwinjectSpec: QuickSpec { override func spec() { } it("returns instance from matching binding") { keys[1].matchesReturnValue = true - bindings[1].instanceUsingReturnValue = 42 + bindings[1].instanceArgInjectorReturnValue = 42 expect { try swinject.instance(of: Int.self) } == 42 } } @@ -103,7 +108,7 @@ class SwinjectSpec: QuickSpec { override func spec() { } it("does not throw if binding matches provided type") { key.matchesReturnValue = true - binding.instanceUsingReturnValue = 42 + binding.instanceArgInjectorReturnValue = 42 expect { try swinject.provider(of: Int.self) }.notTo(throwError()) } it("throws if missing binding for provided type") { @@ -112,18 +117,18 @@ class SwinjectSpec: QuickSpec { override func spec() { } it("does not request provided type until provider is called") { key.matchesReturnValue = true - binding.instanceUsingReturnValue = 42 + binding.instanceArgInjectorReturnValue = 42 _ = try? swinject.provider(of: Int.self) - expect(binding.instanceUsingCallsCount) == 0 + expect(binding.instanceArgInjectorCallsCount) == 0 } it("returns instance from binding") { key.matchesReturnValue = true - binding.instanceUsingReturnValue = 42 + binding.instanceArgInjectorReturnValue = 42 expect { try swinject.provider(of: Int.self)() } == 42 } it("rethrows binding error from provider") { key.matchesReturnValue = true - binding.instanceUsingThrowableError = TestError() + binding.instanceArgInjectorThrowableError = TestError() expect { try swinject.provider(of: Int.self)() }.to(throwError(errorType: TestError.self)) } } From e286fc34fc01d57e042f929d9af6e672219d47ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Tue, 16 Jul 2019 00:27:12 +0200 Subject: [PATCH 036/239] Implement factory binding --- Sources/FactoryBinding.swift | 37 +++++++++++++ Sources/Injector.swift | 1 + Swinject.xcodeproj/project.pbxproj | 8 +++ Tests/UnitSpecs/FactoryBindingSpec.swift | 64 +++++++++++++++++++++++ Tests/UnitSpecs/ProviderBindingSpec.swift | 10 ++-- 5 files changed, 115 insertions(+), 5 deletions(-) create mode 100644 Sources/FactoryBinding.swift create mode 100644 Tests/UnitSpecs/FactoryBindingSpec.swift diff --git a/Sources/FactoryBinding.swift b/Sources/FactoryBinding.swift new file mode 100644 index 00000000..98f2b89b --- /dev/null +++ b/Sources/FactoryBinding.swift @@ -0,0 +1,37 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +public struct FactoryBinding: Binding { + public typealias BoundType = Type + + private let builder: (Injector, Argument) throws -> Type + + init(_ builder: @escaping (Injector, Argument) throws -> Type) { + self.builder = builder + } + + public func instance(arg: Argument, injector provider: Injector) throws -> Type { + try builder(provider, arg) + } +} + +public func factory(_ builder: @escaping (Injector, Arg1) throws -> Type) -> FactoryBinding { + FactoryBinding(builder) +} + +public func factory(_ builder: @escaping (Injector, Arg1, Arg2) throws -> Type) -> FactoryBinding { + FactoryBinding { try builder($0, $1.0, $1.1) } +} + +public func factory(_ builder: @escaping (Injector, Arg1, Arg2, Arg3) throws -> Type) -> FactoryBinding { + FactoryBinding { try builder($0, $1.0, $1.1, $1.2) } +} + +public func factory(_ builder: @escaping (Injector, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> FactoryBinding { + FactoryBinding { try builder($0, $1.0, $1.1, $1.2, $1.3) } +} + +public func factory(_ builder: @escaping (Injector, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> FactoryBinding { + FactoryBinding { try builder($0, $1.0, $1.1, $1.2, $1.3, $1.4) } +} diff --git a/Sources/Injector.swift b/Sources/Injector.swift index b19ff8cb..6aef6638 100644 --- a/Sources/Injector.swift +++ b/Sources/Injector.swift @@ -9,6 +9,7 @@ public protocol Injector { func provider(for request: BindingRequest) throws -> () throws -> Descriptor.BaseType where Descriptor: TypeDescriptor } +// TODO: Overloads for multiple arguments public extension Injector { func instance(of _: Type.Type = Type.self) throws -> Type { try instance(arg: ()) diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 07ce2a00..f6e4520e 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -15,6 +15,8 @@ CD6DE53522DD1C7300532D08 /* BindingKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53322DD1C6800532D08 /* BindingKeySpec.swift */; }; CD6DE53722DD1CE900532D08 /* BindingKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53622DD1CE900532D08 /* BindingKey.swift */; }; CD6DE53922DD1D0A00532D08 /* BindingRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53822DD1D0A00532D08 /* BindingRequest.swift */; }; + CD6DE53B22DD303F00532D08 /* FactoryBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53A22DD303F00532D08 /* FactoryBinding.swift */; }; + CD6DE53D22DD30A100532D08 /* FactoryBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53C22DD30A100532D08 /* FactoryBindingSpec.swift */; }; CD85AF0E22DA57AD00A8B7CA /* ProviderBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF0D22DA57AD00A8B7CA /* ProviderBinding.swift */; }; CD85AF1022DA586D00A8B7CA /* ProviderBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF0F22DA586D00A8B7CA /* ProviderBindingSpec.swift */; }; CD85AF1222DA5A8F00A8B7CA /* NonGeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF1122DA5A8F00A8B7CA /* NonGeneratedMocks.swift */; }; @@ -59,6 +61,8 @@ CD6DE53322DD1C6800532D08 /* BindingKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingKeySpec.swift; sourceTree = ""; }; CD6DE53622DD1CE900532D08 /* BindingKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingKey.swift; sourceTree = ""; }; CD6DE53822DD1D0A00532D08 /* BindingRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingRequest.swift; sourceTree = ""; }; + CD6DE53A22DD303F00532D08 /* FactoryBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FactoryBinding.swift; sourceTree = ""; }; + CD6DE53C22DD30A100532D08 /* FactoryBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FactoryBindingSpec.swift; sourceTree = ""; }; CD85AF0D22DA57AD00A8B7CA /* ProviderBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProviderBinding.swift; sourceTree = ""; }; CD85AF0F22DA586D00A8B7CA /* ProviderBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProviderBindingSpec.swift; sourceTree = ""; }; CD85AF1122DA5A8F00A8B7CA /* NonGeneratedMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonGeneratedMocks.swift; sourceTree = ""; }; @@ -134,6 +138,7 @@ CDD8380B22DA3AD8003E9909 /* Binding.swift */, CD85AF0D22DA57AD00A8B7CA /* ProviderBinding.swift */, CDADF32222DB416C00C5D8DB /* InstanceBinding.swift */, + CD6DE53A22DD303F00532D08 /* FactoryBinding.swift */, CDD8380F22DA429F003E9909 /* Injector.swift */, CDD8380D22DA3B0D003E9909 /* BindingEntry.swift */, CD6DE53622DD1CE900532D08 /* BindingKey.swift */, @@ -183,6 +188,7 @@ CDD8380822DA31C6003E9909 /* TypeBinderSpec.swift */, CD85AF0F22DA586D00A8B7CA /* ProviderBindingSpec.swift */, CDADF33122DB4C1200C5D8DB /* InstanceBindingSpec.swift */, + CD6DE53C22DD30A100532D08 /* FactoryBindingSpec.swift */, CDD8381922DA4C9F003E9909 /* SwinjectSpec.swift */, CD6DE53322DD1C6800532D08 /* BindingKeySpec.swift */, ); @@ -373,6 +379,7 @@ CD6DE53722DD1CE900532D08 /* BindingKey.swift in Sources */, CD6DE53922DD1D0A00532D08 /* BindingRequest.swift in Sources */, CDADF32322DB416C00C5D8DB /* InstanceBinding.swift in Sources */, + CD6DE53B22DD303F00532D08 /* FactoryBinding.swift in Sources */, CDADF32122DB38C600C5D8DB /* SwinjectTree.swift in Sources */, CDD8381D22DA4E02003E9909 /* SwinjectError.swift in Sources */, CDD8380722DA30C6003E9909 /* TypeDescriptor.swift in Sources */, @@ -392,6 +399,7 @@ CDADF34022DB883A00C5D8DB /* GeneratedMocks.swift in Sources */, CDD8380A22DA31D9003E9909 /* TypeBinderSpec.swift in Sources */, CD85AF1222DA5A8F00A8B7CA /* NonGeneratedMocks.swift in Sources */, + CD6DE53D22DD30A100532D08 /* FactoryBindingSpec.swift in Sources */, CDADF33322DB4C1800C5D8DB /* InstanceBindingSpec.swift in Sources */, CD85AF1022DA586D00A8B7CA /* ProviderBindingSpec.swift in Sources */, CDD8380322DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift in Sources */, diff --git a/Tests/UnitSpecs/FactoryBindingSpec.swift b/Tests/UnitSpecs/FactoryBindingSpec.swift new file mode 100644 index 00000000..b573267a --- /dev/null +++ b/Tests/UnitSpecs/FactoryBindingSpec.swift @@ -0,0 +1,64 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +import Nimble +import Quick +@testable import Swinject + +class FactoryBindingSpec: QuickSpec { override func spec() { + it("returns instance made by builder method") { + let binding = factory { (_, _: Void) in 42 } + expect { try binding.instance(injector: DummyInjector()) } == 42 + } + it("does not call builder until instance is requested") { + var called = false + _ = factory { (_, _: Void) in called = true } + expect(called).to(beFalse()) + } + it("calls builder with given provider") { + var passedInjector: Injector? + let injector = DummyInjector() + let binding = factory { (_, _: Void) in passedInjector = injector } + _ = try? binding.instance(injector: injector) + expect(passedInjector) === injector + } + it("calls builder with given argument") { + var passedArgument: Int? + let binding = factory { (_, arg: Int) in passedArgument = arg } + _ = try? binding.instance(arg: 42, injector: DummyInjector()) + expect(passedArgument) == 42 + } + it("rethrows error from builder") { + let binding = factory { (_, _: Void) in throw SwinjectError() } + expect { try binding.instance(injector: DummyInjector()) }.to(throwError()) + } + it("does not reuse instance") { + let binding = factory { (_, _: Void) in Person() } + let instance1 = try? binding.instance(injector: DummyInjector()) + let instance2 = try? binding.instance(injector: DummyInjector()) + expect(instance1) !== instance2 + } + describe("multiple arguments") { + it("works with 2 arguments") { + let binding = factory { (_, _: Int, _: Double) in 42 } + let arguments = (1, 1.0) + expect { try binding.instance(arg: arguments, injector: DummyInjector()) } == 42 + } + it("works with 3 arguments") { + let binding = factory { (_, _: Int, _: Double, _: String) in 42 } + let arguments = (1, 1.0, "") + expect { try binding.instance(arg: arguments, injector: DummyInjector()) } == 42 + } + it("works with 4 arguments") { + let binding = factory { (_, _: Int, _: Double, _: String, _: Float) in 42 } + let arguments = (1, 1.0, "", Float(1.0)) + expect { try binding.instance(arg: arguments, injector: DummyInjector()) } == 42 + } + it("works with 5 arguments") { + let binding = factory { (_, _: Int, _: Double, _: String, _: Float, _: Int) in 42 } + let arguments = (1, 1.0, "", Float(1.0), 5) + expect { try binding.instance(arg: arguments, injector: DummyInjector()) } == 42 + } + } +} } diff --git a/Tests/UnitSpecs/ProviderBindingSpec.swift b/Tests/UnitSpecs/ProviderBindingSpec.swift index 3d6fb39f..728c7346 100644 --- a/Tests/UnitSpecs/ProviderBindingSpec.swift +++ b/Tests/UnitSpecs/ProviderBindingSpec.swift @@ -17,11 +17,11 @@ class ProviderBindingSpec: QuickSpec { override func spec() { expect(called).to(beFalse()) } it("calls builder with given provider") { - var passedProvider: Injector? - let fake = DummyInjector() - let binding = provider { passedProvider = $0 } - _ = try? binding.instance(injector: fake) - expect(passedProvider) === fake + var passedInjector: Injector? + let injector = DummyInjector() + let binding = provider { passedInjector = $0 } + _ = try? binding.instance(injector: injector) + expect(passedInjector) === injector } it("rethrows error from builder") { let binding = provider { throw SwinjectError() } From f3834cc71a409f191c3d74244563da57ce498a97 Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Tue, 16 Jul 2019 13:56:09 +0200 Subject: [PATCH 037/239] Refactor provider injection --- .../{Injector.swift => SwinjectAware.swift} | 24 +++++++++++-------- Swinject.xcodeproj/project.pbxproj | 16 ++++--------- Tests/UnitSpecs/SwinjectSpec.swift | 11 ++++++--- 3 files changed, 26 insertions(+), 25 deletions(-) rename Sources/{Injector.swift => SwinjectAware.swift} (70%) diff --git a/Sources/Injector.swift b/Sources/SwinjectAware.swift similarity index 70% rename from Sources/Injector.swift rename to Sources/SwinjectAware.swift index 6aef6638..cc224938 100644 --- a/Sources/Injector.swift +++ b/Sources/SwinjectAware.swift @@ -4,9 +4,13 @@ public protocol Injector { func instance(for request: BindingRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor +} - // TODO: Move this to extension? - func provider(for request: BindingRequest) throws -> () throws -> Descriptor.BaseType where Descriptor: TypeDescriptor +extension Injector { + // TODO: Get rid of this method + func provider(for request: BindingRequest) -> () throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { + { try self.instance(for: request) } + } } // TODO: Overloads for multiple arguments @@ -30,20 +34,20 @@ public extension Injector { )) } - func provider(of _: Type.Type = Type.self) throws -> () throws -> Type { - try provider(arg: ()) + func provider(of _: Type.Type = Type.self) -> () throws -> Type { + provider(arg: ()) } - func provider(of _: Type.Type = Type.self, tagged tag: Tag) throws -> () throws -> Type { - try provider(tagged: tag, arg: ()) + func provider(of _: Type.Type = Type.self, tagged tag: Tag) -> () throws -> Type { + provider(tagged: tag, arg: ()) } - func provider(of _: Type.Type = Type.self, arg: Argument) throws -> () throws -> Type { - try provider(tagged: NoTag(), arg: arg) + func provider(of _: Type.Type = Type.self, arg: Argument) -> () throws -> Type { + provider(tagged: NoTag(), arg: arg) } - func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg: Argument) throws -> () throws -> Type { - try provider(for: BindingRequest, Argument>( + func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg: Argument) -> () throws -> Type { + provider(for: BindingRequest, Argument>( key: BindingKey(descriptor: tagged(Type.self, with: tag)), argument: arg )) diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index f6e4520e..4b56407a 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -32,7 +32,7 @@ CDD8380A22DA31D9003E9909 /* TypeBinderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380822DA31C6003E9909 /* TypeBinderSpec.swift */; }; CDD8380C22DA3AD8003E9909 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380B22DA3AD8003E9909 /* Binding.swift */; }; CDD8380E22DA3B0D003E9909 /* BindingEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380D22DA3B0D003E9909 /* BindingEntry.swift */; }; - CDD8381022DA429F003E9909 /* Injector.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380F22DA429F003E9909 /* Injector.swift */; }; + CDD8381022DA429F003E9909 /* SwinjectAware.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380F22DA429F003E9909 /* SwinjectAware.swift */; }; CDD8381622DA4B55003E9909 /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381522DA4B55003E9909 /* Swinject.swift */; }; CDD8381B22DA4CBE003E9909 /* SwinjectSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381922DA4C9F003E9909 /* SwinjectSpec.swift */; }; CDD8381D22DA4E02003E9909 /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381C22DA4E02003E9909 /* SwinjectError.swift */; }; @@ -79,7 +79,7 @@ CDD8380822DA31C6003E9909 /* TypeBinderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinderSpec.swift; sourceTree = ""; }; CDD8380B22DA3AD8003E9909 /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; CDD8380D22DA3B0D003E9909 /* BindingEntry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingEntry.swift; sourceTree = ""; }; - CDD8380F22DA429F003E9909 /* Injector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Injector.swift; sourceTree = ""; }; + CDD8380F22DA429F003E9909 /* SwinjectAware.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectAware.swift; sourceTree = ""; }; CDD8381522DA4B55003E9909 /* Swinject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Swinject.swift; sourceTree = ""; }; CDD8381922DA4C9F003E9909 /* SwinjectSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectSpec.swift; sourceTree = ""; }; CDD8381C22DA4E02003E9909 /* SwinjectError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectError.swift; sourceTree = ""; }; @@ -139,7 +139,7 @@ CD85AF0D22DA57AD00A8B7CA /* ProviderBinding.swift */, CDADF32222DB416C00C5D8DB /* InstanceBinding.swift */, CD6DE53A22DD303F00532D08 /* FactoryBinding.swift */, - CDD8380F22DA429F003E9909 /* Injector.swift */, + CDD8380F22DA429F003E9909 /* SwinjectAware.swift */, CDD8380D22DA3B0D003E9909 /* BindingEntry.swift */, CD6DE53622DD1CE900532D08 /* BindingKey.swift */, CD6DE53822DD1D0A00532D08 /* BindingRequest.swift */, @@ -375,7 +375,7 @@ files = ( CDD8380C22DA3AD8003E9909 /* Binding.swift in Sources */, CDADF33522DB521400C5D8DB /* SwinjectModule.swift in Sources */, - CDD8381022DA429F003E9909 /* Injector.swift in Sources */, + CDD8381022DA429F003E9909 /* SwinjectAware.swift in Sources */, CD6DE53722DD1CE900532D08 /* BindingKey.swift in Sources */, CD6DE53922DD1D0A00532D08 /* BindingRequest.swift in Sources */, CDADF32322DB416C00C5D8DB /* InstanceBinding.swift in Sources */, @@ -597,10 +597,6 @@ CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)/Carthage/Build/Mac", - ); INFOPLIST_FILE = Tests/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -621,10 +617,6 @@ CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)/Carthage/Build/Mac", - ); INFOPLIST_FILE = Tests/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", diff --git a/Tests/UnitSpecs/SwinjectSpec.swift b/Tests/UnitSpecs/SwinjectSpec.swift index 4252474a..54286154 100644 --- a/Tests/UnitSpecs/SwinjectSpec.swift +++ b/Tests/UnitSpecs/SwinjectSpec.swift @@ -109,16 +109,16 @@ class SwinjectSpec: QuickSpec { override func spec() { it("does not throw if binding matches provided type") { key.matchesReturnValue = true binding.instanceArgInjectorReturnValue = 42 - expect { try swinject.provider(of: Int.self) }.notTo(throwError()) + expect { try swinject.provider(of: Int.self)() }.notTo(throwError()) } it("throws if missing binding for provided type") { key.matchesReturnValue = false - expect { try swinject.provider(of: Int.self) }.to(throwError()) + expect { try swinject.provider(of: Int.self)() }.to(throwError()) } it("does not request provided type until provider is called") { key.matchesReturnValue = true binding.instanceArgInjectorReturnValue = 42 - _ = try? swinject.provider(of: Int.self) + _ = swinject.provider(of: Int.self) expect(binding.instanceArgInjectorCallsCount) == 0 } it("returns instance from binding") { @@ -131,5 +131,10 @@ class SwinjectSpec: QuickSpec { override func spec() { binding.instanceArgInjectorThrowableError = TestError() expect { try swinject.provider(of: Int.self)() }.to(throwError(errorType: TestError.self)) } + it("passes given argument to binding") { + key.matchesReturnValue = true + _ = try? swinject.provider(of: Any.self, arg: 42)() + expect(binding.instanceArgInjectorReceivedArguments?.arg as? Int) == 42 + } } } } From 96b6186683e0ead735a1651f2efa74b40b8b589c Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Tue, 16 Jul 2019 14:37:37 +0200 Subject: [PATCH 038/239] Implement factory injection --- Sources/SwinjectAware.swift | 20 ++++------- Tests/UnitSpecs/SwinjectSpec.swift | 57 +++++++++++++++++++++++++++--- 2 files changed, 59 insertions(+), 18 deletions(-) diff --git a/Sources/SwinjectAware.swift b/Sources/SwinjectAware.swift index cc224938..aff2c2b0 100644 --- a/Sources/SwinjectAware.swift +++ b/Sources/SwinjectAware.swift @@ -6,12 +6,7 @@ public protocol Injector { func instance(for request: BindingRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor } -extension Injector { - // TODO: Get rid of this method - func provider(for request: BindingRequest) -> () throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { - { try self.instance(for: request) } - } -} +extension Injector {} // TODO: Overloads for multiple arguments public extension Injector { @@ -38,18 +33,15 @@ public extension Injector { provider(arg: ()) } - func provider(of _: Type.Type = Type.self, tagged tag: Tag) -> () throws -> Type { - provider(tagged: tag, arg: ()) - } - func provider(of _: Type.Type = Type.self, arg: Argument) -> () throws -> Type { provider(tagged: NoTag(), arg: arg) } func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg: Argument) -> () throws -> Type { - provider(for: BindingRequest, Argument>( - key: BindingKey(descriptor: tagged(Type.self, with: tag)), - argument: arg - )) + return { try self.instance(tagged: NoTag(), arg: arg) } + } + + func factory(of _: Type.Type = Type.self) -> (Argument) throws -> Type { + return { try self.instance(arg: $0) } } } diff --git a/Tests/UnitSpecs/SwinjectSpec.swift b/Tests/UnitSpecs/SwinjectSpec.swift index 54286154..f62b78b7 100644 --- a/Tests/UnitSpecs/SwinjectSpec.swift +++ b/Tests/UnitSpecs/SwinjectSpec.swift @@ -109,11 +109,13 @@ class SwinjectSpec: QuickSpec { override func spec() { it("does not throw if binding matches provided type") { key.matchesReturnValue = true binding.instanceArgInjectorReturnValue = 42 - expect { try swinject.provider(of: Int.self)() }.notTo(throwError()) + let provider = swinject.provider() as () throws -> Int + expect { try provider() }.notTo(throwError()) } it("throws if missing binding for provided type") { key.matchesReturnValue = false - expect { try swinject.provider(of: Int.self)() }.to(throwError()) + let provider = swinject.provider() as () throws -> Int + expect { try provider() }.to(throwError()) } it("does not request provided type until provider is called") { key.matchesReturnValue = true @@ -124,12 +126,14 @@ class SwinjectSpec: QuickSpec { override func spec() { it("returns instance from binding") { key.matchesReturnValue = true binding.instanceArgInjectorReturnValue = 42 - expect { try swinject.provider(of: Int.self)() } == 42 + let provider = swinject.provider(of: Int.self) + expect { try provider() } == 42 } it("rethrows binding error from provider") { key.matchesReturnValue = true binding.instanceArgInjectorThrowableError = TestError() - expect { try swinject.provider(of: Int.self)() }.to(throwError(errorType: TestError.self)) + let provider = swinject.provider(of: Int.self) + expect { try provider() }.to(throwError(errorType: TestError.self)) } it("passes given argument to binding") { key.matchesReturnValue = true @@ -137,4 +141,49 @@ class SwinjectSpec: QuickSpec { override func spec() { expect(binding.instanceArgInjectorReceivedArguments?.arg as? Int) == 42 } } + describe("factory injection") { + var swinject: Swinject! + var binding = AnyBindingMock() + var key = AnyBindingKeyMock() + beforeEach { + binding = AnyBindingMock() + key = AnyBindingKeyMock() + swinject = Swinject { BindingEntry(key: key, binding: binding) } + } + it("throws if missing binding for created type") { + key.matchesReturnValue = false + let factory = swinject.factory() as (String) throws -> Int + expect { try factory("arg") }.to(throwError()) + } + it("does not throw if binding matches created type") { + key.matchesReturnValue = true + binding.instanceArgInjectorReturnValue = 42 + let factory = swinject.factory() as (String) throws -> Int + expect { try factory("arg") }.notTo(throwError()) + } + it("does not request created type until factory is called") { + key.matchesReturnValue = true + binding.instanceArgInjectorReturnValue = 42 + _ = swinject.factory() as (String) throws -> Int + expect(binding.instanceArgInjectorCallsCount) == 0 + } + it("rethrows binding error from factory") { + key.matchesReturnValue = true + binding.instanceArgInjectorThrowableError = TestError() + let factory = swinject.factory() as (String) throws -> Int + expect { try factory("arg") }.to(throwError(errorType: TestError.self)) + } + it("returns instance from binding") { + key.matchesReturnValue = true + binding.instanceArgInjectorReturnValue = 42 + let factory = swinject.factory() as (String) throws -> Int + expect { try factory("arg") } == 42 + } + it("passes given factory argument to binding") { + key.matchesReturnValue = true + binding.instanceArgInjectorReturnValue = 42 + _ = try? swinject.factory(of: Int.self)("arg") + expect(binding.instanceArgInjectorReceivedArguments?.arg as? String) == "arg" + } + } } } From 1665be0558290dd6ce2695f3e1fec4e201bc6389 Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Tue, 16 Jul 2019 15:07:06 +0200 Subject: [PATCH 039/239] Make factory injection work properly with tags --- Sources/{SwinjectAware.swift => Injector.swift} | 12 ++++++++++-- Swinject.xcodeproj/project.pbxproj | 8 ++++---- Tests/UnitSpecs/SwinjectSpec.swift | 14 ++++++++++++++ 3 files changed, 28 insertions(+), 6 deletions(-) rename Sources/{SwinjectAware.swift => Injector.swift} (77%) diff --git a/Sources/SwinjectAware.swift b/Sources/Injector.swift similarity index 77% rename from Sources/SwinjectAware.swift rename to Sources/Injector.swift index aff2c2b0..179f1bd4 100644 --- a/Sources/SwinjectAware.swift +++ b/Sources/Injector.swift @@ -37,11 +37,19 @@ public extension Injector { provider(tagged: NoTag(), arg: arg) } + func provider(of _: Type.Type = Type.self, tagged tag: Tag) -> () throws -> Type { + provider(tagged: tag, arg: ()) + } + func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg: Argument) -> () throws -> Type { - return { try self.instance(tagged: NoTag(), arg: arg) } + return { try self.instance(tagged: tag, arg: arg) } } func factory(of _: Type.Type = Type.self) -> (Argument) throws -> Type { - return { try self.instance(arg: $0) } + factory(tagged: NoTag()) + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Argument) throws -> Type { + return { try self.instance(of: Type.self, tagged: tag, arg: $0) } } } diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 4b56407a..54c8c8ce 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -32,7 +32,7 @@ CDD8380A22DA31D9003E9909 /* TypeBinderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380822DA31C6003E9909 /* TypeBinderSpec.swift */; }; CDD8380C22DA3AD8003E9909 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380B22DA3AD8003E9909 /* Binding.swift */; }; CDD8380E22DA3B0D003E9909 /* BindingEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380D22DA3B0D003E9909 /* BindingEntry.swift */; }; - CDD8381022DA429F003E9909 /* SwinjectAware.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380F22DA429F003E9909 /* SwinjectAware.swift */; }; + CDD8381022DA429F003E9909 /* Injector.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380F22DA429F003E9909 /* Injector.swift */; }; CDD8381622DA4B55003E9909 /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381522DA4B55003E9909 /* Swinject.swift */; }; CDD8381B22DA4CBE003E9909 /* SwinjectSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381922DA4C9F003E9909 /* SwinjectSpec.swift */; }; CDD8381D22DA4E02003E9909 /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381C22DA4E02003E9909 /* SwinjectError.swift */; }; @@ -79,7 +79,7 @@ CDD8380822DA31C6003E9909 /* TypeBinderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinderSpec.swift; sourceTree = ""; }; CDD8380B22DA3AD8003E9909 /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; CDD8380D22DA3B0D003E9909 /* BindingEntry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingEntry.swift; sourceTree = ""; }; - CDD8380F22DA429F003E9909 /* SwinjectAware.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectAware.swift; sourceTree = ""; }; + CDD8380F22DA429F003E9909 /* Injector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Injector.swift; sourceTree = ""; }; CDD8381522DA4B55003E9909 /* Swinject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Swinject.swift; sourceTree = ""; }; CDD8381922DA4C9F003E9909 /* SwinjectSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectSpec.swift; sourceTree = ""; }; CDD8381C22DA4E02003E9909 /* SwinjectError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectError.swift; sourceTree = ""; }; @@ -139,7 +139,7 @@ CD85AF0D22DA57AD00A8B7CA /* ProviderBinding.swift */, CDADF32222DB416C00C5D8DB /* InstanceBinding.swift */, CD6DE53A22DD303F00532D08 /* FactoryBinding.swift */, - CDD8380F22DA429F003E9909 /* SwinjectAware.swift */, + CDD8380F22DA429F003E9909 /* Injector.swift */, CDD8380D22DA3B0D003E9909 /* BindingEntry.swift */, CD6DE53622DD1CE900532D08 /* BindingKey.swift */, CD6DE53822DD1D0A00532D08 /* BindingRequest.swift */, @@ -375,7 +375,7 @@ files = ( CDD8380C22DA3AD8003E9909 /* Binding.swift in Sources */, CDADF33522DB521400C5D8DB /* SwinjectModule.swift in Sources */, - CDD8381022DA429F003E9909 /* SwinjectAware.swift in Sources */, + CDD8381022DA429F003E9909 /* Injector.swift in Sources */, CD6DE53722DD1CE900532D08 /* BindingKey.swift in Sources */, CD6DE53922DD1D0A00532D08 /* BindingRequest.swift in Sources */, CDADF32322DB416C00C5D8DB /* InstanceBinding.swift in Sources */, diff --git a/Tests/UnitSpecs/SwinjectSpec.swift b/Tests/UnitSpecs/SwinjectSpec.swift index f62b78b7..800e7d9d 100644 --- a/Tests/UnitSpecs/SwinjectSpec.swift +++ b/Tests/UnitSpecs/SwinjectSpec.swift @@ -140,6 +140,13 @@ class SwinjectSpec: QuickSpec { override func spec() { _ = try? swinject.provider(of: Any.self, arg: 42)() expect(binding.instanceArgInjectorReceivedArguments?.arg as? Int) == 42 } + it("uses given tag for the key matching") { + key.matchesReturnValue = true + _ = try? swinject.provider(of: Any.self, tagged: "tag")() + let otherKey = key.matchesReceivedOther as? BindingKey, Void> + let descriptor = otherKey?.descriptor as? Tagged + expect(descriptor?.tag) == "tag" + } } describe("factory injection") { var swinject: Swinject! @@ -185,5 +192,12 @@ class SwinjectSpec: QuickSpec { override func spec() { _ = try? swinject.factory(of: Int.self)("arg") expect(binding.instanceArgInjectorReceivedArguments?.arg as? String) == "arg" } + it("uses given tag for the key matching") { + key.matchesReturnValue = false + _ = try? swinject.factory(tagged: "tag")("arg") as Int + let otherKey = key.matchesReceivedOther as? BindingKey, String> + let descriptor = otherKey?.descriptor as? Tagged + expect(descriptor?.tag) == "tag" + } } } } From 28b4370d030e2c10bdd3821a60e833fc5171729b Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Tue, 16 Jul 2019 15:28:27 +0200 Subject: [PATCH 040/239] Implement factory currying --- Sources/Injector.swift | 14 +++++++++++++- Tests/UnitSpecs/SwinjectSpec.swift | 26 ++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/Sources/Injector.swift b/Sources/Injector.swift index 179f1bd4..781420a3 100644 --- a/Sources/Injector.swift +++ b/Sources/Injector.swift @@ -8,7 +8,7 @@ public protocol Injector { extension Injector {} -// TODO: Overloads for multiple arguments +// TODO: Overloads for multiple arguments & tag / notag combinations public extension Injector { func instance(of _: Type.Type = Type.self) throws -> Type { try instance(arg: ()) @@ -52,4 +52,16 @@ public extension Injector { func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Argument) throws -> Type { return { try self.instance(of: Type.self, tagged: tag, arg: $0) } } + + func factory(of _: Type.Type = Type.self, arg: Arg1) -> (Arg2) throws -> Type { + return { try self.instance(of: Type.self, arg: (arg, $0)) } + } + + func factory(of _: Type.Type = Type.self, arg: Arg1) -> (Arg2, Arg3) throws -> Type { + return { try self.instance(of: Type.self, arg: (arg, $0, $1)) } + } + + func factory(of _: Type.Type = Type.self, args arg1: Arg1, _ arg2: Arg2) -> (Arg3) throws -> Type { + return { try self.instance(of: Type.self, arg: (arg1, arg2, $0)) } + } } diff --git a/Tests/UnitSpecs/SwinjectSpec.swift b/Tests/UnitSpecs/SwinjectSpec.swift index 800e7d9d..708811dc 100644 --- a/Tests/UnitSpecs/SwinjectSpec.swift +++ b/Tests/UnitSpecs/SwinjectSpec.swift @@ -199,5 +199,31 @@ class SwinjectSpec: QuickSpec { override func spec() { let descriptor = otherKey?.descriptor as? Tagged expect(descriptor?.tag) == "tag" } + context("currying") { + beforeEach { + key.matchesReturnValue = true + binding.instanceArgInjectorReturnValue = 42 + } + it("can curry 2-tuple as argument") { + _ = try? swinject.factory(arg: "arg1")("arg2") as Int + let receivedArg = binding.instanceArgInjectorReceivedArguments?.arg as? (String, String) + expect(receivedArg?.0) == "arg1" + expect(receivedArg?.1) == "arg2" + } + it("can curry 3-tuple as 1 / 2 argument") { + _ = try? swinject.factory(arg: "arg1")(2, "arg3") as Int + let receivedArg = binding.instanceArgInjectorReceivedArguments?.arg as? (String, Int, String) + expect(receivedArg?.0) == "arg1" + expect(receivedArg?.1) == 2 + expect(receivedArg?.2) == "arg3" + } + it("can curry 3-tuple as 2 / 1 argument") { + _ = try? swinject.factory(args: "arg1", 2)("arg3") as Int + let receivedArg = binding.instanceArgInjectorReceivedArguments?.arg as? (String, Int, String) + expect(receivedArg?.0) == "arg1" + expect(receivedArg?.1) == 2 + expect(receivedArg?.2) == "arg3" + } + } } } } From 5cd43146ed475ed8f8577e6a46a56dfc56c07593 Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Tue, 16 Jul 2019 16:02:02 +0200 Subject: [PATCH 041/239] Cleanup API --- Sources/Binding.swift | 12 ++-- Sources/BindingRequest.swift | 4 ++ Sources/FactoryBinding.swift | 16 +++--- Sources/Injector.swift | 67 ----------------------- Sources/InstanceBinding.swift | 2 +- Sources/ProviderBinding.swift | 8 +-- Sources/Resolver.swift | 46 ++++++++++++++++ Sources/Swinject.swift | 11 +--- Swinject.xcodeproj/project.pbxproj | 8 +-- Tests/Support/GeneratedMocks.swift | 28 +++++----- Tests/Support/NonGeneratedMocks.swift | 6 +- Tests/UnitSpecs/FactoryBindingSpec.swift | 28 +++++----- Tests/UnitSpecs/InstanceBindingSpec.swift | 2 +- Tests/UnitSpecs/ProviderBindingSpec.swift | 18 +++--- Tests/UnitSpecs/SwinjectSpec.swift | 62 +++++++++------------ 15 files changed, 143 insertions(+), 175 deletions(-) delete mode 100644 Sources/Injector.swift create mode 100644 Sources/Resolver.swift diff --git a/Sources/Binding.swift b/Sources/Binding.swift index a4673ecb..677726c4 100644 --- a/Sources/Binding.swift +++ b/Sources/Binding.swift @@ -4,24 +4,24 @@ // sourcery: AutoMockable public protocol AnyBinding { - func instance(arg: Any, injector: Injector) throws -> Any + func instance(arg: Any, resolver: Resolver) throws -> Any } public protocol Binding: AnyBinding { associatedtype BoundType associatedtype Argument - func instance(arg: Argument, injector: Injector) throws -> BoundType + func instance(arg: Argument, resolver: Resolver) throws -> BoundType } public extension Binding where Argument == Void { - func instance(injector: Injector) throws -> BoundType { - try instance(arg: (), injector: injector) + func instance(resolver: Resolver) throws -> BoundType { + try instance(arg: (), resolver: resolver) } } public extension AnyBinding where Self: Binding { - func instance(arg: Any, injector: Injector) throws -> Any { + func instance(arg: Any, resolver: Resolver) throws -> Any { guard let arg = arg as? Argument else { throw SwinjectError() } - return try instance(arg: arg, injector: injector) as BoundType + return try instance(arg: arg, resolver: resolver) as BoundType } } diff --git a/Sources/BindingRequest.swift b/Sources/BindingRequest.swift index 5e53d81b..05363123 100644 --- a/Sources/BindingRequest.swift +++ b/Sources/BindingRequest.swift @@ -6,3 +6,7 @@ public struct BindingRequest where Descriptor: TypeDescrip let key: BindingKey let argument: Argument } + +func request(type _: Type.Type = Type.self, tag: Tag, arg: Argument) -> BindingRequest, Argument> { + BindingRequest(key: BindingKey(descriptor: Tagged(tag: tag)), argument: arg) +} diff --git a/Sources/FactoryBinding.swift b/Sources/FactoryBinding.swift index 98f2b89b..931e231c 100644 --- a/Sources/FactoryBinding.swift +++ b/Sources/FactoryBinding.swift @@ -5,33 +5,33 @@ public struct FactoryBinding: Binding { public typealias BoundType = Type - private let builder: (Injector, Argument) throws -> Type + private let builder: (Resolver, Argument) throws -> Type - init(_ builder: @escaping (Injector, Argument) throws -> Type) { + init(_ builder: @escaping (Resolver, Argument) throws -> Type) { self.builder = builder } - public func instance(arg: Argument, injector provider: Injector) throws -> Type { + public func instance(arg: Argument, resolver provider: Resolver) throws -> Type { try builder(provider, arg) } } -public func factory(_ builder: @escaping (Injector, Arg1) throws -> Type) -> FactoryBinding { +public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> FactoryBinding { FactoryBinding(builder) } -public func factory(_ builder: @escaping (Injector, Arg1, Arg2) throws -> Type) -> FactoryBinding { +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> FactoryBinding { FactoryBinding { try builder($0, $1.0, $1.1) } } -public func factory(_ builder: @escaping (Injector, Arg1, Arg2, Arg3) throws -> Type) -> FactoryBinding { +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> FactoryBinding { FactoryBinding { try builder($0, $1.0, $1.1, $1.2) } } -public func factory(_ builder: @escaping (Injector, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> FactoryBinding { +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> FactoryBinding { FactoryBinding { try builder($0, $1.0, $1.1, $1.2, $1.3) } } -public func factory(_ builder: @escaping (Injector, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> FactoryBinding { +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> FactoryBinding { FactoryBinding { try builder($0, $1.0, $1.1, $1.2, $1.3, $1.4) } } diff --git a/Sources/Injector.swift b/Sources/Injector.swift deleted file mode 100644 index 781420a3..00000000 --- a/Sources/Injector.swift +++ /dev/null @@ -1,67 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -public protocol Injector { - func instance(for request: BindingRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor -} - -extension Injector {} - -// TODO: Overloads for multiple arguments & tag / notag combinations -public extension Injector { - func instance(of _: Type.Type = Type.self) throws -> Type { - try instance(arg: ()) - } - - func instance(of _: Type.Type = Type.self, tagged tag: Tag) throws -> Type { - try instance(tagged: tag, arg: ()) - } - - func instance(of _: Type.Type = Type.self, arg: Argument) throws -> Type { - try instance(tagged: NoTag(), arg: arg) - } - - func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg: Argument) throws -> Type { - try instance(for: BindingRequest, Argument>( - key: BindingKey(descriptor: tagged(Type.self, with: tag)), - argument: arg - )) - } - - func provider(of _: Type.Type = Type.self) -> () throws -> Type { - provider(arg: ()) - } - - func provider(of _: Type.Type = Type.self, arg: Argument) -> () throws -> Type { - provider(tagged: NoTag(), arg: arg) - } - - func provider(of _: Type.Type = Type.self, tagged tag: Tag) -> () throws -> Type { - provider(tagged: tag, arg: ()) - } - - func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg: Argument) -> () throws -> Type { - return { try self.instance(tagged: tag, arg: arg) } - } - - func factory(of _: Type.Type = Type.self) -> (Argument) throws -> Type { - factory(tagged: NoTag()) - } - - func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Argument) throws -> Type { - return { try self.instance(of: Type.self, tagged: tag, arg: $0) } - } - - func factory(of _: Type.Type = Type.self, arg: Arg1) -> (Arg2) throws -> Type { - return { try self.instance(of: Type.self, arg: (arg, $0)) } - } - - func factory(of _: Type.Type = Type.self, arg: Arg1) -> (Arg2, Arg3) throws -> Type { - return { try self.instance(of: Type.self, arg: (arg, $0, $1)) } - } - - func factory(of _: Type.Type = Type.self, args arg1: Arg1, _ arg2: Arg2) -> (Arg3) throws -> Type { - return { try self.instance(of: Type.self, arg: (arg1, arg2, $0)) } - } -} diff --git a/Sources/InstanceBinding.swift b/Sources/InstanceBinding.swift index 1316f001..4c2f9543 100644 --- a/Sources/InstanceBinding.swift +++ b/Sources/InstanceBinding.swift @@ -12,7 +12,7 @@ public struct InstanceBinding: Binding { _instance = instance } - public func instance(arg _: Void, injector _: Injector) throws -> Type { + public func instance(arg _: Void, resolver _: Resolver) throws -> Type { _instance } } diff --git a/Sources/ProviderBinding.swift b/Sources/ProviderBinding.swift index 0d1ac86c..a9789199 100644 --- a/Sources/ProviderBinding.swift +++ b/Sources/ProviderBinding.swift @@ -6,13 +6,13 @@ public struct ProviderBinding: Binding { public typealias BoundType = Type - private let builder: (Injector) throws -> Type + private let builder: (Resolver) throws -> Type - init(_ builder: @escaping (Injector) throws -> Type) { + init(_ builder: @escaping (Resolver) throws -> Type) { self.builder = builder } - public func instance(arg _: Void, injector provider: Injector) throws -> Type { + public func instance(arg _: Void, resolver provider: Resolver) throws -> Type { try builder(provider) } } @@ -21,6 +21,6 @@ public func provider(_ builder: @escaping () throws -> Type) -> ProviderBi ProviderBinding { _ in try builder() } } -public func provider(_ builder: @escaping (Injector) throws -> Type) -> ProviderBinding { +public func provider(_ builder: @escaping (Resolver) throws -> Type) -> ProviderBinding { ProviderBinding(builder) } diff --git a/Sources/Resolver.swift b/Sources/Resolver.swift new file mode 100644 index 00000000..4f7c70a2 --- /dev/null +++ b/Sources/Resolver.swift @@ -0,0 +1,46 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +public protocol Resolver { + func resolve(_ request: BindingRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor +} + +// TODO: Overloads for multiple arguments & tag / notag combinations +public extension Resolver { + func instance(of _: Type.Type = Type.self) throws -> Type { + try instance(tagged: NoTag()) + } + + func instance(of _: Type.Type = Type.self, tagged tag: Tag) throws -> Type { + try resolve(request(tag: tag, arg: ())) + } + + func provider(of _: Type.Type = Type.self) -> () throws -> Type { + provider(tagged: NoTag()) + } + + func provider(of _: Type.Type = Type.self, tagged tag: Tag) -> () throws -> Type { + return { try self.resolve(request(tag: tag, arg: ())) } + } + + func factory(of _: Type.Type = Type.self) -> (Argument) throws -> Type { + factory(tagged: NoTag()) + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Argument) throws -> Type { + return { try self.resolve(request(tag: tag, arg: $0)) } + } + + func factory(of _: Type.Type = Type.self, arg: Arg1) -> (Arg2) throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: (arg, $0))) } + } + + func factory(of _: Type.Type = Type.self, arg: Arg1) -> (Arg2, Arg3) throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: (arg, $0, $1))) } + } + + func factory(of _: Type.Type = Type.self, args arg1: Arg1, _ arg2: Arg2) -> (Arg3) throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: (arg1, arg2, $0))) } + } +} diff --git a/Sources/Swinject.swift b/Sources/Swinject.swift index 30392626..5ef96949 100644 --- a/Sources/Swinject.swift +++ b/Sources/Swinject.swift @@ -24,16 +24,11 @@ public extension Swinject { } } -extension Swinject: Injector { - public func instance(for request: BindingRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { +extension Swinject: Resolver { + public func resolve(_ request: BindingRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { try instance(from: findBinding(for: request.key), arg: request.argument) } - public func provider(for request: BindingRequest) throws -> () throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { - let binding = try findBinding(for: request.key) - return { try self.instance(from: binding, arg: request.argument) } - } - private func findBinding(for key: AnyBindingKey) throws -> AnyBinding { let entries = tree.bindingEntries.filter { $0.key.matches(key) } guard entries.count == 1 else { throw SwinjectError() } @@ -41,6 +36,6 @@ extension Swinject: Injector { } private func instance(from binding: AnyBinding, arg: Argument) throws -> Type { - try binding.instance(arg: arg, injector: self) as? Type ?? { throw SwinjectError() }() + try binding.instance(arg: arg, resolver: self) as? Type ?? { throw SwinjectError() }() } } diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 54c8c8ce..c787ef0a 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -32,7 +32,7 @@ CDD8380A22DA31D9003E9909 /* TypeBinderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380822DA31C6003E9909 /* TypeBinderSpec.swift */; }; CDD8380C22DA3AD8003E9909 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380B22DA3AD8003E9909 /* Binding.swift */; }; CDD8380E22DA3B0D003E9909 /* BindingEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380D22DA3B0D003E9909 /* BindingEntry.swift */; }; - CDD8381022DA429F003E9909 /* Injector.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380F22DA429F003E9909 /* Injector.swift */; }; + CDD8381022DA429F003E9909 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380F22DA429F003E9909 /* Resolver.swift */; }; CDD8381622DA4B55003E9909 /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381522DA4B55003E9909 /* Swinject.swift */; }; CDD8381B22DA4CBE003E9909 /* SwinjectSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381922DA4C9F003E9909 /* SwinjectSpec.swift */; }; CDD8381D22DA4E02003E9909 /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381C22DA4E02003E9909 /* SwinjectError.swift */; }; @@ -79,7 +79,7 @@ CDD8380822DA31C6003E9909 /* TypeBinderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinderSpec.swift; sourceTree = ""; }; CDD8380B22DA3AD8003E9909 /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; CDD8380D22DA3B0D003E9909 /* BindingEntry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingEntry.swift; sourceTree = ""; }; - CDD8380F22DA429F003E9909 /* Injector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Injector.swift; sourceTree = ""; }; + CDD8380F22DA429F003E9909 /* Resolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Resolver.swift; sourceTree = ""; }; CDD8381522DA4B55003E9909 /* Swinject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Swinject.swift; sourceTree = ""; }; CDD8381922DA4C9F003E9909 /* SwinjectSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectSpec.swift; sourceTree = ""; }; CDD8381C22DA4E02003E9909 /* SwinjectError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectError.swift; sourceTree = ""; }; @@ -139,7 +139,7 @@ CD85AF0D22DA57AD00A8B7CA /* ProviderBinding.swift */, CDADF32222DB416C00C5D8DB /* InstanceBinding.swift */, CD6DE53A22DD303F00532D08 /* FactoryBinding.swift */, - CDD8380F22DA429F003E9909 /* Injector.swift */, + CDD8380F22DA429F003E9909 /* Resolver.swift */, CDD8380D22DA3B0D003E9909 /* BindingEntry.swift */, CD6DE53622DD1CE900532D08 /* BindingKey.swift */, CD6DE53822DD1D0A00532D08 /* BindingRequest.swift */, @@ -375,7 +375,7 @@ files = ( CDD8380C22DA3AD8003E9909 /* Binding.swift in Sources */, CDADF33522DB521400C5D8DB /* SwinjectModule.swift in Sources */, - CDD8381022DA429F003E9909 /* Injector.swift in Sources */, + CDD8381022DA429F003E9909 /* Resolver.swift in Sources */, CD6DE53722DD1CE900532D08 /* BindingKey.swift in Sources */, CD6DE53922DD1D0A00532D08 /* BindingRequest.swift in Sources */, CDADF32322DB416C00C5D8DB /* InstanceBinding.swift in Sources */, diff --git a/Tests/Support/GeneratedMocks.swift b/Tests/Support/GeneratedMocks.swift index 0d8a4482..6972c6d4 100644 --- a/Tests/Support/GeneratedMocks.swift +++ b/Tests/Support/GeneratedMocks.swift @@ -10,25 +10,25 @@ class AnyBindingMock: AnyBinding { // MARK: - instance - var instanceArgInjectorThrowableError: Error? - var instanceArgInjectorCallsCount = 0 - var instanceArgInjectorCalled: Bool { - return instanceArgInjectorCallsCount > 0 + var instanceArgResolverThrowableError: Error? + var instanceArgResolverCallsCount = 0 + var instanceArgResolverCalled: Bool { + return instanceArgResolverCallsCount > 0 } - var instanceArgInjectorReceivedArguments: (arg: Any, injector: Injector)? - var instanceArgInjectorReceivedInvocations: [(arg: Any, injector: Injector)] = [] - var instanceArgInjectorReturnValue: Any! - var instanceArgInjectorClosure: ((Any, Injector) throws -> Any)? + var instanceArgResolverReceivedArguments: (arg: Any, resolver: Resolver)? + var instanceArgResolverReceivedInvocations: [(arg: Any, resolver: Resolver)] = [] + var instanceArgResolverReturnValue: Any! + var instanceArgResolverClosure: ((Any, Resolver) throws -> Any)? - func instance(arg: Any, injector: Injector) throws -> Any { - if let error = instanceArgInjectorThrowableError { + func instance(arg: Any, resolver: Resolver) throws -> Any { + if let error = instanceArgResolverThrowableError { throw error } - instanceArgInjectorCallsCount += 1 - instanceArgInjectorReceivedArguments = (arg: arg, injector: injector) - instanceArgInjectorReceivedInvocations.append((arg: arg, injector: injector)) - return try instanceArgInjectorClosure.map { try $0(arg, injector) } ?? instanceArgInjectorReturnValue + instanceArgResolverCallsCount += 1 + instanceArgResolverReceivedArguments = (arg: arg, resolver: resolver) + instanceArgResolverReceivedInvocations.append((arg: arg, resolver: resolver)) + return try instanceArgResolverClosure.map { try $0(arg, resolver) } ?? instanceArgResolverReturnValue } } diff --git a/Tests/Support/NonGeneratedMocks.swift b/Tests/Support/NonGeneratedMocks.swift index 4532f367..ebf194ec 100644 --- a/Tests/Support/NonGeneratedMocks.swift +++ b/Tests/Support/NonGeneratedMocks.swift @@ -4,8 +4,8 @@ @testable import Swinject -class DummyInjector: Injector { - func instance(for _: BindingRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { +class DummyResolver: Resolver { + func resolve(_ _: BindingRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { fatalError() } @@ -23,7 +23,7 @@ extension AnyBindingMock: Binding { } class DummyBinding: Binding { - func instance(arg _: Argument, injector _: Injector) throws -> Any { + func instance(arg _: Argument, resolver _: Resolver) throws -> Any { fatalError() } } diff --git a/Tests/UnitSpecs/FactoryBindingSpec.swift b/Tests/UnitSpecs/FactoryBindingSpec.swift index b573267a..903ff394 100644 --- a/Tests/UnitSpecs/FactoryBindingSpec.swift +++ b/Tests/UnitSpecs/FactoryBindingSpec.swift @@ -9,7 +9,7 @@ import Quick class FactoryBindingSpec: QuickSpec { override func spec() { it("returns instance made by builder method") { let binding = factory { (_, _: Void) in 42 } - expect { try binding.instance(injector: DummyInjector()) } == 42 + expect { try binding.instance(resolver: DummyResolver()) } == 42 } it("does not call builder until instance is requested") { var called = false @@ -17,48 +17,48 @@ class FactoryBindingSpec: QuickSpec { override func spec() { expect(called).to(beFalse()) } it("calls builder with given provider") { - var passedInjector: Injector? - let injector = DummyInjector() - let binding = factory { (_, _: Void) in passedInjector = injector } - _ = try? binding.instance(injector: injector) - expect(passedInjector) === injector + var passedResolver: Resolver? + let resolver = DummyResolver() + let binding = factory { (_, _: Void) in passedResolver = resolver } + _ = try? binding.instance(resolver: resolver) + expect(passedResolver) === resolver } it("calls builder with given argument") { var passedArgument: Int? let binding = factory { (_, arg: Int) in passedArgument = arg } - _ = try? binding.instance(arg: 42, injector: DummyInjector()) + _ = try? binding.instance(arg: 42, resolver: DummyResolver()) expect(passedArgument) == 42 } it("rethrows error from builder") { let binding = factory { (_, _: Void) in throw SwinjectError() } - expect { try binding.instance(injector: DummyInjector()) }.to(throwError()) + expect { try binding.instance(resolver: DummyResolver()) }.to(throwError()) } it("does not reuse instance") { let binding = factory { (_, _: Void) in Person() } - let instance1 = try? binding.instance(injector: DummyInjector()) - let instance2 = try? binding.instance(injector: DummyInjector()) + let instance1 = try? binding.instance(resolver: DummyResolver()) + let instance2 = try? binding.instance(resolver: DummyResolver()) expect(instance1) !== instance2 } describe("multiple arguments") { it("works with 2 arguments") { let binding = factory { (_, _: Int, _: Double) in 42 } let arguments = (1, 1.0) - expect { try binding.instance(arg: arguments, injector: DummyInjector()) } == 42 + expect { try binding.instance(arg: arguments, resolver: DummyResolver()) } == 42 } it("works with 3 arguments") { let binding = factory { (_, _: Int, _: Double, _: String) in 42 } let arguments = (1, 1.0, "") - expect { try binding.instance(arg: arguments, injector: DummyInjector()) } == 42 + expect { try binding.instance(arg: arguments, resolver: DummyResolver()) } == 42 } it("works with 4 arguments") { let binding = factory { (_, _: Int, _: Double, _: String, _: Float) in 42 } let arguments = (1, 1.0, "", Float(1.0)) - expect { try binding.instance(arg: arguments, injector: DummyInjector()) } == 42 + expect { try binding.instance(arg: arguments, resolver: DummyResolver()) } == 42 } it("works with 5 arguments") { let binding = factory { (_, _: Int, _: Double, _: String, _: Float, _: Int) in 42 } let arguments = (1, 1.0, "", Float(1.0), 5) - expect { try binding.instance(arg: arguments, injector: DummyInjector()) } == 42 + expect { try binding.instance(arg: arguments, resolver: DummyResolver()) } == 42 } } } } diff --git a/Tests/UnitSpecs/InstanceBindingSpec.swift b/Tests/UnitSpecs/InstanceBindingSpec.swift index 45d4299c..5f1f5793 100644 --- a/Tests/UnitSpecs/InstanceBindingSpec.swift +++ b/Tests/UnitSpecs/InstanceBindingSpec.swift @@ -9,6 +9,6 @@ import Quick class InstanceBindingSpec: QuickSpec { override func spec() { it("returns given instance") { let binding = instance(42) - expect { try binding.instance(injector: DummyInjector()) } == 42 + expect { try binding.instance(resolver: DummyResolver()) } == 42 } } } diff --git a/Tests/UnitSpecs/ProviderBindingSpec.swift b/Tests/UnitSpecs/ProviderBindingSpec.swift index 728c7346..837d6715 100644 --- a/Tests/UnitSpecs/ProviderBindingSpec.swift +++ b/Tests/UnitSpecs/ProviderBindingSpec.swift @@ -9,7 +9,7 @@ import Quick class ProviderBindingSpec: QuickSpec { override func spec() { it("returns instance made by provider method") { let binding = provider { 42 } - expect { try binding.instance(injector: DummyInjector()) } == 42 + expect { try binding.instance(resolver: DummyResolver()) } == 42 } it("does not call builder until instance is requested") { var called = false @@ -17,20 +17,20 @@ class ProviderBindingSpec: QuickSpec { override func spec() { expect(called).to(beFalse()) } it("calls builder with given provider") { - var passedInjector: Injector? - let injector = DummyInjector() - let binding = provider { passedInjector = $0 } - _ = try? binding.instance(injector: injector) - expect(passedInjector) === injector + var passedResolver: Resolver? + let resolver = DummyResolver() + let binding = provider { passedResolver = $0 } + _ = try? binding.instance(resolver: resolver) + expect(passedResolver) === resolver } it("rethrows error from builder") { let binding = provider { throw SwinjectError() } - expect { try binding.instance(injector: DummyInjector()) }.to(throwError()) + expect { try binding.instance(resolver: DummyResolver()) }.to(throwError()) } it("does not reuse instance") { let binding = provider { Person() } - let instance1 = try? binding.instance(injector: DummyInjector()) - let instance2 = try? binding.instance(injector: DummyInjector()) + let instance1 = try? binding.instance(resolver: DummyResolver()) + let instance2 = try? binding.instance(resolver: DummyResolver()) expect(instance1) !== instance2 } } } diff --git a/Tests/UnitSpecs/SwinjectSpec.swift b/Tests/UnitSpecs/SwinjectSpec.swift index 708811dc..360f54a3 100644 --- a/Tests/UnitSpecs/SwinjectSpec.swift +++ b/Tests/UnitSpecs/SwinjectSpec.swift @@ -26,46 +26,41 @@ class SwinjectSpec: QuickSpec { override func spec() { it("request instance from matching binding") { key.matchesReturnValue = true _ = try? swinject.instance(of: Any.self) - expect(binding.instanceArgInjectorCallsCount) == 1 + expect(binding.instanceArgResolverCallsCount) == 1 } it("does not request instance from matching binding until instance is required") { key.matchesReturnValue = true - expect(binding.instanceArgInjectorCallsCount) == 0 + expect(binding.instanceArgResolverCallsCount) == 0 } it("only requests instance from matching binding") { key.matchesReturnValue = false _ = try? swinject.instance(of: Any.self) - expect(binding.instanceArgInjectorCallsCount) == 0 + expect(binding.instanceArgResolverCallsCount) == 0 } it("returns instance produced by binding") { key.matchesReturnValue = true - binding.instanceArgInjectorReturnValue = 42 + binding.instanceArgResolverReturnValue = 42 expect { try swinject.instance(of: Any.self) as? Int } == 42 } it("rethrows error from binding") { key.matchesReturnValue = true - binding.instanceArgInjectorThrowableError = TestError() + binding.instanceArgResolverThrowableError = TestError() expect { try swinject.instance(of: Any.self) }.to(throwError(errorType: TestError.self)) } it("crashes if bound type does not match requested type") { key.matchesReturnValue = true - binding.instanceArgInjectorReturnValue = "" + binding.instanceArgResolverReturnValue = "" expect { _ = try swinject.instance(of: Double.self) }.to(throwError()) } it("does not crash if bound type conforms to the requested type") { key.matchesReturnValue = true - binding.instanceArgInjectorReturnValue = 42 + binding.instanceArgResolverReturnValue = 42 expect { _ = try swinject.instance(of: CustomStringConvertible?.self) }.notTo(throwError()) } - it("passes swinject as injector") { + it("passes swinject as resolver") { key.matchesReturnValue = true _ = try? swinject.instance(of: Any.self) - expect(binding.instanceArgInjectorReceivedArguments?.injector is Swinject).to(beTrue()) - } - it("passes given argument to binding") { - key.matchesReturnValue = true - _ = try? swinject.instance(of: Any.self, arg: 42) - expect(binding.instanceArgInjectorReceivedArguments?.arg as? Int) == 42 + expect(binding.instanceArgResolverReceivedArguments?.resolver is Swinject).to(beTrue()) } } context("multiple bindings") { @@ -92,7 +87,7 @@ class SwinjectSpec: QuickSpec { override func spec() { } it("returns instance from matching binding") { keys[1].matchesReturnValue = true - bindings[1].instanceArgInjectorReturnValue = 42 + bindings[1].instanceArgResolverReturnValue = 42 expect { try swinject.instance(of: Int.self) } == 42 } } @@ -108,7 +103,7 @@ class SwinjectSpec: QuickSpec { override func spec() { } it("does not throw if binding matches provided type") { key.matchesReturnValue = true - binding.instanceArgInjectorReturnValue = 42 + binding.instanceArgResolverReturnValue = 42 let provider = swinject.provider() as () throws -> Int expect { try provider() }.notTo(throwError()) } @@ -119,27 +114,22 @@ class SwinjectSpec: QuickSpec { override func spec() { } it("does not request provided type until provider is called") { key.matchesReturnValue = true - binding.instanceArgInjectorReturnValue = 42 + binding.instanceArgResolverReturnValue = 42 _ = swinject.provider(of: Int.self) - expect(binding.instanceArgInjectorCallsCount) == 0 + expect(binding.instanceArgResolverCallsCount) == 0 } it("returns instance from binding") { key.matchesReturnValue = true - binding.instanceArgInjectorReturnValue = 42 + binding.instanceArgResolverReturnValue = 42 let provider = swinject.provider(of: Int.self) expect { try provider() } == 42 } it("rethrows binding error from provider") { key.matchesReturnValue = true - binding.instanceArgInjectorThrowableError = TestError() + binding.instanceArgResolverThrowableError = TestError() let provider = swinject.provider(of: Int.self) expect { try provider() }.to(throwError(errorType: TestError.self)) } - it("passes given argument to binding") { - key.matchesReturnValue = true - _ = try? swinject.provider(of: Any.self, arg: 42)() - expect(binding.instanceArgInjectorReceivedArguments?.arg as? Int) == 42 - } it("uses given tag for the key matching") { key.matchesReturnValue = true _ = try? swinject.provider(of: Any.self, tagged: "tag")() @@ -164,33 +154,33 @@ class SwinjectSpec: QuickSpec { override func spec() { } it("does not throw if binding matches created type") { key.matchesReturnValue = true - binding.instanceArgInjectorReturnValue = 42 + binding.instanceArgResolverReturnValue = 42 let factory = swinject.factory() as (String) throws -> Int expect { try factory("arg") }.notTo(throwError()) } it("does not request created type until factory is called") { key.matchesReturnValue = true - binding.instanceArgInjectorReturnValue = 42 + binding.instanceArgResolverReturnValue = 42 _ = swinject.factory() as (String) throws -> Int - expect(binding.instanceArgInjectorCallsCount) == 0 + expect(binding.instanceArgResolverCallsCount) == 0 } it("rethrows binding error from factory") { key.matchesReturnValue = true - binding.instanceArgInjectorThrowableError = TestError() + binding.instanceArgResolverThrowableError = TestError() let factory = swinject.factory() as (String) throws -> Int expect { try factory("arg") }.to(throwError(errorType: TestError.self)) } it("returns instance from binding") { key.matchesReturnValue = true - binding.instanceArgInjectorReturnValue = 42 + binding.instanceArgResolverReturnValue = 42 let factory = swinject.factory() as (String) throws -> Int expect { try factory("arg") } == 42 } it("passes given factory argument to binding") { key.matchesReturnValue = true - binding.instanceArgInjectorReturnValue = 42 + binding.instanceArgResolverReturnValue = 42 _ = try? swinject.factory(of: Int.self)("arg") - expect(binding.instanceArgInjectorReceivedArguments?.arg as? String) == "arg" + expect(binding.instanceArgResolverReceivedArguments?.arg as? String) == "arg" } it("uses given tag for the key matching") { key.matchesReturnValue = false @@ -202,24 +192,24 @@ class SwinjectSpec: QuickSpec { override func spec() { context("currying") { beforeEach { key.matchesReturnValue = true - binding.instanceArgInjectorReturnValue = 42 + binding.instanceArgResolverReturnValue = 42 } it("can curry 2-tuple as argument") { _ = try? swinject.factory(arg: "arg1")("arg2") as Int - let receivedArg = binding.instanceArgInjectorReceivedArguments?.arg as? (String, String) + let receivedArg = binding.instanceArgResolverReceivedArguments?.arg as? (String, String) expect(receivedArg?.0) == "arg1" expect(receivedArg?.1) == "arg2" } it("can curry 3-tuple as 1 / 2 argument") { _ = try? swinject.factory(arg: "arg1")(2, "arg3") as Int - let receivedArg = binding.instanceArgInjectorReceivedArguments?.arg as? (String, Int, String) + let receivedArg = binding.instanceArgResolverReceivedArguments?.arg as? (String, Int, String) expect(receivedArg?.0) == "arg1" expect(receivedArg?.1) == 2 expect(receivedArg?.2) == "arg3" } it("can curry 3-tuple as 2 / 1 argument") { _ = try? swinject.factory(args: "arg1", 2)("arg3") as Int - let receivedArg = binding.instanceArgInjectorReceivedArguments?.arg as? (String, Int, String) + let receivedArg = binding.instanceArgResolverReceivedArguments?.arg as? (String, Int, String) expect(receivedArg?.0) == "arg1" expect(receivedArg?.1) == 2 expect(receivedArg?.2) == "arg3" From 57e3c8f9c28c926b5260cadc17c65cfd02af0b83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Tue, 16 Jul 2019 21:55:17 +0200 Subject: [PATCH 042/239] Add context to binding invocation --- Sources/Binding.swift | 27 +++++++++++---- Sources/FactoryBinding.swift | 4 +-- Sources/InstanceBinding.swift | 2 +- Sources/ProviderBinding.swift | 2 +- Sources/Swinject.swift | 2 +- Tests/Support/GeneratedMocks.swift | 28 +++++++-------- Tests/Support/NonGeneratedMocks.swift | 2 +- Tests/UnitSpecs/SwinjectSpec.swift | 50 +++++++++++++-------------- 8 files changed, 65 insertions(+), 52 deletions(-) diff --git a/Sources/Binding.swift b/Sources/Binding.swift index 677726c4..5c413e3b 100644 --- a/Sources/Binding.swift +++ b/Sources/Binding.swift @@ -4,24 +4,37 @@ // sourcery: AutoMockable public protocol AnyBinding { - func instance(arg: Any, resolver: Resolver) throws -> Any + func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any } public protocol Binding: AnyBinding { associatedtype BoundType associatedtype Argument - func instance(arg: Argument, resolver: Resolver) throws -> BoundType + associatedtype Context + func instance(arg: Argument, context: Context, resolver: Resolver) throws -> BoundType } -public extension Binding where Argument == Void { +extension Binding where Argument == Void, Context == Void { func instance(resolver: Resolver) throws -> BoundType { - try instance(arg: (), resolver: resolver) + try instance(arg: (), context: (), resolver: resolver) + } +} + +extension Binding where Argument == Void { + func instance(context: Context, resolver: Resolver) throws -> BoundType { + try instance(arg: (), context: context, resolver: resolver) + } +} + +extension Binding where Context == Void { + func instance(arg: Argument, resolver: Resolver) throws -> BoundType { + try instance(arg: arg, context: (), resolver: resolver) } } public extension AnyBinding where Self: Binding { - func instance(arg: Any, resolver: Resolver) throws -> Any { - guard let arg = arg as? Argument else { throw SwinjectError() } - return try instance(arg: arg, resolver: resolver) as BoundType + func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any { + guard let arg = arg as? Argument, let context = context as? Context else { throw SwinjectError() } + return try instance(arg: arg, context: context, resolver: resolver) as BoundType } } diff --git a/Sources/FactoryBinding.swift b/Sources/FactoryBinding.swift index 931e231c..b91faa3e 100644 --- a/Sources/FactoryBinding.swift +++ b/Sources/FactoryBinding.swift @@ -11,8 +11,8 @@ public struct FactoryBinding: Binding { self.builder = builder } - public func instance(arg: Argument, resolver provider: Resolver) throws -> Type { - try builder(provider, arg) + public func instance(arg: Argument, context _: Void, resolver: Resolver) throws -> Type { + try builder(resolver, arg) } } diff --git a/Sources/InstanceBinding.swift b/Sources/InstanceBinding.swift index 4c2f9543..2a21ea82 100644 --- a/Sources/InstanceBinding.swift +++ b/Sources/InstanceBinding.swift @@ -12,7 +12,7 @@ public struct InstanceBinding: Binding { _instance = instance } - public func instance(arg _: Void, resolver _: Resolver) throws -> Type { + public func instance(arg _: Void, context: Void, resolver _: Resolver) throws -> Type { _instance } } diff --git a/Sources/ProviderBinding.swift b/Sources/ProviderBinding.swift index a9789199..b1b1ddb3 100644 --- a/Sources/ProviderBinding.swift +++ b/Sources/ProviderBinding.swift @@ -12,7 +12,7 @@ public struct ProviderBinding: Binding { self.builder = builder } - public func instance(arg _: Void, resolver provider: Resolver) throws -> Type { + public func instance(arg _: Void, context: Void, resolver provider: Resolver) throws -> Type { try builder(provider) } } diff --git a/Sources/Swinject.swift b/Sources/Swinject.swift index 5ef96949..e5514637 100644 --- a/Sources/Swinject.swift +++ b/Sources/Swinject.swift @@ -36,6 +36,6 @@ extension Swinject: Resolver { } private func instance(from binding: AnyBinding, arg: Argument) throws -> Type { - try binding.instance(arg: arg, resolver: self) as? Type ?? { throw SwinjectError() }() + try binding.instance(arg: arg, context: (), resolver: self) as? Type ?? { throw SwinjectError() }() } } diff --git a/Tests/Support/GeneratedMocks.swift b/Tests/Support/GeneratedMocks.swift index 6972c6d4..80e17ab4 100644 --- a/Tests/Support/GeneratedMocks.swift +++ b/Tests/Support/GeneratedMocks.swift @@ -10,25 +10,25 @@ class AnyBindingMock: AnyBinding { // MARK: - instance - var instanceArgResolverThrowableError: Error? - var instanceArgResolverCallsCount = 0 - var instanceArgResolverCalled: Bool { - return instanceArgResolverCallsCount > 0 + var instanceArgContextResolverThrowableError: Error? + var instanceArgContextResolverCallsCount = 0 + var instanceArgContextResolverCalled: Bool { + return instanceArgContextResolverCallsCount > 0 } - var instanceArgResolverReceivedArguments: (arg: Any, resolver: Resolver)? - var instanceArgResolverReceivedInvocations: [(arg: Any, resolver: Resolver)] = [] - var instanceArgResolverReturnValue: Any! - var instanceArgResolverClosure: ((Any, Resolver) throws -> Any)? + var instanceArgContextResolverReceivedArguments: (arg: Any, context: Any, resolver: Resolver)? + var instanceArgContextResolverReceivedInvocations: [(arg: Any, context: Any, resolver: Resolver)] = [] + var instanceArgContextResolverReturnValue: Any! + var instanceArgContextResolverClosure: ((Any, Any, Resolver) throws -> Any)? - func instance(arg: Any, resolver: Resolver) throws -> Any { - if let error = instanceArgResolverThrowableError { + func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any { + if let error = instanceArgContextResolverThrowableError { throw error } - instanceArgResolverCallsCount += 1 - instanceArgResolverReceivedArguments = (arg: arg, resolver: resolver) - instanceArgResolverReceivedInvocations.append((arg: arg, resolver: resolver)) - return try instanceArgResolverClosure.map { try $0(arg, resolver) } ?? instanceArgResolverReturnValue + instanceArgContextResolverCallsCount += 1 + instanceArgContextResolverReceivedArguments = (arg: arg, context: context, resolver: resolver) + instanceArgContextResolverReceivedInvocations.append((arg: arg, context: context, resolver: resolver)) + return try instanceArgContextResolverClosure.map { try $0(arg, context, resolver) } ?? instanceArgContextResolverReturnValue } } diff --git a/Tests/Support/NonGeneratedMocks.swift b/Tests/Support/NonGeneratedMocks.swift index ebf194ec..a404585b 100644 --- a/Tests/Support/NonGeneratedMocks.swift +++ b/Tests/Support/NonGeneratedMocks.swift @@ -23,7 +23,7 @@ extension AnyBindingMock: Binding { } class DummyBinding: Binding { - func instance(arg _: Argument, resolver _: Resolver) throws -> Any { + func instance(arg _: Argument, context: Void, resolver _: Resolver) throws -> Any { fatalError() } } diff --git a/Tests/UnitSpecs/SwinjectSpec.swift b/Tests/UnitSpecs/SwinjectSpec.swift index 360f54a3..821a087a 100644 --- a/Tests/UnitSpecs/SwinjectSpec.swift +++ b/Tests/UnitSpecs/SwinjectSpec.swift @@ -26,41 +26,41 @@ class SwinjectSpec: QuickSpec { override func spec() { it("request instance from matching binding") { key.matchesReturnValue = true _ = try? swinject.instance(of: Any.self) - expect(binding.instanceArgResolverCallsCount) == 1 + expect(binding.instanceArgContextResolverCallsCount) == 1 } it("does not request instance from matching binding until instance is required") { key.matchesReturnValue = true - expect(binding.instanceArgResolverCallsCount) == 0 + expect(binding.instanceArgContextResolverCallsCount) == 0 } it("only requests instance from matching binding") { key.matchesReturnValue = false _ = try? swinject.instance(of: Any.self) - expect(binding.instanceArgResolverCallsCount) == 0 + expect(binding.instanceArgContextResolverCallsCount) == 0 } it("returns instance produced by binding") { key.matchesReturnValue = true - binding.instanceArgResolverReturnValue = 42 + binding.instanceArgContextResolverReturnValue = 42 expect { try swinject.instance(of: Any.self) as? Int } == 42 } it("rethrows error from binding") { key.matchesReturnValue = true - binding.instanceArgResolverThrowableError = TestError() + binding.instanceArgContextResolverThrowableError = TestError() expect { try swinject.instance(of: Any.self) }.to(throwError(errorType: TestError.self)) } it("crashes if bound type does not match requested type") { key.matchesReturnValue = true - binding.instanceArgResolverReturnValue = "" + binding.instanceArgContextResolverReturnValue = "" expect { _ = try swinject.instance(of: Double.self) }.to(throwError()) } it("does not crash if bound type conforms to the requested type") { key.matchesReturnValue = true - binding.instanceArgResolverReturnValue = 42 + binding.instanceArgContextResolverReturnValue = 42 expect { _ = try swinject.instance(of: CustomStringConvertible?.self) }.notTo(throwError()) } it("passes swinject as resolver") { key.matchesReturnValue = true _ = try? swinject.instance(of: Any.self) - expect(binding.instanceArgResolverReceivedArguments?.resolver is Swinject).to(beTrue()) + expect(binding.instanceArgContextResolverReceivedArguments?.resolver is Swinject).to(beTrue()) } } context("multiple bindings") { @@ -87,7 +87,7 @@ class SwinjectSpec: QuickSpec { override func spec() { } it("returns instance from matching binding") { keys[1].matchesReturnValue = true - bindings[1].instanceArgResolverReturnValue = 42 + bindings[1].instanceArgContextResolverReturnValue = 42 expect { try swinject.instance(of: Int.self) } == 42 } } @@ -103,7 +103,7 @@ class SwinjectSpec: QuickSpec { override func spec() { } it("does not throw if binding matches provided type") { key.matchesReturnValue = true - binding.instanceArgResolverReturnValue = 42 + binding.instanceArgContextResolverReturnValue = 42 let provider = swinject.provider() as () throws -> Int expect { try provider() }.notTo(throwError()) } @@ -114,19 +114,19 @@ class SwinjectSpec: QuickSpec { override func spec() { } it("does not request provided type until provider is called") { key.matchesReturnValue = true - binding.instanceArgResolverReturnValue = 42 + binding.instanceArgContextResolverReturnValue = 42 _ = swinject.provider(of: Int.self) - expect(binding.instanceArgResolverCallsCount) == 0 + expect(binding.instanceArgContextResolverCallsCount) == 0 } it("returns instance from binding") { key.matchesReturnValue = true - binding.instanceArgResolverReturnValue = 42 + binding.instanceArgContextResolverReturnValue = 42 let provider = swinject.provider(of: Int.self) expect { try provider() } == 42 } it("rethrows binding error from provider") { key.matchesReturnValue = true - binding.instanceArgResolverThrowableError = TestError() + binding.instanceArgContextResolverThrowableError = TestError() let provider = swinject.provider(of: Int.self) expect { try provider() }.to(throwError(errorType: TestError.self)) } @@ -154,33 +154,33 @@ class SwinjectSpec: QuickSpec { override func spec() { } it("does not throw if binding matches created type") { key.matchesReturnValue = true - binding.instanceArgResolverReturnValue = 42 + binding.instanceArgContextResolverReturnValue = 42 let factory = swinject.factory() as (String) throws -> Int expect { try factory("arg") }.notTo(throwError()) } it("does not request created type until factory is called") { key.matchesReturnValue = true - binding.instanceArgResolverReturnValue = 42 + binding.instanceArgContextResolverReturnValue = 42 _ = swinject.factory() as (String) throws -> Int - expect(binding.instanceArgResolverCallsCount) == 0 + expect(binding.instanceArgContextResolverCallsCount) == 0 } it("rethrows binding error from factory") { key.matchesReturnValue = true - binding.instanceArgResolverThrowableError = TestError() + binding.instanceArgContextResolverThrowableError = TestError() let factory = swinject.factory() as (String) throws -> Int expect { try factory("arg") }.to(throwError(errorType: TestError.self)) } it("returns instance from binding") { key.matchesReturnValue = true - binding.instanceArgResolverReturnValue = 42 + binding.instanceArgContextResolverReturnValue = 42 let factory = swinject.factory() as (String) throws -> Int expect { try factory("arg") } == 42 } it("passes given factory argument to binding") { key.matchesReturnValue = true - binding.instanceArgResolverReturnValue = 42 + binding.instanceArgContextResolverReturnValue = 42 _ = try? swinject.factory(of: Int.self)("arg") - expect(binding.instanceArgResolverReceivedArguments?.arg as? String) == "arg" + expect(binding.instanceArgContextResolverReceivedArguments?.arg as? String) == "arg" } it("uses given tag for the key matching") { key.matchesReturnValue = false @@ -192,24 +192,24 @@ class SwinjectSpec: QuickSpec { override func spec() { context("currying") { beforeEach { key.matchesReturnValue = true - binding.instanceArgResolverReturnValue = 42 + binding.instanceArgContextResolverReturnValue = 42 } it("can curry 2-tuple as argument") { _ = try? swinject.factory(arg: "arg1")("arg2") as Int - let receivedArg = binding.instanceArgResolverReceivedArguments?.arg as? (String, String) + let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? (String, String) expect(receivedArg?.0) == "arg1" expect(receivedArg?.1) == "arg2" } it("can curry 3-tuple as 1 / 2 argument") { _ = try? swinject.factory(arg: "arg1")(2, "arg3") as Int - let receivedArg = binding.instanceArgResolverReceivedArguments?.arg as? (String, Int, String) + let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? (String, Int, String) expect(receivedArg?.0) == "arg1" expect(receivedArg?.1) == 2 expect(receivedArg?.2) == "arg3" } it("can curry 3-tuple as 2 / 1 argument") { _ = try? swinject.factory(args: "arg1", 2)("arg3") as Int - let receivedArg = binding.instanceArgResolverReceivedArguments?.arg as? (String, Int, String) + let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? (String, Int, String) expect(receivedArg?.0) == "arg1" expect(receivedArg?.1) == 2 expect(receivedArg?.2) == "arg3" From 8a4d28f54f52b4fb9ef57d3ccafb5c8f648f4e37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Tue, 16 Jul 2019 22:12:21 +0200 Subject: [PATCH 043/239] Refactor bindings to single internal representation --- Sources/BindingBuilder.swift | 35 ++++++++ Sources/FactoryBinding.swift | 37 -------- Sources/InstanceBinding.swift | 22 ----- Sources/ProviderBinding.swift | 26 ------ Sources/SimpleBinding.swift | 19 ++++ Swinject.xcodeproj/project.pbxproj | 36 +++----- Tests/Support/Utils.swift | 1 - Tests/UnitSpecs/BindingBuilderSpec.swift | 100 ++++++++++++++++++++++ Tests/UnitSpecs/FactoryBindingSpec.swift | 64 -------------- Tests/UnitSpecs/InstanceBindingSpec.swift | 14 --- Tests/UnitSpecs/ProviderBindingSpec.swift | 36 -------- Tests/UnitSpecs/TypeBinderSpec.swift | 4 +- 12 files changed, 168 insertions(+), 226 deletions(-) create mode 100644 Sources/BindingBuilder.swift delete mode 100644 Sources/FactoryBinding.swift delete mode 100644 Sources/InstanceBinding.swift delete mode 100644 Sources/ProviderBinding.swift create mode 100644 Sources/SimpleBinding.swift create mode 100644 Tests/UnitSpecs/BindingBuilderSpec.swift delete mode 100644 Tests/UnitSpecs/FactoryBindingSpec.swift delete mode 100644 Tests/UnitSpecs/InstanceBindingSpec.swift delete mode 100644 Tests/UnitSpecs/ProviderBindingSpec.swift diff --git a/Sources/BindingBuilder.swift b/Sources/BindingBuilder.swift new file mode 100644 index 00000000..c2368784 --- /dev/null +++ b/Sources/BindingBuilder.swift @@ -0,0 +1,35 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +public func instance(_ instance: Type) -> SimpleBinding { + SimpleBinding { _, _ in instance } +} + +public func provider(_ builder: @escaping () throws -> Type) -> SimpleBinding { + SimpleBinding { _, _ in try builder() } +} + +public func provider(_ builder: @escaping (Resolver) throws -> Type) -> SimpleBinding { + SimpleBinding { resolver, _ in try builder(resolver) } +} + +public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> SimpleBinding { + SimpleBinding(builder) +} + +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SimpleBinding { + SimpleBinding { try builder($0, $1.0, $1.1) } +} + +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SimpleBinding { + SimpleBinding { try builder($0, $1.0, $1.1, $1.2) } +} + +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SimpleBinding { + SimpleBinding { try builder($0, $1.0, $1.1, $1.2, $1.3) } +} + +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SimpleBinding { + SimpleBinding { try builder($0, $1.0, $1.1, $1.2, $1.3, $1.4) } +} diff --git a/Sources/FactoryBinding.swift b/Sources/FactoryBinding.swift deleted file mode 100644 index b91faa3e..00000000 --- a/Sources/FactoryBinding.swift +++ /dev/null @@ -1,37 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -public struct FactoryBinding: Binding { - public typealias BoundType = Type - - private let builder: (Resolver, Argument) throws -> Type - - init(_ builder: @escaping (Resolver, Argument) throws -> Type) { - self.builder = builder - } - - public func instance(arg: Argument, context _: Void, resolver: Resolver) throws -> Type { - try builder(resolver, arg) - } -} - -public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> FactoryBinding { - FactoryBinding(builder) -} - -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> FactoryBinding { - FactoryBinding { try builder($0, $1.0, $1.1) } -} - -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> FactoryBinding { - FactoryBinding { try builder($0, $1.0, $1.1, $1.2) } -} - -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> FactoryBinding { - FactoryBinding { try builder($0, $1.0, $1.1, $1.2, $1.3) } -} - -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> FactoryBinding { - FactoryBinding { try builder($0, $1.0, $1.1, $1.2, $1.3, $1.4) } -} diff --git a/Sources/InstanceBinding.swift b/Sources/InstanceBinding.swift deleted file mode 100644 index 2a21ea82..00000000 --- a/Sources/InstanceBinding.swift +++ /dev/null @@ -1,22 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -// TODO: Make internal -public struct InstanceBinding: Binding { - public typealias BoundType = Type - - private let _instance: Type - - init(_ instance: Type) { - _instance = instance - } - - public func instance(arg _: Void, context: Void, resolver _: Resolver) throws -> Type { - _instance - } -} - -public func instance(_ instance: Type) -> InstanceBinding { - InstanceBinding(instance) -} diff --git a/Sources/ProviderBinding.swift b/Sources/ProviderBinding.swift deleted file mode 100644 index b1b1ddb3..00000000 --- a/Sources/ProviderBinding.swift +++ /dev/null @@ -1,26 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -// TODO: Make internal -public struct ProviderBinding: Binding { - public typealias BoundType = Type - - private let builder: (Resolver) throws -> Type - - init(_ builder: @escaping (Resolver) throws -> Type) { - self.builder = builder - } - - public func instance(arg _: Void, context: Void, resolver provider: Resolver) throws -> Type { - try builder(provider) - } -} - -public func provider(_ builder: @escaping () throws -> Type) -> ProviderBinding { - ProviderBinding { _ in try builder() } -} - -public func provider(_ builder: @escaping (Resolver) throws -> Type) -> ProviderBinding { - ProviderBinding(builder) -} diff --git a/Sources/SimpleBinding.swift b/Sources/SimpleBinding.swift new file mode 100644 index 00000000..c5c62016 --- /dev/null +++ b/Sources/SimpleBinding.swift @@ -0,0 +1,19 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +// TODO: More descriptive name +// TODO: Can we make it internal? +public struct SimpleBinding: Binding { + public typealias BoundType = Type + + private let builder: (Resolver, Argument) throws -> Type + + init(_ builder: @escaping (Resolver, Argument) throws -> Type) { + self.builder = builder + } + + public func instance(arg: Argument, context _: Void, resolver: Resolver) throws -> Type { + try builder(resolver, arg) + } +} diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index c787ef0a..80a8719c 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -15,14 +15,11 @@ CD6DE53522DD1C7300532D08 /* BindingKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53322DD1C6800532D08 /* BindingKeySpec.swift */; }; CD6DE53722DD1CE900532D08 /* BindingKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53622DD1CE900532D08 /* BindingKey.swift */; }; CD6DE53922DD1D0A00532D08 /* BindingRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53822DD1D0A00532D08 /* BindingRequest.swift */; }; - CD6DE53B22DD303F00532D08 /* FactoryBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53A22DD303F00532D08 /* FactoryBinding.swift */; }; - CD6DE53D22DD30A100532D08 /* FactoryBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53C22DD30A100532D08 /* FactoryBindingSpec.swift */; }; - CD85AF0E22DA57AD00A8B7CA /* ProviderBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF0D22DA57AD00A8B7CA /* ProviderBinding.swift */; }; - CD85AF1022DA586D00A8B7CA /* ProviderBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF0F22DA586D00A8B7CA /* ProviderBindingSpec.swift */; }; + CD6DE53D22DD30A100532D08 /* BindingBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53C22DD30A100532D08 /* BindingBuilderSpec.swift */; }; + CD6DE54122DE657500532D08 /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE54022DE657400532D08 /* SimpleBinding.swift */; }; + CD6DE54322DE65B500532D08 /* BindingBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE54222DE65B500532D08 /* BindingBuilder.swift */; }; CD85AF1222DA5A8F00A8B7CA /* NonGeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF1122DA5A8F00A8B7CA /* NonGeneratedMocks.swift */; }; CDADF32122DB38C600C5D8DB /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDADF32022DB38C600C5D8DB /* SwinjectTree.swift */; }; - CDADF32322DB416C00C5D8DB /* InstanceBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDADF32222DB416C00C5D8DB /* InstanceBinding.swift */; }; - CDADF33322DB4C1800C5D8DB /* InstanceBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDADF33122DB4C1200C5D8DB /* InstanceBindingSpec.swift */; }; CDADF33522DB521400C5D8DB /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDADF33422DB521400C5D8DB /* SwinjectModule.swift */; }; CDADF33722DB753800C5D8DB /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDADF33622DB753800C5D8DB /* TestModels.swift */; }; CDADF34022DB883A00C5D8DB /* GeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDADF33F22DB883A00C5D8DB /* GeneratedMocks.swift */; }; @@ -61,14 +58,11 @@ CD6DE53322DD1C6800532D08 /* BindingKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingKeySpec.swift; sourceTree = ""; }; CD6DE53622DD1CE900532D08 /* BindingKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingKey.swift; sourceTree = ""; }; CD6DE53822DD1D0A00532D08 /* BindingRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingRequest.swift; sourceTree = ""; }; - CD6DE53A22DD303F00532D08 /* FactoryBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FactoryBinding.swift; sourceTree = ""; }; - CD6DE53C22DD30A100532D08 /* FactoryBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FactoryBindingSpec.swift; sourceTree = ""; }; - CD85AF0D22DA57AD00A8B7CA /* ProviderBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProviderBinding.swift; sourceTree = ""; }; - CD85AF0F22DA586D00A8B7CA /* ProviderBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProviderBindingSpec.swift; sourceTree = ""; }; + CD6DE53C22DD30A100532D08 /* BindingBuilderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingBuilderSpec.swift; sourceTree = ""; }; + CD6DE54022DE657400532D08 /* SimpleBinding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SimpleBinding.swift; sourceTree = ""; }; + CD6DE54222DE65B500532D08 /* BindingBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingBuilder.swift; sourceTree = ""; }; CD85AF1122DA5A8F00A8B7CA /* NonGeneratedMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonGeneratedMocks.swift; sourceTree = ""; }; CDADF32022DB38C600C5D8DB /* SwinjectTree.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTree.swift; sourceTree = ""; }; - CDADF32222DB416C00C5D8DB /* InstanceBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceBinding.swift; sourceTree = ""; }; - CDADF33122DB4C1200C5D8DB /* InstanceBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceBindingSpec.swift; sourceTree = ""; }; CDADF33422DB521400C5D8DB /* SwinjectModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectModule.swift; sourceTree = ""; }; CDADF33622DB753800C5D8DB /* TestModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestModels.swift; sourceTree = ""; }; CDADF33E22DB881D00C5D8DB /* AutoMockable.stencil */ = {isa = PBXFileReference; lastKnownFileType = text; path = AutoMockable.stencil; sourceTree = ""; }; @@ -136,9 +130,8 @@ CDD8380422DA307F003E9909 /* TypeBinder.swift */, CDD8380622DA30C6003E9909 /* TypeDescriptor.swift */, CDD8380B22DA3AD8003E9909 /* Binding.swift */, - CD85AF0D22DA57AD00A8B7CA /* ProviderBinding.swift */, - CDADF32222DB416C00C5D8DB /* InstanceBinding.swift */, - CD6DE53A22DD303F00532D08 /* FactoryBinding.swift */, + CD6DE54022DE657400532D08 /* SimpleBinding.swift */, + CD6DE54222DE65B500532D08 /* BindingBuilder.swift */, CDD8380F22DA429F003E9909 /* Resolver.swift */, CDD8380D22DA3B0D003E9909 /* BindingEntry.swift */, CD6DE53622DD1CE900532D08 /* BindingKey.swift */, @@ -186,9 +179,7 @@ children = ( CDD8380222DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift */, CDD8380822DA31C6003E9909 /* TypeBinderSpec.swift */, - CD85AF0F22DA586D00A8B7CA /* ProviderBindingSpec.swift */, - CDADF33122DB4C1200C5D8DB /* InstanceBindingSpec.swift */, - CD6DE53C22DD30A100532D08 /* FactoryBindingSpec.swift */, + CD6DE53C22DD30A100532D08 /* BindingBuilderSpec.swift */, CDD8381922DA4C9F003E9909 /* SwinjectSpec.swift */, CD6DE53322DD1C6800532D08 /* BindingKeySpec.swift */, ); @@ -374,18 +365,17 @@ buildActionMask = 2147483647; files = ( CDD8380C22DA3AD8003E9909 /* Binding.swift in Sources */, + CD6DE54322DE65B500532D08 /* BindingBuilder.swift in Sources */, CDADF33522DB521400C5D8DB /* SwinjectModule.swift in Sources */, CDD8381022DA429F003E9909 /* Resolver.swift in Sources */, CD6DE53722DD1CE900532D08 /* BindingKey.swift in Sources */, CD6DE53922DD1D0A00532D08 /* BindingRequest.swift in Sources */, - CDADF32322DB416C00C5D8DB /* InstanceBinding.swift in Sources */, - CD6DE53B22DD303F00532D08 /* FactoryBinding.swift in Sources */, CDADF32122DB38C600C5D8DB /* SwinjectTree.swift in Sources */, + CD6DE54122DE657500532D08 /* SimpleBinding.swift in Sources */, CDD8381D22DA4E02003E9909 /* SwinjectError.swift in Sources */, CDD8380722DA30C6003E9909 /* TypeDescriptor.swift in Sources */, CDD8381622DA4B55003E9909 /* Swinject.swift in Sources */, CDD8380522DA307F003E9909 /* TypeBinder.swift in Sources */, - CD85AF0E22DA57AD00A8B7CA /* ProviderBinding.swift in Sources */, CDD8380E22DA3B0D003E9909 /* BindingEntry.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -399,9 +389,7 @@ CDADF34022DB883A00C5D8DB /* GeneratedMocks.swift in Sources */, CDD8380A22DA31D9003E9909 /* TypeBinderSpec.swift in Sources */, CD85AF1222DA5A8F00A8B7CA /* NonGeneratedMocks.swift in Sources */, - CD6DE53D22DD30A100532D08 /* FactoryBindingSpec.swift in Sources */, - CDADF33322DB4C1800C5D8DB /* InstanceBindingSpec.swift in Sources */, - CD85AF1022DA586D00A8B7CA /* ProviderBindingSpec.swift in Sources */, + CD6DE53D22DD30A100532D08 /* BindingBuilderSpec.swift in Sources */, CDD8380322DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift in Sources */, CD6DE53522DD1C7300532D08 /* BindingKeySpec.swift in Sources */, CDADF33722DB753800C5D8DB /* TestModels.swift in Sources */, diff --git a/Tests/Support/Utils.swift b/Tests/Support/Utils.swift index dc2a42e2..0a199f65 100644 --- a/Tests/Support/Utils.swift +++ b/Tests/Support/Utils.swift @@ -4,7 +4,6 @@ import func Swinject.bind import struct Swinject.NoTag -import struct Swinject.ProviderBinding import struct Swinject.Tagged import struct Swinject.TypeBinder import protocol Swinject.TypeDescriptor diff --git a/Tests/UnitSpecs/BindingBuilderSpec.swift b/Tests/UnitSpecs/BindingBuilderSpec.swift new file mode 100644 index 00000000..df165d7c --- /dev/null +++ b/Tests/UnitSpecs/BindingBuilderSpec.swift @@ -0,0 +1,100 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +import Nimble +import Quick +@testable import Swinject + +class BindingBuilderSpec: QuickSpec { override func spec() { + describe("instance") { + it("returns given instance") { + let binding = instance(42) + expect { try binding.instance(resolver: DummyResolver()) } == 42 + } + } + describe("provider") { + it("returns instance made by provider method") { + let binding = provider { 42 } + expect { try binding.instance(resolver: DummyResolver()) } == 42 + } + it("does not call builder until instance is requested") { + var called = false + _ = provider { called = true } + expect(called).to(beFalse()) + } + it("calls builder with given provider") { + var passedResolver: Resolver? + let resolver = DummyResolver() + let binding = provider { passedResolver = $0 } + _ = try? binding.instance(resolver: resolver) + expect(passedResolver) === resolver + } + it("rethrows error from builder") { + let binding = provider { throw SwinjectError() } + expect { try binding.instance(resolver: DummyResolver()) }.to(throwError()) + } + it("does not reuse instance") { + let binding = provider { Person() } + let instance1 = try? binding.instance(resolver: DummyResolver()) + let instance2 = try? binding.instance(resolver: DummyResolver()) + expect(instance1) !== instance2 + } + } + describe("factory") { + it("returns instance made by builder method") { + let binding = factory { (_, _: Void) in 42 } + expect { try binding.instance(resolver: DummyResolver()) } == 42 + } + it("does not call builder until instance is requested") { + var called = false + _ = factory { (_, _: Void) in called = true } + expect(called).to(beFalse()) + } + it("calls builder with given provider") { + var passedResolver: Resolver? + let resolver = DummyResolver() + let binding = factory { (_, _: Void) in passedResolver = resolver } + _ = try? binding.instance(resolver: resolver) + expect(passedResolver) === resolver + } + it("calls builder with given argument") { + var passedArgument: Int? + let binding = factory { (_, arg: Int) in passedArgument = arg } + _ = try? binding.instance(arg: 42, resolver: DummyResolver()) + expect(passedArgument) == 42 + } + it("rethrows error from builder") { + let binding = factory { (_, _: Void) in throw SwinjectError() } + expect { try binding.instance(resolver: DummyResolver()) }.to(throwError()) + } + it("does not reuse instance") { + let binding = factory { (_, _: Void) in Person() } + let instance1 = try? binding.instance(resolver: DummyResolver()) + let instance2 = try? binding.instance(resolver: DummyResolver()) + expect(instance1) !== instance2 + } + describe("multiple arguments") { + it("works with 2 arguments") { + let binding = factory { (_, _: Int, _: Double) in 42 } + let arguments = (1, 1.0) + expect { try binding.instance(arg: arguments, resolver: DummyResolver()) } == 42 + } + it("works with 3 arguments") { + let binding = factory { (_, _: Int, _: Double, _: String) in 42 } + let arguments = (1, 1.0, "") + expect { try binding.instance(arg: arguments, resolver: DummyResolver()) } == 42 + } + it("works with 4 arguments") { + let binding = factory { (_, _: Int, _: Double, _: String, _: Float) in 42 } + let arguments = (1, 1.0, "", Float(1.0)) + expect { try binding.instance(arg: arguments, resolver: DummyResolver()) } == 42 + } + it("works with 5 arguments") { + let binding = factory { (_, _: Int, _: Double, _: String, _: Float, _: Int) in 42 } + let arguments = (1, 1.0, "", Float(1.0), 5) + expect { try binding.instance(arg: arguments, resolver: DummyResolver()) } == 42 + } + } + } +} } diff --git a/Tests/UnitSpecs/FactoryBindingSpec.swift b/Tests/UnitSpecs/FactoryBindingSpec.swift deleted file mode 100644 index 903ff394..00000000 --- a/Tests/UnitSpecs/FactoryBindingSpec.swift +++ /dev/null @@ -1,64 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -import Nimble -import Quick -@testable import Swinject - -class FactoryBindingSpec: QuickSpec { override func spec() { - it("returns instance made by builder method") { - let binding = factory { (_, _: Void) in 42 } - expect { try binding.instance(resolver: DummyResolver()) } == 42 - } - it("does not call builder until instance is requested") { - var called = false - _ = factory { (_, _: Void) in called = true } - expect(called).to(beFalse()) - } - it("calls builder with given provider") { - var passedResolver: Resolver? - let resolver = DummyResolver() - let binding = factory { (_, _: Void) in passedResolver = resolver } - _ = try? binding.instance(resolver: resolver) - expect(passedResolver) === resolver - } - it("calls builder with given argument") { - var passedArgument: Int? - let binding = factory { (_, arg: Int) in passedArgument = arg } - _ = try? binding.instance(arg: 42, resolver: DummyResolver()) - expect(passedArgument) == 42 - } - it("rethrows error from builder") { - let binding = factory { (_, _: Void) in throw SwinjectError() } - expect { try binding.instance(resolver: DummyResolver()) }.to(throwError()) - } - it("does not reuse instance") { - let binding = factory { (_, _: Void) in Person() } - let instance1 = try? binding.instance(resolver: DummyResolver()) - let instance2 = try? binding.instance(resolver: DummyResolver()) - expect(instance1) !== instance2 - } - describe("multiple arguments") { - it("works with 2 arguments") { - let binding = factory { (_, _: Int, _: Double) in 42 } - let arguments = (1, 1.0) - expect { try binding.instance(arg: arguments, resolver: DummyResolver()) } == 42 - } - it("works with 3 arguments") { - let binding = factory { (_, _: Int, _: Double, _: String) in 42 } - let arguments = (1, 1.0, "") - expect { try binding.instance(arg: arguments, resolver: DummyResolver()) } == 42 - } - it("works with 4 arguments") { - let binding = factory { (_, _: Int, _: Double, _: String, _: Float) in 42 } - let arguments = (1, 1.0, "", Float(1.0)) - expect { try binding.instance(arg: arguments, resolver: DummyResolver()) } == 42 - } - it("works with 5 arguments") { - let binding = factory { (_, _: Int, _: Double, _: String, _: Float, _: Int) in 42 } - let arguments = (1, 1.0, "", Float(1.0), 5) - expect { try binding.instance(arg: arguments, resolver: DummyResolver()) } == 42 - } - } -} } diff --git a/Tests/UnitSpecs/InstanceBindingSpec.swift b/Tests/UnitSpecs/InstanceBindingSpec.swift deleted file mode 100644 index 5f1f5793..00000000 --- a/Tests/UnitSpecs/InstanceBindingSpec.swift +++ /dev/null @@ -1,14 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -import Nimble -import Quick -@testable import Swinject - -class InstanceBindingSpec: QuickSpec { override func spec() { - it("returns given instance") { - let binding = instance(42) - expect { try binding.instance(resolver: DummyResolver()) } == 42 - } -} } diff --git a/Tests/UnitSpecs/ProviderBindingSpec.swift b/Tests/UnitSpecs/ProviderBindingSpec.swift deleted file mode 100644 index 837d6715..00000000 --- a/Tests/UnitSpecs/ProviderBindingSpec.swift +++ /dev/null @@ -1,36 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -import Nimble -import Quick -@testable import Swinject - -class ProviderBindingSpec: QuickSpec { override func spec() { - it("returns instance made by provider method") { - let binding = provider { 42 } - expect { try binding.instance(resolver: DummyResolver()) } == 42 - } - it("does not call builder until instance is requested") { - var called = false - _ = provider { called = true } - expect(called).to(beFalse()) - } - it("calls builder with given provider") { - var passedResolver: Resolver? - let resolver = DummyResolver() - let binding = provider { passedResolver = $0 } - _ = try? binding.instance(resolver: resolver) - expect(passedResolver) === resolver - } - it("rethrows error from builder") { - let binding = provider { throw SwinjectError() } - expect { try binding.instance(resolver: DummyResolver()) }.to(throwError()) - } - it("does not reuse instance") { - let binding = provider { Person() } - let instance1 = try? binding.instance(resolver: DummyResolver()) - let instance2 = try? binding.instance(resolver: DummyResolver()) - expect(instance1) !== instance2 - } -} } diff --git a/Tests/UnitSpecs/TypeBinderSpec.swift b/Tests/UnitSpecs/TypeBinderSpec.swift index 44e1d68c..9a23f89c 100644 --- a/Tests/UnitSpecs/TypeBinderSpec.swift +++ b/Tests/UnitSpecs/TypeBinderSpec.swift @@ -38,7 +38,7 @@ class TypeBinderSpec: QuickSpec { override func spec() { } it("produces entry if given value of descriptor type") { let entry = bbind(Int.self).with(42) - expect(entry.binding is InstanceBinding).to(beTrue()) + expect(entry.binding is SimpleBinding).to(beTrue()) } } describe("& operator") { @@ -56,7 +56,7 @@ class TypeBinderSpec: QuickSpec { override func spec() { } it("produces entry provider if given value of descriptor type") { let entry = bbind(Int.self) & 42 - expect(entry.binding is InstanceBinding).to(beTrue()) + expect(entry.binding is SimpleBinding).to(beTrue()) } } } } From 609821f3120c8e1b14f493ae4fd69faa849fc493 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Tue, 16 Jul 2019 22:45:35 +0200 Subject: [PATCH 044/239] Implement contexted binding builder --- Sources/BindingBuilder.swift | 64 ++++-- Sources/SimpleBinding.swift | 10 +- Tests/UnitSpecs/BindingBuilderSpec.swift | 251 ++++++++++++++++------- Tests/UnitSpecs/TypeBinderSpec.swift | 4 +- 4 files changed, 231 insertions(+), 98 deletions(-) diff --git a/Sources/BindingBuilder.swift b/Sources/BindingBuilder.swift index c2368784..65a36f4d 100644 --- a/Sources/BindingBuilder.swift +++ b/Sources/BindingBuilder.swift @@ -2,34 +2,66 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -public func instance(_ instance: Type) -> SimpleBinding { - SimpleBinding { _, _ in instance } +public struct BindingBuilder {} + +public func contexted(_: Context.Type = Context.self) -> BindingBuilder { + BindingBuilder() +} + +extension BindingBuilder { + public func provider(_ builder: @escaping (Resolver, Context) throws -> Type) -> SimpleBinding { + SimpleBinding { r, c, _ in try builder(r, c) } + } + + public func factory(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SimpleBinding { + SimpleBinding(builder) + } + + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SimpleBinding { + SimpleBinding { try builder($0, $1, $2.0, $2.1) } + } + + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SimpleBinding { + SimpleBinding { try builder($0, $1, $2.0, $2.1, $2.2) } + } + + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SimpleBinding { + SimpleBinding { try builder($0, $1, $2.0, $2.1, $2.2, $2.3) } + } + + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SimpleBinding { + SimpleBinding { try builder($0, $1, $2.0, $2.1, $2.2, $2.3, $2.4) } + } +} + +public func instance(_ instance: Type) -> SimpleBinding { + SimpleBinding { _, _, _ in instance } } -public func provider(_ builder: @escaping () throws -> Type) -> SimpleBinding { - SimpleBinding { _, _ in try builder() } +public func provider(_ builder: @escaping () throws -> Type) -> SimpleBinding { + SimpleBinding { _, _, _ in try builder() } } -public func provider(_ builder: @escaping (Resolver) throws -> Type) -> SimpleBinding { - SimpleBinding { resolver, _ in try builder(resolver) } +public func provider(_ builder: @escaping (Resolver) throws -> Type) -> SimpleBinding { + SimpleBinding { r, _, _ in try builder(r) } } -public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> SimpleBinding { - SimpleBinding(builder) +public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> SimpleBinding { + SimpleBinding { try builder($0, $2) } } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SimpleBinding { - SimpleBinding { try builder($0, $1.0, $1.1) } +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SimpleBinding { + SimpleBinding { try builder($0, $2.0, $2.1) } } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SimpleBinding { - SimpleBinding { try builder($0, $1.0, $1.1, $1.2) } +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SimpleBinding { + SimpleBinding { try builder($0, $2.0, $2.1, $2.2) } } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SimpleBinding { - SimpleBinding { try builder($0, $1.0, $1.1, $1.2, $1.3) } +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SimpleBinding { + SimpleBinding { try builder($0, $2.0, $2.1, $2.2, $2.3) } } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SimpleBinding { - SimpleBinding { try builder($0, $1.0, $1.1, $1.2, $1.3, $1.4) } +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SimpleBinding { + SimpleBinding { try builder($0, $2.0, $2.1, $2.2, $2.3, $2.4) } } diff --git a/Sources/SimpleBinding.swift b/Sources/SimpleBinding.swift index c5c62016..b9f02aec 100644 --- a/Sources/SimpleBinding.swift +++ b/Sources/SimpleBinding.swift @@ -4,16 +4,16 @@ // TODO: More descriptive name // TODO: Can we make it internal? -public struct SimpleBinding: Binding { +public struct SimpleBinding: Binding { public typealias BoundType = Type - private let builder: (Resolver, Argument) throws -> Type + private let builder: (Resolver, Context, Argument) throws -> Type - init(_ builder: @escaping (Resolver, Argument) throws -> Type) { + init(_ builder: @escaping (Resolver, Context, Argument) throws -> Type) { self.builder = builder } - public func instance(arg: Argument, context _: Void, resolver: Resolver) throws -> Type { - try builder(resolver, arg) + public func instance(arg: Argument, context: Context, resolver: Resolver) throws -> Type { + try builder(resolver, context, arg) } } diff --git a/Tests/UnitSpecs/BindingBuilderSpec.swift b/Tests/UnitSpecs/BindingBuilderSpec.swift index df165d7c..cfa3e9c7 100644 --- a/Tests/UnitSpecs/BindingBuilderSpec.swift +++ b/Tests/UnitSpecs/BindingBuilderSpec.swift @@ -14,86 +14,187 @@ class BindingBuilderSpec: QuickSpec { override func spec() { } } describe("provider") { - it("returns instance made by provider method") { - let binding = provider { 42 } - expect { try binding.instance(resolver: DummyResolver()) } == 42 - } - it("does not call builder until instance is requested") { - var called = false - _ = provider { called = true } - expect(called).to(beFalse()) - } - it("calls builder with given provider") { - var passedResolver: Resolver? - let resolver = DummyResolver() - let binding = provider { passedResolver = $0 } - _ = try? binding.instance(resolver: resolver) - expect(passedResolver) === resolver - } - it("rethrows error from builder") { - let binding = provider { throw SwinjectError() } - expect { try binding.instance(resolver: DummyResolver()) }.to(throwError()) + // TODO: Can we reuse tests for with / without context? + describe("without context") { + it("returns instance made by provider method") { + let binding = provider { 42 } + expect { try binding.instance(resolver: DummyResolver()) } == 42 + } + it("does not call builder until instance is requested") { + var called = false + _ = provider { called = true } + expect(called).to(beFalse()) + } + it("calls builder with given provider") { + var passedResolver: Resolver? + let resolver = DummyResolver() + let binding = provider { passedResolver = $0 } + _ = try? binding.instance(resolver: resolver) + expect(passedResolver) === resolver + } + it("rethrows error from builder") { + let binding = provider { throw SwinjectError() } + expect { try binding.instance(resolver: DummyResolver()) }.to(throwError()) + } + it("does not reuse instance") { + let binding = provider { Person() } + let instance1 = try? binding.instance(resolver: DummyResolver()) + let instance2 = try? binding.instance(resolver: DummyResolver()) + expect(instance1) !== instance2 + } } - it("does not reuse instance") { - let binding = provider { Person() } - let instance1 = try? binding.instance(resolver: DummyResolver()) - let instance2 = try? binding.instance(resolver: DummyResolver()) - expect(instance1) !== instance2 + describe("contexted") { + it("returns instance made by provider method") { + let binding = contexted(Void.self).provider { _, _ in 42 } + expect { try binding.instance(resolver: DummyResolver()) } == 42 + } + it("does not call builder until instance is requested") { + var called = false + _ = provider { called = true } + expect(called).to(beFalse()) + } + it("calls builder with given provider") { + var passedResolver: Resolver? + let resolver = DummyResolver() + let binding = contexted(Void.self).provider { r, _ in passedResolver = r } + _ = try? binding.instance(resolver: resolver) + expect(passedResolver) === resolver + } + it("calls builder with given context") { + var passedContext: Int? + let binding = contexted(Int.self).provider { _, c in passedContext = c } + _ = try? binding.instance(context: 42, resolver: DummyResolver()) + expect(passedContext) == 42 + } + it("rethrows error from builder") { + let binding = contexted(Void.self).provider { _, _ in throw SwinjectError() } + expect { try binding.instance(resolver: DummyResolver()) }.to(throwError()) + } + it("does not reuse instance") { + let binding = contexted(Void.self).provider { _, _ in Person() } + let instance1 = try? binding.instance(resolver: DummyResolver()) + let instance2 = try? binding.instance(resolver: DummyResolver()) + expect(instance1) !== instance2 + } } } describe("factory") { - it("returns instance made by builder method") { - let binding = factory { (_, _: Void) in 42 } - expect { try binding.instance(resolver: DummyResolver()) } == 42 - } - it("does not call builder until instance is requested") { - var called = false - _ = factory { (_, _: Void) in called = true } - expect(called).to(beFalse()) - } - it("calls builder with given provider") { - var passedResolver: Resolver? - let resolver = DummyResolver() - let binding = factory { (_, _: Void) in passedResolver = resolver } - _ = try? binding.instance(resolver: resolver) - expect(passedResolver) === resolver - } - it("calls builder with given argument") { - var passedArgument: Int? - let binding = factory { (_, arg: Int) in passedArgument = arg } - _ = try? binding.instance(arg: 42, resolver: DummyResolver()) - expect(passedArgument) == 42 - } - it("rethrows error from builder") { - let binding = factory { (_, _: Void) in throw SwinjectError() } - expect { try binding.instance(resolver: DummyResolver()) }.to(throwError()) - } - it("does not reuse instance") { - let binding = factory { (_, _: Void) in Person() } - let instance1 = try? binding.instance(resolver: DummyResolver()) - let instance2 = try? binding.instance(resolver: DummyResolver()) - expect(instance1) !== instance2 + describe("without context") { + it("returns instance made by builder method") { + let binding = factory { (_, _: Void) in 42 } + expect { try binding.instance(resolver: DummyResolver()) } == 42 + } + it("does not call builder until instance is requested") { + var called = false + _ = factory { (_, _: Void) in called = true } + expect(called).to(beFalse()) + } + it("calls builder with given provider") { + var passedResolver: Resolver? + let resolver = DummyResolver() + let binding = factory { (r, _: Void) in passedResolver = r } + _ = try? binding.instance(resolver: resolver) + expect(passedResolver) === resolver + } + it("calls builder with given argument") { + var passedArgument: Int? + let binding = factory { (_, arg: Int) in passedArgument = arg } + _ = try? binding.instance(arg: 42, resolver: DummyResolver()) + expect(passedArgument) == 42 + } + it("rethrows error from builder") { + let binding = factory { (_, _: Void) in throw SwinjectError() } + expect { try binding.instance(resolver: DummyResolver()) }.to(throwError()) + } + it("does not reuse instance") { + let binding = factory { (_, _: Void) in Person() } + let instance1 = try? binding.instance(resolver: DummyResolver()) + let instance2 = try? binding.instance(resolver: DummyResolver()) + expect(instance1) !== instance2 + } + describe("multiple arguments") { + it("works with 2 arguments") { + let binding = factory { (_, _: Int, _: Double) in 42 } + let arguments = (1, 1.0) + expect { try binding.instance(arg: arguments, resolver: DummyResolver()) } == 42 + } + it("works with 3 arguments") { + let binding = factory { (_, _: Int, _: Double, _: String) in 42 } + let arguments = (1, 1.0, "") + expect { try binding.instance(arg: arguments, resolver: DummyResolver()) } == 42 + } + it("works with 4 arguments") { + let binding = factory { (_, _: Int, _: Double, _: String, _: Float) in 42 } + let arguments = (1, 1.0, "", Float(1.0)) + expect { try binding.instance(arg: arguments, resolver: DummyResolver()) } == 42 + } + it("works with 5 arguments") { + let binding = factory { (_, _: Int, _: Double, _: String, _: Float, _: Int) in 42 } + let arguments = (1, 1.0, "", Float(1.0), 5) + expect { try binding.instance(arg: arguments, resolver: DummyResolver()) } == 42 + } + } } - describe("multiple arguments") { - it("works with 2 arguments") { - let binding = factory { (_, _: Int, _: Double) in 42 } - let arguments = (1, 1.0) - expect { try binding.instance(arg: arguments, resolver: DummyResolver()) } == 42 - } - it("works with 3 arguments") { - let binding = factory { (_, _: Int, _: Double, _: String) in 42 } - let arguments = (1, 1.0, "") - expect { try binding.instance(arg: arguments, resolver: DummyResolver()) } == 42 - } - it("works with 4 arguments") { - let binding = factory { (_, _: Int, _: Double, _: String, _: Float) in 42 } - let arguments = (1, 1.0, "", Float(1.0)) - expect { try binding.instance(arg: arguments, resolver: DummyResolver()) } == 42 - } - it("works with 5 arguments") { - let binding = factory { (_, _: Int, _: Double, _: String, _: Float, _: Int) in 42 } - let arguments = (1, 1.0, "", Float(1.0), 5) - expect { try binding.instance(arg: arguments, resolver: DummyResolver()) } == 42 + describe("contexted") { + it("returns instance made by builder method") { + let binding = contexted(Void.self).factory { (_, _, _: Void) in 42 } + expect { try binding.instance(resolver: DummyResolver()) } == 42 + } + it("does not call builder until instance is requested") { + var called = false + _ = contexted(Void.self).factory { (_, _, _: Void) in called = true } + expect(called).to(beFalse()) + } + it("calls builder with given provider") { + var passedResolver: Resolver? + let resolver = DummyResolver() + let binding = contexted(Void.self).factory { (r, _, _: Void) in passedResolver = r } + _ = try? binding.instance(resolver: resolver) + expect(passedResolver) === resolver + } + it("calls builder with given context") { + var passedContext: Int? + let binding = contexted(Int.self).factory { (_, c, _: Void) in passedContext = c } + _ = try? binding.instance(context: 42, resolver: DummyResolver()) + expect(passedContext) == 42 + } + it("calls builder with given argument") { + var passedArgument: Int? + let binding = contexted(Void.self).factory { (_, _, arg: Int) in passedArgument = arg } + _ = try? binding.instance(arg: 42, resolver: DummyResolver()) + expect(passedArgument) == 42 + } + it("rethrows error from builder") { + let binding = contexted(Void.self).factory { (_, _, _: Void) in throw SwinjectError() } + expect { try binding.instance(resolver: DummyResolver()) }.to(throwError()) + } + it("does not reuse instance") { + let binding = contexted(Void.self).factory { (_, _, _: Void) in Person() } + let instance1 = try? binding.instance(resolver: DummyResolver()) + let instance2 = try? binding.instance(resolver: DummyResolver()) + expect(instance1) !== instance2 + } + describe("multiple arguments") { + it("works with 2 arguments") { + let binding = contexted(Void.self).factory { (_, _, _: Int, _: Double) in 42 } + let arguments = (1, 1.0) + expect { try binding.instance(arg: arguments, resolver: DummyResolver()) } == 42 + } + it("works with 3 arguments") { + let binding = contexted(Void.self).factory { (_, _, _: Int, _: Double, _: String) in 42 } + let arguments = (1, 1.0, "") + expect { try binding.instance(arg: arguments, resolver: DummyResolver()) } == 42 + } + it("works with 4 arguments") { + let binding = contexted(Void.self).factory { (_, _, _: Int, _: Double, _: String, _: Float) in 42 } + let arguments = (1, 1.0, "", Float(1.0)) + expect { try binding.instance(arg: arguments, resolver: DummyResolver()) } == 42 + } + it("works with 5 arguments") { + let binding = contexted(Void.self).factory { (_, _, _: Int, _: Double, _: String, _: Float, _: Int) in 42 } + let arguments = (1, 1.0, "", Float(1.0), 5) + expect { try binding.instance(arg: arguments, resolver: DummyResolver()) } == 42 + } } } } diff --git a/Tests/UnitSpecs/TypeBinderSpec.swift b/Tests/UnitSpecs/TypeBinderSpec.swift index 9a23f89c..cb0b1b7a 100644 --- a/Tests/UnitSpecs/TypeBinderSpec.swift +++ b/Tests/UnitSpecs/TypeBinderSpec.swift @@ -38,7 +38,7 @@ class TypeBinderSpec: QuickSpec { override func spec() { } it("produces entry if given value of descriptor type") { let entry = bbind(Int.self).with(42) - expect(entry.binding is SimpleBinding).to(beTrue()) + expect(entry.binding is SimpleBinding).to(beTrue()) } } describe("& operator") { @@ -56,7 +56,7 @@ class TypeBinderSpec: QuickSpec { override func spec() { } it("produces entry provider if given value of descriptor type") { let entry = bbind(Int.self) & 42 - expect(entry.binding is SimpleBinding).to(beTrue()) + expect(entry.binding is SimpleBinding).to(beTrue()) } } } } From 295c951a4dcc301c65a220ff47486f679369d083 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Tue, 16 Jul 2019 23:07:53 +0200 Subject: [PATCH 045/239] Add key matching test --- Tests/UnitSpecs/SwinjectSpec.swift | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Tests/UnitSpecs/SwinjectSpec.swift b/Tests/UnitSpecs/SwinjectSpec.swift index 821a087a..8c48421b 100644 --- a/Tests/UnitSpecs/SwinjectSpec.swift +++ b/Tests/UnitSpecs/SwinjectSpec.swift @@ -62,6 +62,13 @@ class SwinjectSpec: QuickSpec { override func spec() { _ = try? swinject.instance(of: Any.self) expect(binding.instanceArgContextResolverReceivedArguments?.resolver is Swinject).to(beTrue()) } + it("matches binding with correct key") { + key.matchesReturnValue = false + _ = try? swinject.instance(tagged: "tag") as Int + let otherKey = key.matchesReceivedOther as? BindingKey, Void> + let descriptor = otherKey?.descriptor as? Tagged + expect(descriptor?.tag) == "tag" + } } context("multiple bindings") { var swinject: Swinject! @@ -130,7 +137,7 @@ class SwinjectSpec: QuickSpec { override func spec() { let provider = swinject.provider(of: Int.self) expect { try provider() }.to(throwError(errorType: TestError.self)) } - it("uses given tag for the key matching") { + it("matches binding with correct key") { key.matchesReturnValue = true _ = try? swinject.provider(of: Any.self, tagged: "tag")() let otherKey = key.matchesReceivedOther as? BindingKey, Void> @@ -182,7 +189,7 @@ class SwinjectSpec: QuickSpec { override func spec() { _ = try? swinject.factory(of: Int.self)("arg") expect(binding.instanceArgContextResolverReceivedArguments?.arg as? String) == "arg" } - it("uses given tag for the key matching") { + it("matches binding with correct key") { key.matchesReturnValue = false _ = try? swinject.factory(tagged: "tag")("arg") as Int let otherKey = key.matchesReceivedOther as? BindingKey, String> From cd502659990bcd478cfc08871f9ec7ad633c6779 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Tue, 16 Jul 2019 23:10:03 +0200 Subject: [PATCH 046/239] Add context to binding request --- Sources/BindingRequest.swift | 7 ++++--- Sources/Resolver.swift | 2 +- Sources/Swinject.swift | 2 +- Tests/Support/NonGeneratedMocks.swift | 6 +----- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/Sources/BindingRequest.swift b/Sources/BindingRequest.swift index 05363123..43903f2e 100644 --- a/Sources/BindingRequest.swift +++ b/Sources/BindingRequest.swift @@ -2,11 +2,12 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -public struct BindingRequest where Descriptor: TypeDescriptor { +public struct BindingRequest where Descriptor: TypeDescriptor { let key: BindingKey + let context: Context let argument: Argument } -func request(type _: Type.Type = Type.self, tag: Tag, arg: Argument) -> BindingRequest, Argument> { - BindingRequest(key: BindingKey(descriptor: Tagged(tag: tag)), argument: arg) +func request(type _: Type.Type = Type.self, tag: Tag, arg: Argument) -> BindingRequest, Void, Argument> { + BindingRequest(key: BindingKey(descriptor: Tagged(tag: tag)), context: (), argument: arg) } diff --git a/Sources/Resolver.swift b/Sources/Resolver.swift index 4f7c70a2..106f7cac 100644 --- a/Sources/Resolver.swift +++ b/Sources/Resolver.swift @@ -3,7 +3,7 @@ // public protocol Resolver { - func resolve(_ request: BindingRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor + func resolve(_ request: BindingRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor } // TODO: Overloads for multiple arguments & tag / notag combinations diff --git a/Sources/Swinject.swift b/Sources/Swinject.swift index e5514637..ac072740 100644 --- a/Sources/Swinject.swift +++ b/Sources/Swinject.swift @@ -25,7 +25,7 @@ public extension Swinject { } extension Swinject: Resolver { - public func resolve(_ request: BindingRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { + public func resolve(_ request: BindingRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { try instance(from: findBinding(for: request.key), arg: request.argument) } diff --git a/Tests/Support/NonGeneratedMocks.swift b/Tests/Support/NonGeneratedMocks.swift index a404585b..af2391d6 100644 --- a/Tests/Support/NonGeneratedMocks.swift +++ b/Tests/Support/NonGeneratedMocks.swift @@ -5,11 +5,7 @@ @testable import Swinject class DummyResolver: Resolver { - func resolve(_ _: BindingRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { - fatalError() - } - - func provider(for _: BindingRequest) throws -> () throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { + func resolve(_: BindingRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { fatalError() } } From 32a05a7b9526040b7f9ff89b338f6799d8d9bef4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Tue, 16 Jul 2019 23:15:35 +0200 Subject: [PATCH 047/239] Add context to the binding key --- Sources/BindingKey.swift | 10 +++++++--- Sources/BindingRequest.swift | 2 +- Sources/TypeBinder.swift | 2 +- Tests/Support/GeneratedMocks.swift | 14 ++++++++++---- Tests/UnitSpecs/BindingKeySpec.swift | 28 +++++++++++++++++++++++----- Tests/UnitSpecs/SwinjectSpec.swift | 6 +++--- 6 files changed, 45 insertions(+), 17 deletions(-) diff --git a/Sources/BindingKey.swift b/Sources/BindingKey.swift index a95349b1..563f7510 100644 --- a/Sources/BindingKey.swift +++ b/Sources/BindingKey.swift @@ -4,17 +4,21 @@ // sourcery: AutoMockable protocol AnyBindingKey { - var descriptor: AnyTypeDescriptor { get } + var contextType: Any.Type { get } var argumentType: Any.Type { get } + var descriptor: AnyTypeDescriptor { get } func matches(_ other: AnyBindingKey) -> Bool } -public struct BindingKey: AnyBindingKey where Descriptor: TypeDescriptor { +public struct BindingKey: AnyBindingKey where Descriptor: TypeDescriptor { + let contextType: Any.Type = Context.self let argumentType: Any.Type = Argument.self let descriptor: AnyTypeDescriptor func matches(_ other: AnyBindingKey) -> Bool { - descriptor.matches(other.descriptor) && argumentType == other.argumentType + descriptor.matches(other.descriptor) + && (contextType == other.contextType || contextType == Any.self) + && argumentType == other.argumentType } } diff --git a/Sources/BindingRequest.swift b/Sources/BindingRequest.swift index 43903f2e..2358bbeb 100644 --- a/Sources/BindingRequest.swift +++ b/Sources/BindingRequest.swift @@ -3,7 +3,7 @@ // public struct BindingRequest where Descriptor: TypeDescriptor { - let key: BindingKey + let key: BindingKey let context: Context let argument: Argument } diff --git a/Sources/TypeBinder.swift b/Sources/TypeBinder.swift index 69f21042..ba85ca1a 100644 --- a/Sources/TypeBinder.swift +++ b/Sources/TypeBinder.swift @@ -20,7 +20,7 @@ public func bind(_ descriptor: Descriptor) -> TypeBinder public extension TypeBinder { func with(_ binding: SomeBinding) -> BindingEntry where SomeBinding: Binding, SomeBinding.BoundType == Descriptor.BaseType { - BindingEntry(key: BindingKey(descriptor: descriptor), binding: binding) + BindingEntry(key: BindingKey(descriptor: descriptor), binding: binding) } func with(_ anInstance: Descriptor.BaseType) -> BindingEntry { diff --git a/Tests/Support/GeneratedMocks.swift b/Tests/Support/GeneratedMocks.swift index 80e17ab4..ca6d7c11 100644 --- a/Tests/Support/GeneratedMocks.swift +++ b/Tests/Support/GeneratedMocks.swift @@ -48,18 +48,24 @@ class AnyBindingEntryMock: AnyBindingEntry { } class AnyBindingKeyMock: AnyBindingKey { - var descriptor: AnyTypeDescriptor { - get { return underlyingDescriptor } - set(value) { underlyingDescriptor = value } + var contextType: Any.Type { + get { return underlyingContextType } + set(value) { underlyingContextType = value } } - var underlyingDescriptor: AnyTypeDescriptor! + var underlyingContextType: Any.Type! var argumentType: Any.Type { get { return underlyingArgumentType } set(value) { underlyingArgumentType = value } } var underlyingArgumentType: Any.Type! + var descriptor: AnyTypeDescriptor { + get { return underlyingDescriptor } + set(value) { underlyingDescriptor = value } + } + + var underlyingDescriptor: AnyTypeDescriptor! // MARK: - matches diff --git a/Tests/UnitSpecs/BindingKeySpec.swift b/Tests/UnitSpecs/BindingKeySpec.swift index 48d9ede4..dd0729a0 100644 --- a/Tests/UnitSpecs/BindingKeySpec.swift +++ b/Tests/UnitSpecs/BindingKeySpec.swift @@ -7,10 +7,12 @@ import Quick @testable import Swinject class BindingKeySpec: QuickSpec { override func spec() { - typealias AnyBindingKey = BindingKey + typealias AnyBindingKey = BindingKey + typealias ArgumentBindingKey = BindingKey + typealias ContextBindingKey = BindingKey describe("matching") { - var key: AnyBindingKey! + var key: AnyBindingKey! var descriptor = AnyTypeDescriptorMock() var otherKey = AnyBindingKeyMock() beforeEach { @@ -20,6 +22,7 @@ class BindingKeySpec: QuickSpec { override func spec() { otherKey = AnyBindingKeyMock() otherKey.descriptor = AnyTypeDescriptorMock() otherKey.argumentType = Void.self + otherKey.contextType = Void.self } it("does not match if descriptors don't match") { descriptor.matchesReturnValue = false @@ -27,7 +30,7 @@ class BindingKeySpec: QuickSpec { override func spec() { } it("it checks if descriptors match") { let otherDescriptor = AnyTypeDescriptorMock() - _ = key.matches(AnyBindingKey(descriptor: otherDescriptor)) + _ = key.matches(AnyBindingKey(descriptor: otherDescriptor)) expect(descriptor.matchesReceivedOther) === otherDescriptor } it("matches if descriptors match") { @@ -35,14 +38,29 @@ class BindingKeySpec: QuickSpec { override func spec() { expect { key.matches(otherKey) }.to(beTrue()) } it("does not match if argument types are different") { - let key = AnyBindingKey(descriptor: descriptor) + let key = ArgumentBindingKey(descriptor: descriptor) otherKey.argumentType = Double.self expect(key.matches(otherKey)).to(beFalse()) } it("matches if argument types are the same") { - let key = AnyBindingKey(descriptor: descriptor) + let key = ArgumentBindingKey(descriptor: descriptor) otherKey.argumentType = Int.self expect(key.matches(otherKey)).to(beTrue()) } + it("does not match if context types are different") { + let key = ContextBindingKey(descriptor: descriptor) + otherKey.contextType = Double.self + expect(key.matches(otherKey)).to(beFalse()) + } + it("matches if argument context are the same") { + let key = ContextBindingKey(descriptor: descriptor) + otherKey.contextType = Int.self + expect(key.matches(otherKey)).to(beTrue()) + } + it("matches if context is Any") { + let key = ContextBindingKey(descriptor: descriptor) + otherKey.contextType = Int.self + expect(key.matches(otherKey)).to(beTrue()) + } } } } diff --git a/Tests/UnitSpecs/SwinjectSpec.swift b/Tests/UnitSpecs/SwinjectSpec.swift index 8c48421b..04c2431f 100644 --- a/Tests/UnitSpecs/SwinjectSpec.swift +++ b/Tests/UnitSpecs/SwinjectSpec.swift @@ -65,7 +65,7 @@ class SwinjectSpec: QuickSpec { override func spec() { it("matches binding with correct key") { key.matchesReturnValue = false _ = try? swinject.instance(tagged: "tag") as Int - let otherKey = key.matchesReceivedOther as? BindingKey, Void> + let otherKey = key.matchesReceivedOther as? BindingKey, Void, Void> let descriptor = otherKey?.descriptor as? Tagged expect(descriptor?.tag) == "tag" } @@ -140,7 +140,7 @@ class SwinjectSpec: QuickSpec { override func spec() { it("matches binding with correct key") { key.matchesReturnValue = true _ = try? swinject.provider(of: Any.self, tagged: "tag")() - let otherKey = key.matchesReceivedOther as? BindingKey, Void> + let otherKey = key.matchesReceivedOther as? BindingKey, Void, Void> let descriptor = otherKey?.descriptor as? Tagged expect(descriptor?.tag) == "tag" } @@ -192,7 +192,7 @@ class SwinjectSpec: QuickSpec { override func spec() { it("matches binding with correct key") { key.matchesReturnValue = false _ = try? swinject.factory(tagged: "tag")("arg") as Int - let otherKey = key.matchesReceivedOther as? BindingKey, String> + let otherKey = key.matchesReceivedOther as? BindingKey, Void, String> let descriptor = otherKey?.descriptor as? Tagged expect(descriptor?.tag) == "tag" } From 3a1352996d9ed5dce597cd43240a0e77a4294733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Tue, 16 Jul 2019 23:43:12 +0200 Subject: [PATCH 048/239] Fix default context type --- Sources/Binding.swift | 4 +-- Sources/BindingBuilder.swift | 16 +++++----- Tests/UnitSpecs/BindingBuilderSpec.swift | 40 +++++++++++++++--------- Tests/UnitSpecs/TypeBinderSpec.swift | 4 +-- 4 files changed, 38 insertions(+), 26 deletions(-) diff --git a/Sources/Binding.swift b/Sources/Binding.swift index 5c413e3b..0416f3f5 100644 --- a/Sources/Binding.swift +++ b/Sources/Binding.swift @@ -14,7 +14,7 @@ public protocol Binding: AnyBinding { func instance(arg: Argument, context: Context, resolver: Resolver) throws -> BoundType } -extension Binding where Argument == Void, Context == Void { +extension Binding where Argument == Void, Context == Any { func instance(resolver: Resolver) throws -> BoundType { try instance(arg: (), context: (), resolver: resolver) } @@ -26,7 +26,7 @@ extension Binding where Argument == Void { } } -extension Binding where Context == Void { +extension Binding where Context == Any { func instance(arg: Argument, resolver: Resolver) throws -> BoundType { try instance(arg: arg, context: (), resolver: resolver) } diff --git a/Sources/BindingBuilder.swift b/Sources/BindingBuilder.swift index 65a36f4d..2673bf24 100644 --- a/Sources/BindingBuilder.swift +++ b/Sources/BindingBuilder.swift @@ -34,34 +34,34 @@ extension BindingBuilder { } } -public func instance(_ instance: Type) -> SimpleBinding { +public func instance(_ instance: Type) -> SimpleBinding { SimpleBinding { _, _, _ in instance } } -public func provider(_ builder: @escaping () throws -> Type) -> SimpleBinding { +public func provider(_ builder: @escaping () throws -> Type) -> SimpleBinding { SimpleBinding { _, _, _ in try builder() } } -public func provider(_ builder: @escaping (Resolver) throws -> Type) -> SimpleBinding { +public func provider(_ builder: @escaping (Resolver) throws -> Type) -> SimpleBinding { SimpleBinding { r, _, _ in try builder(r) } } -public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> SimpleBinding { +public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> SimpleBinding { SimpleBinding { try builder($0, $2) } } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SimpleBinding { +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SimpleBinding { SimpleBinding { try builder($0, $2.0, $2.1) } } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SimpleBinding { +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SimpleBinding { SimpleBinding { try builder($0, $2.0, $2.1, $2.2) } } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SimpleBinding { +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SimpleBinding { SimpleBinding { try builder($0, $2.0, $2.1, $2.2, $2.3) } } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SimpleBinding { +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SimpleBinding { SimpleBinding { try builder($0, $2.0, $2.1, $2.2, $2.3, $2.4) } } diff --git a/Tests/UnitSpecs/BindingBuilderSpec.swift b/Tests/UnitSpecs/BindingBuilderSpec.swift index cfa3e9c7..a38b3bc5 100644 --- a/Tests/UnitSpecs/BindingBuilderSpec.swift +++ b/Tests/UnitSpecs/BindingBuilderSpec.swift @@ -8,6 +8,10 @@ import Quick class BindingBuilderSpec: QuickSpec { override func spec() { describe("instance") { + it("produces binding with correct type signature") { + let binding = instance(42) as Any + expect(binding is SimpleBinding).to(beTrue()) + } it("returns given instance") { let binding = instance(42) expect { try binding.instance(resolver: DummyResolver()) } == 42 @@ -16,6 +20,10 @@ class BindingBuilderSpec: QuickSpec { override func spec() { describe("provider") { // TODO: Can we reuse tests for with / without context? describe("without context") { + it("produces binding with correct type signature") { + let binding = provider { 42 } as Any + expect(binding is SimpleBinding).to(beTrue()) + } it("returns instance made by provider method") { let binding = provider { 42 } expect { try binding.instance(resolver: DummyResolver()) } == 42 @@ -45,7 +53,7 @@ class BindingBuilderSpec: QuickSpec { override func spec() { } describe("contexted") { it("returns instance made by provider method") { - let binding = contexted(Void.self).provider { _, _ in 42 } + let binding = contexted(Any.self).provider { _, _ in 42 } expect { try binding.instance(resolver: DummyResolver()) } == 42 } it("does not call builder until instance is requested") { @@ -56,7 +64,7 @@ class BindingBuilderSpec: QuickSpec { override func spec() { it("calls builder with given provider") { var passedResolver: Resolver? let resolver = DummyResolver() - let binding = contexted(Void.self).provider { r, _ in passedResolver = r } + let binding = contexted(Any.self).provider { r, _ in passedResolver = r } _ = try? binding.instance(resolver: resolver) expect(passedResolver) === resolver } @@ -67,11 +75,11 @@ class BindingBuilderSpec: QuickSpec { override func spec() { expect(passedContext) == 42 } it("rethrows error from builder") { - let binding = contexted(Void.self).provider { _, _ in throw SwinjectError() } + let binding = contexted(Any.self).provider { _, _ in throw SwinjectError() } expect { try binding.instance(resolver: DummyResolver()) }.to(throwError()) } it("does not reuse instance") { - let binding = contexted(Void.self).provider { _, _ in Person() } + let binding = contexted(Any.self).provider { _, _ in Person() } let instance1 = try? binding.instance(resolver: DummyResolver()) let instance2 = try? binding.instance(resolver: DummyResolver()) expect(instance1) !== instance2 @@ -80,6 +88,10 @@ class BindingBuilderSpec: QuickSpec { override func spec() { } describe("factory") { describe("without context") { + it("produces binding with correct type signature") { + let binding = factory { (_, _: Void) in 42 } as Any + expect(binding is SimpleBinding).to(beTrue()) + } it("returns instance made by builder method") { let binding = factory { (_, _: Void) in 42 } expect { try binding.instance(resolver: DummyResolver()) } == 42 @@ -137,18 +149,18 @@ class BindingBuilderSpec: QuickSpec { override func spec() { } describe("contexted") { it("returns instance made by builder method") { - let binding = contexted(Void.self).factory { (_, _, _: Void) in 42 } + let binding = contexted(Any.self).factory { (_, _, _: Void) in 42 } expect { try binding.instance(resolver: DummyResolver()) } == 42 } it("does not call builder until instance is requested") { var called = false - _ = contexted(Void.self).factory { (_, _, _: Void) in called = true } + _ = contexted(Any.self).factory { (_, _, _: Void) in called = true } expect(called).to(beFalse()) } it("calls builder with given provider") { var passedResolver: Resolver? let resolver = DummyResolver() - let binding = contexted(Void.self).factory { (r, _, _: Void) in passedResolver = r } + let binding = contexted(Any.self).factory { (r, _, _: Void) in passedResolver = r } _ = try? binding.instance(resolver: resolver) expect(passedResolver) === resolver } @@ -160,38 +172,38 @@ class BindingBuilderSpec: QuickSpec { override func spec() { } it("calls builder with given argument") { var passedArgument: Int? - let binding = contexted(Void.self).factory { (_, _, arg: Int) in passedArgument = arg } + let binding = contexted(Any.self).factory { (_, _, arg: Int) in passedArgument = arg } _ = try? binding.instance(arg: 42, resolver: DummyResolver()) expect(passedArgument) == 42 } it("rethrows error from builder") { - let binding = contexted(Void.self).factory { (_, _, _: Void) in throw SwinjectError() } + let binding = contexted(Any.self).factory { (_, _, _: Void) in throw SwinjectError() } expect { try binding.instance(resolver: DummyResolver()) }.to(throwError()) } it("does not reuse instance") { - let binding = contexted(Void.self).factory { (_, _, _: Void) in Person() } + let binding = contexted(Any.self).factory { (_, _, _: Void) in Person() } let instance1 = try? binding.instance(resolver: DummyResolver()) let instance2 = try? binding.instance(resolver: DummyResolver()) expect(instance1) !== instance2 } describe("multiple arguments") { it("works with 2 arguments") { - let binding = contexted(Void.self).factory { (_, _, _: Int, _: Double) in 42 } + let binding = contexted(Any.self).factory { (_, _, _: Int, _: Double) in 42 } let arguments = (1, 1.0) expect { try binding.instance(arg: arguments, resolver: DummyResolver()) } == 42 } it("works with 3 arguments") { - let binding = contexted(Void.self).factory { (_, _, _: Int, _: Double, _: String) in 42 } + let binding = contexted(Any.self).factory { (_, _, _: Int, _: Double, _: String) in 42 } let arguments = (1, 1.0, "") expect { try binding.instance(arg: arguments, resolver: DummyResolver()) } == 42 } it("works with 4 arguments") { - let binding = contexted(Void.self).factory { (_, _, _: Int, _: Double, _: String, _: Float) in 42 } + let binding = contexted(Any.self).factory { (_, _, _: Int, _: Double, _: String, _: Float) in 42 } let arguments = (1, 1.0, "", Float(1.0)) expect { try binding.instance(arg: arguments, resolver: DummyResolver()) } == 42 } it("works with 5 arguments") { - let binding = contexted(Void.self).factory { (_, _, _: Int, _: Double, _: String, _: Float, _: Int) in 42 } + let binding = contexted(Any.self).factory { (_, _, _: Int, _: Double, _: String, _: Float, _: Int) in 42 } let arguments = (1, 1.0, "", Float(1.0), 5) expect { try binding.instance(arg: arguments, resolver: DummyResolver()) } == 42 } diff --git a/Tests/UnitSpecs/TypeBinderSpec.swift b/Tests/UnitSpecs/TypeBinderSpec.swift index cb0b1b7a..8348b4a8 100644 --- a/Tests/UnitSpecs/TypeBinderSpec.swift +++ b/Tests/UnitSpecs/TypeBinderSpec.swift @@ -38,7 +38,7 @@ class TypeBinderSpec: QuickSpec { override func spec() { } it("produces entry if given value of descriptor type") { let entry = bbind(Int.self).with(42) - expect(entry.binding is SimpleBinding).to(beTrue()) + expect(entry.binding is SimpleBinding).to(beTrue()) } } describe("& operator") { @@ -56,7 +56,7 @@ class TypeBinderSpec: QuickSpec { override func spec() { } it("produces entry provider if given value of descriptor type") { let entry = bbind(Int.self) & 42 - expect(entry.binding is SimpleBinding).to(beTrue()) + expect(entry.binding is SimpleBinding).to(beTrue()) } } } } From e5236707dc7b25ea3dcd3d7da4d3c19d6e7b9c83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Wed, 17 Jul 2019 06:27:44 +0200 Subject: [PATCH 049/239] Implement contexted resolver --- .sourcery.yml | 1 + Sources/ContextedResolver.swift | 20 ++++++++++ Sources/Resolver.swift | 12 +++++- Swinject.xcodeproj/project.pbxproj | 12 ++++++ Tests/Support/GeneratedMocks.swift | 25 ++++++++++++ Tests/Support/NonGeneratedMocks.swift | 11 ++++++ Tests/UnitSpecs/ContextedResolverSpec.swift | 42 +++++++++++++++++++++ 7 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 Sources/ContextedResolver.swift create mode 100644 Tests/UnitSpecs/ContextedResolverSpec.swift diff --git a/.sourcery.yml b/.sourcery.yml index 6a171f32..4b38cc34 100644 --- a/.sourcery.yml +++ b/.sourcery.yml @@ -1,5 +1,6 @@ sources: - Sources + - Tests/Support/NonGeneratedMocks.swift templates: - Templates output: diff --git a/Sources/ContextedResolver.swift b/Sources/ContextedResolver.swift new file mode 100644 index 00000000..f15a2231 --- /dev/null +++ b/Sources/ContextedResolver.swift @@ -0,0 +1,20 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +struct ContextedResolver { + let context: Context + let resolver: Resolver +} + +extension ContextedResolver: Resolver { + func resolve(_ request: BindingRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { + try resolver.resolve( + BindingRequest( + key: BindingKey(descriptor: request.key.descriptor), + context: context, + argument: request.argument + ) + ) + } +} diff --git a/Sources/Resolver.swift b/Sources/Resolver.swift index 106f7cac..900eddd0 100644 --- a/Sources/Resolver.swift +++ b/Sources/Resolver.swift @@ -6,7 +6,12 @@ public protocol Resolver { func resolve(_ request: BindingRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor } -// TODO: Overloads for multiple arguments & tag / notag combinations +public extension Resolver { + func on(_ context: Context) -> Resolver { + ContextedResolver(context: context, resolver: self) + } +} + public extension Resolver { func instance(of _: Type.Type = Type.self) throws -> Type { try instance(tagged: NoTag()) @@ -15,7 +20,9 @@ public extension Resolver { func instance(of _: Type.Type = Type.self, tagged tag: Tag) throws -> Type { try resolve(request(tag: tag, arg: ())) } +} +public extension Resolver { func provider(of _: Type.Type = Type.self) -> () throws -> Type { provider(tagged: NoTag()) } @@ -23,7 +30,10 @@ public extension Resolver { func provider(of _: Type.Type = Type.self, tagged tag: Tag) -> () throws -> Type { return { try self.resolve(request(tag: tag, arg: ())) } } +} +// TODO: Overloads for multiple arguments & tag / notag combinations +public extension Resolver { func factory(of _: Type.Type = Type.self) -> (Argument) throws -> Type { factory(tagged: NoTag()) } diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 80a8719c..342c86f5 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -18,6 +18,8 @@ CD6DE53D22DD30A100532D08 /* BindingBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53C22DD30A100532D08 /* BindingBuilderSpec.swift */; }; CD6DE54122DE657500532D08 /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE54022DE657400532D08 /* SimpleBinding.swift */; }; CD6DE54322DE65B500532D08 /* BindingBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE54222DE65B500532D08 /* BindingBuilder.swift */; }; + CD6DE54522DED11600532D08 /* ContextedResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE54422DED11600532D08 /* ContextedResolver.swift */; }; + CD6DE54722DED16400532D08 /* ContextedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE54622DED16400532D08 /* ContextedResolverSpec.swift */; }; CD85AF1222DA5A8F00A8B7CA /* NonGeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF1122DA5A8F00A8B7CA /* NonGeneratedMocks.swift */; }; CDADF32122DB38C600C5D8DB /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDADF32022DB38C600C5D8DB /* SwinjectTree.swift */; }; CDADF33522DB521400C5D8DB /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDADF33422DB521400C5D8DB /* SwinjectModule.swift */; }; @@ -61,6 +63,10 @@ CD6DE53C22DD30A100532D08 /* BindingBuilderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingBuilderSpec.swift; sourceTree = ""; }; CD6DE54022DE657400532D08 /* SimpleBinding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SimpleBinding.swift; sourceTree = ""; }; CD6DE54222DE65B500532D08 /* BindingBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingBuilder.swift; sourceTree = ""; }; + CD6DE54422DED11600532D08 /* ContextedResolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextedResolver.swift; sourceTree = ""; }; + CD6DE54622DED16400532D08 /* ContextedResolverSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextedResolverSpec.swift; sourceTree = ""; }; + CD6DE54822DED4A100532D08 /* .swiftformat */ = {isa = PBXFileReference; lastKnownFileType = text; path = .swiftformat; sourceTree = ""; }; + CD6DE54A22DED4A100532D08 /* .sourcery.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .sourcery.yml; sourceTree = ""; }; CD85AF1122DA5A8F00A8B7CA /* NonGeneratedMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonGeneratedMocks.swift; sourceTree = ""; }; CDADF32022DB38C600C5D8DB /* SwinjectTree.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTree.swift; sourceTree = ""; }; CDADF33422DB521400C5D8DB /* SwinjectModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectModule.swift; sourceTree = ""; }; @@ -104,6 +110,8 @@ 771BFC6622D5F83E00AFB237 = { isa = PBXGroup; children = ( + CD6DE54A22DED4A100532D08 /* .sourcery.yml */, + CD6DE54822DED4A100532D08 /* .swiftformat */, 771BFC7222D5F83E00AFB237 /* Sources */, 771BFC7D22D5F83E00AFB237 /* Tests */, CDADF33B22DB878C00C5D8DB /* Templates */, @@ -133,6 +141,7 @@ CD6DE54022DE657400532D08 /* SimpleBinding.swift */, CD6DE54222DE65B500532D08 /* BindingBuilder.swift */, CDD8380F22DA429F003E9909 /* Resolver.swift */, + CD6DE54422DED11600532D08 /* ContextedResolver.swift */, CDD8380D22DA3B0D003E9909 /* BindingEntry.swift */, CD6DE53622DD1CE900532D08 /* BindingKey.swift */, CD6DE53822DD1D0A00532D08 /* BindingRequest.swift */, @@ -182,6 +191,7 @@ CD6DE53C22DD30A100532D08 /* BindingBuilderSpec.swift */, CDD8381922DA4C9F003E9909 /* SwinjectSpec.swift */, CD6DE53322DD1C6800532D08 /* BindingKeySpec.swift */, + CD6DE54622DED16400532D08 /* ContextedResolverSpec.swift */, ); path = UnitSpecs; sourceTree = ""; @@ -374,6 +384,7 @@ CD6DE54122DE657500532D08 /* SimpleBinding.swift in Sources */, CDD8381D22DA4E02003E9909 /* SwinjectError.swift in Sources */, CDD8380722DA30C6003E9909 /* TypeDescriptor.swift in Sources */, + CD6DE54522DED11600532D08 /* ContextedResolver.swift in Sources */, CDD8381622DA4B55003E9909 /* Swinject.swift in Sources */, CDD8380522DA307F003E9909 /* TypeBinder.swift in Sources */, CDD8380E22DA3B0D003E9909 /* BindingEntry.swift in Sources */, @@ -384,6 +395,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + CD6DE54722DED16400532D08 /* ContextedResolverSpec.swift in Sources */, CDD8381F22DA4F6F003E9909 /* Utils.swift in Sources */, CDD8381B22DA4CBE003E9909 /* SwinjectSpec.swift in Sources */, CDADF34022DB883A00C5D8DB /* GeneratedMocks.swift in Sources */, diff --git a/Tests/Support/GeneratedMocks.swift b/Tests/Support/GeneratedMocks.swift index ca6d7c11..317988f0 100644 --- a/Tests/Support/GeneratedMocks.swift +++ b/Tests/Support/GeneratedMocks.swift @@ -87,6 +87,31 @@ class AnyBindingKeyMock: AnyBindingKey { } } +class AnyResolverMock: AnyResolver { + // MARK: - resolve + + var resolveThrowableError: Error? + var resolveCallsCount = 0 + var resolveCalled: Bool { + return resolveCallsCount > 0 + } + + var resolveReceivedRequest: Any? + var resolveReceivedInvocations: [Any] = [] + var resolveReturnValue: Any! + var resolveClosure: ((Any) throws -> Any)? + + func resolve(_ request: Any) throws -> Any { + if let error = resolveThrowableError { + throw error + } + resolveCallsCount += 1 + resolveReceivedRequest = request + resolveReceivedInvocations.append(request) + return try resolveClosure.map { try $0(request) } ?? resolveReturnValue + } +} + class AnyTypeDescriptorMock: AnyTypeDescriptor { // MARK: - matches diff --git a/Tests/Support/NonGeneratedMocks.swift b/Tests/Support/NonGeneratedMocks.swift index af2391d6..21dadd54 100644 --- a/Tests/Support/NonGeneratedMocks.swift +++ b/Tests/Support/NonGeneratedMocks.swift @@ -23,3 +23,14 @@ class DummyBinding: Binding { fatalError() } } + +// sourcery: AutoMockable +protocol AnyResolver { + func resolve(_ request: Any) throws -> Any +} + +extension AnyResolverMock: Resolver { + func resolve(_ request: BindingRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { + try resolve(request as Any) as! Descriptor.BaseType + } +} diff --git a/Tests/UnitSpecs/ContextedResolverSpec.swift b/Tests/UnitSpecs/ContextedResolverSpec.swift new file mode 100644 index 00000000..69854077 --- /dev/null +++ b/Tests/UnitSpecs/ContextedResolverSpec.swift @@ -0,0 +1,42 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +import Nimble +import Quick +@testable import Swinject + +class ContextedResolverSpec: QuickSpec { override func spec() { + var resolver: ContextedResolver! + var wrapped = AnyResolverMock() + beforeEach { + wrapped = AnyResolverMock() + wrapped.resolveReturnValue = 0 + resolver = ContextedResolver(context: (), resolver: wrapped) + } + describe("resolve") { + it("returns value from wrapped resolver") { + let intRequest = request(type: Int.self, tag: NoTag(), arg: ()) + wrapped.resolveReturnValue = 42 + expect { try resolver.resolve(intRequest) } == 42 + } + it("calls wrapped resolver with given type descriptor") { + let descriptor = AnyTypeDescriptorMock() + let request = BindingRequest(key: BindingKey(descriptor: descriptor), context: (), argument: ()) + _ = try? resolver.resolve(request) + let receivedRequest = wrapped.resolveReceivedRequest as? BindingRequest + expect(receivedRequest?.key.descriptor) === descriptor + } + it("calls wrapped resolver with given argument") { + _ = try? resolver.resolve(request(type: Int.self, tag: NoTag(), arg: "argument")) + let receivedRequest = wrapped.resolveReceivedRequest as? BindingRequest, Void, String> + expect(receivedRequest?.argument) == "argument" + } + it("calls wrapped resolver with it's context") { + let resolver = ContextedResolver(context: "context", resolver: wrapped) + _ = try? resolver.resolve(request(type: Int.self, tag: NoTag(), arg: ())) + let receivedRequest = wrapped.resolveReceivedRequest as? BindingRequest, String, Void> + expect(receivedRequest?.context) == "context" + } + } +} } From c95350110322fece2554136dccd65f33eed62657 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Wed, 17 Jul 2019 06:36:46 +0200 Subject: [PATCH 050/239] Extend Swinject specification --- Sources/Swinject.swift | 6 +++--- Tests/UnitSpecs/SwinjectSpec.swift | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/Sources/Swinject.swift b/Sources/Swinject.swift index ac072740..b4e2e07d 100644 --- a/Sources/Swinject.swift +++ b/Sources/Swinject.swift @@ -26,7 +26,7 @@ public extension Swinject { extension Swinject: Resolver { public func resolve(_ request: BindingRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { - try instance(from: findBinding(for: request.key), arg: request.argument) + try instance(from: findBinding(for: request.key), context: request.context, arg: request.argument) } private func findBinding(for key: AnyBindingKey) throws -> AnyBinding { @@ -35,7 +35,7 @@ extension Swinject: Resolver { return entries[0].binding } - private func instance(from binding: AnyBinding, arg: Argument) throws -> Type { - try binding.instance(arg: arg, context: (), resolver: self) as? Type ?? { throw SwinjectError() }() + private func instance(from binding: AnyBinding, context: Context, arg: Argument) throws -> Type { + try binding.instance(arg: arg, context: context, resolver: self) as? Type ?? { throw SwinjectError() }() } } diff --git a/Tests/UnitSpecs/SwinjectSpec.swift b/Tests/UnitSpecs/SwinjectSpec.swift index 04c2431f..b289ab94 100644 --- a/Tests/UnitSpecs/SwinjectSpec.swift +++ b/Tests/UnitSpecs/SwinjectSpec.swift @@ -69,6 +69,11 @@ class SwinjectSpec: QuickSpec { override func spec() { let descriptor = otherKey?.descriptor as? Tagged expect(descriptor?.tag) == "tag" } + it("matches binding with correct context") { + key.matchesReturnValue = false + _ = try? swinject.on("context").instance() as Int + expect(key.matchesReceivedOther?.contextType is String.Type).to(beTrue()) + } } context("multiple bindings") { var swinject: Swinject! @@ -144,6 +149,16 @@ class SwinjectSpec: QuickSpec { override func spec() { let descriptor = otherKey?.descriptor as? Tagged expect(descriptor?.tag) == "tag" } + it("matches binding with correct context") { + key.matchesReturnValue = false + _ = try? swinject.on("context").provider()() as Int + expect(key.matchesReceivedOther?.contextType is String.Type).to(beTrue()) + } + it("passes given context to the bidndning") { + key.matchesReturnValue = true + _ = try? swinject.on("context").provider()() as Int + expect(binding.instanceArgContextResolverReceivedArguments?.context as? String) == "context" + } } describe("factory injection") { var swinject: Swinject! @@ -196,6 +211,16 @@ class SwinjectSpec: QuickSpec { override func spec() { let descriptor = otherKey?.descriptor as? Tagged expect(descriptor?.tag) == "tag" } + it("matches binding with correct context") { + key.matchesReturnValue = false + _ = try? swinject.on("context").factory()("arg") as Int + expect(key.matchesReceivedOther?.contextType is String.Type).to(beTrue()) + } + it("passes given context to the bidndning") { + key.matchesReturnValue = true + _ = try? swinject.on("context").factory()("arg") as Int + expect(binding.instanceArgContextResolverReceivedArguments?.context as? String) == "context" + } context("currying") { beforeEach { key.matchesReturnValue = true From efd82650043b1b7bd219b1ee673fdc20db6be4a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Wed, 17 Jul 2019 06:45:17 +0200 Subject: [PATCH 051/239] Enable code coverage gathering --- .../xcschemes/Swinject-OSX.xcscheme | 22 +++++++++-- Tests/UnitSpecs/SwinjectTreeBuilderSpec.swift | 37 ++++++++++--------- 2 files changed, 38 insertions(+), 21 deletions(-) diff --git a/Swinject.xcodeproj/xcshareddata/xcschemes/Swinject-OSX.xcscheme b/Swinject.xcodeproj/xcshareddata/xcschemes/Swinject-OSX.xcscheme index ed0a2882..4171a2ce 100644 --- a/Swinject.xcodeproj/xcshareddata/xcschemes/Swinject-OSX.xcscheme +++ b/Swinject.xcodeproj/xcshareddata/xcschemes/Swinject-OSX.xcscheme @@ -1,7 +1,7 @@ + version = "1.7"> @@ -26,10 +26,22 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - shouldUseLaunchSchemeArgsEnv = "YES"> + shouldUseLaunchSchemeArgsEnv = "YES" + codeCoverageEnabled = "YES" + onlyGenerateCoverageForSpecifiedTargets = "YES"> + + + + + skipped = "NO" + parallelizable = "YES"> + + diff --git a/Tests/UnitSpecs/SwinjectTreeBuilderSpec.swift b/Tests/UnitSpecs/SwinjectTreeBuilderSpec.swift index 2a4cdc32..de5d53fe 100644 --- a/Tests/UnitSpecs/SwinjectTreeBuilderSpec.swift +++ b/Tests/UnitSpecs/SwinjectTreeBuilderSpec.swift @@ -22,24 +22,25 @@ class SwinjectTreeBuilderSpec: QuickSpec { override func spec() { } expect(tree.bindingEntries.count) == 5 } - it("builds closure with if statement") { - let tree = makeTree { - if true { AnyBindingEntryMock() } - } - expect(tree.bindingEntries.count) == 1 - } - it("builds closure with nested if statement") { - let tree = makeTree { - if true { AnyBindingEntryMock(); if true { AnyBindingEntryMock() } } - } - expect(tree.bindingEntries.count) == 2 - } - it("builds closure with if else statement") { - let tree = makeTree { - if false {} else { AnyBindingEntryMock(); AnyBindingEntryMock() } - } - expect(tree.bindingEntries.count) == 2 - } + // FIXME: Test coverage enabled build segfaults on this +// it("builds closure with if statement") { +// let tree = makeTree { +// if true { AnyBindingEntryMock() } +// } +// expect(tree.bindingEntries.count) == 1 +// } +// it("builds closure with nested if statement") { +// let tree = makeTree { +// if true { AnyBindingEntryMock(); if true { AnyBindingEntryMock() } } +// } +// expect(tree.bindingEntries.count) == 2 +// } +// it("builds closure with if else statement") { +// let tree = makeTree { +// if false {} else { AnyBindingEntryMock(); AnyBindingEntryMock() } +// } +// expect(tree.bindingEntries.count) == 2 +// } it("builds closure with binding & include entries") { let tree = makeTree { ModuleIncludeEntryMock() From 27c81d0cd871f5bfe506876f15613f3ea23dac47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Wed, 17 Jul 2019 07:09:39 +0200 Subject: [PATCH 052/239] Extend API spec [WIP] --- Tests/ApiSpecs/InjectionApiSpec.swift | 34 +++++++++++++++++++++------ 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/Tests/ApiSpecs/InjectionApiSpec.swift b/Tests/ApiSpecs/InjectionApiSpec.swift index 177e1fdd..bdb30e28 100644 --- a/Tests/ApiSpecs/InjectionApiSpec.swift +++ b/Tests/ApiSpecs/InjectionApiSpec.swift @@ -11,11 +11,7 @@ class InjectionApiSpec: QuickSpec { override func spec() { beforeEach { person = Person() } - it("throws for empty swinject") { - let swinject = Swinject {} - expect { try swinject.instance(of: Int.self) }.to(throwError()) - } - it("returns instance if provider is bound") { + it("returns instance if is bound") { let swinject = Swinject { bbind(Int.self).with(42) } @@ -40,7 +36,7 @@ class InjectionApiSpec: QuickSpec { override func spec() { } expect { try swinject.instance(of: Pet.self).owner } === person } - it("throws if multiple providers are bound") { + it("throws if has multiple entries for the same request") { let swinject = Swinject { bbind(Int.self) & 42 bbind(Int.self) & provider { 17 + 25 } @@ -55,7 +51,7 @@ class InjectionApiSpec: QuickSpec { override func spec() { expect { try swinject.instance(of: Int.self, tagged: 42) }.to(throwError()) expect { try swinject.instance(of: Int.self, tagged: "OtherTag") }.to(throwError()) } - it("returns isntance with correct tag") { + it("returns instance with correct tag") { let swinject = Swinject { bbind(String.self) & "Plain" bbind(String.self, tagged: "Tag") & "Tagged" @@ -63,4 +59,28 @@ class InjectionApiSpec: QuickSpec { override func spec() { expect { try swinject.instance(of: String.self) } == "Plain" expect { try swinject.instance(of: String.self, tagged: "Tag") } == "Tagged" } + it("can inject instance provider") { + let swinject = Swinject { + bbind(Int.self, tagged: "tag") & 42 + } + let provider = swinject.provider(of: Int.self, tagged: "tag") + expect { try provider() } == 42 + } + it("can inject instance factory") { + let intFactory = factory { (r, arg: Int) in Int(try r.instance() as Double) + 5 * arg } + let swinject = Swinject { + bbind(Double.self) & 17.0 + bbind(Int.self) & intFactory + } + let factory = swinject.factory() as (Int) throws -> Int + expect { try factory(5) } == 42 + } + it("can inject factory binding as provider or instance") { + let swinject = Swinject { + bbind(Double.self) & 17.0 + bbind(Int.self) & factory { Int(try $0.instance() as Double) + 5 * $1 } + } + expect { try swinject.provider(of: Int.self, arg: 5)() } == 42 + expect { try swinject.instance(of: Int.self, arg: 5) } == 42 + } } } From ee1aa7b2c78355eaa0b44a4ac10c2d9e08ae90b2 Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Wed, 17 Jul 2019 10:11:46 +0200 Subject: [PATCH 053/239] Update injection api spec --- Sources/Resolver.swift | 33 +++++++++++++++++++++++---- Sources/TypeBinder.swift | 2 +- Tests/ApiSpecs/InjectionApiSpec.swift | 33 ++++++++++++++++++++++++++- Tests/Support/NonGeneratedMocks.swift | 4 ++-- Tests/UnitSpecs/SwinjectSpec.swift | 15 +++++++++++- Tests/UnitSpecs/TypeBinderSpec.swift | 12 ++++++++-- 6 files changed, 88 insertions(+), 11 deletions(-) diff --git a/Sources/Resolver.swift b/Sources/Resolver.swift index 900eddd0..05e2ae22 100644 --- a/Sources/Resolver.swift +++ b/Sources/Resolver.swift @@ -12,27 +12,44 @@ public extension Resolver { } } +// TODO: Overloads for multiple arguments & tag / notag combinations + public extension Resolver { func instance(of _: Type.Type = Type.self) throws -> Type { - try instance(tagged: NoTag()) + try instance(tagged: NoTag(), arg: ()) + } + + func instance(of _: Type.Type = Type.self, arg: Argument) throws -> Type { + try instance(tagged: NoTag(), arg: arg) } func instance(of _: Type.Type = Type.self, tagged tag: Tag) throws -> Type { try resolve(request(tag: tag, arg: ())) } + + func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg: Argument) throws -> Type { + try resolve(request(tag: tag, arg: arg)) + } } public extension Resolver { func provider(of _: Type.Type = Type.self) -> () throws -> Type { - provider(tagged: NoTag()) + provider(tagged: NoTag(), arg: ()) + } + + func provider(of _: Type.Type = Type.self, arg: Argument) -> () throws -> Type { + provider(tagged: NoTag(), arg: arg) } func provider(of _: Type.Type = Type.self, tagged tag: Tag) -> () throws -> Type { - return { try self.resolve(request(tag: tag, arg: ())) } + provider(tagged: tag, arg: ()) + } + + func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg: Argument) -> () throws -> Type { + return { try self.resolve(request(tag: tag, arg: arg)) } } } -// TODO: Overloads for multiple arguments & tag / notag combinations public extension Resolver { func factory(of _: Type.Type = Type.self) -> (Argument) throws -> Type { factory(tagged: NoTag()) @@ -42,10 +59,18 @@ public extension Resolver { return { try self.resolve(request(tag: tag, arg: $0)) } } + func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2) throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: ($0, $1))) } + } + func factory(of _: Type.Type = Type.self, arg: Arg1) -> (Arg2) throws -> Type { return { try self.resolve(request(tag: NoTag(), arg: (arg, $0))) } } + func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2, Arg3) throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: ($0, $1, $2))) } + } + func factory(of _: Type.Type = Type.self, arg: Arg1) -> (Arg2, Arg3) throws -> Type { return { try self.resolve(request(tag: NoTag(), arg: (arg, $0, $1))) } } diff --git a/Sources/TypeBinder.swift b/Sources/TypeBinder.swift index ba85ca1a..13665ec9 100644 --- a/Sources/TypeBinder.swift +++ b/Sources/TypeBinder.swift @@ -20,7 +20,7 @@ public func bind(_ descriptor: Descriptor) -> TypeBinder public extension TypeBinder { func with(_ binding: SomeBinding) -> BindingEntry where SomeBinding: Binding, SomeBinding.BoundType == Descriptor.BaseType { - BindingEntry(key: BindingKey(descriptor: descriptor), binding: binding) + BindingEntry(key: BindingKey(descriptor: descriptor), binding: binding) } func with(_ anInstance: Descriptor.BaseType) -> BindingEntry { diff --git a/Tests/ApiSpecs/InjectionApiSpec.swift b/Tests/ApiSpecs/InjectionApiSpec.swift index bdb30e28..7bfe3664 100644 --- a/Tests/ApiSpecs/InjectionApiSpec.swift +++ b/Tests/ApiSpecs/InjectionApiSpec.swift @@ -29,7 +29,7 @@ class InjectionApiSpec: QuickSpec { override func spec() { } expect { try swinject.instance(of: Pet.self) }.to(throwError()) } - it("returns instance from bound dependency provider") { + it("returns instance if all dependencies are bound") { let swinject = Swinject { bbind(Pet.self) & provider { Pet(owner: try $0.instance()) } bbind(Person.self) & instance(person) @@ -67,6 +67,7 @@ class InjectionApiSpec: QuickSpec { override func spec() { expect { try provider() } == 42 } it("can inject instance factory") { + // FIXME: compiler segfaults if declaring this factory inside function builder let intFactory = factory { (r, arg: Int) in Int(try r.instance() as Double) + 5 * arg } let swinject = Swinject { bbind(Double.self) & 17.0 @@ -83,4 +84,34 @@ class InjectionApiSpec: QuickSpec { override func spec() { expect { try swinject.provider(of: Int.self, arg: 5)() } == 42 expect { try swinject.instance(of: Int.self, arg: 5) } == 42 } + it("can curry factory's arguments") { + let swinject = Swinject { + bbind(Int.self) & factory { (_, a1: Int, a2: Double, a3: String) in + a1 + Int(a2) + Int(a3)! + } + } + expect { try swinject.factory(of: Int.self)(11, 14.0, "17") } == 42 + expect { try swinject.factory(of: Int.self, arg: 11)(14.0, "17") } == 42 + expect { try swinject.factory(of: Int.self, args: 11, 14.0)("17") } == 42 + } + it("can pass context to the bindings") { + // FIXME: compiler segfaults if declaring these providers inside function builder + let intProvider = contexted(String.self).provider { _, string in Int(string)! } + let doubleProvider = contexted(String.self).provider { _, string in Double(string)! } + let swinject = Swinject { + bbind(Int.self) & intProvider + bbind(Double.self) & doubleProvider + } + let contexted = swinject.on("42") + expect { try contexted.instance(of: Int.self) } == 42 + expect { try contexted.instance(of: Double.self) } == 42 + expect { try swinject.instance(of: Int.self) }.to(throwError()) + } + it("can use binding without context in any context") { + let swinject = Swinject { + bbind(Int.self) & 42 + } + expect { try swinject.on("context").instance() as Int } == 42 + expect { try swinject.on(Person()).instance() as Int } == 42 + } } } diff --git a/Tests/Support/NonGeneratedMocks.swift b/Tests/Support/NonGeneratedMocks.swift index 21dadd54..3621d424 100644 --- a/Tests/Support/NonGeneratedMocks.swift +++ b/Tests/Support/NonGeneratedMocks.swift @@ -18,8 +18,8 @@ extension AnyBindingMock: Binding { typealias Argument = Any } -class DummyBinding: Binding { - func instance(arg _: Argument, context: Void, resolver _: Resolver) throws -> Any { +class DummyBinding: Binding { + func instance(arg _: Argument, context: Context, resolver _: Resolver) throws -> Any { fatalError() } } diff --git a/Tests/UnitSpecs/SwinjectSpec.swift b/Tests/UnitSpecs/SwinjectSpec.swift index b289ab94..f012c4ef 100644 --- a/Tests/UnitSpecs/SwinjectSpec.swift +++ b/Tests/UnitSpecs/SwinjectSpec.swift @@ -226,12 +226,25 @@ class SwinjectSpec: QuickSpec { override func spec() { key.matchesReturnValue = true binding.instanceArgContextResolverReturnValue = 42 } - it("can curry 2-tuple as argument") { + it("can curry 2-tuple as 0 / 2 argument") { + _ = try? swinject.factory()("arg1", "arg2") as Int + let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? (String, String) + expect(receivedArg?.0) == "arg1" + expect(receivedArg?.1) == "arg2" + } + it("can curry 2-tuple as 1 / 1 argument") { _ = try? swinject.factory(arg: "arg1")("arg2") as Int let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? (String, String) expect(receivedArg?.0) == "arg1" expect(receivedArg?.1) == "arg2" } + it("can curry 3-tuple as 0 / 3 argument") { + _ = try? swinject.factory()("arg1", 2, "arg3") as Int + let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? (String, Int, String) + expect(receivedArg?.0) == "arg1" + expect(receivedArg?.1) == 2 + expect(receivedArg?.2) == "arg3" + } it("can curry 3-tuple as 1 / 2 argument") { _ = try? swinject.factory(arg: "arg1")(2, "arg3") as Int let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? (String, Int, String) diff --git a/Tests/UnitSpecs/TypeBinderSpec.swift b/Tests/UnitSpecs/TypeBinderSpec.swift index 8348b4a8..eba73a3e 100644 --- a/Tests/UnitSpecs/TypeBinderSpec.swift +++ b/Tests/UnitSpecs/TypeBinderSpec.swift @@ -29,9 +29,13 @@ class TypeBinderSpec: QuickSpec { override func spec() { expect(entry.key.descriptor) === descriptor } it("produces entry with correct argument type") { - let entry = bbind(Any.self).with(DummyBinding()) + let entry = bbind(Any.self).with(DummyBinding()) expect(entry.key.argumentType is Int.Type).to(beTrue()) } + it("produces entry with correct context type") { + let entry = bbind(Any.self).with(DummyBinding()) + expect(entry.key.contextType is Int.Type).to(beTrue()) + } it("produces entry with correct binding") { let entry = bbind(Any.self).with(binding) expect(entry.binding) === binding @@ -47,9 +51,13 @@ class TypeBinderSpec: QuickSpec { override func spec() { expect(entry.key.descriptor) === descriptor } it("produces entry with correct argument type") { - let entry = bbind(Any.self) & DummyBinding() + let entry = bbind(Any.self) & DummyBinding() expect(entry.key.argumentType is Int.Type).to(beTrue()) } + it("produces entry with correct context type") { + let entry = bbind(Any.self) & DummyBinding() + expect(entry.key.contextType is Int.Type).to(beTrue()) + } it("produces entry with correct binding") { let entry = bbind(Any.self) & binding expect(entry.binding) === binding From cb5bb67df8be5282a3309c6016e35099345172af Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Wed, 17 Jul 2019 15:32:48 +0200 Subject: [PATCH 054/239] Rename binding to instance maker --- Sources/Binding.swift | 40 ---- Sources/BindingBuilder.swift | 67 ------ Sources/BindingEntry.swift | 12 +- Sources/BindingKey.swift | 8 +- Sources/BindingRequest.swift | 8 +- Sources/ContextedResolver.swift | 6 +- Sources/InstanceMaker.swift | 40 ++++ Sources/Resolver.swift | 2 +- Sources/SimpleBinding.swift | 19 -- Sources/SimpleInstanceMaker.swift | 79 +++++++ Sources/Swinject.swift | 14 +- Sources/SwinjectTree.swift | 4 +- Sources/TypeBinder.swift | 10 +- Swinject.xcodeproj/project.pbxproj | 28 +-- Tests/ApiSpecs/InjectionApiSpec.swift | 6 +- Tests/Support/GeneratedMocks.swift | 56 ++--- Tests/Support/NonGeneratedMocks.swift | 10 +- Tests/UnitSpecs/BindingBuilderSpec.swift | 213 ------------------ Tests/UnitSpecs/BindingKeySpec.swift | 28 +-- Tests/UnitSpecs/ContextedResolverSpec.swift | 8 +- Tests/UnitSpecs/SimpleInstanceMakerSpec.swift | 213 ++++++++++++++++++ Tests/UnitSpecs/SwinjectSpec.swift | 156 ++++++------- Tests/UnitSpecs/SwinjectTreeBuilderSpec.swift | 32 +-- Tests/UnitSpecs/TypeBinderSpec.swift | 32 +-- 24 files changed, 540 insertions(+), 551 deletions(-) delete mode 100644 Sources/Binding.swift delete mode 100644 Sources/BindingBuilder.swift create mode 100644 Sources/InstanceMaker.swift delete mode 100644 Sources/SimpleBinding.swift create mode 100644 Sources/SimpleInstanceMaker.swift delete mode 100644 Tests/UnitSpecs/BindingBuilderSpec.swift create mode 100644 Tests/UnitSpecs/SimpleInstanceMakerSpec.swift diff --git a/Sources/Binding.swift b/Sources/Binding.swift deleted file mode 100644 index 0416f3f5..00000000 --- a/Sources/Binding.swift +++ /dev/null @@ -1,40 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -// sourcery: AutoMockable -public protocol AnyBinding { - func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any -} - -public protocol Binding: AnyBinding { - associatedtype BoundType - associatedtype Argument - associatedtype Context - func instance(arg: Argument, context: Context, resolver: Resolver) throws -> BoundType -} - -extension Binding where Argument == Void, Context == Any { - func instance(resolver: Resolver) throws -> BoundType { - try instance(arg: (), context: (), resolver: resolver) - } -} - -extension Binding where Argument == Void { - func instance(context: Context, resolver: Resolver) throws -> BoundType { - try instance(arg: (), context: context, resolver: resolver) - } -} - -extension Binding where Context == Any { - func instance(arg: Argument, resolver: Resolver) throws -> BoundType { - try instance(arg: arg, context: (), resolver: resolver) - } -} - -public extension AnyBinding where Self: Binding { - func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any { - guard let arg = arg as? Argument, let context = context as? Context else { throw SwinjectError() } - return try instance(arg: arg, context: context, resolver: resolver) as BoundType - } -} diff --git a/Sources/BindingBuilder.swift b/Sources/BindingBuilder.swift deleted file mode 100644 index 2673bf24..00000000 --- a/Sources/BindingBuilder.swift +++ /dev/null @@ -1,67 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -public struct BindingBuilder {} - -public func contexted(_: Context.Type = Context.self) -> BindingBuilder { - BindingBuilder() -} - -extension BindingBuilder { - public func provider(_ builder: @escaping (Resolver, Context) throws -> Type) -> SimpleBinding { - SimpleBinding { r, c, _ in try builder(r, c) } - } - - public func factory(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SimpleBinding { - SimpleBinding(builder) - } - - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SimpleBinding { - SimpleBinding { try builder($0, $1, $2.0, $2.1) } - } - - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SimpleBinding { - SimpleBinding { try builder($0, $1, $2.0, $2.1, $2.2) } - } - - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SimpleBinding { - SimpleBinding { try builder($0, $1, $2.0, $2.1, $2.2, $2.3) } - } - - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SimpleBinding { - SimpleBinding { try builder($0, $1, $2.0, $2.1, $2.2, $2.3, $2.4) } - } -} - -public func instance(_ instance: Type) -> SimpleBinding { - SimpleBinding { _, _, _ in instance } -} - -public func provider(_ builder: @escaping () throws -> Type) -> SimpleBinding { - SimpleBinding { _, _, _ in try builder() } -} - -public func provider(_ builder: @escaping (Resolver) throws -> Type) -> SimpleBinding { - SimpleBinding { r, _, _ in try builder(r) } -} - -public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> SimpleBinding { - SimpleBinding { try builder($0, $2) } -} - -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SimpleBinding { - SimpleBinding { try builder($0, $2.0, $2.1) } -} - -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SimpleBinding { - SimpleBinding { try builder($0, $2.0, $2.1, $2.2) } -} - -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SimpleBinding { - SimpleBinding { try builder($0, $2.0, $2.1, $2.2, $2.3) } -} - -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SimpleBinding { - SimpleBinding { try builder($0, $2.0, $2.1, $2.2, $2.3, $2.4) } -} diff --git a/Sources/BindingEntry.swift b/Sources/BindingEntry.swift index 116bb4fe..6600b968 100644 --- a/Sources/BindingEntry.swift +++ b/Sources/BindingEntry.swift @@ -3,13 +3,13 @@ // // sourcery: AutoMockable -protocol AnyBindingEntry: SwinjectEntry { - var key: AnyBindingKey { get } - var binding: AnyBinding { get } +protocol AnyMakerEntry: SwinjectEntry { + var key: AnyMakerKey { get } + var maker: AnyInstanceMaker { get } } // TODO: Make this internal -public struct BindingEntry: AnyBindingEntry { - let key: AnyBindingKey - let binding: AnyBinding +public struct MakerEntry: AnyMakerEntry { + let key: AnyMakerKey + let maker: AnyInstanceMaker } diff --git a/Sources/BindingKey.swift b/Sources/BindingKey.swift index 563f7510..a7a61f98 100644 --- a/Sources/BindingKey.swift +++ b/Sources/BindingKey.swift @@ -3,20 +3,20 @@ // // sourcery: AutoMockable -protocol AnyBindingKey { +protocol AnyMakerKey { var contextType: Any.Type { get } var argumentType: Any.Type { get } var descriptor: AnyTypeDescriptor { get } - func matches(_ other: AnyBindingKey) -> Bool + func matches(_ other: AnyMakerKey) -> Bool } -public struct BindingKey: AnyBindingKey where Descriptor: TypeDescriptor { +public struct MakerKey: AnyMakerKey where Descriptor: TypeDescriptor { let contextType: Any.Type = Context.self let argumentType: Any.Type = Argument.self let descriptor: AnyTypeDescriptor - func matches(_ other: AnyBindingKey) -> Bool { + func matches(_ other: AnyMakerKey) -> Bool { descriptor.matches(other.descriptor) && (contextType == other.contextType || contextType == Any.self) && argumentType == other.argumentType diff --git a/Sources/BindingRequest.swift b/Sources/BindingRequest.swift index 2358bbeb..9d7fa66e 100644 --- a/Sources/BindingRequest.swift +++ b/Sources/BindingRequest.swift @@ -2,12 +2,12 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -public struct BindingRequest where Descriptor: TypeDescriptor { - let key: BindingKey +public struct MakerRequest where Descriptor: TypeDescriptor { + let key: MakerKey let context: Context let argument: Argument } -func request(type _: Type.Type = Type.self, tag: Tag, arg: Argument) -> BindingRequest, Void, Argument> { - BindingRequest(key: BindingKey(descriptor: Tagged(tag: tag)), context: (), argument: arg) +func request(type _: Type.Type = Type.self, tag: Tag, arg: Argument) -> MakerRequest, Void, Argument> { + MakerRequest(key: MakerKey(descriptor: Tagged(tag: tag)), context: (), argument: arg) } diff --git a/Sources/ContextedResolver.swift b/Sources/ContextedResolver.swift index f15a2231..c69b84d0 100644 --- a/Sources/ContextedResolver.swift +++ b/Sources/ContextedResolver.swift @@ -8,10 +8,10 @@ struct ContextedResolver { } extension ContextedResolver: Resolver { - func resolve(_ request: BindingRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { + func resolve(_ request: MakerRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { try resolver.resolve( - BindingRequest( - key: BindingKey(descriptor: request.key.descriptor), + MakerRequest( + key: MakerKey(descriptor: request.key.descriptor), context: context, argument: request.argument ) diff --git a/Sources/InstanceMaker.swift b/Sources/InstanceMaker.swift new file mode 100644 index 00000000..3bebf3cf --- /dev/null +++ b/Sources/InstanceMaker.swift @@ -0,0 +1,40 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +// sourcery: AutoMockable +public protocol AnyInstanceMaker { + func makeInstance(arg: Any, context: Any, resolver: Resolver) throws -> Any +} + +public protocol InstanceMaker: AnyInstanceMaker { + associatedtype MadeType + associatedtype Argument + associatedtype Context + func makeInstance(arg: Argument, context: Context, resolver: Resolver) throws -> MadeType +} + +extension InstanceMaker where Argument == Void, Context == Any { + func makeInstance(resolver: Resolver) throws -> MadeType { + try makeInstance(arg: (), context: (), resolver: resolver) + } +} + +extension InstanceMaker where Argument == Void { + func makeInstance(context: Context, resolver: Resolver) throws -> MadeType { + try makeInstance(arg: (), context: context, resolver: resolver) + } +} + +extension InstanceMaker where Context == Any { + func makeInstance(arg: Argument, resolver: Resolver) throws -> MadeType { + try makeInstance(arg: arg, context: (), resolver: resolver) + } +} + +public extension AnyInstanceMaker where Self: InstanceMaker { + func makeInstance(arg: Any, context: Any, resolver: Resolver) throws -> Any { + guard let arg = arg as? Argument, let context = context as? Context else { throw SwinjectError() } + return try makeInstance(arg: arg, context: context, resolver: resolver) as MadeType + } +} diff --git a/Sources/Resolver.swift b/Sources/Resolver.swift index 05e2ae22..cbb70d74 100644 --- a/Sources/Resolver.swift +++ b/Sources/Resolver.swift @@ -3,7 +3,7 @@ // public protocol Resolver { - func resolve(_ request: BindingRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor + func resolve(_ request: MakerRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor } public extension Resolver { diff --git a/Sources/SimpleBinding.swift b/Sources/SimpleBinding.swift deleted file mode 100644 index b9f02aec..00000000 --- a/Sources/SimpleBinding.swift +++ /dev/null @@ -1,19 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -// TODO: More descriptive name -// TODO: Can we make it internal? -public struct SimpleBinding: Binding { - public typealias BoundType = Type - - private let builder: (Resolver, Context, Argument) throws -> Type - - init(_ builder: @escaping (Resolver, Context, Argument) throws -> Type) { - self.builder = builder - } - - public func instance(arg: Argument, context: Context, resolver: Resolver) throws -> Type { - try builder(resolver, context, arg) - } -} diff --git a/Sources/SimpleInstanceMaker.swift b/Sources/SimpleInstanceMaker.swift new file mode 100644 index 00000000..9cfb9827 --- /dev/null +++ b/Sources/SimpleInstanceMaker.swift @@ -0,0 +1,79 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +public struct SimpleInstanceMaker: InstanceMaker { + public typealias MadeType = Type + + private let builder: (Resolver, Context, Argument) throws -> Type + + init(_ builder: @escaping (Resolver, Context, Argument) throws -> Type) { + self.builder = builder + } + + public func makeInstance(arg: Argument, context: Context, resolver: Resolver) throws -> Type { + try builder(resolver, context, arg) + } +} + +public func contexted(_: Context.Type = Context.self) -> SimpleInstanceMaker.Type { + SimpleInstanceMaker.self +} + +extension SimpleInstanceMaker { + public static func provider(_ builder: @escaping (Resolver, Context) throws -> Type) -> SimpleInstanceMaker { + .init { r, c, _ in try builder(r, c) } + } + + public static func factory(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SimpleInstanceMaker { + .init(builder) + } + + public static func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SimpleInstanceMaker { + .init { try builder($0, $1, $2.0, $2.1) } + } + + public static func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SimpleInstanceMaker { + .init { try builder($0, $1, $2.0, $2.1, $2.2) } + } + + public static func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SimpleInstanceMaker { + .init { try builder($0, $1, $2.0, $2.1, $2.2, $2.3) } + } + + public static func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SimpleInstanceMaker { + .init { try builder($0, $1, $2.0, $2.1, $2.2, $2.3, $2.4) } + } +} + +public func instance(_ instance: Type) -> SimpleInstanceMaker { + .init { _, _, _ in instance } +} + +public func provider(_ builder: @escaping () throws -> Type) -> SimpleInstanceMaker { + .init { _, _, _ in try builder() } +} + +public func provider(_ builder: @escaping (Resolver) throws -> Type) -> SimpleInstanceMaker { + .init { r, _, _ in try builder(r) } +} + +public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> SimpleInstanceMaker { + .init { try builder($0, $2) } +} + +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SimpleInstanceMaker { + .init { try builder($0, $2.0, $2.1) } +} + +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SimpleInstanceMaker { + .init { try builder($0, $2.0, $2.1, $2.2) } +} + +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SimpleInstanceMaker { + SimpleInstanceMaker { try builder($0, $2.0, $2.1, $2.2, $2.3) } +} + +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SimpleInstanceMaker { + SimpleInstanceMaker { try builder($0, $2.0, $2.1, $2.2, $2.3, $2.4) } +} diff --git a/Sources/Swinject.swift b/Sources/Swinject.swift index b4e2e07d..164892b5 100644 --- a/Sources/Swinject.swift +++ b/Sources/Swinject.swift @@ -25,17 +25,17 @@ public extension Swinject { } extension Swinject: Resolver { - public func resolve(_ request: BindingRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { - try instance(from: findBinding(for: request.key), context: request.context, arg: request.argument) + public func resolve(_ request: MakerRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { + try instance(from: findMaker(for: request.key), context: request.context, arg: request.argument) } - private func findBinding(for key: AnyBindingKey) throws -> AnyBinding { - let entries = tree.bindingEntries.filter { $0.key.matches(key) } + private func findMaker(for key: AnyMakerKey) throws -> AnyInstanceMaker { + let entries = tree.makerEntries.filter { $0.key.matches(key) } guard entries.count == 1 else { throw SwinjectError() } - return entries[0].binding + return entries[0].maker } - private func instance(from binding: AnyBinding, context: Context, arg: Argument) throws -> Type { - try binding.instance(arg: arg, context: context, resolver: self) as? Type ?? { throw SwinjectError() }() + private func instance(from maker: AnyInstanceMaker, context: Context, arg: Argument) throws -> Type { + try maker.makeInstance(arg: arg, context: context, resolver: self) as? Type ?? { throw SwinjectError() }() } } diff --git a/Sources/SwinjectTree.swift b/Sources/SwinjectTree.swift index 8f5eb493..f2fb6850 100644 --- a/Sources/SwinjectTree.swift +++ b/Sources/SwinjectTree.swift @@ -5,7 +5,7 @@ public protocol SwinjectEntry {} public struct SwinjectTree { - let bindingEntries: [AnyBindingEntry] + let makerEntries: [AnyMakerEntry] let includeEntries: [ModuleIncludeEntry] } @@ -33,7 +33,7 @@ public enum SwinjectTreeBuilder { public static func buildFunction(_ input: [SwinjectEntry]) -> SwinjectTree { let entries = input.flatMap(unpack) return SwinjectTree( - bindingEntries: entries.compactMap { $0 as? AnyBindingEntry }, + makerEntries: entries.compactMap { $0 as? AnyMakerEntry }, includeEntries: entries.compactMap { $0 as? ModuleIncludeEntry } ) // TODO: Validate diff --git a/Sources/TypeBinder.swift b/Sources/TypeBinder.swift index 13665ec9..f566e22a 100644 --- a/Sources/TypeBinder.swift +++ b/Sources/TypeBinder.swift @@ -19,19 +19,19 @@ public func bind(_ descriptor: Descriptor) -> TypeBinder } public extension TypeBinder { - func with(_ binding: SomeBinding) -> BindingEntry where SomeBinding: Binding, SomeBinding.BoundType == Descriptor.BaseType { - BindingEntry(key: BindingKey(descriptor: descriptor), binding: binding) + func with(_ maker: SomeMaker) -> MakerEntry where SomeMaker: InstanceMaker, SomeMaker.MadeType == Descriptor.BaseType { + MakerEntry(key: MakerKey(descriptor: descriptor), maker: maker) } - func with(_ anInstance: Descriptor.BaseType) -> BindingEntry { + func with(_ anInstance: Descriptor.BaseType) -> MakerEntry { with(instance(anInstance)) } } -public func & (lhs: TypeBinder, rhs: SomeBinding) -> BindingEntry where SomeBinding: Binding, SomeBinding.BoundType == Descriptor.BaseType { +public func & (lhs: TypeBinder, rhs: SomeMaker) -> MakerEntry where SomeMaker: InstanceMaker, SomeMaker.MadeType == Descriptor.BaseType { lhs.with(rhs) } -public func & (lhs: TypeBinder, rhs: Descriptor.BaseType) -> BindingEntry { +public func & (lhs: TypeBinder, rhs: Descriptor.BaseType) -> MakerEntry { lhs.with(rhs) } diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 342c86f5..80d60e42 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -15,9 +15,8 @@ CD6DE53522DD1C7300532D08 /* BindingKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53322DD1C6800532D08 /* BindingKeySpec.swift */; }; CD6DE53722DD1CE900532D08 /* BindingKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53622DD1CE900532D08 /* BindingKey.swift */; }; CD6DE53922DD1D0A00532D08 /* BindingRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53822DD1D0A00532D08 /* BindingRequest.swift */; }; - CD6DE53D22DD30A100532D08 /* BindingBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53C22DD30A100532D08 /* BindingBuilderSpec.swift */; }; - CD6DE54122DE657500532D08 /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE54022DE657400532D08 /* SimpleBinding.swift */; }; - CD6DE54322DE65B500532D08 /* BindingBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE54222DE65B500532D08 /* BindingBuilder.swift */; }; + CD6DE53D22DD30A100532D08 /* SimpleInstanceMakerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53C22DD30A100532D08 /* SimpleInstanceMakerSpec.swift */; }; + CD6DE54322DE65B500532D08 /* SimpleInstanceMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE54222DE65B500532D08 /* SimpleInstanceMaker.swift */; }; CD6DE54522DED11600532D08 /* ContextedResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE54422DED11600532D08 /* ContextedResolver.swift */; }; CD6DE54722DED16400532D08 /* ContextedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE54622DED16400532D08 /* ContextedResolverSpec.swift */; }; CD85AF1222DA5A8F00A8B7CA /* NonGeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF1122DA5A8F00A8B7CA /* NonGeneratedMocks.swift */; }; @@ -29,7 +28,7 @@ CDD8380522DA307F003E9909 /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380422DA307F003E9909 /* TypeBinder.swift */; }; CDD8380722DA30C6003E9909 /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380622DA30C6003E9909 /* TypeDescriptor.swift */; }; CDD8380A22DA31D9003E9909 /* TypeBinderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380822DA31C6003E9909 /* TypeBinderSpec.swift */; }; - CDD8380C22DA3AD8003E9909 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380B22DA3AD8003E9909 /* Binding.swift */; }; + CDD8380C22DA3AD8003E9909 /* InstanceMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380B22DA3AD8003E9909 /* InstanceMaker.swift */; }; CDD8380E22DA3B0D003E9909 /* BindingEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380D22DA3B0D003E9909 /* BindingEntry.swift */; }; CDD8381022DA429F003E9909 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380F22DA429F003E9909 /* Resolver.swift */; }; CDD8381622DA4B55003E9909 /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381522DA4B55003E9909 /* Swinject.swift */; }; @@ -60,9 +59,8 @@ CD6DE53322DD1C6800532D08 /* BindingKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingKeySpec.swift; sourceTree = ""; }; CD6DE53622DD1CE900532D08 /* BindingKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingKey.swift; sourceTree = ""; }; CD6DE53822DD1D0A00532D08 /* BindingRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingRequest.swift; sourceTree = ""; }; - CD6DE53C22DD30A100532D08 /* BindingBuilderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingBuilderSpec.swift; sourceTree = ""; }; - CD6DE54022DE657400532D08 /* SimpleBinding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SimpleBinding.swift; sourceTree = ""; }; - CD6DE54222DE65B500532D08 /* BindingBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingBuilder.swift; sourceTree = ""; }; + CD6DE53C22DD30A100532D08 /* SimpleInstanceMakerSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleInstanceMakerSpec.swift; sourceTree = ""; }; + CD6DE54222DE65B500532D08 /* SimpleInstanceMaker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleInstanceMaker.swift; sourceTree = ""; }; CD6DE54422DED11600532D08 /* ContextedResolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextedResolver.swift; sourceTree = ""; }; CD6DE54622DED16400532D08 /* ContextedResolverSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextedResolverSpec.swift; sourceTree = ""; }; CD6DE54822DED4A100532D08 /* .swiftformat */ = {isa = PBXFileReference; lastKnownFileType = text; path = .swiftformat; sourceTree = ""; }; @@ -77,7 +75,7 @@ CDD8380422DA307F003E9909 /* TypeBinder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinder.swift; sourceTree = ""; }; CDD8380622DA30C6003E9909 /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; CDD8380822DA31C6003E9909 /* TypeBinderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinderSpec.swift; sourceTree = ""; }; - CDD8380B22DA3AD8003E9909 /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; + CDD8380B22DA3AD8003E9909 /* InstanceMaker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceMaker.swift; sourceTree = ""; }; CDD8380D22DA3B0D003E9909 /* BindingEntry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingEntry.swift; sourceTree = ""; }; CDD8380F22DA429F003E9909 /* Resolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Resolver.swift; sourceTree = ""; }; CDD8381522DA4B55003E9909 /* Swinject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Swinject.swift; sourceTree = ""; }; @@ -137,9 +135,8 @@ CDADF32022DB38C600C5D8DB /* SwinjectTree.swift */, CDD8380422DA307F003E9909 /* TypeBinder.swift */, CDD8380622DA30C6003E9909 /* TypeDescriptor.swift */, - CDD8380B22DA3AD8003E9909 /* Binding.swift */, - CD6DE54022DE657400532D08 /* SimpleBinding.swift */, - CD6DE54222DE65B500532D08 /* BindingBuilder.swift */, + CDD8380B22DA3AD8003E9909 /* InstanceMaker.swift */, + CD6DE54222DE65B500532D08 /* SimpleInstanceMaker.swift */, CDD8380F22DA429F003E9909 /* Resolver.swift */, CD6DE54422DED11600532D08 /* ContextedResolver.swift */, CDD8380D22DA3B0D003E9909 /* BindingEntry.swift */, @@ -188,7 +185,7 @@ children = ( CDD8380222DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift */, CDD8380822DA31C6003E9909 /* TypeBinderSpec.swift */, - CD6DE53C22DD30A100532D08 /* BindingBuilderSpec.swift */, + CD6DE53C22DD30A100532D08 /* SimpleInstanceMakerSpec.swift */, CDD8381922DA4C9F003E9909 /* SwinjectSpec.swift */, CD6DE53322DD1C6800532D08 /* BindingKeySpec.swift */, CD6DE54622DED16400532D08 /* ContextedResolverSpec.swift */, @@ -374,14 +371,13 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - CDD8380C22DA3AD8003E9909 /* Binding.swift in Sources */, - CD6DE54322DE65B500532D08 /* BindingBuilder.swift in Sources */, + CDD8380C22DA3AD8003E9909 /* InstanceMaker.swift in Sources */, + CD6DE54322DE65B500532D08 /* SimpleInstanceMaker.swift in Sources */, CDADF33522DB521400C5D8DB /* SwinjectModule.swift in Sources */, CDD8381022DA429F003E9909 /* Resolver.swift in Sources */, CD6DE53722DD1CE900532D08 /* BindingKey.swift in Sources */, CD6DE53922DD1D0A00532D08 /* BindingRequest.swift in Sources */, CDADF32122DB38C600C5D8DB /* SwinjectTree.swift in Sources */, - CD6DE54122DE657500532D08 /* SimpleBinding.swift in Sources */, CDD8381D22DA4E02003E9909 /* SwinjectError.swift in Sources */, CDD8380722DA30C6003E9909 /* TypeDescriptor.swift in Sources */, CD6DE54522DED11600532D08 /* ContextedResolver.swift in Sources */, @@ -401,7 +397,7 @@ CDADF34022DB883A00C5D8DB /* GeneratedMocks.swift in Sources */, CDD8380A22DA31D9003E9909 /* TypeBinderSpec.swift in Sources */, CD85AF1222DA5A8F00A8B7CA /* NonGeneratedMocks.swift in Sources */, - CD6DE53D22DD30A100532D08 /* BindingBuilderSpec.swift in Sources */, + CD6DE53D22DD30A100532D08 /* SimpleInstanceMakerSpec.swift in Sources */, CDD8380322DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift in Sources */, CD6DE53522DD1C7300532D08 /* BindingKeySpec.swift in Sources */, CDADF33722DB753800C5D8DB /* TestModels.swift in Sources */, diff --git a/Tests/ApiSpecs/InjectionApiSpec.swift b/Tests/ApiSpecs/InjectionApiSpec.swift index 7bfe3664..ea748efa 100644 --- a/Tests/ApiSpecs/InjectionApiSpec.swift +++ b/Tests/ApiSpecs/InjectionApiSpec.swift @@ -76,7 +76,7 @@ class InjectionApiSpec: QuickSpec { override func spec() { let factory = swinject.factory() as (Int) throws -> Int expect { try factory(5) } == 42 } - it("can inject factory binding as provider or instance") { + it("can inject factory maker as provider or instance") { let swinject = Swinject { bbind(Double.self) & 17.0 bbind(Int.self) & factory { Int(try $0.instance() as Double) + 5 * $1 } @@ -94,7 +94,7 @@ class InjectionApiSpec: QuickSpec { override func spec() { expect { try swinject.factory(of: Int.self, arg: 11)(14.0, "17") } == 42 expect { try swinject.factory(of: Int.self, args: 11, 14.0)("17") } == 42 } - it("can pass context to the bindings") { + it("can pass context to the makers") { // FIXME: compiler segfaults if declaring these providers inside function builder let intProvider = contexted(String.self).provider { _, string in Int(string)! } let doubleProvider = contexted(String.self).provider { _, string in Double(string)! } @@ -107,7 +107,7 @@ class InjectionApiSpec: QuickSpec { override func spec() { expect { try contexted.instance(of: Double.self) } == 42 expect { try swinject.instance(of: Int.self) }.to(throwError()) } - it("can use binding without context in any context") { + it("can use maker without context in any context") { let swinject = Swinject { bbind(Int.self) & 42 } diff --git a/Tests/Support/GeneratedMocks.swift b/Tests/Support/GeneratedMocks.swift index 317988f0..c3ced83f 100644 --- a/Tests/Support/GeneratedMocks.swift +++ b/Tests/Support/GeneratedMocks.swift @@ -7,47 +7,47 @@ @testable import Swinject -class AnyBindingMock: AnyBinding { - // MARK: - instance +class AnyInstanceMakerMock: AnyInstanceMaker { + // MARK: - makeInstance - var instanceArgContextResolverThrowableError: Error? - var instanceArgContextResolverCallsCount = 0 - var instanceArgContextResolverCalled: Bool { - return instanceArgContextResolverCallsCount > 0 + var makeInstanceArgContextResolverThrowableError: Error? + var makeInstanceArgContextResolverCallsCount = 0 + var makeInstanceArgContextResolverCalled: Bool { + return makeInstanceArgContextResolverCallsCount > 0 } - var instanceArgContextResolverReceivedArguments: (arg: Any, context: Any, resolver: Resolver)? - var instanceArgContextResolverReceivedInvocations: [(arg: Any, context: Any, resolver: Resolver)] = [] - var instanceArgContextResolverReturnValue: Any! - var instanceArgContextResolverClosure: ((Any, Any, Resolver) throws -> Any)? + var makeInstanceArgContextResolverReceivedArguments: (arg: Any, context: Any, resolver: Resolver)? + var makeInstanceArgContextResolverReceivedInvocations: [(arg: Any, context: Any, resolver: Resolver)] = [] + var makeInstanceArgContextResolverReturnValue: Any! + var makeInstanceArgContextResolverClosure: ((Any, Any, Resolver) throws -> Any)? - func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any { - if let error = instanceArgContextResolverThrowableError { + func makeInstance(arg: Any, context: Any, resolver: Resolver) throws -> Any { + if let error = makeInstanceArgContextResolverThrowableError { throw error } - instanceArgContextResolverCallsCount += 1 - instanceArgContextResolverReceivedArguments = (arg: arg, context: context, resolver: resolver) - instanceArgContextResolverReceivedInvocations.append((arg: arg, context: context, resolver: resolver)) - return try instanceArgContextResolverClosure.map { try $0(arg, context, resolver) } ?? instanceArgContextResolverReturnValue + makeInstanceArgContextResolverCallsCount += 1 + makeInstanceArgContextResolverReceivedArguments = (arg: arg, context: context, resolver: resolver) + makeInstanceArgContextResolverReceivedInvocations.append((arg: arg, context: context, resolver: resolver)) + return try makeInstanceArgContextResolverClosure.map { try $0(arg, context, resolver) } ?? makeInstanceArgContextResolverReturnValue } } -class AnyBindingEntryMock: AnyBindingEntry { - var key: AnyBindingKey { +class AnyMakerEntryMock: AnyMakerEntry { + var key: AnyMakerKey { get { return underlyingKey } set(value) { underlyingKey = value } } - var underlyingKey: AnyBindingKey! - var binding: AnyBinding { - get { return underlyingBinding } - set(value) { underlyingBinding = value } + var underlyingKey: AnyMakerKey! + var maker: AnyInstanceMaker { + get { return underlyingMaker } + set(value) { underlyingMaker = value } } - var underlyingBinding: AnyBinding! + var underlyingMaker: AnyInstanceMaker! } -class AnyBindingKeyMock: AnyBindingKey { +class AnyMakerKeyMock: AnyMakerKey { var contextType: Any.Type { get { return underlyingContextType } set(value) { underlyingContextType = value } @@ -74,12 +74,12 @@ class AnyBindingKeyMock: AnyBindingKey { return matchesCallsCount > 0 } - var matchesReceivedOther: AnyBindingKey? - var matchesReceivedInvocations: [AnyBindingKey] = [] + var matchesReceivedOther: AnyMakerKey? + var matchesReceivedInvocations: [AnyMakerKey] = [] var matchesReturnValue: Bool! - var matchesClosure: ((AnyBindingKey) -> Bool)? + var matchesClosure: ((AnyMakerKey) -> Bool)? - func matches(_ other: AnyBindingKey) -> Bool { + func matches(_ other: AnyMakerKey) -> Bool { matchesCallsCount += 1 matchesReceivedOther = other matchesReceivedInvocations.append(other) diff --git a/Tests/Support/NonGeneratedMocks.swift b/Tests/Support/NonGeneratedMocks.swift index 3621d424..cc36c67b 100644 --- a/Tests/Support/NonGeneratedMocks.swift +++ b/Tests/Support/NonGeneratedMocks.swift @@ -5,7 +5,7 @@ @testable import Swinject class DummyResolver: Resolver { - func resolve(_: BindingRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { + func resolve(_: MakerRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { fatalError() } } @@ -14,12 +14,12 @@ extension AnyTypeDescriptorMock: TypeDescriptor { typealias BaseType = Any } -extension AnyBindingMock: Binding { +extension AnyInstanceMakerMock: InstanceMaker { typealias Argument = Any } -class DummyBinding: Binding { - func instance(arg _: Argument, context: Context, resolver _: Resolver) throws -> Any { +class DummyMaker: InstanceMaker { + func makeInstance(arg _: Argument, context: Context, resolver _: Resolver) throws -> Any { fatalError() } } @@ -30,7 +30,7 @@ protocol AnyResolver { } extension AnyResolverMock: Resolver { - func resolve(_ request: BindingRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { + func resolve(_ request: MakerRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { try resolve(request as Any) as! Descriptor.BaseType } } diff --git a/Tests/UnitSpecs/BindingBuilderSpec.swift b/Tests/UnitSpecs/BindingBuilderSpec.swift deleted file mode 100644 index a38b3bc5..00000000 --- a/Tests/UnitSpecs/BindingBuilderSpec.swift +++ /dev/null @@ -1,213 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -import Nimble -import Quick -@testable import Swinject - -class BindingBuilderSpec: QuickSpec { override func spec() { - describe("instance") { - it("produces binding with correct type signature") { - let binding = instance(42) as Any - expect(binding is SimpleBinding).to(beTrue()) - } - it("returns given instance") { - let binding = instance(42) - expect { try binding.instance(resolver: DummyResolver()) } == 42 - } - } - describe("provider") { - // TODO: Can we reuse tests for with / without context? - describe("without context") { - it("produces binding with correct type signature") { - let binding = provider { 42 } as Any - expect(binding is SimpleBinding).to(beTrue()) - } - it("returns instance made by provider method") { - let binding = provider { 42 } - expect { try binding.instance(resolver: DummyResolver()) } == 42 - } - it("does not call builder until instance is requested") { - var called = false - _ = provider { called = true } - expect(called).to(beFalse()) - } - it("calls builder with given provider") { - var passedResolver: Resolver? - let resolver = DummyResolver() - let binding = provider { passedResolver = $0 } - _ = try? binding.instance(resolver: resolver) - expect(passedResolver) === resolver - } - it("rethrows error from builder") { - let binding = provider { throw SwinjectError() } - expect { try binding.instance(resolver: DummyResolver()) }.to(throwError()) - } - it("does not reuse instance") { - let binding = provider { Person() } - let instance1 = try? binding.instance(resolver: DummyResolver()) - let instance2 = try? binding.instance(resolver: DummyResolver()) - expect(instance1) !== instance2 - } - } - describe("contexted") { - it("returns instance made by provider method") { - let binding = contexted(Any.self).provider { _, _ in 42 } - expect { try binding.instance(resolver: DummyResolver()) } == 42 - } - it("does not call builder until instance is requested") { - var called = false - _ = provider { called = true } - expect(called).to(beFalse()) - } - it("calls builder with given provider") { - var passedResolver: Resolver? - let resolver = DummyResolver() - let binding = contexted(Any.self).provider { r, _ in passedResolver = r } - _ = try? binding.instance(resolver: resolver) - expect(passedResolver) === resolver - } - it("calls builder with given context") { - var passedContext: Int? - let binding = contexted(Int.self).provider { _, c in passedContext = c } - _ = try? binding.instance(context: 42, resolver: DummyResolver()) - expect(passedContext) == 42 - } - it("rethrows error from builder") { - let binding = contexted(Any.self).provider { _, _ in throw SwinjectError() } - expect { try binding.instance(resolver: DummyResolver()) }.to(throwError()) - } - it("does not reuse instance") { - let binding = contexted(Any.self).provider { _, _ in Person() } - let instance1 = try? binding.instance(resolver: DummyResolver()) - let instance2 = try? binding.instance(resolver: DummyResolver()) - expect(instance1) !== instance2 - } - } - } - describe("factory") { - describe("without context") { - it("produces binding with correct type signature") { - let binding = factory { (_, _: Void) in 42 } as Any - expect(binding is SimpleBinding).to(beTrue()) - } - it("returns instance made by builder method") { - let binding = factory { (_, _: Void) in 42 } - expect { try binding.instance(resolver: DummyResolver()) } == 42 - } - it("does not call builder until instance is requested") { - var called = false - _ = factory { (_, _: Void) in called = true } - expect(called).to(beFalse()) - } - it("calls builder with given provider") { - var passedResolver: Resolver? - let resolver = DummyResolver() - let binding = factory { (r, _: Void) in passedResolver = r } - _ = try? binding.instance(resolver: resolver) - expect(passedResolver) === resolver - } - it("calls builder with given argument") { - var passedArgument: Int? - let binding = factory { (_, arg: Int) in passedArgument = arg } - _ = try? binding.instance(arg: 42, resolver: DummyResolver()) - expect(passedArgument) == 42 - } - it("rethrows error from builder") { - let binding = factory { (_, _: Void) in throw SwinjectError() } - expect { try binding.instance(resolver: DummyResolver()) }.to(throwError()) - } - it("does not reuse instance") { - let binding = factory { (_, _: Void) in Person() } - let instance1 = try? binding.instance(resolver: DummyResolver()) - let instance2 = try? binding.instance(resolver: DummyResolver()) - expect(instance1) !== instance2 - } - describe("multiple arguments") { - it("works with 2 arguments") { - let binding = factory { (_, _: Int, _: Double) in 42 } - let arguments = (1, 1.0) - expect { try binding.instance(arg: arguments, resolver: DummyResolver()) } == 42 - } - it("works with 3 arguments") { - let binding = factory { (_, _: Int, _: Double, _: String) in 42 } - let arguments = (1, 1.0, "") - expect { try binding.instance(arg: arguments, resolver: DummyResolver()) } == 42 - } - it("works with 4 arguments") { - let binding = factory { (_, _: Int, _: Double, _: String, _: Float) in 42 } - let arguments = (1, 1.0, "", Float(1.0)) - expect { try binding.instance(arg: arguments, resolver: DummyResolver()) } == 42 - } - it("works with 5 arguments") { - let binding = factory { (_, _: Int, _: Double, _: String, _: Float, _: Int) in 42 } - let arguments = (1, 1.0, "", Float(1.0), 5) - expect { try binding.instance(arg: arguments, resolver: DummyResolver()) } == 42 - } - } - } - describe("contexted") { - it("returns instance made by builder method") { - let binding = contexted(Any.self).factory { (_, _, _: Void) in 42 } - expect { try binding.instance(resolver: DummyResolver()) } == 42 - } - it("does not call builder until instance is requested") { - var called = false - _ = contexted(Any.self).factory { (_, _, _: Void) in called = true } - expect(called).to(beFalse()) - } - it("calls builder with given provider") { - var passedResolver: Resolver? - let resolver = DummyResolver() - let binding = contexted(Any.self).factory { (r, _, _: Void) in passedResolver = r } - _ = try? binding.instance(resolver: resolver) - expect(passedResolver) === resolver - } - it("calls builder with given context") { - var passedContext: Int? - let binding = contexted(Int.self).factory { (_, c, _: Void) in passedContext = c } - _ = try? binding.instance(context: 42, resolver: DummyResolver()) - expect(passedContext) == 42 - } - it("calls builder with given argument") { - var passedArgument: Int? - let binding = contexted(Any.self).factory { (_, _, arg: Int) in passedArgument = arg } - _ = try? binding.instance(arg: 42, resolver: DummyResolver()) - expect(passedArgument) == 42 - } - it("rethrows error from builder") { - let binding = contexted(Any.self).factory { (_, _, _: Void) in throw SwinjectError() } - expect { try binding.instance(resolver: DummyResolver()) }.to(throwError()) - } - it("does not reuse instance") { - let binding = contexted(Any.self).factory { (_, _, _: Void) in Person() } - let instance1 = try? binding.instance(resolver: DummyResolver()) - let instance2 = try? binding.instance(resolver: DummyResolver()) - expect(instance1) !== instance2 - } - describe("multiple arguments") { - it("works with 2 arguments") { - let binding = contexted(Any.self).factory { (_, _, _: Int, _: Double) in 42 } - let arguments = (1, 1.0) - expect { try binding.instance(arg: arguments, resolver: DummyResolver()) } == 42 - } - it("works with 3 arguments") { - let binding = contexted(Any.self).factory { (_, _, _: Int, _: Double, _: String) in 42 } - let arguments = (1, 1.0, "") - expect { try binding.instance(arg: arguments, resolver: DummyResolver()) } == 42 - } - it("works with 4 arguments") { - let binding = contexted(Any.self).factory { (_, _, _: Int, _: Double, _: String, _: Float) in 42 } - let arguments = (1, 1.0, "", Float(1.0)) - expect { try binding.instance(arg: arguments, resolver: DummyResolver()) } == 42 - } - it("works with 5 arguments") { - let binding = contexted(Any.self).factory { (_, _, _: Int, _: Double, _: String, _: Float, _: Int) in 42 } - let arguments = (1, 1.0, "", Float(1.0), 5) - expect { try binding.instance(arg: arguments, resolver: DummyResolver()) } == 42 - } - } - } - } -} } diff --git a/Tests/UnitSpecs/BindingKeySpec.swift b/Tests/UnitSpecs/BindingKeySpec.swift index dd0729a0..ee765e96 100644 --- a/Tests/UnitSpecs/BindingKeySpec.swift +++ b/Tests/UnitSpecs/BindingKeySpec.swift @@ -6,20 +6,20 @@ import Nimble import Quick @testable import Swinject -class BindingKeySpec: QuickSpec { override func spec() { - typealias AnyBindingKey = BindingKey - typealias ArgumentBindingKey = BindingKey - typealias ContextBindingKey = BindingKey +class MakerKeySpec: QuickSpec { override func spec() { + typealias AnyMakerKey = MakerKey + typealias ArgumentMakerKey = MakerKey + typealias ContextMakerKey = MakerKey describe("matching") { - var key: AnyBindingKey! + var key: AnyMakerKey! var descriptor = AnyTypeDescriptorMock() - var otherKey = AnyBindingKeyMock() + var otherKey = AnyMakerKeyMock() beforeEach { descriptor = AnyTypeDescriptorMock() descriptor.matchesReturnValue = true - key = AnyBindingKey(descriptor: descriptor) - otherKey = AnyBindingKeyMock() + key = AnyMakerKey(descriptor: descriptor) + otherKey = AnyMakerKeyMock() otherKey.descriptor = AnyTypeDescriptorMock() otherKey.argumentType = Void.self otherKey.contextType = Void.self @@ -30,7 +30,7 @@ class BindingKeySpec: QuickSpec { override func spec() { } it("it checks if descriptors match") { let otherDescriptor = AnyTypeDescriptorMock() - _ = key.matches(AnyBindingKey(descriptor: otherDescriptor)) + _ = key.matches(AnyMakerKey(descriptor: otherDescriptor)) expect(descriptor.matchesReceivedOther) === otherDescriptor } it("matches if descriptors match") { @@ -38,27 +38,27 @@ class BindingKeySpec: QuickSpec { override func spec() { expect { key.matches(otherKey) }.to(beTrue()) } it("does not match if argument types are different") { - let key = ArgumentBindingKey(descriptor: descriptor) + let key = ArgumentMakerKey(descriptor: descriptor) otherKey.argumentType = Double.self expect(key.matches(otherKey)).to(beFalse()) } it("matches if argument types are the same") { - let key = ArgumentBindingKey(descriptor: descriptor) + let key = ArgumentMakerKey(descriptor: descriptor) otherKey.argumentType = Int.self expect(key.matches(otherKey)).to(beTrue()) } it("does not match if context types are different") { - let key = ContextBindingKey(descriptor: descriptor) + let key = ContextMakerKey(descriptor: descriptor) otherKey.contextType = Double.self expect(key.matches(otherKey)).to(beFalse()) } it("matches if argument context are the same") { - let key = ContextBindingKey(descriptor: descriptor) + let key = ContextMakerKey(descriptor: descriptor) otherKey.contextType = Int.self expect(key.matches(otherKey)).to(beTrue()) } it("matches if context is Any") { - let key = ContextBindingKey(descriptor: descriptor) + let key = ContextMakerKey(descriptor: descriptor) otherKey.contextType = Int.self expect(key.matches(otherKey)).to(beTrue()) } diff --git a/Tests/UnitSpecs/ContextedResolverSpec.swift b/Tests/UnitSpecs/ContextedResolverSpec.swift index 69854077..505e36ce 100644 --- a/Tests/UnitSpecs/ContextedResolverSpec.swift +++ b/Tests/UnitSpecs/ContextedResolverSpec.swift @@ -22,20 +22,20 @@ class ContextedResolverSpec: QuickSpec { override func spec() { } it("calls wrapped resolver with given type descriptor") { let descriptor = AnyTypeDescriptorMock() - let request = BindingRequest(key: BindingKey(descriptor: descriptor), context: (), argument: ()) + let request = MakerRequest(key: MakerKey(descriptor: descriptor), context: (), argument: ()) _ = try? resolver.resolve(request) - let receivedRequest = wrapped.resolveReceivedRequest as? BindingRequest + let receivedRequest = wrapped.resolveReceivedRequest as? MakerRequest expect(receivedRequest?.key.descriptor) === descriptor } it("calls wrapped resolver with given argument") { _ = try? resolver.resolve(request(type: Int.self, tag: NoTag(), arg: "argument")) - let receivedRequest = wrapped.resolveReceivedRequest as? BindingRequest, Void, String> + let receivedRequest = wrapped.resolveReceivedRequest as? MakerRequest, Void, String> expect(receivedRequest?.argument) == "argument" } it("calls wrapped resolver with it's context") { let resolver = ContextedResolver(context: "context", resolver: wrapped) _ = try? resolver.resolve(request(type: Int.self, tag: NoTag(), arg: ())) - let receivedRequest = wrapped.resolveReceivedRequest as? BindingRequest, String, Void> + let receivedRequest = wrapped.resolveReceivedRequest as? MakerRequest, String, Void> expect(receivedRequest?.context) == "context" } } diff --git a/Tests/UnitSpecs/SimpleInstanceMakerSpec.swift b/Tests/UnitSpecs/SimpleInstanceMakerSpec.swift new file mode 100644 index 00000000..70801cf9 --- /dev/null +++ b/Tests/UnitSpecs/SimpleInstanceMakerSpec.swift @@ -0,0 +1,213 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +import Nimble +import Quick +@testable import Swinject + +class SimpleInstanceMakerSpec: QuickSpec { override func spec() { + describe("instance") { + it("produces maker with correct type signature") { + let maker = instance(42) as Any + expect(maker is SimpleInstanceMaker).to(beTrue()) + } + it("returns given instance") { + let maker = instance(42) + expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 + } + } + describe("provider") { + // TODO: Can we reuse tests for with / without context? + describe("without context") { + it("produces maker with correct type signature") { + let maker = provider { 42 } as Any + expect(maker is SimpleInstanceMaker).to(beTrue()) + } + it("returns instance made by provider method") { + let maker = provider { 42 } + expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 + } + it("does not call builder until instance is requested") { + var called = false + _ = provider { called = true } + expect(called).to(beFalse()) + } + it("calls builder with given provider") { + var passedResolver: Resolver? + let resolver = DummyResolver() + let maker = provider { passedResolver = $0 } + _ = try? maker.makeInstance(resolver: resolver) + expect(passedResolver) === resolver + } + it("rethrows error from builder") { + let maker = provider { throw SwinjectError() } + expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) + } + it("does not reuse instance") { + let maker = provider { Person() } + let instance1 = try? maker.makeInstance(resolver: DummyResolver()) + let instance2 = try? maker.makeInstance(resolver: DummyResolver()) + expect(instance1) !== instance2 + } + } + describe("contexted") { + it("returns instance made by provider method") { + let maker = contexted(Any.self).provider { _, _ in 42 } + expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 + } + it("does not call builder until instance is requested") { + var called = false + _ = provider { called = true } + expect(called).to(beFalse()) + } + it("calls builder with given provider") { + var passedResolver: Resolver? + let resolver = DummyResolver() + let maker = contexted(Any.self).provider { r, _ in passedResolver = r } + _ = try? maker.makeInstance(resolver: resolver) + expect(passedResolver) === resolver + } + it("calls builder with given context") { + var passedContext: Int? + let maker = contexted(Int.self).provider { _, c in passedContext = c } + _ = try? maker.makeInstance(context: 42, resolver: DummyResolver()) + expect(passedContext) == 42 + } + it("rethrows error from builder") { + let maker = contexted(Any.self).provider { _, _ in throw SwinjectError() } + expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) + } + it("does not reuse instance") { + let maker = contexted(Any.self).provider { _, _ in Person() } + let instance1 = try? maker.makeInstance(resolver: DummyResolver()) + let instance2 = try? maker.makeInstance(resolver: DummyResolver()) + expect(instance1) !== instance2 + } + } + } + describe("factory") { + describe("without context") { + it("produces maker with correct type signature") { + let maker = factory { (_, _: Void) in 42 } as Any + expect(maker is SimpleInstanceMaker).to(beTrue()) + } + it("returns instance made by builder method") { + let maker = factory { (_, _: Void) in 42 } + expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 + } + it("does not call builder until instance is requested") { + var called = false + _ = factory { (_, _: Void) in called = true } + expect(called).to(beFalse()) + } + it("calls builder with given provider") { + var passedResolver: Resolver? + let resolver = DummyResolver() + let maker = factory { (r, _: Void) in passedResolver = r } + _ = try? maker.makeInstance(resolver: resolver) + expect(passedResolver) === resolver + } + it("calls builder with given argument") { + var passedArgument: Int? + let maker = factory { (_, arg: Int) in passedArgument = arg } + _ = try? maker.makeInstance(arg: 42, resolver: DummyResolver()) + expect(passedArgument) == 42 + } + it("rethrows error from builder") { + let maker = factory { (_, _: Void) in throw SwinjectError() } + expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) + } + it("does not reuse instance") { + let maker = factory { (_, _: Void) in Person() } + let instance1 = try? maker.makeInstance(resolver: DummyResolver()) + let instance2 = try? maker.makeInstance(resolver: DummyResolver()) + expect(instance1) !== instance2 + } + describe("multiple arguments") { + it("works with 2 arguments") { + let maker = factory { (_, _: Int, _: Double) in 42 } + let arguments = (1, 1.0) + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + } + it("works with 3 arguments") { + let maker = factory { (_, _: Int, _: Double, _: String) in 42 } + let arguments = (1, 1.0, "") + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + } + it("works with 4 arguments") { + let maker = factory { (_, _: Int, _: Double, _: String, _: Float) in 42 } + let arguments = (1, 1.0, "", Float(1.0)) + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + } + it("works with 5 arguments") { + let maker = factory { (_, _: Int, _: Double, _: String, _: Float, _: Int) in 42 } + let arguments = (1, 1.0, "", Float(1.0), 5) + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + } + } + } + describe("contexted") { + it("returns instance made by builder method") { + let maker = contexted(Any.self).factory { (_, _, _: Void) in 42 } + expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 + } + it("does not call builder until instance is requested") { + var called = false + _ = contexted(Any.self).factory { (_, _, _: Void) in called = true } + expect(called).to(beFalse()) + } + it("calls builder with given provider") { + var passedResolver: Resolver? + let resolver = DummyResolver() + let maker = contexted(Any.self).factory { (r, _, _: Void) in passedResolver = r } + _ = try? maker.makeInstance(resolver: resolver) + expect(passedResolver) === resolver + } + it("calls builder with given context") { + var passedContext: Int? + let maker = contexted(Int.self).factory { (_, c, _: Void) in passedContext = c } + _ = try? maker.makeInstance(context: 42, resolver: DummyResolver()) + expect(passedContext) == 42 + } + it("calls builder with given argument") { + var passedArgument: Int? + let maker = contexted(Any.self).factory { (_, _, arg: Int) in passedArgument = arg } + _ = try? maker.makeInstance(arg: 42, resolver: DummyResolver()) + expect(passedArgument) == 42 + } + it("rethrows error from builder") { + let maker = contexted(Any.self).factory { (_, _, _: Void) in throw SwinjectError() } + expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) + } + it("does not reuse instance") { + let maker = contexted(Any.self).factory { (_, _, _: Void) in Person() } + let instance1 = try? maker.makeInstance(resolver: DummyResolver()) + let instance2 = try? maker.makeInstance(resolver: DummyResolver()) + expect(instance1) !== instance2 + } + describe("multiple arguments") { + it("works with 2 arguments") { + let maker = contexted(Any.self).factory { (_, _, _: Int, _: Double) in 42 } + let arguments = (1, 1.0) + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + } + it("works with 3 arguments") { + let maker = contexted(Any.self).factory { (_, _, _: Int, _: Double, _: String) in 42 } + let arguments = (1, 1.0, "") + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + } + it("works with 4 arguments") { + let maker = contexted(Any.self).factory { (_, _, _: Int, _: Double, _: String, _: Float) in 42 } + let arguments = (1, 1.0, "", Float(1.0)) + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + } + it("works with 5 arguments") { + let maker = contexted(Any.self).factory { (_, _, _: Int, _: Double, _: String, _: Float, _: Int) in 42 } + let arguments = (1, 1.0, "", Float(1.0), 5) + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + } + } + } + } +} } diff --git a/Tests/UnitSpecs/SwinjectSpec.swift b/Tests/UnitSpecs/SwinjectSpec.swift index f012c4ef..4998c348 100644 --- a/Tests/UnitSpecs/SwinjectSpec.swift +++ b/Tests/UnitSpecs/SwinjectSpec.swift @@ -8,85 +8,85 @@ import Quick class SwinjectSpec: QuickSpec { override func spec() { describe("instance injection") { - context("no bindings") { + context("no makers") { it("throws") { let swinject = Swinject {} expect { try swinject.instance(of: Int.self) }.to(throwError()) } } - context("single binding") { + context("single maker") { var swinject: Swinject! - var binding = AnyBindingMock() - var key = AnyBindingKeyMock() + var maker = AnyInstanceMakerMock() + var key = AnyMakerKeyMock() beforeEach { - binding = AnyBindingMock() - key = AnyBindingKeyMock() - swinject = Swinject { BindingEntry(key: key, binding: binding) } + maker = AnyInstanceMakerMock() + key = AnyMakerKeyMock() + swinject = Swinject { MakerEntry(key: key, maker: maker) } } - it("request instance from matching binding") { + it("request instance from matching maker") { key.matchesReturnValue = true _ = try? swinject.instance(of: Any.self) - expect(binding.instanceArgContextResolverCallsCount) == 1 + expect(maker.makeInstanceArgContextResolverCallsCount) == 1 } - it("does not request instance from matching binding until instance is required") { + it("does not request instance from matching maker until instance is required") { key.matchesReturnValue = true - expect(binding.instanceArgContextResolverCallsCount) == 0 + expect(maker.makeInstanceArgContextResolverCallsCount) == 0 } - it("only requests instance from matching binding") { + it("only requests instance from matching maker") { key.matchesReturnValue = false _ = try? swinject.instance(of: Any.self) - expect(binding.instanceArgContextResolverCallsCount) == 0 + expect(maker.makeInstanceArgContextResolverCallsCount) == 0 } - it("returns instance produced by binding") { + it("returns instance produced by maker") { key.matchesReturnValue = true - binding.instanceArgContextResolverReturnValue = 42 + maker.makeInstanceArgContextResolverReturnValue = 42 expect { try swinject.instance(of: Any.self) as? Int } == 42 } - it("rethrows error from binding") { + it("rethrows error from maker") { key.matchesReturnValue = true - binding.instanceArgContextResolverThrowableError = TestError() + maker.makeInstanceArgContextResolverThrowableError = TestError() expect { try swinject.instance(of: Any.self) }.to(throwError(errorType: TestError.self)) } it("crashes if bound type does not match requested type") { key.matchesReturnValue = true - binding.instanceArgContextResolverReturnValue = "" + maker.makeInstanceArgContextResolverReturnValue = "" expect { _ = try swinject.instance(of: Double.self) }.to(throwError()) } it("does not crash if bound type conforms to the requested type") { key.matchesReturnValue = true - binding.instanceArgContextResolverReturnValue = 42 + maker.makeInstanceArgContextResolverReturnValue = 42 expect { _ = try swinject.instance(of: CustomStringConvertible?.self) }.notTo(throwError()) } it("passes swinject as resolver") { key.matchesReturnValue = true _ = try? swinject.instance(of: Any.self) - expect(binding.instanceArgContextResolverReceivedArguments?.resolver is Swinject).to(beTrue()) + expect(maker.makeInstanceArgContextResolverReceivedArguments?.resolver is Swinject).to(beTrue()) } - it("matches binding with correct key") { + it("matches maker with correct key") { key.matchesReturnValue = false _ = try? swinject.instance(tagged: "tag") as Int - let otherKey = key.matchesReceivedOther as? BindingKey, Void, Void> + let otherKey = key.matchesReceivedOther as? MakerKey, Void, Void> let descriptor = otherKey?.descriptor as? Tagged expect(descriptor?.tag) == "tag" } - it("matches binding with correct context") { + it("matches maker with correct context") { key.matchesReturnValue = false _ = try? swinject.on("context").instance() as Int expect(key.matchesReceivedOther?.contextType is String.Type).to(beTrue()) } } - context("multiple bindings") { + context("multiple makers") { var swinject: Swinject! - var bindings = [AnyBindingMock]() - var keys = [AnyBindingKeyMock]() + var makers = [AnyInstanceMakerMock]() + var keys = [AnyMakerKeyMock]() beforeEach { - keys = Array(0 ..< 3).map { _ in AnyBindingKeyMock() } + keys = Array(0 ..< 3).map { _ in AnyMakerKeyMock() } keys.forEach { $0.matchesReturnValue = false } - bindings = keys.map { _ in AnyBindingMock() } + makers = keys.map { _ in AnyInstanceMakerMock() } swinject = Swinject { - BindingEntry(key: keys[0], binding: bindings[0]) - BindingEntry(key: keys[1], binding: bindings[1]) - BindingEntry(key: keys[2], binding: bindings[2]) + MakerEntry(key: keys[0], maker: makers[0]) + MakerEntry(key: keys[1], maker: makers[1]) + MakerEntry(key: keys[2], maker: makers[2]) } } it("throws if multiple entries match requested type") { @@ -97,59 +97,59 @@ class SwinjectSpec: QuickSpec { override func spec() { keys[1].matchesReturnValue = true expect { try swinject.instance(of: Any.self) }.notTo(throwError()) } - it("returns instance from matching binding") { + it("returns instance from matching maker") { keys[1].matchesReturnValue = true - bindings[1].instanceArgContextResolverReturnValue = 42 + makers[1].makeInstanceArgContextResolverReturnValue = 42 expect { try swinject.instance(of: Int.self) } == 42 } } } describe("provider injection") { var swinject: Swinject! - var binding = AnyBindingMock() - var key = AnyBindingKeyMock() + var maker = AnyInstanceMakerMock() + var key = AnyMakerKeyMock() beforeEach { - binding = AnyBindingMock() - key = AnyBindingKeyMock() - swinject = Swinject { BindingEntry(key: key, binding: binding) } + maker = AnyInstanceMakerMock() + key = AnyMakerKeyMock() + swinject = Swinject { MakerEntry(key: key, maker: maker) } } - it("does not throw if binding matches provided type") { + it("does not throw if maker matches provided type") { key.matchesReturnValue = true - binding.instanceArgContextResolverReturnValue = 42 + maker.makeInstanceArgContextResolverReturnValue = 42 let provider = swinject.provider() as () throws -> Int expect { try provider() }.notTo(throwError()) } - it("throws if missing binding for provided type") { + it("throws if missing maker for provided type") { key.matchesReturnValue = false let provider = swinject.provider() as () throws -> Int expect { try provider() }.to(throwError()) } it("does not request provided type until provider is called") { key.matchesReturnValue = true - binding.instanceArgContextResolverReturnValue = 42 + maker.makeInstanceArgContextResolverReturnValue = 42 _ = swinject.provider(of: Int.self) - expect(binding.instanceArgContextResolverCallsCount) == 0 + expect(maker.makeInstanceArgContextResolverCallsCount) == 0 } - it("returns instance from binding") { + it("returns instance from maker") { key.matchesReturnValue = true - binding.instanceArgContextResolverReturnValue = 42 + maker.makeInstanceArgContextResolverReturnValue = 42 let provider = swinject.provider(of: Int.self) expect { try provider() } == 42 } - it("rethrows binding error from provider") { + it("rethrows maker error from provider") { key.matchesReturnValue = true - binding.instanceArgContextResolverThrowableError = TestError() + maker.makeInstanceArgContextResolverThrowableError = TestError() let provider = swinject.provider(of: Int.self) expect { try provider() }.to(throwError(errorType: TestError.self)) } - it("matches binding with correct key") { + it("matches maker with correct key") { key.matchesReturnValue = true _ = try? swinject.provider(of: Any.self, tagged: "tag")() - let otherKey = key.matchesReceivedOther as? BindingKey, Void, Void> + let otherKey = key.matchesReceivedOther as? MakerKey, Void, Void> let descriptor = otherKey?.descriptor as? Tagged expect(descriptor?.tag) == "tag" } - it("matches binding with correct context") { + it("matches maker with correct context") { key.matchesReturnValue = false _ = try? swinject.on("context").provider()() as Int expect(key.matchesReceivedOther?.contextType is String.Type).to(beTrue()) @@ -157,61 +157,61 @@ class SwinjectSpec: QuickSpec { override func spec() { it("passes given context to the bidndning") { key.matchesReturnValue = true _ = try? swinject.on("context").provider()() as Int - expect(binding.instanceArgContextResolverReceivedArguments?.context as? String) == "context" + expect(maker.makeInstanceArgContextResolverReceivedArguments?.context as? String) == "context" } } describe("factory injection") { var swinject: Swinject! - var binding = AnyBindingMock() - var key = AnyBindingKeyMock() + var maker = AnyInstanceMakerMock() + var key = AnyMakerKeyMock() beforeEach { - binding = AnyBindingMock() - key = AnyBindingKeyMock() - swinject = Swinject { BindingEntry(key: key, binding: binding) } + maker = AnyInstanceMakerMock() + key = AnyMakerKeyMock() + swinject = Swinject { MakerEntry(key: key, maker: maker) } } - it("throws if missing binding for created type") { + it("throws if missing maker for created type") { key.matchesReturnValue = false let factory = swinject.factory() as (String) throws -> Int expect { try factory("arg") }.to(throwError()) } - it("does not throw if binding matches created type") { + it("does not throw if maker matches created type") { key.matchesReturnValue = true - binding.instanceArgContextResolverReturnValue = 42 + maker.makeInstanceArgContextResolverReturnValue = 42 let factory = swinject.factory() as (String) throws -> Int expect { try factory("arg") }.notTo(throwError()) } it("does not request created type until factory is called") { key.matchesReturnValue = true - binding.instanceArgContextResolverReturnValue = 42 + maker.makeInstanceArgContextResolverReturnValue = 42 _ = swinject.factory() as (String) throws -> Int - expect(binding.instanceArgContextResolverCallsCount) == 0 + expect(maker.makeInstanceArgContextResolverCallsCount) == 0 } - it("rethrows binding error from factory") { + it("rethrows maker error from factory") { key.matchesReturnValue = true - binding.instanceArgContextResolverThrowableError = TestError() + maker.makeInstanceArgContextResolverThrowableError = TestError() let factory = swinject.factory() as (String) throws -> Int expect { try factory("arg") }.to(throwError(errorType: TestError.self)) } - it("returns instance from binding") { + it("returns instance from maker") { key.matchesReturnValue = true - binding.instanceArgContextResolverReturnValue = 42 + maker.makeInstanceArgContextResolverReturnValue = 42 let factory = swinject.factory() as (String) throws -> Int expect { try factory("arg") } == 42 } - it("passes given factory argument to binding") { + it("passes given factory argument to maker") { key.matchesReturnValue = true - binding.instanceArgContextResolverReturnValue = 42 + maker.makeInstanceArgContextResolverReturnValue = 42 _ = try? swinject.factory(of: Int.self)("arg") - expect(binding.instanceArgContextResolverReceivedArguments?.arg as? String) == "arg" + expect(maker.makeInstanceArgContextResolverReceivedArguments?.arg as? String) == "arg" } - it("matches binding with correct key") { + it("matches maker with correct key") { key.matchesReturnValue = false _ = try? swinject.factory(tagged: "tag")("arg") as Int - let otherKey = key.matchesReceivedOther as? BindingKey, Void, String> + let otherKey = key.matchesReceivedOther as? MakerKey, Void, String> let descriptor = otherKey?.descriptor as? Tagged expect(descriptor?.tag) == "tag" } - it("matches binding with correct context") { + it("matches maker with correct context") { key.matchesReturnValue = false _ = try? swinject.on("context").factory()("arg") as Int expect(key.matchesReceivedOther?.contextType is String.Type).to(beTrue()) @@ -219,42 +219,42 @@ class SwinjectSpec: QuickSpec { override func spec() { it("passes given context to the bidndning") { key.matchesReturnValue = true _ = try? swinject.on("context").factory()("arg") as Int - expect(binding.instanceArgContextResolverReceivedArguments?.context as? String) == "context" + expect(maker.makeInstanceArgContextResolverReceivedArguments?.context as? String) == "context" } context("currying") { beforeEach { key.matchesReturnValue = true - binding.instanceArgContextResolverReturnValue = 42 + maker.makeInstanceArgContextResolverReturnValue = 42 } it("can curry 2-tuple as 0 / 2 argument") { _ = try? swinject.factory()("arg1", "arg2") as Int - let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? (String, String) + let receivedArg = maker.makeInstanceArgContextResolverReceivedArguments?.arg as? (String, String) expect(receivedArg?.0) == "arg1" expect(receivedArg?.1) == "arg2" } it("can curry 2-tuple as 1 / 1 argument") { _ = try? swinject.factory(arg: "arg1")("arg2") as Int - let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? (String, String) + let receivedArg = maker.makeInstanceArgContextResolverReceivedArguments?.arg as? (String, String) expect(receivedArg?.0) == "arg1" expect(receivedArg?.1) == "arg2" } it("can curry 3-tuple as 0 / 3 argument") { _ = try? swinject.factory()("arg1", 2, "arg3") as Int - let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? (String, Int, String) + let receivedArg = maker.makeInstanceArgContextResolverReceivedArguments?.arg as? (String, Int, String) expect(receivedArg?.0) == "arg1" expect(receivedArg?.1) == 2 expect(receivedArg?.2) == "arg3" } it("can curry 3-tuple as 1 / 2 argument") { _ = try? swinject.factory(arg: "arg1")(2, "arg3") as Int - let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? (String, Int, String) + let receivedArg = maker.makeInstanceArgContextResolverReceivedArguments?.arg as? (String, Int, String) expect(receivedArg?.0) == "arg1" expect(receivedArg?.1) == 2 expect(receivedArg?.2) == "arg3" } it("can curry 3-tuple as 2 / 1 argument") { _ = try? swinject.factory(args: "arg1", 2)("arg3") as Int - let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? (String, Int, String) + let receivedArg = maker.makeInstanceArgContextResolverReceivedArguments?.arg as? (String, Int, String) expect(receivedArg?.0) == "arg1" expect(receivedArg?.1) == 2 expect(receivedArg?.2) == "arg3" diff --git a/Tests/UnitSpecs/SwinjectTreeBuilderSpec.swift b/Tests/UnitSpecs/SwinjectTreeBuilderSpec.swift index de5d53fe..22f347ee 100644 --- a/Tests/UnitSpecs/SwinjectTreeBuilderSpec.swift +++ b/Tests/UnitSpecs/SwinjectTreeBuilderSpec.swift @@ -10,47 +10,47 @@ class SwinjectTreeBuilderSpec: QuickSpec { override func spec() { describe("allowed syntax") { it("builds empty closure") { let tree = makeTree {} - expect(tree.bindingEntries).to(beEmpty()) + expect(tree.makerEntries).to(beEmpty()) } it("builds closure with single entry") { - let tree = makeTree { AnyBindingEntryMock() } - expect(tree.bindingEntries.count) == 1 + let tree = makeTree { AnyMakerEntryMock() } + expect(tree.makerEntries.count) == 1 } it("builds closure with multiple entries") { let tree = makeTree { - AnyBindingEntryMock(); AnyBindingEntryMock(); AnyBindingEntryMock(); AnyBindingEntryMock(); AnyBindingEntryMock() + AnyMakerEntryMock(); AnyMakerEntryMock(); AnyMakerEntryMock(); AnyMakerEntryMock(); AnyMakerEntryMock() } - expect(tree.bindingEntries.count) == 5 + expect(tree.makerEntries.count) == 5 } // FIXME: Test coverage enabled build segfaults on this // it("builds closure with if statement") { // let tree = makeTree { -// if true { AnyBindingEntryMock() } +// if true { AnyMakerEntryMock() } // } -// expect(tree.bindingEntries.count) == 1 +// expect(tree.makerEntries.count) == 1 // } // it("builds closure with nested if statement") { // let tree = makeTree { -// if true { AnyBindingEntryMock(); if true { AnyBindingEntryMock() } } +// if true { AnyMakerEntryMock(); if true { AnyMakerEntryMock() } } // } -// expect(tree.bindingEntries.count) == 2 +// expect(tree.makerEntries.count) == 2 // } // it("builds closure with if else statement") { // let tree = makeTree { -// if false {} else { AnyBindingEntryMock(); AnyBindingEntryMock() } +// if false {} else { AnyMakerEntryMock(); AnyMakerEntryMock() } // } -// expect(tree.bindingEntries.count) == 2 +// expect(tree.makerEntries.count) == 2 // } - it("builds closure with binding & include entries") { + it("builds closure with maker & include entries") { let tree = makeTree { ModuleIncludeEntryMock() ModuleIncludeEntryMock() - AnyBindingEntryMock() - AnyBindingEntryMock() - AnyBindingEntryMock() + AnyMakerEntryMock() + AnyMakerEntryMock() + AnyMakerEntryMock() } expect(tree.includeEntries.count) == 2 - expect(tree.bindingEntries.count) == 3 + expect(tree.makerEntries.count) == 3 } } } } diff --git a/Tests/UnitSpecs/TypeBinderSpec.swift b/Tests/UnitSpecs/TypeBinderSpec.swift index eba73a3e..02c0b608 100644 --- a/Tests/UnitSpecs/TypeBinderSpec.swift +++ b/Tests/UnitSpecs/TypeBinderSpec.swift @@ -8,10 +8,10 @@ import Quick class TypeBinderSpec: QuickSpec { override func spec() { var descriptor = AnyTypeDescriptorMock() - var binding = AnyBindingMock() + var maker = AnyInstanceMakerMock() beforeEach { descriptor = AnyTypeDescriptorMock() - binding = AnyBindingMock() + maker = AnyInstanceMakerMock() } describe("bind") { it("descriptor has correct tag for tagged type") { @@ -25,46 +25,46 @@ class TypeBinderSpec: QuickSpec { override func spec() { } describe("`with` method") { it("produces entry with correct descriptor") { - let entry = bbind(descriptor).with(binding) + let entry = bbind(descriptor).with(maker) expect(entry.key.descriptor) === descriptor } it("produces entry with correct argument type") { - let entry = bbind(Any.self).with(DummyBinding()) + let entry = bbind(Any.self).with(DummyMaker()) expect(entry.key.argumentType is Int.Type).to(beTrue()) } it("produces entry with correct context type") { - let entry = bbind(Any.self).with(DummyBinding()) + let entry = bbind(Any.self).with(DummyMaker()) expect(entry.key.contextType is Int.Type).to(beTrue()) } - it("produces entry with correct binding") { - let entry = bbind(Any.self).with(binding) - expect(entry.binding) === binding + it("produces entry with correct maker") { + let entry = bbind(Any.self).with(maker) + expect(entry.maker) === maker } it("produces entry if given value of descriptor type") { let entry = bbind(Int.self).with(42) - expect(entry.binding is SimpleBinding).to(beTrue()) + expect(entry.maker is SimpleInstanceMaker).to(beTrue()) } } describe("& operator") { it("produces entry with correct descriptor") { - let entry = bbind(descriptor) & binding + let entry = bbind(descriptor) & maker expect(entry.key.descriptor) === descriptor } it("produces entry with correct argument type") { - let entry = bbind(Any.self) & DummyBinding() + let entry = bbind(Any.self) & DummyMaker() expect(entry.key.argumentType is Int.Type).to(beTrue()) } it("produces entry with correct context type") { - let entry = bbind(Any.self) & DummyBinding() + let entry = bbind(Any.self) & DummyMaker() expect(entry.key.contextType is Int.Type).to(beTrue()) } - it("produces entry with correct binding") { - let entry = bbind(Any.self) & binding - expect(entry.binding) === binding + it("produces entry with correct maker") { + let entry = bbind(Any.self) & maker + expect(entry.maker) === maker } it("produces entry provider if given value of descriptor type") { let entry = bbind(Int.self) & 42 - expect(entry.binding is SimpleBinding).to(beTrue()) + expect(entry.maker is SimpleInstanceMaker).to(beTrue()) } } } } From 6dc7638e7788e43030bf937cd07c1641244f381a Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Wed, 17 Jul 2019 15:40:10 +0200 Subject: [PATCH 055/239] Rename MakerEntry to Binding --- Sources/Binding.swift | 11 +++ Sources/BindingEntry.swift | 15 ---- Sources/BindingKey.swift | 8 +- Sources/BindingRequest.swift | 4 +- Sources/ContextedResolver.swift | 2 +- Sources/Swinject.swift | 8 +- Sources/SwinjectTree.swift | 4 +- Sources/TypeBinder.swift | 10 +-- Swinject.xcodeproj/project.pbxproj | 8 +- Tests/ApiSpecs/InjectionApiSpec.swift | 2 +- Tests/Support/GeneratedMocks.swift | 77 ++++++++----------- Tests/UnitSpecs/BindingKeySpec.swift | 28 +++---- Tests/UnitSpecs/ContextedResolverSpec.swift | 2 +- Tests/UnitSpecs/SwinjectSpec.swift | 38 ++++----- Tests/UnitSpecs/SwinjectTreeBuilderSpec.swift | 24 +++--- Tests/UnitSpecs/TypeBinderSpec.swift | 60 +++++++-------- 16 files changed, 142 insertions(+), 159 deletions(-) create mode 100644 Sources/Binding.swift delete mode 100644 Sources/BindingEntry.swift diff --git a/Sources/Binding.swift b/Sources/Binding.swift new file mode 100644 index 00000000..bd5cde29 --- /dev/null +++ b/Sources/Binding.swift @@ -0,0 +1,11 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +// sourcery: AutoMockable +public protocol Binding: SwinjectEntry {} + +struct SimpleBinding: Binding { + let key: AnyBindingKey + let maker: AnyInstanceMaker +} diff --git a/Sources/BindingEntry.swift b/Sources/BindingEntry.swift deleted file mode 100644 index 6600b968..00000000 --- a/Sources/BindingEntry.swift +++ /dev/null @@ -1,15 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -// sourcery: AutoMockable -protocol AnyMakerEntry: SwinjectEntry { - var key: AnyMakerKey { get } - var maker: AnyInstanceMaker { get } -} - -// TODO: Make this internal -public struct MakerEntry: AnyMakerEntry { - let key: AnyMakerKey - let maker: AnyInstanceMaker -} diff --git a/Sources/BindingKey.swift b/Sources/BindingKey.swift index a7a61f98..563f7510 100644 --- a/Sources/BindingKey.swift +++ b/Sources/BindingKey.swift @@ -3,20 +3,20 @@ // // sourcery: AutoMockable -protocol AnyMakerKey { +protocol AnyBindingKey { var contextType: Any.Type { get } var argumentType: Any.Type { get } var descriptor: AnyTypeDescriptor { get } - func matches(_ other: AnyMakerKey) -> Bool + func matches(_ other: AnyBindingKey) -> Bool } -public struct MakerKey: AnyMakerKey where Descriptor: TypeDescriptor { +public struct BindingKey: AnyBindingKey where Descriptor: TypeDescriptor { let contextType: Any.Type = Context.self let argumentType: Any.Type = Argument.self let descriptor: AnyTypeDescriptor - func matches(_ other: AnyMakerKey) -> Bool { + func matches(_ other: AnyBindingKey) -> Bool { descriptor.matches(other.descriptor) && (contextType == other.contextType || contextType == Any.self) && argumentType == other.argumentType diff --git a/Sources/BindingRequest.swift b/Sources/BindingRequest.swift index 9d7fa66e..e8fe1d7e 100644 --- a/Sources/BindingRequest.swift +++ b/Sources/BindingRequest.swift @@ -3,11 +3,11 @@ // public struct MakerRequest where Descriptor: TypeDescriptor { - let key: MakerKey + let key: BindingKey let context: Context let argument: Argument } func request(type _: Type.Type = Type.self, tag: Tag, arg: Argument) -> MakerRequest, Void, Argument> { - MakerRequest(key: MakerKey(descriptor: Tagged(tag: tag)), context: (), argument: arg) + MakerRequest(key: BindingKey(descriptor: Tagged(tag: tag)), context: (), argument: arg) } diff --git a/Sources/ContextedResolver.swift b/Sources/ContextedResolver.swift index c69b84d0..e699c25e 100644 --- a/Sources/ContextedResolver.swift +++ b/Sources/ContextedResolver.swift @@ -11,7 +11,7 @@ extension ContextedResolver: Resolver { func resolve(_ request: MakerRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { try resolver.resolve( MakerRequest( - key: MakerKey(descriptor: request.key.descriptor), + key: BindingKey(descriptor: request.key.descriptor), context: context, argument: request.argument ) diff --git a/Sources/Swinject.swift b/Sources/Swinject.swift index 164892b5..56127ddb 100644 --- a/Sources/Swinject.swift +++ b/Sources/Swinject.swift @@ -29,10 +29,10 @@ extension Swinject: Resolver { try instance(from: findMaker(for: request.key), context: request.context, arg: request.argument) } - private func findMaker(for key: AnyMakerKey) throws -> AnyInstanceMaker { - let entries = tree.makerEntries.filter { $0.key.matches(key) } - guard entries.count == 1 else { throw SwinjectError() } - return entries[0].maker + private func findMaker(for key: AnyBindingKey) throws -> AnyInstanceMaker { + let bindings = tree.bindings.compactMap { $0 as? SimpleBinding }.filter { $0.key.matches(key) } + guard bindings.count == 1 else { throw SwinjectError() } + return bindings[0].maker } private func instance(from maker: AnyInstanceMaker, context: Context, arg: Argument) throws -> Type { diff --git a/Sources/SwinjectTree.swift b/Sources/SwinjectTree.swift index f2fb6850..588b1e04 100644 --- a/Sources/SwinjectTree.swift +++ b/Sources/SwinjectTree.swift @@ -5,7 +5,7 @@ public protocol SwinjectEntry {} public struct SwinjectTree { - let makerEntries: [AnyMakerEntry] + let bindings: [Binding] let includeEntries: [ModuleIncludeEntry] } @@ -33,7 +33,7 @@ public enum SwinjectTreeBuilder { public static func buildFunction(_ input: [SwinjectEntry]) -> SwinjectTree { let entries = input.flatMap(unpack) return SwinjectTree( - makerEntries: entries.compactMap { $0 as? AnyMakerEntry }, + bindings: entries.compactMap { $0 as? Binding }, includeEntries: entries.compactMap { $0 as? ModuleIncludeEntry } ) // TODO: Validate diff --git a/Sources/TypeBinder.swift b/Sources/TypeBinder.swift index f566e22a..7f0a7c80 100644 --- a/Sources/TypeBinder.swift +++ b/Sources/TypeBinder.swift @@ -19,19 +19,19 @@ public func bind(_ descriptor: Descriptor) -> TypeBinder } public extension TypeBinder { - func with(_ maker: SomeMaker) -> MakerEntry where SomeMaker: InstanceMaker, SomeMaker.MadeType == Descriptor.BaseType { - MakerEntry(key: MakerKey(descriptor: descriptor), maker: maker) + func with(_ maker: SomeMaker) -> Binding where SomeMaker: InstanceMaker, SomeMaker.MadeType == Descriptor.BaseType { + SimpleBinding(key: BindingKey(descriptor: descriptor), maker: maker) } - func with(_ anInstance: Descriptor.BaseType) -> MakerEntry { + func with(_ anInstance: Descriptor.BaseType) -> Binding { with(instance(anInstance)) } } -public func & (lhs: TypeBinder, rhs: SomeMaker) -> MakerEntry where SomeMaker: InstanceMaker, SomeMaker.MadeType == Descriptor.BaseType { +public func & (lhs: TypeBinder, rhs: SomeMaker) -> Binding where SomeMaker: InstanceMaker, SomeMaker.MadeType == Descriptor.BaseType { lhs.with(rhs) } -public func & (lhs: TypeBinder, rhs: Descriptor.BaseType) -> MakerEntry { +public func & (lhs: TypeBinder, rhs: Descriptor.BaseType) -> Binding { lhs.with(rhs) } diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 80d60e42..2907fcf6 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -29,7 +29,7 @@ CDD8380722DA30C6003E9909 /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380622DA30C6003E9909 /* TypeDescriptor.swift */; }; CDD8380A22DA31D9003E9909 /* TypeBinderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380822DA31C6003E9909 /* TypeBinderSpec.swift */; }; CDD8380C22DA3AD8003E9909 /* InstanceMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380B22DA3AD8003E9909 /* InstanceMaker.swift */; }; - CDD8380E22DA3B0D003E9909 /* BindingEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380D22DA3B0D003E9909 /* BindingEntry.swift */; }; + CDD8380E22DA3B0D003E9909 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380D22DA3B0D003E9909 /* Binding.swift */; }; CDD8381022DA429F003E9909 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8380F22DA429F003E9909 /* Resolver.swift */; }; CDD8381622DA4B55003E9909 /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381522DA4B55003E9909 /* Swinject.swift */; }; CDD8381B22DA4CBE003E9909 /* SwinjectSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381922DA4C9F003E9909 /* SwinjectSpec.swift */; }; @@ -76,7 +76,7 @@ CDD8380622DA30C6003E9909 /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; CDD8380822DA31C6003E9909 /* TypeBinderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinderSpec.swift; sourceTree = ""; }; CDD8380B22DA3AD8003E9909 /* InstanceMaker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceMaker.swift; sourceTree = ""; }; - CDD8380D22DA3B0D003E9909 /* BindingEntry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingEntry.swift; sourceTree = ""; }; + CDD8380D22DA3B0D003E9909 /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; CDD8380F22DA429F003E9909 /* Resolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Resolver.swift; sourceTree = ""; }; CDD8381522DA4B55003E9909 /* Swinject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Swinject.swift; sourceTree = ""; }; CDD8381922DA4C9F003E9909 /* SwinjectSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectSpec.swift; sourceTree = ""; }; @@ -139,7 +139,7 @@ CD6DE54222DE65B500532D08 /* SimpleInstanceMaker.swift */, CDD8380F22DA429F003E9909 /* Resolver.swift */, CD6DE54422DED11600532D08 /* ContextedResolver.swift */, - CDD8380D22DA3B0D003E9909 /* BindingEntry.swift */, + CDD8380D22DA3B0D003E9909 /* Binding.swift */, CD6DE53622DD1CE900532D08 /* BindingKey.swift */, CD6DE53822DD1D0A00532D08 /* BindingRequest.swift */, CDD8381522DA4B55003E9909 /* Swinject.swift */, @@ -383,7 +383,7 @@ CD6DE54522DED11600532D08 /* ContextedResolver.swift in Sources */, CDD8381622DA4B55003E9909 /* Swinject.swift in Sources */, CDD8380522DA307F003E9909 /* TypeBinder.swift in Sources */, - CDD8380E22DA3B0D003E9909 /* BindingEntry.swift in Sources */, + CDD8380E22DA3B0D003E9909 /* Binding.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Tests/ApiSpecs/InjectionApiSpec.swift b/Tests/ApiSpecs/InjectionApiSpec.swift index ea748efa..d241e13e 100644 --- a/Tests/ApiSpecs/InjectionApiSpec.swift +++ b/Tests/ApiSpecs/InjectionApiSpec.swift @@ -36,7 +36,7 @@ class InjectionApiSpec: QuickSpec { override func spec() { } expect { try swinject.instance(of: Pet.self).owner } === person } - it("throws if has multiple entries for the same request") { + it("throws if has multiple bindings for the same request") { let swinject = Swinject { bbind(Int.self) & 42 bbind(Int.self) & provider { 17 + 25 } diff --git a/Tests/Support/GeneratedMocks.swift b/Tests/Support/GeneratedMocks.swift index c3ced83f..193000d5 100644 --- a/Tests/Support/GeneratedMocks.swift +++ b/Tests/Support/GeneratedMocks.swift @@ -7,47 +7,7 @@ @testable import Swinject -class AnyInstanceMakerMock: AnyInstanceMaker { - // MARK: - makeInstance - - var makeInstanceArgContextResolverThrowableError: Error? - var makeInstanceArgContextResolverCallsCount = 0 - var makeInstanceArgContextResolverCalled: Bool { - return makeInstanceArgContextResolverCallsCount > 0 - } - - var makeInstanceArgContextResolverReceivedArguments: (arg: Any, context: Any, resolver: Resolver)? - var makeInstanceArgContextResolverReceivedInvocations: [(arg: Any, context: Any, resolver: Resolver)] = [] - var makeInstanceArgContextResolverReturnValue: Any! - var makeInstanceArgContextResolverClosure: ((Any, Any, Resolver) throws -> Any)? - - func makeInstance(arg: Any, context: Any, resolver: Resolver) throws -> Any { - if let error = makeInstanceArgContextResolverThrowableError { - throw error - } - makeInstanceArgContextResolverCallsCount += 1 - makeInstanceArgContextResolverReceivedArguments = (arg: arg, context: context, resolver: resolver) - makeInstanceArgContextResolverReceivedInvocations.append((arg: arg, context: context, resolver: resolver)) - return try makeInstanceArgContextResolverClosure.map { try $0(arg, context, resolver) } ?? makeInstanceArgContextResolverReturnValue - } -} - -class AnyMakerEntryMock: AnyMakerEntry { - var key: AnyMakerKey { - get { return underlyingKey } - set(value) { underlyingKey = value } - } - - var underlyingKey: AnyMakerKey! - var maker: AnyInstanceMaker { - get { return underlyingMaker } - set(value) { underlyingMaker = value } - } - - var underlyingMaker: AnyInstanceMaker! -} - -class AnyMakerKeyMock: AnyMakerKey { +class AnyBindingKeyMock: AnyBindingKey { var contextType: Any.Type { get { return underlyingContextType } set(value) { underlyingContextType = value } @@ -74,12 +34,12 @@ class AnyMakerKeyMock: AnyMakerKey { return matchesCallsCount > 0 } - var matchesReceivedOther: AnyMakerKey? - var matchesReceivedInvocations: [AnyMakerKey] = [] + var matchesReceivedOther: AnyBindingKey? + var matchesReceivedInvocations: [AnyBindingKey] = [] var matchesReturnValue: Bool! - var matchesClosure: ((AnyMakerKey) -> Bool)? + var matchesClosure: ((AnyBindingKey) -> Bool)? - func matches(_ other: AnyMakerKey) -> Bool { + func matches(_ other: AnyBindingKey) -> Bool { matchesCallsCount += 1 matchesReceivedOther = other matchesReceivedInvocations.append(other) @@ -87,6 +47,31 @@ class AnyMakerKeyMock: AnyMakerKey { } } +class AnyInstanceMakerMock: AnyInstanceMaker { + // MARK: - makeInstance + + var makeInstanceArgContextResolverThrowableError: Error? + var makeInstanceArgContextResolverCallsCount = 0 + var makeInstanceArgContextResolverCalled: Bool { + return makeInstanceArgContextResolverCallsCount > 0 + } + + var makeInstanceArgContextResolverReceivedArguments: (arg: Any, context: Any, resolver: Resolver)? + var makeInstanceArgContextResolverReceivedInvocations: [(arg: Any, context: Any, resolver: Resolver)] = [] + var makeInstanceArgContextResolverReturnValue: Any! + var makeInstanceArgContextResolverClosure: ((Any, Any, Resolver) throws -> Any)? + + func makeInstance(arg: Any, context: Any, resolver: Resolver) throws -> Any { + if let error = makeInstanceArgContextResolverThrowableError { + throw error + } + makeInstanceArgContextResolverCallsCount += 1 + makeInstanceArgContextResolverReceivedArguments = (arg: arg, context: context, resolver: resolver) + makeInstanceArgContextResolverReceivedInvocations.append((arg: arg, context: context, resolver: resolver)) + return try makeInstanceArgContextResolverClosure.map { try $0(arg, context, resolver) } ?? makeInstanceArgContextResolverReturnValue + } +} + class AnyResolverMock: AnyResolver { // MARK: - resolve @@ -133,4 +118,6 @@ class AnyTypeDescriptorMock: AnyTypeDescriptor { } } +class BindingMock: Binding {} + class ModuleIncludeEntryMock: ModuleIncludeEntry {} diff --git a/Tests/UnitSpecs/BindingKeySpec.swift b/Tests/UnitSpecs/BindingKeySpec.swift index ee765e96..dd0729a0 100644 --- a/Tests/UnitSpecs/BindingKeySpec.swift +++ b/Tests/UnitSpecs/BindingKeySpec.swift @@ -6,20 +6,20 @@ import Nimble import Quick @testable import Swinject -class MakerKeySpec: QuickSpec { override func spec() { - typealias AnyMakerKey = MakerKey - typealias ArgumentMakerKey = MakerKey - typealias ContextMakerKey = MakerKey +class BindingKeySpec: QuickSpec { override func spec() { + typealias AnyBindingKey = BindingKey + typealias ArgumentBindingKey = BindingKey + typealias ContextBindingKey = BindingKey describe("matching") { - var key: AnyMakerKey! + var key: AnyBindingKey! var descriptor = AnyTypeDescriptorMock() - var otherKey = AnyMakerKeyMock() + var otherKey = AnyBindingKeyMock() beforeEach { descriptor = AnyTypeDescriptorMock() descriptor.matchesReturnValue = true - key = AnyMakerKey(descriptor: descriptor) - otherKey = AnyMakerKeyMock() + key = AnyBindingKey(descriptor: descriptor) + otherKey = AnyBindingKeyMock() otherKey.descriptor = AnyTypeDescriptorMock() otherKey.argumentType = Void.self otherKey.contextType = Void.self @@ -30,7 +30,7 @@ class MakerKeySpec: QuickSpec { override func spec() { } it("it checks if descriptors match") { let otherDescriptor = AnyTypeDescriptorMock() - _ = key.matches(AnyMakerKey(descriptor: otherDescriptor)) + _ = key.matches(AnyBindingKey(descriptor: otherDescriptor)) expect(descriptor.matchesReceivedOther) === otherDescriptor } it("matches if descriptors match") { @@ -38,27 +38,27 @@ class MakerKeySpec: QuickSpec { override func spec() { expect { key.matches(otherKey) }.to(beTrue()) } it("does not match if argument types are different") { - let key = ArgumentMakerKey(descriptor: descriptor) + let key = ArgumentBindingKey(descriptor: descriptor) otherKey.argumentType = Double.self expect(key.matches(otherKey)).to(beFalse()) } it("matches if argument types are the same") { - let key = ArgumentMakerKey(descriptor: descriptor) + let key = ArgumentBindingKey(descriptor: descriptor) otherKey.argumentType = Int.self expect(key.matches(otherKey)).to(beTrue()) } it("does not match if context types are different") { - let key = ContextMakerKey(descriptor: descriptor) + let key = ContextBindingKey(descriptor: descriptor) otherKey.contextType = Double.self expect(key.matches(otherKey)).to(beFalse()) } it("matches if argument context are the same") { - let key = ContextMakerKey(descriptor: descriptor) + let key = ContextBindingKey(descriptor: descriptor) otherKey.contextType = Int.self expect(key.matches(otherKey)).to(beTrue()) } it("matches if context is Any") { - let key = ContextMakerKey(descriptor: descriptor) + let key = ContextBindingKey(descriptor: descriptor) otherKey.contextType = Int.self expect(key.matches(otherKey)).to(beTrue()) } diff --git a/Tests/UnitSpecs/ContextedResolverSpec.swift b/Tests/UnitSpecs/ContextedResolverSpec.swift index 505e36ce..75ea2d28 100644 --- a/Tests/UnitSpecs/ContextedResolverSpec.swift +++ b/Tests/UnitSpecs/ContextedResolverSpec.swift @@ -22,7 +22,7 @@ class ContextedResolverSpec: QuickSpec { override func spec() { } it("calls wrapped resolver with given type descriptor") { let descriptor = AnyTypeDescriptorMock() - let request = MakerRequest(key: MakerKey(descriptor: descriptor), context: (), argument: ()) + let request = MakerRequest(key: BindingKey(descriptor: descriptor), context: (), argument: ()) _ = try? resolver.resolve(request) let receivedRequest = wrapped.resolveReceivedRequest as? MakerRequest expect(receivedRequest?.key.descriptor) === descriptor diff --git a/Tests/UnitSpecs/SwinjectSpec.swift b/Tests/UnitSpecs/SwinjectSpec.swift index 4998c348..dde14d2b 100644 --- a/Tests/UnitSpecs/SwinjectSpec.swift +++ b/Tests/UnitSpecs/SwinjectSpec.swift @@ -17,11 +17,11 @@ class SwinjectSpec: QuickSpec { override func spec() { context("single maker") { var swinject: Swinject! var maker = AnyInstanceMakerMock() - var key = AnyMakerKeyMock() + var key = AnyBindingKeyMock() beforeEach { maker = AnyInstanceMakerMock() - key = AnyMakerKeyMock() - swinject = Swinject { MakerEntry(key: key, maker: maker) } + key = AnyBindingKeyMock() + swinject = Swinject { SimpleBinding(key: key, maker: maker) } } it("request instance from matching maker") { key.matchesReturnValue = true @@ -65,7 +65,7 @@ class SwinjectSpec: QuickSpec { override func spec() { it("matches maker with correct key") { key.matchesReturnValue = false _ = try? swinject.instance(tagged: "tag") as Int - let otherKey = key.matchesReceivedOther as? MakerKey, Void, Void> + let otherKey = key.matchesReceivedOther as? BindingKey, Void, Void> let descriptor = otherKey?.descriptor as? Tagged expect(descriptor?.tag) == "tag" } @@ -78,22 +78,22 @@ class SwinjectSpec: QuickSpec { override func spec() { context("multiple makers") { var swinject: Swinject! var makers = [AnyInstanceMakerMock]() - var keys = [AnyMakerKeyMock]() + var keys = [AnyBindingKeyMock]() beforeEach { - keys = Array(0 ..< 3).map { _ in AnyMakerKeyMock() } + keys = Array(0 ..< 3).map { _ in AnyBindingKeyMock() } keys.forEach { $0.matchesReturnValue = false } makers = keys.map { _ in AnyInstanceMakerMock() } swinject = Swinject { - MakerEntry(key: keys[0], maker: makers[0]) - MakerEntry(key: keys[1], maker: makers[1]) - MakerEntry(key: keys[2], maker: makers[2]) + SimpleBinding(key: keys[0], maker: makers[0]) + SimpleBinding(key: keys[1], maker: makers[1]) + SimpleBinding(key: keys[2], maker: makers[2]) } } - it("throws if multiple entries match requested type") { + it("throws if multiple bindings match requested type") { keys.forEach { $0.matchesReturnValue = true } expect { try swinject.instance(of: Any.self) }.to(throwError()) } - it("does not throw if single entry matches requested type") { + it("does not throw if single binding matches requested type") { keys[1].matchesReturnValue = true expect { try swinject.instance(of: Any.self) }.notTo(throwError()) } @@ -107,11 +107,11 @@ class SwinjectSpec: QuickSpec { override func spec() { describe("provider injection") { var swinject: Swinject! var maker = AnyInstanceMakerMock() - var key = AnyMakerKeyMock() + var key = AnyBindingKeyMock() beforeEach { maker = AnyInstanceMakerMock() - key = AnyMakerKeyMock() - swinject = Swinject { MakerEntry(key: key, maker: maker) } + key = AnyBindingKeyMock() + swinject = Swinject { SimpleBinding(key: key, maker: maker) } } it("does not throw if maker matches provided type") { key.matchesReturnValue = true @@ -145,7 +145,7 @@ class SwinjectSpec: QuickSpec { override func spec() { it("matches maker with correct key") { key.matchesReturnValue = true _ = try? swinject.provider(of: Any.self, tagged: "tag")() - let otherKey = key.matchesReceivedOther as? MakerKey, Void, Void> + let otherKey = key.matchesReceivedOther as? BindingKey, Void, Void> let descriptor = otherKey?.descriptor as? Tagged expect(descriptor?.tag) == "tag" } @@ -163,11 +163,11 @@ class SwinjectSpec: QuickSpec { override func spec() { describe("factory injection") { var swinject: Swinject! var maker = AnyInstanceMakerMock() - var key = AnyMakerKeyMock() + var key = AnyBindingKeyMock() beforeEach { maker = AnyInstanceMakerMock() - key = AnyMakerKeyMock() - swinject = Swinject { MakerEntry(key: key, maker: maker) } + key = AnyBindingKeyMock() + swinject = Swinject { SimpleBinding(key: key, maker: maker) } } it("throws if missing maker for created type") { key.matchesReturnValue = false @@ -207,7 +207,7 @@ class SwinjectSpec: QuickSpec { override func spec() { it("matches maker with correct key") { key.matchesReturnValue = false _ = try? swinject.factory(tagged: "tag")("arg") as Int - let otherKey = key.matchesReceivedOther as? MakerKey, Void, String> + let otherKey = key.matchesReceivedOther as? BindingKey, Void, String> let descriptor = otherKey?.descriptor as? Tagged expect(descriptor?.tag) == "tag" } diff --git a/Tests/UnitSpecs/SwinjectTreeBuilderSpec.swift b/Tests/UnitSpecs/SwinjectTreeBuilderSpec.swift index 22f347ee..f7c85d5a 100644 --- a/Tests/UnitSpecs/SwinjectTreeBuilderSpec.swift +++ b/Tests/UnitSpecs/SwinjectTreeBuilderSpec.swift @@ -10,34 +10,34 @@ class SwinjectTreeBuilderSpec: QuickSpec { override func spec() { describe("allowed syntax") { it("builds empty closure") { let tree = makeTree {} - expect(tree.makerEntries).to(beEmpty()) + expect(tree.bindings).to(beEmpty()) } it("builds closure with single entry") { - let tree = makeTree { AnyMakerEntryMock() } - expect(tree.makerEntries.count) == 1 + let tree = makeTree { BindingMock() } + expect(tree.bindings.count) == 1 } it("builds closure with multiple entries") { let tree = makeTree { - AnyMakerEntryMock(); AnyMakerEntryMock(); AnyMakerEntryMock(); AnyMakerEntryMock(); AnyMakerEntryMock() + BindingMock(); BindingMock(); BindingMock(); BindingMock(); BindingMock() } - expect(tree.makerEntries.count) == 5 + expect(tree.bindings.count) == 5 } // FIXME: Test coverage enabled build segfaults on this // it("builds closure with if statement") { // let tree = makeTree { -// if true { AnyMakerEntryMock() } +// if true { AnyBindingMock() } // } // expect(tree.makerEntries.count) == 1 // } // it("builds closure with nested if statement") { // let tree = makeTree { -// if true { AnyMakerEntryMock(); if true { AnyMakerEntryMock() } } +// if true { AnyBindingMock(); if true { AnyBindingMock() } } // } // expect(tree.makerEntries.count) == 2 // } // it("builds closure with if else statement") { // let tree = makeTree { -// if false {} else { AnyMakerEntryMock(); AnyMakerEntryMock() } +// if false {} else { AnyBindingMock(); AnyBindingMock() } // } // expect(tree.makerEntries.count) == 2 // } @@ -45,12 +45,12 @@ class SwinjectTreeBuilderSpec: QuickSpec { override func spec() { let tree = makeTree { ModuleIncludeEntryMock() ModuleIncludeEntryMock() - AnyMakerEntryMock() - AnyMakerEntryMock() - AnyMakerEntryMock() + BindingMock() + BindingMock() + BindingMock() } expect(tree.includeEntries.count) == 2 - expect(tree.makerEntries.count) == 3 + expect(tree.bindings.count) == 3 } } } } diff --git a/Tests/UnitSpecs/TypeBinderSpec.swift b/Tests/UnitSpecs/TypeBinderSpec.swift index 02c0b608..0f1e8ee0 100644 --- a/Tests/UnitSpecs/TypeBinderSpec.swift +++ b/Tests/UnitSpecs/TypeBinderSpec.swift @@ -24,47 +24,47 @@ class TypeBinderSpec: QuickSpec { override func spec() { } } describe("`with` method") { - it("produces entry with correct descriptor") { - let entry = bbind(descriptor).with(maker) - expect(entry.key.descriptor) === descriptor + it("produces binding with correct descriptor") { + let binding = bbind(descriptor).with(maker) as? SimpleBinding + expect(binding?.key.descriptor) === descriptor } - it("produces entry with correct argument type") { - let entry = bbind(Any.self).with(DummyMaker()) - expect(entry.key.argumentType is Int.Type).to(beTrue()) + it("produces binding with correct argument type") { + let binding = bbind(Any.self).with(DummyMaker()) as? SimpleBinding + expect(binding?.key.argumentType is Int.Type).to(beTrue()) } - it("produces entry with correct context type") { - let entry = bbind(Any.self).with(DummyMaker()) - expect(entry.key.contextType is Int.Type).to(beTrue()) + it("produces binding with correct context type") { + let binding = bbind(Any.self).with(DummyMaker()) as? SimpleBinding + expect(binding?.key.contextType is Int.Type).to(beTrue()) } - it("produces entry with correct maker") { - let entry = bbind(Any.self).with(maker) - expect(entry.maker) === maker + it("produces binding with correct maker") { + let binding = bbind(Any.self).with(maker) as? SimpleBinding + expect(binding?.maker) === maker } - it("produces entry if given value of descriptor type") { - let entry = bbind(Int.self).with(42) - expect(entry.maker is SimpleInstanceMaker).to(beTrue()) + it("produces binding if given value of descriptor type") { + let binding = bbind(Int.self).with(42) as? SimpleBinding + expect(binding?.maker is SimpleInstanceMaker).to(beTrue()) } } describe("& operator") { - it("produces entry with correct descriptor") { - let entry = bbind(descriptor) & maker - expect(entry.key.descriptor) === descriptor + it("produces binding with correct descriptor") { + let binding = bbind(descriptor) & maker as? SimpleBinding + expect(binding?.key.descriptor) === descriptor } - it("produces entry with correct argument type") { - let entry = bbind(Any.self) & DummyMaker() - expect(entry.key.argumentType is Int.Type).to(beTrue()) + it("produces binding with correct argument type") { + let binding = bbind(Any.self) & DummyMaker() as? SimpleBinding + expect(binding?.key.argumentType is Int.Type).to(beTrue()) } - it("produces entry with correct context type") { - let entry = bbind(Any.self) & DummyMaker() - expect(entry.key.contextType is Int.Type).to(beTrue()) + it("produces binding with correct context type") { + let binding = bbind(Any.self) & DummyMaker() as? SimpleBinding + expect(binding?.key.contextType is Int.Type).to(beTrue()) } - it("produces entry with correct maker") { - let entry = bbind(Any.self) & maker - expect(entry.maker) === maker + it("produces binding with correct maker") { + let binding = bbind(Any.self) & maker as? SimpleBinding + expect(binding?.maker) === maker } - it("produces entry provider if given value of descriptor type") { - let entry = bbind(Int.self) & 42 - expect(entry.maker is SimpleInstanceMaker).to(beTrue()) + it("produces binding provider if given value of descriptor type") { + let binding = bbind(Int.self) & 42 as? SimpleBinding + expect(binding?.maker is SimpleInstanceMaker).to(beTrue()) } } } } From 04d77352938a95cfcbb9fbf59a98ac9b1b3c5654 Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Wed, 17 Jul 2019 16:34:35 +0200 Subject: [PATCH 056/239] Refactor Swinject to use binding as proxy for matching / creation --- Sources/Binding.swift | 18 ++- Sources/BindingKey.swift | 4 +- Sources/Swinject.swift | 12 +- Tests/Support/GeneratedMocks.swift | 44 +++++- Tests/UnitSpecs/SwinjectSpec.swift | 220 ++++++++++++++--------------- 5 files changed, 173 insertions(+), 125 deletions(-) diff --git a/Sources/Binding.swift b/Sources/Binding.swift index bd5cde29..8a0ed241 100644 --- a/Sources/Binding.swift +++ b/Sources/Binding.swift @@ -3,9 +3,23 @@ // // sourcery: AutoMockable -public protocol Binding: SwinjectEntry {} +public protocol Binding: SwinjectEntry { + func matches(_ key: AnyBindingKey) -> Bool + func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any +} -struct SimpleBinding: Binding { +struct SimpleBinding { let key: AnyBindingKey let maker: AnyInstanceMaker } + +extension SimpleBinding: Binding { + // TODO: Proper Unit Tests + func matches(_ key: AnyBindingKey) -> Bool { + self.key.matches(key) + } + + func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any { + try maker.makeInstance(arg: arg, context: context, resolver: resolver) + } +} diff --git a/Sources/BindingKey.swift b/Sources/BindingKey.swift index 563f7510..ce352db4 100644 --- a/Sources/BindingKey.swift +++ b/Sources/BindingKey.swift @@ -3,7 +3,7 @@ // // sourcery: AutoMockable -protocol AnyBindingKey { +public protocol AnyBindingKey { var contextType: Any.Type { get } var argumentType: Any.Type { get } var descriptor: AnyTypeDescriptor { get } @@ -11,7 +11,7 @@ protocol AnyBindingKey { func matches(_ other: AnyBindingKey) -> Bool } -public struct BindingKey: AnyBindingKey where Descriptor: TypeDescriptor { +struct BindingKey: AnyBindingKey where Descriptor: TypeDescriptor { let contextType: Any.Type = Context.self let argumentType: Any.Type = Argument.self let descriptor: AnyTypeDescriptor diff --git a/Sources/Swinject.swift b/Sources/Swinject.swift index 56127ddb..46be931b 100644 --- a/Sources/Swinject.swift +++ b/Sources/Swinject.swift @@ -26,16 +26,16 @@ public extension Swinject { extension Swinject: Resolver { public func resolve(_ request: MakerRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { - try instance(from: findMaker(for: request.key), context: request.context, arg: request.argument) + try instance(from: findBinding(for: request.key), context: request.context, arg: request.argument) } - private func findMaker(for key: AnyBindingKey) throws -> AnyInstanceMaker { - let bindings = tree.bindings.compactMap { $0 as? SimpleBinding }.filter { $0.key.matches(key) } + private func findBinding(for key: AnyBindingKey) throws -> Binding { + let bindings = tree.bindings.filter { $0.matches(key) } guard bindings.count == 1 else { throw SwinjectError() } - return bindings[0].maker + return bindings[0] } - private func instance(from maker: AnyInstanceMaker, context: Context, arg: Argument) throws -> Type { - try maker.makeInstance(arg: arg, context: context, resolver: self) as? Type ?? { throw SwinjectError() }() + private func instance(from binding: Binding, context: Context, arg: Argument) throws -> Type { + try binding.instance(arg: arg, context: context, resolver: self) as? Type ?? { throw SwinjectError() }() } } diff --git a/Tests/Support/GeneratedMocks.swift b/Tests/Support/GeneratedMocks.swift index 193000d5..0121b45e 100644 --- a/Tests/Support/GeneratedMocks.swift +++ b/Tests/Support/GeneratedMocks.swift @@ -118,6 +118,48 @@ class AnyTypeDescriptorMock: AnyTypeDescriptor { } } -class BindingMock: Binding {} +class BindingMock: Binding { + // MARK: - matches + + var matchesCallsCount = 0 + var matchesCalled: Bool { + return matchesCallsCount > 0 + } + + var matchesReceivedKey: AnyBindingKey? + var matchesReceivedInvocations: [AnyBindingKey] = [] + var matchesReturnValue: Bool! + var matchesClosure: ((AnyBindingKey) -> Bool)? + + func matches(_ key: AnyBindingKey) -> Bool { + matchesCallsCount += 1 + matchesReceivedKey = key + matchesReceivedInvocations.append(key) + return matchesClosure.map { $0(key) } ?? matchesReturnValue + } + + // MARK: - instance + + var instanceArgContextResolverThrowableError: Error? + var instanceArgContextResolverCallsCount = 0 + var instanceArgContextResolverCalled: Bool { + return instanceArgContextResolverCallsCount > 0 + } + + var instanceArgContextResolverReceivedArguments: (arg: Any, context: Any, resolver: Resolver)? + var instanceArgContextResolverReceivedInvocations: [(arg: Any, context: Any, resolver: Resolver)] = [] + var instanceArgContextResolverReturnValue: Any! + var instanceArgContextResolverClosure: ((Any, Any, Resolver) throws -> Any)? + + func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any { + if let error = instanceArgContextResolverThrowableError { + throw error + } + instanceArgContextResolverCallsCount += 1 + instanceArgContextResolverReceivedArguments = (arg: arg, context: context, resolver: resolver) + instanceArgContextResolverReceivedInvocations.append((arg: arg, context: context, resolver: resolver)) + return try instanceArgContextResolverClosure.map { try $0(arg, context, resolver) } ?? instanceArgContextResolverReturnValue + } +} class ModuleIncludeEntryMock: ModuleIncludeEntry {} diff --git a/Tests/UnitSpecs/SwinjectSpec.swift b/Tests/UnitSpecs/SwinjectSpec.swift index dde14d2b..4a90187c 100644 --- a/Tests/UnitSpecs/SwinjectSpec.swift +++ b/Tests/UnitSpecs/SwinjectSpec.swift @@ -8,253 +8,245 @@ import Quick class SwinjectSpec: QuickSpec { override func spec() { describe("instance injection") { - context("no makers") { + context("no bindings") { it("throws") { let swinject = Swinject {} expect { try swinject.instance(of: Int.self) }.to(throwError()) } } - context("single maker") { + context("single binding") { var swinject: Swinject! - var maker = AnyInstanceMakerMock() - var key = AnyBindingKeyMock() + var binding = BindingMock() beforeEach { - maker = AnyInstanceMakerMock() - key = AnyBindingKeyMock() - swinject = Swinject { SimpleBinding(key: key, maker: maker) } + binding = BindingMock() + swinject = Swinject { binding } } - it("request instance from matching maker") { - key.matchesReturnValue = true + it("request instance from matching binding") { + binding.matchesReturnValue = true _ = try? swinject.instance(of: Any.self) - expect(maker.makeInstanceArgContextResolverCallsCount) == 1 + expect(binding.instanceArgContextResolverCallsCount) == 1 } - it("does not request instance from matching maker until instance is required") { - key.matchesReturnValue = true - expect(maker.makeInstanceArgContextResolverCallsCount) == 0 + it("does not request instance from matching binding until instance is required") { + binding.matchesReturnValue = true + expect(binding.instanceArgContextResolverCallsCount) == 0 } - it("only requests instance from matching maker") { - key.matchesReturnValue = false + it("only requests instance from matching binding") { + binding.matchesReturnValue = false _ = try? swinject.instance(of: Any.self) - expect(maker.makeInstanceArgContextResolverCallsCount) == 0 + expect(binding.instanceArgContextResolverCallsCount) == 0 } - it("returns instance produced by maker") { - key.matchesReturnValue = true - maker.makeInstanceArgContextResolverReturnValue = 42 + it("returns instance produced by binding") { + binding.matchesReturnValue = true + binding.instanceArgContextResolverReturnValue = 42 expect { try swinject.instance(of: Any.self) as? Int } == 42 } - it("rethrows error from maker") { - key.matchesReturnValue = true - maker.makeInstanceArgContextResolverThrowableError = TestError() + it("rethrows error from binding") { + binding.matchesReturnValue = true + binding.instanceArgContextResolverThrowableError = TestError() expect { try swinject.instance(of: Any.self) }.to(throwError(errorType: TestError.self)) } it("crashes if bound type does not match requested type") { - key.matchesReturnValue = true - maker.makeInstanceArgContextResolverReturnValue = "" + binding.matchesReturnValue = true + binding.instanceArgContextResolverReturnValue = "" expect { _ = try swinject.instance(of: Double.self) }.to(throwError()) } it("does not crash if bound type conforms to the requested type") { - key.matchesReturnValue = true - maker.makeInstanceArgContextResolverReturnValue = 42 + binding.matchesReturnValue = true + binding.instanceArgContextResolverReturnValue = 42 expect { _ = try swinject.instance(of: CustomStringConvertible?.self) }.notTo(throwError()) } it("passes swinject as resolver") { - key.matchesReturnValue = true + binding.matchesReturnValue = true _ = try? swinject.instance(of: Any.self) - expect(maker.makeInstanceArgContextResolverReceivedArguments?.resolver is Swinject).to(beTrue()) + expect(binding.instanceArgContextResolverReceivedArguments?.resolver is Swinject).to(beTrue()) } - it("matches maker with correct key") { - key.matchesReturnValue = false + it("matches binding with correct key") { + binding.matchesReturnValue = false _ = try? swinject.instance(tagged: "tag") as Int - let otherKey = key.matchesReceivedOther as? BindingKey, Void, Void> + let otherKey = binding.matchesReceivedKey as? BindingKey, Void, Void> let descriptor = otherKey?.descriptor as? Tagged expect(descriptor?.tag) == "tag" } - it("matches maker with correct context") { - key.matchesReturnValue = false + it("matches binding with correct context") { + binding.matchesReturnValue = false _ = try? swinject.on("context").instance() as Int - expect(key.matchesReceivedOther?.contextType is String.Type).to(beTrue()) + expect(binding.matchesReceivedKey?.contextType is String.Type).to(beTrue()) } } - context("multiple makers") { + context("multiple bindings") { var swinject: Swinject! - var makers = [AnyInstanceMakerMock]() - var keys = [AnyBindingKeyMock]() + var bindings = [BindingMock]() beforeEach { - keys = Array(0 ..< 3).map { _ in AnyBindingKeyMock() } - keys.forEach { $0.matchesReturnValue = false } - makers = keys.map { _ in AnyInstanceMakerMock() } + bindings = Array(0 ..< 3).map { _ in BindingMock() } + bindings.forEach { $0.matchesReturnValue = false } swinject = Swinject { - SimpleBinding(key: keys[0], maker: makers[0]) - SimpleBinding(key: keys[1], maker: makers[1]) - SimpleBinding(key: keys[2], maker: makers[2]) + bindings[0] + bindings[1] + bindings[2] } } it("throws if multiple bindings match requested type") { - keys.forEach { $0.matchesReturnValue = true } + bindings.forEach { $0.matchesReturnValue = true } expect { try swinject.instance(of: Any.self) }.to(throwError()) } it("does not throw if single binding matches requested type") { - keys[1].matchesReturnValue = true + bindings[1].matchesReturnValue = true expect { try swinject.instance(of: Any.self) }.notTo(throwError()) } - it("returns instance from matching maker") { - keys[1].matchesReturnValue = true - makers[1].makeInstanceArgContextResolverReturnValue = 42 + it("returns instance from matching binding") { + bindings[1].matchesReturnValue = true + bindings[1].instanceArgContextResolverReturnValue = 42 expect { try swinject.instance(of: Int.self) } == 42 } } } describe("provider injection") { var swinject: Swinject! - var maker = AnyInstanceMakerMock() - var key = AnyBindingKeyMock() + var binding = BindingMock() beforeEach { - maker = AnyInstanceMakerMock() - key = AnyBindingKeyMock() - swinject = Swinject { SimpleBinding(key: key, maker: maker) } + binding = BindingMock() + swinject = Swinject { binding } } - it("does not throw if maker matches provided type") { - key.matchesReturnValue = true - maker.makeInstanceArgContextResolverReturnValue = 42 + it("does not throw if binding matches provided type") { + binding.matchesReturnValue = true + binding.instanceArgContextResolverReturnValue = 42 let provider = swinject.provider() as () throws -> Int expect { try provider() }.notTo(throwError()) } - it("throws if missing maker for provided type") { - key.matchesReturnValue = false + it("throws if missing binding for provided type") { + binding.matchesReturnValue = false let provider = swinject.provider() as () throws -> Int expect { try provider() }.to(throwError()) } it("does not request provided type until provider is called") { - key.matchesReturnValue = true - maker.makeInstanceArgContextResolverReturnValue = 42 + binding.matchesReturnValue = true + binding.instanceArgContextResolverReturnValue = 42 _ = swinject.provider(of: Int.self) - expect(maker.makeInstanceArgContextResolverCallsCount) == 0 + expect(binding.instanceArgContextResolverCallsCount) == 0 } - it("returns instance from maker") { - key.matchesReturnValue = true - maker.makeInstanceArgContextResolverReturnValue = 42 + it("returns instance from binding") { + binding.matchesReturnValue = true + binding.instanceArgContextResolverReturnValue = 42 let provider = swinject.provider(of: Int.self) expect { try provider() } == 42 } - it("rethrows maker error from provider") { - key.matchesReturnValue = true - maker.makeInstanceArgContextResolverThrowableError = TestError() + it("rethrows binding error from provider") { + binding.matchesReturnValue = true + binding.instanceArgContextResolverThrowableError = TestError() let provider = swinject.provider(of: Int.self) expect { try provider() }.to(throwError(errorType: TestError.self)) } - it("matches maker with correct key") { - key.matchesReturnValue = true + it("matches binding with correct key") { + binding.matchesReturnValue = true _ = try? swinject.provider(of: Any.self, tagged: "tag")() - let otherKey = key.matchesReceivedOther as? BindingKey, Void, Void> + let otherKey = binding.matchesReceivedKey as? BindingKey, Void, Void> let descriptor = otherKey?.descriptor as? Tagged expect(descriptor?.tag) == "tag" } - it("matches maker with correct context") { - key.matchesReturnValue = false + it("matches binding with correct context") { + binding.matchesReturnValue = false _ = try? swinject.on("context").provider()() as Int - expect(key.matchesReceivedOther?.contextType is String.Type).to(beTrue()) + expect(binding.matchesReceivedKey?.contextType is String.Type).to(beTrue()) } - it("passes given context to the bidndning") { - key.matchesReturnValue = true + it("passes given context to the binding") { + binding.matchesReturnValue = true _ = try? swinject.on("context").provider()() as Int - expect(maker.makeInstanceArgContextResolverReceivedArguments?.context as? String) == "context" + expect(binding.instanceArgContextResolverReceivedArguments?.context as? String) == "context" } } describe("factory injection") { var swinject: Swinject! - var maker = AnyInstanceMakerMock() - var key = AnyBindingKeyMock() + var binding = BindingMock() beforeEach { - maker = AnyInstanceMakerMock() - key = AnyBindingKeyMock() - swinject = Swinject { SimpleBinding(key: key, maker: maker) } + binding = BindingMock() + swinject = Swinject { binding } } - it("throws if missing maker for created type") { - key.matchesReturnValue = false + it("throws if missing binding for created type") { + binding.matchesReturnValue = false let factory = swinject.factory() as (String) throws -> Int expect { try factory("arg") }.to(throwError()) } - it("does not throw if maker matches created type") { - key.matchesReturnValue = true - maker.makeInstanceArgContextResolverReturnValue = 42 + it("does not throw if binding matches created type") { + binding.matchesReturnValue = true + binding.instanceArgContextResolverReturnValue = 42 let factory = swinject.factory() as (String) throws -> Int expect { try factory("arg") }.notTo(throwError()) } it("does not request created type until factory is called") { - key.matchesReturnValue = true - maker.makeInstanceArgContextResolverReturnValue = 42 + binding.matchesReturnValue = true + binding.instanceArgContextResolverReturnValue = 42 _ = swinject.factory() as (String) throws -> Int - expect(maker.makeInstanceArgContextResolverCallsCount) == 0 + expect(binding.instanceArgContextResolverCallsCount) == 0 } - it("rethrows maker error from factory") { - key.matchesReturnValue = true - maker.makeInstanceArgContextResolverThrowableError = TestError() + it("rethrows binding error from factory") { + binding.matchesReturnValue = true + binding.instanceArgContextResolverThrowableError = TestError() let factory = swinject.factory() as (String) throws -> Int expect { try factory("arg") }.to(throwError(errorType: TestError.self)) } - it("returns instance from maker") { - key.matchesReturnValue = true - maker.makeInstanceArgContextResolverReturnValue = 42 + it("returns instance from binding") { + binding.matchesReturnValue = true + binding.instanceArgContextResolverReturnValue = 42 let factory = swinject.factory() as (String) throws -> Int expect { try factory("arg") } == 42 } - it("passes given factory argument to maker") { - key.matchesReturnValue = true - maker.makeInstanceArgContextResolverReturnValue = 42 + it("passes given factory argument to binding") { + binding.matchesReturnValue = true + binding.instanceArgContextResolverReturnValue = 42 _ = try? swinject.factory(of: Int.self)("arg") - expect(maker.makeInstanceArgContextResolverReceivedArguments?.arg as? String) == "arg" + expect(binding.instanceArgContextResolverReceivedArguments?.arg as? String) == "arg" } - it("matches maker with correct key") { - key.matchesReturnValue = false + it("matches binding with correct key") { + binding.matchesReturnValue = false _ = try? swinject.factory(tagged: "tag")("arg") as Int - let otherKey = key.matchesReceivedOther as? BindingKey, Void, String> + let otherKey = binding.matchesReceivedKey as? BindingKey, Void, String> let descriptor = otherKey?.descriptor as? Tagged expect(descriptor?.tag) == "tag" } - it("matches maker with correct context") { - key.matchesReturnValue = false + it("matches binding with correct context") { + binding.matchesReturnValue = false _ = try? swinject.on("context").factory()("arg") as Int - expect(key.matchesReceivedOther?.contextType is String.Type).to(beTrue()) + expect(binding.matchesReceivedKey?.contextType is String.Type).to(beTrue()) } it("passes given context to the bidndning") { - key.matchesReturnValue = true + binding.matchesReturnValue = true _ = try? swinject.on("context").factory()("arg") as Int - expect(maker.makeInstanceArgContextResolverReceivedArguments?.context as? String) == "context" + expect(binding.instanceArgContextResolverReceivedArguments?.context as? String) == "context" } context("currying") { beforeEach { - key.matchesReturnValue = true - maker.makeInstanceArgContextResolverReturnValue = 42 + binding.matchesReturnValue = true + binding.instanceArgContextResolverReturnValue = 42 } it("can curry 2-tuple as 0 / 2 argument") { _ = try? swinject.factory()("arg1", "arg2") as Int - let receivedArg = maker.makeInstanceArgContextResolverReceivedArguments?.arg as? (String, String) + let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? (String, String) expect(receivedArg?.0) == "arg1" expect(receivedArg?.1) == "arg2" } it("can curry 2-tuple as 1 / 1 argument") { _ = try? swinject.factory(arg: "arg1")("arg2") as Int - let receivedArg = maker.makeInstanceArgContextResolverReceivedArguments?.arg as? (String, String) + let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? (String, String) expect(receivedArg?.0) == "arg1" expect(receivedArg?.1) == "arg2" } it("can curry 3-tuple as 0 / 3 argument") { _ = try? swinject.factory()("arg1", 2, "arg3") as Int - let receivedArg = maker.makeInstanceArgContextResolverReceivedArguments?.arg as? (String, Int, String) + let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? (String, Int, String) expect(receivedArg?.0) == "arg1" expect(receivedArg?.1) == 2 expect(receivedArg?.2) == "arg3" } it("can curry 3-tuple as 1 / 2 argument") { _ = try? swinject.factory(arg: "arg1")(2, "arg3") as Int - let receivedArg = maker.makeInstanceArgContextResolverReceivedArguments?.arg as? (String, Int, String) + let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? (String, Int, String) expect(receivedArg?.0) == "arg1" expect(receivedArg?.1) == 2 expect(receivedArg?.2) == "arg3" } it("can curry 3-tuple as 2 / 1 argument") { _ = try? swinject.factory(args: "arg1", 2)("arg3") as Int - let receivedArg = maker.makeInstanceArgContextResolverReceivedArguments?.arg as? (String, Int, String) + let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? (String, Int, String) expect(receivedArg?.0) == "arg1" expect(receivedArg?.1) == 2 expect(receivedArg?.2) == "arg3" From 08b2ce46fced16011e40fbc07f561ccd475b58dc Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Wed, 17 Jul 2019 16:40:55 +0200 Subject: [PATCH 057/239] Move InstanceMaker extensions to tests --- Sources/InstanceMaker.swift | 18 ---------------- Swinject.xcodeproj/project.pbxproj | 12 +++++++---- Tests/Support/{Utils.swift => Bridge.swift} | 0 Tests/Support/Convenience.swift | 23 +++++++++++++++++++++ 4 files changed, 31 insertions(+), 22 deletions(-) rename Tests/Support/{Utils.swift => Bridge.swift} (100%) create mode 100644 Tests/Support/Convenience.swift diff --git a/Sources/InstanceMaker.swift b/Sources/InstanceMaker.swift index 3bebf3cf..dfb2c107 100644 --- a/Sources/InstanceMaker.swift +++ b/Sources/InstanceMaker.swift @@ -14,24 +14,6 @@ public protocol InstanceMaker: AnyInstanceMaker { func makeInstance(arg: Argument, context: Context, resolver: Resolver) throws -> MadeType } -extension InstanceMaker where Argument == Void, Context == Any { - func makeInstance(resolver: Resolver) throws -> MadeType { - try makeInstance(arg: (), context: (), resolver: resolver) - } -} - -extension InstanceMaker where Argument == Void { - func makeInstance(context: Context, resolver: Resolver) throws -> MadeType { - try makeInstance(arg: (), context: context, resolver: resolver) - } -} - -extension InstanceMaker where Context == Any { - func makeInstance(arg: Argument, resolver: Resolver) throws -> MadeType { - try makeInstance(arg: arg, context: (), resolver: resolver) - } -} - public extension AnyInstanceMaker where Self: InstanceMaker { func makeInstance(arg: Any, context: Any, resolver: Resolver) throws -> Any { guard let arg = arg as? Argument, let context = context as? Context else { throw SwinjectError() } diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 2907fcf6..d0546ade 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -12,6 +12,7 @@ 771BFC9122D600B700AFB237 /* Nimble in Frameworks */ = {isa = PBXBuildFile; productRef = 771BFC9022D600B700AFB237 /* Nimble */; }; 771BFC9422D600CC00AFB237 /* Quick in Frameworks */ = {isa = PBXBuildFile; productRef = 771BFC9322D600CC00AFB237 /* Quick */; }; 77729C9E22DCCA20005C3281 /* InjectionApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77729C9D22DCCA20005C3281 /* InjectionApiSpec.swift */; }; + 77906E7D22DF6A8D009CDCF4 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77906E7C22DF6A8D009CDCF4 /* Convenience.swift */; }; CD6DE53522DD1C7300532D08 /* BindingKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53322DD1C6800532D08 /* BindingKeySpec.swift */; }; CD6DE53722DD1CE900532D08 /* BindingKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53622DD1CE900532D08 /* BindingKey.swift */; }; CD6DE53922DD1D0A00532D08 /* BindingRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53822DD1D0A00532D08 /* BindingRequest.swift */; }; @@ -34,7 +35,7 @@ CDD8381622DA4B55003E9909 /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381522DA4B55003E9909 /* Swinject.swift */; }; CDD8381B22DA4CBE003E9909 /* SwinjectSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381922DA4C9F003E9909 /* SwinjectSpec.swift */; }; CDD8381D22DA4E02003E9909 /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381C22DA4E02003E9909 /* SwinjectError.swift */; }; - CDD8381F22DA4F6F003E9909 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381E22DA4F6F003E9909 /* Utils.swift */; }; + CDD8381F22DA4F6F003E9909 /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381E22DA4F6F003E9909 /* Bridge.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -56,6 +57,7 @@ 771BFC8B22D5FAAE00AFB237 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nimble.framework; path = Carthage/Build/Mac/Nimble.framework; sourceTree = ""; }; 771BFC8C22D5FAAE00AFB237 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quick.framework; path = Carthage/Build/Mac/Quick.framework; sourceTree = ""; }; 77729C9D22DCCA20005C3281 /* InjectionApiSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InjectionApiSpec.swift; sourceTree = ""; }; + 77906E7C22DF6A8D009CDCF4 /* Convenience.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Convenience.swift; sourceTree = ""; }; CD6DE53322DD1C6800532D08 /* BindingKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingKeySpec.swift; sourceTree = ""; }; CD6DE53622DD1CE900532D08 /* BindingKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingKey.swift; sourceTree = ""; }; CD6DE53822DD1D0A00532D08 /* BindingRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingRequest.swift; sourceTree = ""; }; @@ -81,7 +83,7 @@ CDD8381522DA4B55003E9909 /* Swinject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Swinject.swift; sourceTree = ""; }; CDD8381922DA4C9F003E9909 /* SwinjectSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectSpec.swift; sourceTree = ""; }; CDD8381C22DA4E02003E9909 /* SwinjectError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectError.swift; sourceTree = ""; }; - CDD8381E22DA4F6F003E9909 /* Utils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = ""; }; + CDD8381E22DA4F6F003E9909 /* Bridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bridge.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -172,7 +174,8 @@ 77729C9422DCC56D005C3281 /* Support */ = { isa = PBXGroup; children = ( - CDD8381E22DA4F6F003E9909 /* Utils.swift */, + CDD8381E22DA4F6F003E9909 /* Bridge.swift */, + 77906E7C22DF6A8D009CDCF4 /* Convenience.swift */, CDADF33622DB753800C5D8DB /* TestModels.swift */, CDADF33F22DB883A00C5D8DB /* GeneratedMocks.swift */, CD85AF1122DA5A8F00A8B7CA /* NonGeneratedMocks.swift */, @@ -392,7 +395,8 @@ buildActionMask = 2147483647; files = ( CD6DE54722DED16400532D08 /* ContextedResolverSpec.swift in Sources */, - CDD8381F22DA4F6F003E9909 /* Utils.swift in Sources */, + 77906E7D22DF6A8D009CDCF4 /* Convenience.swift in Sources */, + CDD8381F22DA4F6F003E9909 /* Bridge.swift in Sources */, CDD8381B22DA4CBE003E9909 /* SwinjectSpec.swift in Sources */, CDADF34022DB883A00C5D8DB /* GeneratedMocks.swift in Sources */, CDD8380A22DA31D9003E9909 /* TypeBinderSpec.swift in Sources */, diff --git a/Tests/Support/Utils.swift b/Tests/Support/Bridge.swift similarity index 100% rename from Tests/Support/Utils.swift rename to Tests/Support/Bridge.swift diff --git a/Tests/Support/Convenience.swift b/Tests/Support/Convenience.swift new file mode 100644 index 00000000..4d09d1ca --- /dev/null +++ b/Tests/Support/Convenience.swift @@ -0,0 +1,23 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +@testable import Swinject + +extension InstanceMaker where Argument == Void, Context == Any { + func makeInstance(resolver: Resolver) throws -> MadeType { + try makeInstance(arg: (), context: (), resolver: resolver) + } +} + +extension InstanceMaker where Argument == Void { + func makeInstance(context: Context, resolver: Resolver) throws -> MadeType { + try makeInstance(arg: (), context: context, resolver: resolver) + } +} + +extension InstanceMaker where Context == Any { + func makeInstance(arg: Argument, resolver: Resolver) throws -> MadeType { + try makeInstance(arg: arg, context: (), resolver: resolver) + } +} From 71424870154c886c157b6a4e8402198e97da0aba Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Wed, 17 Jul 2019 16:45:50 +0200 Subject: [PATCH 058/239] Rename MakerRequest to InstanceRequest --- Sources/BindingRequest.swift | 13 ------------- Sources/ContextedResolver.swift | 4 ++-- Sources/InstanceRequest.swift | 13 +++++++++++++ Sources/Resolver.swift | 2 +- Sources/Swinject.swift | 2 +- Sources/SwinjectError.swift | 2 +- Swinject.xcodeproj/project.pbxproj | 8 ++++---- Tests/Support/NonGeneratedMocks.swift | 4 ++-- Tests/UnitSpecs/ContextedResolverSpec.swift | 8 ++++---- 9 files changed, 28 insertions(+), 28 deletions(-) delete mode 100644 Sources/BindingRequest.swift create mode 100644 Sources/InstanceRequest.swift diff --git a/Sources/BindingRequest.swift b/Sources/BindingRequest.swift deleted file mode 100644 index e8fe1d7e..00000000 --- a/Sources/BindingRequest.swift +++ /dev/null @@ -1,13 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -public struct MakerRequest where Descriptor: TypeDescriptor { - let key: BindingKey - let context: Context - let argument: Argument -} - -func request(type _: Type.Type = Type.self, tag: Tag, arg: Argument) -> MakerRequest, Void, Argument> { - MakerRequest(key: BindingKey(descriptor: Tagged(tag: tag)), context: (), argument: arg) -} diff --git a/Sources/ContextedResolver.swift b/Sources/ContextedResolver.swift index e699c25e..bc0eda11 100644 --- a/Sources/ContextedResolver.swift +++ b/Sources/ContextedResolver.swift @@ -8,9 +8,9 @@ struct ContextedResolver { } extension ContextedResolver: Resolver { - func resolve(_ request: MakerRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { + func resolve(_ request: InstanceRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { try resolver.resolve( - MakerRequest( + InstanceRequest( key: BindingKey(descriptor: request.key.descriptor), context: context, argument: request.argument diff --git a/Sources/InstanceRequest.swift b/Sources/InstanceRequest.swift new file mode 100644 index 00000000..b550052e --- /dev/null +++ b/Sources/InstanceRequest.swift @@ -0,0 +1,13 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +public struct InstanceRequest where Descriptor: TypeDescriptor { + let key: BindingKey + let context: Context + let argument: Argument +} + +func request(type _: Type.Type = Type.self, tag: Tag, arg: Argument) -> InstanceRequest, Void, Argument> { + InstanceRequest(key: BindingKey(descriptor: Tagged(tag: tag)), context: (), argument: arg) +} diff --git a/Sources/Resolver.swift b/Sources/Resolver.swift index cbb70d74..a48ef4ef 100644 --- a/Sources/Resolver.swift +++ b/Sources/Resolver.swift @@ -3,7 +3,7 @@ // public protocol Resolver { - func resolve(_ request: MakerRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor + func resolve(_ request: InstanceRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor } public extension Resolver { diff --git a/Sources/Swinject.swift b/Sources/Swinject.swift index 46be931b..8218b63a 100644 --- a/Sources/Swinject.swift +++ b/Sources/Swinject.swift @@ -25,7 +25,7 @@ public extension Swinject { } extension Swinject: Resolver { - public func resolve(_ request: MakerRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { + public func resolve(_ request: InstanceRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { try instance(from: findBinding(for: request.key), context: request.context, arg: request.argument) } diff --git a/Sources/SwinjectError.swift b/Sources/SwinjectError.swift index 2bed412e..ee16c729 100644 --- a/Sources/SwinjectError.swift +++ b/Sources/SwinjectError.swift @@ -2,7 +2,7 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -struct SwinjectError: Error { +public struct SwinjectError: Error { let file: String let line: Int diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index d0546ade..39b24269 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -15,7 +15,7 @@ 77906E7D22DF6A8D009CDCF4 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77906E7C22DF6A8D009CDCF4 /* Convenience.swift */; }; CD6DE53522DD1C7300532D08 /* BindingKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53322DD1C6800532D08 /* BindingKeySpec.swift */; }; CD6DE53722DD1CE900532D08 /* BindingKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53622DD1CE900532D08 /* BindingKey.swift */; }; - CD6DE53922DD1D0A00532D08 /* BindingRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53822DD1D0A00532D08 /* BindingRequest.swift */; }; + CD6DE53922DD1D0A00532D08 /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53822DD1D0A00532D08 /* InstanceRequest.swift */; }; CD6DE53D22DD30A100532D08 /* SimpleInstanceMakerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53C22DD30A100532D08 /* SimpleInstanceMakerSpec.swift */; }; CD6DE54322DE65B500532D08 /* SimpleInstanceMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE54222DE65B500532D08 /* SimpleInstanceMaker.swift */; }; CD6DE54522DED11600532D08 /* ContextedResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE54422DED11600532D08 /* ContextedResolver.swift */; }; @@ -60,7 +60,7 @@ 77906E7C22DF6A8D009CDCF4 /* Convenience.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Convenience.swift; sourceTree = ""; }; CD6DE53322DD1C6800532D08 /* BindingKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingKeySpec.swift; sourceTree = ""; }; CD6DE53622DD1CE900532D08 /* BindingKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingKey.swift; sourceTree = ""; }; - CD6DE53822DD1D0A00532D08 /* BindingRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingRequest.swift; sourceTree = ""; }; + CD6DE53822DD1D0A00532D08 /* InstanceRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRequest.swift; sourceTree = ""; }; CD6DE53C22DD30A100532D08 /* SimpleInstanceMakerSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleInstanceMakerSpec.swift; sourceTree = ""; }; CD6DE54222DE65B500532D08 /* SimpleInstanceMaker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleInstanceMaker.swift; sourceTree = ""; }; CD6DE54422DED11600532D08 /* ContextedResolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextedResolver.swift; sourceTree = ""; }; @@ -143,7 +143,7 @@ CD6DE54422DED11600532D08 /* ContextedResolver.swift */, CDD8380D22DA3B0D003E9909 /* Binding.swift */, CD6DE53622DD1CE900532D08 /* BindingKey.swift */, - CD6DE53822DD1D0A00532D08 /* BindingRequest.swift */, + CD6DE53822DD1D0A00532D08 /* InstanceRequest.swift */, CDD8381522DA4B55003E9909 /* Swinject.swift */, CDD8381C22DA4E02003E9909 /* SwinjectError.swift */, CDADF33422DB521400C5D8DB /* SwinjectModule.swift */, @@ -379,7 +379,7 @@ CDADF33522DB521400C5D8DB /* SwinjectModule.swift in Sources */, CDD8381022DA429F003E9909 /* Resolver.swift in Sources */, CD6DE53722DD1CE900532D08 /* BindingKey.swift in Sources */, - CD6DE53922DD1D0A00532D08 /* BindingRequest.swift in Sources */, + CD6DE53922DD1D0A00532D08 /* InstanceRequest.swift in Sources */, CDADF32122DB38C600C5D8DB /* SwinjectTree.swift in Sources */, CDD8381D22DA4E02003E9909 /* SwinjectError.swift in Sources */, CDD8380722DA30C6003E9909 /* TypeDescriptor.swift in Sources */, diff --git a/Tests/Support/NonGeneratedMocks.swift b/Tests/Support/NonGeneratedMocks.swift index cc36c67b..de14988b 100644 --- a/Tests/Support/NonGeneratedMocks.swift +++ b/Tests/Support/NonGeneratedMocks.swift @@ -5,7 +5,7 @@ @testable import Swinject class DummyResolver: Resolver { - func resolve(_: MakerRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { + func resolve(_: InstanceRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { fatalError() } } @@ -30,7 +30,7 @@ protocol AnyResolver { } extension AnyResolverMock: Resolver { - func resolve(_ request: MakerRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { + func resolve(_ request: InstanceRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { try resolve(request as Any) as! Descriptor.BaseType } } diff --git a/Tests/UnitSpecs/ContextedResolverSpec.swift b/Tests/UnitSpecs/ContextedResolverSpec.swift index 75ea2d28..109aeb40 100644 --- a/Tests/UnitSpecs/ContextedResolverSpec.swift +++ b/Tests/UnitSpecs/ContextedResolverSpec.swift @@ -22,20 +22,20 @@ class ContextedResolverSpec: QuickSpec { override func spec() { } it("calls wrapped resolver with given type descriptor") { let descriptor = AnyTypeDescriptorMock() - let request = MakerRequest(key: BindingKey(descriptor: descriptor), context: (), argument: ()) + let request = InstanceRequest(key: BindingKey(descriptor: descriptor), context: (), argument: ()) _ = try? resolver.resolve(request) - let receivedRequest = wrapped.resolveReceivedRequest as? MakerRequest + let receivedRequest = wrapped.resolveReceivedRequest as? InstanceRequest expect(receivedRequest?.key.descriptor) === descriptor } it("calls wrapped resolver with given argument") { _ = try? resolver.resolve(request(type: Int.self, tag: NoTag(), arg: "argument")) - let receivedRequest = wrapped.resolveReceivedRequest as? MakerRequest, Void, String> + let receivedRequest = wrapped.resolveReceivedRequest as? InstanceRequest, Void, String> expect(receivedRequest?.argument) == "argument" } it("calls wrapped resolver with it's context") { let resolver = ContextedResolver(context: "context", resolver: wrapped) _ = try? resolver.resolve(request(type: Int.self, tag: NoTag(), arg: ())) - let receivedRequest = wrapped.resolveReceivedRequest as? MakerRequest, String, Void> + let receivedRequest = wrapped.resolveReceivedRequest as? InstanceRequest, String, Void> expect(receivedRequest?.context) == "context" } } From d8c94bf1d95c62893e0b9934dd92c378918e28cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Wed, 17 Jul 2019 18:05:51 +0200 Subject: [PATCH 059/239] Update api spec --- Tests/ApiSpecs/InjectionApiSpec.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/ApiSpecs/InjectionApiSpec.swift b/Tests/ApiSpecs/InjectionApiSpec.swift index d241e13e..5b553664 100644 --- a/Tests/ApiSpecs/InjectionApiSpec.swift +++ b/Tests/ApiSpecs/InjectionApiSpec.swift @@ -76,7 +76,7 @@ class InjectionApiSpec: QuickSpec { override func spec() { let factory = swinject.factory() as (Int) throws -> Int expect { try factory(5) } == 42 } - it("can inject factory maker as provider or instance") { + it("can inject factory binding as provider or instance") { let swinject = Swinject { bbind(Double.self) & 17.0 bbind(Int.self) & factory { Int(try $0.instance() as Double) + 5 * $1 } @@ -94,7 +94,7 @@ class InjectionApiSpec: QuickSpec { override func spec() { expect { try swinject.factory(of: Int.self, arg: 11)(14.0, "17") } == 42 expect { try swinject.factory(of: Int.self, args: 11, 14.0)("17") } == 42 } - it("can pass context to the makers") { + it("can pass context to the bindings") { // FIXME: compiler segfaults if declaring these providers inside function builder let intProvider = contexted(String.self).provider { _, string in Int(string)! } let doubleProvider = contexted(String.self).provider { _, string in Double(string)! } @@ -107,7 +107,7 @@ class InjectionApiSpec: QuickSpec { override func spec() { expect { try contexted.instance(of: Double.self) } == 42 expect { try swinject.instance(of: Int.self) }.to(throwError()) } - it("can use maker without context in any context") { + it("can use binding without context in any context") { let swinject = Swinject { bbind(Int.self) & 42 } From ce22adf62ac4c58f7f91ba343e620c391f39b005 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Wed, 17 Jul 2019 18:43:03 +0200 Subject: [PATCH 060/239] Define scope concept --- Sources/Scope.swift | 18 ++++++++++++++++++ Swinject.xcodeproj/project.pbxproj | 4 ++++ 2 files changed, 22 insertions(+) create mode 100644 Sources/Scope.swift diff --git a/Sources/Scope.swift b/Sources/Scope.swift new file mode 100644 index 00000000..0a8d5eb8 --- /dev/null +++ b/Sources/Scope.swift @@ -0,0 +1,18 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +public protocol Scope { + associatedtype Context + + static var lock: Lock { get } + static func registry(for context: Context) -> ScopeRegistry +} + +public protocol Lock {} + +public protocol ScopeRegistry { + // FXIME: name `AnyBindingKey` seems out of context here + func register(_ instance: Type, for key: AnyBindingKey) where Type: AnyObject + func instance(for key: AnyBindingKey) -> Type? where Type: AnyObject +} diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 39b24269..2bd826c1 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -20,6 +20,7 @@ CD6DE54322DE65B500532D08 /* SimpleInstanceMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE54222DE65B500532D08 /* SimpleInstanceMaker.swift */; }; CD6DE54522DED11600532D08 /* ContextedResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE54422DED11600532D08 /* ContextedResolver.swift */; }; CD6DE54722DED16400532D08 /* ContextedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE54622DED16400532D08 /* ContextedResolverSpec.swift */; }; + CD6DE54C22DF85AF00532D08 /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE54B22DF85AF00532D08 /* Scope.swift */; }; CD85AF1222DA5A8F00A8B7CA /* NonGeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF1122DA5A8F00A8B7CA /* NonGeneratedMocks.swift */; }; CDADF32122DB38C600C5D8DB /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDADF32022DB38C600C5D8DB /* SwinjectTree.swift */; }; CDADF33522DB521400C5D8DB /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDADF33422DB521400C5D8DB /* SwinjectModule.swift */; }; @@ -67,6 +68,7 @@ CD6DE54622DED16400532D08 /* ContextedResolverSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextedResolverSpec.swift; sourceTree = ""; }; CD6DE54822DED4A100532D08 /* .swiftformat */ = {isa = PBXFileReference; lastKnownFileType = text; path = .swiftformat; sourceTree = ""; }; CD6DE54A22DED4A100532D08 /* .sourcery.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .sourcery.yml; sourceTree = ""; }; + CD6DE54B22DF85AF00532D08 /* Scope.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Scope.swift; sourceTree = ""; }; CD85AF1122DA5A8F00A8B7CA /* NonGeneratedMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonGeneratedMocks.swift; sourceTree = ""; }; CDADF32022DB38C600C5D8DB /* SwinjectTree.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTree.swift; sourceTree = ""; }; CDADF33422DB521400C5D8DB /* SwinjectModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectModule.swift; sourceTree = ""; }; @@ -147,6 +149,7 @@ CDD8381522DA4B55003E9909 /* Swinject.swift */, CDD8381C22DA4E02003E9909 /* SwinjectError.swift */, CDADF33422DB521400C5D8DB /* SwinjectModule.swift */, + CD6DE54B22DF85AF00532D08 /* Scope.swift */, ); path = Sources; sourceTree = ""; @@ -382,6 +385,7 @@ CD6DE53922DD1D0A00532D08 /* InstanceRequest.swift in Sources */, CDADF32122DB38C600C5D8DB /* SwinjectTree.swift in Sources */, CDD8381D22DA4E02003E9909 /* SwinjectError.swift in Sources */, + CD6DE54C22DF85AF00532D08 /* Scope.swift in Sources */, CDD8380722DA30C6003E9909 /* TypeDescriptor.swift in Sources */, CD6DE54522DED11600532D08 /* ContextedResolver.swift in Sources */, CDD8381622DA4B55003E9909 /* Swinject.swift in Sources */, From ed10c5c4690fcb09b1756a7cedcf14cd0714e57b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Wed, 17 Jul 2019 19:43:34 +0200 Subject: [PATCH 061/239] Use BinderEnvironment to produce an instance maker --- Sources/BinderEnvironment.swift | 9 +++++++++ Sources/InstanceMaker.swift | 2 ++ Sources/SimpleInstanceMaker.swift | 18 +++++++----------- Swinject.xcodeproj/project.pbxproj | 14 ++++++++++++++ 4 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 Sources/BinderEnvironment.swift diff --git a/Sources/BinderEnvironment.swift b/Sources/BinderEnvironment.swift new file mode 100644 index 00000000..dff2d251 --- /dev/null +++ b/Sources/BinderEnvironment.swift @@ -0,0 +1,9 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +public struct BinderEnvironment {} + +public func contexted(_: Context.Type = Context.self) -> BinderEnvironment { + BinderEnvironment() +} diff --git a/Sources/InstanceMaker.swift b/Sources/InstanceMaker.swift index dfb2c107..2c1fd867 100644 --- a/Sources/InstanceMaker.swift +++ b/Sources/InstanceMaker.swift @@ -7,6 +7,8 @@ public protocol AnyInstanceMaker { func makeInstance(arg: Any, context: Any, resolver: Resolver) throws -> Any } +// FIXME: "Maker" is not a typical concept +// Could we use `InstanceFactory` / `InstanceBuilder` instead, or would it be too overloaded? public protocol InstanceMaker: AnyInstanceMaker { associatedtype MadeType associatedtype Argument diff --git a/Sources/SimpleInstanceMaker.swift b/Sources/SimpleInstanceMaker.swift index 9cfb9827..1d6faa12 100644 --- a/Sources/SimpleInstanceMaker.swift +++ b/Sources/SimpleInstanceMaker.swift @@ -16,32 +16,28 @@ public struct SimpleInstanceMaker: InstanceMaker { } } -public func contexted(_: Context.Type = Context.self) -> SimpleInstanceMaker.Type { - SimpleInstanceMaker.self -} - -extension SimpleInstanceMaker { - public static func provider(_ builder: @escaping (Resolver, Context) throws -> Type) -> SimpleInstanceMaker { +public extension BinderEnvironment { + func provider(_ builder: @escaping (Resolver, Context) throws -> Type) -> SimpleInstanceMaker { .init { r, c, _ in try builder(r, c) } } - public static func factory(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SimpleInstanceMaker { + func factory(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SimpleInstanceMaker { .init(builder) } - public static func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SimpleInstanceMaker { + func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SimpleInstanceMaker { .init { try builder($0, $1, $2.0, $2.1) } } - public static func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SimpleInstanceMaker { + func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SimpleInstanceMaker { .init { try builder($0, $1, $2.0, $2.1, $2.2) } } - public static func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SimpleInstanceMaker { + func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SimpleInstanceMaker { .init { try builder($0, $1, $2.0, $2.1, $2.2, $2.3) } } - public static func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SimpleInstanceMaker { + func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SimpleInstanceMaker { .init { try builder($0, $1, $2.0, $2.1, $2.2, $2.3, $2.4) } } } diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 2bd826c1..2b852058 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -21,6 +21,10 @@ CD6DE54522DED11600532D08 /* ContextedResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE54422DED11600532D08 /* ContextedResolver.swift */; }; CD6DE54722DED16400532D08 /* ContextedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE54622DED16400532D08 /* ContextedResolverSpec.swift */; }; CD6DE54C22DF85AF00532D08 /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE54B22DF85AF00532D08 /* Scope.swift */; }; + CD6DE54E22DF886F00532D08 /* ScopedInstanceMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE54D22DF886F00532D08 /* ScopedInstanceMaker.swift */; }; + CD6DE55022DF8B2700532D08 /* ScopedInstanceMakerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE54F22DF8B2700532D08 /* ScopedInstanceMakerSpec.swift */; }; + CD6DE55222DF93A000532D08 /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE55122DF93A000532D08 /* BinderEnvironment.swift */; }; + CD6DE55322DF94ED00532D08 /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE55122DF93A000532D08 /* BinderEnvironment.swift */; }; CD85AF1222DA5A8F00A8B7CA /* NonGeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF1122DA5A8F00A8B7CA /* NonGeneratedMocks.swift */; }; CDADF32122DB38C600C5D8DB /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDADF32022DB38C600C5D8DB /* SwinjectTree.swift */; }; CDADF33522DB521400C5D8DB /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDADF33422DB521400C5D8DB /* SwinjectModule.swift */; }; @@ -69,6 +73,9 @@ CD6DE54822DED4A100532D08 /* .swiftformat */ = {isa = PBXFileReference; lastKnownFileType = text; path = .swiftformat; sourceTree = ""; }; CD6DE54A22DED4A100532D08 /* .sourcery.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .sourcery.yml; sourceTree = ""; }; CD6DE54B22DF85AF00532D08 /* Scope.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Scope.swift; sourceTree = ""; }; + CD6DE54D22DF886F00532D08 /* ScopedInstanceMaker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopedInstanceMaker.swift; sourceTree = ""; }; + CD6DE54F22DF8B2700532D08 /* ScopedInstanceMakerSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopedInstanceMakerSpec.swift; sourceTree = ""; }; + CD6DE55122DF93A000532D08 /* BinderEnvironment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderEnvironment.swift; sourceTree = ""; }; CD85AF1122DA5A8F00A8B7CA /* NonGeneratedMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonGeneratedMocks.swift; sourceTree = ""; }; CDADF32022DB38C600C5D8DB /* SwinjectTree.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTree.swift; sourceTree = ""; }; CDADF33422DB521400C5D8DB /* SwinjectModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectModule.swift; sourceTree = ""; }; @@ -141,6 +148,8 @@ CDD8380622DA30C6003E9909 /* TypeDescriptor.swift */, CDD8380B22DA3AD8003E9909 /* InstanceMaker.swift */, CD6DE54222DE65B500532D08 /* SimpleInstanceMaker.swift */, + CD6DE54D22DF886F00532D08 /* ScopedInstanceMaker.swift */, + CD6DE55122DF93A000532D08 /* BinderEnvironment.swift */, CDD8380F22DA429F003E9909 /* Resolver.swift */, CD6DE54422DED11600532D08 /* ContextedResolver.swift */, CDD8380D22DA3B0D003E9909 /* Binding.swift */, @@ -195,6 +204,7 @@ CDD8381922DA4C9F003E9909 /* SwinjectSpec.swift */, CD6DE53322DD1C6800532D08 /* BindingKeySpec.swift */, CD6DE54622DED16400532D08 /* ContextedResolverSpec.swift */, + CD6DE54F22DF8B2700532D08 /* ScopedInstanceMakerSpec.swift */, ); path = UnitSpecs; sourceTree = ""; @@ -388,9 +398,11 @@ CD6DE54C22DF85AF00532D08 /* Scope.swift in Sources */, CDD8380722DA30C6003E9909 /* TypeDescriptor.swift in Sources */, CD6DE54522DED11600532D08 /* ContextedResolver.swift in Sources */, + CD6DE55322DF94ED00532D08 /* BinderEnvironment.swift in Sources */, CDD8381622DA4B55003E9909 /* Swinject.swift in Sources */, CDD8380522DA307F003E9909 /* TypeBinder.swift in Sources */, CDD8380E22DA3B0D003E9909 /* Binding.swift in Sources */, + CD6DE54E22DF886F00532D08 /* ScopedInstanceMaker.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -405,11 +417,13 @@ CDADF34022DB883A00C5D8DB /* GeneratedMocks.swift in Sources */, CDD8380A22DA31D9003E9909 /* TypeBinderSpec.swift in Sources */, CD85AF1222DA5A8F00A8B7CA /* NonGeneratedMocks.swift in Sources */, + CD6DE55222DF93A000532D08 /* BinderEnvironment.swift in Sources */, CD6DE53D22DD30A100532D08 /* SimpleInstanceMakerSpec.swift in Sources */, CDD8380322DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift in Sources */, CD6DE53522DD1C7300532D08 /* BindingKeySpec.swift in Sources */, CDADF33722DB753800C5D8DB /* TestModels.swift in Sources */, 77729C9E22DCCA20005C3281 /* InjectionApiSpec.swift in Sources */, + CD6DE55022DF8B2700532D08 /* ScopedInstanceMakerSpec.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; From decb7453c3efd12168f477a63f53b83ea02e7004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Wed, 17 Jul 2019 20:59:32 +0200 Subject: [PATCH 062/239] Implement scoped instance maker with explicit scope --- Sources/BinderEnvironment.swift | 12 +- Sources/Scope.swift | 12 +- Sources/ScopedInstanceMaker.swift | 56 ++++++++ Sources/SimpleInstanceMaker.swift | 2 +- Swinject.xcodeproj/project.pbxproj | 2 - Tests/Support/GeneratedMocks.swift | 67 ++++++++++ Tests/Support/NonGeneratedMocks.swift | 20 +++ Tests/UnitSpecs/ScopedInstanceMakerSpec.swift | 124 ++++++++++++++++++ Tests/UnitSpecs/SimpleInstanceMakerSpec.swift | 8 +- 9 files changed, 288 insertions(+), 15 deletions(-) create mode 100644 Sources/ScopedInstanceMaker.swift create mode 100644 Tests/UnitSpecs/ScopedInstanceMakerSpec.swift diff --git a/Sources/BinderEnvironment.swift b/Sources/BinderEnvironment.swift index dff2d251..21bb4f72 100644 --- a/Sources/BinderEnvironment.swift +++ b/Sources/BinderEnvironment.swift @@ -2,8 +2,14 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -public struct BinderEnvironment {} +public struct BinderEnvironment { + let scope: AScope +} + +public func contexted(_: Context.Type = Context.self) -> BinderEnvironment { + BinderEnvironment(scope: ()) +} -public func contexted(_: Context.Type = Context.self) -> BinderEnvironment { - BinderEnvironment() +public func scoped(_ scope: AScope) -> BinderEnvironment where AScope: Scope { + BinderEnvironment(scope: scope) } diff --git a/Sources/Scope.swift b/Sources/Scope.swift index 0a8d5eb8..6405c0d1 100644 --- a/Sources/Scope.swift +++ b/Sources/Scope.swift @@ -2,17 +2,19 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // +// sourcery: AutoMockable public protocol Scope { associatedtype Context - static var lock: Lock { get } - static func registry(for context: Context) -> ScopeRegistry + var lock: Lock { get } + func registry(for context: Context) -> ScopeRegistry } public protocol Lock {} public protocol ScopeRegistry { - // FXIME: name `AnyBindingKey` seems out of context here - func register(_ instance: Type, for key: AnyBindingKey) where Type: AnyObject - func instance(for key: AnyBindingKey) -> Type? where Type: AnyObject + func register(_ instance: Type, for key: ScopeRegistryKey) + func instance(for key: ScopeRegistryKey) -> Type? } + +public struct ScopeRegistryKey {} diff --git a/Sources/ScopedInstanceMaker.swift b/Sources/ScopedInstanceMaker.swift new file mode 100644 index 00000000..756cb8c3 --- /dev/null +++ b/Sources/ScopedInstanceMaker.swift @@ -0,0 +1,56 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +// FIXME: AScope is suboptimal name for a parameter +// Can we rename Scope -> ScopeProtocol? +public struct ScopedInstanceMaker: InstanceMaker where AScope: Scope { + public typealias MadeType = Type + public typealias Context = AScope.Context + + let scope: AScope + private let builder: (Resolver, Context, Argument) throws -> Type + + init(_ scope: AScope, _ builder: @escaping (Resolver, Context, Argument) throws -> Type) { + self.scope = scope + self.builder = builder + } + + public func makeInstance(arg: Argument, context: Context, resolver: Resolver) throws -> Type { + try builder(resolver, context, arg) + } +} + +public extension BinderEnvironment where AScope: Scope, Context == AScope.Context { + func singleton(_ builder: @escaping () throws -> Type) -> ScopedInstanceMaker { + .init(scope) { _, _, _ in try builder() } + } + + func singleton(_ builder: @escaping (Resolver) throws -> Type) -> ScopedInstanceMaker { + .init(scope) { r, _, _ in try builder(r) } + } + + func singleton(_ builder: @escaping (Resolver, Context) throws -> Type) -> ScopedInstanceMaker { + .init(scope) { r, c, _ in try builder(r, c) } + } + + func multiton(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> ScopedInstanceMaker { + .init(scope, builder) + } + + func multiton(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> ScopedInstanceMaker { + .init(scope) { try builder($0, $1, $2.0, $2.1) } + } + + func multiton(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> ScopedInstanceMaker { + .init(scope) { try builder($0, $1, $2.0, $2.1, $2.2) } + } + + func multiton(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> ScopedInstanceMaker { + .init(scope) { try builder($0, $1, $2.0, $2.1, $2.2, $2.3) } + } + + func multiton(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> ScopedInstanceMaker { + .init(scope) { try builder($0, $1, $2.0, $2.1, $2.2, $2.3, $2.4) } + } +} diff --git a/Sources/SimpleInstanceMaker.swift b/Sources/SimpleInstanceMaker.swift index 1d6faa12..322e82e5 100644 --- a/Sources/SimpleInstanceMaker.swift +++ b/Sources/SimpleInstanceMaker.swift @@ -16,7 +16,7 @@ public struct SimpleInstanceMaker: InstanceMaker { } } -public extension BinderEnvironment { +public extension BinderEnvironment where AScope == Void { func provider(_ builder: @escaping (Resolver, Context) throws -> Type) -> SimpleInstanceMaker { .init { r, c, _ in try builder(r, c) } } diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 2b852058..a35eeea8 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -23,7 +23,6 @@ CD6DE54C22DF85AF00532D08 /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE54B22DF85AF00532D08 /* Scope.swift */; }; CD6DE54E22DF886F00532D08 /* ScopedInstanceMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE54D22DF886F00532D08 /* ScopedInstanceMaker.swift */; }; CD6DE55022DF8B2700532D08 /* ScopedInstanceMakerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE54F22DF8B2700532D08 /* ScopedInstanceMakerSpec.swift */; }; - CD6DE55222DF93A000532D08 /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE55122DF93A000532D08 /* BinderEnvironment.swift */; }; CD6DE55322DF94ED00532D08 /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE55122DF93A000532D08 /* BinderEnvironment.swift */; }; CD85AF1222DA5A8F00A8B7CA /* NonGeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF1122DA5A8F00A8B7CA /* NonGeneratedMocks.swift */; }; CDADF32122DB38C600C5D8DB /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDADF32022DB38C600C5D8DB /* SwinjectTree.swift */; }; @@ -417,7 +416,6 @@ CDADF34022DB883A00C5D8DB /* GeneratedMocks.swift in Sources */, CDD8380A22DA31D9003E9909 /* TypeBinderSpec.swift in Sources */, CD85AF1222DA5A8F00A8B7CA /* NonGeneratedMocks.swift in Sources */, - CD6DE55222DF93A000532D08 /* BinderEnvironment.swift in Sources */, CD6DE53D22DD30A100532D08 /* SimpleInstanceMakerSpec.swift in Sources */, CDD8380322DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift in Sources */, CD6DE53522DD1C7300532D08 /* BindingKeySpec.swift in Sources */, diff --git a/Tests/Support/GeneratedMocks.swift b/Tests/Support/GeneratedMocks.swift index 0121b45e..a40840ae 100644 --- a/Tests/Support/GeneratedMocks.swift +++ b/Tests/Support/GeneratedMocks.swift @@ -97,6 +97,45 @@ class AnyResolverMock: AnyResolver { } } +class AnyScopeRegistryMock: AnyScopeRegistry { + // MARK: - register + + var registerForCallsCount = 0 + var registerForCalled: Bool { + return registerForCallsCount > 0 + } + + var registerForReceivedArguments: (instance: Any, key: ScopeRegistryKey)? + var registerForReceivedInvocations: [(instance: Any, key: ScopeRegistryKey)] = [] + var registerForClosure: ((Any, ScopeRegistryKey) -> Void)? + + func register(_ instance: Any, for key: ScopeRegistryKey) { + registerForCallsCount += 1 + registerForReceivedArguments = (instance: instance, key: key) + registerForReceivedInvocations.append((instance: instance, key: key)) + registerForClosure?(instance, key) + } + + // MARK: - instance + + var instanceForCallsCount = 0 + var instanceForCalled: Bool { + return instanceForCallsCount > 0 + } + + var instanceForReceivedKey: ScopeRegistryKey? + var instanceForReceivedInvocations: [ScopeRegistryKey] = [] + var instanceForReturnValue: Any? + var instanceForClosure: ((ScopeRegistryKey) -> Any?)? + + func instance(for key: ScopeRegistryKey) -> Any? { + instanceForCallsCount += 1 + instanceForReceivedKey = key + instanceForReceivedInvocations.append(key) + return instanceForClosure.map { $0(key) } ?? instanceForReturnValue + } +} + class AnyTypeDescriptorMock: AnyTypeDescriptor { // MARK: - matches @@ -163,3 +202,31 @@ class BindingMock: Binding { } class ModuleIncludeEntryMock: ModuleIncludeEntry {} + +class ScopeMock: Scope { + var lock: Lock { + get { return underlyingLock } + set(value) { underlyingLock = value } + } + + var underlyingLock: Lock! + + // MARK: - registry + + var registryForCallsCount = 0 + var registryForCalled: Bool { + return registryForCallsCount > 0 + } + + var registryForReceivedContext: Context? + var registryForReceivedInvocations: [Context] = [] + var registryForReturnValue: ScopeRegistry! + var registryForClosure: ((Context) -> ScopeRegistry)? + + func registry(for context: Context) -> ScopeRegistry { + registryForCallsCount += 1 + registryForReceivedContext = context + registryForReceivedInvocations.append(context) + return registryForClosure.map { $0(context) } ?? registryForReturnValue + } +} diff --git a/Tests/Support/NonGeneratedMocks.swift b/Tests/Support/NonGeneratedMocks.swift index de14988b..9c8ec845 100644 --- a/Tests/Support/NonGeneratedMocks.swift +++ b/Tests/Support/NonGeneratedMocks.swift @@ -34,3 +34,23 @@ extension AnyResolverMock: Resolver { try resolve(request as Any) as! Descriptor.BaseType } } + +extension ScopeMock { + typealias Context = Any +} + +// sourcery: AutoMockable +protocol AnyScopeRegistry { + func register(_ instance: Any, for key: ScopeRegistryKey) + func instance(for key: ScopeRegistryKey) -> Any? +} + +extension AnyScopeRegistryMock: ScopeRegistry { + func register(_ instance: Type, for key: ScopeRegistryKey) { + register(instance as Any, for: key) + } + + func instance(for key: ScopeRegistryKey) -> Type? { + (instance(for: key) as Any?) as? Type + } +} diff --git a/Tests/UnitSpecs/ScopedInstanceMakerSpec.swift b/Tests/UnitSpecs/ScopedInstanceMakerSpec.swift new file mode 100644 index 00000000..eed0199d --- /dev/null +++ b/Tests/UnitSpecs/ScopedInstanceMakerSpec.swift @@ -0,0 +1,124 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +import Nimble +import Quick +@testable import Swinject + +// TODO: Reuse code between scoped / simple instance maker + +class ScopedInstanceMakerSpec: QuickSpec { override func spec() { + describe("explicit scope") { + var scope = ScopeMock() + var environment: BinderEnvironment! + beforeEach { + scope = ScopeMock() + environment = scoped(scope) + } + describe("singleton") { + it("has correct scope") { + let maker = environment.singleton { 42 } + expect(maker.scope) === scope + } + it("returns instance made by builder") { + let maker = environment.singleton { 42 } + expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 + } + it("does not call builder until instance is requested") { + var called = false + _ = environment.singleton { called = true } + expect(called).to(beFalse()) + } + it("calls builder with given resolver") { + var passedResolver: Resolver? + let resolver = DummyResolver() + let maker = environment.singleton { passedResolver = $0 } + _ = try? maker.makeInstance(resolver: resolver) + expect(passedResolver) === resolver + } + it("calls builder with given context") { + var passedContext: Any? + let maker = environment.singleton { _, c in passedContext = c } + _ = try? maker.makeInstance(context: "context", resolver: DummyResolver()) + expect(passedContext as? String) == "context" + } + it("rethrows error from builder") { + let maker = environment.singleton { throw SwinjectError() } + expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) + } + it("does not reuse instance") { + let maker = environment.singleton { _, _ in Person() } + let instance1 = try? maker.makeInstance(resolver: DummyResolver()) + let instance2 = try? maker.makeInstance(resolver: DummyResolver()) + expect(instance1) !== instance2 + } + } + describe("multiton") { + it("has correct scope") { + let maker = environment.multiton { (_, _, _: Void) in 42 } + expect(maker.scope) === scope + } + it("returns instance made by builder method") { + let maker = environment.multiton { (_, _, _: Void) in 42 } + expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 + } + it("does not call builder until instance is requested") { + var called = false + _ = environment.multiton { (_, _, _: Void) in called = true } + expect(called).to(beFalse()) + } + it("calls builder with given resolver") { + var passedResolver: Resolver? + let resolver = DummyResolver() + let maker = environment.multiton { (r, _, _: Void) in passedResolver = r } + _ = try? maker.makeInstance(resolver: resolver) + expect(passedResolver) === resolver + } + it("calls builder with given context") { + var passedContext: Any? + let maker = environment.multiton { (_, c, _: Void) in passedContext = c } + _ = try? maker.makeInstance(context: "context", resolver: DummyResolver()) + expect(passedContext as? String) == "context" + } + it("calls builder with given argument") { + var passedArgument: Int? + let maker = environment.multiton { (_, _, arg: Int) in passedArgument = arg } + _ = try? maker.makeInstance(arg: 42, resolver: DummyResolver()) + expect(passedArgument) == 42 + } + it("rethrows error from builder") { + let maker = environment.multiton { (_, _, _: Void) in throw SwinjectError() } + expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) + } + it("does not reuse instance") { + let maker = environment.multiton { (_, _, _: Void) in Person() } + let instance1 = try? maker.makeInstance(resolver: DummyResolver()) + let instance2 = try? maker.makeInstance(resolver: DummyResolver()) + expect(instance1) !== instance2 + } + describe("multiple arguments") { + it("works with 2 arguments") { + let maker = environment.multiton { (_, _, _: Int, _: Double) in 42 } + let arguments = (1, 1.0) + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + } + it("works with 3 arguments") { + let maker = environment.multiton { (_, _, _: Int, _: Double, _: String) in 42 } + let arguments = (1, 1.0, "") + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + } + it("works with 4 arguments") { + let maker = environment.multiton { (_, _, _: Int, _: Double, _: String, _: Float) in 42 } + let arguments = (1, 1.0, "", Float(1.0)) + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + } + it("works with 5 arguments") { + let maker = environment.multiton { (_, _, _: Int, _: Double, _: String, _: Float, _: Int) in 42 } + let arguments = (1, 1.0, "", Float(1.0), 5) + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + } + } + } + } +} } diff --git a/Tests/UnitSpecs/SimpleInstanceMakerSpec.swift b/Tests/UnitSpecs/SimpleInstanceMakerSpec.swift index 70801cf9..04058b74 100644 --- a/Tests/UnitSpecs/SimpleInstanceMakerSpec.swift +++ b/Tests/UnitSpecs/SimpleInstanceMakerSpec.swift @@ -33,7 +33,7 @@ class SimpleInstanceMakerSpec: QuickSpec { override func spec() { _ = provider { called = true } expect(called).to(beFalse()) } - it("calls builder with given provider") { + it("calls builder with given resolver") { var passedResolver: Resolver? let resolver = DummyResolver() let maker = provider { passedResolver = $0 } @@ -61,7 +61,7 @@ class SimpleInstanceMakerSpec: QuickSpec { override func spec() { _ = provider { called = true } expect(called).to(beFalse()) } - it("calls builder with given provider") { + it("calls builder with given resolver") { var passedResolver: Resolver? let resolver = DummyResolver() let maker = contexted(Any.self).provider { r, _ in passedResolver = r } @@ -101,7 +101,7 @@ class SimpleInstanceMakerSpec: QuickSpec { override func spec() { _ = factory { (_, _: Void) in called = true } expect(called).to(beFalse()) } - it("calls builder with given provider") { + it("calls builder with given resolver") { var passedResolver: Resolver? let resolver = DummyResolver() let maker = factory { (r, _: Void) in passedResolver = r } @@ -157,7 +157,7 @@ class SimpleInstanceMakerSpec: QuickSpec { override func spec() { _ = contexted(Any.self).factory { (_, _, _: Void) in called = true } expect(called).to(beFalse()) } - it("calls builder with given provider") { + it("calls builder with given resolver") { var passedResolver: Resolver? let resolver = DummyResolver() let maker = contexted(Any.self).factory { (r, _, _: Void) in passedResolver = r } From 6a85c41577e23ac84a8bf0760440ac28e6e8b1fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Wed, 17 Jul 2019 21:38:12 +0200 Subject: [PATCH 063/239] Implement scoped instance maker on implicit scope --- Sources/Scope.swift | 14 +++ Sources/ScopedInstanceMaker.swift | 28 ++++++ Tests/UnitSpecs/ScopedInstanceMakerSpec.swift | 94 +++++++++++++++++++ 3 files changed, 136 insertions(+) diff --git a/Sources/Scope.swift b/Sources/Scope.swift index 6405c0d1..0fbb6619 100644 --- a/Sources/Scope.swift +++ b/Sources/Scope.swift @@ -18,3 +18,17 @@ public protocol ScopeRegistry { } public struct ScopeRegistryKey {} + +public class ImplicitScope: Scope { + public typealias Context = Any + + public var lock: Lock { fatalError() } + + public func registry(for _: Any) -> ScopeRegistry { + fatalError() + } +} + +extension ImplicitScope { + static let implicit = ImplicitScope() +} diff --git a/Sources/ScopedInstanceMaker.swift b/Sources/ScopedInstanceMaker.swift index 756cb8c3..1fc91448 100644 --- a/Sources/ScopedInstanceMaker.swift +++ b/Sources/ScopedInstanceMaker.swift @@ -54,3 +54,31 @@ public extension BinderEnvironment where AScope: Scope, Context == AScope.Contex .init(scope) { try builder($0, $1, $2.0, $2.1, $2.2, $2.3, $2.4) } } } + +public func singleton(_ builder: @escaping () throws -> Type) -> ScopedInstanceMaker { + .init(.implicit) { _, _, _ in try builder() } +} + +public func singleton(_ builder: @escaping (Resolver) throws -> Type) -> ScopedInstanceMaker { + .init(.implicit) { r, _, _ in try builder(r) } +} + +public func multiton(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> ScopedInstanceMaker { + .init(.implicit) { try builder($0, $2) } +} + +public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> ScopedInstanceMaker { + .init(.implicit) { try builder($0, $2.0, $2.1) } +} + +public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> ScopedInstanceMaker { + .init(.implicit) { try builder($0, $2.0, $2.1, $2.2) } +} + +public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> ScopedInstanceMaker { + .init(.implicit) { try builder($0, $2.0, $2.1, $2.2, $2.3) } +} + +public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> ScopedInstanceMaker { + .init(.implicit) { try builder($0, $2.0, $2.1, $2.2, $2.3, $2.4) } +} diff --git a/Tests/UnitSpecs/ScopedInstanceMakerSpec.swift b/Tests/UnitSpecs/ScopedInstanceMakerSpec.swift index eed0199d..1dbfb8ea 100644 --- a/Tests/UnitSpecs/ScopedInstanceMakerSpec.swift +++ b/Tests/UnitSpecs/ScopedInstanceMakerSpec.swift @@ -121,4 +121,98 @@ class ScopedInstanceMakerSpec: QuickSpec { override func spec() { } } } + describe("implicit scope") { + describe("singleton") { + it("has correct scope") { + let maker = singleton { 42 } + expect(maker.scope) === ImplicitScope.implicit + } + it("returns instance made by builder") { + let maker = singleton { 42 } + expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 + } + it("does not call builder until instance is requested") { + var called = false + _ = singleton { called = true } + expect(called).to(beFalse()) + } + it("calls builder with given resolver") { + var passedResolver: Resolver? + let resolver = DummyResolver() + let maker = singleton { passedResolver = $0 } + _ = try? maker.makeInstance(resolver: resolver) + expect(passedResolver) === resolver + } + it("rethrows error from builder") { + let maker = singleton { throw SwinjectError() } + expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) + } + it("does not reuse instance") { + let maker = singleton { Person() } + let instance1 = try? maker.makeInstance(resolver: DummyResolver()) + let instance2 = try? maker.makeInstance(resolver: DummyResolver()) + expect(instance1) !== instance2 + } + } + describe("multiton") { + it("has correct scope") { + let maker = multiton { (_, _: Void) in 42 } + expect(maker.scope) === ImplicitScope.implicit + } + it("returns instance made by builder method") { + let maker = multiton { (_, _: Void) in 42 } + expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 + } + it("does not call builder until instance is requested") { + var called = false + _ = multiton { (_, _: Void) in called = true } + expect(called).to(beFalse()) + } + it("calls builder with given resolver") { + var passedResolver: Resolver? + let resolver = DummyResolver() + let maker = multiton { (r, _: Void) in passedResolver = r } + _ = try? maker.makeInstance(resolver: resolver) + expect(passedResolver) === resolver + } + it("calls builder with given argument") { + var passedArgument: Int? + let maker = multiton { (_, arg: Int) in passedArgument = arg } + _ = try? maker.makeInstance(arg: 42, resolver: DummyResolver()) + expect(passedArgument) == 42 + } + it("rethrows error from builder") { + let maker = multiton { (_, _: Void) in throw SwinjectError() } + expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) + } + it("does not reuse instance") { + let maker = multiton { (_, _: Void) in Person() } + let instance1 = try? maker.makeInstance(resolver: DummyResolver()) + let instance2 = try? maker.makeInstance(resolver: DummyResolver()) + expect(instance1) !== instance2 + } + describe("multiple arguments") { + it("works with 2 arguments") { + let maker = multiton { (_, _: Int, _: Double) in 42 } + let arguments = (1, 1.0) + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + } + it("works with 3 arguments") { + let maker = multiton { (_, _: Int, _: Double, _: String) in 42 } + let arguments = (1, 1.0, "") + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + } + it("works with 4 arguments") { + let maker = multiton { (_, _: Int, _: Double, _: String, _: Float) in 42 } + let arguments = (1, 1.0, "", Float(1.0)) + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + } + it("works with 5 arguments") { + let maker = multiton { (_, _: Int, _: Double, _: String, _: Float, _: Int) in 42 } + let arguments = (1, 1.0, "", Float(1.0), 5) + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + } + } + } + } } } From 1859dbf28edb8ec728ab3ecbbb0a7010ee94b2cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Wed, 17 Jul 2019 21:56:50 +0200 Subject: [PATCH 064/239] Reorganize code --- Sources/BinderEnvironment.swift | 120 +++++ Sources/ScopedInstanceMaker.swift | 62 --- Sources/SimpleInstanceMaker.swift | 58 --- Swinject.xcodeproj/project.pbxproj | 4 + Tests/UnitSpecs/BinderEnvironmentSpec.swift | 421 ++++++++++++++++++ Tests/UnitSpecs/ScopedInstanceMakerSpec.swift | 209 +-------- Tests/UnitSpecs/SimpleInstanceMakerSpec.swift | 204 +-------- 7 files changed, 547 insertions(+), 531 deletions(-) create mode 100644 Tests/UnitSpecs/BinderEnvironmentSpec.swift diff --git a/Sources/BinderEnvironment.swift b/Sources/BinderEnvironment.swift index 21bb4f72..a36fab19 100644 --- a/Sources/BinderEnvironment.swift +++ b/Sources/BinderEnvironment.swift @@ -13,3 +13,123 @@ public func contexted(_: Context.Type = Context.self) -> BinderEnvironm public func scoped(_ scope: AScope) -> BinderEnvironment where AScope: Scope { BinderEnvironment(scope: scope) } + +public extension BinderEnvironment where AScope == Void { + func provider(_ builder: @escaping (Resolver, Context) throws -> Type) -> SimpleInstanceMaker { + .init { r, c, _ in try builder(r, c) } + } + + func factory(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SimpleInstanceMaker { + .init(builder) + } + + func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SimpleInstanceMaker { + .init { try builder($0, $1, $2.0, $2.1) } + } + + func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SimpleInstanceMaker { + .init { try builder($0, $1, $2.0, $2.1, $2.2) } + } + + func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SimpleInstanceMaker { + .init { try builder($0, $1, $2.0, $2.1, $2.2, $2.3) } + } + + func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SimpleInstanceMaker { + .init { try builder($0, $1, $2.0, $2.1, $2.2, $2.3, $2.4) } + } +} + +public extension BinderEnvironment where AScope: Scope, Context == AScope.Context { + func singleton(_ builder: @escaping () throws -> Type) -> ScopedInstanceMaker { + .init(scope) { _, _, _ in try builder() } + } + + func singleton(_ builder: @escaping (Resolver) throws -> Type) -> ScopedInstanceMaker { + .init(scope) { r, _, _ in try builder(r) } + } + + func singleton(_ builder: @escaping (Resolver, Context) throws -> Type) -> ScopedInstanceMaker { + .init(scope) { r, c, _ in try builder(r, c) } + } + + func multiton(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> ScopedInstanceMaker { + .init(scope, builder) + } + + func multiton(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> ScopedInstanceMaker { + .init(scope) { try builder($0, $1, $2.0, $2.1) } + } + + func multiton(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> ScopedInstanceMaker { + .init(scope) { try builder($0, $1, $2.0, $2.1, $2.2) } + } + + func multiton(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> ScopedInstanceMaker { + .init(scope) { try builder($0, $1, $2.0, $2.1, $2.2, $2.3) } + } + + func multiton(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> ScopedInstanceMaker { + .init(scope) { try builder($0, $1, $2.0, $2.1, $2.2, $2.3, $2.4) } + } +} + +public func instance(_ instance: Type) -> SimpleInstanceMaker { + .init { _, _, _ in instance } +} + +public func provider(_ builder: @escaping () throws -> Type) -> SimpleInstanceMaker { + .init { _, _, _ in try builder() } +} + +public func provider(_ builder: @escaping (Resolver) throws -> Type) -> SimpleInstanceMaker { + .init { r, _, _ in try builder(r) } +} + +public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> SimpleInstanceMaker { + .init { try builder($0, $2) } +} + +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SimpleInstanceMaker { + .init { try builder($0, $2.0, $2.1) } +} + +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SimpleInstanceMaker { + .init { try builder($0, $2.0, $2.1, $2.2) } +} + +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SimpleInstanceMaker { + SimpleInstanceMaker { try builder($0, $2.0, $2.1, $2.2, $2.3) } +} + +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SimpleInstanceMaker { + SimpleInstanceMaker { try builder($0, $2.0, $2.1, $2.2, $2.3, $2.4) } +} + +public func singleton(_ builder: @escaping () throws -> Type) -> ScopedInstanceMaker { + .init(.implicit) { _, _, _ in try builder() } +} + +public func singleton(_ builder: @escaping (Resolver) throws -> Type) -> ScopedInstanceMaker { + .init(.implicit) { r, _, _ in try builder(r) } +} + +public func multiton(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> ScopedInstanceMaker { + .init(.implicit) { try builder($0, $2) } +} + +public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> ScopedInstanceMaker { + .init(.implicit) { try builder($0, $2.0, $2.1) } +} + +public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> ScopedInstanceMaker { + .init(.implicit) { try builder($0, $2.0, $2.1, $2.2) } +} + +public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> ScopedInstanceMaker { + .init(.implicit) { try builder($0, $2.0, $2.1, $2.2, $2.3) } +} + +public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> ScopedInstanceMaker { + .init(.implicit) { try builder($0, $2.0, $2.1, $2.2, $2.3, $2.4) } +} diff --git a/Sources/ScopedInstanceMaker.swift b/Sources/ScopedInstanceMaker.swift index 1fc91448..5bbd4105 100644 --- a/Sources/ScopedInstanceMaker.swift +++ b/Sources/ScopedInstanceMaker.swift @@ -20,65 +20,3 @@ public struct ScopedInstanceMaker: InstanceMaker where A try builder(resolver, context, arg) } } - -public extension BinderEnvironment where AScope: Scope, Context == AScope.Context { - func singleton(_ builder: @escaping () throws -> Type) -> ScopedInstanceMaker { - .init(scope) { _, _, _ in try builder() } - } - - func singleton(_ builder: @escaping (Resolver) throws -> Type) -> ScopedInstanceMaker { - .init(scope) { r, _, _ in try builder(r) } - } - - func singleton(_ builder: @escaping (Resolver, Context) throws -> Type) -> ScopedInstanceMaker { - .init(scope) { r, c, _ in try builder(r, c) } - } - - func multiton(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> ScopedInstanceMaker { - .init(scope, builder) - } - - func multiton(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> ScopedInstanceMaker { - .init(scope) { try builder($0, $1, $2.0, $2.1) } - } - - func multiton(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> ScopedInstanceMaker { - .init(scope) { try builder($0, $1, $2.0, $2.1, $2.2) } - } - - func multiton(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> ScopedInstanceMaker { - .init(scope) { try builder($0, $1, $2.0, $2.1, $2.2, $2.3) } - } - - func multiton(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> ScopedInstanceMaker { - .init(scope) { try builder($0, $1, $2.0, $2.1, $2.2, $2.3, $2.4) } - } -} - -public func singleton(_ builder: @escaping () throws -> Type) -> ScopedInstanceMaker { - .init(.implicit) { _, _, _ in try builder() } -} - -public func singleton(_ builder: @escaping (Resolver) throws -> Type) -> ScopedInstanceMaker { - .init(.implicit) { r, _, _ in try builder(r) } -} - -public func multiton(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> ScopedInstanceMaker { - .init(.implicit) { try builder($0, $2) } -} - -public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> ScopedInstanceMaker { - .init(.implicit) { try builder($0, $2.0, $2.1) } -} - -public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> ScopedInstanceMaker { - .init(.implicit) { try builder($0, $2.0, $2.1, $2.2) } -} - -public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> ScopedInstanceMaker { - .init(.implicit) { try builder($0, $2.0, $2.1, $2.2, $2.3) } -} - -public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> ScopedInstanceMaker { - .init(.implicit) { try builder($0, $2.0, $2.1, $2.2, $2.3, $2.4) } -} diff --git a/Sources/SimpleInstanceMaker.swift b/Sources/SimpleInstanceMaker.swift index 322e82e5..8b1d1531 100644 --- a/Sources/SimpleInstanceMaker.swift +++ b/Sources/SimpleInstanceMaker.swift @@ -15,61 +15,3 @@ public struct SimpleInstanceMaker: InstanceMaker { try builder(resolver, context, arg) } } - -public extension BinderEnvironment where AScope == Void { - func provider(_ builder: @escaping (Resolver, Context) throws -> Type) -> SimpleInstanceMaker { - .init { r, c, _ in try builder(r, c) } - } - - func factory(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SimpleInstanceMaker { - .init(builder) - } - - func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SimpleInstanceMaker { - .init { try builder($0, $1, $2.0, $2.1) } - } - - func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SimpleInstanceMaker { - .init { try builder($0, $1, $2.0, $2.1, $2.2) } - } - - func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SimpleInstanceMaker { - .init { try builder($0, $1, $2.0, $2.1, $2.2, $2.3) } - } - - func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SimpleInstanceMaker { - .init { try builder($0, $1, $2.0, $2.1, $2.2, $2.3, $2.4) } - } -} - -public func instance(_ instance: Type) -> SimpleInstanceMaker { - .init { _, _, _ in instance } -} - -public func provider(_ builder: @escaping () throws -> Type) -> SimpleInstanceMaker { - .init { _, _, _ in try builder() } -} - -public func provider(_ builder: @escaping (Resolver) throws -> Type) -> SimpleInstanceMaker { - .init { r, _, _ in try builder(r) } -} - -public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> SimpleInstanceMaker { - .init { try builder($0, $2) } -} - -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SimpleInstanceMaker { - .init { try builder($0, $2.0, $2.1) } -} - -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SimpleInstanceMaker { - .init { try builder($0, $2.0, $2.1, $2.2) } -} - -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SimpleInstanceMaker { - SimpleInstanceMaker { try builder($0, $2.0, $2.1, $2.2, $2.3) } -} - -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SimpleInstanceMaker { - SimpleInstanceMaker { try builder($0, $2.0, $2.1, $2.2, $2.3, $2.4) } -} diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index a35eeea8..af00ded6 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -24,6 +24,7 @@ CD6DE54E22DF886F00532D08 /* ScopedInstanceMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE54D22DF886F00532D08 /* ScopedInstanceMaker.swift */; }; CD6DE55022DF8B2700532D08 /* ScopedInstanceMakerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE54F22DF8B2700532D08 /* ScopedInstanceMakerSpec.swift */; }; CD6DE55322DF94ED00532D08 /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE55122DF93A000532D08 /* BinderEnvironment.swift */; }; + CD6DE55522DFB2A600532D08 /* BinderEnvironmentSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE55422DFB2A600532D08 /* BinderEnvironmentSpec.swift */; }; CD85AF1222DA5A8F00A8B7CA /* NonGeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF1122DA5A8F00A8B7CA /* NonGeneratedMocks.swift */; }; CDADF32122DB38C600C5D8DB /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDADF32022DB38C600C5D8DB /* SwinjectTree.swift */; }; CDADF33522DB521400C5D8DB /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDADF33422DB521400C5D8DB /* SwinjectModule.swift */; }; @@ -75,6 +76,7 @@ CD6DE54D22DF886F00532D08 /* ScopedInstanceMaker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopedInstanceMaker.swift; sourceTree = ""; }; CD6DE54F22DF8B2700532D08 /* ScopedInstanceMakerSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopedInstanceMakerSpec.swift; sourceTree = ""; }; CD6DE55122DF93A000532D08 /* BinderEnvironment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderEnvironment.swift; sourceTree = ""; }; + CD6DE55422DFB2A600532D08 /* BinderEnvironmentSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderEnvironmentSpec.swift; sourceTree = ""; }; CD85AF1122DA5A8F00A8B7CA /* NonGeneratedMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonGeneratedMocks.swift; sourceTree = ""; }; CDADF32022DB38C600C5D8DB /* SwinjectTree.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTree.swift; sourceTree = ""; }; CDADF33422DB521400C5D8DB /* SwinjectModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectModule.swift; sourceTree = ""; }; @@ -204,6 +206,7 @@ CD6DE53322DD1C6800532D08 /* BindingKeySpec.swift */, CD6DE54622DED16400532D08 /* ContextedResolverSpec.swift */, CD6DE54F22DF8B2700532D08 /* ScopedInstanceMakerSpec.swift */, + CD6DE55422DFB2A600532D08 /* BinderEnvironmentSpec.swift */, ); path = UnitSpecs; sourceTree = ""; @@ -419,6 +422,7 @@ CD6DE53D22DD30A100532D08 /* SimpleInstanceMakerSpec.swift in Sources */, CDD8380322DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift in Sources */, CD6DE53522DD1C7300532D08 /* BindingKeySpec.swift in Sources */, + CD6DE55522DFB2A600532D08 /* BinderEnvironmentSpec.swift in Sources */, CDADF33722DB753800C5D8DB /* TestModels.swift in Sources */, 77729C9E22DCCA20005C3281 /* InjectionApiSpec.swift in Sources */, CD6DE55022DF8B2700532D08 /* ScopedInstanceMakerSpec.swift in Sources */, diff --git a/Tests/UnitSpecs/BinderEnvironmentSpec.swift b/Tests/UnitSpecs/BinderEnvironmentSpec.swift new file mode 100644 index 00000000..eaea4cf1 --- /dev/null +++ b/Tests/UnitSpecs/BinderEnvironmentSpec.swift @@ -0,0 +1,421 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +import Nimble +import Quick +@testable import Swinject + +// TODO: Reuse code +class BinderEnvironmentSpec: QuickSpec { override func spec() { + describe("implicit") { + describe("instance") { + it("produces maker with correct type signature") { + let maker = instance(42) as Any + expect(maker is SimpleInstanceMaker).to(beTrue()) + } + it("returns given instance") { + let maker = instance(42) + expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 + } + } + describe("provider") { + it("produces maker with correct type signature") { + let maker = provider { 42 } as Any + expect(maker is SimpleInstanceMaker).to(beTrue()) + } + it("returns instance made by provider method") { + let maker = provider { 42 } + expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 + } + it("does not call builder until instance is requested") { + var called = false + _ = provider { called = true } + expect(called).to(beFalse()) + } + it("calls builder with given resolver") { + var passedResolver: Resolver? + let resolver = DummyResolver() + let maker = provider { passedResolver = $0 } + _ = try? maker.makeInstance(resolver: resolver) + expect(passedResolver) === resolver + } + it("rethrows error from builder") { + let maker = provider { throw SwinjectError() } + expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) + } + it("does not reuse instance") { + let maker = provider { Person() } + let instance1 = try? maker.makeInstance(resolver: DummyResolver()) + let instance2 = try? maker.makeInstance(resolver: DummyResolver()) + expect(instance1) !== instance2 + } + } + describe("factory") { + it("produces maker with correct type signature") { + let maker = factory { (_, _: Void) in 42 } as Any + expect(maker is SimpleInstanceMaker).to(beTrue()) + } + it("returns instance made by builder method") { + let maker = factory { (_, _: Void) in 42 } + expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 + } + it("does not call builder until instance is requested") { + var called = false + _ = factory { (_, _: Void) in called = true } + expect(called).to(beFalse()) + } + it("calls builder with given resolver") { + var passedResolver: Resolver? + let resolver = DummyResolver() + let maker = factory { (r, _: Void) in passedResolver = r } + _ = try? maker.makeInstance(resolver: resolver) + expect(passedResolver) === resolver + } + it("calls builder with given argument") { + var passedArgument: Int? + let maker = factory { (_, arg: Int) in passedArgument = arg } + _ = try? maker.makeInstance(arg: 42, resolver: DummyResolver()) + expect(passedArgument) == 42 + } + it("rethrows error from builder") { + let maker = factory { (_, _: Void) in throw SwinjectError() } + expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) + } + it("does not reuse instance") { + let maker = factory { (_, _: Void) in Person() } + let instance1 = try? maker.makeInstance(resolver: DummyResolver()) + let instance2 = try? maker.makeInstance(resolver: DummyResolver()) + expect(instance1) !== instance2 + } + describe("multiple arguments") { + it("works with 2 arguments") { + let maker = factory { (_, _: Int, _: Double) in 42 } + let arguments = (1, 1.0) + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + } + it("works with 3 arguments") { + let maker = factory { (_, _: Int, _: Double, _: String) in 42 } + let arguments = (1, 1.0, "") + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + } + it("works with 4 arguments") { + let maker = factory { (_, _: Int, _: Double, _: String, _: Float) in 42 } + let arguments = (1, 1.0, "", Float(1.0)) + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + } + it("works with 5 arguments") { + let maker = factory { (_, _: Int, _: Double, _: String, _: Float, _: Int) in 42 } + let arguments = (1, 1.0, "", Float(1.0), 5) + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + } + } + } + describe("singleton") { + it("has correct scope") { + let maker = singleton { 42 } + expect(maker.scope) === ImplicitScope.implicit + } + it("returns instance made by builder") { + let maker = singleton { 42 } + expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 + } + it("does not call builder until instance is requested") { + var called = false + _ = singleton { called = true } + expect(called).to(beFalse()) + } + it("calls builder with given resolver") { + var passedResolver: Resolver? + let resolver = DummyResolver() + let maker = singleton { passedResolver = $0 } + _ = try? maker.makeInstance(resolver: resolver) + expect(passedResolver) === resolver + } + it("rethrows error from builder") { + let maker = singleton { throw SwinjectError() } + expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) + } + it("does not reuse instance") { + let maker = singleton { Person() } + let instance1 = try? maker.makeInstance(resolver: DummyResolver()) + let instance2 = try? maker.makeInstance(resolver: DummyResolver()) + expect(instance1) !== instance2 + } + } + describe("multiton") { + it("has correct scope") { + let maker = multiton { (_, _: Void) in 42 } + expect(maker.scope) === ImplicitScope.implicit + } + it("returns instance made by builder method") { + let maker = multiton { (_, _: Void) in 42 } + expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 + } + it("does not call builder until instance is requested") { + var called = false + _ = multiton { (_, _: Void) in called = true } + expect(called).to(beFalse()) + } + it("calls builder with given resolver") { + var passedResolver: Resolver? + let resolver = DummyResolver() + let maker = multiton { (r, _: Void) in passedResolver = r } + _ = try? maker.makeInstance(resolver: resolver) + expect(passedResolver) === resolver + } + it("calls builder with given argument") { + var passedArgument: Int? + let maker = multiton { (_, arg: Int) in passedArgument = arg } + _ = try? maker.makeInstance(arg: 42, resolver: DummyResolver()) + expect(passedArgument) == 42 + } + it("rethrows error from builder") { + let maker = multiton { (_, _: Void) in throw SwinjectError() } + expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) + } + it("does not reuse instance") { + let maker = multiton { (_, _: Void) in Person() } + let instance1 = try? maker.makeInstance(resolver: DummyResolver()) + let instance2 = try? maker.makeInstance(resolver: DummyResolver()) + expect(instance1) !== instance2 + } + describe("multiple arguments") { + it("works with 2 arguments") { + let maker = multiton { (_, _: Int, _: Double) in 42 } + let arguments = (1, 1.0) + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + } + it("works with 3 arguments") { + let maker = multiton { (_, _: Int, _: Double, _: String) in 42 } + let arguments = (1, 1.0, "") + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + } + it("works with 4 arguments") { + let maker = multiton { (_, _: Int, _: Double, _: String, _: Float) in 42 } + let arguments = (1, 1.0, "", Float(1.0)) + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + } + it("works with 5 arguments") { + let maker = multiton { (_, _: Int, _: Double, _: String, _: Float, _: Int) in 42 } + let arguments = (1, 1.0, "", Float(1.0), 5) + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + } + } + } + } + describe("contexted") { + var environment: BinderEnvironment! + beforeEach { + environment = contexted(Any.self) + } + describe("provider") { + it("returns instance made by provider method") { + let maker = environment.provider { _, _ in 42 } + expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 + } + it("does not call builder until instance is requested") { + var called = false + _ = provider { called = true } + expect(called).to(beFalse()) + } + it("calls builder with given resolver") { + var passedResolver: Resolver? + let resolver = DummyResolver() + let maker = environment.provider { r, _ in passedResolver = r } + _ = try? maker.makeInstance(resolver: resolver) + expect(passedResolver) === resolver + } + it("calls builder with given context") { + var passedContext: Any? + let maker = environment.provider { _, c in passedContext = c } + _ = try? maker.makeInstance(context: 42, resolver: DummyResolver()) + expect(passedContext as? Int) == 42 + } + it("rethrows error from builder") { + let maker = environment.provider { _, _ in throw SwinjectError() } + expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) + } + it("does not reuse instance") { + let maker = environment.provider { _, _ in Person() } + let instance1 = try? maker.makeInstance(resolver: DummyResolver()) + let instance2 = try? maker.makeInstance(resolver: DummyResolver()) + expect(instance1) !== instance2 + } + } + describe("factory") { + it("returns instance made by builder method") { + let maker = environment.factory { (_, _, _: Void) in 42 } + expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 + } + it("does not call builder until instance is requested") { + var called = false + _ = environment.factory { (_, _, _: Void) in called = true } + expect(called).to(beFalse()) + } + it("calls builder with given resolver") { + var passedResolver: Resolver? + let resolver = DummyResolver() + let maker = environment.factory { (r, _, _: Void) in passedResolver = r } + _ = try? maker.makeInstance(resolver: resolver) + expect(passedResolver) === resolver + } + it("calls builder with given context") { + var passedContext: Any? + let maker = environment.factory { (_, c, _: Void) in passedContext = c } + _ = try? maker.makeInstance(context: 42, resolver: DummyResolver()) + expect(passedContext as? Int) == 42 + } + it("calls builder with given argument") { + var passedArgument: Int? + let maker = environment.factory { (_, _, arg: Int) in passedArgument = arg } + _ = try? maker.makeInstance(arg: 42, resolver: DummyResolver()) + expect(passedArgument) == 42 + } + it("rethrows error from builder") { + let maker = environment.factory { (_, _, _: Void) in throw SwinjectError() } + expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) + } + it("does not reuse instance") { + let maker = environment.factory { (_, _, _: Void) in Person() } + let instance1 = try? maker.makeInstance(resolver: DummyResolver()) + let instance2 = try? maker.makeInstance(resolver: DummyResolver()) + expect(instance1) !== instance2 + } + describe("multiple arguments") { + it("works with 2 arguments") { + let maker = environment.factory { (_, _, _: Int, _: Double) in 42 } + let arguments = (1, 1.0) + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + } + it("works with 3 arguments") { + let maker = environment.factory { (_, _, _: Int, _: Double, _: String) in 42 } + let arguments = (1, 1.0, "") + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + } + it("works with 4 arguments") { + let maker = environment.factory { (_, _, _: Int, _: Double, _: String, _: Float) in 42 } + let arguments = (1, 1.0, "", Float(1.0)) + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + } + it("works with 5 arguments") { + let maker = environment.factory { (_, _, _: Int, _: Double, _: String, _: Float, _: Int) in 42 } + let arguments = (1, 1.0, "", Float(1.0), 5) + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + } + } + } + } + describe("scoped") { + var scope = ScopeMock() + var environment: BinderEnvironment! + beforeEach { + scope = ScopeMock() + environment = scoped(scope) + } + describe("singleton") { + it("has correct scope") { + let maker = environment.singleton { 42 } + expect(maker.scope) === scope + } + it("returns instance made by builder") { + let maker = environment.singleton { 42 } + expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 + } + it("does not call builder until instance is requested") { + var called = false + _ = environment.singleton { called = true } + expect(called).to(beFalse()) + } + it("calls builder with given resolver") { + var passedResolver: Resolver? + let resolver = DummyResolver() + let maker = environment.singleton { passedResolver = $0 } + _ = try? maker.makeInstance(resolver: resolver) + expect(passedResolver) === resolver + } + it("calls builder with given context") { + var passedContext: Any? + let maker = environment.singleton { _, c in passedContext = c } + _ = try? maker.makeInstance(context: "context", resolver: DummyResolver()) + expect(passedContext as? String) == "context" + } + it("rethrows error from builder") { + let maker = environment.singleton { throw SwinjectError() } + expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) + } + it("does not reuse instance") { + let maker = environment.singleton { _, _ in Person() } + let instance1 = try? maker.makeInstance(resolver: DummyResolver()) + let instance2 = try? maker.makeInstance(resolver: DummyResolver()) + expect(instance1) !== instance2 + } + } + describe("multiton") { + it("has correct scope") { + let maker = environment.multiton { (_, _, _: Void) in 42 } + expect(maker.scope) === scope + } + it("returns instance made by builder method") { + let maker = environment.multiton { (_, _, _: Void) in 42 } + expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 + } + it("does not call builder until instance is requested") { + var called = false + _ = environment.multiton { (_, _, _: Void) in called = true } + expect(called).to(beFalse()) + } + it("calls builder with given resolver") { + var passedResolver: Resolver? + let resolver = DummyResolver() + let maker = environment.multiton { (r, _, _: Void) in passedResolver = r } + _ = try? maker.makeInstance(resolver: resolver) + expect(passedResolver) === resolver + } + it("calls builder with given context") { + var passedContext: Any? + let maker = environment.multiton { (_, c, _: Void) in passedContext = c } + _ = try? maker.makeInstance(context: "context", resolver: DummyResolver()) + expect(passedContext as? String) == "context" + } + it("calls builder with given argument") { + var passedArgument: Int? + let maker = environment.multiton { (_, _, arg: Int) in passedArgument = arg } + _ = try? maker.makeInstance(arg: 42, resolver: DummyResolver()) + expect(passedArgument) == 42 + } + it("rethrows error from builder") { + let maker = environment.multiton { (_, _, _: Void) in throw SwinjectError() } + expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) + } + it("does not reuse instance") { + let maker = environment.multiton { (_, _, _: Void) in Person() } + let instance1 = try? maker.makeInstance(resolver: DummyResolver()) + let instance2 = try? maker.makeInstance(resolver: DummyResolver()) + expect(instance1) !== instance2 + } + describe("multiple arguments") { + it("works with 2 arguments") { + let maker = environment.multiton { (_, _, _: Int, _: Double) in 42 } + let arguments = (1, 1.0) + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + } + it("works with 3 arguments") { + let maker = environment.multiton { (_, _, _: Int, _: Double, _: String) in 42 } + let arguments = (1, 1.0, "") + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + } + it("works with 4 arguments") { + let maker = environment.multiton { (_, _, _: Int, _: Double, _: String, _: Float) in 42 } + let arguments = (1, 1.0, "", Float(1.0)) + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + } + it("works with 5 arguments") { + let maker = environment.multiton { (_, _, _: Int, _: Double, _: String, _: Float, _: Int) in 42 } + let arguments = (1, 1.0, "", Float(1.0), 5) + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + } + } + } + } +} } diff --git a/Tests/UnitSpecs/ScopedInstanceMakerSpec.swift b/Tests/UnitSpecs/ScopedInstanceMakerSpec.swift index 1dbfb8ea..a4aaee69 100644 --- a/Tests/UnitSpecs/ScopedInstanceMakerSpec.swift +++ b/Tests/UnitSpecs/ScopedInstanceMakerSpec.swift @@ -6,213 +6,6 @@ import Nimble import Quick @testable import Swinject -// TODO: Reuse code between scoped / simple instance maker - class ScopedInstanceMakerSpec: QuickSpec { override func spec() { - describe("explicit scope") { - var scope = ScopeMock() - var environment: BinderEnvironment! - beforeEach { - scope = ScopeMock() - environment = scoped(scope) - } - describe("singleton") { - it("has correct scope") { - let maker = environment.singleton { 42 } - expect(maker.scope) === scope - } - it("returns instance made by builder") { - let maker = environment.singleton { 42 } - expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 - } - it("does not call builder until instance is requested") { - var called = false - _ = environment.singleton { called = true } - expect(called).to(beFalse()) - } - it("calls builder with given resolver") { - var passedResolver: Resolver? - let resolver = DummyResolver() - let maker = environment.singleton { passedResolver = $0 } - _ = try? maker.makeInstance(resolver: resolver) - expect(passedResolver) === resolver - } - it("calls builder with given context") { - var passedContext: Any? - let maker = environment.singleton { _, c in passedContext = c } - _ = try? maker.makeInstance(context: "context", resolver: DummyResolver()) - expect(passedContext as? String) == "context" - } - it("rethrows error from builder") { - let maker = environment.singleton { throw SwinjectError() } - expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) - } - it("does not reuse instance") { - let maker = environment.singleton { _, _ in Person() } - let instance1 = try? maker.makeInstance(resolver: DummyResolver()) - let instance2 = try? maker.makeInstance(resolver: DummyResolver()) - expect(instance1) !== instance2 - } - } - describe("multiton") { - it("has correct scope") { - let maker = environment.multiton { (_, _, _: Void) in 42 } - expect(maker.scope) === scope - } - it("returns instance made by builder method") { - let maker = environment.multiton { (_, _, _: Void) in 42 } - expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 - } - it("does not call builder until instance is requested") { - var called = false - _ = environment.multiton { (_, _, _: Void) in called = true } - expect(called).to(beFalse()) - } - it("calls builder with given resolver") { - var passedResolver: Resolver? - let resolver = DummyResolver() - let maker = environment.multiton { (r, _, _: Void) in passedResolver = r } - _ = try? maker.makeInstance(resolver: resolver) - expect(passedResolver) === resolver - } - it("calls builder with given context") { - var passedContext: Any? - let maker = environment.multiton { (_, c, _: Void) in passedContext = c } - _ = try? maker.makeInstance(context: "context", resolver: DummyResolver()) - expect(passedContext as? String) == "context" - } - it("calls builder with given argument") { - var passedArgument: Int? - let maker = environment.multiton { (_, _, arg: Int) in passedArgument = arg } - _ = try? maker.makeInstance(arg: 42, resolver: DummyResolver()) - expect(passedArgument) == 42 - } - it("rethrows error from builder") { - let maker = environment.multiton { (_, _, _: Void) in throw SwinjectError() } - expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) - } - it("does not reuse instance") { - let maker = environment.multiton { (_, _, _: Void) in Person() } - let instance1 = try? maker.makeInstance(resolver: DummyResolver()) - let instance2 = try? maker.makeInstance(resolver: DummyResolver()) - expect(instance1) !== instance2 - } - describe("multiple arguments") { - it("works with 2 arguments") { - let maker = environment.multiton { (_, _, _: Int, _: Double) in 42 } - let arguments = (1, 1.0) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 - } - it("works with 3 arguments") { - let maker = environment.multiton { (_, _, _: Int, _: Double, _: String) in 42 } - let arguments = (1, 1.0, "") - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 - } - it("works with 4 arguments") { - let maker = environment.multiton { (_, _, _: Int, _: Double, _: String, _: Float) in 42 } - let arguments = (1, 1.0, "", Float(1.0)) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 - } - it("works with 5 arguments") { - let maker = environment.multiton { (_, _, _: Int, _: Double, _: String, _: Float, _: Int) in 42 } - let arguments = (1, 1.0, "", Float(1.0), 5) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 - } - } - } - } - describe("implicit scope") { - describe("singleton") { - it("has correct scope") { - let maker = singleton { 42 } - expect(maker.scope) === ImplicitScope.implicit - } - it("returns instance made by builder") { - let maker = singleton { 42 } - expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 - } - it("does not call builder until instance is requested") { - var called = false - _ = singleton { called = true } - expect(called).to(beFalse()) - } - it("calls builder with given resolver") { - var passedResolver: Resolver? - let resolver = DummyResolver() - let maker = singleton { passedResolver = $0 } - _ = try? maker.makeInstance(resolver: resolver) - expect(passedResolver) === resolver - } - it("rethrows error from builder") { - let maker = singleton { throw SwinjectError() } - expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) - } - it("does not reuse instance") { - let maker = singleton { Person() } - let instance1 = try? maker.makeInstance(resolver: DummyResolver()) - let instance2 = try? maker.makeInstance(resolver: DummyResolver()) - expect(instance1) !== instance2 - } - } - describe("multiton") { - it("has correct scope") { - let maker = multiton { (_, _: Void) in 42 } - expect(maker.scope) === ImplicitScope.implicit - } - it("returns instance made by builder method") { - let maker = multiton { (_, _: Void) in 42 } - expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 - } - it("does not call builder until instance is requested") { - var called = false - _ = multiton { (_, _: Void) in called = true } - expect(called).to(beFalse()) - } - it("calls builder with given resolver") { - var passedResolver: Resolver? - let resolver = DummyResolver() - let maker = multiton { (r, _: Void) in passedResolver = r } - _ = try? maker.makeInstance(resolver: resolver) - expect(passedResolver) === resolver - } - it("calls builder with given argument") { - var passedArgument: Int? - let maker = multiton { (_, arg: Int) in passedArgument = arg } - _ = try? maker.makeInstance(arg: 42, resolver: DummyResolver()) - expect(passedArgument) == 42 - } - it("rethrows error from builder") { - let maker = multiton { (_, _: Void) in throw SwinjectError() } - expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) - } - it("does not reuse instance") { - let maker = multiton { (_, _: Void) in Person() } - let instance1 = try? maker.makeInstance(resolver: DummyResolver()) - let instance2 = try? maker.makeInstance(resolver: DummyResolver()) - expect(instance1) !== instance2 - } - describe("multiple arguments") { - it("works with 2 arguments") { - let maker = multiton { (_, _: Int, _: Double) in 42 } - let arguments = (1, 1.0) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 - } - it("works with 3 arguments") { - let maker = multiton { (_, _: Int, _: Double, _: String) in 42 } - let arguments = (1, 1.0, "") - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 - } - it("works with 4 arguments") { - let maker = multiton { (_, _: Int, _: Double, _: String, _: Float) in 42 } - let arguments = (1, 1.0, "", Float(1.0)) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 - } - it("works with 5 arguments") { - let maker = multiton { (_, _: Int, _: Double, _: String, _: Float, _: Int) in 42 } - let arguments = (1, 1.0, "", Float(1.0), 5) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 - } - } - } - } + // } } diff --git a/Tests/UnitSpecs/SimpleInstanceMakerSpec.swift b/Tests/UnitSpecs/SimpleInstanceMakerSpec.swift index 04058b74..e6e728fd 100644 --- a/Tests/UnitSpecs/SimpleInstanceMakerSpec.swift +++ b/Tests/UnitSpecs/SimpleInstanceMakerSpec.swift @@ -7,207 +7,5 @@ import Quick @testable import Swinject class SimpleInstanceMakerSpec: QuickSpec { override func spec() { - describe("instance") { - it("produces maker with correct type signature") { - let maker = instance(42) as Any - expect(maker is SimpleInstanceMaker).to(beTrue()) - } - it("returns given instance") { - let maker = instance(42) - expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 - } - } - describe("provider") { - // TODO: Can we reuse tests for with / without context? - describe("without context") { - it("produces maker with correct type signature") { - let maker = provider { 42 } as Any - expect(maker is SimpleInstanceMaker).to(beTrue()) - } - it("returns instance made by provider method") { - let maker = provider { 42 } - expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 - } - it("does not call builder until instance is requested") { - var called = false - _ = provider { called = true } - expect(called).to(beFalse()) - } - it("calls builder with given resolver") { - var passedResolver: Resolver? - let resolver = DummyResolver() - let maker = provider { passedResolver = $0 } - _ = try? maker.makeInstance(resolver: resolver) - expect(passedResolver) === resolver - } - it("rethrows error from builder") { - let maker = provider { throw SwinjectError() } - expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) - } - it("does not reuse instance") { - let maker = provider { Person() } - let instance1 = try? maker.makeInstance(resolver: DummyResolver()) - let instance2 = try? maker.makeInstance(resolver: DummyResolver()) - expect(instance1) !== instance2 - } - } - describe("contexted") { - it("returns instance made by provider method") { - let maker = contexted(Any.self).provider { _, _ in 42 } - expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 - } - it("does not call builder until instance is requested") { - var called = false - _ = provider { called = true } - expect(called).to(beFalse()) - } - it("calls builder with given resolver") { - var passedResolver: Resolver? - let resolver = DummyResolver() - let maker = contexted(Any.self).provider { r, _ in passedResolver = r } - _ = try? maker.makeInstance(resolver: resolver) - expect(passedResolver) === resolver - } - it("calls builder with given context") { - var passedContext: Int? - let maker = contexted(Int.self).provider { _, c in passedContext = c } - _ = try? maker.makeInstance(context: 42, resolver: DummyResolver()) - expect(passedContext) == 42 - } - it("rethrows error from builder") { - let maker = contexted(Any.self).provider { _, _ in throw SwinjectError() } - expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) - } - it("does not reuse instance") { - let maker = contexted(Any.self).provider { _, _ in Person() } - let instance1 = try? maker.makeInstance(resolver: DummyResolver()) - let instance2 = try? maker.makeInstance(resolver: DummyResolver()) - expect(instance1) !== instance2 - } - } - } - describe("factory") { - describe("without context") { - it("produces maker with correct type signature") { - let maker = factory { (_, _: Void) in 42 } as Any - expect(maker is SimpleInstanceMaker).to(beTrue()) - } - it("returns instance made by builder method") { - let maker = factory { (_, _: Void) in 42 } - expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 - } - it("does not call builder until instance is requested") { - var called = false - _ = factory { (_, _: Void) in called = true } - expect(called).to(beFalse()) - } - it("calls builder with given resolver") { - var passedResolver: Resolver? - let resolver = DummyResolver() - let maker = factory { (r, _: Void) in passedResolver = r } - _ = try? maker.makeInstance(resolver: resolver) - expect(passedResolver) === resolver - } - it("calls builder with given argument") { - var passedArgument: Int? - let maker = factory { (_, arg: Int) in passedArgument = arg } - _ = try? maker.makeInstance(arg: 42, resolver: DummyResolver()) - expect(passedArgument) == 42 - } - it("rethrows error from builder") { - let maker = factory { (_, _: Void) in throw SwinjectError() } - expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) - } - it("does not reuse instance") { - let maker = factory { (_, _: Void) in Person() } - let instance1 = try? maker.makeInstance(resolver: DummyResolver()) - let instance2 = try? maker.makeInstance(resolver: DummyResolver()) - expect(instance1) !== instance2 - } - describe("multiple arguments") { - it("works with 2 arguments") { - let maker = factory { (_, _: Int, _: Double) in 42 } - let arguments = (1, 1.0) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 - } - it("works with 3 arguments") { - let maker = factory { (_, _: Int, _: Double, _: String) in 42 } - let arguments = (1, 1.0, "") - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 - } - it("works with 4 arguments") { - let maker = factory { (_, _: Int, _: Double, _: String, _: Float) in 42 } - let arguments = (1, 1.0, "", Float(1.0)) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 - } - it("works with 5 arguments") { - let maker = factory { (_, _: Int, _: Double, _: String, _: Float, _: Int) in 42 } - let arguments = (1, 1.0, "", Float(1.0), 5) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 - } - } - } - describe("contexted") { - it("returns instance made by builder method") { - let maker = contexted(Any.self).factory { (_, _, _: Void) in 42 } - expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 - } - it("does not call builder until instance is requested") { - var called = false - _ = contexted(Any.self).factory { (_, _, _: Void) in called = true } - expect(called).to(beFalse()) - } - it("calls builder with given resolver") { - var passedResolver: Resolver? - let resolver = DummyResolver() - let maker = contexted(Any.self).factory { (r, _, _: Void) in passedResolver = r } - _ = try? maker.makeInstance(resolver: resolver) - expect(passedResolver) === resolver - } - it("calls builder with given context") { - var passedContext: Int? - let maker = contexted(Int.self).factory { (_, c, _: Void) in passedContext = c } - _ = try? maker.makeInstance(context: 42, resolver: DummyResolver()) - expect(passedContext) == 42 - } - it("calls builder with given argument") { - var passedArgument: Int? - let maker = contexted(Any.self).factory { (_, _, arg: Int) in passedArgument = arg } - _ = try? maker.makeInstance(arg: 42, resolver: DummyResolver()) - expect(passedArgument) == 42 - } - it("rethrows error from builder") { - let maker = contexted(Any.self).factory { (_, _, _: Void) in throw SwinjectError() } - expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) - } - it("does not reuse instance") { - let maker = contexted(Any.self).factory { (_, _, _: Void) in Person() } - let instance1 = try? maker.makeInstance(resolver: DummyResolver()) - let instance2 = try? maker.makeInstance(resolver: DummyResolver()) - expect(instance1) !== instance2 - } - describe("multiple arguments") { - it("works with 2 arguments") { - let maker = contexted(Any.self).factory { (_, _, _: Int, _: Double) in 42 } - let arguments = (1, 1.0) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 - } - it("works with 3 arguments") { - let maker = contexted(Any.self).factory { (_, _, _: Int, _: Double, _: String) in 42 } - let arguments = (1, 1.0, "") - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 - } - it("works with 4 arguments") { - let maker = contexted(Any.self).factory { (_, _, _: Int, _: Double, _: String, _: Float) in 42 } - let arguments = (1, 1.0, "", Float(1.0)) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 - } - it("works with 5 arguments") { - let maker = contexted(Any.self).factory { (_, _, _: Int, _: Double, _: String, _: Float, _: Int) in 42 } - let arguments = (1, 1.0, "", Float(1.0), 5) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 - } - } - } - } + // } } From 8a57926af535a2eb75f8b32f7fbbaf1ae17cc0de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Wed, 17 Jul 2019 22:15:51 +0200 Subject: [PATCH 065/239] Restructure code --- Sources/BinderEnvironment.swift | 66 ++++++++++--------- Sources/Binding.swift | 16 +---- Sources/ScopedBinding.swift | 26 ++++++++ Sources/ScopedInstanceMaker.swift | 22 ------- Sources/SimpleBinding.swift | 34 ++++++++++ Sources/SimpleInstanceMaker.swift | 17 ----- Swinject.xcodeproj/project.pbxproj | 32 ++++----- Tests/UnitSpecs/BinderEnvironmentSpec.swift | 6 +- ...akerSpec.swift => ScopedBindingSpec.swift} | 2 +- ...akerSpec.swift => SimpleBindingSpec.swift} | 2 +- Tests/UnitSpecs/TypeBinderSpec.swift | 4 +- 11 files changed, 120 insertions(+), 107 deletions(-) create mode 100644 Sources/ScopedBinding.swift delete mode 100644 Sources/ScopedInstanceMaker.swift create mode 100644 Sources/SimpleBinding.swift delete mode 100644 Sources/SimpleInstanceMaker.swift rename Tests/UnitSpecs/{ScopedInstanceMakerSpec.swift => ScopedBindingSpec.swift} (67%) rename Tests/UnitSpecs/{SimpleInstanceMakerSpec.swift => SimpleBindingSpec.swift} (67%) diff --git a/Sources/BinderEnvironment.swift b/Sources/BinderEnvironment.swift index a36fab19..c7103cf1 100644 --- a/Sources/BinderEnvironment.swift +++ b/Sources/BinderEnvironment.swift @@ -15,121 +15,125 @@ public func scoped(_ scope: AScope) -> BinderEnvironment(_ builder: @escaping (Resolver, Context) throws -> Type) -> SimpleInstanceMaker { + func provider(_ builder: @escaping (Resolver, Context) throws -> Type) -> SimpleBinding.Builder { .init { r, c, _ in try builder(r, c) } } - func factory(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SimpleInstanceMaker { + func factory(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SimpleBinding.Builder { .init(builder) } +} - func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SimpleInstanceMaker { +public extension BinderEnvironment where AScope == Void { + func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SimpleBinding.Builder { .init { try builder($0, $1, $2.0, $2.1) } } - func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SimpleInstanceMaker { + func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SimpleBinding.Builder { .init { try builder($0, $1, $2.0, $2.1, $2.2) } } - func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SimpleInstanceMaker { + func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SimpleBinding.Builder { .init { try builder($0, $1, $2.0, $2.1, $2.2, $2.3) } } - func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SimpleInstanceMaker { + func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SimpleBinding.Builder { .init { try builder($0, $1, $2.0, $2.1, $2.2, $2.3, $2.4) } } } public extension BinderEnvironment where AScope: Scope, Context == AScope.Context { - func singleton(_ builder: @escaping () throws -> Type) -> ScopedInstanceMaker { + func singleton(_ builder: @escaping () throws -> Type) -> ScopedBinding.Builder { .init(scope) { _, _, _ in try builder() } } - func singleton(_ builder: @escaping (Resolver) throws -> Type) -> ScopedInstanceMaker { + func singleton(_ builder: @escaping (Resolver) throws -> Type) -> ScopedBinding.Builder { .init(scope) { r, _, _ in try builder(r) } } - func singleton(_ builder: @escaping (Resolver, Context) throws -> Type) -> ScopedInstanceMaker { + func singleton(_ builder: @escaping (Resolver, Context) throws -> Type) -> ScopedBinding.Builder { .init(scope) { r, c, _ in try builder(r, c) } } +} - func multiton(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> ScopedInstanceMaker { +public extension BinderEnvironment where AScope: Scope, Context == AScope.Context { + func multiton(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> ScopedBinding.Builder { .init(scope, builder) } - func multiton(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> ScopedInstanceMaker { + func multiton(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> ScopedBinding.Builder { .init(scope) { try builder($0, $1, $2.0, $2.1) } } - func multiton(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> ScopedInstanceMaker { + func multiton(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> ScopedBinding.Builder { .init(scope) { try builder($0, $1, $2.0, $2.1, $2.2) } } - func multiton(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> ScopedInstanceMaker { + func multiton(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> ScopedBinding.Builder { .init(scope) { try builder($0, $1, $2.0, $2.1, $2.2, $2.3) } } - func multiton(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> ScopedInstanceMaker { + func multiton(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> ScopedBinding.Builder { .init(scope) { try builder($0, $1, $2.0, $2.1, $2.2, $2.3, $2.4) } } } -public func instance(_ instance: Type) -> SimpleInstanceMaker { +public func instance(_ instance: Type) -> SimpleBinding.Builder { .init { _, _, _ in instance } } -public func provider(_ builder: @escaping () throws -> Type) -> SimpleInstanceMaker { +public func provider(_ builder: @escaping () throws -> Type) -> SimpleBinding.Builder { .init { _, _, _ in try builder() } } -public func provider(_ builder: @escaping (Resolver) throws -> Type) -> SimpleInstanceMaker { +public func provider(_ builder: @escaping (Resolver) throws -> Type) -> SimpleBinding.Builder { .init { r, _, _ in try builder(r) } } -public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> SimpleInstanceMaker { +public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> SimpleBinding.Builder { .init { try builder($0, $2) } } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SimpleInstanceMaker { +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SimpleBinding.Builder { .init { try builder($0, $2.0, $2.1) } } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SimpleInstanceMaker { +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SimpleBinding.Builder { .init { try builder($0, $2.0, $2.1, $2.2) } } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SimpleInstanceMaker { - SimpleInstanceMaker { try builder($0, $2.0, $2.1, $2.2, $2.3) } +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SimpleBinding.Builder { + SimpleBinding.Builder { try builder($0, $2.0, $2.1, $2.2, $2.3) } } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SimpleInstanceMaker { - SimpleInstanceMaker { try builder($0, $2.0, $2.1, $2.2, $2.3, $2.4) } +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SimpleBinding.Builder { + SimpleBinding.Builder { try builder($0, $2.0, $2.1, $2.2, $2.3, $2.4) } } -public func singleton(_ builder: @escaping () throws -> Type) -> ScopedInstanceMaker { +public func singleton(_ builder: @escaping () throws -> Type) -> ScopedBinding.Builder { .init(.implicit) { _, _, _ in try builder() } } -public func singleton(_ builder: @escaping (Resolver) throws -> Type) -> ScopedInstanceMaker { +public func singleton(_ builder: @escaping (Resolver) throws -> Type) -> ScopedBinding.Builder { .init(.implicit) { r, _, _ in try builder(r) } } -public func multiton(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> ScopedInstanceMaker { +public func multiton(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> ScopedBinding.Builder { .init(.implicit) { try builder($0, $2) } } -public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> ScopedInstanceMaker { +public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> ScopedBinding.Builder { .init(.implicit) { try builder($0, $2.0, $2.1) } } -public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> ScopedInstanceMaker { +public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> ScopedBinding.Builder { .init(.implicit) { try builder($0, $2.0, $2.1, $2.2) } } -public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> ScopedInstanceMaker { +public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> ScopedBinding.Builder { .init(.implicit) { try builder($0, $2.0, $2.1, $2.2, $2.3) } } -public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> ScopedInstanceMaker { +public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> ScopedBinding.Builder { .init(.implicit) { try builder($0, $2.0, $2.1, $2.2, $2.3, $2.4) } } diff --git a/Sources/Binding.swift b/Sources/Binding.swift index 8a0ed241..3f9ac1dc 100644 --- a/Sources/Binding.swift +++ b/Sources/Binding.swift @@ -8,18 +8,6 @@ public protocol Binding: SwinjectEntry { func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any } -struct SimpleBinding { - let key: AnyBindingKey - let maker: AnyInstanceMaker -} - -extension SimpleBinding: Binding { - // TODO: Proper Unit Tests - func matches(_ key: AnyBindingKey) -> Bool { - self.key.matches(key) - } - - func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any { - try maker.makeInstance(arg: arg, context: context, resolver: resolver) - } +public protocol BindingMaker { + func makeBinding(for descriptor: Descriptor) -> Binding where Descriptor: TypeDescriptor } diff --git a/Sources/ScopedBinding.swift b/Sources/ScopedBinding.swift new file mode 100644 index 00000000..5309ea44 --- /dev/null +++ b/Sources/ScopedBinding.swift @@ -0,0 +1,26 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +// FIXME: AScope is suboptimal name for a parameter +// Can we rename Scope -> ScopeProtocol? +public struct ScopedBinding {} + +extension ScopedBinding { + public struct Builder: InstanceMaker where AScope: Scope { + public typealias MadeType = Type + public typealias Context = AScope.Context + + let scope: AScope + private let builder: (Resolver, Context, Argument) throws -> Type + + init(_ scope: AScope, _ builder: @escaping (Resolver, Context, Argument) throws -> Type) { + self.scope = scope + self.builder = builder + } + + public func makeInstance(arg: Argument, context: Context, resolver: Resolver) throws -> Type { + try builder(resolver, context, arg) + } + } +} diff --git a/Sources/ScopedInstanceMaker.swift b/Sources/ScopedInstanceMaker.swift deleted file mode 100644 index 5bbd4105..00000000 --- a/Sources/ScopedInstanceMaker.swift +++ /dev/null @@ -1,22 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -// FIXME: AScope is suboptimal name for a parameter -// Can we rename Scope -> ScopeProtocol? -public struct ScopedInstanceMaker: InstanceMaker where AScope: Scope { - public typealias MadeType = Type - public typealias Context = AScope.Context - - let scope: AScope - private let builder: (Resolver, Context, Argument) throws -> Type - - init(_ scope: AScope, _ builder: @escaping (Resolver, Context, Argument) throws -> Type) { - self.scope = scope - self.builder = builder - } - - public func makeInstance(arg: Argument, context: Context, resolver: Resolver) throws -> Type { - try builder(resolver, context, arg) - } -} diff --git a/Sources/SimpleBinding.swift b/Sources/SimpleBinding.swift new file mode 100644 index 00000000..33cb259d --- /dev/null +++ b/Sources/SimpleBinding.swift @@ -0,0 +1,34 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +public struct SimpleBinding { + let key: AnyBindingKey + let maker: AnyInstanceMaker +} + +extension SimpleBinding: Binding { + public func matches(_ key: AnyBindingKey) -> Bool { + self.key.matches(key) + } + + public func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any { + try maker.makeInstance(arg: arg, context: context, resolver: resolver) + } +} + +extension SimpleBinding { + public struct Builder: InstanceMaker { + public typealias MadeType = Type + + private let builder: (Resolver, Context, Argument) throws -> Type + + init(_ builder: @escaping (Resolver, Context, Argument) throws -> Type) { + self.builder = builder + } + + public func makeInstance(arg: Argument, context: Context, resolver: Resolver) throws -> Type { + try builder(resolver, context, arg) + } + } +} diff --git a/Sources/SimpleInstanceMaker.swift b/Sources/SimpleInstanceMaker.swift deleted file mode 100644 index 8b1d1531..00000000 --- a/Sources/SimpleInstanceMaker.swift +++ /dev/null @@ -1,17 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -public struct SimpleInstanceMaker: InstanceMaker { - public typealias MadeType = Type - - private let builder: (Resolver, Context, Argument) throws -> Type - - init(_ builder: @escaping (Resolver, Context, Argument) throws -> Type) { - self.builder = builder - } - - public func makeInstance(arg: Argument, context: Context, resolver: Resolver) throws -> Type { - try builder(resolver, context, arg) - } -} diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index af00ded6..fd2401b6 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -16,13 +16,13 @@ CD6DE53522DD1C7300532D08 /* BindingKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53322DD1C6800532D08 /* BindingKeySpec.swift */; }; CD6DE53722DD1CE900532D08 /* BindingKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53622DD1CE900532D08 /* BindingKey.swift */; }; CD6DE53922DD1D0A00532D08 /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53822DD1D0A00532D08 /* InstanceRequest.swift */; }; - CD6DE53D22DD30A100532D08 /* SimpleInstanceMakerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53C22DD30A100532D08 /* SimpleInstanceMakerSpec.swift */; }; - CD6DE54322DE65B500532D08 /* SimpleInstanceMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE54222DE65B500532D08 /* SimpleInstanceMaker.swift */; }; + CD6DE53D22DD30A100532D08 /* SimpleBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53C22DD30A100532D08 /* SimpleBindingSpec.swift */; }; + CD6DE54322DE65B500532D08 /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE54222DE65B500532D08 /* SimpleBinding.swift */; }; CD6DE54522DED11600532D08 /* ContextedResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE54422DED11600532D08 /* ContextedResolver.swift */; }; CD6DE54722DED16400532D08 /* ContextedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE54622DED16400532D08 /* ContextedResolverSpec.swift */; }; CD6DE54C22DF85AF00532D08 /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE54B22DF85AF00532D08 /* Scope.swift */; }; - CD6DE54E22DF886F00532D08 /* ScopedInstanceMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE54D22DF886F00532D08 /* ScopedInstanceMaker.swift */; }; - CD6DE55022DF8B2700532D08 /* ScopedInstanceMakerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE54F22DF8B2700532D08 /* ScopedInstanceMakerSpec.swift */; }; + CD6DE54E22DF886F00532D08 /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE54D22DF886F00532D08 /* ScopedBinding.swift */; }; + CD6DE55022DF8B2700532D08 /* ScopedBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE54F22DF8B2700532D08 /* ScopedBindingSpec.swift */; }; CD6DE55322DF94ED00532D08 /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE55122DF93A000532D08 /* BinderEnvironment.swift */; }; CD6DE55522DFB2A600532D08 /* BinderEnvironmentSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE55422DFB2A600532D08 /* BinderEnvironmentSpec.swift */; }; CD85AF1222DA5A8F00A8B7CA /* NonGeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD85AF1122DA5A8F00A8B7CA /* NonGeneratedMocks.swift */; }; @@ -66,15 +66,15 @@ CD6DE53322DD1C6800532D08 /* BindingKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingKeySpec.swift; sourceTree = ""; }; CD6DE53622DD1CE900532D08 /* BindingKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingKey.swift; sourceTree = ""; }; CD6DE53822DD1D0A00532D08 /* InstanceRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRequest.swift; sourceTree = ""; }; - CD6DE53C22DD30A100532D08 /* SimpleInstanceMakerSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleInstanceMakerSpec.swift; sourceTree = ""; }; - CD6DE54222DE65B500532D08 /* SimpleInstanceMaker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleInstanceMaker.swift; sourceTree = ""; }; + CD6DE53C22DD30A100532D08 /* SimpleBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleBindingSpec.swift; sourceTree = ""; }; + CD6DE54222DE65B500532D08 /* SimpleBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleBinding.swift; sourceTree = ""; }; CD6DE54422DED11600532D08 /* ContextedResolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextedResolver.swift; sourceTree = ""; }; CD6DE54622DED16400532D08 /* ContextedResolverSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextedResolverSpec.swift; sourceTree = ""; }; CD6DE54822DED4A100532D08 /* .swiftformat */ = {isa = PBXFileReference; lastKnownFileType = text; path = .swiftformat; sourceTree = ""; }; CD6DE54A22DED4A100532D08 /* .sourcery.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .sourcery.yml; sourceTree = ""; }; CD6DE54B22DF85AF00532D08 /* Scope.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Scope.swift; sourceTree = ""; }; - CD6DE54D22DF886F00532D08 /* ScopedInstanceMaker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopedInstanceMaker.swift; sourceTree = ""; }; - CD6DE54F22DF8B2700532D08 /* ScopedInstanceMakerSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopedInstanceMakerSpec.swift; sourceTree = ""; }; + CD6DE54D22DF886F00532D08 /* ScopedBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopedBinding.swift; sourceTree = ""; }; + CD6DE54F22DF8B2700532D08 /* ScopedBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopedBindingSpec.swift; sourceTree = ""; }; CD6DE55122DF93A000532D08 /* BinderEnvironment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderEnvironment.swift; sourceTree = ""; }; CD6DE55422DFB2A600532D08 /* BinderEnvironmentSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderEnvironmentSpec.swift; sourceTree = ""; }; CD85AF1122DA5A8F00A8B7CA /* NonGeneratedMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonGeneratedMocks.swift; sourceTree = ""; }; @@ -148,8 +148,8 @@ CDD8380422DA307F003E9909 /* TypeBinder.swift */, CDD8380622DA30C6003E9909 /* TypeDescriptor.swift */, CDD8380B22DA3AD8003E9909 /* InstanceMaker.swift */, - CD6DE54222DE65B500532D08 /* SimpleInstanceMaker.swift */, - CD6DE54D22DF886F00532D08 /* ScopedInstanceMaker.swift */, + CD6DE54222DE65B500532D08 /* SimpleBinding.swift */, + CD6DE54D22DF886F00532D08 /* ScopedBinding.swift */, CD6DE55122DF93A000532D08 /* BinderEnvironment.swift */, CDD8380F22DA429F003E9909 /* Resolver.swift */, CD6DE54422DED11600532D08 /* ContextedResolver.swift */, @@ -201,11 +201,11 @@ children = ( CDD8380222DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift */, CDD8380822DA31C6003E9909 /* TypeBinderSpec.swift */, - CD6DE53C22DD30A100532D08 /* SimpleInstanceMakerSpec.swift */, + CD6DE53C22DD30A100532D08 /* SimpleBindingSpec.swift */, CDD8381922DA4C9F003E9909 /* SwinjectSpec.swift */, CD6DE53322DD1C6800532D08 /* BindingKeySpec.swift */, CD6DE54622DED16400532D08 /* ContextedResolverSpec.swift */, - CD6DE54F22DF8B2700532D08 /* ScopedInstanceMakerSpec.swift */, + CD6DE54F22DF8B2700532D08 /* ScopedBindingSpec.swift */, CD6DE55422DFB2A600532D08 /* BinderEnvironmentSpec.swift */, ); path = UnitSpecs; @@ -390,7 +390,7 @@ buildActionMask = 2147483647; files = ( CDD8380C22DA3AD8003E9909 /* InstanceMaker.swift in Sources */, - CD6DE54322DE65B500532D08 /* SimpleInstanceMaker.swift in Sources */, + CD6DE54322DE65B500532D08 /* SimpleBinding.swift in Sources */, CDADF33522DB521400C5D8DB /* SwinjectModule.swift in Sources */, CDD8381022DA429F003E9909 /* Resolver.swift in Sources */, CD6DE53722DD1CE900532D08 /* BindingKey.swift in Sources */, @@ -404,7 +404,7 @@ CDD8381622DA4B55003E9909 /* Swinject.swift in Sources */, CDD8380522DA307F003E9909 /* TypeBinder.swift in Sources */, CDD8380E22DA3B0D003E9909 /* Binding.swift in Sources */, - CD6DE54E22DF886F00532D08 /* ScopedInstanceMaker.swift in Sources */, + CD6DE54E22DF886F00532D08 /* ScopedBinding.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -419,13 +419,13 @@ CDADF34022DB883A00C5D8DB /* GeneratedMocks.swift in Sources */, CDD8380A22DA31D9003E9909 /* TypeBinderSpec.swift in Sources */, CD85AF1222DA5A8F00A8B7CA /* NonGeneratedMocks.swift in Sources */, - CD6DE53D22DD30A100532D08 /* SimpleInstanceMakerSpec.swift in Sources */, + CD6DE53D22DD30A100532D08 /* SimpleBindingSpec.swift in Sources */, CDD8380322DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift in Sources */, CD6DE53522DD1C7300532D08 /* BindingKeySpec.swift in Sources */, CD6DE55522DFB2A600532D08 /* BinderEnvironmentSpec.swift in Sources */, CDADF33722DB753800C5D8DB /* TestModels.swift in Sources */, 77729C9E22DCCA20005C3281 /* InjectionApiSpec.swift in Sources */, - CD6DE55022DF8B2700532D08 /* ScopedInstanceMakerSpec.swift in Sources */, + CD6DE55022DF8B2700532D08 /* ScopedBindingSpec.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Tests/UnitSpecs/BinderEnvironmentSpec.swift b/Tests/UnitSpecs/BinderEnvironmentSpec.swift index eaea4cf1..2653f4db 100644 --- a/Tests/UnitSpecs/BinderEnvironmentSpec.swift +++ b/Tests/UnitSpecs/BinderEnvironmentSpec.swift @@ -12,7 +12,7 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { describe("instance") { it("produces maker with correct type signature") { let maker = instance(42) as Any - expect(maker is SimpleInstanceMaker).to(beTrue()) + expect(maker is SimpleBinding.Builder).to(beTrue()) } it("returns given instance") { let maker = instance(42) @@ -22,7 +22,7 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { describe("provider") { it("produces maker with correct type signature") { let maker = provider { 42 } as Any - expect(maker is SimpleInstanceMaker).to(beTrue()) + expect(maker is SimpleBinding.Builder).to(beTrue()) } it("returns instance made by provider method") { let maker = provider { 42 } @@ -54,7 +54,7 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { describe("factory") { it("produces maker with correct type signature") { let maker = factory { (_, _: Void) in 42 } as Any - expect(maker is SimpleInstanceMaker).to(beTrue()) + expect(maker is SimpleBinding.Builder).to(beTrue()) } it("returns instance made by builder method") { let maker = factory { (_, _: Void) in 42 } diff --git a/Tests/UnitSpecs/ScopedInstanceMakerSpec.swift b/Tests/UnitSpecs/ScopedBindingSpec.swift similarity index 67% rename from Tests/UnitSpecs/ScopedInstanceMakerSpec.swift rename to Tests/UnitSpecs/ScopedBindingSpec.swift index a4aaee69..86ffc41e 100644 --- a/Tests/UnitSpecs/ScopedInstanceMakerSpec.swift +++ b/Tests/UnitSpecs/ScopedBindingSpec.swift @@ -6,6 +6,6 @@ import Nimble import Quick @testable import Swinject -class ScopedInstanceMakerSpec: QuickSpec { override func spec() { +class ScopedBindingSpec: QuickSpec { override func spec() { // } } diff --git a/Tests/UnitSpecs/SimpleInstanceMakerSpec.swift b/Tests/UnitSpecs/SimpleBindingSpec.swift similarity index 67% rename from Tests/UnitSpecs/SimpleInstanceMakerSpec.swift rename to Tests/UnitSpecs/SimpleBindingSpec.swift index e6e728fd..b96761e1 100644 --- a/Tests/UnitSpecs/SimpleInstanceMakerSpec.swift +++ b/Tests/UnitSpecs/SimpleBindingSpec.swift @@ -6,6 +6,6 @@ import Nimble import Quick @testable import Swinject -class SimpleInstanceMakerSpec: QuickSpec { override func spec() { +class SimpleBindingSpec: QuickSpec { override func spec() { // } } diff --git a/Tests/UnitSpecs/TypeBinderSpec.swift b/Tests/UnitSpecs/TypeBinderSpec.swift index 0f1e8ee0..86752d3d 100644 --- a/Tests/UnitSpecs/TypeBinderSpec.swift +++ b/Tests/UnitSpecs/TypeBinderSpec.swift @@ -42,7 +42,7 @@ class TypeBinderSpec: QuickSpec { override func spec() { } it("produces binding if given value of descriptor type") { let binding = bbind(Int.self).with(42) as? SimpleBinding - expect(binding?.maker is SimpleInstanceMaker).to(beTrue()) + expect(binding?.maker is SimpleBinding.Builder).to(beTrue()) } } describe("& operator") { @@ -64,7 +64,7 @@ class TypeBinderSpec: QuickSpec { override func spec() { } it("produces binding provider if given value of descriptor type") { let binding = bbind(Int.self) & 42 as? SimpleBinding - expect(binding?.maker is SimpleInstanceMaker).to(beTrue()) + expect(binding?.maker is SimpleBinding.Builder).to(beTrue()) } } } } From 97bead89afdc45a37011eec8fc6cf05837f325d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Wed, 17 Jul 2019 22:49:43 +0200 Subject: [PATCH 066/239] Implement binding builders --- Sources/Scope.swift | 15 ++++-- Sources/ScopedBinding.swift | 44 ++++++++++++---- Sources/SimpleBinding.swift | 23 ++++++--- Tests/Support/GeneratedMocks.swift | 56 ++++++++++----------- Tests/Support/NonGeneratedMocks.swift | 7 ++- Tests/UnitSpecs/BinderEnvironmentSpec.swift | 6 +-- Tests/UnitSpecs/ScopedBindingSpec.swift | 20 +++++++- Tests/UnitSpecs/SimpleBindingSpec.swift | 15 +++++- 8 files changed, 133 insertions(+), 53 deletions(-) diff --git a/Sources/Scope.swift b/Sources/Scope.swift index 0fbb6619..be345bdf 100644 --- a/Sources/Scope.swift +++ b/Sources/Scope.swift @@ -3,13 +3,22 @@ // // sourcery: AutoMockable -public protocol Scope { - associatedtype Context - +public protocol AnyScope { var lock: Lock { get } + func registry(for context: Any) -> ScopeRegistry +} + +public protocol Scope: AnyScope { + associatedtype Context func registry(for context: Context) -> ScopeRegistry } +extension Scope { + func registry(for context: Any) -> ScopeRegistry { + registry(for: context as! Context) + } +} + public protocol Lock {} public protocol ScopeRegistry { diff --git a/Sources/ScopedBinding.swift b/Sources/ScopedBinding.swift index 5309ea44..812d69cf 100644 --- a/Sources/ScopedBinding.swift +++ b/Sources/ScopedBinding.swift @@ -2,15 +2,24 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -// FIXME: AScope is suboptimal name for a parameter -// Can we rename Scope -> ScopeProtocol? -public struct ScopedBinding {} +public struct ScopedBinding { + let key: AnyBindingKey + let maker: AnyInstanceMaker + let scope: AnyScope +} -extension ScopedBinding { - public struct Builder: InstanceMaker where AScope: Scope { - public typealias MadeType = Type - public typealias Context = AScope.Context +extension ScopedBinding: Binding { + public func matches(_: AnyBindingKey) -> Bool { + fatalError() + } + public func instance(arg _: Any, context _: Any, resolver _: Resolver) throws -> Any { + fatalError() + } +} + +extension ScopedBinding { + public struct Builder where AScope: Scope { let scope: AScope private let builder: (Resolver, Context, Argument) throws -> Type @@ -18,9 +27,24 @@ extension ScopedBinding { self.scope = scope self.builder = builder } + } +} - public func makeInstance(arg: Argument, context: Context, resolver: Resolver) throws -> Type { - try builder(resolver, context, arg) - } +extension ScopedBinding.Builder: InstanceMaker { + public typealias MadeType = Type + public typealias Context = AScope.Context + + public func makeInstance(arg: Argument, context: Context, resolver: Resolver) throws -> Type { + try builder(resolver, context, arg) + } +} + +extension ScopedBinding.Builder: BindingMaker { + public func makeBinding(for descriptor: Descriptor) -> Binding where Descriptor: TypeDescriptor { + ScopedBinding( + key: BindingKey(descriptor: descriptor), + maker: self, + scope: scope + ) } } diff --git a/Sources/SimpleBinding.swift b/Sources/SimpleBinding.swift index 33cb259d..1d1a63da 100644 --- a/Sources/SimpleBinding.swift +++ b/Sources/SimpleBinding.swift @@ -18,17 +18,28 @@ extension SimpleBinding: Binding { } extension SimpleBinding { - public struct Builder: InstanceMaker { - public typealias MadeType = Type - + public struct Builder { private let builder: (Resolver, Context, Argument) throws -> Type init(_ builder: @escaping (Resolver, Context, Argument) throws -> Type) { self.builder = builder } + } +} - public func makeInstance(arg: Argument, context: Context, resolver: Resolver) throws -> Type { - try builder(resolver, context, arg) - } +extension SimpleBinding.Builder: InstanceMaker { + public typealias MadeType = Type + + public func makeInstance(arg: Argument, context: Context, resolver: Resolver) throws -> Type { + try builder(resolver, context, arg) + } +} + +extension SimpleBinding.Builder: BindingMaker { + public func makeBinding(for descriptor: Descriptor) -> Binding where Descriptor: TypeDescriptor { + SimpleBinding( + key: BindingKey(descriptor: descriptor), + maker: self + ) } } diff --git a/Tests/Support/GeneratedMocks.swift b/Tests/Support/GeneratedMocks.swift index a40840ae..51bc2203 100644 --- a/Tests/Support/GeneratedMocks.swift +++ b/Tests/Support/GeneratedMocks.swift @@ -97,6 +97,34 @@ class AnyResolverMock: AnyResolver { } } +class AnyScopeMock: AnyScope { + var lock: Lock { + get { return underlyingLock } + set(value) { underlyingLock = value } + } + + var underlyingLock: Lock! + + // MARK: - registry + + var registryForCallsCount = 0 + var registryForCalled: Bool { + return registryForCallsCount > 0 + } + + var registryForReceivedContext: Any? + var registryForReceivedInvocations: [Any] = [] + var registryForReturnValue: ScopeRegistry! + var registryForClosure: ((Any) -> ScopeRegistry)? + + func registry(for context: Any) -> ScopeRegistry { + registryForCallsCount += 1 + registryForReceivedContext = context + registryForReceivedInvocations.append(context) + return registryForClosure.map { $0(context) } ?? registryForReturnValue + } +} + class AnyScopeRegistryMock: AnyScopeRegistry { // MARK: - register @@ -202,31 +230,3 @@ class BindingMock: Binding { } class ModuleIncludeEntryMock: ModuleIncludeEntry {} - -class ScopeMock: Scope { - var lock: Lock { - get { return underlyingLock } - set(value) { underlyingLock = value } - } - - var underlyingLock: Lock! - - // MARK: - registry - - var registryForCallsCount = 0 - var registryForCalled: Bool { - return registryForCallsCount > 0 - } - - var registryForReceivedContext: Context? - var registryForReceivedInvocations: [Context] = [] - var registryForReturnValue: ScopeRegistry! - var registryForClosure: ((Context) -> ScopeRegistry)? - - func registry(for context: Context) -> ScopeRegistry { - registryForCallsCount += 1 - registryForReceivedContext = context - registryForReceivedInvocations.append(context) - return registryForClosure.map { $0(context) } ?? registryForReturnValue - } -} diff --git a/Tests/Support/NonGeneratedMocks.swift b/Tests/Support/NonGeneratedMocks.swift index 9c8ec845..e61c5a0a 100644 --- a/Tests/Support/NonGeneratedMocks.swift +++ b/Tests/Support/NonGeneratedMocks.swift @@ -35,10 +35,15 @@ extension AnyResolverMock: Resolver { } } -extension ScopeMock { +extension AnyScopeMock: Scope { typealias Context = Any } +class DummyScope: Scope { + var lock: Lock { fatalError() } + func registry(for _: Context) -> ScopeRegistry { fatalError() } +} + // sourcery: AutoMockable protocol AnyScopeRegistry { func register(_ instance: Any, for key: ScopeRegistryKey) diff --git a/Tests/UnitSpecs/BinderEnvironmentSpec.swift b/Tests/UnitSpecs/BinderEnvironmentSpec.swift index 2653f4db..31d09db9 100644 --- a/Tests/UnitSpecs/BinderEnvironmentSpec.swift +++ b/Tests/UnitSpecs/BinderEnvironmentSpec.swift @@ -307,10 +307,10 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { } } describe("scoped") { - var scope = ScopeMock() - var environment: BinderEnvironment! + var scope = AnyScopeMock() + var environment: BinderEnvironment! beforeEach { - scope = ScopeMock() + scope = AnyScopeMock() environment = scoped(scope) } describe("singleton") { diff --git a/Tests/UnitSpecs/ScopedBindingSpec.swift b/Tests/UnitSpecs/ScopedBindingSpec.swift index 86ffc41e..9b879792 100644 --- a/Tests/UnitSpecs/ScopedBindingSpec.swift +++ b/Tests/UnitSpecs/ScopedBindingSpec.swift @@ -7,5 +7,23 @@ import Quick @testable import Swinject class ScopedBindingSpec: QuickSpec { override func spec() { - // + describe("binding builder") { + let descriptor = AnyTypeDescriptorMock() + let scope = DummyScope() + let builder = ScopedBinding.Builder, Int>(scope) { _, _, _ in } + it("makes binding with self as maker") { + let binding = builder.makeBinding(for: descriptor) as? ScopedBinding + expect(binding?.maker is ScopedBinding.Builder, Int>).to(beTrue()) + } + it("makes binding with correct key") { + let binding = builder.makeBinding(for: descriptor) as? ScopedBinding + expect(binding?.key.descriptor) === descriptor + expect(binding?.key.contextType is String.Type).to(beTrue()) + expect(binding?.key.argumentType is Int.Type).to(beTrue()) + } + it("makes binding with correct scope") { + let binding = builder.makeBinding(for: descriptor) as? ScopedBinding + expect(binding?.scope) === scope + } + } } } diff --git a/Tests/UnitSpecs/SimpleBindingSpec.swift b/Tests/UnitSpecs/SimpleBindingSpec.swift index b96761e1..b359e043 100644 --- a/Tests/UnitSpecs/SimpleBindingSpec.swift +++ b/Tests/UnitSpecs/SimpleBindingSpec.swift @@ -7,5 +7,18 @@ import Quick @testable import Swinject class SimpleBindingSpec: QuickSpec { override func spec() { - // + describe("binding builder") { + let builder = SimpleBinding.Builder { _, _, _ in } + it("makes binding with self as maker") { + let binding = builder.makeBinding(for: AnyTypeDescriptorMock()) as? SimpleBinding + expect(binding?.maker is SimpleBinding.Builder).to(beTrue()) + } + it("makes binding with correct key") { + let descriptor = AnyTypeDescriptorMock() + let binding = builder.makeBinding(for: descriptor) as? SimpleBinding + expect(binding?.key.descriptor) === descriptor + expect(binding?.key.contextType is String.Type).to(beTrue()) + expect(binding?.key.argumentType is Int.Type).to(beTrue()) + } + } } } From 2126ed0a4ffc56480638acd3edc29e392b8a19ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Wed, 17 Jul 2019 23:18:34 +0200 Subject: [PATCH 067/239] Update type binder implementation --- Sources/Binding.swift | 1 + Sources/ScopedBinding.swift | 2 + Sources/SimpleBinding.swift | 2 + Sources/TypeBinder.swift | 10 ++--- Tests/ApiSpecs/InjectionApiSpec.swift | 1 - Tests/Support/GeneratedMocks.swift | 21 +++++++++ Tests/Support/NonGeneratedMocks.swift | 13 ++++++ Tests/UnitSpecs/TypeBinderSpec.swift | 65 +++++++++++---------------- 8 files changed, 70 insertions(+), 45 deletions(-) diff --git a/Sources/Binding.swift b/Sources/Binding.swift index 3f9ac1dc..247877b1 100644 --- a/Sources/Binding.swift +++ b/Sources/Binding.swift @@ -9,5 +9,6 @@ public protocol Binding: SwinjectEntry { } public protocol BindingMaker { + associatedtype BoundType func makeBinding(for descriptor: Descriptor) -> Binding where Descriptor: TypeDescriptor } diff --git a/Sources/ScopedBinding.swift b/Sources/ScopedBinding.swift index 812d69cf..133d6d5e 100644 --- a/Sources/ScopedBinding.swift +++ b/Sources/ScopedBinding.swift @@ -40,6 +40,8 @@ extension ScopedBinding.Builder: InstanceMaker { } extension ScopedBinding.Builder: BindingMaker { + public typealias BoundType = Type + public func makeBinding(for descriptor: Descriptor) -> Binding where Descriptor: TypeDescriptor { ScopedBinding( key: BindingKey(descriptor: descriptor), diff --git a/Sources/SimpleBinding.swift b/Sources/SimpleBinding.swift index 1d1a63da..d673d2f9 100644 --- a/Sources/SimpleBinding.swift +++ b/Sources/SimpleBinding.swift @@ -36,6 +36,8 @@ extension SimpleBinding.Builder: InstanceMaker { } extension SimpleBinding.Builder: BindingMaker { + public typealias BoundType = Type + public func makeBinding(for descriptor: Descriptor) -> Binding where Descriptor: TypeDescriptor { SimpleBinding( key: BindingKey(descriptor: descriptor), diff --git a/Sources/TypeBinder.swift b/Sources/TypeBinder.swift index 7f0a7c80..4bdc6970 100644 --- a/Sources/TypeBinder.swift +++ b/Sources/TypeBinder.swift @@ -19,16 +19,16 @@ public func bind(_ descriptor: Descriptor) -> TypeBinder } public extension TypeBinder { - func with(_ maker: SomeMaker) -> Binding where SomeMaker: InstanceMaker, SomeMaker.MadeType == Descriptor.BaseType { - SimpleBinding(key: BindingKey(descriptor: descriptor), maker: maker) + func with(_ maker: Maker) -> Binding where Maker: BindingMaker, Maker.BoundType == Descriptor.BaseType { + maker.makeBinding(for: descriptor) } - func with(_ anInstance: Descriptor.BaseType) -> Binding { - with(instance(anInstance)) + func with(_ value: Descriptor.BaseType) -> Binding { + instance(value).makeBinding(for: descriptor) } } -public func & (lhs: TypeBinder, rhs: SomeMaker) -> Binding where SomeMaker: InstanceMaker, SomeMaker.MadeType == Descriptor.BaseType { +public func & (lhs: TypeBinder, rhs: Maker) -> Binding where Maker: BindingMaker, Maker.BoundType == Descriptor.BaseType { lhs.with(rhs) } diff --git a/Tests/ApiSpecs/InjectionApiSpec.swift b/Tests/ApiSpecs/InjectionApiSpec.swift index 5b553664..de14ca06 100644 --- a/Tests/ApiSpecs/InjectionApiSpec.swift +++ b/Tests/ApiSpecs/InjectionApiSpec.swift @@ -1,7 +1,6 @@ // // Copyright © 2019 Swinject Contributors. All rights reserved. // - import Nimble import Quick import Swinject diff --git a/Tests/Support/GeneratedMocks.swift b/Tests/Support/GeneratedMocks.swift index 51bc2203..733a7bd1 100644 --- a/Tests/Support/GeneratedMocks.swift +++ b/Tests/Support/GeneratedMocks.swift @@ -47,6 +47,27 @@ class AnyBindingKeyMock: AnyBindingKey { } } +class AnyBindningMakerMock: AnyBindningMaker { + // MARK: - makeBinding + + var makeBindingForCallsCount = 0 + var makeBindingForCalled: Bool { + return makeBindingForCallsCount > 0 + } + + var makeBindingForReceivedDescriptor: AnyTypeDescriptor? + var makeBindingForReceivedInvocations: [AnyTypeDescriptor] = [] + var makeBindingForReturnValue: Binding! + var makeBindingForClosure: ((AnyTypeDescriptor) -> Binding)? + + func makeBinding(for descriptor: AnyTypeDescriptor) -> Binding { + makeBindingForCallsCount += 1 + makeBindingForReceivedDescriptor = descriptor + makeBindingForReceivedInvocations.append(descriptor) + return makeBindingForClosure.map { $0(descriptor) } ?? makeBindingForReturnValue + } +} + class AnyInstanceMakerMock: AnyInstanceMaker { // MARK: - makeInstance diff --git a/Tests/Support/NonGeneratedMocks.swift b/Tests/Support/NonGeneratedMocks.swift index e61c5a0a..aebcc6f6 100644 --- a/Tests/Support/NonGeneratedMocks.swift +++ b/Tests/Support/NonGeneratedMocks.swift @@ -59,3 +59,16 @@ extension AnyScopeRegistryMock: ScopeRegistry { (instance(for: key) as Any?) as? Type } } + +// sourcery: AutoMockable +protocol AnyBindningMaker { + func makeBinding(for descriptor: AnyTypeDescriptor) -> Binding +} + +extension AnyBindningMakerMock: BindingMaker { + typealias BoundType = Any + + func makeBinding(for descriptor: Descriptor) -> Binding where Descriptor: TypeDescriptor { + makeBinding(for: descriptor as AnyTypeDescriptor) + } +} diff --git a/Tests/UnitSpecs/TypeBinderSpec.swift b/Tests/UnitSpecs/TypeBinderSpec.swift index 86752d3d..dc5dc819 100644 --- a/Tests/UnitSpecs/TypeBinderSpec.swift +++ b/Tests/UnitSpecs/TypeBinderSpec.swift @@ -8,10 +8,11 @@ import Quick class TypeBinderSpec: QuickSpec { override func spec() { var descriptor = AnyTypeDescriptorMock() - var maker = AnyInstanceMakerMock() + var maker = AnyBindningMakerMock() beforeEach { descriptor = AnyTypeDescriptorMock() - maker = AnyInstanceMakerMock() + maker = AnyBindningMakerMock() + maker.makeBindingForReturnValue = BindingMock() } describe("bind") { it("descriptor has correct tag for tagged type") { @@ -24,47 +25,33 @@ class TypeBinderSpec: QuickSpec { override func spec() { } } describe("`with` method") { - it("produces binding with correct descriptor") { - let binding = bbind(descriptor).with(maker) as? SimpleBinding - expect(binding?.key.descriptor) === descriptor + it("passes descriptor to maker") { + _ = bbind(descriptor).with(maker) + expect(maker.makeBindingForReceivedDescriptor) === descriptor } - it("produces binding with correct argument type") { - let binding = bbind(Any.self).with(DummyMaker()) as? SimpleBinding - expect(binding?.key.argumentType is Int.Type).to(beTrue()) + it("returns binding from maker") { + let binding = BindingMock() + maker.makeBindingForReturnValue = binding + expect(bbind(descriptor).with(maker)) === binding } - it("produces binding with correct context type") { - let binding = bbind(Any.self).with(DummyMaker()) as? SimpleBinding - expect(binding?.key.contextType is Int.Type).to(beTrue()) - } - it("produces binding with correct maker") { - let binding = bbind(Any.self).with(maker) as? SimpleBinding - expect(binding?.maker) === maker - } - it("produces binding if given value of descriptor type") { - let binding = bbind(Int.self).with(42) as? SimpleBinding - expect(binding?.maker is SimpleBinding.Builder).to(beTrue()) + it("works with passing instance directly") { + let binding = bbind(descriptor).with(42) + expect { try binding.instance(arg: (), context: (), resolver: DummyResolver()) as? Int } == 42 } } - describe("& operator") { - it("produces binding with correct descriptor") { - let binding = bbind(descriptor) & maker as? SimpleBinding - expect(binding?.key.descriptor) === descriptor - } - it("produces binding with correct argument type") { - let binding = bbind(Any.self) & DummyMaker() as? SimpleBinding - expect(binding?.key.argumentType is Int.Type).to(beTrue()) - } - it("produces binding with correct context type") { - let binding = bbind(Any.self) & DummyMaker() as? SimpleBinding - expect(binding?.key.contextType is Int.Type).to(beTrue()) - } - it("produces binding with correct maker") { - let binding = bbind(Any.self) & maker as? SimpleBinding - expect(binding?.maker) === maker - } - it("produces binding provider if given value of descriptor type") { - let binding = bbind(Int.self) & 42 as? SimpleBinding - expect(binding?.maker is SimpleBinding.Builder).to(beTrue()) + describe("`&` method") { + it("passes descriptor to maker") { + _ = bbind(descriptor) & maker + expect(maker.makeBindingForReceivedDescriptor) === descriptor + } + it("returns binding from maker") { + let binding = BindingMock() + maker.makeBindingForReturnValue = binding + expect(bbind(descriptor) & maker) === binding + } + it("works with passing instance directly") { + let binding = bbind(descriptor) & 42 + expect { try binding.instance(arg: (), context: (), resolver: DummyResolver()) as? Int } == 42 } } } } From e18bd87059fcc38c903eab91648a3989da6a1428 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Wed, 17 Jul 2019 23:28:28 +0200 Subject: [PATCH 068/239] Implement scoped binding matching --- Sources/ScopedBinding.swift | 4 ++-- Tests/ApiSpecs/InjectionApiSpec.swift | 1 + Tests/UnitSpecs/ScopedBindingSpec.swift | 23 +++++++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Sources/ScopedBinding.swift b/Sources/ScopedBinding.swift index 133d6d5e..f979f546 100644 --- a/Sources/ScopedBinding.swift +++ b/Sources/ScopedBinding.swift @@ -9,8 +9,8 @@ public struct ScopedBinding { } extension ScopedBinding: Binding { - public func matches(_: AnyBindingKey) -> Bool { - fatalError() + public func matches(_ key: AnyBindingKey) -> Bool { + self.key.matches(key) } public func instance(arg _: Any, context _: Any, resolver _: Resolver) throws -> Any { diff --git a/Tests/ApiSpecs/InjectionApiSpec.swift b/Tests/ApiSpecs/InjectionApiSpec.swift index de14ca06..5b553664 100644 --- a/Tests/ApiSpecs/InjectionApiSpec.swift +++ b/Tests/ApiSpecs/InjectionApiSpec.swift @@ -1,6 +1,7 @@ // // Copyright © 2019 Swinject Contributors. All rights reserved. // + import Nimble import Quick import Swinject diff --git a/Tests/UnitSpecs/ScopedBindingSpec.swift b/Tests/UnitSpecs/ScopedBindingSpec.swift index 9b879792..21b01d33 100644 --- a/Tests/UnitSpecs/ScopedBindingSpec.swift +++ b/Tests/UnitSpecs/ScopedBindingSpec.swift @@ -26,4 +26,27 @@ class ScopedBindingSpec: QuickSpec { override func spec() { expect(binding?.scope) === scope } } + describe("matching") { + var key = AnyBindingKeyMock() + var bindingKey = AnyBindingKeyMock() + var binding: ScopedBinding! + beforeEach { + key = AnyBindingKeyMock() + bindingKey = AnyBindingKeyMock() + bindingKey.matchesReturnValue = false + binding = ScopedBinding(key: bindingKey, maker: AnyInstanceMakerMock(), scope: AnyScopeMock()) + } + it("passes the input key to the binding key") { + _ = binding.matches(key) + expect(bindingKey.matchesReceivedOther) === key + } + it("returns true if binding key matches") { + bindingKey.matchesReturnValue = true + expect(binding.matches(key)).to(beTrue()) + } + it("returns false if binding key matches") { + bindingKey.matchesReturnValue = false + expect(binding.matches(key)).to(beFalse()) + } + } } } From 804c02b927687cf4fd5033f704538b2c1ebea193 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Thu, 18 Jul 2019 00:43:01 +0200 Subject: [PATCH 069/239] Implement scoped binding's instance retrieval --- Sources/InstanceMaker.swift | 2 +- Sources/Scope.swift | 14 +++-- Sources/ScopedBinding.swift | 18 +++++- Tests/Support/GeneratedMocks.swift | 78 ++++++++++++------------- Tests/Support/NonGeneratedMocks.swift | 25 +++----- Tests/UnitSpecs/ScopedBindingSpec.swift | 78 +++++++++++++++++++++++++ 6 files changed, 154 insertions(+), 61 deletions(-) diff --git a/Sources/InstanceMaker.swift b/Sources/InstanceMaker.swift index 2c1fd867..3851716b 100644 --- a/Sources/InstanceMaker.swift +++ b/Sources/InstanceMaker.swift @@ -16,7 +16,7 @@ public protocol InstanceMaker: AnyInstanceMaker { func makeInstance(arg: Argument, context: Context, resolver: Resolver) throws -> MadeType } -public extension AnyInstanceMaker where Self: InstanceMaker { +public extension InstanceMaker { func makeInstance(arg: Any, context: Any, resolver: Resolver) throws -> Any { guard let arg = arg as? Argument, let context = context as? Context else { throw SwinjectError() } return try makeInstance(arg: arg, context: context, resolver: resolver) as MadeType diff --git a/Sources/Scope.swift b/Sources/Scope.swift index be345bdf..48a91587 100644 --- a/Sources/Scope.swift +++ b/Sources/Scope.swift @@ -19,14 +19,20 @@ extension Scope { } } -public protocol Lock {} +public protocol Lock { + func sync(_ action: () throws -> T) rethrows -> T +} +// sourcery: AutoMockable public protocol ScopeRegistry { - func register(_ instance: Type, for key: ScopeRegistryKey) - func instance(for key: ScopeRegistryKey) -> Type? + func register(_ instance: Any, for key: ScopeRegistryKey) + func instance(for key: ScopeRegistryKey) -> Any? } -public struct ScopeRegistryKey {} +public struct ScopeRegistryKey { + let descriptor: AnyTypeDescriptor + let argument: Any +} public class ImplicitScope: Scope { public typealias Context = Any diff --git a/Sources/ScopedBinding.swift b/Sources/ScopedBinding.swift index f979f546..0eb01cb4 100644 --- a/Sources/ScopedBinding.swift +++ b/Sources/ScopedBinding.swift @@ -13,7 +13,23 @@ extension ScopedBinding: Binding { self.key.matches(key) } - public func instance(arg _: Any, context _: Any, resolver _: Resolver) throws -> Any { + public func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any { + try scope.lock.sync { + let registry = scope.registry(for: context) + let key = ScopeRegistryKey(descriptor: self.key.descriptor, argument: arg) + if let instance = registry.instance(for: key) as Any? { + return instance + } else { + let newInstance = try maker.makeInstance(arg: arg, context: context, resolver: resolver) + registry.register(newInstance, for: key) + return newInstance + } + } + } +} + +private class NoResolver: Resolver { + func resolve(_: InstanceRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { fatalError() } } diff --git a/Tests/Support/GeneratedMocks.swift b/Tests/Support/GeneratedMocks.swift index 733a7bd1..094c7270 100644 --- a/Tests/Support/GeneratedMocks.swift +++ b/Tests/Support/GeneratedMocks.swift @@ -146,45 +146,6 @@ class AnyScopeMock: AnyScope { } } -class AnyScopeRegistryMock: AnyScopeRegistry { - // MARK: - register - - var registerForCallsCount = 0 - var registerForCalled: Bool { - return registerForCallsCount > 0 - } - - var registerForReceivedArguments: (instance: Any, key: ScopeRegistryKey)? - var registerForReceivedInvocations: [(instance: Any, key: ScopeRegistryKey)] = [] - var registerForClosure: ((Any, ScopeRegistryKey) -> Void)? - - func register(_ instance: Any, for key: ScopeRegistryKey) { - registerForCallsCount += 1 - registerForReceivedArguments = (instance: instance, key: key) - registerForReceivedInvocations.append((instance: instance, key: key)) - registerForClosure?(instance, key) - } - - // MARK: - instance - - var instanceForCallsCount = 0 - var instanceForCalled: Bool { - return instanceForCallsCount > 0 - } - - var instanceForReceivedKey: ScopeRegistryKey? - var instanceForReceivedInvocations: [ScopeRegistryKey] = [] - var instanceForReturnValue: Any? - var instanceForClosure: ((ScopeRegistryKey) -> Any?)? - - func instance(for key: ScopeRegistryKey) -> Any? { - instanceForCallsCount += 1 - instanceForReceivedKey = key - instanceForReceivedInvocations.append(key) - return instanceForClosure.map { $0(key) } ?? instanceForReturnValue - } -} - class AnyTypeDescriptorMock: AnyTypeDescriptor { // MARK: - matches @@ -251,3 +212,42 @@ class BindingMock: Binding { } class ModuleIncludeEntryMock: ModuleIncludeEntry {} + +class ScopeRegistryMock: ScopeRegistry { + // MARK: - register + + var registerForCallsCount = 0 + var registerForCalled: Bool { + return registerForCallsCount > 0 + } + + var registerForReceivedArguments: (instance: Any, key: ScopeRegistryKey)? + var registerForReceivedInvocations: [(instance: Any, key: ScopeRegistryKey)] = [] + var registerForClosure: ((Any, ScopeRegistryKey) -> Void)? + + func register(_ instance: Any, for key: ScopeRegistryKey) { + registerForCallsCount += 1 + registerForReceivedArguments = (instance: instance, key: key) + registerForReceivedInvocations.append((instance: instance, key: key)) + registerForClosure?(instance, key) + } + + // MARK: - instance + + var instanceForCallsCount = 0 + var instanceForCalled: Bool { + return instanceForCallsCount > 0 + } + + var instanceForReceivedKey: ScopeRegistryKey? + var instanceForReceivedInvocations: [ScopeRegistryKey] = [] + var instanceForReturnValue: Any? + var instanceForClosure: ((ScopeRegistryKey) -> Any?)? + + func instance(for key: ScopeRegistryKey) -> Any? { + instanceForCallsCount += 1 + instanceForReceivedKey = key + instanceForReceivedInvocations.append(key) + return instanceForClosure.map { $0(key) } ?? instanceForReturnValue + } +} diff --git a/Tests/Support/NonGeneratedMocks.swift b/Tests/Support/NonGeneratedMocks.swift index aebcc6f6..537a8b3f 100644 --- a/Tests/Support/NonGeneratedMocks.swift +++ b/Tests/Support/NonGeneratedMocks.swift @@ -44,22 +44,6 @@ class DummyScope: Scope { func registry(for _: Context) -> ScopeRegistry { fatalError() } } -// sourcery: AutoMockable -protocol AnyScopeRegistry { - func register(_ instance: Any, for key: ScopeRegistryKey) - func instance(for key: ScopeRegistryKey) -> Any? -} - -extension AnyScopeRegistryMock: ScopeRegistry { - func register(_ instance: Type, for key: ScopeRegistryKey) { - register(instance as Any, for: key) - } - - func instance(for key: ScopeRegistryKey) -> Type? { - (instance(for: key) as Any?) as? Type - } -} - // sourcery: AutoMockable protocol AnyBindningMaker { func makeBinding(for descriptor: AnyTypeDescriptor) -> Binding @@ -72,3 +56,12 @@ extension AnyBindningMakerMock: BindingMaker { makeBinding(for: descriptor as AnyTypeDescriptor) } } + +class ReplayLock: Lock { + var syncCallsCount = 0 + + func sync(_ action: () throws -> T) rethrows -> T { + syncCallsCount += 1 + return try action() + } +} diff --git a/Tests/UnitSpecs/ScopedBindingSpec.swift b/Tests/UnitSpecs/ScopedBindingSpec.swift index 21b01d33..a4adaf69 100644 --- a/Tests/UnitSpecs/ScopedBindingSpec.swift +++ b/Tests/UnitSpecs/ScopedBindingSpec.swift @@ -49,4 +49,82 @@ class ScopedBindingSpec: QuickSpec { override func spec() { expect(binding.matches(key)).to(beFalse()) } } + describe("instance") { + var key = AnyBindingKeyMock() + var lock = ReplayLock() + var registry = ScopeRegistryMock() + var scope = AnyScopeMock() + var maker = AnyInstanceMakerMock() + var binding: ScopedBinding! + beforeEach { + lock = ReplayLock() + registry = ScopeRegistryMock() + scope = AnyScopeMock() + scope.lock = lock + scope.registryForReturnValue = registry + maker = AnyInstanceMakerMock() + key = AnyBindingKeyMock() + key.descriptor = AnyTypeDescriptorMock() + binding = ScopedBinding(key: key, maker: maker, scope: scope) + } + it("syncs using scope's lock") { + _ = try? binding.instance(arg: (), context: (), resolver: DummyResolver()) + expect(lock.syncCallsCount) == 1 + } + context("no instance in registry") { + beforeEach { + registry.instanceForReturnValue = nil + } + it("returns instance produced by maker") { + maker.makeInstanceArgContextResolverReturnValue = 42 + let instance = try? binding.instance(arg: (), context: (), resolver: DummyResolver()) as? Int + expect(instance) == 42 + } + it("rethrows error from maker") { + maker.makeInstanceArgContextResolverThrowableError = TestError() + expect { + try binding.instance(arg: (), context: (), resolver: DummyResolver()) + }.to(throwError(errorType: TestError.self)) + } + it("puts made instance into registry") { + maker.makeInstanceArgContextResolverReturnValue = 42 + _ = try? binding.instance(arg: (), context: (), resolver: DummyResolver()) + expect(registry.registerForReceivedArguments?.instance as? Int) == 42 + } + it("invokes maker with correct parameters") { + let resolver = DummyResolver() + _ = try? binding.instance(arg: 42, context: "context", resolver: resolver) + expect(maker.makeInstanceArgContextResolverReceivedArguments?.arg as? Int) == 42 + expect(maker.makeInstanceArgContextResolverReceivedArguments?.context as? String) == "context" + expect(maker.makeInstanceArgContextResolverReceivedArguments?.resolver) === resolver + } + it("puts instance into registry using a correct key") { + let descriptor = AnyTypeDescriptorMock() + key.descriptor = descriptor + _ = try? binding.instance(arg: 42, context: (), resolver: DummyResolver()) + expect(registry.registerForReceivedArguments?.key.argument as? Int) == 42 + expect(registry.registerForReceivedArguments?.key.descriptor) === descriptor + } + } + context("instance in registry") { + beforeEach { + registry.instanceForReturnValue = 42 + } + it("returns instance from registry") { + let instance = try? binding.instance(arg: (), context: (), resolver: DummyResolver()) as? Int + expect(instance) == 42 + } + } + it("retrieves registry using passed context") { + _ = try? binding.instance(arg: (), context: "context", resolver: DummyResolver()) + expect(scope.registryForReceivedContext as? String) == "context" + } + it("retrieves instance from registry using a correct key") { + let descriptor = AnyTypeDescriptorMock() + key.descriptor = descriptor + _ = try? binding.instance(arg: 42, context: (), resolver: DummyResolver()) + expect(registry.instanceForReceivedKey?.argument as? Int) == 42 + expect(registry.instanceForReceivedKey?.descriptor) === descriptor + } + } } } From 8aad2b5b5f7767540add504620df3dcdd2df3433 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Thu, 18 Jul 2019 01:02:55 +0200 Subject: [PATCH 070/239] Cleanup --- Sources/ScopedBinding.swift | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Sources/ScopedBinding.swift b/Sources/ScopedBinding.swift index 0eb01cb4..be40c626 100644 --- a/Sources/ScopedBinding.swift +++ b/Sources/ScopedBinding.swift @@ -28,12 +28,6 @@ extension ScopedBinding: Binding { } } -private class NoResolver: Resolver { - func resolve(_: InstanceRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { - fatalError() - } -} - extension ScopedBinding { public struct Builder where AScope: Scope { let scope: AScope From f1f9155560666097f6daa8580828d13019741d74 Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Thu, 18 Jul 2019 15:34:57 +0200 Subject: [PATCH 071/239] Implement registry key matching --- Sources/Matchable.swift | 34 ++++++ Sources/Scope.swift | 11 -- Sources/ScopeRegistry.swift | 19 ++++ Sources/ScopeRegistryKey.swift | 22 ++++ Sources/TypeDescriptor.swift | 8 +- Swinject.xcodeproj/project.pbxproj | 20 ++++ Tests/Support/GeneratedMocks.swift | 43 +++++++- Tests/UnitSpecs/ScopeRegistryKeySpec.swift | 100 ++++++++++++++++++ .../UnitSpecs/StandardScopeRegistrySpec.swift | 21 ++++ 9 files changed, 259 insertions(+), 19 deletions(-) create mode 100644 Sources/Matchable.swift create mode 100644 Sources/ScopeRegistry.swift create mode 100644 Sources/ScopeRegistryKey.swift create mode 100644 Tests/UnitSpecs/ScopeRegistryKeySpec.swift create mode 100644 Tests/UnitSpecs/StandardScopeRegistrySpec.swift diff --git a/Sources/Matchable.swift b/Sources/Matchable.swift new file mode 100644 index 00000000..233fc533 --- /dev/null +++ b/Sources/Matchable.swift @@ -0,0 +1,34 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +// sourcery: AutoMockable +public protocol Matchable { + func matches(_ other: Any) -> Bool + var hashValue: Int { get } // FIXME: Use hash(into:) +} + +// TODO: Box / Unbox internally all the arguments +struct AnyMatchable: Matchable, Hashable { + let value: Any + private let _matches: (Any) -> Bool + private let _hashInto: (inout Hasher) -> Void + + init(_ value: T) { + self.value = value + _matches = { $0 as? T == value } + _hashInto = { value.hash(into: &$0) } + } + + func matches(_ other: Any) -> Bool { + _matches(other) + } + + func hash(into hasher: inout Hasher) { + _hashInto(&hasher) + } + + static func == (lhs: AnyMatchable, rhs: AnyMatchable) -> Bool { + lhs.matches(rhs.value) + } +} diff --git a/Sources/Scope.swift b/Sources/Scope.swift index 48a91587..33dcf330 100644 --- a/Sources/Scope.swift +++ b/Sources/Scope.swift @@ -23,17 +23,6 @@ public protocol Lock { func sync(_ action: () throws -> T) rethrows -> T } -// sourcery: AutoMockable -public protocol ScopeRegistry { - func register(_ instance: Any, for key: ScopeRegistryKey) - func instance(for key: ScopeRegistryKey) -> Any? -} - -public struct ScopeRegistryKey { - let descriptor: AnyTypeDescriptor - let argument: Any -} - public class ImplicitScope: Scope { public typealias Context = Any diff --git a/Sources/ScopeRegistry.swift b/Sources/ScopeRegistry.swift new file mode 100644 index 00000000..2d14ccc3 --- /dev/null +++ b/Sources/ScopeRegistry.swift @@ -0,0 +1,19 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +// sourcery: AutoMockable +public protocol ScopeRegistry { + func register(_ instance: Any, for key: ScopeRegistryKey) + func instance(for key: ScopeRegistryKey) -> Any? +} + +public class StandardScopeRegistry: ScopeRegistry { + public func register(_: Any, for _: ScopeRegistryKey) { + fatalError() + } + + public func instance(for _: ScopeRegistryKey) -> Any? { + nil + } +} diff --git a/Sources/ScopeRegistryKey.swift b/Sources/ScopeRegistryKey.swift new file mode 100644 index 00000000..fab4224c --- /dev/null +++ b/Sources/ScopeRegistryKey.swift @@ -0,0 +1,22 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +public struct ScopeRegistryKey { + let descriptor: AnyTypeDescriptor + let argument: Any +} + +extension ScopeRegistryKey: Hashable { + public static func == (lhs: ScopeRegistryKey, rhs: ScopeRegistryKey) -> Bool { + lhs.descriptor.matches(rhs.descriptor) + && rhs.descriptor.matches(lhs.descriptor) + && (lhs.argument as? Matchable)?.matches(rhs.argument) ?? false + && (rhs.argument as? Matchable)?.matches(lhs.argument) ?? false + } + + public func hash(into hasher: inout Hasher) { + descriptor.hashValue.hash(into: &hasher) + (argument as? Matchable)?.hashValue.hash(into: &hasher) + } +} diff --git a/Sources/TypeDescriptor.swift b/Sources/TypeDescriptor.swift index 41a394b7..e84822b1 100644 --- a/Sources/TypeDescriptor.swift +++ b/Sources/TypeDescriptor.swift @@ -3,9 +3,7 @@ // // sourcery: AutoMockable -public protocol AnyTypeDescriptor { - func matches(_ other: AnyTypeDescriptor) -> Bool -} +public protocol AnyTypeDescriptor: Matchable {} public protocol TypeDescriptor: AnyTypeDescriptor { associatedtype BaseType @@ -16,10 +14,12 @@ public struct NoTag: Equatable {} public struct Tagged: TypeDescriptor where Tag: Equatable { let tag: Tag - public func matches(_ other: AnyTypeDescriptor) -> Bool { + public func matches(_ other: Any) -> Bool { guard let other = other as? Tagged else { return false } return tag == other.tag } + + public var hashValue: Int { 0 } // FIXME: } func tagged(_: Type.Type, with tag: Tag) -> Tagged where Tag: Equatable { diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index fd2401b6..00cc7a9b 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -11,6 +11,11 @@ 771BFC8122D5F83E00AFB237 /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 771BFC7322D5F83E00AFB237 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; 771BFC9122D600B700AFB237 /* Nimble in Frameworks */ = {isa = PBXBuildFile; productRef = 771BFC9022D600B700AFB237 /* Nimble */; }; 771BFC9422D600CC00AFB237 /* Quick in Frameworks */ = {isa = PBXBuildFile; productRef = 771BFC9322D600CC00AFB237 /* Quick */; }; + 7723ABD722E095460067D423 /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7723ABD622E095460067D423 /* ScopeRegistry.swift */; }; + 7723ABDA22E0962C0067D423 /* StandardScopeRegistrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7723ABD822E0961B0067D423 /* StandardScopeRegistrySpec.swift */; }; + 7723ABDD22E0979E0067D423 /* ScopeRegistryKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7723ABDB22E097950067D423 /* ScopeRegistryKeySpec.swift */; }; + 7723ABDF22E0A9FD0067D423 /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7723ABDE22E0A9FD0067D423 /* Matchable.swift */; }; + 7755159D22E0B3C2004BF092 /* ScopeRegistryKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7755159C22E0B3C2004BF092 /* ScopeRegistryKey.swift */; }; 77729C9E22DCCA20005C3281 /* InjectionApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77729C9D22DCCA20005C3281 /* InjectionApiSpec.swift */; }; 77906E7D22DF6A8D009CDCF4 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77906E7C22DF6A8D009CDCF4 /* Convenience.swift */; }; CD6DE53522DD1C7300532D08 /* BindingKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53322DD1C6800532D08 /* BindingKeySpec.swift */; }; @@ -61,6 +66,11 @@ 771BFC8022D5F83E00AFB237 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 771BFC8B22D5FAAE00AFB237 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nimble.framework; path = Carthage/Build/Mac/Nimble.framework; sourceTree = ""; }; 771BFC8C22D5FAAE00AFB237 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quick.framework; path = Carthage/Build/Mac/Quick.framework; sourceTree = ""; }; + 7723ABD622E095460067D423 /* ScopeRegistry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistry.swift; sourceTree = ""; }; + 7723ABD822E0961B0067D423 /* StandardScopeRegistrySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StandardScopeRegistrySpec.swift; sourceTree = ""; }; + 7723ABDB22E097950067D423 /* ScopeRegistryKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistryKeySpec.swift; sourceTree = ""; }; + 7723ABDE22E0A9FD0067D423 /* Matchable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Matchable.swift; sourceTree = ""; }; + 7755159C22E0B3C2004BF092 /* ScopeRegistryKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistryKey.swift; sourceTree = ""; }; 77729C9D22DCCA20005C3281 /* InjectionApiSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InjectionApiSpec.swift; sourceTree = ""; }; 77906E7C22DF6A8D009CDCF4 /* Convenience.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Convenience.swift; sourceTree = ""; }; CD6DE53322DD1C6800532D08 /* BindingKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingKeySpec.swift; sourceTree = ""; }; @@ -160,6 +170,9 @@ CDD8381C22DA4E02003E9909 /* SwinjectError.swift */, CDADF33422DB521400C5D8DB /* SwinjectModule.swift */, CD6DE54B22DF85AF00532D08 /* Scope.swift */, + 7723ABD622E095460067D423 /* ScopeRegistry.swift */, + 7755159C22E0B3C2004BF092 /* ScopeRegistryKey.swift */, + 7723ABDE22E0A9FD0067D423 /* Matchable.swift */, ); path = Sources; sourceTree = ""; @@ -207,6 +220,8 @@ CD6DE54622DED16400532D08 /* ContextedResolverSpec.swift */, CD6DE54F22DF8B2700532D08 /* ScopedBindingSpec.swift */, CD6DE55422DFB2A600532D08 /* BinderEnvironmentSpec.swift */, + 7723ABD822E0961B0067D423 /* StandardScopeRegistrySpec.swift */, + 7723ABDB22E097950067D423 /* ScopeRegistryKeySpec.swift */, ); path = UnitSpecs; sourceTree = ""; @@ -400,7 +415,10 @@ CD6DE54C22DF85AF00532D08 /* Scope.swift in Sources */, CDD8380722DA30C6003E9909 /* TypeDescriptor.swift in Sources */, CD6DE54522DED11600532D08 /* ContextedResolver.swift in Sources */, + 7723ABDF22E0A9FD0067D423 /* Matchable.swift in Sources */, + 7755159D22E0B3C2004BF092 /* ScopeRegistryKey.swift in Sources */, CD6DE55322DF94ED00532D08 /* BinderEnvironment.swift in Sources */, + 7723ABD722E095460067D423 /* ScopeRegistry.swift in Sources */, CDD8381622DA4B55003E9909 /* Swinject.swift in Sources */, CDD8380522DA307F003E9909 /* TypeBinder.swift in Sources */, CDD8380E22DA3B0D003E9909 /* Binding.swift in Sources */, @@ -423,6 +441,8 @@ CDD8380322DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift in Sources */, CD6DE53522DD1C7300532D08 /* BindingKeySpec.swift in Sources */, CD6DE55522DFB2A600532D08 /* BinderEnvironmentSpec.swift in Sources */, + 7723ABDA22E0962C0067D423 /* StandardScopeRegistrySpec.swift in Sources */, + 7723ABDD22E0979E0067D423 /* ScopeRegistryKeySpec.swift in Sources */, CDADF33722DB753800C5D8DB /* TestModels.swift in Sources */, 77729C9E22DCCA20005C3281 /* InjectionApiSpec.swift in Sources */, CD6DE55022DF8B2700532D08 /* ScopedBindingSpec.swift in Sources */, diff --git a/Tests/Support/GeneratedMocks.swift b/Tests/Support/GeneratedMocks.swift index 094c7270..e34fa2ff 100644 --- a/Tests/Support/GeneratedMocks.swift +++ b/Tests/Support/GeneratedMocks.swift @@ -147,6 +147,13 @@ class AnyScopeMock: AnyScope { } class AnyTypeDescriptorMock: AnyTypeDescriptor { + var hashValue: Int { + get { return underlyingHashValue } + set(value) { underlyingHashValue = value } + } + + var underlyingHashValue: Int! + // MARK: - matches var matchesCallsCount = 0 @@ -154,12 +161,12 @@ class AnyTypeDescriptorMock: AnyTypeDescriptor { return matchesCallsCount > 0 } - var matchesReceivedOther: AnyTypeDescriptor? - var matchesReceivedInvocations: [AnyTypeDescriptor] = [] + var matchesReceivedOther: Any? + var matchesReceivedInvocations: [Any] = [] var matchesReturnValue: Bool! - var matchesClosure: ((AnyTypeDescriptor) -> Bool)? + var matchesClosure: ((Any) -> Bool)? - func matches(_ other: AnyTypeDescriptor) -> Bool { + func matches(_ other: Any) -> Bool { matchesCallsCount += 1 matchesReceivedOther = other matchesReceivedInvocations.append(other) @@ -211,6 +218,34 @@ class BindingMock: Binding { } } +class MatchableMock: Matchable { + var hashValue: Int { + get { return underlyingHashValue } + set(value) { underlyingHashValue = value } + } + + var underlyingHashValue: Int! + + // MARK: - matches + + var matchesCallsCount = 0 + var matchesCalled: Bool { + return matchesCallsCount > 0 + } + + var matchesReceivedOther: Any? + var matchesReceivedInvocations: [Any] = [] + var matchesReturnValue: Bool! + var matchesClosure: ((Any) -> Bool)? + + func matches(_ other: Any) -> Bool { + matchesCallsCount += 1 + matchesReceivedOther = other + matchesReceivedInvocations.append(other) + return matchesClosure.map { $0(other) } ?? matchesReturnValue + } +} + class ModuleIncludeEntryMock: ModuleIncludeEntry {} class ScopeRegistryMock: ScopeRegistry { diff --git a/Tests/UnitSpecs/ScopeRegistryKeySpec.swift b/Tests/UnitSpecs/ScopeRegistryKeySpec.swift new file mode 100644 index 00000000..be5c17c3 --- /dev/null +++ b/Tests/UnitSpecs/ScopeRegistryKeySpec.swift @@ -0,0 +1,100 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +import Nimble +import Quick +@testable import Swinject + +class ScopeRegistryKeySpec: QuickSpec { override func spec() { + var descriptor1 = AnyTypeDescriptorMock() + var descriptor2 = AnyTypeDescriptorMock() + var argument1 = MatchableMock() + var argument2 = MatchableMock() + var key1: ScopeRegistryKey! + var key2: ScopeRegistryKey! + beforeEach { + descriptor1 = AnyTypeDescriptorMock() + descriptor1.matchesReturnValue = true + descriptor1.hashValue = 0 + argument1 = MatchableMock() + argument1.matchesReturnValue = true + argument1.hashValue = 0 + descriptor2 = AnyTypeDescriptorMock() + descriptor2.matchesReturnValue = true + descriptor2.hashValue = 0 + argument2 = MatchableMock() + argument2.matchesReturnValue = true + argument2.hashValue = 0 + key1 = ScopeRegistryKey(descriptor: descriptor1, argument: argument1) + key2 = ScopeRegistryKey(descriptor: descriptor2, argument: argument2) + } + describe("equality") { + describe("descriptor matching") { + it("does not equal if first descriptor doesnt match") { + descriptor1.matchesReturnValue = false + descriptor2.matchesReturnValue = true + expect(key1) != key2 + } + it("does not equal if second descriptor doesnt match") { + descriptor1.matchesReturnValue = true + descriptor2.matchesReturnValue = false + expect(key1) != key2 + } + it("equals if both descriptor match") { + descriptor1.matchesReturnValue = true + descriptor2.matchesReturnValue = true + expect(key1) == key2 + } + } + describe("argument matching") { + it("does not equal if first argument is not matchable") { + key1 = ScopeRegistryKey(descriptor: descriptor1, argument: ()) + expect(key1) != key2 + } + it("does not equal if first argument doesnt match") { + argument1.matchesReturnValue = false + expect(key1) != key2 + } + it("does not equal if second argument is not matchable") { + key2 = ScopeRegistryKey(descriptor: descriptor2, argument: ()) + expect(key1) != key2 + } + it("does not equal if second argument doesnt match") { + argument2.matchesReturnValue = false + expect(key1) != key2 + } + it("equals if both arguments match") { + argument1.matchesReturnValue = true + argument2.matchesReturnValue = true + expect(key1) == key2 + } + } + } + describe("hash") { + describe("hashes descriptor") { + it("does not equal if descriptor hashes are different") { + descriptor1.hashValue = 1 + descriptor2.hashValue = 2 + expect(key1.hashValue) != key2.hashValue + } + it("equals if descriptor hashes are the same") { + descriptor1.hashValue = 1 + descriptor2.hashValue = 1 + expect(key1.hashValue) == key2.hashValue + } + } + describe("hashes matchable argument") { + it("does not equal if argument hashes are different") { + argument1.hashValue = 1 + argument2.hashValue = 2 + expect(key1.hashValue) != key2.hashValue + } + it("equals if argument hashes are the same") { + argument1.hashValue = 1 + argument2.hashValue = 1 + expect(key1.hashValue) == key2.hashValue + } + } + } +} } diff --git a/Tests/UnitSpecs/StandardScopeRegistrySpec.swift b/Tests/UnitSpecs/StandardScopeRegistrySpec.swift new file mode 100644 index 00000000..18f7558d --- /dev/null +++ b/Tests/UnitSpecs/StandardScopeRegistrySpec.swift @@ -0,0 +1,21 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +import Nimble +import Quick +@testable import Swinject + +class StandardScopeRegistrySpec: QuickSpec { override func spec() { + var registry: StandardScopeRegistry! + beforeEach { + registry = StandardScopeRegistry() + } + describe("empty") { + it("returns no instance") { + expect(registry.instance(for: dummyKey)).to(beNil()) + } + } +} } + +let dummyKey = ScopeRegistryKey(descriptor: plain(Void.self), argument: 0) From be0e47d602e67496c7516e83171e3571e146cf97 Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Thu, 18 Jul 2019 16:56:07 +0200 Subject: [PATCH 072/239] Implement matchable conformance for Tagged --- Sources/Resolver.swift | 10 +++++----- Sources/TypeDescriptor.swift | 10 ++++++---- Swinject.xcodeproj/project.pbxproj | 4 ++++ Tests/UnitSpecs/TaggedTypeSpec.swift | 21 +++++++++++++++++++++ 4 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 Tests/UnitSpecs/TaggedTypeSpec.swift diff --git a/Sources/Resolver.swift b/Sources/Resolver.swift index a48ef4ef..4155c051 100644 --- a/Sources/Resolver.swift +++ b/Sources/Resolver.swift @@ -23,11 +23,11 @@ public extension Resolver { try instance(tagged: NoTag(), arg: arg) } - func instance(of _: Type.Type = Type.self, tagged tag: Tag) throws -> Type { + func instance(of _: Type.Type = Type.self, tagged tag: Tag) throws -> Type { try resolve(request(tag: tag, arg: ())) } - func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg: Argument) throws -> Type { + func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg: Argument) throws -> Type { try resolve(request(tag: tag, arg: arg)) } } @@ -41,11 +41,11 @@ public extension Resolver { provider(tagged: NoTag(), arg: arg) } - func provider(of _: Type.Type = Type.self, tagged tag: Tag) -> () throws -> Type { + func provider(of _: Type.Type = Type.self, tagged tag: Tag) -> () throws -> Type { provider(tagged: tag, arg: ()) } - func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg: Argument) -> () throws -> Type { + func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg: Argument) -> () throws -> Type { return { try self.resolve(request(tag: tag, arg: arg)) } } } @@ -55,7 +55,7 @@ public extension Resolver { factory(tagged: NoTag()) } - func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Argument) throws -> Type { + func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Argument) throws -> Type { return { try self.resolve(request(tag: tag, arg: $0)) } } diff --git a/Sources/TypeDescriptor.swift b/Sources/TypeDescriptor.swift index e84822b1..06716dc8 100644 --- a/Sources/TypeDescriptor.swift +++ b/Sources/TypeDescriptor.swift @@ -9,9 +9,9 @@ public protocol TypeDescriptor: AnyTypeDescriptor { associatedtype BaseType } -public struct NoTag: Equatable {} +public struct NoTag: Hashable {} -public struct Tagged: TypeDescriptor where Tag: Equatable { +public struct Tagged: TypeDescriptor where Tag: Hashable { let tag: Tag public func matches(_ other: Any) -> Bool { @@ -19,10 +19,12 @@ public struct Tagged: TypeDescriptor where Tag: Equatable { return tag == other.tag } - public var hashValue: Int { 0 } // FIXME: + public var hashValue: Int { + String(describing: BaseType.self).hashValue ^ tag.hashValue + } } -func tagged(_: Type.Type, with tag: Tag) -> Tagged where Tag: Equatable { +func tagged(_: Type.Type, with tag: Tag) -> Tagged where Tag: Hashable { Tagged(tag: tag) } diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 00cc7a9b..7d41718e 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -16,6 +16,7 @@ 7723ABDD22E0979E0067D423 /* ScopeRegistryKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7723ABDB22E097950067D423 /* ScopeRegistryKeySpec.swift */; }; 7723ABDF22E0A9FD0067D423 /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7723ABDE22E0A9FD0067D423 /* Matchable.swift */; }; 7755159D22E0B3C2004BF092 /* ScopeRegistryKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7755159C22E0B3C2004BF092 /* ScopeRegistryKey.swift */; }; + 775515A022E0BE79004BF092 /* TaggedTypeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7755159E22E0BE62004BF092 /* TaggedTypeSpec.swift */; }; 77729C9E22DCCA20005C3281 /* InjectionApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77729C9D22DCCA20005C3281 /* InjectionApiSpec.swift */; }; 77906E7D22DF6A8D009CDCF4 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77906E7C22DF6A8D009CDCF4 /* Convenience.swift */; }; CD6DE53522DD1C7300532D08 /* BindingKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53322DD1C6800532D08 /* BindingKeySpec.swift */; }; @@ -71,6 +72,7 @@ 7723ABDB22E097950067D423 /* ScopeRegistryKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistryKeySpec.swift; sourceTree = ""; }; 7723ABDE22E0A9FD0067D423 /* Matchable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Matchable.swift; sourceTree = ""; }; 7755159C22E0B3C2004BF092 /* ScopeRegistryKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistryKey.swift; sourceTree = ""; }; + 7755159E22E0BE62004BF092 /* TaggedTypeSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaggedTypeSpec.swift; sourceTree = ""; }; 77729C9D22DCCA20005C3281 /* InjectionApiSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InjectionApiSpec.swift; sourceTree = ""; }; 77906E7C22DF6A8D009CDCF4 /* Convenience.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Convenience.swift; sourceTree = ""; }; CD6DE53322DD1C6800532D08 /* BindingKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingKeySpec.swift; sourceTree = ""; }; @@ -222,6 +224,7 @@ CD6DE55422DFB2A600532D08 /* BinderEnvironmentSpec.swift */, 7723ABD822E0961B0067D423 /* StandardScopeRegistrySpec.swift */, 7723ABDB22E097950067D423 /* ScopeRegistryKeySpec.swift */, + 7755159E22E0BE62004BF092 /* TaggedTypeSpec.swift */, ); path = UnitSpecs; sourceTree = ""; @@ -439,6 +442,7 @@ CD85AF1222DA5A8F00A8B7CA /* NonGeneratedMocks.swift in Sources */, CD6DE53D22DD30A100532D08 /* SimpleBindingSpec.swift in Sources */, CDD8380322DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift in Sources */, + 775515A022E0BE79004BF092 /* TaggedTypeSpec.swift in Sources */, CD6DE53522DD1C7300532D08 /* BindingKeySpec.swift in Sources */, CD6DE55522DFB2A600532D08 /* BinderEnvironmentSpec.swift in Sources */, 7723ABDA22E0962C0067D423 /* StandardScopeRegistrySpec.swift in Sources */, diff --git a/Tests/UnitSpecs/TaggedTypeSpec.swift b/Tests/UnitSpecs/TaggedTypeSpec.swift new file mode 100644 index 00000000..9a1c4e06 --- /dev/null +++ b/Tests/UnitSpecs/TaggedTypeSpec.swift @@ -0,0 +1,21 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +import Nimble +import Quick +@testable import Swinject + +class TaggedTypeSpec: QuickSpec { override func spec() { + describe("hashValue") { + it("is different for different types") { + expect(plain(Int.self).hashValue) != plain(String.self).hashValue + } + it("is different for different tags") { + expect(tagged(Int.self, with: "tag1").hashValue) != tagged(Int.self, with: "tag2").hashValue + } + it("is same for the same descriptor") { + expect(tagged(Int.self, with: "tag1").hashValue) == tagged(Int.self, with: "tag1").hashValue + } + } +} } From 550484cc4465b736751d064127af12db60dacb8e Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Thu, 18 Jul 2019 17:29:05 +0200 Subject: [PATCH 073/239] Implement standard scoped registry --- Sources/Matchable.swift | 16 +++++--- Sources/ScopeRegistry.swift | 10 +++-- .../UnitSpecs/StandardScopeRegistrySpec.swift | 38 +++++++++++++++++-- 3 files changed, 51 insertions(+), 13 deletions(-) diff --git a/Sources/Matchable.swift b/Sources/Matchable.swift index 233fc533..7d1b128b 100644 --- a/Sources/Matchable.swift +++ b/Sources/Matchable.swift @@ -11,21 +11,25 @@ public protocol Matchable { // TODO: Box / Unbox internally all the arguments struct AnyMatchable: Matchable, Hashable { let value: Any - private let _matches: (Any) -> Bool - private let _hashInto: (inout Hasher) -> Void + private let matchesValue: (Any) -> Bool + private let hashValueInto: (inout Hasher) -> Void init(_ value: T) { self.value = value - _matches = { $0 as? T == value } - _hashInto = { value.hash(into: &$0) } + matchesValue = { $0 as? T == value } + hashValueInto = { value.hash(into: &$0) } } func matches(_ other: Any) -> Bool { - _matches(other) + if let other = other as? AnyMatchable { + return matchesValue(other.value) + } else { + return false + } } func hash(into hasher: inout Hasher) { - _hashInto(&hasher) + hashValueInto(&hasher) } static func == (lhs: AnyMatchable, rhs: AnyMatchable) -> Bool { diff --git a/Sources/ScopeRegistry.swift b/Sources/ScopeRegistry.swift index 2d14ccc3..32ba5412 100644 --- a/Sources/ScopeRegistry.swift +++ b/Sources/ScopeRegistry.swift @@ -9,11 +9,13 @@ public protocol ScopeRegistry { } public class StandardScopeRegistry: ScopeRegistry { - public func register(_: Any, for _: ScopeRegistryKey) { - fatalError() + private var entries = [ScopeRegistryKey: [Any]]() + + public func register(_ instance: Any, for key: ScopeRegistryKey) { + entries[key, default: []].append(instance) } - public func instance(for _: ScopeRegistryKey) -> Any? { - nil + public func instance(for key: ScopeRegistryKey) -> Any? { + entries[key]?.last } } diff --git a/Tests/UnitSpecs/StandardScopeRegistrySpec.swift b/Tests/UnitSpecs/StandardScopeRegistrySpec.swift index 18f7558d..84994820 100644 --- a/Tests/UnitSpecs/StandardScopeRegistrySpec.swift +++ b/Tests/UnitSpecs/StandardScopeRegistrySpec.swift @@ -8,14 +8,46 @@ import Quick class StandardScopeRegistrySpec: QuickSpec { override func spec() { var registry: StandardScopeRegistry! + let person = Array(1 ... 3).map { _ in Person() } + let key = Array(1 ... 3).map { ScopeRegistryKey(descriptor: plain(Int.self), argument: AnyMatchable($0)) } beforeEach { registry = StandardScopeRegistry() } describe("empty") { it("returns no instance") { - expect(registry.instance(for: dummyKey)).to(beNil()) + expect(registry.instance(for: key[0])).to(beNil()) + } + } + describe("single intance") { + beforeEach { + registry.register(person[0], for: key[0]) + } + it("returns instance for correct key") { + expect(registry.instance(for: key[0])) === person[0] + } + it("returns no instance for incorrect key") { + expect(registry.instance(for: key[1])).to(beNil()) + } + } + describe("multiple intances") { + it("returns different instances for different keys") { + registry.register(person[0], for: key[0]) + registry.register(person[1], for: key[1]) + expect(registry.instance(for: key[0])) === person[0] + expect(registry.instance(for: key[1])) === person[1] + } + it("returns the last instance registered for the key") { + registry.register(person[0], for: key[0]) + registry.register(person[1], for: key[0]) + expect(registry.instance(for: key[0])) === person[1] + } + it("should keep references to all registerd instances") { + var aPerson = Person() as Person? + weak var weakRef = aPerson + registry.register(aPerson!, for: key[0]) + registry.register(person[0], for: key[0]) + aPerson = nil + expect(weakRef).notTo(beNil()) } } } } - -let dummyKey = ScopeRegistryKey(descriptor: plain(Void.self), argument: 0) From 648f3ee3dc120220f81f28c4632842882bb327da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Thu, 18 Jul 2019 18:32:02 +0200 Subject: [PATCH 074/239] Close closable instances wher registry is released --- Sources/Closable.swift | 8 +++++++ Sources/ScopeRegistry.swift | 6 +++++ Swinject.xcodeproj/project.pbxproj | 4 ++++ Tests/Support/GeneratedMocks.swift | 16 +++++++++++++ .../UnitSpecs/StandardScopeRegistrySpec.swift | 24 +++++++++++++++++-- 5 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 Sources/Closable.swift diff --git a/Sources/Closable.swift b/Sources/Closable.swift new file mode 100644 index 00000000..6837eabd --- /dev/null +++ b/Sources/Closable.swift @@ -0,0 +1,8 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +// sourcery: AutoMockable +public protocol Closable { + func close() +} diff --git a/Sources/ScopeRegistry.swift b/Sources/ScopeRegistry.swift index 32ba5412..7f35d8bd 100644 --- a/Sources/ScopeRegistry.swift +++ b/Sources/ScopeRegistry.swift @@ -18,4 +18,10 @@ public class StandardScopeRegistry: ScopeRegistry { public func instance(for key: ScopeRegistryKey) -> Any? { entries[key]?.last } + + deinit { + entries.values + .flatMap { $0 } + .forEach { ($0 as? Closable)?.close() } + } } diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 7d41718e..fc694ef8 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -47,6 +47,7 @@ CDD8381B22DA4CBE003E9909 /* SwinjectSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381922DA4C9F003E9909 /* SwinjectSpec.swift */; }; CDD8381D22DA4E02003E9909 /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381C22DA4E02003E9909 /* SwinjectError.swift */; }; CDD8381F22DA4F6F003E9909 /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD8381E22DA4F6F003E9909 /* Bridge.swift */; }; + CDE19EC022E0D3A200981365 /* Closable.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE19EBF22E0D3A200981365 /* Closable.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -106,6 +107,7 @@ CDD8381922DA4C9F003E9909 /* SwinjectSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectSpec.swift; sourceTree = ""; }; CDD8381C22DA4E02003E9909 /* SwinjectError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectError.swift; sourceTree = ""; }; CDD8381E22DA4F6F003E9909 /* Bridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bridge.swift; sourceTree = ""; }; + CDE19EBF22E0D3A200981365 /* Closable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Closable.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -175,6 +177,7 @@ 7723ABD622E095460067D423 /* ScopeRegistry.swift */, 7755159C22E0B3C2004BF092 /* ScopeRegistryKey.swift */, 7723ABDE22E0A9FD0067D423 /* Matchable.swift */, + CDE19EBF22E0D3A200981365 /* Closable.swift */, ); path = Sources; sourceTree = ""; @@ -421,6 +424,7 @@ 7723ABDF22E0A9FD0067D423 /* Matchable.swift in Sources */, 7755159D22E0B3C2004BF092 /* ScopeRegistryKey.swift in Sources */, CD6DE55322DF94ED00532D08 /* BinderEnvironment.swift in Sources */, + CDE19EC022E0D3A200981365 /* Closable.swift in Sources */, 7723ABD722E095460067D423 /* ScopeRegistry.swift in Sources */, CDD8381622DA4B55003E9909 /* Swinject.swift in Sources */, CDD8380522DA307F003E9909 /* TypeBinder.swift in Sources */, diff --git a/Tests/Support/GeneratedMocks.swift b/Tests/Support/GeneratedMocks.swift index e34fa2ff..0dd29163 100644 --- a/Tests/Support/GeneratedMocks.swift +++ b/Tests/Support/GeneratedMocks.swift @@ -218,6 +218,22 @@ class BindingMock: Binding { } } +class ClosableMock: Closable { + // MARK: - close + + var closeCallsCount = 0 + var closeCalled: Bool { + return closeCallsCount > 0 + } + + var closeClosure: (() -> Void)? + + func close() { + closeCallsCount += 1 + closeClosure?() + } +} + class MatchableMock: Matchable { var hashValue: Int { get { return underlyingHashValue } diff --git a/Tests/UnitSpecs/StandardScopeRegistrySpec.swift b/Tests/UnitSpecs/StandardScopeRegistrySpec.swift index 84994820..b7310e87 100644 --- a/Tests/UnitSpecs/StandardScopeRegistrySpec.swift +++ b/Tests/UnitSpecs/StandardScopeRegistrySpec.swift @@ -8,8 +8,8 @@ import Quick class StandardScopeRegistrySpec: QuickSpec { override func spec() { var registry: StandardScopeRegistry! - let person = Array(1 ... 3).map { _ in Person() } - let key = Array(1 ... 3).map { ScopeRegistryKey(descriptor: plain(Int.self), argument: AnyMatchable($0)) } + let person = (1 ... 3).map { _ in Person() } + let key = (1 ... 3).map { ScopeRegistryKey(descriptor: plain(Int.self), argument: AnyMatchable($0)) } beforeEach { registry = StandardScopeRegistry() } @@ -50,4 +50,24 @@ class StandardScopeRegistrySpec: QuickSpec { override func spec() { expect(weakRef).notTo(beNil()) } } + describe("deinit") { + var closable = [ClosableMock]() + beforeEach { + closable = (1 ... 3).map { _ in ClosableMock() } + } + it("closes all instances registered for single key") { + registry.register(closable[0], for: key[0]) + registry.register(closable[1], for: key[0]) + registry = nil + expect(closable[0].closeCalled).to(beTrue()) + expect(closable[1].closeCalled).to(beTrue()) + } + it("closes instances registered for all keys") { + registry.register(closable[0], for: key[0]) + registry.register(closable[1], for: key[1]) + registry = nil + expect(closable[0].closeCalled).to(beTrue()) + expect(closable[1].closeCalled).to(beTrue()) + } + } } } From cdcf69cfad4bfaa2359cc82e0d00e1341d7cc521 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Thu, 18 Jul 2019 21:19:48 +0200 Subject: [PATCH 075/239] Reimplement scoped binding --- Sources/Scope.swift | 7 --- Sources/ScopeRegistry.swift | 20 +------ Sources/ScopedBinding.swift | 14 ++--- Tests/Support/GeneratedMocks.swift | 51 +++++------------ Tests/Support/NonGeneratedMocks.swift | 19 +++++-- Tests/UnitSpecs/ScopedBindingSpec.swift | 56 +++++------------- .../UnitSpecs/StandardScopeRegistrySpec.swift | 57 ------------------- 7 files changed, 47 insertions(+), 177 deletions(-) diff --git a/Sources/Scope.swift b/Sources/Scope.swift index 33dcf330..eebe7a5f 100644 --- a/Sources/Scope.swift +++ b/Sources/Scope.swift @@ -4,7 +4,6 @@ // sourcery: AutoMockable public protocol AnyScope { - var lock: Lock { get } func registry(for context: Any) -> ScopeRegistry } @@ -19,15 +18,9 @@ extension Scope { } } -public protocol Lock { - func sync(_ action: () throws -> T) rethrows -> T -} - public class ImplicitScope: Scope { public typealias Context = Any - public var lock: Lock { fatalError() } - public func registry(for _: Any) -> ScopeRegistry { fatalError() } diff --git a/Sources/ScopeRegistry.swift b/Sources/ScopeRegistry.swift index 7f35d8bd..4214b577 100644 --- a/Sources/ScopeRegistry.swift +++ b/Sources/ScopeRegistry.swift @@ -2,26 +2,12 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -// sourcery: AutoMockable public protocol ScopeRegistry { - func register(_ instance: Any, for key: ScopeRegistryKey) - func instance(for key: ScopeRegistryKey) -> Any? + func instance(for key: ScopeRegistryKey, builder: () throws -> Any) rethrows -> Any } public class StandardScopeRegistry: ScopeRegistry { - private var entries = [ScopeRegistryKey: [Any]]() - - public func register(_ instance: Any, for key: ScopeRegistryKey) { - entries[key, default: []].append(instance) - } - - public func instance(for key: ScopeRegistryKey) -> Any? { - entries[key]?.last - } - - deinit { - entries.values - .flatMap { $0 } - .forEach { ($0 as? Closable)?.close() } + public func instance(for _: ScopeRegistryKey, builder _: () throws -> Any) rethrows -> Any { + fatalError() } } diff --git a/Sources/ScopedBinding.swift b/Sources/ScopedBinding.swift index be40c626..928190a9 100644 --- a/Sources/ScopedBinding.swift +++ b/Sources/ScopedBinding.swift @@ -14,17 +14,11 @@ extension ScopedBinding: Binding { } public func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any { - try scope.lock.sync { - let registry = scope.registry(for: context) - let key = ScopeRegistryKey(descriptor: self.key.descriptor, argument: arg) - if let instance = registry.instance(for: key) as Any? { - return instance - } else { - let newInstance = try maker.makeInstance(arg: arg, context: context, resolver: resolver) - registry.register(newInstance, for: key) - return newInstance + try scope + .registry(for: context) + .instance(for: ScopeRegistryKey(descriptor: key.descriptor, argument: arg)) { + try maker.makeInstance(arg: arg, context: context, resolver: resolver) } - } } } diff --git a/Tests/Support/GeneratedMocks.swift b/Tests/Support/GeneratedMocks.swift index 0dd29163..4dc3740e 100644 --- a/Tests/Support/GeneratedMocks.swift +++ b/Tests/Support/GeneratedMocks.swift @@ -119,13 +119,6 @@ class AnyResolverMock: AnyResolver { } class AnyScopeMock: AnyScope { - var lock: Lock { - get { return underlyingLock } - set(value) { underlyingLock = value } - } - - var underlyingLock: Lock! - // MARK: - registry var registryForCallsCount = 0 @@ -264,41 +257,23 @@ class MatchableMock: Matchable { class ModuleIncludeEntryMock: ModuleIncludeEntry {} -class ScopeRegistryMock: ScopeRegistry { - // MARK: - register - - var registerForCallsCount = 0 - var registerForCalled: Bool { - return registerForCallsCount > 0 - } - - var registerForReceivedArguments: (instance: Any, key: ScopeRegistryKey)? - var registerForReceivedInvocations: [(instance: Any, key: ScopeRegistryKey)] = [] - var registerForClosure: ((Any, ScopeRegistryKey) -> Void)? - - func register(_ instance: Any, for key: ScopeRegistryKey) { - registerForCallsCount += 1 - registerForReceivedArguments = (instance: instance, key: key) - registerForReceivedInvocations.append((instance: instance, key: key)) - registerForClosure?(instance, key) - } - +class StaticScopeRegistryMock: StaticScopeRegistry { // MARK: - instance - var instanceForCallsCount = 0 - var instanceForCalled: Bool { - return instanceForCallsCount > 0 + var instanceKeyCallsCount = 0 + var instanceKeyCalled: Bool { + return instanceKeyCallsCount > 0 } - var instanceForReceivedKey: ScopeRegistryKey? - var instanceForReceivedInvocations: [ScopeRegistryKey] = [] - var instanceForReturnValue: Any? - var instanceForClosure: ((ScopeRegistryKey) -> Any?)? + var instanceKeyReceivedKey: ScopeRegistryKey? + var instanceKeyReceivedInvocations: [ScopeRegistryKey] = [] + var instanceKeyReturnValue: Any! + var instanceKeyClosure: ((ScopeRegistryKey) -> Any)? - func instance(for key: ScopeRegistryKey) -> Any? { - instanceForCallsCount += 1 - instanceForReceivedKey = key - instanceForReceivedInvocations.append(key) - return instanceForClosure.map { $0(key) } ?? instanceForReturnValue + func instance(key: ScopeRegistryKey) -> Any { + instanceKeyCallsCount += 1 + instanceKeyReceivedKey = key + instanceKeyReceivedInvocations.append(key) + return instanceKeyClosure.map { $0(key) } ?? instanceKeyReturnValue } } diff --git a/Tests/Support/NonGeneratedMocks.swift b/Tests/Support/NonGeneratedMocks.swift index 537a8b3f..83eafa82 100644 --- a/Tests/Support/NonGeneratedMocks.swift +++ b/Tests/Support/NonGeneratedMocks.swift @@ -40,7 +40,6 @@ extension AnyScopeMock: Scope { } class DummyScope: Scope { - var lock: Lock { fatalError() } func registry(for _: Context) -> ScopeRegistry { fatalError() } } @@ -57,11 +56,19 @@ extension AnyBindningMakerMock: BindingMaker { } } -class ReplayLock: Lock { - var syncCallsCount = 0 +// sourcery: AutoMockable +protocol StaticScopeRegistry { + func instance(key: ScopeRegistryKey) -> Any +} + +extension StaticScopeRegistryMock: ScopeRegistry { + func instance(for key: ScopeRegistryKey, builder _: () throws -> Any) rethrows -> Any { + instance(key: key) + } +} - func sync(_ action: () throws -> T) rethrows -> T { - syncCallsCount += 1 - return try action() +struct BuilderScopeRegistry: ScopeRegistry { + func instance(for _: ScopeRegistryKey, builder: () throws -> Any) rethrows -> Any { + try builder() } } diff --git a/Tests/UnitSpecs/ScopedBindingSpec.swift b/Tests/UnitSpecs/ScopedBindingSpec.swift index a4adaf69..1e324db3 100644 --- a/Tests/UnitSpecs/ScopedBindingSpec.swift +++ b/Tests/UnitSpecs/ScopedBindingSpec.swift @@ -51,29 +51,33 @@ class ScopedBindingSpec: QuickSpec { override func spec() { } describe("instance") { var key = AnyBindingKeyMock() - var lock = ReplayLock() - var registry = ScopeRegistryMock() + var registry = StaticScopeRegistryMock() var scope = AnyScopeMock() var maker = AnyInstanceMakerMock() var binding: ScopedBinding! beforeEach { - lock = ReplayLock() - registry = ScopeRegistryMock() + registry = StaticScopeRegistryMock() scope = AnyScopeMock() - scope.lock = lock scope.registryForReturnValue = registry maker = AnyInstanceMakerMock() key = AnyBindingKeyMock() key.descriptor = AnyTypeDescriptorMock() binding = ScopedBinding(key: key, maker: maker, scope: scope) } - it("syncs using scope's lock") { - _ = try? binding.instance(arg: (), context: (), resolver: DummyResolver()) - expect(lock.syncCallsCount) == 1 + it("retrieves registry using passed context") { + _ = try? binding.instance(arg: (), context: "context", resolver: DummyResolver()) + expect(scope.registryForReceivedContext as? String) == "context" } - context("no instance in registry") { + it("retrieves instance from registry using a correct key") { + let descriptor = AnyTypeDescriptorMock() + key.descriptor = descriptor + _ = try? binding.instance(arg: 42, context: (), resolver: DummyResolver()) + expect(registry.instanceKeyReceivedKey?.argument as? Int) == 42 + expect(registry.instanceKeyReceivedKey?.descriptor) === descriptor + } + context("instance builder") { beforeEach { - registry.instanceForReturnValue = nil + scope.registryForReturnValue = BuilderScopeRegistry() } it("returns instance produced by maker") { maker.makeInstanceArgContextResolverReturnValue = 42 @@ -86,11 +90,6 @@ class ScopedBindingSpec: QuickSpec { override func spec() { try binding.instance(arg: (), context: (), resolver: DummyResolver()) }.to(throwError(errorType: TestError.self)) } - it("puts made instance into registry") { - maker.makeInstanceArgContextResolverReturnValue = 42 - _ = try? binding.instance(arg: (), context: (), resolver: DummyResolver()) - expect(registry.registerForReceivedArguments?.instance as? Int) == 42 - } it("invokes maker with correct parameters") { let resolver = DummyResolver() _ = try? binding.instance(arg: 42, context: "context", resolver: resolver) @@ -98,33 +97,6 @@ class ScopedBindingSpec: QuickSpec { override func spec() { expect(maker.makeInstanceArgContextResolverReceivedArguments?.context as? String) == "context" expect(maker.makeInstanceArgContextResolverReceivedArguments?.resolver) === resolver } - it("puts instance into registry using a correct key") { - let descriptor = AnyTypeDescriptorMock() - key.descriptor = descriptor - _ = try? binding.instance(arg: 42, context: (), resolver: DummyResolver()) - expect(registry.registerForReceivedArguments?.key.argument as? Int) == 42 - expect(registry.registerForReceivedArguments?.key.descriptor) === descriptor - } - } - context("instance in registry") { - beforeEach { - registry.instanceForReturnValue = 42 - } - it("returns instance from registry") { - let instance = try? binding.instance(arg: (), context: (), resolver: DummyResolver()) as? Int - expect(instance) == 42 - } - } - it("retrieves registry using passed context") { - _ = try? binding.instance(arg: (), context: "context", resolver: DummyResolver()) - expect(scope.registryForReceivedContext as? String) == "context" - } - it("retrieves instance from registry using a correct key") { - let descriptor = AnyTypeDescriptorMock() - key.descriptor = descriptor - _ = try? binding.instance(arg: 42, context: (), resolver: DummyResolver()) - expect(registry.instanceForReceivedKey?.argument as? Int) == 42 - expect(registry.instanceForReceivedKey?.descriptor) === descriptor } } } } diff --git a/Tests/UnitSpecs/StandardScopeRegistrySpec.swift b/Tests/UnitSpecs/StandardScopeRegistrySpec.swift index b7310e87..bfaf3245 100644 --- a/Tests/UnitSpecs/StandardScopeRegistrySpec.swift +++ b/Tests/UnitSpecs/StandardScopeRegistrySpec.swift @@ -13,61 +13,4 @@ class StandardScopeRegistrySpec: QuickSpec { override func spec() { beforeEach { registry = StandardScopeRegistry() } - describe("empty") { - it("returns no instance") { - expect(registry.instance(for: key[0])).to(beNil()) - } - } - describe("single intance") { - beforeEach { - registry.register(person[0], for: key[0]) - } - it("returns instance for correct key") { - expect(registry.instance(for: key[0])) === person[0] - } - it("returns no instance for incorrect key") { - expect(registry.instance(for: key[1])).to(beNil()) - } - } - describe("multiple intances") { - it("returns different instances for different keys") { - registry.register(person[0], for: key[0]) - registry.register(person[1], for: key[1]) - expect(registry.instance(for: key[0])) === person[0] - expect(registry.instance(for: key[1])) === person[1] - } - it("returns the last instance registered for the key") { - registry.register(person[0], for: key[0]) - registry.register(person[1], for: key[0]) - expect(registry.instance(for: key[0])) === person[1] - } - it("should keep references to all registerd instances") { - var aPerson = Person() as Person? - weak var weakRef = aPerson - registry.register(aPerson!, for: key[0]) - registry.register(person[0], for: key[0]) - aPerson = nil - expect(weakRef).notTo(beNil()) - } - } - describe("deinit") { - var closable = [ClosableMock]() - beforeEach { - closable = (1 ... 3).map { _ in ClosableMock() } - } - it("closes all instances registered for single key") { - registry.register(closable[0], for: key[0]) - registry.register(closable[1], for: key[0]) - registry = nil - expect(closable[0].closeCalled).to(beTrue()) - expect(closable[1].closeCalled).to(beTrue()) - } - it("closes instances registered for all keys") { - registry.register(closable[0], for: key[0]) - registry.register(closable[1], for: key[1]) - registry = nil - expect(closable[0].closeCalled).to(beTrue()) - expect(closable[1].closeCalled).to(beTrue()) - } - } } } From 4a384c9230ec0e6c98bc474c63192dced0554e48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Thu, 18 Jul 2019 22:57:27 +0200 Subject: [PATCH 076/239] Reimplement standard scope registry --- Sources/ScopeRegistry.swift | 38 +++++++- Tests/Support/Convenience.swift | 12 +++ .../UnitSpecs/StandardScopeRegistrySpec.swift | 87 ++++++++++++++++++- 3 files changed, 132 insertions(+), 5 deletions(-) diff --git a/Sources/ScopeRegistry.swift b/Sources/ScopeRegistry.swift index 4214b577..4a6d78ff 100644 --- a/Sources/ScopeRegistry.swift +++ b/Sources/ScopeRegistry.swift @@ -2,12 +2,44 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // +import Foundation + public protocol ScopeRegistry { func instance(for key: ScopeRegistryKey, builder: () throws -> Any) rethrows -> Any } -public class StandardScopeRegistry: ScopeRegistry { - public func instance(for _: ScopeRegistryKey, builder _: () throws -> Any) rethrows -> Any { - fatalError() +public class StandardScopeRegistry: ScopeRegistry, Closable { + private let lock = NSRecursiveLock() + private var instances = [ScopeRegistryKey: Any]() + + public func instance(for key: ScopeRegistryKey, builder: () throws -> Any) rethrows -> Any { + try lock.sync { + if let instance = instances[key] { + return instance + } else { + let newInstance = try builder() + instances[key] = newInstance + return newInstance + } + } + } + + public func close() { + lock.sync { + instances.values.forEach { ($0 as? Closable)?.close() } + instances.removeAll() + } + } + + deinit { + close() + } +} + +extension NSLocking { + func sync(_ action: () throws -> T) rethrows -> T { + lock() + defer { unlock() } + return try action() } } diff --git a/Tests/Support/Convenience.swift b/Tests/Support/Convenience.swift index 4d09d1ca..783b0887 100644 --- a/Tests/Support/Convenience.swift +++ b/Tests/Support/Convenience.swift @@ -2,6 +2,7 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // +import Nimble @testable import Swinject extension InstanceMaker where Argument == Void, Context == Any { @@ -21,3 +22,14 @@ extension InstanceMaker where Context == Any { try makeInstance(arg: arg, context: (), resolver: resolver) } } + +func concurrentPerform(iterations: Int, action: () -> Void) { + var finished = 0 + DispatchQueue.concurrentPerform(iterations: iterations) { _ in + action() + finished += 1 + } + waitUntil { done in + if finished == iterations { done() } + } +} diff --git a/Tests/UnitSpecs/StandardScopeRegistrySpec.swift b/Tests/UnitSpecs/StandardScopeRegistrySpec.swift index bfaf3245..4527b81e 100644 --- a/Tests/UnitSpecs/StandardScopeRegistrySpec.swift +++ b/Tests/UnitSpecs/StandardScopeRegistrySpec.swift @@ -8,9 +8,92 @@ import Quick class StandardScopeRegistrySpec: QuickSpec { override func spec() { var registry: StandardScopeRegistry! - let person = (1 ... 3).map { _ in Person() } - let key = (1 ... 3).map { ScopeRegistryKey(descriptor: plain(Int.self), argument: AnyMatchable($0)) } + let key = (1 ... 5).map { ScopeRegistryKey(descriptor: plain(Int.self), argument: AnyMatchable($0)) } beforeEach { registry = StandardScopeRegistry() } + describe("instance") { + var builderCallCount = 0 + let countingBuilder: () -> Any = { builderCallCount += 1; return 0 } + beforeEach { + builderCallCount = 0 + } + it("calls builder on first invocation for key") { + _ = registry.instance(for: key[0], builder: countingBuilder) + expect(builderCallCount) == 1 + } + it("calls builder only once for each key") { + _ = registry.instance(for: key[0], builder: countingBuilder) + _ = registry.instance(for: key[1], builder: countingBuilder) + _ = registry.instance(for: key[0], builder: countingBuilder) + _ = registry.instance(for: key[1], builder: countingBuilder) + expect(builderCallCount) == 2 + } + it("rethtrows error from builder") { + expect { + try registry.instance(for: key[0]) { throw TestError() } + }.to(throwError(errorType: TestError.self)) + } + it("returns result of builder for first invocation") { + expect(registry.instance(for: key[0]) { 42 } as? Int) == 42 + } + it("returns result of builder on second invocation") { + _ = registry.instance(for: key[0]) { 42 } + _ = registry.instance(for: key[1]) { 25 } + expect(registry.instance(for: key[0]) { 0 } as? Int) == 42 + expect(registry.instance(for: key[1]) { 0 } as? Int) == 25 + } + } + describe("closable") { + var closable = [ClosableMock]() + beforeEach { + closable = (1 ... 3).map { _ in ClosableMock() } + } + it("does not close instance before deinit") { + _ = registry.instance(for: key[0]) { closable[0] } + expect(closable[0].closeCallsCount) == 0 + } + it("closes instances when closed") { + _ = registry.instance(for: key[0]) { closable[0] } + _ = registry.instance(for: key[1]) { closable[1] } + registry.close() + expect(closable[0].closeCallsCount) == 1 + expect(closable[1].closeCallsCount) == 1 + } + it("closes instances on deinit") { + _ = registry.instance(for: key[0]) { closable[0] } + _ = registry.instance(for: key[1]) { closable[1] } + registry = nil + expect(closable[0].closeCallsCount) == 1 + expect(closable[1].closeCallsCount) == 1 + } + it("releases instance references when closed") { + var person: Person? = Person() + weak var weakRef = person + _ = registry.instance(for: key[0]) { person! } + registry.close() + person = nil + expect(weakRef).to(beNil()) + } + } + describe("concurrency") { + it("calls builder only once when invoked concurrently multiple times") { + var builderCallCount = 0 + concurrentPerform(iterations: 5) { + _ = registry.instance(for: key[0]) { + Thread.sleep(forTimeInterval: 0.1) + builderCallCount += 1 + return 0 + } + } + expect(builderCallCount) == 1 + } + it("closes instance only once when closed concurrently multiple times") { + let closable = ClosableMock() + closable.closeClosure = { Thread.sleep(forTimeInterval: 0.1) } + _ = registry.instance(for: key[0]) { closable } + concurrentPerform(iterations: 5, action: registry.close) + expect(closable.closeCallsCount) == 1 + } + } } } From 743c79919dfdc231a2393e5e546afc9babcdcf0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Thu, 18 Jul 2019 23:29:54 +0200 Subject: [PATCH 077/239] Implement unbounded scope --- Sources/BinderEnvironment.swift | 28 ++++++------- Sources/Scope.swift | 18 ++++++-- Sources/ScopeRegistry.swift | 9 ++-- Swinject.xcodeproj/project.pbxproj | 4 ++ Tests/Support/GeneratedMocks.swift | 14 +++++++ Tests/Support/NonGeneratedMocks.swift | 3 ++ Tests/UnitSpecs/BinderEnvironmentSpec.swift | 4 +- .../UnitSpecs/StandardScopeRegistrySpec.swift | 41 +++++++++++++------ Tests/UnitSpecs/UnboundScopeSpec.swift | 33 +++++++++++++++ 9 files changed, 119 insertions(+), 35 deletions(-) create mode 100644 Tests/UnitSpecs/UnboundScopeSpec.swift diff --git a/Sources/BinderEnvironment.swift b/Sources/BinderEnvironment.swift index c7103cf1..326be52f 100644 --- a/Sources/BinderEnvironment.swift +++ b/Sources/BinderEnvironment.swift @@ -110,30 +110,30 @@ public func factory(_ builder: @escaping (Re SimpleBinding.Builder { try builder($0, $2.0, $2.1, $2.2, $2.3, $2.4) } } -public func singleton(_ builder: @escaping () throws -> Type) -> ScopedBinding.Builder { - .init(.implicit) { _, _, _ in try builder() } +public func singleton(_ builder: @escaping () throws -> Type) -> ScopedBinding.Builder { + .init(.root) { _, _, _ in try builder() } } -public func singleton(_ builder: @escaping (Resolver) throws -> Type) -> ScopedBinding.Builder { - .init(.implicit) { r, _, _ in try builder(r) } +public func singleton(_ builder: @escaping (Resolver) throws -> Type) -> ScopedBinding.Builder { + .init(.root) { r, _, _ in try builder(r) } } -public func multiton(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> ScopedBinding.Builder { - .init(.implicit) { try builder($0, $2) } +public func multiton(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> ScopedBinding.Builder { + .init(.root) { try builder($0, $2) } } -public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> ScopedBinding.Builder { - .init(.implicit) { try builder($0, $2.0, $2.1) } +public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> ScopedBinding.Builder { + .init(.root) { try builder($0, $2.0, $2.1) } } -public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> ScopedBinding.Builder { - .init(.implicit) { try builder($0, $2.0, $2.1, $2.2) } +public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> ScopedBinding.Builder { + .init(.root) { try builder($0, $2.0, $2.1, $2.2) } } -public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> ScopedBinding.Builder { - .init(.implicit) { try builder($0, $2.0, $2.1, $2.2, $2.3) } +public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> ScopedBinding.Builder { + .init(.root) { try builder($0, $2.0, $2.1, $2.2, $2.3) } } -public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> ScopedBinding.Builder { - .init(.implicit) { try builder($0, $2.0, $2.1, $2.2, $2.3, $2.4) } +public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> ScopedBinding.Builder { + .init(.root) { try builder($0, $2.0, $2.1, $2.2, $2.3, $2.4) } } diff --git a/Sources/Scope.swift b/Sources/Scope.swift index eebe7a5f..614a4898 100644 --- a/Sources/Scope.swift +++ b/Sources/Scope.swift @@ -18,14 +18,24 @@ extension Scope { } } -public class ImplicitScope: Scope { +public class UnboundScope: Scope, Closable { public typealias Context = Any + private let _registry: ScopeRegistry + + public init(registry: ScopeRegistry = StandardScopeRegistry()) { + _registry = registry + } + public func registry(for _: Any) -> ScopeRegistry { - fatalError() + _registry + } + + public func close() { + _registry.clear() } } -extension ImplicitScope { - static let implicit = ImplicitScope() +extension UnboundScope { + static let root = UnboundScope() } diff --git a/Sources/ScopeRegistry.swift b/Sources/ScopeRegistry.swift index 4a6d78ff..e5da7532 100644 --- a/Sources/ScopeRegistry.swift +++ b/Sources/ScopeRegistry.swift @@ -6,12 +6,15 @@ import Foundation public protocol ScopeRegistry { func instance(for key: ScopeRegistryKey, builder: () throws -> Any) rethrows -> Any + func clear() } public class StandardScopeRegistry: ScopeRegistry, Closable { private let lock = NSRecursiveLock() private var instances = [ScopeRegistryKey: Any]() + public init() {} + public func instance(for key: ScopeRegistryKey, builder: () throws -> Any) rethrows -> Any { try lock.sync { if let instance = instances[key] { @@ -31,9 +34,9 @@ public class StandardScopeRegistry: ScopeRegistry, Closable { } } - deinit { - close() - } + public func clear() { close() } + + deinit { close() } } extension NSLocking { diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index fc694ef8..72129294 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -19,6 +19,7 @@ 775515A022E0BE79004BF092 /* TaggedTypeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7755159E22E0BE62004BF092 /* TaggedTypeSpec.swift */; }; 77729C9E22DCCA20005C3281 /* InjectionApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77729C9D22DCCA20005C3281 /* InjectionApiSpec.swift */; }; 77906E7D22DF6A8D009CDCF4 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77906E7C22DF6A8D009CDCF4 /* Convenience.swift */; }; + CD086B1522E1162E00FC9E50 /* UnboundScopeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD086B1422E1162E00FC9E50 /* UnboundScopeSpec.swift */; }; CD6DE53522DD1C7300532D08 /* BindingKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53322DD1C6800532D08 /* BindingKeySpec.swift */; }; CD6DE53722DD1CE900532D08 /* BindingKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53622DD1CE900532D08 /* BindingKey.swift */; }; CD6DE53922DD1D0A00532D08 /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53822DD1D0A00532D08 /* InstanceRequest.swift */; }; @@ -76,6 +77,7 @@ 7755159E22E0BE62004BF092 /* TaggedTypeSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaggedTypeSpec.swift; sourceTree = ""; }; 77729C9D22DCCA20005C3281 /* InjectionApiSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InjectionApiSpec.swift; sourceTree = ""; }; 77906E7C22DF6A8D009CDCF4 /* Convenience.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Convenience.swift; sourceTree = ""; }; + CD086B1422E1162E00FC9E50 /* UnboundScopeSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnboundScopeSpec.swift; sourceTree = ""; }; CD6DE53322DD1C6800532D08 /* BindingKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingKeySpec.swift; sourceTree = ""; }; CD6DE53622DD1CE900532D08 /* BindingKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingKey.swift; sourceTree = ""; }; CD6DE53822DD1D0A00532D08 /* InstanceRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRequest.swift; sourceTree = ""; }; @@ -228,6 +230,7 @@ 7723ABD822E0961B0067D423 /* StandardScopeRegistrySpec.swift */, 7723ABDB22E097950067D423 /* ScopeRegistryKeySpec.swift */, 7755159E22E0BE62004BF092 /* TaggedTypeSpec.swift */, + CD086B1422E1162E00FC9E50 /* UnboundScopeSpec.swift */, ); path = UnitSpecs; sourceTree = ""; @@ -450,6 +453,7 @@ CD6DE53522DD1C7300532D08 /* BindingKeySpec.swift in Sources */, CD6DE55522DFB2A600532D08 /* BinderEnvironmentSpec.swift in Sources */, 7723ABDA22E0962C0067D423 /* StandardScopeRegistrySpec.swift in Sources */, + CD086B1522E1162E00FC9E50 /* UnboundScopeSpec.swift in Sources */, 7723ABDD22E0979E0067D423 /* ScopeRegistryKeySpec.swift in Sources */, CDADF33722DB753800C5D8DB /* TestModels.swift in Sources */, 77729C9E22DCCA20005C3281 /* InjectionApiSpec.swift in Sources */, diff --git a/Tests/Support/GeneratedMocks.swift b/Tests/Support/GeneratedMocks.swift index 4dc3740e..b4e8b469 100644 --- a/Tests/Support/GeneratedMocks.swift +++ b/Tests/Support/GeneratedMocks.swift @@ -276,4 +276,18 @@ class StaticScopeRegistryMock: StaticScopeRegistry { instanceKeyReceivedInvocations.append(key) return instanceKeyClosure.map { $0(key) } ?? instanceKeyReturnValue } + + // MARK: - clear + + var clearCallsCount = 0 + var clearCalled: Bool { + return clearCallsCount > 0 + } + + var clearClosure: (() -> Void)? + + func clear() { + clearCallsCount += 1 + clearClosure?() + } } diff --git a/Tests/Support/NonGeneratedMocks.swift b/Tests/Support/NonGeneratedMocks.swift index 83eafa82..95916080 100644 --- a/Tests/Support/NonGeneratedMocks.swift +++ b/Tests/Support/NonGeneratedMocks.swift @@ -59,6 +59,7 @@ extension AnyBindningMakerMock: BindingMaker { // sourcery: AutoMockable protocol StaticScopeRegistry { func instance(key: ScopeRegistryKey) -> Any + func clear() } extension StaticScopeRegistryMock: ScopeRegistry { @@ -71,4 +72,6 @@ struct BuilderScopeRegistry: ScopeRegistry { func instance(for _: ScopeRegistryKey, builder: () throws -> Any) rethrows -> Any { try builder() } + + func clear() {} } diff --git a/Tests/UnitSpecs/BinderEnvironmentSpec.swift b/Tests/UnitSpecs/BinderEnvironmentSpec.swift index 31d09db9..188496ad 100644 --- a/Tests/UnitSpecs/BinderEnvironmentSpec.swift +++ b/Tests/UnitSpecs/BinderEnvironmentSpec.swift @@ -114,7 +114,7 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { describe("singleton") { it("has correct scope") { let maker = singleton { 42 } - expect(maker.scope) === ImplicitScope.implicit + expect(maker.scope) === UnboundScope.root } it("returns instance made by builder") { let maker = singleton { 42 } @@ -146,7 +146,7 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { describe("multiton") { it("has correct scope") { let maker = multiton { (_, _: Void) in 42 } - expect(maker.scope) === ImplicitScope.implicit + expect(maker.scope) === UnboundScope.root } it("returns instance made by builder method") { let maker = multiton { (_, _: Void) in 42 } diff --git a/Tests/UnitSpecs/StandardScopeRegistrySpec.swift b/Tests/UnitSpecs/StandardScopeRegistrySpec.swift index 4527b81e..2a87be18 100644 --- a/Tests/UnitSpecs/StandardScopeRegistrySpec.swift +++ b/Tests/UnitSpecs/StandardScopeRegistrySpec.swift @@ -9,7 +9,9 @@ import Quick class StandardScopeRegistrySpec: QuickSpec { override func spec() { var registry: StandardScopeRegistry! let key = (1 ... 5).map { ScopeRegistryKey(descriptor: plain(Int.self), argument: AnyMatchable($0)) } + var closable = [ClosableMock]() beforeEach { + closable = (1 ... 3).map { _ in ClosableMock() } registry = StandardScopeRegistry() } describe("instance") { @@ -44,12 +46,25 @@ class StandardScopeRegistrySpec: QuickSpec { override func spec() { expect(registry.instance(for: key[1]) { 0 } as? Int) == 25 } } - describe("closable") { - var closable = [ClosableMock]() - beforeEach { - closable = (1 ... 3).map { _ in ClosableMock() } + describe("clear") { + it("closes instances when cleared") { + _ = registry.instance(for: key[0]) { closable[0] } + _ = registry.instance(for: key[1]) { closable[1] } + registry.clear() + expect(closable[0].closeCallsCount) == 1 + expect(closable[1].closeCallsCount) == 1 } - it("does not close instance before deinit") { + it("releases instance references when cleared") { + var person: Person? = Person() + weak var weakRef = person + _ = registry.instance(for: key[0]) { person! } + registry.clear() + person = nil + expect(weakRef).to(beNil()) + } + } + describe("closable") { + it("does not close instance by default") { _ = registry.instance(for: key[0]) { closable[0] } expect(closable[0].closeCallsCount) == 0 } @@ -60,13 +75,6 @@ class StandardScopeRegistrySpec: QuickSpec { override func spec() { expect(closable[0].closeCallsCount) == 1 expect(closable[1].closeCallsCount) == 1 } - it("closes instances on deinit") { - _ = registry.instance(for: key[0]) { closable[0] } - _ = registry.instance(for: key[1]) { closable[1] } - registry = nil - expect(closable[0].closeCallsCount) == 1 - expect(closable[1].closeCallsCount) == 1 - } it("releases instance references when closed") { var person: Person? = Person() weak var weakRef = person @@ -76,6 +84,15 @@ class StandardScopeRegistrySpec: QuickSpec { override func spec() { expect(weakRef).to(beNil()) } } + describe("deinit") { + it("closes instances on deinit") { + _ = registry.instance(for: key[0]) { closable[0] } + _ = registry.instance(for: key[1]) { closable[1] } + registry = nil + expect(closable[0].closeCallsCount) == 1 + expect(closable[1].closeCallsCount) == 1 + } + } describe("concurrency") { it("calls builder only once when invoked concurrently multiple times") { var builderCallCount = 0 diff --git a/Tests/UnitSpecs/UnboundScopeSpec.swift b/Tests/UnitSpecs/UnboundScopeSpec.swift new file mode 100644 index 00000000..bd3a9851 --- /dev/null +++ b/Tests/UnitSpecs/UnboundScopeSpec.swift @@ -0,0 +1,33 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +import Nimble +import Quick +@testable import Swinject + +class UnboundScopeSpec: QuickSpec { override func spec() { + var registry = StaticScopeRegistryMock() + var scope: UnboundScope! + beforeEach { + registry = StaticScopeRegistryMock() + scope = UnboundScope(registry: registry) + } + describe("registry") { + it("returns passed registry") { + expect(scope.registry(for: 0)) === registry + } + it("uses standard registry by default") { + expect(UnboundScope().registry(for: 0) is StandardScopeRegistry) == true + } + } + describe("closable") { + it("clears passed registry when closed") { + scope.close() + expect(registry.clearCallsCount) == 1 + } + it("does not clear registry until closed") { + expect(registry.clearCallsCount) == 0 + } + } +} } From 291b4aebde84d02337cacc7a4879b4e9cfc365f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Thu, 18 Jul 2019 23:59:38 +0200 Subject: [PATCH 078/239] Describe singleton API --- Sources/ScopeRegistryKey.swift | 20 +++++++++--- Tests/ApiSpecs/InjectionApiSpec.swift | 37 ++++++++++++++++++++++ Tests/UnitSpecs/ScopeRegistryKeySpec.swift | 5 +++ 3 files changed, 58 insertions(+), 4 deletions(-) diff --git a/Sources/ScopeRegistryKey.swift b/Sources/ScopeRegistryKey.swift index fab4224c..d4e097f9 100644 --- a/Sources/ScopeRegistryKey.swift +++ b/Sources/ScopeRegistryKey.swift @@ -9,10 +9,22 @@ public struct ScopeRegistryKey { extension ScopeRegistryKey: Hashable { public static func == (lhs: ScopeRegistryKey, rhs: ScopeRegistryKey) -> Bool { - lhs.descriptor.matches(rhs.descriptor) - && rhs.descriptor.matches(lhs.descriptor) - && (lhs.argument as? Matchable)?.matches(rhs.argument) ?? false - && (rhs.argument as? Matchable)?.matches(lhs.argument) ?? false + areDescriptorsEqual(lhs.descriptor, rhs.descriptor) && areArgumentsEqual(lhs.argument, rhs.argument) + } + + private static func areDescriptorsEqual(_ lhs: AnyTypeDescriptor, _ rhs: AnyTypeDescriptor) -> Bool { + lhs.matches(rhs) && rhs.matches(lhs) + } + + private static func areArgumentsEqual(_ lhs: Any, _ rhs: Any) -> Bool { + switch (lhs, rhs) { + case is (Void, Void): + return true + case let (lhs as Matchable, rhs as Matchable): + return lhs.matches(rhs) && rhs.matches(lhs) + default: + return false + } } public func hash(into hasher: inout Hasher) { diff --git a/Tests/ApiSpecs/InjectionApiSpec.swift b/Tests/ApiSpecs/InjectionApiSpec.swift index 5b553664..7cbb65fe 100644 --- a/Tests/ApiSpecs/InjectionApiSpec.swift +++ b/Tests/ApiSpecs/InjectionApiSpec.swift @@ -114,4 +114,41 @@ class InjectionApiSpec: QuickSpec { override func spec() { expect { try swinject.on("context").instance() as Int } == 42 expect { try swinject.on(Person()).instance() as Int } == 42 } + it("can bind singleton") { + let swinject = Swinject { + bbind(Person.self) & singleton { Person() } + } + let first = try? swinject.instance() as Person + let second = try? swinject.instance() as Person + expect(first) === second + } + it("can bind scoped singleton") { + let scope = UnboundScope() + let swinject = Swinject { + bbind(Person.self) & scoped(scope).singleton { Person() } + } + let first = try? swinject.instance() as Person + let second = try? swinject.instance() as Person + expect(first) === second + } + it("can close scopes") { + let scope = UnboundScope() + let swinject = Swinject { + bbind(Person.self) & scoped(scope).singleton { Person() } + } + let first = try? swinject.instance() as Person + scope.close() + let second = try? swinject.instance() as Person + expect(first) !== second + } + it("notifies instances when scope is closed") { + let scope = UnboundScope() + let swinject = Swinject { + bbind(ClosableMock.self) & scoped(scope).singleton { ClosableMock() } + } + let closable = try? swinject.instance() as ClosableMock + scope.close() + expect(closable?.closeCalled) == true + } + // FIXME: Binding Protocol to Implementation does not work } } diff --git a/Tests/UnitSpecs/ScopeRegistryKeySpec.swift b/Tests/UnitSpecs/ScopeRegistryKeySpec.swift index be5c17c3..4ffbbebb 100644 --- a/Tests/UnitSpecs/ScopeRegistryKeySpec.swift +++ b/Tests/UnitSpecs/ScopeRegistryKeySpec.swift @@ -69,6 +69,11 @@ class ScopeRegistryKeySpec: QuickSpec { override func spec() { argument2.matchesReturnValue = true expect(key1) == key2 } + it("equals if both arguments are Void") { + key1 = ScopeRegistryKey(descriptor: descriptor1, argument: ()) + key2 = ScopeRegistryKey(descriptor: descriptor2, argument: ()) + expect(key1) == key2 + } } } describe("hash") { From e2296224368e8391eb0fe5c1a924765de588fb57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Fri, 19 Jul 2019 00:33:48 +0200 Subject: [PATCH 079/239] Restructure codebase to core & 3.0 API --- Sources/{ => 3.0 API}/BinderEnvironment.swift | 0 .../Resolver+Injection.swift} | 10 --- Sources/3.0 API/Swinject+Builder.swift | 17 ++++ Sources/{ => 3.0 API}/SwinjectModule.swift | 0 Sources/{ => 3.0 API}/TypeBinder.swift | 0 Sources/{ => Core}/Binding.swift | 0 Sources/{ => Core}/BindingKey.swift | 0 Sources/{ => Core}/Closable.swift | 0 Sources/{ => Core}/ContextedResolver.swift | 0 Sources/{ => Core}/InstanceMaker.swift | 0 Sources/{ => Core}/InstanceRequest.swift | 0 Sources/{ => Core}/Matchable.swift | 0 Sources/Core/Resolver.swift | 13 +++ Sources/{ => Core}/Scope.swift | 0 Sources/{ => Core}/ScopeRegistry.swift | 0 Sources/{ => Core}/ScopeRegistryKey.swift | 0 Sources/{ => Core}/ScopedBinding.swift | 0 Sources/{ => Core}/SimpleBinding.swift | 0 Sources/{ => Core}/Swinject.swift | 14 ---- Sources/{ => Core}/SwinjectError.swift | 0 Sources/{ => Core}/SwinjectTree.swift | 0 Sources/{ => Core}/TypeDescriptor.swift | 0 Swinject.xcodeproj/project.pbxproj | 84 ++++++++++++------- .../SwinjectApiSpec.swift} | 2 +- .../BinderEnvironmentSpec.swift | 0 .../BindingKeySpec.swift | 0 .../ContextedResolverSpec.swift | 0 .../ScopeRegistryKeySpec.swift | 0 .../ScopedBindingSpec.swift | 0 .../SimpleBindingSpec.swift | 0 .../StandardScopeRegistrySpec.swift | 0 .../SwinjectSpec.swift | 0 .../SwinjectTreeBuilderSpec.swift | 0 .../TaggedTypeSpec.swift | 0 .../TypeBinderSpec.swift | 0 .../UnboundScopeSpec.swift | 0 36 files changed, 85 insertions(+), 55 deletions(-) rename Sources/{ => 3.0 API}/BinderEnvironment.swift (100%) rename Sources/{Resolver.swift => 3.0 API/Resolver+Injection.swift} (88%) create mode 100644 Sources/3.0 API/Swinject+Builder.swift rename Sources/{ => 3.0 API}/SwinjectModule.swift (100%) rename Sources/{ => 3.0 API}/TypeBinder.swift (100%) rename Sources/{ => Core}/Binding.swift (100%) rename Sources/{ => Core}/BindingKey.swift (100%) rename Sources/{ => Core}/Closable.swift (100%) rename Sources/{ => Core}/ContextedResolver.swift (100%) rename Sources/{ => Core}/InstanceMaker.swift (100%) rename Sources/{ => Core}/InstanceRequest.swift (100%) rename Sources/{ => Core}/Matchable.swift (100%) create mode 100644 Sources/Core/Resolver.swift rename Sources/{ => Core}/Scope.swift (100%) rename Sources/{ => Core}/ScopeRegistry.swift (100%) rename Sources/{ => Core}/ScopeRegistryKey.swift (100%) rename Sources/{ => Core}/ScopedBinding.swift (100%) rename Sources/{ => Core}/SimpleBinding.swift (100%) rename Sources/{ => Core}/Swinject.swift (69%) rename Sources/{ => Core}/SwinjectError.swift (100%) rename Sources/{ => Core}/SwinjectTree.swift (100%) rename Sources/{ => Core}/TypeDescriptor.swift (100%) rename Tests/{ApiSpecs/InjectionApiSpec.swift => 3.0 API/SwinjectApiSpec.swift} (99%) rename Tests/{UnitSpecs => Unit Specs}/BinderEnvironmentSpec.swift (100%) rename Tests/{UnitSpecs => Unit Specs}/BindingKeySpec.swift (100%) rename Tests/{UnitSpecs => Unit Specs}/ContextedResolverSpec.swift (100%) rename Tests/{UnitSpecs => Unit Specs}/ScopeRegistryKeySpec.swift (100%) rename Tests/{UnitSpecs => Unit Specs}/ScopedBindingSpec.swift (100%) rename Tests/{UnitSpecs => Unit Specs}/SimpleBindingSpec.swift (100%) rename Tests/{UnitSpecs => Unit Specs}/StandardScopeRegistrySpec.swift (100%) rename Tests/{UnitSpecs => Unit Specs}/SwinjectSpec.swift (100%) rename Tests/{UnitSpecs => Unit Specs}/SwinjectTreeBuilderSpec.swift (100%) rename Tests/{UnitSpecs => Unit Specs}/TaggedTypeSpec.swift (100%) rename Tests/{UnitSpecs => Unit Specs}/TypeBinderSpec.swift (100%) rename Tests/{UnitSpecs => Unit Specs}/UnboundScopeSpec.swift (100%) diff --git a/Sources/BinderEnvironment.swift b/Sources/3.0 API/BinderEnvironment.swift similarity index 100% rename from Sources/BinderEnvironment.swift rename to Sources/3.0 API/BinderEnvironment.swift diff --git a/Sources/Resolver.swift b/Sources/3.0 API/Resolver+Injection.swift similarity index 88% rename from Sources/Resolver.swift rename to Sources/3.0 API/Resolver+Injection.swift index 4155c051..2b8368ed 100644 --- a/Sources/Resolver.swift +++ b/Sources/3.0 API/Resolver+Injection.swift @@ -2,16 +2,6 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -public protocol Resolver { - func resolve(_ request: InstanceRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor -} - -public extension Resolver { - func on(_ context: Context) -> Resolver { - ContextedResolver(context: context, resolver: self) - } -} - // TODO: Overloads for multiple arguments & tag / notag combinations public extension Resolver { diff --git a/Sources/3.0 API/Swinject+Builder.swift b/Sources/3.0 API/Swinject+Builder.swift new file mode 100644 index 00000000..cffaa9a9 --- /dev/null +++ b/Sources/3.0 API/Swinject+Builder.swift @@ -0,0 +1,17 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +public extension Swinject { + init(@SwinjectTreeBuilder builder: () -> [SwinjectEntry]) { + self.init(tree: SwinjectTreeBuilder.buildFunction(builder())) + } + + init(@SwinjectTreeBuilder builder: () -> SwinjectEntry) { + self.init(tree: SwinjectTreeBuilder.buildFunction([builder()])) + } + + init(@SwinjectTreeBuilder _: () -> Void) { + self.init(tree: SwinjectTreeBuilder.buildFunction([])) + } +} diff --git a/Sources/SwinjectModule.swift b/Sources/3.0 API/SwinjectModule.swift similarity index 100% rename from Sources/SwinjectModule.swift rename to Sources/3.0 API/SwinjectModule.swift diff --git a/Sources/TypeBinder.swift b/Sources/3.0 API/TypeBinder.swift similarity index 100% rename from Sources/TypeBinder.swift rename to Sources/3.0 API/TypeBinder.swift diff --git a/Sources/Binding.swift b/Sources/Core/Binding.swift similarity index 100% rename from Sources/Binding.swift rename to Sources/Core/Binding.swift diff --git a/Sources/BindingKey.swift b/Sources/Core/BindingKey.swift similarity index 100% rename from Sources/BindingKey.swift rename to Sources/Core/BindingKey.swift diff --git a/Sources/Closable.swift b/Sources/Core/Closable.swift similarity index 100% rename from Sources/Closable.swift rename to Sources/Core/Closable.swift diff --git a/Sources/ContextedResolver.swift b/Sources/Core/ContextedResolver.swift similarity index 100% rename from Sources/ContextedResolver.swift rename to Sources/Core/ContextedResolver.swift diff --git a/Sources/InstanceMaker.swift b/Sources/Core/InstanceMaker.swift similarity index 100% rename from Sources/InstanceMaker.swift rename to Sources/Core/InstanceMaker.swift diff --git a/Sources/InstanceRequest.swift b/Sources/Core/InstanceRequest.swift similarity index 100% rename from Sources/InstanceRequest.swift rename to Sources/Core/InstanceRequest.swift diff --git a/Sources/Matchable.swift b/Sources/Core/Matchable.swift similarity index 100% rename from Sources/Matchable.swift rename to Sources/Core/Matchable.swift diff --git a/Sources/Core/Resolver.swift b/Sources/Core/Resolver.swift new file mode 100644 index 00000000..13fda855 --- /dev/null +++ b/Sources/Core/Resolver.swift @@ -0,0 +1,13 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +public protocol Resolver { + func resolve(_ request: InstanceRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor +} + +public extension Resolver { + func on(_ context: Context) -> Resolver { + ContextedResolver(context: context, resolver: self) + } +} diff --git a/Sources/Scope.swift b/Sources/Core/Scope.swift similarity index 100% rename from Sources/Scope.swift rename to Sources/Core/Scope.swift diff --git a/Sources/ScopeRegistry.swift b/Sources/Core/ScopeRegistry.swift similarity index 100% rename from Sources/ScopeRegistry.swift rename to Sources/Core/ScopeRegistry.swift diff --git a/Sources/ScopeRegistryKey.swift b/Sources/Core/ScopeRegistryKey.swift similarity index 100% rename from Sources/ScopeRegistryKey.swift rename to Sources/Core/ScopeRegistryKey.swift diff --git a/Sources/ScopedBinding.swift b/Sources/Core/ScopedBinding.swift similarity index 100% rename from Sources/ScopedBinding.swift rename to Sources/Core/ScopedBinding.swift diff --git a/Sources/SimpleBinding.swift b/Sources/Core/SimpleBinding.swift similarity index 100% rename from Sources/SimpleBinding.swift rename to Sources/Core/SimpleBinding.swift diff --git a/Sources/Swinject.swift b/Sources/Core/Swinject.swift similarity index 69% rename from Sources/Swinject.swift rename to Sources/Core/Swinject.swift index 8218b63a..d5f41a0b 100644 --- a/Sources/Swinject.swift +++ b/Sources/Core/Swinject.swift @@ -10,20 +10,6 @@ public struct Swinject { } } -public extension Swinject { - init(@SwinjectTreeBuilder builder: () -> [SwinjectEntry]) { - self.init(tree: SwinjectTreeBuilder.buildFunction(builder())) - } - - init(@SwinjectTreeBuilder builder: () -> SwinjectEntry) { - self.init(tree: SwinjectTreeBuilder.buildFunction([builder()])) - } - - init(@SwinjectTreeBuilder _: () -> Void) { - self.init(tree: SwinjectTreeBuilder.buildFunction([])) - } -} - extension Swinject: Resolver { public func resolve(_ request: InstanceRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { try instance(from: findBinding(for: request.key), context: request.context, arg: request.argument) diff --git a/Sources/SwinjectError.swift b/Sources/Core/SwinjectError.swift similarity index 100% rename from Sources/SwinjectError.swift rename to Sources/Core/SwinjectError.swift diff --git a/Sources/SwinjectTree.swift b/Sources/Core/SwinjectTree.swift similarity index 100% rename from Sources/SwinjectTree.swift rename to Sources/Core/SwinjectTree.swift diff --git a/Sources/TypeDescriptor.swift b/Sources/Core/TypeDescriptor.swift similarity index 100% rename from Sources/TypeDescriptor.swift rename to Sources/Core/TypeDescriptor.swift diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 72129294..81714cf8 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -17,9 +17,11 @@ 7723ABDF22E0A9FD0067D423 /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7723ABDE22E0A9FD0067D423 /* Matchable.swift */; }; 7755159D22E0B3C2004BF092 /* ScopeRegistryKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7755159C22E0B3C2004BF092 /* ScopeRegistryKey.swift */; }; 775515A022E0BE79004BF092 /* TaggedTypeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7755159E22E0BE62004BF092 /* TaggedTypeSpec.swift */; }; - 77729C9E22DCCA20005C3281 /* InjectionApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77729C9D22DCCA20005C3281 /* InjectionApiSpec.swift */; }; + 77729C9E22DCCA20005C3281 /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77729C9D22DCCA20005C3281 /* SwinjectApiSpec.swift */; }; 77906E7D22DF6A8D009CDCF4 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77906E7C22DF6A8D009CDCF4 /* Convenience.swift */; }; CD086B1522E1162E00FC9E50 /* UnboundScopeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD086B1422E1162E00FC9E50 /* UnboundScopeSpec.swift */; }; + CD086B1922E12A8C00FC9E50 /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD086B1822E12A8C00FC9E50 /* Resolver+Injection.swift */; }; + CD086B1B22E12ADA00FC9E50 /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD086B1A22E12ADA00FC9E50 /* Swinject+Builder.swift */; }; CD6DE53522DD1C7300532D08 /* BindingKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53322DD1C6800532D08 /* BindingKeySpec.swift */; }; CD6DE53722DD1CE900532D08 /* BindingKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53622DD1CE900532D08 /* BindingKey.swift */; }; CD6DE53922DD1D0A00532D08 /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6DE53822DD1D0A00532D08 /* InstanceRequest.swift */; }; @@ -75,9 +77,11 @@ 7723ABDE22E0A9FD0067D423 /* Matchable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Matchable.swift; sourceTree = ""; }; 7755159C22E0B3C2004BF092 /* ScopeRegistryKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistryKey.swift; sourceTree = ""; }; 7755159E22E0BE62004BF092 /* TaggedTypeSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaggedTypeSpec.swift; sourceTree = ""; }; - 77729C9D22DCCA20005C3281 /* InjectionApiSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InjectionApiSpec.swift; sourceTree = ""; }; + 77729C9D22DCCA20005C3281 /* SwinjectApiSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwinjectApiSpec.swift; sourceTree = ""; }; 77906E7C22DF6A8D009CDCF4 /* Convenience.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Convenience.swift; sourceTree = ""; }; CD086B1422E1162E00FC9E50 /* UnboundScopeSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnboundScopeSpec.swift; sourceTree = ""; }; + CD086B1822E12A8C00FC9E50 /* Resolver+Injection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Resolver+Injection.swift"; sourceTree = ""; }; + CD086B1A22E12ADA00FC9E50 /* Swinject+Builder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Swinject+Builder.swift"; sourceTree = ""; }; CD6DE53322DD1C6800532D08 /* BindingKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingKeySpec.swift; sourceTree = ""; }; CD6DE53622DD1CE900532D08 /* BindingKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingKey.swift; sourceTree = ""; }; CD6DE53822DD1D0A00532D08 /* InstanceRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRequest.swift; sourceTree = ""; }; @@ -158,28 +162,10 @@ 771BFC7222D5F83E00AFB237 /* Sources */ = { isa = PBXGroup; children = ( + CD086B1722E1286C00FC9E50 /* 3.0 API */, + CD086B1622E1285E00FC9E50 /* Core */, 771BFC7322D5F83E00AFB237 /* Swinject.h */, 771BFC7422D5F83E00AFB237 /* Info.plist */, - CDADF32022DB38C600C5D8DB /* SwinjectTree.swift */, - CDD8380422DA307F003E9909 /* TypeBinder.swift */, - CDD8380622DA30C6003E9909 /* TypeDescriptor.swift */, - CDD8380B22DA3AD8003E9909 /* InstanceMaker.swift */, - CD6DE54222DE65B500532D08 /* SimpleBinding.swift */, - CD6DE54D22DF886F00532D08 /* ScopedBinding.swift */, - CD6DE55122DF93A000532D08 /* BinderEnvironment.swift */, - CDD8380F22DA429F003E9909 /* Resolver.swift */, - CD6DE54422DED11600532D08 /* ContextedResolver.swift */, - CDD8380D22DA3B0D003E9909 /* Binding.swift */, - CD6DE53622DD1CE900532D08 /* BindingKey.swift */, - CD6DE53822DD1D0A00532D08 /* InstanceRequest.swift */, - CDD8381522DA4B55003E9909 /* Swinject.swift */, - CDD8381C22DA4E02003E9909 /* SwinjectError.swift */, - CDADF33422DB521400C5D8DB /* SwinjectModule.swift */, - CD6DE54B22DF85AF00532D08 /* Scope.swift */, - 7723ABD622E095460067D423 /* ScopeRegistry.swift */, - 7755159C22E0B3C2004BF092 /* ScopeRegistryKey.swift */, - 7723ABDE22E0A9FD0067D423 /* Matchable.swift */, - CDE19EBF22E0D3A200981365 /* Closable.swift */, ); path = Sources; sourceTree = ""; @@ -187,8 +173,8 @@ 771BFC7D22D5F83E00AFB237 /* Tests */ = { isa = PBXGroup; children = ( - 77729C9C22DCCA20005C3281 /* ApiSpecs */, - 77729C9622DCC597005C3281 /* UnitSpecs */, + 77729C9C22DCCA20005C3281 /* 3.0 API */, + 77729C9622DCC597005C3281 /* Unit Specs */, 77729C9422DCC56D005C3281 /* Support */, 771BFC8022D5F83E00AFB237 /* Info.plist */, ); @@ -216,7 +202,7 @@ path = Support; sourceTree = ""; }; - 77729C9622DCC597005C3281 /* UnitSpecs */ = { + 77729C9622DCC597005C3281 /* Unit Specs */ = { isa = PBXGroup; children = ( CDD8380222DA2B67003E9909 /* SwinjectTreeBuilderSpec.swift */, @@ -232,15 +218,51 @@ 7755159E22E0BE62004BF092 /* TaggedTypeSpec.swift */, CD086B1422E1162E00FC9E50 /* UnboundScopeSpec.swift */, ); - path = UnitSpecs; + path = "Unit Specs"; + sourceTree = ""; + }; + 77729C9C22DCCA20005C3281 /* 3.0 API */ = { + isa = PBXGroup; + children = ( + 77729C9D22DCCA20005C3281 /* SwinjectApiSpec.swift */, + ); + path = "3.0 API"; sourceTree = ""; }; - 77729C9C22DCCA20005C3281 /* ApiSpecs */ = { + CD086B1622E1285E00FC9E50 /* Core */ = { isa = PBXGroup; children = ( - 77729C9D22DCCA20005C3281 /* InjectionApiSpec.swift */, + CDD8381522DA4B55003E9909 /* Swinject.swift */, + CD6DE54422DED11600532D08 /* ContextedResolver.swift */, + CDD8380F22DA429F003E9909 /* Resolver.swift */, + CD6DE54222DE65B500532D08 /* SimpleBinding.swift */, + CD6DE54D22DF886F00532D08 /* ScopedBinding.swift */, + CDD8381C22DA4E02003E9909 /* SwinjectError.swift */, + CDE19EBF22E0D3A200981365 /* Closable.swift */, + 7723ABDE22E0A9FD0067D423 /* Matchable.swift */, + 7755159C22E0B3C2004BF092 /* ScopeRegistryKey.swift */, + 7723ABD622E095460067D423 /* ScopeRegistry.swift */, + CD6DE54B22DF85AF00532D08 /* Scope.swift */, + CD6DE53822DD1D0A00532D08 /* InstanceRequest.swift */, + CD6DE53622DD1CE900532D08 /* BindingKey.swift */, + CDD8380D22DA3B0D003E9909 /* Binding.swift */, + CDD8380B22DA3AD8003E9909 /* InstanceMaker.swift */, + CDD8380622DA30C6003E9909 /* TypeDescriptor.swift */, + CDADF32022DB38C600C5D8DB /* SwinjectTree.swift */, + ); + path = Core; + sourceTree = ""; + }; + CD086B1722E1286C00FC9E50 /* 3.0 API */ = { + isa = PBXGroup; + children = ( + CDD8380422DA307F003E9909 /* TypeBinder.swift */, + CD6DE55122DF93A000532D08 /* BinderEnvironment.swift */, + CD086B1822E12A8C00FC9E50 /* Resolver+Injection.swift */, + CD086B1A22E12ADA00FC9E50 /* Swinject+Builder.swift */, + CDADF33422DB521400C5D8DB /* SwinjectModule.swift */, ); - path = ApiSpecs; + path = "3.0 API"; sourceTree = ""; }; CDADF33B22DB878C00C5D8DB /* Templates */ = { @@ -422,6 +444,7 @@ CDADF32122DB38C600C5D8DB /* SwinjectTree.swift in Sources */, CDD8381D22DA4E02003E9909 /* SwinjectError.swift in Sources */, CD6DE54C22DF85AF00532D08 /* Scope.swift in Sources */, + CD086B1922E12A8C00FC9E50 /* Resolver+Injection.swift in Sources */, CDD8380722DA30C6003E9909 /* TypeDescriptor.swift in Sources */, CD6DE54522DED11600532D08 /* ContextedResolver.swift in Sources */, 7723ABDF22E0A9FD0067D423 /* Matchable.swift in Sources */, @@ -432,6 +455,7 @@ CDD8381622DA4B55003E9909 /* Swinject.swift in Sources */, CDD8380522DA307F003E9909 /* TypeBinder.swift in Sources */, CDD8380E22DA3B0D003E9909 /* Binding.swift in Sources */, + CD086B1B22E12ADA00FC9E50 /* Swinject+Builder.swift in Sources */, CD6DE54E22DF886F00532D08 /* ScopedBinding.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -456,7 +480,7 @@ CD086B1522E1162E00FC9E50 /* UnboundScopeSpec.swift in Sources */, 7723ABDD22E0979E0067D423 /* ScopeRegistryKeySpec.swift in Sources */, CDADF33722DB753800C5D8DB /* TestModels.swift in Sources */, - 77729C9E22DCCA20005C3281 /* InjectionApiSpec.swift in Sources */, + 77729C9E22DCCA20005C3281 /* SwinjectApiSpec.swift in Sources */, CD6DE55022DF8B2700532D08 /* ScopedBindingSpec.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Tests/ApiSpecs/InjectionApiSpec.swift b/Tests/3.0 API/SwinjectApiSpec.swift similarity index 99% rename from Tests/ApiSpecs/InjectionApiSpec.swift rename to Tests/3.0 API/SwinjectApiSpec.swift index 7cbb65fe..d0de4b73 100644 --- a/Tests/ApiSpecs/InjectionApiSpec.swift +++ b/Tests/3.0 API/SwinjectApiSpec.swift @@ -6,7 +6,7 @@ import Nimble import Quick import Swinject -class InjectionApiSpec: QuickSpec { override func spec() { +class SwinjectApiSpec: QuickSpec { override func spec() { var person = Person() beforeEach { person = Person() diff --git a/Tests/UnitSpecs/BinderEnvironmentSpec.swift b/Tests/Unit Specs/BinderEnvironmentSpec.swift similarity index 100% rename from Tests/UnitSpecs/BinderEnvironmentSpec.swift rename to Tests/Unit Specs/BinderEnvironmentSpec.swift diff --git a/Tests/UnitSpecs/BindingKeySpec.swift b/Tests/Unit Specs/BindingKeySpec.swift similarity index 100% rename from Tests/UnitSpecs/BindingKeySpec.swift rename to Tests/Unit Specs/BindingKeySpec.swift diff --git a/Tests/UnitSpecs/ContextedResolverSpec.swift b/Tests/Unit Specs/ContextedResolverSpec.swift similarity index 100% rename from Tests/UnitSpecs/ContextedResolverSpec.swift rename to Tests/Unit Specs/ContextedResolverSpec.swift diff --git a/Tests/UnitSpecs/ScopeRegistryKeySpec.swift b/Tests/Unit Specs/ScopeRegistryKeySpec.swift similarity index 100% rename from Tests/UnitSpecs/ScopeRegistryKeySpec.swift rename to Tests/Unit Specs/ScopeRegistryKeySpec.swift diff --git a/Tests/UnitSpecs/ScopedBindingSpec.swift b/Tests/Unit Specs/ScopedBindingSpec.swift similarity index 100% rename from Tests/UnitSpecs/ScopedBindingSpec.swift rename to Tests/Unit Specs/ScopedBindingSpec.swift diff --git a/Tests/UnitSpecs/SimpleBindingSpec.swift b/Tests/Unit Specs/SimpleBindingSpec.swift similarity index 100% rename from Tests/UnitSpecs/SimpleBindingSpec.swift rename to Tests/Unit Specs/SimpleBindingSpec.swift diff --git a/Tests/UnitSpecs/StandardScopeRegistrySpec.swift b/Tests/Unit Specs/StandardScopeRegistrySpec.swift similarity index 100% rename from Tests/UnitSpecs/StandardScopeRegistrySpec.swift rename to Tests/Unit Specs/StandardScopeRegistrySpec.swift diff --git a/Tests/UnitSpecs/SwinjectSpec.swift b/Tests/Unit Specs/SwinjectSpec.swift similarity index 100% rename from Tests/UnitSpecs/SwinjectSpec.swift rename to Tests/Unit Specs/SwinjectSpec.swift diff --git a/Tests/UnitSpecs/SwinjectTreeBuilderSpec.swift b/Tests/Unit Specs/SwinjectTreeBuilderSpec.swift similarity index 100% rename from Tests/UnitSpecs/SwinjectTreeBuilderSpec.swift rename to Tests/Unit Specs/SwinjectTreeBuilderSpec.swift diff --git a/Tests/UnitSpecs/TaggedTypeSpec.swift b/Tests/Unit Specs/TaggedTypeSpec.swift similarity index 100% rename from Tests/UnitSpecs/TaggedTypeSpec.swift rename to Tests/Unit Specs/TaggedTypeSpec.swift diff --git a/Tests/UnitSpecs/TypeBinderSpec.swift b/Tests/Unit Specs/TypeBinderSpec.swift similarity index 100% rename from Tests/UnitSpecs/TypeBinderSpec.swift rename to Tests/Unit Specs/TypeBinderSpec.swift diff --git a/Tests/UnitSpecs/UnboundScopeSpec.swift b/Tests/Unit Specs/UnboundScopeSpec.swift similarity index 100% rename from Tests/UnitSpecs/UnboundScopeSpec.swift rename to Tests/Unit Specs/UnboundScopeSpec.swift From d04091e529873c65a76a2fab6f23a58b72838ca0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Fri, 19 Jul 2019 01:32:01 +0200 Subject: [PATCH 080/239] Implement optional injecting --- Sources/Core/TypeDescriptor.swift | 27 ++++++++++++++++--- Tests/3.0 API/SwinjectApiSpec.swift | 6 +++++ Tests/Unit Specs/TaggedTypeSpec.swift | 39 ++++++++++++++++++++++++--- 3 files changed, 66 insertions(+), 6 deletions(-) diff --git a/Sources/Core/TypeDescriptor.swift b/Sources/Core/TypeDescriptor.swift index 06716dc8..7bc118ea 100644 --- a/Sources/Core/TypeDescriptor.swift +++ b/Sources/Core/TypeDescriptor.swift @@ -15,12 +15,25 @@ public struct Tagged: TypeDescriptor where Tag: Hashable { let tag: Tag public func matches(_ other: Any) -> Bool { - guard let other = other as? Tagged else { return false } - return tag == other.tag + if let other = other as? Tagged { + return tag == other.tag + } + if let other = other as? Tagged { + return tag == other.tag + } + return false } public var hashValue: Int { - String(describing: BaseType.self).hashValue ^ tag.hashValue + String(describing: hashedType).hashValue ^ tag.hashValue + } + + private var hashedType: Any.Type { + if let optional = BaseType.self as? OptionalProtocol.Type { + return optional.wrappedType + } else { + return BaseType.self + } } } @@ -31,3 +44,11 @@ func tagged(_: Type.Type, with tag: Tag) -> Tagged where T func plain(_: Type.Type) -> Tagged { Tagged(tag: NoTag()) } + +protocol OptionalProtocol { + static var wrappedType: Any.Type { get } +} + +extension Optional: OptionalProtocol { + static var wrappedType: Any.Type { Wrapped.self } +} diff --git a/Tests/3.0 API/SwinjectApiSpec.swift b/Tests/3.0 API/SwinjectApiSpec.swift index d0de4b73..a8b8afa3 100644 --- a/Tests/3.0 API/SwinjectApiSpec.swift +++ b/Tests/3.0 API/SwinjectApiSpec.swift @@ -59,6 +59,12 @@ class SwinjectApiSpec: QuickSpec { override func spec() { expect { try swinject.instance(of: String.self) } == "Plain" expect { try swinject.instance(of: String.self, tagged: "Tag") } == "Tagged" } + it("can inject optionals") { + let swinject = Swinject { + bbind(Int.self) & 42 + } + expect { try swinject.instance() as Int? } == 42 + } it("can inject instance provider") { let swinject = Swinject { bbind(Int.self, tagged: "tag") & 42 diff --git a/Tests/Unit Specs/TaggedTypeSpec.swift b/Tests/Unit Specs/TaggedTypeSpec.swift index 9a1c4e06..3e461c9c 100644 --- a/Tests/Unit Specs/TaggedTypeSpec.swift +++ b/Tests/Unit Specs/TaggedTypeSpec.swift @@ -9,13 +9,46 @@ import Quick class TaggedTypeSpec: QuickSpec { override func spec() { describe("hashValue") { it("is different for different types") { - expect(plain(Int.self).hashValue) != plain(String.self).hashValue + let first = plain(Int.self) + let second = plain(String.self) + expect(first.hashValue) != second.hashValue } it("is different for different tags") { - expect(tagged(Int.self, with: "tag1").hashValue) != tagged(Int.self, with: "tag2").hashValue + let first = tagged(Int.self, with: "tag1") + let second = tagged(Int.self, with: "tag2") + expect(first.hashValue) != second.hashValue } it("is same for the same descriptor") { - expect(tagged(Int.self, with: "tag1").hashValue) == tagged(Int.self, with: "tag1").hashValue + let first = tagged(Int.self, with: "tag1") + let second = tagged(Int.self, with: "tag1") + expect(first.hashValue) == second.hashValue + } + it("is same for the type and it's optional") { + let first = plain(Int.self) + let second = plain(Int?.self) + expect(first.hashValue) == second.hashValue + } + } + describe("matches") { + it("doesn't match if base type is different") { + let first = plain(Int.self) + let second = plain(String.self) + expect(first.matches(second)) == false + } + it("doesn't match if tag is different") { + let first = tagged(Int.self, with: "tag1") + let second = tagged(Int.self, with: "tag2") + expect(first.matches(second)) == false + } + it("matches if the same descriptor") { + let first = tagged(Int.self, with: "tag1") + let second = tagged(Int.self, with: "tag1") + expect(first.matches(second)) == true + } + it("matches if second type is optional of first type") { + let first = plain(Int.self) + let second = plain(Int?.self) + expect(first.matches(second)) == true } } } } From 947a0d5437f1b185a234e8ba3c35a4ad5f33722e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 21 Jul 2019 15:51:06 +0200 Subject: [PATCH 081/239] Update filestructure --- Sources/{ => 2.0 API}/Assembler.swift | 0 Sources/{ => 2.0 API}/Assembly.swift | 0 Sources/{ => 2.0 API}/Behavior.swift | 0 Sources/{ => 2.0 API}/Container.Arguments.erb | 0 .../{ => 2.0 API}/Container.Arguments.swift | 0 Sources/{ => 2.0 API}/Container.Logging.swift | 0 .../Container.TypeForwarding.swift | 0 Sources/{ => 2.0 API}/Container.swift | 0 Sources/{ => 2.0 API}/DebugHelper.swift | 0 Sources/{ => 2.0 API}/FunctionType.swift | 0 Sources/{ => 2.0 API}/GraphIdentifier.swift | 0 Sources/{ => 2.0 API}/InstanceStorage.swift | 0 Sources/{ => 2.0 API}/InstanceWrapper.swift | 0 .../{ => 2.0 API}/ObjectScope.Standard.swift | 0 Sources/{ => 2.0 API}/ObjectScope.swift | 0 Sources/{ => 2.0 API}/Resolver.erb | 0 Sources/{ => 2.0 API}/Resolver.swift | 0 .../ServiceEntry.TypeForwarding.erb | 0 .../ServiceEntry.TypeForwarding.swift | 0 Sources/{ => 2.0 API}/ServiceEntry.swift | 0 Sources/{ => 2.0 API}/ServiceKey.swift | 0 Sources/{ => 2.0 API}/SpinLock.swift | 0 .../SynchronizedResolver.Arguments.erb | 0 .../SynchronizedResolver.Arguments.swift | 0 .../{ => 2.0 API}/SynchronizedResolver.swift | 0 Sources/{ => 2.0 API}/UnavailableItems.swift | 0 Sources/{ => 2.0 API}/_Resolver.swift | 0 Swinject.xcodeproj/project.pbxproj | 1542 +++++++++++------ .../{SwinjectTests => 2.0 API}/.swiftlint.yml | 0 Tests/{SwinjectTests => 2.0 API}/Animal.swift | 0 .../AssemblerSpec.swift | 0 .../BasicAssembly.swift | 0 .../BehaviorFakes.swift | 0 .../Circularity.swift | 0 .../ContainerSpec.Arguments.swift | 0 .../ContainerSpec.Behavior.swift | 0 .../ContainerSpec.Circularity.swift | 0 .../ContainerSpec.CustomScope.swift | 0 ...ontainerSpec.CustomStringConvertible.swift | 0 .../ContainerSpec.DebugHelper.swift | 0 .../ContainerSpec.GraphCaching.swift | 0 .../ContainerSpec.TypeForwarding.swift | 0 .../ContainerSpec.swift | 0 .../EmploymentAssembly.swift | 0 Tests/{SwinjectTests => 2.0 API}/Food.swift | 0 Tests/{SwinjectTests => 2.0 API}/Info.plist | 0 .../{SwinjectTests => 2.0 API}/LazySpec.swift | 0 .../LoadAwareAssembly.swift | 0 Tests/{SwinjectTests => 2.0 API}/Person.swift | 0 .../ProviderSpec.swift | 0 .../ServiceEntrySpec.swift | 0 .../ServiceKeySpec.swift | 0 .../SynchronizedResolverSpec.swift | 0 .../WeakStorageSpec.swift | 0 project.yml | 3 +- 55 files changed, 1059 insertions(+), 486 deletions(-) rename Sources/{ => 2.0 API}/Assembler.swift (100%) rename Sources/{ => 2.0 API}/Assembly.swift (100%) rename Sources/{ => 2.0 API}/Behavior.swift (100%) rename Sources/{ => 2.0 API}/Container.Arguments.erb (100%) rename Sources/{ => 2.0 API}/Container.Arguments.swift (100%) rename Sources/{ => 2.0 API}/Container.Logging.swift (100%) rename Sources/{ => 2.0 API}/Container.TypeForwarding.swift (100%) rename Sources/{ => 2.0 API}/Container.swift (100%) rename Sources/{ => 2.0 API}/DebugHelper.swift (100%) rename Sources/{ => 2.0 API}/FunctionType.swift (100%) rename Sources/{ => 2.0 API}/GraphIdentifier.swift (100%) rename Sources/{ => 2.0 API}/InstanceStorage.swift (100%) rename Sources/{ => 2.0 API}/InstanceWrapper.swift (100%) rename Sources/{ => 2.0 API}/ObjectScope.Standard.swift (100%) rename Sources/{ => 2.0 API}/ObjectScope.swift (100%) rename Sources/{ => 2.0 API}/Resolver.erb (100%) rename Sources/{ => 2.0 API}/Resolver.swift (100%) rename Sources/{ => 2.0 API}/ServiceEntry.TypeForwarding.erb (100%) rename Sources/{ => 2.0 API}/ServiceEntry.TypeForwarding.swift (100%) rename Sources/{ => 2.0 API}/ServiceEntry.swift (100%) rename Sources/{ => 2.0 API}/ServiceKey.swift (100%) rename Sources/{ => 2.0 API}/SpinLock.swift (100%) rename Sources/{ => 2.0 API}/SynchronizedResolver.Arguments.erb (100%) rename Sources/{ => 2.0 API}/SynchronizedResolver.Arguments.swift (100%) rename Sources/{ => 2.0 API}/SynchronizedResolver.swift (100%) rename Sources/{ => 2.0 API}/UnavailableItems.swift (100%) rename Sources/{ => 2.0 API}/_Resolver.swift (100%) rename Tests/{SwinjectTests => 2.0 API}/.swiftlint.yml (100%) rename Tests/{SwinjectTests => 2.0 API}/Animal.swift (100%) rename Tests/{SwinjectTests => 2.0 API}/AssemblerSpec.swift (100%) rename Tests/{SwinjectTests => 2.0 API}/BasicAssembly.swift (100%) rename Tests/{SwinjectTests => 2.0 API}/BehaviorFakes.swift (100%) rename Tests/{SwinjectTests => 2.0 API}/Circularity.swift (100%) rename Tests/{SwinjectTests => 2.0 API}/ContainerSpec.Arguments.swift (100%) rename Tests/{SwinjectTests => 2.0 API}/ContainerSpec.Behavior.swift (100%) rename Tests/{SwinjectTests => 2.0 API}/ContainerSpec.Circularity.swift (100%) rename Tests/{SwinjectTests => 2.0 API}/ContainerSpec.CustomScope.swift (100%) rename Tests/{SwinjectTests => 2.0 API}/ContainerSpec.CustomStringConvertible.swift (100%) rename Tests/{SwinjectTests => 2.0 API}/ContainerSpec.DebugHelper.swift (100%) rename Tests/{SwinjectTests => 2.0 API}/ContainerSpec.GraphCaching.swift (100%) rename Tests/{SwinjectTests => 2.0 API}/ContainerSpec.TypeForwarding.swift (100%) rename Tests/{SwinjectTests => 2.0 API}/ContainerSpec.swift (100%) rename Tests/{SwinjectTests => 2.0 API}/EmploymentAssembly.swift (100%) rename Tests/{SwinjectTests => 2.0 API}/Food.swift (100%) rename Tests/{SwinjectTests => 2.0 API}/Info.plist (100%) rename Tests/{SwinjectTests => 2.0 API}/LazySpec.swift (100%) rename Tests/{SwinjectTests => 2.0 API}/LoadAwareAssembly.swift (100%) rename Tests/{SwinjectTests => 2.0 API}/Person.swift (100%) rename Tests/{SwinjectTests => 2.0 API}/ProviderSpec.swift (100%) rename Tests/{SwinjectTests => 2.0 API}/ServiceEntrySpec.swift (100%) rename Tests/{SwinjectTests => 2.0 API}/ServiceKeySpec.swift (100%) rename Tests/{SwinjectTests => 2.0 API}/SynchronizedResolverSpec.swift (100%) rename Tests/{SwinjectTests => 2.0 API}/WeakStorageSpec.swift (100%) diff --git a/Sources/Assembler.swift b/Sources/2.0 API/Assembler.swift similarity index 100% rename from Sources/Assembler.swift rename to Sources/2.0 API/Assembler.swift diff --git a/Sources/Assembly.swift b/Sources/2.0 API/Assembly.swift similarity index 100% rename from Sources/Assembly.swift rename to Sources/2.0 API/Assembly.swift diff --git a/Sources/Behavior.swift b/Sources/2.0 API/Behavior.swift similarity index 100% rename from Sources/Behavior.swift rename to Sources/2.0 API/Behavior.swift diff --git a/Sources/Container.Arguments.erb b/Sources/2.0 API/Container.Arguments.erb similarity index 100% rename from Sources/Container.Arguments.erb rename to Sources/2.0 API/Container.Arguments.erb diff --git a/Sources/Container.Arguments.swift b/Sources/2.0 API/Container.Arguments.swift similarity index 100% rename from Sources/Container.Arguments.swift rename to Sources/2.0 API/Container.Arguments.swift diff --git a/Sources/Container.Logging.swift b/Sources/2.0 API/Container.Logging.swift similarity index 100% rename from Sources/Container.Logging.swift rename to Sources/2.0 API/Container.Logging.swift diff --git a/Sources/Container.TypeForwarding.swift b/Sources/2.0 API/Container.TypeForwarding.swift similarity index 100% rename from Sources/Container.TypeForwarding.swift rename to Sources/2.0 API/Container.TypeForwarding.swift diff --git a/Sources/Container.swift b/Sources/2.0 API/Container.swift similarity index 100% rename from Sources/Container.swift rename to Sources/2.0 API/Container.swift diff --git a/Sources/DebugHelper.swift b/Sources/2.0 API/DebugHelper.swift similarity index 100% rename from Sources/DebugHelper.swift rename to Sources/2.0 API/DebugHelper.swift diff --git a/Sources/FunctionType.swift b/Sources/2.0 API/FunctionType.swift similarity index 100% rename from Sources/FunctionType.swift rename to Sources/2.0 API/FunctionType.swift diff --git a/Sources/GraphIdentifier.swift b/Sources/2.0 API/GraphIdentifier.swift similarity index 100% rename from Sources/GraphIdentifier.swift rename to Sources/2.0 API/GraphIdentifier.swift diff --git a/Sources/InstanceStorage.swift b/Sources/2.0 API/InstanceStorage.swift similarity index 100% rename from Sources/InstanceStorage.swift rename to Sources/2.0 API/InstanceStorage.swift diff --git a/Sources/InstanceWrapper.swift b/Sources/2.0 API/InstanceWrapper.swift similarity index 100% rename from Sources/InstanceWrapper.swift rename to Sources/2.0 API/InstanceWrapper.swift diff --git a/Sources/ObjectScope.Standard.swift b/Sources/2.0 API/ObjectScope.Standard.swift similarity index 100% rename from Sources/ObjectScope.Standard.swift rename to Sources/2.0 API/ObjectScope.Standard.swift diff --git a/Sources/ObjectScope.swift b/Sources/2.0 API/ObjectScope.swift similarity index 100% rename from Sources/ObjectScope.swift rename to Sources/2.0 API/ObjectScope.swift diff --git a/Sources/Resolver.erb b/Sources/2.0 API/Resolver.erb similarity index 100% rename from Sources/Resolver.erb rename to Sources/2.0 API/Resolver.erb diff --git a/Sources/Resolver.swift b/Sources/2.0 API/Resolver.swift similarity index 100% rename from Sources/Resolver.swift rename to Sources/2.0 API/Resolver.swift diff --git a/Sources/ServiceEntry.TypeForwarding.erb b/Sources/2.0 API/ServiceEntry.TypeForwarding.erb similarity index 100% rename from Sources/ServiceEntry.TypeForwarding.erb rename to Sources/2.0 API/ServiceEntry.TypeForwarding.erb diff --git a/Sources/ServiceEntry.TypeForwarding.swift b/Sources/2.0 API/ServiceEntry.TypeForwarding.swift similarity index 100% rename from Sources/ServiceEntry.TypeForwarding.swift rename to Sources/2.0 API/ServiceEntry.TypeForwarding.swift diff --git a/Sources/ServiceEntry.swift b/Sources/2.0 API/ServiceEntry.swift similarity index 100% rename from Sources/ServiceEntry.swift rename to Sources/2.0 API/ServiceEntry.swift diff --git a/Sources/ServiceKey.swift b/Sources/2.0 API/ServiceKey.swift similarity index 100% rename from Sources/ServiceKey.swift rename to Sources/2.0 API/ServiceKey.swift diff --git a/Sources/SpinLock.swift b/Sources/2.0 API/SpinLock.swift similarity index 100% rename from Sources/SpinLock.swift rename to Sources/2.0 API/SpinLock.swift diff --git a/Sources/SynchronizedResolver.Arguments.erb b/Sources/2.0 API/SynchronizedResolver.Arguments.erb similarity index 100% rename from Sources/SynchronizedResolver.Arguments.erb rename to Sources/2.0 API/SynchronizedResolver.Arguments.erb diff --git a/Sources/SynchronizedResolver.Arguments.swift b/Sources/2.0 API/SynchronizedResolver.Arguments.swift similarity index 100% rename from Sources/SynchronizedResolver.Arguments.swift rename to Sources/2.0 API/SynchronizedResolver.Arguments.swift diff --git a/Sources/SynchronizedResolver.swift b/Sources/2.0 API/SynchronizedResolver.swift similarity index 100% rename from Sources/SynchronizedResolver.swift rename to Sources/2.0 API/SynchronizedResolver.swift diff --git a/Sources/UnavailableItems.swift b/Sources/2.0 API/UnavailableItems.swift similarity index 100% rename from Sources/UnavailableItems.swift rename to Sources/2.0 API/UnavailableItems.swift diff --git a/Sources/_Resolver.swift b/Sources/2.0 API/_Resolver.swift similarity index 100% rename from Sources/_Resolver.swift rename to Sources/2.0 API/_Resolver.swift diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index e5154f94..7d71b044 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -7,222 +7,402 @@ objects = { /* Begin PBXBuildFile section */ - 075EB59C6EDD6B80867B1504 /* ContainerSpec.CustomScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74FE954435F1C361FB14C24B /* ContainerSpec.CustomScope.swift */; }; - 08AD1C582FACCC7B9795B773 /* SpinLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCA8BBC9A1EDE4D17189D634 /* SpinLock.swift */; }; - 090E91188A70ECF0954B4C77 /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1525F92CDAA706A848343E2B /* AssemblerSpec.swift */; }; - 0A83B33E2D49288CAE37F3B7 /* FunctionType.swift in Sources */ = {isa = PBXBuildFile; fileRef = F388AD8E55D8C6F1E31D0522 /* FunctionType.swift */; }; - 0B898EC1B4F5EB15BFBE93BD /* GraphIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B058F48AF289C3AC307C2F7 /* GraphIdentifier.swift */; }; + 01146C3ECC9A6B1973EED93F /* SynchronizedResolver.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 869CA0001EA621843F1EF2BB /* SynchronizedResolver.Arguments.swift */; }; + 01197582F81B8D30D7D4A8AF /* NonGeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841D83ADB41363D1E38087B4 /* NonGeneratedMocks.swift */; }; + 0125E3E8A17D6F2F0CE2F893 /* ContainerSpec.GraphCaching.swift in Sources */ = {isa = PBXBuildFile; fileRef = D366825BB9272905C79AEA47 /* ContainerSpec.GraphCaching.swift */; }; + 013A1E1096BD1305A3A14493 /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1910A1471C3CA9EA86F350BA /* LoadAwareAssembly.swift */; }; + 01D985B5F99817DEE0E0DAD1 /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */; }; + 02CBAAF2DD5E7D589F997A27 /* SpinLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 919757437CA99D0C506EC028 /* SpinLock.swift */; }; + 03005DC48E35AEF37251FADC /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; + 036C85135915C0847704947C /* ServiceEntry.TypeForwarding.erb in Resources */ = {isa = PBXBuildFile; fileRef = E6B3186E0AE372A6663F41E9 /* ServiceEntry.TypeForwarding.erb */; }; + 03E7834C4448A5D939948CCF /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; + 03F8F4469A12ED907FBDABE9 /* Resolver.erb in Resources */ = {isa = PBXBuildFile; fileRef = B7DE2D7907C552B2C165E920 /* Resolver.erb */; }; + 04C24C140F2D0BBFE48C682C /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; + 050982D62AE0244372456440 /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92B8E618A08408404FB2A7A /* TypeBinder.swift */; }; + 0516305FEAEA5A677A6FA9B3 /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; + 0539332D989C37CA34A5FB4F /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEE8FDF4B975A8F2A9FCC5FF /* Food.swift */; }; + 0568E116A56DA02DA92BAC8E /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; + 07538993A345EEC62228247E /* ServiceEntrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2234FFBE7F556D1372AFB42D /* ServiceEntrySpec.swift */; }; + 084187169E13A6E9E709297C /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; + 087E0E3216DB7D53DE7A6BE0 /* FunctionType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F2567098AC12010C308E26D /* FunctionType.swift */; }; 0C24BE87E4F1CF7482DB3468 /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 273FB7A6277E0841E1570990 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 0C78A6E9A14903C552837408 /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D425BCEDCFC8C7CAC6CF85D /* ContainerSpec.Circularity.swift */; }; 0C7996FAC479BA40B124F470 /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = ADD71387EBA54D7EF60D0089 /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 0CB54EA8A31AA0CEC8797118 /* SynchronizedResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 710204D1A678B791BB0FC60E /* SynchronizedResolver.swift */; }; - 0D2BC7D4B52A54D2D0D8E3F1 /* ObjectScope.Standard.swift in Sources */ = {isa = PBXBuildFile; fileRef = A79864FE285C06A91E006806 /* ObjectScope.Standard.swift */; }; - 0D37403DE7C898FE2A10BD33 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5922B783F35F436C528594C1 /* Assembly.swift */; }; - 0DDB9143708044A62671A2F1 /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 172E48E07BA72BCBFB305E93 /* Container.swift */; }; + 0CB9E677FDF7CF424A738F34 /* Container.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C13D01A2DE6F53DF3175D22 /* Container.Arguments.swift */; }; + 0CED31C429BA9F9B23EB2B1F /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42490D1D0C395951243F5CFF /* Container.swift */; }; + 0CFCEE57963529ECA1FFD8C2 /* SynchronizedResolver.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 869CA0001EA621843F1EF2BB /* SynchronizedResolver.Arguments.swift */; }; + 0D44E3E0902E51A7B25E946C /* SynchronizedResolver.Arguments.erb in Resources */ = {isa = PBXBuildFile; fileRef = 7395512173A1439ED411B188 /* SynchronizedResolver.Arguments.erb */; }; + 0D6143A7732F1334275D3658 /* UnboundScopeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 671D5D89472DAFA916814506 /* UnboundScopeSpec.swift */; }; + 0DFB6FB4DF6A713EA545930F /* Container.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C2DBC728B763B04CB25963 /* Container.TypeForwarding.swift */; }; 0E465ECE9EC970161D607F7F /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EA7A547FC60DBD02D132B3E6 /* Swinject.framework */; }; - 0ECBB4FB936DEFAF537BF688 /* WeakStorageSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BFC0320217B5AECBAB994D1 /* WeakStorageSpec.swift */; }; - 0F5F881E37F5CD79ED9E0408 /* FunctionType.swift in Sources */ = {isa = PBXBuildFile; fileRef = F388AD8E55D8C6F1E31D0522 /* FunctionType.swift */; }; - 0F6FC2C68A3398EE072A2F9E /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC379E27E9804FC6C0BA0842 /* Resolver.swift */; }; - 10803956513842C932359FE2 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB483EF286681035F8A98F43 /* ContainerSpec.CustomStringConvertible.swift */; }; + 0E8E5B08478EB883D9B52947 /* ScopedBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */; }; + 100DC02D61F72A611B7CF6E3 /* UnboundScopeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 671D5D89472DAFA916814506 /* UnboundScopeSpec.swift */; }; + 10EB88F976AC1025DC22FE8A /* InstanceStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06A8ED72CD6241A2CDEA8479 /* InstanceStorage.swift */; }; + 124369E08D4848D05E3EA6B1 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1FA0377AF4799D42E9462FA /* BasicAssembly.swift */; }; + 13379D1C70FC17FE2F949341 /* BindingKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */; }; 133D41B8AD245B9DBAFC6606 /* Quick.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 683A1FB7D7F4E9508D57E936 /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 1441592A94F585D04EDE2C6C /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7196841DBEB28245AF90D79E /* ContainerSpec.swift */; }; - 1727EBCCD8C71D08851A7410 /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A55238408D01CA3199A54A5 /* ContainerSpec.Behavior.swift */; }; - 175D54CF1A731ED4512264B7 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC379E27E9804FC6C0BA0842 /* Resolver.swift */; }; + 14AECF24B26ECEC8E9086FBB /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3586A4987B7C7C8122D674E /* SwinjectError.swift */; }; + 151340C24653963B97464BA9 /* ContextedResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBA3EF319F06A1B3B6C84C29 /* ContextedResolver.swift */; }; + 15FA8361AB335F4CC372A52C /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; + 166CBBCA1E1441AD87A60EFF /* BindingKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */; }; + 16727D477E4258A547C21D93 /* DebugHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F4982F617A2FF202637E57C /* DebugHelper.swift */; }; + 16FE1BC18A9DD0D21CAF2806 /* ScopeRegistryKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2902FD4C1A50263340A51FFB /* ScopeRegistryKeySpec.swift */; }; + 1718A1577AB543174FD8E644 /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; + 173F76A64BF34826968532DC /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59111BE319C59E4CD6CF68CD /* Assembler.swift */; }; + 187BD516162B3FBB1158E015 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 359BCD3DA6F0CC2241878C82 /* EmploymentAssembly.swift */; }; + 18A07EB6FB61F3CDCC766AF4 /* ScopeRegistryKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */; }; + 192278AA7165EC3C2C12A4C2 /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; + 196AA219BB35334B07B34F37 /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */; }; + 199D71D592CEDF7400DA3D0A /* ContextedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4021EB1EA6A2770920FAD979 /* ContextedResolverSpec.swift */; }; 1A03A1D9524E8912AF1CEE11 /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = EA7A547FC60DBD02D132B3E6 /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 1A2377BC65B8A180D68BB262 /* ContainerSpec.DebugHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5DA24DF3EBEAA57BFC8D8631 /* ContainerSpec.DebugHelper.swift */; }; - 1B0EB3B7A052F64E94D74E87 /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47328731EED63322AD76FB3A /* Circularity.swift */; }; - 1C093CAA7406BDC73E019673 /* DebugHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE752946EBDAC1CB5823A39E /* DebugHelper.swift */; }; - 1D074CFE13423997A82ADF07 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB483EF286681035F8A98F43 /* ContainerSpec.CustomStringConvertible.swift */; }; - 1DD937FA2EF27FF04C2EF25B /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8817F361F89EB6F454B8F89 /* ContainerSpec.TypeForwarding.swift */; }; - 20240BBFA874D27CFD896044 /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C662DAE2FD2FCCA8585DB89 /* ContainerSpec.Arguments.swift */; }; - 20F6C8D41D807E70796EBEA7 /* ServiceEntrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = D794CFA41AB11452E4FC6B48 /* ServiceEntrySpec.swift */; }; - 22D5B9E5714FCAB1ACC43D17 /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47328731EED63322AD76FB3A /* Circularity.swift */; }; - 2345F9D14C54EF8C860DCDA6 /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A55238408D01CA3199A54A5 /* ContainerSpec.Behavior.swift */; }; - 251DDFD910D4EBF1737E46CE /* SpinLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCA8BBC9A1EDE4D17189D634 /* SpinLock.swift */; }; + 1ACC90951353E5F69899A833 /* SimpleBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */; }; + 1AD4C43B074F736BBDADA8C9 /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; + 1B29712FD3C5FB3B372EE35F /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */; }; + 1BBE296A616C1761DD76935C /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 443508AA18D686A564F59882 /* .swiftlint.yml */; }; + 1C2F5A09F986586F85FAC3E8 /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; + 1C8B304AAB75579AE100EDDF /* ServiceEntry.TypeForwarding.erb in Resources */ = {isa = PBXBuildFile; fileRef = E6B3186E0AE372A6663F41E9 /* ServiceEntry.TypeForwarding.erb */; }; + 1CFCB38BC4EE2D3AAD40154E /* ScopedBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */; }; + 1F256E6920935F88C753F739 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; + 1F2E1C6B8F28C5441D52C033 /* ObjectScope.Standard.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD433AFA21FF52AF81A9C9B8 /* ObjectScope.Standard.swift */; }; + 1F4FBB9D795CE9D45E5A8BEE /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; + 20823C309A5C58900CDFA8C3 /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; + 22837E727E47A3B8A588AB78 /* TypeBinderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDA62EEBC79ED2639C93A76B /* TypeBinderSpec.swift */; }; + 240057137A0476B5874B0BCB /* DebugHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F4982F617A2FF202637E57C /* DebugHelper.swift */; }; 25DE2596CC5387B9353FC204 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */; }; - 2729BB3A164474BBCD5FE6AD /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 957AFDACC07687608E5E5F7E /* ObjectScope.swift */; }; - 27FDAE467746E4974EB287EF /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C662DAE2FD2FCCA8585DB89 /* ContainerSpec.Arguments.swift */; }; - 2828C15FCDE70DB18B81D8FE /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7101AB0DE88A5340F7EAAC04 /* InstanceWrapper.swift */; }; - 2962CE114DE17D807445BFD4 /* DebugHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE752946EBDAC1CB5823A39E /* DebugHelper.swift */; }; - 2BBA6302511D78391E3C9F8E /* ServiceKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD2ED5B0128132DCD709777F /* ServiceKey.swift */; }; - 2E434DABCF502284B530CD54 /* SynchronizedResolver.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1979933FD5852C28F6D8784A /* SynchronizedResolver.Arguments.swift */; }; - 302C5A83E38B435AA67FFC86 /* FunctionType.swift in Sources */ = {isa = PBXBuildFile; fileRef = F388AD8E55D8C6F1E31D0522 /* FunctionType.swift */; }; - 30350031317A671C77F81A96 /* ServiceKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD2ED5B0128132DCD709777F /* ServiceKey.swift */; }; - 30EC53EC03C05BF6681FC187 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8817F361F89EB6F454B8F89 /* ContainerSpec.TypeForwarding.swift */; }; - 3265EB0F084010B28B6B4C2B /* SynchronizedResolver.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1979933FD5852C28F6D8784A /* SynchronizedResolver.Arguments.swift */; }; - 340A98C94442E19E76F63A2D /* Container.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = C38F57E5E5BE1DC65C3DDAF6 /* Container.Arguments.swift */; }; - 36C7496040FF588E19A8256B /* Container.Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0F839BCDE52371FE49454B9 /* Container.Logging.swift */; }; - 3733855FF6222CF7DCE24F4B /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCC59458E04C20587D870946 /* BasicAssembly.swift */; }; - 37655AE5BF345D66B36726FF /* InstanceStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B7688D6F1E3466891D0582E /* InstanceStorage.swift */; }; - 39E32CABC6B0830B733518F6 /* ObjectScope.Standard.swift in Sources */ = {isa = PBXBuildFile; fileRef = A79864FE285C06A91E006806 /* ObjectScope.Standard.swift */; }; - 3BCB0A11FBB2D2EC3D3B6F9C /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB483EF286681035F8A98F43 /* ContainerSpec.CustomStringConvertible.swift */; }; - 402AAC65E9FD3A7B3CC97E55 /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7B00D2ED19209D0C6210169 /* Person.swift */; }; - 4055DBF12F18CE2B4A96A85E /* ContainerSpec.GraphCaching.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1524909CA7B5BFA7E2BEE347 /* ContainerSpec.GraphCaching.swift */; }; - 42934DD22585444E3F2BA68C /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 944B981A9157833AC3397B4A /* Assembler.swift */; }; - 4357EE4ED4DBA7D9AFF68E67 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC379E27E9804FC6C0BA0842 /* Resolver.swift */; }; - 43CC601C7D23298C9E52D59B /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2380F40FC2B9229F36B13679 /* LoadAwareAssembly.swift */; }; - 45FA563D704A03B7859FFFC8 /* ContainerSpec.GraphCaching.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1524909CA7B5BFA7E2BEE347 /* ContainerSpec.GraphCaching.swift */; }; - 4676E3F114A76CA377C1AFEA /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFBC1F44A2B361CB169F7B66 /* Animal.swift */; }; - 474999499F01967E54E300A8 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCC59458E04C20587D870946 /* BasicAssembly.swift */; }; + 261D54C316CB625359F7EE97 /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; + 26AC238FC2FB5279ABF37C89 /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */; }; + 26C8D37F26408DC308A0CDA3 /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; + 2B386345150685F670BF04B1 /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9985BEF966DCBB28B12BE17B /* Person.swift */; }; + 2B67E8B80A930E8598FAD10C /* Closable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D0BCCCD61CD9BECC29E064 /* Closable.swift */; }; + 2BD8335377FA7F918849C815 /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; + 2BE5AF2623B96992C74970F9 /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BA261FF01C5F5510873B3EC /* Animal.swift */; }; + 2C6047BB84D52FC94F63B7C8 /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBDB67E0FC7B8BEE58EECFBB /* BehaviorFakes.swift */; }; + 2CA05A2362E0390075908A32 /* BinderEnvironmentSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */; }; + 2D1BB3EDEBEA06A17138B298 /* TaggedTypeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */; }; + 2DCEEF373F410202226D2DB5 /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */; }; + 2E147955709F10BA7E36F657 /* Resolver.erb in Resources */ = {isa = PBXBuildFile; fileRef = B7DE2D7907C552B2C165E920 /* Resolver.erb */; }; + 30BD96CC0333463C71377C4B /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; + 31266C4BA7CE6C3FBAFBACDD /* Container.Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE4B1E4BA98573B6FED2D118 /* Container.Logging.swift */; }; + 35175F8F168EDB5EB83BD8E9 /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C074BAC560F277E806146C60 /* SimpleBinding.swift */; }; + 3547656EF55D129316B7C5E2 /* InstanceMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CADDB3E9E363310028AA5920 /* InstanceMaker.swift */; }; + 35847FDC65085C6741D2A132 /* SimpleBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */; }; + 36F9E405E993FFF9FF7BAEA7 /* Container.Arguments.erb in Resources */ = {isa = PBXBuildFile; fileRef = 24C19DEC1E7BDED41182B68C /* Container.Arguments.erb */; }; + 375945E6CD15BC4D5C8654C9 /* TaggedTypeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */; }; + 377EE35B80E8F91543B52F0C /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; + 37E07236E0E63570242CE23F /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; + 37FE9A9C76DB50ABB28AF9BE /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; + 38FACA739BA59278725FAE67 /* ServiceEntry.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03CDF95C1EAFCD54450B34B6 /* ServiceEntry.TypeForwarding.swift */; }; + 39431794D93EA4DDD0BBB2C5 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; + 39D7CF8F5563E3C1BDDEED93 /* _Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17BEC193FDDE3BA488EA592E /* _Resolver.swift */; }; + 39F9BBD670C944E1331FAB13 /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */; }; + 3A149A223FA316F68C0A486A /* NonGeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841D83ADB41363D1E38087B4 /* NonGeneratedMocks.swift */; }; + 3A2FE7C2BA76C096122F92ED /* UnboundScopeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 671D5D89472DAFA916814506 /* UnboundScopeSpec.swift */; }; + 3AC304A612ECAED02C58BBF5 /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BFF4BA99493C54260878C4 /* ObjectScope.swift */; }; + 3B2E8B8CF4825DB05B0233F8 /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */; }; + 3B61931D1E9C0F7D1AAEDDF7 /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92B8E618A08408404FB2A7A /* TypeBinder.swift */; }; + 3DA1F1126FD1FC935353F847 /* ServiceKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45CA41659767E1378A9F492B /* ServiceKeySpec.swift */; }; + 3E13E204659AF2DCE94D75CB /* ObjectScope.Standard.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD433AFA21FF52AF81A9C9B8 /* ObjectScope.Standard.swift */; }; + 3EF86AD69EBCED9EAAAA5CF4 /* Container.Arguments.erb in Resources */ = {isa = PBXBuildFile; fileRef = 24C19DEC1E7BDED41182B68C /* Container.Arguments.erb */; }; + 3F04B9C7812B5E21DCE4D36C /* GeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */; }; + 3F1FB19A735BE6E1FA749E75 /* SwinjectSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9527A4CA5BCBA7AFA3596757 /* SwinjectSpec.swift */; }; + 3F8EA877F153EE374FF8E31A /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = A10187BB3A994165E7FC1528 /* ScopedBinding.swift */; }; + 3FCA6D47DF9FC0CDC62B8404 /* UnavailableItems.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDE0E0309FE888FE251632A6 /* UnavailableItems.swift */; }; + 401A790CF8450924114D89ED /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BFF4BA99493C54260878C4 /* ObjectScope.swift */; }; + 418F111C8E128766AC8E33CC /* Closable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D0BCCCD61CD9BECC29E064 /* Closable.swift */; }; + 41EEA4724CD401F38F9622E3 /* InstanceMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CADDB3E9E363310028AA5920 /* InstanceMaker.swift */; }; + 4281FDA4B4AFFC91F82B6B73 /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 443508AA18D686A564F59882 /* .swiftlint.yml */; }; + 439254FAE8DF567DE9659ADA /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3586A4987B7C7C8122D674E /* SwinjectError.swift */; }; + 4503217DA585B602EDE65742 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1FA0377AF4799D42E9462FA /* BasicAssembly.swift */; }; + 457481A631CA1253094D108B /* GraphIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E95633441FFB44D8A05585C /* GraphIdentifier.swift */; }; + 4578AA4291288B21ABD74735 /* ContextedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4021EB1EA6A2770920FAD979 /* ContextedResolverSpec.swift */; }; + 45E5B568D6D0E7FC976DCDC1 /* ServiceKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45CA41659767E1378A9F492B /* ServiceKeySpec.swift */; }; + 46A14FAA5AA73BE8A0397707 /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; + 4735419DE3D63E556D07C663 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B580B43E1891812C97209 /* Binding.swift */; }; 47B127ECD4209183E7E4A245 /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = A0157DBBD5E1F45963BB0932 /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 47D6EF0F9A0CDF72690F57BF /* ContainerSpec.CustomScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74FE954435F1C361FB14C24B /* ContainerSpec.CustomScope.swift */; }; - 4A27DDA9D1B4C60031832778 /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 330AFD602B38E9D09A67B587 /* LazySpec.swift */; }; - 4AF3F51DF2307CD6A492A6B5 /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1271722CF77709A1173E7863 /* Food.swift */; }; - 4B805F11A7508EC44B45CA58 /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AF3AB0ED5AFE7A82E85EC5C /* ProviderSpec.swift */; }; + 48714C7B99D346C83E1E8293 /* InstanceMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CADDB3E9E363310028AA5920 /* InstanceMaker.swift */; }; + 4939B8B795061A74ADFC02D8 /* ServiceEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38615FC8EEB466C5C1EAD21C /* ServiceEntry.swift */; }; + 49FB15929F16836D51779A1D /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B580B43E1891812C97209 /* Binding.swift */; }; + 4A9FFFF0FF25724AC5A0BB52 /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; + 4B35CE8BAA88DCAE7D36BC4B /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; + 4BB09CCBB703AADD728BD796 /* ServiceKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = D101B42AE242A5A00C319FAE /* ServiceKey.swift */; }; 4BCB79EECFCA81178439A85C /* Quick.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 1C58FC14EEA170B0DC079DE4 /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 4C5F485478BFD523C1CC9905 /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7101AB0DE88A5340F7EAAC04 /* InstanceWrapper.swift */; }; - 4D2202002FEB4BC17F348209 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22762C9585A1DA3894306060 /* SynchronizedResolverSpec.swift */; }; - 4D278458638503A42F2184E7 /* ContainerSpec.DebugHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5DA24DF3EBEAA57BFC8D8631 /* ContainerSpec.DebugHelper.swift */; }; + 4C55A4A0FFA4E251DC482E20 /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */; }; + 4C6D7AE29CB7E16431AACFA2 /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; + 4C89DEC934923C4BBF6A3616 /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; + 4CAAE6389422432C6BE5008C /* UnavailableItems.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDE0E0309FE888FE251632A6 /* UnavailableItems.swift */; }; + 4D0ABCA733720469F2240C31 /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */; }; 4D591BB725EAB0ACF9436900 /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 4E0826120965628AF3E94107 /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 957AFDACC07687608E5E5F7E /* ObjectScope.swift */; }; - 4E5331DAB50E295CDEC474C8 /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 944B981A9157833AC3397B4A /* Assembler.swift */; }; - 4E9795D487BC97278A6CE0A2 /* ContainerSpec.CustomScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74FE954435F1C361FB14C24B /* ContainerSpec.CustomScope.swift */; }; - 4FB5B42144E8C4C1EB052E5C /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5922B783F35F436C528594C1 /* Assembly.swift */; }; - 5247D163D277E44E7FD9F34A /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFBC1F44A2B361CB169F7B66 /* Animal.swift */; }; - 54BFB762DC126C707C42BE23 /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7B00D2ED19209D0C6210169 /* Person.swift */; }; - 57302467C822B28ADA343F17 /* GraphIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B058F48AF289C3AC307C2F7 /* GraphIdentifier.swift */; }; - 586655E32F8BDB7E0AA27818 /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2380F40FC2B9229F36B13679 /* LoadAwareAssembly.swift */; }; - 58E6E45CB0688AE1E1F17E2D /* DebugHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE752946EBDAC1CB5823A39E /* DebugHelper.swift */; }; - 5918BFBD4D4379D4B6FDA658 /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7196841DBEB28245AF90D79E /* ContainerSpec.swift */; }; - 5A95ABFA790342B2BCD1AD0A /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEF07245CC462D98868097A3 /* BehaviorFakes.swift */; }; - 5BAAF912E24457CD60A13C31 /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C662DAE2FD2FCCA8585DB89 /* ContainerSpec.Arguments.swift */; }; - 5D290B067B74A36E552A7041 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCC59458E04C20587D870946 /* BasicAssembly.swift */; }; + 4DA000959B4D60B509859810 /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; + 4F10C414D344D3FF9212D51F /* UnavailableItems.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDE0E0309FE888FE251632A6 /* UnavailableItems.swift */; }; + 509CD01E61B453F238D33973 /* ContainerSpec.DebugHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF340AF8DD2D821A225A36B3 /* ContainerSpec.DebugHelper.swift */; }; + 50B230799AFB8C24D1F5CD5D /* SwinjectSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9527A4CA5BCBA7AFA3596757 /* SwinjectSpec.swift */; }; + 51F2CD3C07148069167AB6E9 /* ServiceEntry.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03CDF95C1EAFCD54450B34B6 /* ServiceEntry.TypeForwarding.swift */; }; + 52E8D60BBA9177F35E823779 /* ContainerSpec.CustomScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 332BC41A010B0C5AEAFDF545 /* ContainerSpec.CustomScope.swift */; }; + 5329D4D400755935B22C0881 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1FA0377AF4799D42E9462FA /* BasicAssembly.swift */; }; + 5381C2CDA084C5BEF82D7521 /* Container.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C2DBC728B763B04CB25963 /* Container.TypeForwarding.swift */; }; + 53DC7093FD7C2FEE16154DED /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */; }; + 53F72D1C7E26B52E5D548206 /* WeakStorageSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DECE1C39517B81037CC0D53 /* WeakStorageSpec.swift */; }; + 549227903CFDDF4E8272C691 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; + 54A1FEE340AC3A2413876AD2 /* ScopeRegistryKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */; }; + 5541D9BB4DF2EBB3E7325359 /* _Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17BEC193FDDE3BA488EA592E /* _Resolver.swift */; }; + 5570E14A839D4065FFBA7EF4 /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCAF491EC7DCD7477F9A0ECB /* SwinjectModule.swift */; }; + 564B886D2A35AF26FC411922 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; + 572CA6A9E19927F5D434BB6F /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; + 576AE1D429E00A58A4A56591 /* SynchronizedResolver.Arguments.erb in Resources */ = {isa = PBXBuildFile; fileRef = 7395512173A1439ED411B188 /* SynchronizedResolver.Arguments.erb */; }; + 588A600231D894122A4D9C47 /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; + 58C9D537D453BC7C7DC5C0C1 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 359BCD3DA6F0CC2241878C82 /* EmploymentAssembly.swift */; }; + 58CFFB8C98C465B9101AA9A8 /* InstanceMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CADDB3E9E363310028AA5920 /* InstanceMaker.swift */; }; + 58F7BDE8BB54898CA690BD24 /* StandardScopeRegistrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */; }; + 59E450454D5403C171E8CD20 /* ServiceEntrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2234FFBE7F556D1372AFB42D /* ServiceEntrySpec.swift */; }; + 5ADE98E33813B9287DE1FCE6 /* ServiceEntry.TypeForwarding.erb in Resources */ = {isa = PBXBuildFile; fileRef = E6B3186E0AE372A6663F41E9 /* ServiceEntry.TypeForwarding.erb */; }; + 5B0ECCEBC6CB23571A9EDA38 /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */; }; + 5BBBB5E7162B0429D7332DD4 /* SwinjectSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9527A4CA5BCBA7AFA3596757 /* SwinjectSpec.swift */; }; + 5C06BD3982896046EAA70C8C /* WeakStorageSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DECE1C39517B81037CC0D53 /* WeakStorageSpec.swift */; }; + 5C4C106D138E771C872F5E80 /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; + 5CADD5B13173034498BF4A5F /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BA261FF01C5F5510873B3EC /* Animal.swift */; }; + 5CB4448E66F839C3915D6927 /* StandardScopeRegistrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */; }; + 5D241BBB39F54B8FA2BFF595 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; + 5D2C492FD5088FCB2BA5CDB8 /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92B8E618A08408404FB2A7A /* TypeBinder.swift */; }; + 5E74770DDD69EAFE5D187F90 /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; + 5E983707B893B9A8EF94B33E /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBDB67E0FC7B8BEE58EECFBB /* BehaviorFakes.swift */; }; + 5F008535F981266945B3968B /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B3797A6BB56AE76CEC19F2A /* SwinjectApiSpec.swift */; }; 60467C140BE3C99C1B872A55 /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 823617F3B8A9192F56B13331 /* Quick.framework */; }; + 60AF45155775AA5E97AAB5C1 /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEE8FDF4B975A8F2A9FCC5FF /* Food.swift */; }; + 60CEB9FCA08EFF202DD38096 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1FA0377AF4799D42E9462FA /* BasicAssembly.swift */; }; + 610AC1395A7576F46E470411 /* SynchronizedResolver.Arguments.erb in Resources */ = {isa = PBXBuildFile; fileRef = 7395512173A1439ED411B188 /* SynchronizedResolver.Arguments.erb */; }; + 61FA449BF10682C9E89E767F /* ObjectScope.Standard.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD433AFA21FF52AF81A9C9B8 /* ObjectScope.Standard.swift */; }; 627F366F03B0D6E549AAE98F /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ADD71387EBA54D7EF60D0089 /* Swinject.framework */; }; - 638F1392D758C1BCE9B1EC82 /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47328731EED63322AD76FB3A /* Circularity.swift */; }; - 6690747249BE2F741C15D234 /* Container.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7605BDEF71547D0B17D7195A /* Container.TypeForwarding.swift */; }; - 671ACA3184D8092AFC0E0831 /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7196841DBEB28245AF90D79E /* ContainerSpec.swift */; }; - 6805CF789644E4B5C584A718 /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFBC1F44A2B361CB169F7B66 /* Animal.swift */; }; + 62986D0AAAE9D3934E125332 /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; + 648FDC2A1E3DC75CB47D31E1 /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; + 64A8413AD2ED65BB25BD0113 /* BindingKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = A24B4E8F1CA18603DBB6884A /* BindingKey.swift */; }; + 64BC606D6414CB4BE8834B08 /* GeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */; }; + 65764CCFA94D4C0A0822507A /* UnboundScopeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 671D5D89472DAFA916814506 /* UnboundScopeSpec.swift */; }; + 66033468A5FC65C19B60086A /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07B4728F7C73CC5530956A2 /* Resolver.swift */; }; + 661B5A18940BA6E67D9BA65E /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; + 67A89300EA08B0FB7AB0FBF8 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; 68A42DF14E0117A95B44148F /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C765B92B00C0AC8625BB4AC9 /* Quick.framework */; }; - 68C043EF2363C867DC147C93 /* SynchronizedResolver.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1979933FD5852C28F6D8784A /* SynchronizedResolver.Arguments.swift */; }; - 6BE1770BC7453F216178DBC2 /* DebugHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE752946EBDAC1CB5823A39E /* DebugHelper.swift */; }; - 6BED7E1B661C866CC829ADDC /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22762C9585A1DA3894306060 /* SynchronizedResolverSpec.swift */; }; - 6C811A4EA7E829AFF3EA96C8 /* InstanceStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B7688D6F1E3466891D0582E /* InstanceStorage.swift */; }; - 6F232D19EFBDF1186B8937D6 /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8D8BA4B04A5F517AF663DCE /* Behavior.swift */; }; - 700B9A4AA23950509753EB8B /* ServiceKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE86AA2A0C4B722DD40FDEAE /* ServiceKeySpec.swift */; }; - 704CA2EDFA147F1D54730AF9 /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A55238408D01CA3199A54A5 /* ContainerSpec.Behavior.swift */; }; - 7293CBF54B3122C271BDA9A5 /* ServiceEntrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = D794CFA41AB11452E4FC6B48 /* ServiceEntrySpec.swift */; }; - 72DE2F84AC8F4635EA5271B6 /* ContainerSpec.DebugHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5DA24DF3EBEAA57BFC8D8631 /* ContainerSpec.DebugHelper.swift */; }; - 72EDFFA3763E4BE2F735F513 /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8D8BA4B04A5F517AF663DCE /* Behavior.swift */; }; - 73A5651B096AD8DF3B1F2994 /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A55238408D01CA3199A54A5 /* ContainerSpec.Behavior.swift */; }; - 7402D61AAD867E4307F0C5CD /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1525F92CDAA706A848343E2B /* AssemblerSpec.swift */; }; - 77274083C7E0835D523E51F8 /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7101AB0DE88A5340F7EAAC04 /* InstanceWrapper.swift */; }; - 77F0E05A531252D2615FB27C /* UnavailableItems.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39924B830576F62A4B528A37 /* UnavailableItems.swift */; }; - 781B68347543DE1190644D44 /* ObjectScope.Standard.swift in Sources */ = {isa = PBXBuildFile; fileRef = A79864FE285C06A91E006806 /* ObjectScope.Standard.swift */; }; - 7840FF61771830C4E1FC3CD3 /* ServiceEntry.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54FFC812F14E9976208B644F /* ServiceEntry.TypeForwarding.swift */; }; - 78EA94E0C9584CF5F0E01803 /* ServiceKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE86AA2A0C4B722DD40FDEAE /* ServiceKeySpec.swift */; }; - 7BF577F6D6ACC84563538B81 /* Container.Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0F839BCDE52371FE49454B9 /* Container.Logging.swift */; }; + 699DB780BD90A5AAAD5B4646 /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCAF491EC7DCD7477F9A0ECB /* SwinjectModule.swift */; }; + 6BFA0D58FD4131D3A2248208 /* ContextedResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBA3EF319F06A1B3B6C84C29 /* ContextedResolver.swift */; }; + 6C59839F450D54DB72D0D726 /* ContainerSpec.CustomScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 332BC41A010B0C5AEAFDF545 /* ContainerSpec.CustomScope.swift */; }; + 6C980EED98CBEADFD6DAA72A /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B3797A6BB56AE76CEC19F2A /* SwinjectApiSpec.swift */; }; + 6CBAFB568580240ECE9E1ECE /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 443508AA18D686A564F59882 /* .swiftlint.yml */; }; + 6DCE3C30CAE0350C428154DC /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; + 6F5323F408E5708076C02768 /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = A10187BB3A994165E7FC1528 /* ScopedBinding.swift */; }; + 70268F222B8478BDC084E211 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; + 705F51FD21F7E1536BFC0C41 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B580B43E1891812C97209 /* Binding.swift */; }; + 714EFF2818A5DE7278A522BB /* ContainerSpec.CustomScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 332BC41A010B0C5AEAFDF545 /* ContainerSpec.CustomScope.swift */; }; + 71674FB84CBE1E97B72123BF /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9985BEF966DCBB28B12BE17B /* Person.swift */; }; + 71C4A75D54446D844BA5FB85 /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; + 73214A0BF7D4AE8B78DEB4FD /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = A10187BB3A994165E7FC1528 /* ScopedBinding.swift */; }; + 741344C30785507B22DF703B /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; + 7472B748AEA9F4D1E5EF9A70 /* Container.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C13D01A2DE6F53DF3175D22 /* Container.Arguments.swift */; }; + 7480A500FEC04BB9CB048AE1 /* BinderEnvironmentSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */; }; + 748FE5C55FB93BFFA9012CD3 /* SynchronizedResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4040F8D091ED67C84E2B8854 /* SynchronizedResolver.swift */; }; + 75645864A9295D669631750E /* SynchronizedResolver.Arguments.erb in Resources */ = {isa = PBXBuildFile; fileRef = 7395512173A1439ED411B188 /* SynchronizedResolver.Arguments.erb */; }; + 76B3D9DBF8D5593F67A7B7E6 /* ContextedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4021EB1EA6A2770920FAD979 /* ContextedResolverSpec.swift */; }; + 782801544D9F468F536E045E /* Container.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C2DBC728B763B04CB25963 /* Container.TypeForwarding.swift */; }; + 7845113EAF8FFAFD5EC10540 /* BindingKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */; }; + 788AE378F10DA216265FFF52 /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; + 78ACD9EBF8625ECD24103A17 /* ServiceEntry.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03CDF95C1EAFCD54450B34B6 /* ServiceEntry.TypeForwarding.swift */; }; + 79772C34E5102A8E3003DBF8 /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BFF4BA99493C54260878C4 /* ObjectScope.swift */; }; + 79814146B3796F42B447326D /* ServiceEntrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2234FFBE7F556D1372AFB42D /* ServiceEntrySpec.swift */; }; + 7A9246A43400FC1504683E20 /* ServiceKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45CA41659767E1378A9F492B /* ServiceKeySpec.swift */; }; + 7DD047C203659BCA7F04E48D /* Container.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C13D01A2DE6F53DF3175D22 /* Container.Arguments.swift */; }; + 7E0539C5CD130F0AC4B02096 /* Container.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C13D01A2DE6F53DF3175D22 /* Container.Arguments.swift */; }; 7E9CB14F7E723994920F6E44 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 34AFFAC41BA9D02A38BDB7A3 /* Nimble.framework */; }; - 7EDEE8914F8AA2786C36DCD9 /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2380F40FC2B9229F36B13679 /* LoadAwareAssembly.swift */; }; - 7F191DD81CBC604077F15636 /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2380F40FC2B9229F36B13679 /* LoadAwareAssembly.swift */; }; - 7F87DDBFFE209D63EDCF2DCC /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCC59458E04C20587D870946 /* BasicAssembly.swift */; }; - 80C2D3C86F4316AF8B3DE04F /* GraphIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B058F48AF289C3AC307C2F7 /* GraphIdentifier.swift */; }; - 816C0A8ADA69C8C26E274FAC /* _Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15C304EFDAFB81043B2896E5 /* _Resolver.swift */; }; - 8182EFE66C55AA14FAE05C29 /* WeakStorageSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BFC0320217B5AECBAB994D1 /* WeakStorageSpec.swift */; }; - 864328A1CFF21E37951EF280 /* Container.Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0F839BCDE52371FE49454B9 /* Container.Logging.swift */; }; - 86485CD992A5A151BF5C3418 /* ServiceKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE86AA2A0C4B722DD40FDEAE /* ServiceKeySpec.swift */; }; + 7EF126DA0473C0062F388D6D /* Resolver.erb in Resources */ = {isa = PBXBuildFile; fileRef = B7DE2D7907C552B2C165E920 /* Resolver.erb */; }; + 7F22099B321798EAD85DBC07 /* Container.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C2DBC728B763B04CB25963 /* Container.TypeForwarding.swift */; }; + 8108969F33C37040624E0D02 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07B4728F7C73CC5530956A2 /* Resolver.swift */; }; + 816F47E9D87CAE910091B484 /* Closable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D0BCCCD61CD9BECC29E064 /* Closable.swift */; }; + 81CCC69088D0ADF8E0DC72AC /* ServiceKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45CA41659767E1378A9F492B /* ServiceKeySpec.swift */; }; + 828C5B0915A8D08CF98F5F4C /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; + 833635A5D695AA696559C250 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 359BCD3DA6F0CC2241878C82 /* EmploymentAssembly.swift */; }; 86BE1ED67D6C0A493A9F141A /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 683A1FB7D7F4E9508D57E936 /* Quick.framework */; }; - 877278A5D5478D3648ABFE6F /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1271722CF77709A1173E7863 /* Food.swift */; }; - 87F79D3108B7A3BCC61F4B11 /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D425BCEDCFC8C7CAC6CF85D /* ContainerSpec.Circularity.swift */; }; + 86CD1F46C15A352BCF7CE396 /* ScopeRegistryKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2902FD4C1A50263340A51FFB /* ScopeRegistryKeySpec.swift */; }; + 86E1845B6272AF95F1806CB4 /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; + 87008A3FBE4224F139BA3BC5 /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 443508AA18D686A564F59882 /* .swiftlint.yml */; }; + 87056684D7F91917F6B0AC7A /* BinderEnvironmentSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */; }; + 871BB9B8221656F0189ABEC6 /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; + 876F90C64EA036596E797CB3 /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; + 87F8C64D9E8B4317C0C036E0 /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C074BAC560F277E806146C60 /* SimpleBinding.swift */; }; 89613FDC2024EE34FD246A16 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ADC44E9312C3B974AFD8F07B /* Nimble.framework */; }; + 89D83D5E42814659DFE8F518 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; 89F0AA65C3C9837A0A2452DF /* Quick.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = C765B92B00C0AC8625BB4AC9 /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 8A9F1BA9C50102EA05550627 /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 957AFDACC07687608E5E5F7E /* ObjectScope.swift */; }; - 8BA859223087DF7188401BD3 /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 957AFDACC07687608E5E5F7E /* ObjectScope.swift */; }; - 8C21DFDCEFDDAE65E8437BB2 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5922B783F35F436C528594C1 /* Assembly.swift */; }; - 8D0076BDF161AF29B32DF783 /* ContainerSpec.GraphCaching.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1524909CA7B5BFA7E2BEE347 /* ContainerSpec.GraphCaching.swift */; }; + 8A212C0486A514CF17B5F140 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */; }; + 8AAC0C68038E02A6049ABDC0 /* StandardScopeRegistrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */; }; + 8AEB5894656086C3E2F022FD /* SimpleBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */; }; + 8D58DF5C6963153A8B17D325 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; + 8D71D83DB3F5D3655FB6C71D /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C074BAC560F277E806146C60 /* SimpleBinding.swift */; }; + 8D75A0A4A84E2B46E264B5FB /* ContextedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4021EB1EA6A2770920FAD979 /* ContextedResolverSpec.swift */; }; + 8DBFFFD80828247AED253B0D /* ContainerSpec.GraphCaching.swift in Sources */ = {isa = PBXBuildFile; fileRef = D366825BB9272905C79AEA47 /* ContainerSpec.GraphCaching.swift */; }; 8E1BBA6F7B45E1DF056670AC /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 273FB7A6277E0841E1570990 /* Nimble.framework */; }; 8E9E1BD32B056F472DA14E51 /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1C58FC14EEA170B0DC079DE4 /* Quick.framework */; }; - 8EC748DCE0D0671F6CDE49FD /* _Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15C304EFDAFB81043B2896E5 /* _Resolver.swift */; }; - 90CE5A8E248F46DAD69ECBBC /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AF3AB0ED5AFE7A82E85EC5C /* ProviderSpec.swift */; }; + 8F48909C95AA648D056A392B /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; + 8F70C49F6F6D27A67CDB8F0C /* TypeBinderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDA62EEBC79ED2639C93A76B /* TypeBinderSpec.swift */; }; + 900A130E222A2FE479D8D348 /* UnavailableItems.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDE0E0309FE888FE251632A6 /* UnavailableItems.swift */; }; + 908AE547955AE4432C1D161A /* ServiceEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38615FC8EEB466C5C1EAD21C /* ServiceEntry.swift */; }; + 90B4143005C86717AC76B6EE /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; + 9102F98F672DD39F304AFC3B /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9985BEF966DCBB28B12BE17B /* Person.swift */; }; + 91DAE32F86CEA897AD52AEDB /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42490D1D0C395951243F5CFF /* Container.swift */; }; + 91FED72828F68263D599B6C0 /* SimpleBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */; }; 920EF7689DA7C81235B75CE7 /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 34AFFAC41BA9D02A38BDB7A3 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 9264E4C053A699FE01EAD232 /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; + 939769201BD93B84E6BAD258 /* SpinLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 919757437CA99D0C506EC028 /* SpinLock.swift */; }; + 93DCA2A58C4067D5E60F7ED1 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; + 9437AF5CAAD1A2D033AE3599 /* ScopeRegistryKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */; }; 944F92334ADBCBB7C6A89F20 /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 74DE57FB3E8228904E6FE0D7 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 95BBA67883E6022CA70018F6 /* UnavailableItems.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39924B830576F62A4B528A37 /* UnavailableItems.swift */; }; - 965528C3E27CB1110A8303A6 /* Container.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = C38F57E5E5BE1DC65C3DDAF6 /* Container.Arguments.swift */; }; - 96A5AFA0CA2068EFDEDC7CFD /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C662DAE2FD2FCCA8585DB89 /* ContainerSpec.Arguments.swift */; }; - 993CE5C68BD5B7A752E11CCC /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 172E48E07BA72BCBFB305E93 /* Container.swift */; }; - 9A103C945465C850E48EDFA5 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC379E27E9804FC6C0BA0842 /* Resolver.swift */; }; - 9B4D16CC757508288B70318F /* ServiceEntry.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54FFC812F14E9976208B644F /* ServiceEntry.TypeForwarding.swift */; }; - 9B6F196AB4CFAB63D982488E /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1271722CF77709A1173E7863 /* Food.swift */; }; - 9DAF63C8E5E734B308FFC7C8 /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 172E48E07BA72BCBFB305E93 /* Container.swift */; }; - 9DC4FFC335C3E9DA114909F8 /* UnavailableItems.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39924B830576F62A4B528A37 /* UnavailableItems.swift */; }; - 9EC00930C918970D1C92D155 /* SpinLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCA8BBC9A1EDE4D17189D634 /* SpinLock.swift */; }; - 9F847EF5225A75955CA90A66 /* SynchronizedResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 710204D1A678B791BB0FC60E /* SynchronizedResolver.swift */; }; - A13B16F6559AEB652E160E0C /* ContainerSpec.GraphCaching.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1524909CA7B5BFA7E2BEE347 /* ContainerSpec.GraphCaching.swift */; }; + 94615DB1AD57F1547933D8A5 /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCAF491EC7DCD7477F9A0ECB /* SwinjectModule.swift */; }; + 94804E926B3009A776DD0B61 /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59111BE319C59E4CD6CF68CD /* Assembler.swift */; }; + 9623C7F8B9FED0541D959708 /* ScopeRegistryKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2902FD4C1A50263340A51FFB /* ScopeRegistryKeySpec.swift */; }; + 963D32297EE5CA9C18A0C246 /* NonGeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841D83ADB41363D1E38087B4 /* NonGeneratedMocks.swift */; }; + 971B97F191A9FF75A6586E0A /* ScopeRegistryKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */; }; + 982E4682C79B74226C03E0C9 /* ServiceEntry.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03CDF95C1EAFCD54450B34B6 /* ServiceEntry.TypeForwarding.swift */; }; + 98C8EA8C215D9CC0940AE725 /* Container.Arguments.erb in Resources */ = {isa = PBXBuildFile; fileRef = 24C19DEC1E7BDED41182B68C /* Container.Arguments.erb */; }; + 9A551D43739EDE556FF3F9ED /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBDB67E0FC7B8BEE58EECFBB /* BehaviorFakes.swift */; }; + 9AFDF0122A11B2E996B16C3D /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; + 9B04477B2B117122CB99989A /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1910A1471C3CA9EA86F350BA /* LoadAwareAssembly.swift */; }; + 9B83FF80C5BE658ED0F7B709 /* ScopedBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */; }; + 9B9AA902B80620568D732D7B /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; + 9BAAD1DEBA041700C921A589 /* WeakStorageSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DECE1C39517B81037CC0D53 /* WeakStorageSpec.swift */; }; + 9C08C2D57E0B0B46D5748B6C /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; + 9C81098E44AF728D63640DA1 /* SynchronizedResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4040F8D091ED67C84E2B8854 /* SynchronizedResolver.swift */; }; + 9CEF62C5A3EC3CB8034F08BB /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1910A1471C3CA9EA86F350BA /* LoadAwareAssembly.swift */; }; + 9D1AD9CBA32CEE29EF6C68C2 /* GeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */; }; + 9D99BBDFE65AC69067BC569C /* InstanceStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06A8ED72CD6241A2CDEA8479 /* InstanceStorage.swift */; }; + 9DD1C1273B38FCF4FFE9BCC2 /* BindingKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */; }; + 9E084F679592ADFA28D3AD6D /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; + 9EF6DF530041FC494572D3DB /* ContextedResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBA3EF319F06A1B3B6C84C29 /* ContextedResolver.swift */; }; + 9F1C7A652660EA87BF599126 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; + 9FEC055DC6BE1D844FE5F082 /* Closable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D0BCCCD61CD9BECC29E064 /* Closable.swift */; }; + A014793C56F8966AD2D7CC50 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; + A1650894E467EA95327AEF5E /* FunctionType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F2567098AC12010C308E26D /* FunctionType.swift */; }; A19EFC58B60E547CC3A3A6BE /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 74DE57FB3E8228904E6FE0D7 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; - A1DF30AA83A2A4C37D98D61D /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5922B783F35F436C528594C1 /* Assembly.swift */; }; - A26A6675AEFBA7B0BA4D54B0 /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7B00D2ED19209D0C6210169 /* Person.swift */; }; - A2761D703903F90D61CF5C99 /* ServiceEntrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = D794CFA41AB11452E4FC6B48 /* ServiceEntrySpec.swift */; }; - A3F92AC7BF36EB36A788FDC4 /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7B00D2ED19209D0C6210169 /* Person.swift */; }; - A5A103C646976ADA8A7F43BF /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AF3AB0ED5AFE7A82E85EC5C /* ProviderSpec.swift */; }; - A5DF7F64F8B8AB188D53CCEA /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7101AB0DE88A5340F7EAAC04 /* InstanceWrapper.swift */; }; - A61A3F70F3DB46DF8C92FD27 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22762C9585A1DA3894306060 /* SynchronizedResolverSpec.swift */; }; - A6BB3A31E614C0F121D3C6A7 /* Container.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7605BDEF71547D0B17D7195A /* Container.TypeForwarding.swift */; }; - A7668BF415225429EFAF0E35 /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 330AFD602B38E9D09A67B587 /* LazySpec.swift */; }; - A7753D1167A5734EC2443A22 /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 172E48E07BA72BCBFB305E93 /* Container.swift */; }; - A78168C79AFDFF0A389360AB /* Container.Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0F839BCDE52371FE49454B9 /* Container.Logging.swift */; }; - AA27D98622E1E7D0DAA2AB6E /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8817F361F89EB6F454B8F89 /* ContainerSpec.TypeForwarding.swift */; }; - AA825E89EC3B290292D842CC /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AF3AB0ED5AFE7A82E85EC5C /* ProviderSpec.swift */; }; - AF98E2A2C8E6826789B6BA7D /* ServiceEntry.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54FFC812F14E9976208B644F /* ServiceEntry.TypeForwarding.swift */; }; - B39E6321D83F35A465A638D6 /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D425BCEDCFC8C7CAC6CF85D /* ContainerSpec.Circularity.swift */; }; - B61E5AE2DD1EAD926D5AEB2F /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 944B981A9157833AC3397B4A /* Assembler.swift */; }; - B730032C29EFD182B190AD51 /* Container.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = C38F57E5E5BE1DC65C3DDAF6 /* Container.Arguments.swift */; }; - B86853DECB65EA40E6278C9C /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 077047532310E42432E94D83 /* EmploymentAssembly.swift */; }; - BB97CBCDD4EC8CA43FA4D27E /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFBC1F44A2B361CB169F7B66 /* Animal.swift */; }; - BBF5CD565090567DD9AF1FCF /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1271722CF77709A1173E7863 /* Food.swift */; }; - BD4F788A72567496B6C2DE1A /* ServiceEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76238B6105E2E443A94CE595 /* ServiceEntry.swift */; }; - BDBC4E2B95A3C16E377517A2 /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D425BCEDCFC8C7CAC6CF85D /* ContainerSpec.Circularity.swift */; }; - BE7B3987C077BF12943BB9DD /* ServiceEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76238B6105E2E443A94CE595 /* ServiceEntry.swift */; }; - BE87396543B252618790873A /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1525F92CDAA706A848343E2B /* AssemblerSpec.swift */; }; - BEEF777D3B3975F2E9107746 /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 330AFD602B38E9D09A67B587 /* LazySpec.swift */; }; - C00B23025B6846852DF1F78B /* WeakStorageSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BFC0320217B5AECBAB994D1 /* WeakStorageSpec.swift */; }; - C02A7B0746493E486AD131C3 /* SynchronizedResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 710204D1A678B791BB0FC60E /* SynchronizedResolver.swift */; }; - C0615D8AD0393E52F14AD280 /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 330AFD602B38E9D09A67B587 /* LazySpec.swift */; }; - C086EF6C96295CCB3CB99FC3 /* WeakStorageSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BFC0320217B5AECBAB994D1 /* WeakStorageSpec.swift */; }; + A1B275A2EFA22C45AC46B31E /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; + A2745DCB0ACE7714C65CA2A9 /* ObjectScope.Standard.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD433AFA21FF52AF81A9C9B8 /* ObjectScope.Standard.swift */; }; + A4490FF7ACCC5CBFB2C1896C /* Container.Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE4B1E4BA98573B6FED2D118 /* Container.Logging.swift */; }; + A44D1B2E48E1C0FEF146933A /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; + A4866802E1E597EEFEFDEB66 /* BindingKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = A24B4E8F1CA18603DBB6884A /* BindingKey.swift */; }; + A4C25E4406175163B7C5B810 /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B3797A6BB56AE76CEC19F2A /* SwinjectApiSpec.swift */; }; + A4CBDC3AA56FFC5719896568 /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; + A4EA3E548D1CAB029697B0A9 /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; + A600D3F52D38EBC5A3C75CC2 /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */; }; + A6A470DC3A6D310AA0671075 /* ContainerSpec.CustomScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 332BC41A010B0C5AEAFDF545 /* ContainerSpec.CustomScope.swift */; }; + A778AD223AF6C6E30BFFFC84 /* SpinLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 919757437CA99D0C506EC028 /* SpinLock.swift */; }; + AA6651CFD4090465E7CB7871 /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCAF491EC7DCD7477F9A0ECB /* SwinjectModule.swift */; }; + AAB6386F88442B22E9F7FF0E /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42490D1D0C395951243F5CFF /* Container.swift */; }; + AAC84D757FE8F601FF053923 /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3586A4987B7C7C8122D674E /* SwinjectError.swift */; }; + ABA204BE7AEAC01BF1D6002E /* ServiceKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = D101B42AE242A5A00C319FAE /* ServiceKey.swift */; }; + AF5F860DBFE2607EF4157CF7 /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; + B1B107E3FA2DC2E985160D75 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; + B1B1A13B6792198E4E835034 /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */; }; + B2FCC51BB61148422256A14A /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; + B5048A00D49FD5C1C098EE01 /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; + B61FAC17826BAFD2DC1C0E5E /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; + B753AC265ABCEF3CBCE3C4CE /* ServiceKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = D101B42AE242A5A00C319FAE /* ServiceKey.swift */; }; + B7CE6F32765FC472CE205458 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; + B89CFD4B5A564B7EC2DFC62E /* ServiceEntry.TypeForwarding.erb in Resources */ = {isa = PBXBuildFile; fileRef = E6B3186E0AE372A6663F41E9 /* ServiceEntry.TypeForwarding.erb */; }; + B95786317494375C0E2D2044 /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; + B9FAEC69210B352FC744079E /* TypeBinderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDA62EEBC79ED2639C93A76B /* TypeBinderSpec.swift */; }; + BAFD66351A9ED8E7BFB19CD3 /* NonGeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841D83ADB41363D1E38087B4 /* NonGeneratedMocks.swift */; }; + BB3AAADF214D5FF3E25E3974 /* SwinjectSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9527A4CA5BCBA7AFA3596757 /* SwinjectSpec.swift */; }; + BF8E048DADB28763928A2ACC /* SynchronizedResolver.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 869CA0001EA621843F1EF2BB /* SynchronizedResolver.Arguments.swift */; }; C0CCC43D2CDFF01CF0FF9F89 /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = ADC44E9312C3B974AFD8F07B /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - C159DD8F1F2E6AAC8587C438 /* ServiceEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76238B6105E2E443A94CE595 /* ServiceEntry.swift */; }; - C1FC636DE630CA087CBC6408 /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8D8BA4B04A5F517AF663DCE /* Behavior.swift */; }; + C15318646655D97EBDCAA67B /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B3797A6BB56AE76CEC19F2A /* SwinjectApiSpec.swift */; }; + C16D64C4A1ABCF441BEB2EBE /* GraphIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E95633441FFB44D8A05585C /* GraphIdentifier.swift */; }; C37B885879F0D716B36E1C5B /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 74DE57FB3E8228904E6FE0D7 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; - C7CFEAB275D2CC34CF1055EF /* _Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15C304EFDAFB81043B2896E5 /* _Resolver.swift */; }; - C81FF3F03E909FE65874B72A /* SynchronizedResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 710204D1A678B791BB0FC60E /* SynchronizedResolver.swift */; }; - C875EFA8E8DBD0F31D71EC2A /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7196841DBEB28245AF90D79E /* ContainerSpec.swift */; }; - C906533ED6AEC3BA210E73C1 /* Container.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7605BDEF71547D0B17D7195A /* Container.TypeForwarding.swift */; }; + C3AD37D47C38E5EB20FAF917 /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; + C493D6AD1D8748A2698F0B81 /* ContainerSpec.DebugHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF340AF8DD2D821A225A36B3 /* ContainerSpec.DebugHelper.swift */; }; + C4C2C38793731903F172D88E /* Container.Arguments.erb in Resources */ = {isa = PBXBuildFile; fileRef = 24C19DEC1E7BDED41182B68C /* Container.Arguments.erb */; }; + C50BFD826112288F1D693A30 /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; + C5584C2C04564AFC0BCD3710 /* GraphIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E95633441FFB44D8A05585C /* GraphIdentifier.swift */; }; + C6ED278B6F0E08A4B1E57C45 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; + C75EC8F8DD60676B120917EA /* ContextedResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBA3EF319F06A1B3B6C84C29 /* ContextedResolver.swift */; }; + C797CCF413DF181935DAB58C /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; + C7BB5752C697E748B828C03B /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; + C8F1F075F5792C9936B0577D /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42490D1D0C395951243F5CFF /* Container.swift */; }; C9DD3F5C59F6A8833279F790 /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6EA4ECB5E4CEC9751AD36854 /* Swinject.framework */; }; - CACBE4F33EFE0CA42C6CFE1F /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB483EF286681035F8A98F43 /* ContainerSpec.CustomStringConvertible.swift */; }; - CCE1FC81D2456BC5F439585F /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEF07245CC462D98868097A3 /* BehaviorFakes.swift */; }; - CE741D8C6B8C31D05A5C6AD6 /* ContainerSpec.DebugHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5DA24DF3EBEAA57BFC8D8631 /* ContainerSpec.DebugHelper.swift */; }; - CF5A5794A6F5CA48017907A4 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 077047532310E42432E94D83 /* EmploymentAssembly.swift */; }; + CA202C787FE269EF63ADC449 /* TaggedTypeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */; }; + CA7DED9FF907336CB6091795 /* ServiceKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = D101B42AE242A5A00C319FAE /* ServiceKey.swift */; }; + CC5509F4681D4489DB0D447E /* DebugHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F4982F617A2FF202637E57C /* DebugHelper.swift */; }; + CE62237127502CCD13CC22C2 /* _Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17BEC193FDDE3BA488EA592E /* _Resolver.swift */; }; CFC3CDB46CD8FFA22EB0FADD /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A0157DBBD5E1F45963BB0932 /* Swinject.framework */; }; - D1C66A9C78612719063E399E /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 077047532310E42432E94D83 /* EmploymentAssembly.swift */; }; - D223F4C178F9B7F3E87B14FB /* UnavailableItems.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39924B830576F62A4B528A37 /* UnavailableItems.swift */; }; - D56BA2D6F1FD24840F5FFABC /* Container.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = C38F57E5E5BE1DC65C3DDAF6 /* Container.Arguments.swift */; }; - D9538DE064194CC8EF546AE5 /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEF07245CC462D98868097A3 /* BehaviorFakes.swift */; }; - DA36F83E3A3791702269E5B4 /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47328731EED63322AD76FB3A /* Circularity.swift */; }; - DB34E302A6E9CFA36D3DF0AD /* InstanceStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B7688D6F1E3466891D0582E /* InstanceStorage.swift */; }; - DC462CD4ACCE5B2843CA4608 /* _Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15C304EFDAFB81043B2896E5 /* _Resolver.swift */; }; + D0F428B5C92CA0C25EF4BE61 /* _Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17BEC193FDDE3BA488EA592E /* _Resolver.swift */; }; + D10FFA4B80F4BE6024B1DCEE /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1910A1471C3CA9EA86F350BA /* LoadAwareAssembly.swift */; }; + D18275ADB0E56D3087894518 /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; + D1E4114EED19E341BB80869A /* FunctionType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F2567098AC12010C308E26D /* FunctionType.swift */; }; + D2391A103E7356AD7E08F5BA /* ScopedBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */; }; + D267BD55BBEDE3ECEC449472 /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; + D29AAB45717CC7988EC72163 /* WeakStorageSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DECE1C39517B81037CC0D53 /* WeakStorageSpec.swift */; }; + D3828F01A014F3A06B1141D7 /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; + D42D98955F4F78E3FC91803E /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; + D4939ABFFDAE2A5768D23C65 /* StandardScopeRegistrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */; }; + D557A108A21751DF75542692 /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; + D5BD321738E03967CA8E27C6 /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; + D628C0489129065C23B33107 /* ServiceEntrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2234FFBE7F556D1372AFB42D /* ServiceEntrySpec.swift */; }; + D688F61360D46A16B0678BA4 /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BFF4BA99493C54260878C4 /* ObjectScope.swift */; }; + D6AA597218691F1FE87724E7 /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = A10187BB3A994165E7FC1528 /* ScopedBinding.swift */; }; + D7C2A6D05BD948EA1E3B26FB /* SynchronizedResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4040F8D091ED67C84E2B8854 /* SynchronizedResolver.swift */; }; + D7D5560E4F790F41126F61CF /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; + D7DE20CC15F3A6BD09E43A75 /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; + D7DFD1B77BFB5FABAE165A11 /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; + D86ACC6D9B9C62FF398F8293 /* TaggedTypeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */; }; + D88115BD7D62C38F04045EF0 /* ContainerSpec.GraphCaching.swift in Sources */ = {isa = PBXBuildFile; fileRef = D366825BB9272905C79AEA47 /* ContainerSpec.GraphCaching.swift */; }; + D88D7841C5C84A2E34CE15FD /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92B8E618A08408404FB2A7A /* TypeBinder.swift */; }; + D8E2986FB186B630E54B60CD /* GraphIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E95633441FFB44D8A05585C /* GraphIdentifier.swift */; }; + D98CA679A3AAC176D291CA8E /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEE8FDF4B975A8F2A9FCC5FF /* Food.swift */; }; + DA6CB0A98FE5968CAAFDE9BF /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9985BEF966DCBB28B12BE17B /* Person.swift */; }; + DAFA9AE69744F3C5DC71CF50 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */; }; + DB14CA46130A816F6FAADE92 /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C074BAC560F277E806146C60 /* SimpleBinding.swift */; }; + DC5C3A946BDA224C388D2438 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 359BCD3DA6F0CC2241878C82 /* EmploymentAssembly.swift */; }; DD1B936DC7365917DCA09FC8 /* Quick.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 823617F3B8A9192F56B13331 /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - DE192CCEA6B9CF4DCA5672EA /* ContainerSpec.CustomScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74FE954435F1C361FB14C24B /* ContainerSpec.CustomScope.swift */; }; - DE5F51C679465B0B26A8A4FC /* ObjectScope.Standard.swift in Sources */ = {isa = PBXBuildFile; fileRef = A79864FE285C06A91E006806 /* ObjectScope.Standard.swift */; }; - DE770BEC337CC097E8F9D71D /* ServiceEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76238B6105E2E443A94CE595 /* ServiceEntry.swift */; }; - DFF310C7B58D0E403B9CDFBC /* ServiceKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD2ED5B0128132DCD709777F /* ServiceKey.swift */; }; - E1ABBED82706E6565883AA92 /* SpinLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCA8BBC9A1EDE4D17189D634 /* SpinLock.swift */; }; - E2B2D8E9CA96AD3128FBC460 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22762C9585A1DA3894306060 /* SynchronizedResolverSpec.swift */; }; - E2C53E7AD6F4EAC94344EA70 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 077047532310E42432E94D83 /* EmploymentAssembly.swift */; }; - E319B41334A1A1B39718C82D /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 944B981A9157833AC3397B4A /* Assembler.swift */; }; - E41556F95F26B91659A528C7 /* Container.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7605BDEF71547D0B17D7195A /* Container.TypeForwarding.swift */; }; - E55F6A7F3E680CD37FF30CB3 /* ServiceEntrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = D794CFA41AB11452E4FC6B48 /* ServiceEntrySpec.swift */; }; - E9D0C8B78B02E96C517205CC /* SynchronizedResolver.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1979933FD5852C28F6D8784A /* SynchronizedResolver.Arguments.swift */; }; - ED9BFC3E808DEAD8FAC55893 /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEF07245CC462D98868097A3 /* BehaviorFakes.swift */; }; - EDFE608E5040BE9F021E306F /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8D8BA4B04A5F517AF663DCE /* Behavior.swift */; }; - EF9934A7BA979658B5F8F43D /* GraphIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B058F48AF289C3AC307C2F7 /* GraphIdentifier.swift */; }; + DD4783AE23A8C2A89F591605 /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59111BE319C59E4CD6CF68CD /* Assembler.swift */; }; + DDFC9466110B6C18B2DCCD34 /* SynchronizedResolver.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 869CA0001EA621843F1EF2BB /* SynchronizedResolver.Arguments.swift */; }; + DE0A534B660AA93F73A2CB41 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; + DEB3F135FFAEBF825881E886 /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; + E0D7B3285AA1FE51E14A52A1 /* BindingKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = A24B4E8F1CA18603DBB6884A /* BindingKey.swift */; }; + E2E66C47DB6C2F99B13F01CF /* DebugHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F4982F617A2FF202637E57C /* DebugHelper.swift */; }; + E34C98A8BF87513994A6AD86 /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; + E423395FC7006DD82513F347 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; + E484C3994AD91E91C454B11D /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; + E584841CFD26155FB056C85A /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; + E62C6509D0B52001CC309068 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */; }; + E63F31788438E1A43D480E84 /* Resolver.erb in Resources */ = {isa = PBXBuildFile; fileRef = B7DE2D7907C552B2C165E920 /* Resolver.erb */; }; + E6E536A44F40492F42CA4044 /* ContainerSpec.DebugHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF340AF8DD2D821A225A36B3 /* ContainerSpec.DebugHelper.swift */; }; + E7383E65C483ED1E66A49C5C /* InstanceStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06A8ED72CD6241A2CDEA8479 /* InstanceStorage.swift */; }; + E7E9DE84E1861D125F8D686A /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07B4728F7C73CC5530956A2 /* Resolver.swift */; }; + E80558941BC2149C25A17495 /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; + E8A89383E1D1106DEABB778B /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; + E8D70420E8A3C91D01BC3B5B /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; + E9F5DF3C8AA3A9651D504AF7 /* Container.Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE4B1E4BA98573B6FED2D118 /* Container.Logging.swift */; }; + EABC31077D2369311E6C14C3 /* ServiceEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38615FC8EEB466C5C1EAD21C /* ServiceEntry.swift */; }; + EAC4EA9BAC87B34AD5BA2110 /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3586A4987B7C7C8122D674E /* SwinjectError.swift */; }; + EAD0757CE0163D3549CB5405 /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; + EC4EE4B0AECDBA8EC0B8F73D /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BA261FF01C5F5510873B3EC /* Animal.swift */; }; + ED346CAABC0FF77612D9E186 /* SynchronizedResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4040F8D091ED67C84E2B8854 /* SynchronizedResolver.swift */; }; + EEA8C20EB41C7FF5168941A5 /* SpinLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 919757437CA99D0C506EC028 /* SpinLock.swift */; }; + EEB1E43EF50551F8B9793381 /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59111BE319C59E4CD6CF68CD /* Assembler.swift */; }; + EEB3FA667B9103A8417F5EA4 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; + EEC04BEF02E6776003CC2003 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B580B43E1891812C97209 /* Binding.swift */; }; + EEE1C6EB43E2F4D480A7156A /* TypeBinderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDA62EEBC79ED2639C93A76B /* TypeBinderSpec.swift */; }; + EF25C3A81E568411233E6867 /* ServiceEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38615FC8EEB466C5C1EAD21C /* ServiceEntry.swift */; }; + EFCA30870DA55BC3572AF634 /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BA261FF01C5F5510873B3EC /* Animal.swift */; }; EFE89A258FE9EDFFE5F88FD0 /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 74DE57FB3E8228904E6FE0D7 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; - F3CAED24DBFE30186428258B /* ServiceEntry.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54FFC812F14E9976208B644F /* ServiceEntry.TypeForwarding.swift */; }; - F62433C175C3BE1E8802EB92 /* ServiceKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD2ED5B0128132DCD709777F /* ServiceKey.swift */; }; - F90B6E4422BC7E6C62F35A9D /* FunctionType.swift in Sources */ = {isa = PBXBuildFile; fileRef = F388AD8E55D8C6F1E31D0522 /* FunctionType.swift */; }; - FAB069174717CDFE17EEF2B9 /* ServiceKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE86AA2A0C4B722DD40FDEAE /* ServiceKeySpec.swift */; }; + F151A5040BB76E8E909D9D6B /* Container.Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE4B1E4BA98573B6FED2D118 /* Container.Logging.swift */; }; + F1931BC25DA64EF32EC42F86 /* ContainerSpec.GraphCaching.swift in Sources */ = {isa = PBXBuildFile; fileRef = D366825BB9272905C79AEA47 /* ContainerSpec.GraphCaching.swift */; }; + F1D5D6A0A7679A14317617E1 /* GeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */; }; + F4D2218805AEBF797A2945AB /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEE8FDF4B975A8F2A9FCC5FF /* Food.swift */; }; + F4D7CC563B9C212A418C4EBC /* ScopeRegistryKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2902FD4C1A50263340A51FFB /* ScopeRegistryKeySpec.swift */; }; + F50BA96120EDA5D470F4265C /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBDB67E0FC7B8BEE58EECFBB /* BehaviorFakes.swift */; }; + F78892037CEB565626A69451 /* ContainerSpec.DebugHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF340AF8DD2D821A225A36B3 /* ContainerSpec.DebugHelper.swift */; }; + F7F9B3DB89AC8EC05B6A2B89 /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; + F8DB4EDA0367BCC6832E4AA6 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; + FA44B27F082856C56051F088 /* InstanceStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06A8ED72CD6241A2CDEA8479 /* InstanceStorage.swift */; }; + FAF8F8B75F63D43995A004E8 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; FB6FF5C5729B8E050616CCF6 /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 6EA4ECB5E4CEC9751AD36854 /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - FC8967B917A687C2BB69196E /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1525F92CDAA706A848343E2B /* AssemblerSpec.swift */; }; - FD6AEC9A2FEEA1CE0D33AFF6 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8817F361F89EB6F454B8F89 /* ContainerSpec.TypeForwarding.swift */; }; - FF4CDB6E2BF9F2F0EAA237D7 /* InstanceStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B7688D6F1E3466891D0582E /* InstanceStorage.swift */; }; + FCBA6B66A6BBA29B3EC6CDDD /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; + FD1678ED0C9813A653D9C68B /* BinderEnvironmentSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */; }; + FD792405FD95651F8205BB2D /* FunctionType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F2567098AC12010C308E26D /* FunctionType.swift */; }; + FDB7873663CEFBF7BE76ECFF /* BindingKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = A24B4E8F1CA18603DBB6884A /* BindingKey.swift */; }; + FDCF96E2A442CDC6815B8127 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07B4728F7C73CC5530956A2 /* Resolver.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -312,72 +492,117 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 077047532310E42432E94D83 /* EmploymentAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmploymentAssembly.swift; sourceTree = ""; }; - 0A55238408D01CA3199A54A5 /* ContainerSpec.Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Behavior.swift; sourceTree = ""; }; - 0AF3AB0ED5AFE7A82E85EC5C /* ProviderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProviderSpec.swift; sourceTree = ""; }; - 0D425BCEDCFC8C7CAC6CF85D /* ContainerSpec.Circularity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Circularity.swift; sourceTree = ""; }; - 1271722CF77709A1173E7863 /* Food.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Food.swift; sourceTree = ""; }; - 1524909CA7B5BFA7E2BEE347 /* ContainerSpec.GraphCaching.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.GraphCaching.swift; sourceTree = ""; }; - 1525F92CDAA706A848343E2B /* AssemblerSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AssemblerSpec.swift; sourceTree = ""; }; - 15C304EFDAFB81043B2896E5 /* _Resolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = _Resolver.swift; sourceTree = ""; }; - 172E48E07BA72BCBFB305E93 /* Container.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.swift; sourceTree = ""; }; - 1979933FD5852C28F6D8784A /* SynchronizedResolver.Arguments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SynchronizedResolver.Arguments.swift; sourceTree = ""; }; + 03CDF95C1EAFCD54450B34B6 /* ServiceEntry.TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServiceEntry.TypeForwarding.swift; sourceTree = ""; }; + 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.swift; sourceTree = ""; }; + 06A8ED72CD6241A2CDEA8479 /* InstanceStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceStorage.swift; sourceTree = ""; }; + 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopedBindingSpec.swift; sourceTree = ""; }; + 0E0B580B43E1891812C97209 /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; + 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SynchronizedResolverSpec.swift; sourceTree = ""; }; + 13513FA012659ADE699A3608 /* LazySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LazySpec.swift; sourceTree = ""; }; + 17BEC193FDDE3BA488EA592E /* _Resolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = _Resolver.swift; sourceTree = ""; }; + 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleBindingSpec.swift; sourceTree = ""; }; + 1910A1471C3CA9EA86F350BA /* LoadAwareAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadAwareAssembly.swift; sourceTree = ""; }; 1AAFEBED373D3DD8E29B1131 /* SwinjectTests.xctest */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.cfbundle; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 1B3797A6BB56AE76CEC19F2A /* SwinjectApiSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectApiSpec.swift; sourceTree = ""; }; 1C58FC14EEA170B0DC079DE4 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; - 22762C9585A1DA3894306060 /* SynchronizedResolverSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SynchronizedResolverSpec.swift; sourceTree = ""; }; - 2380F40FC2B9229F36B13679 /* LoadAwareAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadAwareAssembly.swift; sourceTree = ""; }; + 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Circularity.swift; sourceTree = ""; }; + 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Behavior.swift; sourceTree = ""; }; + 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Arguments.swift; sourceTree = ""; }; + 2234FFBE7F556D1372AFB42D /* ServiceEntrySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServiceEntrySpec.swift; sourceTree = ""; }; + 24C19DEC1E7BDED41182B68C /* Container.Arguments.erb */ = {isa = PBXFileReference; path = Container.Arguments.erb; sourceTree = ""; }; 273FB7A6277E0841E1570990 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; - 2C662DAE2FD2FCCA8585DB89 /* ContainerSpec.Arguments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Arguments.swift; sourceTree = ""; }; + 2902FD4C1A50263340A51FFB /* ScopeRegistryKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistryKeySpec.swift; sourceTree = ""; }; 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; - 330AFD602B38E9D09A67B587 /* LazySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LazySpec.swift; sourceTree = ""; }; + 332BC41A010B0C5AEAFDF545 /* ContainerSpec.CustomScope.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.CustomScope.swift; sourceTree = ""; }; 34AFFAC41BA9D02A38BDB7A3 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; + 359BCD3DA6F0CC2241878C82 /* EmploymentAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmploymentAssembly.swift; sourceTree = ""; }; 36322E7DDA56C7E6DF006787 /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - 39924B830576F62A4B528A37 /* UnavailableItems.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnavailableItems.swift; sourceTree = ""; }; - 3B7688D6F1E3466891D0582E /* InstanceStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceStorage.swift; sourceTree = ""; }; - 47328731EED63322AD76FB3A /* Circularity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Circularity.swift; sourceTree = ""; }; - 54FFC812F14E9976208B644F /* ServiceEntry.TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServiceEntry.TypeForwarding.swift; sourceTree = ""; }; + 36BFF4BA99493C54260878C4 /* ObjectScope.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObjectScope.swift; sourceTree = ""; }; + 38615FC8EEB466C5C1EAD21C /* ServiceEntry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServiceEntry.swift; sourceTree = ""; }; + 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Swinject+Builder.swift"; sourceTree = ""; }; + 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaggedTypeSpec.swift; sourceTree = ""; }; + 3DECE1C39517B81037CC0D53 /* WeakStorageSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeakStorageSpec.swift; sourceTree = ""; }; + 4021EB1EA6A2770920FAD979 /* ContextedResolverSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextedResolverSpec.swift; sourceTree = ""; }; + 4040F8D091ED67C84E2B8854 /* SynchronizedResolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SynchronizedResolver.swift; sourceTree = ""; }; + 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingKeySpec.swift; sourceTree = ""; }; + 42490D1D0C395951243F5CFF /* Container.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.swift; sourceTree = ""; }; + 443508AA18D686A564F59882 /* .swiftlint.yml */ = {isa = PBXFileReference; path = .swiftlint.yml; sourceTree = ""; }; + 45CA41659767E1378A9F492B /* ServiceKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServiceKeySpec.swift; sourceTree = ""; }; + 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTree.swift; sourceTree = ""; }; + 494AA2AA587975747596C157 /* ProviderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProviderSpec.swift; sourceTree = ""; }; + 4E95633441FFB44D8A05585C /* GraphIdentifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphIdentifier.swift; sourceTree = ""; }; + 4F2567098AC12010C308E26D /* FunctionType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FunctionType.swift; sourceTree = ""; }; + 5057BAB33984E3E33469452B /* Scope.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Scope.swift; sourceTree = ""; }; 5543571F82B41D79C35A0871 /* SwinjectTests.xctest */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.cfbundle; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - 5922B783F35F436C528594C1 /* Assembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Assembly.swift; sourceTree = ""; }; - 5DA24DF3EBEAA57BFC8D8631 /* ContainerSpec.DebugHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.DebugHelper.swift; sourceTree = ""; }; + 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Resolver+Injection.swift"; sourceTree = ""; }; + 59111BE319C59E4CD6CF68CD /* Assembler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Assembler.swift; sourceTree = ""; }; + 5AB605ED0F735221D0EB1D5F /* Convenience.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Convenience.swift; sourceTree = ""; }; + 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Matchable.swift; sourceTree = ""; }; + 5F4982F617A2FF202637E57C /* DebugHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DebugHelper.swift; sourceTree = ""; }; 5F7BC1C4169BB4382C6D3E1F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 65D0BCCCD61CD9BECC29E064 /* Closable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Closable.swift; sourceTree = ""; }; + 671D5D89472DAFA916814506 /* UnboundScopeSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnboundScopeSpec.swift; sourceTree = ""; }; 683A1FB7D7F4E9508D57E936 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; + 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceWrapper.swift; sourceTree = ""; }; + 6C13D01A2DE6F53DF3175D22 /* Container.Arguments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.Arguments.swift; sourceTree = ""; }; 6EA4ECB5E4CEC9751AD36854 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 7101AB0DE88A5340F7EAAC04 /* InstanceWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceWrapper.swift; sourceTree = ""; }; - 710204D1A678B791BB0FC60E /* SynchronizedResolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SynchronizedResolver.swift; sourceTree = ""; }; - 7196841DBEB28245AF90D79E /* ContainerSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.swift; sourceTree = ""; }; + 715A7D1ADE43B7CB0EF80004 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 722CAC1761180366DE75A4A6 /* TestModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestModels.swift; sourceTree = ""; }; + 7395512173A1439ED411B188 /* SynchronizedResolver.Arguments.erb */ = {isa = PBXFileReference; path = SynchronizedResolver.Arguments.erb; sourceTree = ""; }; + 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.CustomStringConvertible.swift; sourceTree = ""; }; 74DE57FB3E8228904E6FE0D7 /* Swinject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Swinject.h; sourceTree = ""; }; - 74FE954435F1C361FB14C24B /* ContainerSpec.CustomScope.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.CustomScope.swift; sourceTree = ""; }; - 7605BDEF71547D0B17D7195A /* Container.TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.TypeForwarding.swift; sourceTree = ""; }; - 76238B6105E2E443A94CE595 /* ServiceEntry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServiceEntry.swift; sourceTree = ""; }; + 7BA261FF01C5F5510873B3EC /* Animal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Animal.swift; sourceTree = ""; }; + 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistry.swift; sourceTree = ""; }; 823617F3B8A9192F56B13331 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; - 944B981A9157833AC3397B4A /* Assembler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Assembler.swift; sourceTree = ""; }; - 957AFDACC07687608E5E5F7E /* ObjectScope.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObjectScope.swift; sourceTree = ""; }; - 9B058F48AF289C3AC307C2F7 /* GraphIdentifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphIdentifier.swift; sourceTree = ""; }; - 9BFC0320217B5AECBAB994D1 /* WeakStorageSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeakStorageSpec.swift; sourceTree = ""; }; + 841D83ADB41363D1E38087B4 /* NonGeneratedMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonGeneratedMocks.swift; sourceTree = ""; }; + 869CA0001EA621843F1EF2BB /* SynchronizedResolver.Arguments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SynchronizedResolver.Arguments.swift; sourceTree = ""; }; + 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeneratedMocks.swift; sourceTree = ""; }; + 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTreeBuilderSpec.swift; sourceTree = ""; }; + 919757437CA99D0C506EC028 /* SpinLock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpinLock.swift; sourceTree = ""; }; + 9527A4CA5BCBA7AFA3596757 /* SwinjectSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectSpec.swift; sourceTree = ""; }; + 95C2DBC728B763B04CB25963 /* Container.TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.TypeForwarding.swift; sourceTree = ""; }; + 9620155728133F451B31C0AD /* Swinject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Swinject.swift; sourceTree = ""; }; + 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistryKey.swift; sourceTree = ""; }; + 9985BEF966DCBB28B12BE17B /* Person.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Person.swift; sourceTree = ""; }; A0157DBBD5E1F45963BB0932 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - A79864FE285C06A91E006806 /* ObjectScope.Standard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObjectScope.Standard.swift; sourceTree = ""; }; - A8817F361F89EB6F454B8F89 /* ContainerSpec.TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.TypeForwarding.swift; sourceTree = ""; }; + A10187BB3A994165E7FC1528 /* ScopedBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopedBinding.swift; sourceTree = ""; }; + A24B4E8F1CA18603DBB6884A /* BindingKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingKey.swift; sourceTree = ""; }; + A3586A4987B7C7C8122D674E /* SwinjectError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectError.swift; sourceTree = ""; }; + A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Resolver.swift; sourceTree = ""; }; + ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Circularity.swift; sourceTree = ""; }; ADC44E9312C3B974AFD8F07B /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; ADD71387EBA54D7EF60D0089 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - AEAC51C6D09DEBE863D5A06E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - B0F839BCDE52371FE49454B9 /* Container.Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.Logging.swift; sourceTree = ""; }; - BCA8BBC9A1EDE4D17189D634 /* SpinLock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpinLock.swift; sourceTree = ""; }; - BD2ED5B0128132DCD709777F /* ServiceKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServiceKey.swift; sourceTree = ""; }; - BEF07245CC462D98868097A3 /* BehaviorFakes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BehaviorFakes.swift; sourceTree = ""; }; - C38F57E5E5BE1DC65C3DDAF6 /* Container.Arguments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.Arguments.swift; sourceTree = ""; }; + B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AssemblerSpec.swift; sourceTree = ""; }; + B7DE2D7907C552B2C165E920 /* Resolver.erb */ = {isa = PBXFileReference; path = Resolver.erb; sourceTree = ""; }; + B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderEnvironment.swift; sourceTree = ""; }; + B92B8E618A08408404FB2A7A /* TypeBinder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinder.swift; sourceTree = ""; }; + BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StandardScopeRegistrySpec.swift; sourceTree = ""; }; + BBDB67E0FC7B8BEE58EECFBB /* BehaviorFakes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BehaviorFakes.swift; sourceTree = ""; }; + BDE0E0309FE888FE251632A6 /* UnavailableItems.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnavailableItems.swift; sourceTree = ""; }; + BE4B1E4BA98573B6FED2D118 /* Container.Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.Logging.swift; sourceTree = ""; }; + BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Behavior.swift; sourceTree = ""; }; + C074BAC560F277E806146C60 /* SimpleBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleBinding.swift; sourceTree = ""; }; + C07B4728F7C73CC5530956A2 /* Resolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Resolver.swift; sourceTree = ""; }; C765B92B00C0AC8625BB4AC9 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; - C8D8BA4B04A5F517AF663DCE /* Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Behavior.swift; sourceTree = ""; }; - D794CFA41AB11452E4FC6B48 /* ServiceEntrySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServiceEntrySpec.swift; sourceTree = ""; }; - D7B00D2ED19209D0C6210169 /* Person.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Person.swift; sourceTree = ""; }; - DE752946EBDAC1CB5823A39E /* DebugHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DebugHelper.swift; sourceTree = ""; }; - DE86AA2A0C4B722DD40FDEAE /* ServiceKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServiceKeySpec.swift; sourceTree = ""; }; + CADDB3E9E363310028AA5920 /* InstanceMaker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceMaker.swift; sourceTree = ""; }; + CC85CB215058F95C0BC190B1 /* Bridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bridge.swift; sourceTree = ""; }; + D101B42AE242A5A00C319FAE /* ServiceKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServiceKey.swift; sourceTree = ""; }; + D1FA0377AF4799D42E9462FA /* BasicAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BasicAssembly.swift; sourceTree = ""; }; + D366825BB9272905C79AEA47 /* ContainerSpec.GraphCaching.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.GraphCaching.swift; sourceTree = ""; }; + DF340AF8DD2D821A225A36B3 /* ContainerSpec.DebugHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.DebugHelper.swift; sourceTree = ""; }; + E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRequest.swift; sourceTree = ""; }; + E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; + E6B3186E0AE372A6663F41E9 /* ServiceEntry.TypeForwarding.erb */ = {isa = PBXFileReference; path = ServiceEntry.TypeForwarding.erb; sourceTree = ""; }; EA7A547FC60DBD02D132B3E6 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - EB483EF286681035F8A98F43 /* ContainerSpec.CustomStringConvertible.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.CustomStringConvertible.swift; sourceTree = ""; }; - EC379E27E9804FC6C0BA0842 /* Resolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Resolver.swift; sourceTree = ""; }; + EBA3EF319F06A1B3B6C84C29 /* ContextedResolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextedResolver.swift; sourceTree = ""; }; ECE2B2EFBFDA910758EE1CA5 /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - F388AD8E55D8C6F1E31D0522 /* FunctionType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FunctionType.swift; sourceTree = ""; }; - FCC59458E04C20587D870946 /* BasicAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BasicAssembly.swift; sourceTree = ""; }; - FFBC1F44A2B361CB169F7B66 /* Animal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Animal.swift; sourceTree = ""; }; + EDA62EEBC79ED2639C93A76B /* TypeBinderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinderSpec.swift; sourceTree = ""; }; + EEE8FDF4B975A8F2A9FCC5FF /* Food.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Food.swift; sourceTree = ""; }; + F290F6B1207A0557A528220B /* Assembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Assembly.swift; sourceTree = ""; }; + F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.TypeForwarding.swift; sourceTree = ""; }; + FCAF491EC7DCD7477F9A0ECB /* SwinjectModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectModule.swift; sourceTree = ""; }; + FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderEnvironmentSpec.swift; sourceTree = ""; }; + FD433AFA21FF52AF81A9C9B8 /* ObjectScope.Standard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObjectScope.Standard.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -424,37 +649,23 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 1281EF9C9707360B39DD4C11 /* SwinjectTests */ = { + 0A05322134E988A4593B5122 /* Unit Specs */ = { isa = PBXGroup; children = ( - FFBC1F44A2B361CB169F7B66 /* Animal.swift */, - 1525F92CDAA706A848343E2B /* AssemblerSpec.swift */, - FCC59458E04C20587D870946 /* BasicAssembly.swift */, - BEF07245CC462D98868097A3 /* BehaviorFakes.swift */, - 47328731EED63322AD76FB3A /* Circularity.swift */, - 2C662DAE2FD2FCCA8585DB89 /* ContainerSpec.Arguments.swift */, - 0A55238408D01CA3199A54A5 /* ContainerSpec.Behavior.swift */, - 0D425BCEDCFC8C7CAC6CF85D /* ContainerSpec.Circularity.swift */, - 74FE954435F1C361FB14C24B /* ContainerSpec.CustomScope.swift */, - EB483EF286681035F8A98F43 /* ContainerSpec.CustomStringConvertible.swift */, - 5DA24DF3EBEAA57BFC8D8631 /* ContainerSpec.DebugHelper.swift */, - 1524909CA7B5BFA7E2BEE347 /* ContainerSpec.GraphCaching.swift */, - 7196841DBEB28245AF90D79E /* ContainerSpec.swift */, - A8817F361F89EB6F454B8F89 /* ContainerSpec.TypeForwarding.swift */, - 077047532310E42432E94D83 /* EmploymentAssembly.swift */, - 1271722CF77709A1173E7863 /* Food.swift */, - AEAC51C6D09DEBE863D5A06E /* Info.plist */, - 330AFD602B38E9D09A67B587 /* LazySpec.swift */, - 2380F40FC2B9229F36B13679 /* LoadAwareAssembly.swift */, - D7B00D2ED19209D0C6210169 /* Person.swift */, - 0AF3AB0ED5AFE7A82E85EC5C /* ProviderSpec.swift */, - D794CFA41AB11452E4FC6B48 /* ServiceEntrySpec.swift */, - DE86AA2A0C4B722DD40FDEAE /* ServiceKeySpec.swift */, - 22762C9585A1DA3894306060 /* SynchronizedResolverSpec.swift */, - 9BFC0320217B5AECBAB994D1 /* WeakStorageSpec.swift */, - ); - name = SwinjectTests; - path = Tests/SwinjectTests; + FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */, + 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */, + 4021EB1EA6A2770920FAD979 /* ContextedResolverSpec.swift */, + 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */, + 2902FD4C1A50263340A51FFB /* ScopeRegistryKeySpec.swift */, + 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */, + BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */, + 9527A4CA5BCBA7AFA3596757 /* SwinjectSpec.swift */, + 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */, + 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */, + EDA62EEBC79ED2639C93A76B /* TypeBinderSpec.swift */, + 671D5D89472DAFA916814506 /* UnboundScopeSpec.swift */, + ); + path = "Unit Specs"; sourceTree = ""; }; 2B85A6F2D9BDA29BD0BA73F8 /* Mac */ = { @@ -466,6 +677,18 @@ path = Mac; sourceTree = ""; }; + 2D9982F0E5050BAE1832702E /* 3.0 API */ = { + isa = PBXGroup; + children = ( + B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */, + 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */, + 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */, + FCAF491EC7DCD7477F9A0ECB /* SwinjectModule.swift */, + B92B8E618A08408404FB2A7A /* TypeBinder.swift */, + ); + path = "3.0 API"; + sourceTree = ""; + }; 2E9A714E7592B96BBF7B7749 /* tvOS */ = { isa = PBXGroup; children = ( @@ -475,6 +698,52 @@ path = tvOS; sourceTree = ""; }; + 4F46C48FA15F512EAED5F67A /* Support */ = { + isa = PBXGroup; + children = ( + CC85CB215058F95C0BC190B1 /* Bridge.swift */, + 5AB605ED0F735221D0EB1D5F /* Convenience.swift */, + 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */, + 841D83ADB41363D1E38087B4 /* NonGeneratedMocks.swift */, + 722CAC1761180366DE75A4A6 /* TestModels.swift */, + ); + path = Support; + sourceTree = ""; + }; + 5F6AA1259C61A4D472220C36 /* 2.0 API */ = { + isa = PBXGroup; + children = ( + 17BEC193FDDE3BA488EA592E /* _Resolver.swift */, + 59111BE319C59E4CD6CF68CD /* Assembler.swift */, + F290F6B1207A0557A528220B /* Assembly.swift */, + 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */, + 24C19DEC1E7BDED41182B68C /* Container.Arguments.erb */, + 6C13D01A2DE6F53DF3175D22 /* Container.Arguments.swift */, + BE4B1E4BA98573B6FED2D118 /* Container.Logging.swift */, + 42490D1D0C395951243F5CFF /* Container.swift */, + 95C2DBC728B763B04CB25963 /* Container.TypeForwarding.swift */, + 5F4982F617A2FF202637E57C /* DebugHelper.swift */, + 4F2567098AC12010C308E26D /* FunctionType.swift */, + 4E95633441FFB44D8A05585C /* GraphIdentifier.swift */, + 06A8ED72CD6241A2CDEA8479 /* InstanceStorage.swift */, + 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */, + FD433AFA21FF52AF81A9C9B8 /* ObjectScope.Standard.swift */, + 36BFF4BA99493C54260878C4 /* ObjectScope.swift */, + B7DE2D7907C552B2C165E920 /* Resolver.erb */, + C07B4728F7C73CC5530956A2 /* Resolver.swift */, + 38615FC8EEB466C5C1EAD21C /* ServiceEntry.swift */, + E6B3186E0AE372A6663F41E9 /* ServiceEntry.TypeForwarding.erb */, + 03CDF95C1EAFCD54450B34B6 /* ServiceEntry.TypeForwarding.swift */, + D101B42AE242A5A00C319FAE /* ServiceKey.swift */, + 919757437CA99D0C506EC028 /* SpinLock.swift */, + 7395512173A1439ED411B188 /* SynchronizedResolver.Arguments.erb */, + 869CA0001EA621843F1EF2BB /* SynchronizedResolver.Arguments.swift */, + 4040F8D091ED67C84E2B8854 /* SynchronizedResolver.swift */, + BDE0E0309FE888FE251632A6 /* UnavailableItems.swift */, + ); + path = "2.0 API"; + sourceTree = ""; + }; 63C3B0D3B7813CDFB4636392 /* watchOS */ = { isa = PBXGroup; children = ( @@ -516,11 +785,19 @@ path = iOS; sourceTree = ""; }; + 9A6E5EB655CFE64BBCF5DED1 /* 3.0 API */ = { + isa = PBXGroup; + children = ( + 1B3797A6BB56AE76CEC19F2A /* SwinjectApiSpec.swift */, + ); + path = "3.0 API"; + sourceTree = ""; + }; A4F7E56739BB9CB479DDDBF6 = { isa = PBXGroup; children = ( D026A6699A2A932511D29E14 /* Sources */, - 1281EF9C9707360B39DD4C11 /* SwinjectTests */, + C5602A1B64E47775AF8D5700 /* Tests */, 80E97D8FD5574A96B6BC9EB9 /* Frameworks */, 8EB6E58A3F28FAEBBC372598 /* Products */, ); @@ -529,6 +806,17 @@ tabWidth = 4; usesTabs = 0; }; + C5602A1B64E47775AF8D5700 /* Tests */ = { + isa = PBXGroup; + children = ( + F64B4AFEC15ABABB3014A636 /* 2.0 API */, + 9A6E5EB655CFE64BBCF5DED1 /* 3.0 API */, + 4F46C48FA15F512EAED5F67A /* Support */, + 0A05322134E988A4593B5122 /* Unit Specs */, + ); + path = Tests; + sourceTree = ""; + }; CCDA8C80FD167EED2793A467 /* Carthage */ = { isa = PBXGroup; children = ( @@ -544,35 +832,72 @@ D026A6699A2A932511D29E14 /* Sources */ = { isa = PBXGroup; children = ( - 15C304EFDAFB81043B2896E5 /* _Resolver.swift */, - 944B981A9157833AC3397B4A /* Assembler.swift */, - 5922B783F35F436C528594C1 /* Assembly.swift */, - C8D8BA4B04A5F517AF663DCE /* Behavior.swift */, - C38F57E5E5BE1DC65C3DDAF6 /* Container.Arguments.swift */, - B0F839BCDE52371FE49454B9 /* Container.Logging.swift */, - 172E48E07BA72BCBFB305E93 /* Container.swift */, - 7605BDEF71547D0B17D7195A /* Container.TypeForwarding.swift */, - DE752946EBDAC1CB5823A39E /* DebugHelper.swift */, - F388AD8E55D8C6F1E31D0522 /* FunctionType.swift */, - 9B058F48AF289C3AC307C2F7 /* GraphIdentifier.swift */, 5F7BC1C4169BB4382C6D3E1F /* Info.plist */, - 3B7688D6F1E3466891D0582E /* InstanceStorage.swift */, - 7101AB0DE88A5340F7EAAC04 /* InstanceWrapper.swift */, - A79864FE285C06A91E006806 /* ObjectScope.Standard.swift */, - 957AFDACC07687608E5E5F7E /* ObjectScope.swift */, - EC379E27E9804FC6C0BA0842 /* Resolver.swift */, - 76238B6105E2E443A94CE595 /* ServiceEntry.swift */, - 54FFC812F14E9976208B644F /* ServiceEntry.TypeForwarding.swift */, - BD2ED5B0128132DCD709777F /* ServiceKey.swift */, - BCA8BBC9A1EDE4D17189D634 /* SpinLock.swift */, 74DE57FB3E8228904E6FE0D7 /* Swinject.h */, - 1979933FD5852C28F6D8784A /* SynchronizedResolver.Arguments.swift */, - 710204D1A678B791BB0FC60E /* SynchronizedResolver.swift */, - 39924B830576F62A4B528A37 /* UnavailableItems.swift */, + 5F6AA1259C61A4D472220C36 /* 2.0 API */, + 2D9982F0E5050BAE1832702E /* 3.0 API */, + FCA9C6262A4D071C8E7EEBD0 /* Core */, ); path = Sources; sourceTree = ""; }; + F64B4AFEC15ABABB3014A636 /* 2.0 API */ = { + isa = PBXGroup; + children = ( + 443508AA18D686A564F59882 /* .swiftlint.yml */, + 7BA261FF01C5F5510873B3EC /* Animal.swift */, + B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */, + D1FA0377AF4799D42E9462FA /* BasicAssembly.swift */, + BBDB67E0FC7B8BEE58EECFBB /* BehaviorFakes.swift */, + 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */, + 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */, + BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */, + ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */, + 332BC41A010B0C5AEAFDF545 /* ContainerSpec.CustomScope.swift */, + 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */, + DF340AF8DD2D821A225A36B3 /* ContainerSpec.DebugHelper.swift */, + D366825BB9272905C79AEA47 /* ContainerSpec.GraphCaching.swift */, + 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */, + F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */, + 359BCD3DA6F0CC2241878C82 /* EmploymentAssembly.swift */, + EEE8FDF4B975A8F2A9FCC5FF /* Food.swift */, + 715A7D1ADE43B7CB0EF80004 /* Info.plist */, + 13513FA012659ADE699A3608 /* LazySpec.swift */, + 1910A1471C3CA9EA86F350BA /* LoadAwareAssembly.swift */, + 9985BEF966DCBB28B12BE17B /* Person.swift */, + 494AA2AA587975747596C157 /* ProviderSpec.swift */, + 2234FFBE7F556D1372AFB42D /* ServiceEntrySpec.swift */, + 45CA41659767E1378A9F492B /* ServiceKeySpec.swift */, + 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */, + 3DECE1C39517B81037CC0D53 /* WeakStorageSpec.swift */, + ); + path = "2.0 API"; + sourceTree = ""; + }; + FCA9C6262A4D071C8E7EEBD0 /* Core */ = { + isa = PBXGroup; + children = ( + 0E0B580B43E1891812C97209 /* Binding.swift */, + A24B4E8F1CA18603DBB6884A /* BindingKey.swift */, + 65D0BCCCD61CD9BECC29E064 /* Closable.swift */, + EBA3EF319F06A1B3B6C84C29 /* ContextedResolver.swift */, + CADDB3E9E363310028AA5920 /* InstanceMaker.swift */, + E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */, + 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */, + A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */, + 5057BAB33984E3E33469452B /* Scope.swift */, + A10187BB3A994165E7FC1528 /* ScopedBinding.swift */, + 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */, + 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */, + C074BAC560F277E806146C60 /* SimpleBinding.swift */, + 9620155728133F451B31C0AD /* Swinject.swift */, + A3586A4987B7C7C8122D674E /* SwinjectError.swift */, + 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */, + E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */, + ); + path = Core; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ @@ -618,6 +943,7 @@ 585AA4C5E589D1DCBB7F94E5 /* Headers */, 15C9FE5CAD693ADAC2CE7497 /* Sources */, 66D6B3BD3D539FA0C7A9CCA0 /* Swiftlint */, + D245CDD8138FA4393DF16F89 /* Resources */, ); buildRules = ( ); @@ -635,6 +961,7 @@ 54CB4C9F1A52910358025C89 /* Headers */, 604EA45A8BA53D9420351811 /* Sources */, 0001F3C7499902D8D5EB3077 /* Swiftlint */, + E9EF3170DCCA3B360FDA5671 /* Resources */, ); buildRules = ( ); @@ -652,6 +979,7 @@ 02763B86C881518A9271575B /* Headers */, 01C827BE688B831820F3BF57 /* Sources */, 07B6CBBA986B903471B2C38A /* Swiftlint */, + C95D6FDA3B52AAE89B739A57 /* Resources */, ); buildRules = ( ); @@ -669,6 +997,7 @@ E896EE40D53913BA1CD0CA02 /* Headers */, A40C67870E9515117AC87B4F /* Sources */, DF58753EC2B1D8F6A5679F10 /* Swiftlint */, + 78E2087E6ED9E88E480F72BD /* Resources */, ); buildRules = ( ); @@ -684,6 +1013,7 @@ buildConfigurationList = E8497AE035EA38240581F137 /* Build configuration list for PBXNativeTarget "SwinjectTests_watchOS" */; buildPhases = ( 1304DAA7FD78B883E968FE7C /* Sources */, + D5F9594040A6B7CB9B7F97CA /* Resources */, 56399A4C1DD2937674333948 /* Frameworks */, 939C14CDC5C4776E6EEDE451 /* Embed Frameworks */, ); @@ -702,6 +1032,7 @@ buildConfigurationList = F2CFF2ABE576901944A0EBE9 /* Build configuration list for PBXNativeTarget "SwinjectTests_iOS" */; buildPhases = ( 03981BBA914C84906DAE3E8E /* Sources */, + 7A529E244C2531EA2E24DAFC /* Resources */, 36A47EE05A910E4C6BEF6BE3 /* Frameworks */, 983C12AEC980DD055A8AC8A0 /* Embed Frameworks */, ); @@ -720,6 +1051,7 @@ buildConfigurationList = 1EA983EB3F6C7C5CBA3E35C1 /* Build configuration list for PBXNativeTarget "SwinjectTests_macOS" */; buildPhases = ( 240CFEC651F5218936958F61 /* Sources */, + 253C56E2D440F347D4C6D942 /* Resources */, 282390D348496C94EC908BCB /* Frameworks */, F8E2E7B38FA954F5E78D7EC0 /* Embed Frameworks */, ); @@ -738,6 +1070,7 @@ buildConfigurationList = 77F411327F2141AB8AA74A77 /* Build configuration list for PBXNativeTarget "SwinjectTests_tvOS" */; buildPhases = ( 35AA717831EFE6CE722FA1D0 /* Sources */, + 323434757E4C54BDD93C9DE0 /* Resources */, C0A6DEF2D3F1844F449F1998 /* Frameworks */, 6F329FDF6A936CC5E993C847 /* Embed Frameworks */, ); @@ -782,6 +1115,85 @@ }; /* End PBXProject section */ +/* Begin PBXResourcesBuildPhase section */ + 253C56E2D440F347D4C6D942 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 4281FDA4B4AFFC91F82B6B73 /* .swiftlint.yml in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 323434757E4C54BDD93C9DE0 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 6CBAFB568580240ECE9E1ECE /* .swiftlint.yml in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 78E2087E6ED9E88E480F72BD /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 36F9E405E993FFF9FF7BAEA7 /* Container.Arguments.erb in Resources */, + 2E147955709F10BA7E36F657 /* Resolver.erb in Resources */, + 5ADE98E33813B9287DE1FCE6 /* ServiceEntry.TypeForwarding.erb in Resources */, + 610AC1395A7576F46E470411 /* SynchronizedResolver.Arguments.erb in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 7A529E244C2531EA2E24DAFC /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 87008A3FBE4224F139BA3BC5 /* .swiftlint.yml in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + C95D6FDA3B52AAE89B739A57 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 98C8EA8C215D9CC0940AE725 /* Container.Arguments.erb in Resources */, + E63F31788438E1A43D480E84 /* Resolver.erb in Resources */, + 036C85135915C0847704947C /* ServiceEntry.TypeForwarding.erb in Resources */, + 576AE1D429E00A58A4A56591 /* SynchronizedResolver.Arguments.erb in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + D245CDD8138FA4393DF16F89 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 3EF86AD69EBCED9EAAAA5CF4 /* Container.Arguments.erb in Resources */, + 03F8F4469A12ED907FBDABE9 /* Resolver.erb in Resources */, + 1C8B304AAB75579AE100EDDF /* ServiceEntry.TypeForwarding.erb in Resources */, + 0D44E3E0902E51A7B25E946C /* SynchronizedResolver.Arguments.erb in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + D5F9594040A6B7CB9B7F97CA /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 1BBE296A616C1761DD76935C /* .swiftlint.yml in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + E9EF3170DCCA3B360FDA5671 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + C4C2C38793731903F172D88E /* Container.Arguments.erb in Resources */, + 7EF126DA0473C0062F388D6D /* Resolver.erb in Resources */, + B89CFD4B5A564B7EC2DFC62E /* ServiceEntry.TypeForwarding.erb in Resources */, + 75645864A9295D669631750E /* SynchronizedResolver.Arguments.erb in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + /* Begin PBXShellScriptBuildPhase section */ 0001F3C7499902D8D5EB3077 /* Swiftlint */ = { isa = PBXShellScriptBuildPhase; @@ -862,29 +1274,51 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 42934DD22585444E3F2BA68C /* Assembler.swift in Sources */, - 8C21DFDCEFDDAE65E8437BB2 /* Assembly.swift in Sources */, - 6F232D19EFBDF1186B8937D6 /* Behavior.swift in Sources */, - 340A98C94442E19E76F63A2D /* Container.Arguments.swift in Sources */, - 36C7496040FF588E19A8256B /* Container.Logging.swift in Sources */, - C906533ED6AEC3BA210E73C1 /* Container.TypeForwarding.swift in Sources */, - 9DAF63C8E5E734B308FFC7C8 /* Container.swift in Sources */, - 2962CE114DE17D807445BFD4 /* DebugHelper.swift in Sources */, - 0A83B33E2D49288CAE37F3B7 /* FunctionType.swift in Sources */, - 80C2D3C86F4316AF8B3DE04F /* GraphIdentifier.swift in Sources */, - 6C811A4EA7E829AFF3EA96C8 /* InstanceStorage.swift in Sources */, - 4C5F485478BFD523C1CC9905 /* InstanceWrapper.swift in Sources */, - DE5F51C679465B0B26A8A4FC /* ObjectScope.Standard.swift in Sources */, - 2729BB3A164474BBCD5FE6AD /* ObjectScope.swift in Sources */, - 0F6FC2C68A3398EE072A2F9E /* Resolver.swift in Sources */, - F3CAED24DBFE30186428258B /* ServiceEntry.TypeForwarding.swift in Sources */, - C159DD8F1F2E6AAC8587C438 /* ServiceEntry.swift in Sources */, - DFF310C7B58D0E403B9CDFBC /* ServiceKey.swift in Sources */, - 9EC00930C918970D1C92D155 /* SpinLock.swift in Sources */, - E9D0C8B78B02E96C517205CC /* SynchronizedResolver.Arguments.swift in Sources */, - C02A7B0746493E486AD131C3 /* SynchronizedResolver.swift in Sources */, - 77F0E05A531252D2615FB27C /* UnavailableItems.swift in Sources */, - 816C0A8ADA69C8C26E274FAC /* _Resolver.swift in Sources */, + 173F76A64BF34826968532DC /* Assembler.swift in Sources */, + 084187169E13A6E9E709297C /* Assembly.swift in Sources */, + 0568E116A56DA02DA92BAC8E /* Behavior.swift in Sources */, + 5B0ECCEBC6CB23571A9EDA38 /* BinderEnvironment.swift in Sources */, + 49FB15929F16836D51779A1D /* Binding.swift in Sources */, + 64A8413AD2ED65BB25BD0113 /* BindingKey.swift in Sources */, + 9FEC055DC6BE1D844FE5F082 /* Closable.swift in Sources */, + 0CB9E677FDF7CF424A738F34 /* Container.Arguments.swift in Sources */, + A4490FF7ACCC5CBFB2C1896C /* Container.Logging.swift in Sources */, + 7F22099B321798EAD85DBC07 /* Container.TypeForwarding.swift in Sources */, + 0CED31C429BA9F9B23EB2B1F /* Container.swift in Sources */, + 9EF6DF530041FC494572D3DB /* ContextedResolver.swift in Sources */, + 240057137A0476B5874B0BCB /* DebugHelper.swift in Sources */, + A1650894E467EA95327AEF5E /* FunctionType.swift in Sources */, + C5584C2C04564AFC0BCD3710 /* GraphIdentifier.swift in Sources */, + 3547656EF55D129316B7C5E2 /* InstanceMaker.swift in Sources */, + B61FAC17826BAFD2DC1C0E5E /* InstanceRequest.swift in Sources */, + FA44B27F082856C56051F088 /* InstanceStorage.swift in Sources */, + 2DCEEF373F410202226D2DB5 /* InstanceWrapper.swift in Sources */, + 9264E4C053A699FE01EAD232 /* Matchable.swift in Sources */, + 3E13E204659AF2DCE94D75CB /* ObjectScope.Standard.swift in Sources */, + 79772C34E5102A8E3003DBF8 /* ObjectScope.swift in Sources */, + 5C4C106D138E771C872F5E80 /* Resolver+Injection.swift in Sources */, + DAFA9AE69744F3C5DC71CF50 /* Resolver.swift in Sources */, + E7E9DE84E1861D125F8D686A /* Resolver.swift in Sources */, + 71C4A75D54446D844BA5FB85 /* Scope.swift in Sources */, + 1AD4C43B074F736BBDADA8C9 /* ScopeRegistry.swift in Sources */, + 971B97F191A9FF75A6586E0A /* ScopeRegistryKey.swift in Sources */, + 3F8EA877F153EE374FF8E31A /* ScopedBinding.swift in Sources */, + 38FACA739BA59278725FAE67 /* ServiceEntry.TypeForwarding.swift in Sources */, + EF25C3A81E568411233E6867 /* ServiceEntry.swift in Sources */, + 4BB09CCBB703AADD728BD796 /* ServiceKey.swift in Sources */, + 8D71D83DB3F5D3655FB6C71D /* SimpleBinding.swift in Sources */, + A778AD223AF6C6E30BFFFC84 /* SpinLock.swift in Sources */, + 15FA8361AB335F4CC372A52C /* Swinject+Builder.swift in Sources */, + 828C5B0915A8D08CF98F5F4C /* Swinject.swift in Sources */, + EAC4EA9BAC87B34AD5BA2110 /* SwinjectError.swift in Sources */, + 94615DB1AD57F1547933D8A5 /* SwinjectModule.swift in Sources */, + 8F48909C95AA648D056A392B /* SwinjectTree.swift in Sources */, + 0CFCEE57963529ECA1FFD8C2 /* SynchronizedResolver.Arguments.swift in Sources */, + ED346CAABC0FF77612D9E186 /* SynchronizedResolver.swift in Sources */, + 3B61931D1E9C0F7D1AAEDDF7 /* TypeBinder.swift in Sources */, + 62986D0AAAE9D3934E125332 /* TypeDescriptor.swift in Sources */, + 900A130E222A2FE479D8D348 /* UnavailableItems.swift in Sources */, + 39D7CF8F5563E3C1BDDEED93 /* _Resolver.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -892,30 +1326,48 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 5247D163D277E44E7FD9F34A /* Animal.swift in Sources */, - BE87396543B252618790873A /* AssemblerSpec.swift in Sources */, - 5D290B067B74A36E552A7041 /* BasicAssembly.swift in Sources */, - ED9BFC3E808DEAD8FAC55893 /* BehaviorFakes.swift in Sources */, - 1B0EB3B7A052F64E94D74E87 /* Circularity.swift in Sources */, - 20240BBFA874D27CFD896044 /* ContainerSpec.Arguments.swift in Sources */, - 1727EBCCD8C71D08851A7410 /* ContainerSpec.Behavior.swift in Sources */, - 0C78A6E9A14903C552837408 /* ContainerSpec.Circularity.swift in Sources */, - 075EB59C6EDD6B80867B1504 /* ContainerSpec.CustomScope.swift in Sources */, - CACBE4F33EFE0CA42C6CFE1F /* ContainerSpec.CustomStringConvertible.swift in Sources */, - 72DE2F84AC8F4635EA5271B6 /* ContainerSpec.DebugHelper.swift in Sources */, - A13B16F6559AEB652E160E0C /* ContainerSpec.GraphCaching.swift in Sources */, - 1DD937FA2EF27FF04C2EF25B /* ContainerSpec.TypeForwarding.swift in Sources */, - C875EFA8E8DBD0F31D71EC2A /* ContainerSpec.swift in Sources */, - B86853DECB65EA40E6278C9C /* EmploymentAssembly.swift in Sources */, - 4AF3F51DF2307CD6A492A6B5 /* Food.swift in Sources */, - A7668BF415225429EFAF0E35 /* LazySpec.swift in Sources */, - 7EDEE8914F8AA2786C36DCD9 /* LoadAwareAssembly.swift in Sources */, - A26A6675AEFBA7B0BA4D54B0 /* Person.swift in Sources */, - 4B805F11A7508EC44B45CA58 /* ProviderSpec.swift in Sources */, - E55F6A7F3E680CD37FF30CB3 /* ServiceEntrySpec.swift in Sources */, - 700B9A4AA23950509753EB8B /* ServiceKeySpec.swift in Sources */, - 4D2202002FEB4BC17F348209 /* SynchronizedResolverSpec.swift in Sources */, - 8182EFE66C55AA14FAE05C29 /* WeakStorageSpec.swift in Sources */, + 2BE5AF2623B96992C74970F9 /* Animal.swift in Sources */, + D7D5560E4F790F41126F61CF /* AssemblerSpec.swift in Sources */, + 4503217DA585B602EDE65742 /* BasicAssembly.swift in Sources */, + F50BA96120EDA5D470F4265C /* BehaviorFakes.swift in Sources */, + 87056684D7F91917F6B0AC7A /* BinderEnvironmentSpec.swift in Sources */, + 7845113EAF8FFAFD5EC10540 /* BindingKeySpec.swift in Sources */, + 876F90C64EA036596E797CB3 /* Bridge.swift in Sources */, + 4C55A4A0FFA4E251DC482E20 /* Circularity.swift in Sources */, + 4A9FFFF0FF25724AC5A0BB52 /* ContainerSpec.Arguments.swift in Sources */, + A4EA3E548D1CAB029697B0A9 /* ContainerSpec.Behavior.swift in Sources */, + 86E1845B6272AF95F1806CB4 /* ContainerSpec.Circularity.swift in Sources */, + 6C59839F450D54DB72D0D726 /* ContainerSpec.CustomScope.swift in Sources */, + 93DCA2A58C4067D5E60F7ED1 /* ContainerSpec.CustomStringConvertible.swift in Sources */, + F78892037CEB565626A69451 /* ContainerSpec.DebugHelper.swift in Sources */, + F1931BC25DA64EF32EC42F86 /* ContainerSpec.GraphCaching.swift in Sources */, + F8DB4EDA0367BCC6832E4AA6 /* ContainerSpec.TypeForwarding.swift in Sources */, + 4C6D7AE29CB7E16431AACFA2 /* ContainerSpec.swift in Sources */, + 8D75A0A4A84E2B46E264B5FB /* ContextedResolverSpec.swift in Sources */, + A014793C56F8966AD2D7CC50 /* Convenience.swift in Sources */, + DC5C3A946BDA224C388D2438 /* EmploymentAssembly.swift in Sources */, + 60AF45155775AA5E97AAB5C1 /* Food.swift in Sources */, + 9D1AD9CBA32CEE29EF6C68C2 /* GeneratedMocks.swift in Sources */, + 9C08C2D57E0B0B46D5748B6C /* LazySpec.swift in Sources */, + 013A1E1096BD1305A3A14493 /* LoadAwareAssembly.swift in Sources */, + 01197582F81B8D30D7D4A8AF /* NonGeneratedMocks.swift in Sources */, + DA6CB0A98FE5968CAAFDE9BF /* Person.swift in Sources */, + 788AE378F10DA216265FFF52 /* ProviderSpec.swift in Sources */, + 16FE1BC18A9DD0D21CAF2806 /* ScopeRegistryKeySpec.swift in Sources */, + D2391A103E7356AD7E08F5BA /* ScopedBindingSpec.swift in Sources */, + 79814146B3796F42B447326D /* ServiceEntrySpec.swift in Sources */, + 45E5B568D6D0E7FC976DCDC1 /* ServiceKeySpec.swift in Sources */, + 91FED72828F68263D599B6C0 /* SimpleBindingSpec.swift in Sources */, + 5CB4448E66F839C3915D6927 /* StandardScopeRegistrySpec.swift in Sources */, + A4C25E4406175163B7C5B810 /* SwinjectApiSpec.swift in Sources */, + BB3AAADF214D5FF3E25E3974 /* SwinjectSpec.swift in Sources */, + F7F9B3DB89AC8EC05B6A2B89 /* SwinjectTreeBuilderSpec.swift in Sources */, + EEB3FA667B9103A8417F5EA4 /* SynchronizedResolverSpec.swift in Sources */, + 375945E6CD15BC4D5C8654C9 /* TaggedTypeSpec.swift in Sources */, + B1B107E3FA2DC2E985160D75 /* TestModels.swift in Sources */, + B9FAEC69210B352FC744079E /* TypeBinderSpec.swift in Sources */, + 3A2FE7C2BA76C096122F92ED /* UnboundScopeSpec.swift in Sources */, + 5C06BD3982896046EAA70C8C /* WeakStorageSpec.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -923,30 +1375,48 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 4676E3F114A76CA377C1AFEA /* Animal.swift in Sources */, - 7402D61AAD867E4307F0C5CD /* AssemblerSpec.swift in Sources */, - 7F87DDBFFE209D63EDCF2DCC /* BasicAssembly.swift in Sources */, - D9538DE064194CC8EF546AE5 /* BehaviorFakes.swift in Sources */, - 22D5B9E5714FCAB1ACC43D17 /* Circularity.swift in Sources */, - 27FDAE467746E4974EB287EF /* ContainerSpec.Arguments.swift in Sources */, - 2345F9D14C54EF8C860DCDA6 /* ContainerSpec.Behavior.swift in Sources */, - BDBC4E2B95A3C16E377517A2 /* ContainerSpec.Circularity.swift in Sources */, - 47D6EF0F9A0CDF72690F57BF /* ContainerSpec.CustomScope.swift in Sources */, - 10803956513842C932359FE2 /* ContainerSpec.CustomStringConvertible.swift in Sources */, - 1A2377BC65B8A180D68BB262 /* ContainerSpec.DebugHelper.swift in Sources */, - 45FA563D704A03B7859FFFC8 /* ContainerSpec.GraphCaching.swift in Sources */, - AA27D98622E1E7D0DAA2AB6E /* ContainerSpec.TypeForwarding.swift in Sources */, - 1441592A94F585D04EDE2C6C /* ContainerSpec.swift in Sources */, - CF5A5794A6F5CA48017907A4 /* EmploymentAssembly.swift in Sources */, - BBF5CD565090567DD9AF1FCF /* Food.swift in Sources */, - 4A27DDA9D1B4C60031832778 /* LazySpec.swift in Sources */, - 586655E32F8BDB7E0AA27818 /* LoadAwareAssembly.swift in Sources */, - 402AAC65E9FD3A7B3CC97E55 /* Person.swift in Sources */, - AA825E89EC3B290292D842CC /* ProviderSpec.swift in Sources */, - 20F6C8D41D807E70796EBEA7 /* ServiceEntrySpec.swift in Sources */, - 86485CD992A5A151BF5C3418 /* ServiceKeySpec.swift in Sources */, - A61A3F70F3DB46DF8C92FD27 /* SynchronizedResolverSpec.swift in Sources */, - C086EF6C96295CCB3CB99FC3 /* WeakStorageSpec.swift in Sources */, + EC4EE4B0AECDBA8EC0B8F73D /* Animal.swift in Sources */, + 30BD96CC0333463C71377C4B /* AssemblerSpec.swift in Sources */, + 5329D4D400755935B22C0881 /* BasicAssembly.swift in Sources */, + 5E983707B893B9A8EF94B33E /* BehaviorFakes.swift in Sources */, + FD1678ED0C9813A653D9C68B /* BinderEnvironmentSpec.swift in Sources */, + 166CBBCA1E1441AD87A60EFF /* BindingKeySpec.swift in Sources */, + 4B35CE8BAA88DCAE7D36BC4B /* Bridge.swift in Sources */, + B1B1A13B6792198E4E835034 /* Circularity.swift in Sources */, + 0516305FEAEA5A677A6FA9B3 /* ContainerSpec.Arguments.swift in Sources */, + 2BD8335377FA7F918849C815 /* ContainerSpec.Behavior.swift in Sources */, + 37FE9A9C76DB50ABB28AF9BE /* ContainerSpec.Circularity.swift in Sources */, + 714EFF2818A5DE7278A522BB /* ContainerSpec.CustomScope.swift in Sources */, + E423395FC7006DD82513F347 /* ContainerSpec.CustomStringConvertible.swift in Sources */, + E6E536A44F40492F42CA4044 /* ContainerSpec.DebugHelper.swift in Sources */, + 0125E3E8A17D6F2F0CE2F893 /* ContainerSpec.GraphCaching.swift in Sources */, + FAF8F8B75F63D43995A004E8 /* ContainerSpec.TypeForwarding.swift in Sources */, + C797CCF413DF181935DAB58C /* ContainerSpec.swift in Sources */, + 76B3D9DBF8D5593F67A7B7E6 /* ContextedResolverSpec.swift in Sources */, + DE0A534B660AA93F73A2CB41 /* Convenience.swift in Sources */, + 833635A5D695AA696559C250 /* EmploymentAssembly.swift in Sources */, + F4D2218805AEBF797A2945AB /* Food.swift in Sources */, + 64BC606D6414CB4BE8834B08 /* GeneratedMocks.swift in Sources */, + D42D98955F4F78E3FC91803E /* LazySpec.swift in Sources */, + 9B04477B2B117122CB99989A /* LoadAwareAssembly.swift in Sources */, + 3A149A223FA316F68C0A486A /* NonGeneratedMocks.swift in Sources */, + 2B386345150685F670BF04B1 /* Person.swift in Sources */, + 03E7834C4448A5D939948CCF /* ProviderSpec.swift in Sources */, + 86CD1F46C15A352BCF7CE396 /* ScopeRegistryKeySpec.swift in Sources */, + 9B83FF80C5BE658ED0F7B709 /* ScopedBindingSpec.swift in Sources */, + D628C0489129065C23B33107 /* ServiceEntrySpec.swift in Sources */, + 7A9246A43400FC1504683E20 /* ServiceKeySpec.swift in Sources */, + 8AEB5894656086C3E2F022FD /* SimpleBindingSpec.swift in Sources */, + D4939ABFFDAE2A5768D23C65 /* StandardScopeRegistrySpec.swift in Sources */, + 6C980EED98CBEADFD6DAA72A /* SwinjectApiSpec.swift in Sources */, + 3F1FB19A735BE6E1FA749E75 /* SwinjectSpec.swift in Sources */, + E34C98A8BF87513994A6AD86 /* SwinjectTreeBuilderSpec.swift in Sources */, + 70268F222B8478BDC084E211 /* SynchronizedResolverSpec.swift in Sources */, + D86ACC6D9B9C62FF398F8293 /* TaggedTypeSpec.swift in Sources */, + 549227903CFDDF4E8272C691 /* TestModels.swift in Sources */, + 22837E727E47A3B8A588AB78 /* TypeBinderSpec.swift in Sources */, + 0D6143A7732F1334275D3658 /* UnboundScopeSpec.swift in Sources */, + 53F72D1C7E26B52E5D548206 /* WeakStorageSpec.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -954,29 +1424,51 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - B61E5AE2DD1EAD926D5AEB2F /* Assembler.swift in Sources */, - 0D37403DE7C898FE2A10BD33 /* Assembly.swift in Sources */, - C1FC636DE630CA087CBC6408 /* Behavior.swift in Sources */, - D56BA2D6F1FD24840F5FFABC /* Container.Arguments.swift in Sources */, - 7BF577F6D6ACC84563538B81 /* Container.Logging.swift in Sources */, - A6BB3A31E614C0F121D3C6A7 /* Container.TypeForwarding.swift in Sources */, - A7753D1167A5734EC2443A22 /* Container.swift in Sources */, - 58E6E45CB0688AE1E1F17E2D /* DebugHelper.swift in Sources */, - F90B6E4422BC7E6C62F35A9D /* FunctionType.swift in Sources */, - 0B898EC1B4F5EB15BFBE93BD /* GraphIdentifier.swift in Sources */, - DB34E302A6E9CFA36D3DF0AD /* InstanceStorage.swift in Sources */, - 2828C15FCDE70DB18B81D8FE /* InstanceWrapper.swift in Sources */, - 39E32CABC6B0830B733518F6 /* ObjectScope.Standard.swift in Sources */, - 8A9F1BA9C50102EA05550627 /* ObjectScope.swift in Sources */, - 175D54CF1A731ED4512264B7 /* Resolver.swift in Sources */, - 7840FF61771830C4E1FC3CD3 /* ServiceEntry.TypeForwarding.swift in Sources */, - BD4F788A72567496B6C2DE1A /* ServiceEntry.swift in Sources */, - 30350031317A671C77F81A96 /* ServiceKey.swift in Sources */, - 08AD1C582FACCC7B9795B773 /* SpinLock.swift in Sources */, - 2E434DABCF502284B530CD54 /* SynchronizedResolver.Arguments.swift in Sources */, - 0CB54EA8A31AA0CEC8797118 /* SynchronizedResolver.swift in Sources */, - 9DC4FFC335C3E9DA114909F8 /* UnavailableItems.swift in Sources */, - 8EC748DCE0D0671F6CDE49FD /* _Resolver.swift in Sources */, + 94804E926B3009A776DD0B61 /* Assembler.swift in Sources */, + C6ED278B6F0E08A4B1E57C45 /* Assembly.swift in Sources */, + 588A600231D894122A4D9C47 /* Behavior.swift in Sources */, + 196AA219BB35334B07B34F37 /* BinderEnvironment.swift in Sources */, + 4735419DE3D63E556D07C663 /* Binding.swift in Sources */, + FDB7873663CEFBF7BE76ECFF /* BindingKey.swift in Sources */, + 2B67E8B80A930E8598FAD10C /* Closable.swift in Sources */, + 7E0539C5CD130F0AC4B02096 /* Container.Arguments.swift in Sources */, + E9F5DF3C8AA3A9651D504AF7 /* Container.Logging.swift in Sources */, + 5381C2CDA084C5BEF82D7521 /* Container.TypeForwarding.swift in Sources */, + AAB6386F88442B22E9F7FF0E /* Container.swift in Sources */, + C75EC8F8DD60676B120917EA /* ContextedResolver.swift in Sources */, + CC5509F4681D4489DB0D447E /* DebugHelper.swift in Sources */, + FD792405FD95651F8205BB2D /* FunctionType.swift in Sources */, + C16D64C4A1ABCF441BEB2EBE /* GraphIdentifier.swift in Sources */, + 58CFFB8C98C465B9101AA9A8 /* InstanceMaker.swift in Sources */, + 9AFDF0122A11B2E996B16C3D /* InstanceRequest.swift in Sources */, + E7383E65C483ED1E66A49C5C /* InstanceStorage.swift in Sources */, + 3B2E8B8CF4825DB05B0233F8 /* InstanceWrapper.swift in Sources */, + C50BFD826112288F1D693A30 /* Matchable.swift in Sources */, + A2745DCB0ACE7714C65CA2A9 /* ObjectScope.Standard.swift in Sources */, + 401A790CF8450924114D89ED /* ObjectScope.swift in Sources */, + 741344C30785507B22DF703B /* Resolver+Injection.swift in Sources */, + E62C6509D0B52001CC309068 /* Resolver.swift in Sources */, + FDCF96E2A442CDC6815B8127 /* Resolver.swift in Sources */, + 1718A1577AB543174FD8E644 /* Scope.swift in Sources */, + 1F4FBB9D795CE9D45E5A8BEE /* ScopeRegistry.swift in Sources */, + 54A1FEE340AC3A2413876AD2 /* ScopeRegistryKey.swift in Sources */, + 73214A0BF7D4AE8B78DEB4FD /* ScopedBinding.swift in Sources */, + 982E4682C79B74226C03E0C9 /* ServiceEntry.TypeForwarding.swift in Sources */, + 908AE547955AE4432C1D161A /* ServiceEntry.swift in Sources */, + CA7DED9FF907336CB6091795 /* ServiceKey.swift in Sources */, + DB14CA46130A816F6FAADE92 /* SimpleBinding.swift in Sources */, + EEA8C20EB41C7FF5168941A5 /* SpinLock.swift in Sources */, + FCBA6B66A6BBA29B3EC6CDDD /* Swinject+Builder.swift in Sources */, + B5048A00D49FD5C1C098EE01 /* Swinject.swift in Sources */, + 439254FAE8DF567DE9659ADA /* SwinjectError.swift in Sources */, + AA6651CFD4090465E7CB7871 /* SwinjectModule.swift in Sources */, + 4DA000959B4D60B509859810 /* SwinjectTree.swift in Sources */, + DDFC9466110B6C18B2DCCD34 /* SynchronizedResolver.Arguments.swift in Sources */, + D7C2A6D05BD948EA1E3B26FB /* SynchronizedResolver.swift in Sources */, + 5D2C492FD5088FCB2BA5CDB8 /* TypeBinder.swift in Sources */, + 03005DC48E35AEF37251FADC /* TypeDescriptor.swift in Sources */, + 3FCA6D47DF9FC0CDC62B8404 /* UnavailableItems.swift in Sources */, + 5541D9BB4DF2EBB3E7325359 /* _Resolver.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -984,30 +1476,48 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 6805CF789644E4B5C584A718 /* Animal.swift in Sources */, - 090E91188A70ECF0954B4C77 /* AssemblerSpec.swift in Sources */, - 474999499F01967E54E300A8 /* BasicAssembly.swift in Sources */, - CCE1FC81D2456BC5F439585F /* BehaviorFakes.swift in Sources */, - 638F1392D758C1BCE9B1EC82 /* Circularity.swift in Sources */, - 5BAAF912E24457CD60A13C31 /* ContainerSpec.Arguments.swift in Sources */, - 73A5651B096AD8DF3B1F2994 /* ContainerSpec.Behavior.swift in Sources */, - 87F79D3108B7A3BCC61F4B11 /* ContainerSpec.Circularity.swift in Sources */, - DE192CCEA6B9CF4DCA5672EA /* ContainerSpec.CustomScope.swift in Sources */, - 1D074CFE13423997A82ADF07 /* ContainerSpec.CustomStringConvertible.swift in Sources */, - CE741D8C6B8C31D05A5C6AD6 /* ContainerSpec.DebugHelper.swift in Sources */, - 4055DBF12F18CE2B4A96A85E /* ContainerSpec.GraphCaching.swift in Sources */, - 30EC53EC03C05BF6681FC187 /* ContainerSpec.TypeForwarding.swift in Sources */, - 5918BFBD4D4379D4B6FDA658 /* ContainerSpec.swift in Sources */, - D1C66A9C78612719063E399E /* EmploymentAssembly.swift in Sources */, - 9B6F196AB4CFAB63D982488E /* Food.swift in Sources */, - BEEF777D3B3975F2E9107746 /* LazySpec.swift in Sources */, - 43CC601C7D23298C9E52D59B /* LoadAwareAssembly.swift in Sources */, - A3F92AC7BF36EB36A788FDC4 /* Person.swift in Sources */, - 90CE5A8E248F46DAD69ECBBC /* ProviderSpec.swift in Sources */, - A2761D703903F90D61CF5C99 /* ServiceEntrySpec.swift in Sources */, - FAB069174717CDFE17EEF2B9 /* ServiceKeySpec.swift in Sources */, - 6BED7E1B661C866CC829ADDC /* SynchronizedResolverSpec.swift in Sources */, - C00B23025B6846852DF1F78B /* WeakStorageSpec.swift in Sources */, + EFCA30870DA55BC3572AF634 /* Animal.swift in Sources */, + A44D1B2E48E1C0FEF146933A /* AssemblerSpec.swift in Sources */, + 124369E08D4848D05E3EA6B1 /* BasicAssembly.swift in Sources */, + 2C6047BB84D52FC94F63B7C8 /* BehaviorFakes.swift in Sources */, + 7480A500FEC04BB9CB048AE1 /* BinderEnvironmentSpec.swift in Sources */, + 13379D1C70FC17FE2F949341 /* BindingKeySpec.swift in Sources */, + E584841CFD26155FB056C85A /* Bridge.swift in Sources */, + A600D3F52D38EBC5A3C75CC2 /* Circularity.swift in Sources */, + C7BB5752C697E748B828C03B /* ContainerSpec.Arguments.swift in Sources */, + 4C89DEC934923C4BBF6A3616 /* ContainerSpec.Behavior.swift in Sources */, + EAD0757CE0163D3549CB5405 /* ContainerSpec.Circularity.swift in Sources */, + 52E8D60BBA9177F35E823779 /* ContainerSpec.CustomScope.swift in Sources */, + 377EE35B80E8F91543B52F0C /* ContainerSpec.CustomStringConvertible.swift in Sources */, + 509CD01E61B453F238D33973 /* ContainerSpec.DebugHelper.swift in Sources */, + D88115BD7D62C38F04045EF0 /* ContainerSpec.GraphCaching.swift in Sources */, + 5D241BBB39F54B8FA2BFF595 /* ContainerSpec.TypeForwarding.swift in Sources */, + 37E07236E0E63570242CE23F /* ContainerSpec.swift in Sources */, + 4578AA4291288B21ABD74735 /* ContextedResolverSpec.swift in Sources */, + 564B886D2A35AF26FC411922 /* Convenience.swift in Sources */, + 58C9D537D453BC7C7DC5C0C1 /* EmploymentAssembly.swift in Sources */, + 0539332D989C37CA34A5FB4F /* Food.swift in Sources */, + F1D5D6A0A7679A14317617E1 /* GeneratedMocks.swift in Sources */, + 661B5A18940BA6E67D9BA65E /* LazySpec.swift in Sources */, + 9CEF62C5A3EC3CB8034F08BB /* LoadAwareAssembly.swift in Sources */, + 963D32297EE5CA9C18A0C246 /* NonGeneratedMocks.swift in Sources */, + 71674FB84CBE1E97B72123BF /* Person.swift in Sources */, + 261D54C316CB625359F7EE97 /* ProviderSpec.swift in Sources */, + 9623C7F8B9FED0541D959708 /* ScopeRegistryKeySpec.swift in Sources */, + 1CFCB38BC4EE2D3AAD40154E /* ScopedBindingSpec.swift in Sources */, + 59E450454D5403C171E8CD20 /* ServiceEntrySpec.swift in Sources */, + 3DA1F1126FD1FC935353F847 /* ServiceKeySpec.swift in Sources */, + 35847FDC65085C6741D2A132 /* SimpleBindingSpec.swift in Sources */, + 58F7BDE8BB54898CA690BD24 /* StandardScopeRegistrySpec.swift in Sources */, + C15318646655D97EBDCAA67B /* SwinjectApiSpec.swift in Sources */, + 50B230799AFB8C24D1F5CD5D /* SwinjectSpec.swift in Sources */, + A4CBDC3AA56FFC5719896568 /* SwinjectTreeBuilderSpec.swift in Sources */, + 89D83D5E42814659DFE8F518 /* SynchronizedResolverSpec.swift in Sources */, + 2D1BB3EDEBEA06A17138B298 /* TaggedTypeSpec.swift in Sources */, + B7CE6F32765FC472CE205458 /* TestModels.swift in Sources */, + EEE1C6EB43E2F4D480A7156A /* TypeBinderSpec.swift in Sources */, + 65764CCFA94D4C0A0822507A /* UnboundScopeSpec.swift in Sources */, + D29AAB45717CC7988EC72163 /* WeakStorageSpec.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1015,30 +1525,48 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - BB97CBCDD4EC8CA43FA4D27E /* Animal.swift in Sources */, - FC8967B917A687C2BB69196E /* AssemblerSpec.swift in Sources */, - 3733855FF6222CF7DCE24F4B /* BasicAssembly.swift in Sources */, - 5A95ABFA790342B2BCD1AD0A /* BehaviorFakes.swift in Sources */, - DA36F83E3A3791702269E5B4 /* Circularity.swift in Sources */, - 96A5AFA0CA2068EFDEDC7CFD /* ContainerSpec.Arguments.swift in Sources */, - 704CA2EDFA147F1D54730AF9 /* ContainerSpec.Behavior.swift in Sources */, - B39E6321D83F35A465A638D6 /* ContainerSpec.Circularity.swift in Sources */, - 4E9795D487BC97278A6CE0A2 /* ContainerSpec.CustomScope.swift in Sources */, - 3BCB0A11FBB2D2EC3D3B6F9C /* ContainerSpec.CustomStringConvertible.swift in Sources */, - 4D278458638503A42F2184E7 /* ContainerSpec.DebugHelper.swift in Sources */, - 8D0076BDF161AF29B32DF783 /* ContainerSpec.GraphCaching.swift in Sources */, - FD6AEC9A2FEEA1CE0D33AFF6 /* ContainerSpec.TypeForwarding.swift in Sources */, - 671ACA3184D8092AFC0E0831 /* ContainerSpec.swift in Sources */, - E2C53E7AD6F4EAC94344EA70 /* EmploymentAssembly.swift in Sources */, - 877278A5D5478D3648ABFE6F /* Food.swift in Sources */, - C0615D8AD0393E52F14AD280 /* LazySpec.swift in Sources */, - 7F191DD81CBC604077F15636 /* LoadAwareAssembly.swift in Sources */, - 54BFB762DC126C707C42BE23 /* Person.swift in Sources */, - A5A103C646976ADA8A7F43BF /* ProviderSpec.swift in Sources */, - 7293CBF54B3122C271BDA9A5 /* ServiceEntrySpec.swift in Sources */, - 78EA94E0C9584CF5F0E01803 /* ServiceKeySpec.swift in Sources */, - E2B2D8E9CA96AD3128FBC460 /* SynchronizedResolverSpec.swift in Sources */, - 0ECBB4FB936DEFAF537BF688 /* WeakStorageSpec.swift in Sources */, + 5CADD5B13173034498BF4A5F /* Animal.swift in Sources */, + D5BD321738E03967CA8E27C6 /* AssemblerSpec.swift in Sources */, + 60CEB9FCA08EFF202DD38096 /* BasicAssembly.swift in Sources */, + 9A551D43739EDE556FF3F9ED /* BehaviorFakes.swift in Sources */, + 2CA05A2362E0390075908A32 /* BinderEnvironmentSpec.swift in Sources */, + 9DD1C1273B38FCF4FFE9BCC2 /* BindingKeySpec.swift in Sources */, + D7DFD1B77BFB5FABAE165A11 /* Bridge.swift in Sources */, + 26AC238FC2FB5279ABF37C89 /* Circularity.swift in Sources */, + 871BB9B8221656F0189ABEC6 /* ContainerSpec.Arguments.swift in Sources */, + 20823C309A5C58900CDFA8C3 /* ContainerSpec.Behavior.swift in Sources */, + 9B9AA902B80620568D732D7B /* ContainerSpec.Circularity.swift in Sources */, + A6A470DC3A6D310AA0671075 /* ContainerSpec.CustomScope.swift in Sources */, + E8D70420E8A3C91D01BC3B5B /* ContainerSpec.CustomStringConvertible.swift in Sources */, + C493D6AD1D8748A2698F0B81 /* ContainerSpec.DebugHelper.swift in Sources */, + 8DBFFFD80828247AED253B0D /* ContainerSpec.GraphCaching.swift in Sources */, + 9F1C7A652660EA87BF599126 /* ContainerSpec.TypeForwarding.swift in Sources */, + E80558941BC2149C25A17495 /* ContainerSpec.swift in Sources */, + 199D71D592CEDF7400DA3D0A /* ContextedResolverSpec.swift in Sources */, + A1B275A2EFA22C45AC46B31E /* Convenience.swift in Sources */, + 187BD516162B3FBB1158E015 /* EmploymentAssembly.swift in Sources */, + D98CA679A3AAC176D291CA8E /* Food.swift in Sources */, + 3F04B9C7812B5E21DCE4D36C /* GeneratedMocks.swift in Sources */, + 648FDC2A1E3DC75CB47D31E1 /* LazySpec.swift in Sources */, + D10FFA4B80F4BE6024B1DCEE /* LoadAwareAssembly.swift in Sources */, + BAFD66351A9ED8E7BFB19CD3 /* NonGeneratedMocks.swift in Sources */, + 9102F98F672DD39F304AFC3B /* Person.swift in Sources */, + E484C3994AD91E91C454B11D /* ProviderSpec.swift in Sources */, + F4D7CC563B9C212A418C4EBC /* ScopeRegistryKeySpec.swift in Sources */, + 0E8E5B08478EB883D9B52947 /* ScopedBindingSpec.swift in Sources */, + 07538993A345EEC62228247E /* ServiceEntrySpec.swift in Sources */, + 81CCC69088D0ADF8E0DC72AC /* ServiceKeySpec.swift in Sources */, + 1ACC90951353E5F69899A833 /* SimpleBindingSpec.swift in Sources */, + 8AAC0C68038E02A6049ABDC0 /* StandardScopeRegistrySpec.swift in Sources */, + 5F008535F981266945B3968B /* SwinjectApiSpec.swift in Sources */, + 5BBBB5E7162B0429D7332DD4 /* SwinjectSpec.swift in Sources */, + 6DCE3C30CAE0350C428154DC /* SwinjectTreeBuilderSpec.swift in Sources */, + 67A89300EA08B0FB7AB0FBF8 /* SynchronizedResolverSpec.swift in Sources */, + CA202C787FE269EF63ADC449 /* TaggedTypeSpec.swift in Sources */, + 8D58DF5C6963153A8B17D325 /* TestModels.swift in Sources */, + 8F70C49F6F6D27A67CDB8F0C /* TypeBinderSpec.swift in Sources */, + 100DC02D61F72A611B7CF6E3 /* UnboundScopeSpec.swift in Sources */, + 9BAAD1DEBA041700C921A589 /* WeakStorageSpec.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1046,29 +1574,51 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 4E5331DAB50E295CDEC474C8 /* Assembler.swift in Sources */, - A1DF30AA83A2A4C37D98D61D /* Assembly.swift in Sources */, - EDFE608E5040BE9F021E306F /* Behavior.swift in Sources */, - B730032C29EFD182B190AD51 /* Container.Arguments.swift in Sources */, - 864328A1CFF21E37951EF280 /* Container.Logging.swift in Sources */, - 6690747249BE2F741C15D234 /* Container.TypeForwarding.swift in Sources */, - 993CE5C68BD5B7A752E11CCC /* Container.swift in Sources */, - 6BE1770BC7453F216178DBC2 /* DebugHelper.swift in Sources */, - 302C5A83E38B435AA67FFC86 /* FunctionType.swift in Sources */, - EF9934A7BA979658B5F8F43D /* GraphIdentifier.swift in Sources */, - 37655AE5BF345D66B36726FF /* InstanceStorage.swift in Sources */, - A5DF7F64F8B8AB188D53CCEA /* InstanceWrapper.swift in Sources */, - 0D2BC7D4B52A54D2D0D8E3F1 /* ObjectScope.Standard.swift in Sources */, - 8BA859223087DF7188401BD3 /* ObjectScope.swift in Sources */, - 4357EE4ED4DBA7D9AFF68E67 /* Resolver.swift in Sources */, - 9B4D16CC757508288B70318F /* ServiceEntry.TypeForwarding.swift in Sources */, - DE770BEC337CC097E8F9D71D /* ServiceEntry.swift in Sources */, - 2BBA6302511D78391E3C9F8E /* ServiceKey.swift in Sources */, - E1ABBED82706E6565883AA92 /* SpinLock.swift in Sources */, - 68C043EF2363C867DC147C93 /* SynchronizedResolver.Arguments.swift in Sources */, - C81FF3F03E909FE65874B72A /* SynchronizedResolver.swift in Sources */, - D223F4C178F9B7F3E87B14FB /* UnavailableItems.swift in Sources */, - C7CFEAB275D2CC34CF1055EF /* _Resolver.swift in Sources */, + DD4783AE23A8C2A89F591605 /* Assembler.swift in Sources */, + 39431794D93EA4DDD0BBB2C5 /* Assembly.swift in Sources */, + C3AD37D47C38E5EB20FAF917 /* Behavior.swift in Sources */, + 01D985B5F99817DEE0E0DAD1 /* BinderEnvironment.swift in Sources */, + 705F51FD21F7E1536BFC0C41 /* Binding.swift in Sources */, + A4866802E1E597EEFEFDEB66 /* BindingKey.swift in Sources */, + 816F47E9D87CAE910091B484 /* Closable.swift in Sources */, + 7472B748AEA9F4D1E5EF9A70 /* Container.Arguments.swift in Sources */, + 31266C4BA7CE6C3FBAFBACDD /* Container.Logging.swift in Sources */, + 0DFB6FB4DF6A713EA545930F /* Container.TypeForwarding.swift in Sources */, + C8F1F075F5792C9936B0577D /* Container.swift in Sources */, + 6BFA0D58FD4131D3A2248208 /* ContextedResolver.swift in Sources */, + E2E66C47DB6C2F99B13F01CF /* DebugHelper.swift in Sources */, + D1E4114EED19E341BB80869A /* FunctionType.swift in Sources */, + D8E2986FB186B630E54B60CD /* GraphIdentifier.swift in Sources */, + 48714C7B99D346C83E1E8293 /* InstanceMaker.swift in Sources */, + 04C24C140F2D0BBFE48C682C /* InstanceRequest.swift in Sources */, + 9D99BBDFE65AC69067BC569C /* InstanceStorage.swift in Sources */, + 53DC7093FD7C2FEE16154DED /* InstanceWrapper.swift in Sources */, + DEB3F135FFAEBF825881E886 /* Matchable.swift in Sources */, + 61FA449BF10682C9E89E767F /* ObjectScope.Standard.swift in Sources */, + D688F61360D46A16B0678BA4 /* ObjectScope.swift in Sources */, + 1C2F5A09F986586F85FAC3E8 /* Resolver+Injection.swift in Sources */, + 1B29712FD3C5FB3B372EE35F /* Resolver.swift in Sources */, + 8108969F33C37040624E0D02 /* Resolver.swift in Sources */, + D557A108A21751DF75542692 /* Scope.swift in Sources */, + D7DE20CC15F3A6BD09E43A75 /* ScopeRegistry.swift in Sources */, + 9437AF5CAAD1A2D033AE3599 /* ScopeRegistryKey.swift in Sources */, + D6AA597218691F1FE87724E7 /* ScopedBinding.swift in Sources */, + 78ACD9EBF8625ECD24103A17 /* ServiceEntry.TypeForwarding.swift in Sources */, + EABC31077D2369311E6C14C3 /* ServiceEntry.swift in Sources */, + ABA204BE7AEAC01BF1D6002E /* ServiceKey.swift in Sources */, + 35175F8F168EDB5EB83BD8E9 /* SimpleBinding.swift in Sources */, + 939769201BD93B84E6BAD258 /* SpinLock.swift in Sources */, + D18275ADB0E56D3087894518 /* Swinject+Builder.swift in Sources */, + 9E084F679592ADFA28D3AD6D /* Swinject.swift in Sources */, + AAC84D757FE8F601FF053923 /* SwinjectError.swift in Sources */, + 5570E14A839D4065FFBA7EF4 /* SwinjectModule.swift in Sources */, + E8A89383E1D1106DEABB778B /* SwinjectTree.swift in Sources */, + 01146C3ECC9A6B1973EED93F /* SynchronizedResolver.Arguments.swift in Sources */, + 9C81098E44AF728D63640DA1 /* SynchronizedResolver.swift in Sources */, + 050982D62AE0244372456440 /* TypeBinder.swift in Sources */, + 572CA6A9E19927F5D434BB6F /* TypeDescriptor.swift in Sources */, + 4F10C414D344D3FF9212D51F /* UnavailableItems.swift in Sources */, + D0F428B5C92CA0C25EF4BE61 /* _Resolver.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1076,29 +1626,51 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - E319B41334A1A1B39718C82D /* Assembler.swift in Sources */, - 4FB5B42144E8C4C1EB052E5C /* Assembly.swift in Sources */, - 72EDFFA3763E4BE2F735F513 /* Behavior.swift in Sources */, - 965528C3E27CB1110A8303A6 /* Container.Arguments.swift in Sources */, - A78168C79AFDFF0A389360AB /* Container.Logging.swift in Sources */, - E41556F95F26B91659A528C7 /* Container.TypeForwarding.swift in Sources */, - 0DDB9143708044A62671A2F1 /* Container.swift in Sources */, - 1C093CAA7406BDC73E019673 /* DebugHelper.swift in Sources */, - 0F5F881E37F5CD79ED9E0408 /* FunctionType.swift in Sources */, - 57302467C822B28ADA343F17 /* GraphIdentifier.swift in Sources */, - FF4CDB6E2BF9F2F0EAA237D7 /* InstanceStorage.swift in Sources */, - 77274083C7E0835D523E51F8 /* InstanceWrapper.swift in Sources */, - 781B68347543DE1190644D44 /* ObjectScope.Standard.swift in Sources */, - 4E0826120965628AF3E94107 /* ObjectScope.swift in Sources */, - 9A103C945465C850E48EDFA5 /* Resolver.swift in Sources */, - AF98E2A2C8E6826789B6BA7D /* ServiceEntry.TypeForwarding.swift in Sources */, - BE7B3987C077BF12943BB9DD /* ServiceEntry.swift in Sources */, - F62433C175C3BE1E8802EB92 /* ServiceKey.swift in Sources */, - 251DDFD910D4EBF1737E46CE /* SpinLock.swift in Sources */, - 3265EB0F084010B28B6B4C2B /* SynchronizedResolver.Arguments.swift in Sources */, - 9F847EF5225A75955CA90A66 /* SynchronizedResolver.swift in Sources */, - 95BBA67883E6022CA70018F6 /* UnavailableItems.swift in Sources */, - DC462CD4ACCE5B2843CA4608 /* _Resolver.swift in Sources */, + EEB1E43EF50551F8B9793381 /* Assembler.swift in Sources */, + 1F256E6920935F88C753F739 /* Assembly.swift in Sources */, + AF5F860DBFE2607EF4157CF7 /* Behavior.swift in Sources */, + 4D0ABCA733720469F2240C31 /* BinderEnvironment.swift in Sources */, + EEC04BEF02E6776003CC2003 /* Binding.swift in Sources */, + E0D7B3285AA1FE51E14A52A1 /* BindingKey.swift in Sources */, + 418F111C8E128766AC8E33CC /* Closable.swift in Sources */, + 7DD047C203659BCA7F04E48D /* Container.Arguments.swift in Sources */, + F151A5040BB76E8E909D9D6B /* Container.Logging.swift in Sources */, + 782801544D9F468F536E045E /* Container.TypeForwarding.swift in Sources */, + 91DAE32F86CEA897AD52AEDB /* Container.swift in Sources */, + 151340C24653963B97464BA9 /* ContextedResolver.swift in Sources */, + 16727D477E4258A547C21D93 /* DebugHelper.swift in Sources */, + 087E0E3216DB7D53DE7A6BE0 /* FunctionType.swift in Sources */, + 457481A631CA1253094D108B /* GraphIdentifier.swift in Sources */, + 41EEA4724CD401F38F9622E3 /* InstanceMaker.swift in Sources */, + 5E74770DDD69EAFE5D187F90 /* InstanceRequest.swift in Sources */, + 10EB88F976AC1025DC22FE8A /* InstanceStorage.swift in Sources */, + 39F9BBD670C944E1331FAB13 /* InstanceWrapper.swift in Sources */, + D3828F01A014F3A06B1141D7 /* Matchable.swift in Sources */, + 1F2E1C6B8F28C5441D52C033 /* ObjectScope.Standard.swift in Sources */, + 3AC304A612ECAED02C58BBF5 /* ObjectScope.swift in Sources */, + 90B4143005C86717AC76B6EE /* Resolver+Injection.swift in Sources */, + 8A212C0486A514CF17B5F140 /* Resolver.swift in Sources */, + 66033468A5FC65C19B60086A /* Resolver.swift in Sources */, + B2FCC51BB61148422256A14A /* Scope.swift in Sources */, + 46A14FAA5AA73BE8A0397707 /* ScopeRegistry.swift in Sources */, + 18A07EB6FB61F3CDCC766AF4 /* ScopeRegistryKey.swift in Sources */, + 6F5323F408E5708076C02768 /* ScopedBinding.swift in Sources */, + 51F2CD3C07148069167AB6E9 /* ServiceEntry.TypeForwarding.swift in Sources */, + 4939B8B795061A74ADFC02D8 /* ServiceEntry.swift in Sources */, + B753AC265ABCEF3CBCE3C4CE /* ServiceKey.swift in Sources */, + 87F8C64D9E8B4317C0C036E0 /* SimpleBinding.swift in Sources */, + 02CBAAF2DD5E7D589F997A27 /* SpinLock.swift in Sources */, + D267BD55BBEDE3ECEC449472 /* Swinject+Builder.swift in Sources */, + 26C8D37F26408DC308A0CDA3 /* Swinject.swift in Sources */, + 14AECF24B26ECEC8E9086FBB /* SwinjectError.swift in Sources */, + 699DB780BD90A5AAAD5B4646 /* SwinjectModule.swift in Sources */, + 192278AA7165EC3C2C12A4C2 /* SwinjectTree.swift in Sources */, + BF8E048DADB28763928A2ACC /* SynchronizedResolver.Arguments.swift in Sources */, + 748FE5C55FB93BFFA9012CD3 /* SynchronizedResolver.swift in Sources */, + D88D7841C5C84A2E34CE15FD /* TypeBinder.swift in Sources */, + B95786317494375C0E2D2044 /* TypeDescriptor.swift in Sources */, + 4CAAE6389422432C6BE5008C /* UnavailableItems.swift in Sources */, + CE62237127502CCD13CC22C2 /* _Resolver.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1194,7 +1766,7 @@ "$(inherited)", "$(PROJECT_DIR)/Carthage/Build/watchOS", ); - INFOPLIST_FILE = Tests/SwinjectTests/Info.plist; + INFOPLIST_FILE = "Tests/2.0 API/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; @@ -1310,7 +1882,7 @@ "$(inherited)", "$(PROJECT_DIR)/Carthage/Build/tvOS", ); - INFOPLIST_FILE = Tests/SwinjectTests/Info.plist; + INFOPLIST_FILE = "Tests/2.0 API/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; @@ -1380,7 +1952,7 @@ "$(inherited)", "$(PROJECT_DIR)/Carthage/Build/iOS", ); - INFOPLIST_FILE = Tests/SwinjectTests/Info.plist; + INFOPLIST_FILE = "Tests/2.0 API/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; @@ -1496,7 +2068,7 @@ "$(inherited)", "$(PROJECT_DIR)/Carthage/Build/Mac", ); - INFOPLIST_FILE = Tests/SwinjectTests/Info.plist; + INFOPLIST_FILE = "Tests/2.0 API/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; @@ -1515,7 +2087,7 @@ "$(inherited)", "$(PROJECT_DIR)/Carthage/Build/tvOS", ); - INFOPLIST_FILE = Tests/SwinjectTests/Info.plist; + INFOPLIST_FILE = "Tests/2.0 API/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; @@ -1536,7 +2108,7 @@ "$(inherited)", "$(PROJECT_DIR)/Carthage/Build/Mac", ); - INFOPLIST_FILE = Tests/SwinjectTests/Info.plist; + INFOPLIST_FILE = "Tests/2.0 API/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; @@ -1555,7 +2127,7 @@ "$(inherited)", "$(PROJECT_DIR)/Carthage/Build/watchOS", ); - INFOPLIST_FILE = Tests/SwinjectTests/Info.plist; + INFOPLIST_FILE = "Tests/2.0 API/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; @@ -1576,7 +2148,7 @@ "$(inherited)", "$(PROJECT_DIR)/Carthage/Build/iOS", ); - INFOPLIST_FILE = Tests/SwinjectTests/Info.plist; + INFOPLIST_FILE = "Tests/2.0 API/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; diff --git a/Tests/SwinjectTests/.swiftlint.yml b/Tests/2.0 API/.swiftlint.yml similarity index 100% rename from Tests/SwinjectTests/.swiftlint.yml rename to Tests/2.0 API/.swiftlint.yml diff --git a/Tests/SwinjectTests/Animal.swift b/Tests/2.0 API/Animal.swift similarity index 100% rename from Tests/SwinjectTests/Animal.swift rename to Tests/2.0 API/Animal.swift diff --git a/Tests/SwinjectTests/AssemblerSpec.swift b/Tests/2.0 API/AssemblerSpec.swift similarity index 100% rename from Tests/SwinjectTests/AssemblerSpec.swift rename to Tests/2.0 API/AssemblerSpec.swift diff --git a/Tests/SwinjectTests/BasicAssembly.swift b/Tests/2.0 API/BasicAssembly.swift similarity index 100% rename from Tests/SwinjectTests/BasicAssembly.swift rename to Tests/2.0 API/BasicAssembly.swift diff --git a/Tests/SwinjectTests/BehaviorFakes.swift b/Tests/2.0 API/BehaviorFakes.swift similarity index 100% rename from Tests/SwinjectTests/BehaviorFakes.swift rename to Tests/2.0 API/BehaviorFakes.swift diff --git a/Tests/SwinjectTests/Circularity.swift b/Tests/2.0 API/Circularity.swift similarity index 100% rename from Tests/SwinjectTests/Circularity.swift rename to Tests/2.0 API/Circularity.swift diff --git a/Tests/SwinjectTests/ContainerSpec.Arguments.swift b/Tests/2.0 API/ContainerSpec.Arguments.swift similarity index 100% rename from Tests/SwinjectTests/ContainerSpec.Arguments.swift rename to Tests/2.0 API/ContainerSpec.Arguments.swift diff --git a/Tests/SwinjectTests/ContainerSpec.Behavior.swift b/Tests/2.0 API/ContainerSpec.Behavior.swift similarity index 100% rename from Tests/SwinjectTests/ContainerSpec.Behavior.swift rename to Tests/2.0 API/ContainerSpec.Behavior.swift diff --git a/Tests/SwinjectTests/ContainerSpec.Circularity.swift b/Tests/2.0 API/ContainerSpec.Circularity.swift similarity index 100% rename from Tests/SwinjectTests/ContainerSpec.Circularity.swift rename to Tests/2.0 API/ContainerSpec.Circularity.swift diff --git a/Tests/SwinjectTests/ContainerSpec.CustomScope.swift b/Tests/2.0 API/ContainerSpec.CustomScope.swift similarity index 100% rename from Tests/SwinjectTests/ContainerSpec.CustomScope.swift rename to Tests/2.0 API/ContainerSpec.CustomScope.swift diff --git a/Tests/SwinjectTests/ContainerSpec.CustomStringConvertible.swift b/Tests/2.0 API/ContainerSpec.CustomStringConvertible.swift similarity index 100% rename from Tests/SwinjectTests/ContainerSpec.CustomStringConvertible.swift rename to Tests/2.0 API/ContainerSpec.CustomStringConvertible.swift diff --git a/Tests/SwinjectTests/ContainerSpec.DebugHelper.swift b/Tests/2.0 API/ContainerSpec.DebugHelper.swift similarity index 100% rename from Tests/SwinjectTests/ContainerSpec.DebugHelper.swift rename to Tests/2.0 API/ContainerSpec.DebugHelper.swift diff --git a/Tests/SwinjectTests/ContainerSpec.GraphCaching.swift b/Tests/2.0 API/ContainerSpec.GraphCaching.swift similarity index 100% rename from Tests/SwinjectTests/ContainerSpec.GraphCaching.swift rename to Tests/2.0 API/ContainerSpec.GraphCaching.swift diff --git a/Tests/SwinjectTests/ContainerSpec.TypeForwarding.swift b/Tests/2.0 API/ContainerSpec.TypeForwarding.swift similarity index 100% rename from Tests/SwinjectTests/ContainerSpec.TypeForwarding.swift rename to Tests/2.0 API/ContainerSpec.TypeForwarding.swift diff --git a/Tests/SwinjectTests/ContainerSpec.swift b/Tests/2.0 API/ContainerSpec.swift similarity index 100% rename from Tests/SwinjectTests/ContainerSpec.swift rename to Tests/2.0 API/ContainerSpec.swift diff --git a/Tests/SwinjectTests/EmploymentAssembly.swift b/Tests/2.0 API/EmploymentAssembly.swift similarity index 100% rename from Tests/SwinjectTests/EmploymentAssembly.swift rename to Tests/2.0 API/EmploymentAssembly.swift diff --git a/Tests/SwinjectTests/Food.swift b/Tests/2.0 API/Food.swift similarity index 100% rename from Tests/SwinjectTests/Food.swift rename to Tests/2.0 API/Food.swift diff --git a/Tests/SwinjectTests/Info.plist b/Tests/2.0 API/Info.plist similarity index 100% rename from Tests/SwinjectTests/Info.plist rename to Tests/2.0 API/Info.plist diff --git a/Tests/SwinjectTests/LazySpec.swift b/Tests/2.0 API/LazySpec.swift similarity index 100% rename from Tests/SwinjectTests/LazySpec.swift rename to Tests/2.0 API/LazySpec.swift diff --git a/Tests/SwinjectTests/LoadAwareAssembly.swift b/Tests/2.0 API/LoadAwareAssembly.swift similarity index 100% rename from Tests/SwinjectTests/LoadAwareAssembly.swift rename to Tests/2.0 API/LoadAwareAssembly.swift diff --git a/Tests/SwinjectTests/Person.swift b/Tests/2.0 API/Person.swift similarity index 100% rename from Tests/SwinjectTests/Person.swift rename to Tests/2.0 API/Person.swift diff --git a/Tests/SwinjectTests/ProviderSpec.swift b/Tests/2.0 API/ProviderSpec.swift similarity index 100% rename from Tests/SwinjectTests/ProviderSpec.swift rename to Tests/2.0 API/ProviderSpec.swift diff --git a/Tests/SwinjectTests/ServiceEntrySpec.swift b/Tests/2.0 API/ServiceEntrySpec.swift similarity index 100% rename from Tests/SwinjectTests/ServiceEntrySpec.swift rename to Tests/2.0 API/ServiceEntrySpec.swift diff --git a/Tests/SwinjectTests/ServiceKeySpec.swift b/Tests/2.0 API/ServiceKeySpec.swift similarity index 100% rename from Tests/SwinjectTests/ServiceKeySpec.swift rename to Tests/2.0 API/ServiceKeySpec.swift diff --git a/Tests/SwinjectTests/SynchronizedResolverSpec.swift b/Tests/2.0 API/SynchronizedResolverSpec.swift similarity index 100% rename from Tests/SwinjectTests/SynchronizedResolverSpec.swift rename to Tests/2.0 API/SynchronizedResolverSpec.swift diff --git a/Tests/SwinjectTests/WeakStorageSpec.swift b/Tests/2.0 API/WeakStorageSpec.swift similarity index 100% rename from Tests/SwinjectTests/WeakStorageSpec.swift rename to Tests/2.0 API/WeakStorageSpec.swift diff --git a/project.yml b/project.yml index 8cb86759..f19dc9a8 100644 --- a/project.yml +++ b/project.yml @@ -36,7 +36,8 @@ targets: WATCHOS_DEPLOYMENT_TARGET: '2.0' scheme: {} sources: - - Tests/SwinjectTests + - path: Tests + excludes: [LinuxMain.swift] dependencies: - target: Swinject_${platform} - carthage: Quick From e839b6c32b988052fa97bb4dc8443146df4a75e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 21 Jul 2019 15:57:41 +0200 Subject: [PATCH 082/239] Reconcile 2.0 & 3.0 conflicts --- Sources/3.0 API/BinderEnvironment.swift | 50 ++--- Sources/3.0 API/Resolver+Injection.swift | 6 +- Sources/Core/Binding.swift | 2 +- Sources/Core/ContextedResolver.swift | 6 +- Sources/Core/InstanceMaker.swift | 6 +- .../Core/{Resolver.swift => Resolver3.swift} | 9 +- Sources/Core/ScopedBinding.swift | 8 +- Sources/Core/SimpleBinding.swift | 8 +- Sources/Core/Swinject.swift | 2 +- Sources/Core/TypeDescriptor.swift | 4 +- Swinject.xcodeproj/project.pbxproj | 108 ++++++++--- Tests/Support/Convenience.swift | 6 +- Tests/Support/GeneratedMocks.swift | 58 +++--- Tests/Support/NonGeneratedMocks.swift | 8 +- Tests/Unit Specs/BinderEnvironmentSpec.swift | 178 +++++++++--------- Tests/Unit Specs/ContextedResolverSpec.swift | 12 +- Tests/Unit Specs/ScopedBindingSpec.swift | 20 +- Tests/Unit Specs/SwinjectSpec.swift | 58 +++--- Tests/Unit Specs/TypeBinderSpec.swift | 4 +- 19 files changed, 301 insertions(+), 252 deletions(-) rename Sources/Core/{Resolver.swift => Resolver3.swift} (57%) diff --git a/Sources/3.0 API/BinderEnvironment.swift b/Sources/3.0 API/BinderEnvironment.swift index 326be52f..c3df31ff 100644 --- a/Sources/3.0 API/BinderEnvironment.swift +++ b/Sources/3.0 API/BinderEnvironment.swift @@ -15,29 +15,29 @@ public func scoped(_ scope: AScope) -> BinderEnvironment(_ builder: @escaping (Resolver, Context) throws -> Type) -> SimpleBinding.Builder { + func provider(_ builder: @escaping (Resolver3, Context) throws -> Type) -> SimpleBinding.Builder { .init { r, c, _ in try builder(r, c) } } - func factory(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SimpleBinding.Builder { + func factory(_ builder: @escaping (Resolver3, Context, Arg1) throws -> Type) -> SimpleBinding.Builder { .init(builder) } } public extension BinderEnvironment where AScope == Void { - func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SimpleBinding.Builder { + func factory(_ builder: @escaping (Resolver3, Context, Arg1, Arg2) throws -> Type) -> SimpleBinding.Builder { .init { try builder($0, $1, $2.0, $2.1) } } - func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SimpleBinding.Builder { + func factory(_ builder: @escaping (Resolver3, Context, Arg1, Arg2, Arg3) throws -> Type) -> SimpleBinding.Builder { .init { try builder($0, $1, $2.0, $2.1, $2.2) } } - func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SimpleBinding.Builder { + func factory(_ builder: @escaping (Resolver3, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SimpleBinding.Builder { .init { try builder($0, $1, $2.0, $2.1, $2.2, $2.3) } } - func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SimpleBinding.Builder { + func factory(_ builder: @escaping (Resolver3, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SimpleBinding.Builder { .init { try builder($0, $1, $2.0, $2.1, $2.2, $2.3, $2.4) } } } @@ -47,33 +47,33 @@ public extension BinderEnvironment where AScope: Scope, Context == AScope.Contex .init(scope) { _, _, _ in try builder() } } - func singleton(_ builder: @escaping (Resolver) throws -> Type) -> ScopedBinding.Builder { + func singleton(_ builder: @escaping (Resolver3) throws -> Type) -> ScopedBinding.Builder { .init(scope) { r, _, _ in try builder(r) } } - func singleton(_ builder: @escaping (Resolver, Context) throws -> Type) -> ScopedBinding.Builder { + func singleton(_ builder: @escaping (Resolver3, Context) throws -> Type) -> ScopedBinding.Builder { .init(scope) { r, c, _ in try builder(r, c) } } } public extension BinderEnvironment where AScope: Scope, Context == AScope.Context { - func multiton(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> ScopedBinding.Builder { + func multiton(_ builder: @escaping (Resolver3, Context, Arg1) throws -> Type) -> ScopedBinding.Builder { .init(scope, builder) } - func multiton(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> ScopedBinding.Builder { + func multiton(_ builder: @escaping (Resolver3, Context, Arg1, Arg2) throws -> Type) -> ScopedBinding.Builder { .init(scope) { try builder($0, $1, $2.0, $2.1) } } - func multiton(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> ScopedBinding.Builder { + func multiton(_ builder: @escaping (Resolver3, Context, Arg1, Arg2, Arg3) throws -> Type) -> ScopedBinding.Builder { .init(scope) { try builder($0, $1, $2.0, $2.1, $2.2) } } - func multiton(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> ScopedBinding.Builder { + func multiton(_ builder: @escaping (Resolver3, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> ScopedBinding.Builder { .init(scope) { try builder($0, $1, $2.0, $2.1, $2.2, $2.3) } } - func multiton(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> ScopedBinding.Builder { + func multiton(_ builder: @escaping (Resolver3, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> ScopedBinding.Builder { .init(scope) { try builder($0, $1, $2.0, $2.1, $2.2, $2.3, $2.4) } } } @@ -86,27 +86,27 @@ public func provider(_ builder: @escaping () throws -> Type) -> SimpleBind .init { _, _, _ in try builder() } } -public func provider(_ builder: @escaping (Resolver) throws -> Type) -> SimpleBinding.Builder { +public func provider(_ builder: @escaping (Resolver3) throws -> Type) -> SimpleBinding.Builder { .init { r, _, _ in try builder(r) } } -public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> SimpleBinding.Builder { +public func factory(_ builder: @escaping (Resolver3, Arg1) throws -> Type) -> SimpleBinding.Builder { .init { try builder($0, $2) } } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SimpleBinding.Builder { +public func factory(_ builder: @escaping (Resolver3, Arg1, Arg2) throws -> Type) -> SimpleBinding.Builder { .init { try builder($0, $2.0, $2.1) } } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SimpleBinding.Builder { +public func factory(_ builder: @escaping (Resolver3, Arg1, Arg2, Arg3) throws -> Type) -> SimpleBinding.Builder { .init { try builder($0, $2.0, $2.1, $2.2) } } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SimpleBinding.Builder { +public func factory(_ builder: @escaping (Resolver3, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SimpleBinding.Builder { SimpleBinding.Builder { try builder($0, $2.0, $2.1, $2.2, $2.3) } } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SimpleBinding.Builder { +public func factory(_ builder: @escaping (Resolver3, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SimpleBinding.Builder { SimpleBinding.Builder { try builder($0, $2.0, $2.1, $2.2, $2.3, $2.4) } } @@ -114,26 +114,26 @@ public func singleton(_ builder: @escaping () throws -> Type) -> ScopedBin .init(.root) { _, _, _ in try builder() } } -public func singleton(_ builder: @escaping (Resolver) throws -> Type) -> ScopedBinding.Builder { +public func singleton(_ builder: @escaping (Resolver3) throws -> Type) -> ScopedBinding.Builder { .init(.root) { r, _, _ in try builder(r) } } -public func multiton(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> ScopedBinding.Builder { +public func multiton(_ builder: @escaping (Resolver3, Arg1) throws -> Type) -> ScopedBinding.Builder { .init(.root) { try builder($0, $2) } } -public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> ScopedBinding.Builder { +public func multiton(_ builder: @escaping (Resolver3, Arg1, Arg2) throws -> Type) -> ScopedBinding.Builder { .init(.root) { try builder($0, $2.0, $2.1) } } -public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> ScopedBinding.Builder { +public func multiton(_ builder: @escaping (Resolver3, Arg1, Arg2, Arg3) throws -> Type) -> ScopedBinding.Builder { .init(.root) { try builder($0, $2.0, $2.1, $2.2) } } -public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> ScopedBinding.Builder { +public func multiton(_ builder: @escaping (Resolver3, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> ScopedBinding.Builder { .init(.root) { try builder($0, $2.0, $2.1, $2.2, $2.3) } } -public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> ScopedBinding.Builder { +public func multiton(_ builder: @escaping (Resolver3, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> ScopedBinding.Builder { .init(.root) { try builder($0, $2.0, $2.1, $2.2, $2.3, $2.4) } } diff --git a/Sources/3.0 API/Resolver+Injection.swift b/Sources/3.0 API/Resolver+Injection.swift index 2b8368ed..c0d3f6db 100644 --- a/Sources/3.0 API/Resolver+Injection.swift +++ b/Sources/3.0 API/Resolver+Injection.swift @@ -4,7 +4,7 @@ // TODO: Overloads for multiple arguments & tag / notag combinations -public extension Resolver { +public extension Resolver3 { func instance(of _: Type.Type = Type.self) throws -> Type { try instance(tagged: NoTag(), arg: ()) } @@ -22,7 +22,7 @@ public extension Resolver { } } -public extension Resolver { +public extension Resolver3 { func provider(of _: Type.Type = Type.self) -> () throws -> Type { provider(tagged: NoTag(), arg: ()) } @@ -40,7 +40,7 @@ public extension Resolver { } } -public extension Resolver { +public extension Resolver3 { func factory(of _: Type.Type = Type.self) -> (Argument) throws -> Type { factory(tagged: NoTag()) } diff --git a/Sources/Core/Binding.swift b/Sources/Core/Binding.swift index 247877b1..65080d8e 100644 --- a/Sources/Core/Binding.swift +++ b/Sources/Core/Binding.swift @@ -5,7 +5,7 @@ // sourcery: AutoMockable public protocol Binding: SwinjectEntry { func matches(_ key: AnyBindingKey) -> Bool - func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any + func instance(arg: Any, context: Any, resolver: Resolver3) throws -> Any } public protocol BindingMaker { diff --git a/Sources/Core/ContextedResolver.swift b/Sources/Core/ContextedResolver.swift index bc0eda11..4754197a 100644 --- a/Sources/Core/ContextedResolver.swift +++ b/Sources/Core/ContextedResolver.swift @@ -2,12 +2,12 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -struct ContextedResolver { +struct ContextedResolver3 { let context: Context - let resolver: Resolver + let resolver: Resolver3 } -extension ContextedResolver: Resolver { +extension ContextedResolver3: Resolver3 { func resolve(_ request: InstanceRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { try resolver.resolve( InstanceRequest( diff --git a/Sources/Core/InstanceMaker.swift b/Sources/Core/InstanceMaker.swift index 3851716b..f758c5fe 100644 --- a/Sources/Core/InstanceMaker.swift +++ b/Sources/Core/InstanceMaker.swift @@ -4,7 +4,7 @@ // sourcery: AutoMockable public protocol AnyInstanceMaker { - func makeInstance(arg: Any, context: Any, resolver: Resolver) throws -> Any + func makeInstance(arg: Any, context: Any, resolver: Resolver3) throws -> Any } // FIXME: "Maker" is not a typical concept @@ -13,11 +13,11 @@ public protocol InstanceMaker: AnyInstanceMaker { associatedtype MadeType associatedtype Argument associatedtype Context - func makeInstance(arg: Argument, context: Context, resolver: Resolver) throws -> MadeType + func makeInstance(arg: Argument, context: Context, resolver: Resolver3) throws -> MadeType } public extension InstanceMaker { - func makeInstance(arg: Any, context: Any, resolver: Resolver) throws -> Any { + func makeInstance(arg: Any, context: Any, resolver: Resolver3) throws -> Any { guard let arg = arg as? Argument, let context = context as? Context else { throw SwinjectError() } return try makeInstance(arg: arg, context: context, resolver: resolver) as MadeType } diff --git a/Sources/Core/Resolver.swift b/Sources/Core/Resolver3.swift similarity index 57% rename from Sources/Core/Resolver.swift rename to Sources/Core/Resolver3.swift index 13fda855..5862dcf9 100644 --- a/Sources/Core/Resolver.swift +++ b/Sources/Core/Resolver3.swift @@ -2,12 +2,13 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -public protocol Resolver { +// TODO: Rename +public protocol Resolver3 { func resolve(_ request: InstanceRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor } -public extension Resolver { - func on(_ context: Context) -> Resolver { - ContextedResolver(context: context, resolver: self) +public extension Resolver3 { + func on(_ context: Context) -> Resolver3 { + ContextedResolver3(context: context, resolver: self) } } diff --git a/Sources/Core/ScopedBinding.swift b/Sources/Core/ScopedBinding.swift index 928190a9..b754472f 100644 --- a/Sources/Core/ScopedBinding.swift +++ b/Sources/Core/ScopedBinding.swift @@ -13,7 +13,7 @@ extension ScopedBinding: Binding { self.key.matches(key) } - public func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any { + public func instance(arg: Any, context: Any, resolver: Resolver3) throws -> Any { try scope .registry(for: context) .instance(for: ScopeRegistryKey(descriptor: key.descriptor, argument: arg)) { @@ -25,9 +25,9 @@ extension ScopedBinding: Binding { extension ScopedBinding { public struct Builder where AScope: Scope { let scope: AScope - private let builder: (Resolver, Context, Argument) throws -> Type + private let builder: (Resolver3, Context, Argument) throws -> Type - init(_ scope: AScope, _ builder: @escaping (Resolver, Context, Argument) throws -> Type) { + init(_ scope: AScope, _ builder: @escaping (Resolver3, Context, Argument) throws -> Type) { self.scope = scope self.builder = builder } @@ -38,7 +38,7 @@ extension ScopedBinding.Builder: InstanceMaker { public typealias MadeType = Type public typealias Context = AScope.Context - public func makeInstance(arg: Argument, context: Context, resolver: Resolver) throws -> Type { + public func makeInstance(arg: Argument, context: Context, resolver: Resolver3) throws -> Type { try builder(resolver, context, arg) } } diff --git a/Sources/Core/SimpleBinding.swift b/Sources/Core/SimpleBinding.swift index d673d2f9..5e688ba1 100644 --- a/Sources/Core/SimpleBinding.swift +++ b/Sources/Core/SimpleBinding.swift @@ -12,16 +12,16 @@ extension SimpleBinding: Binding { self.key.matches(key) } - public func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any { + public func instance(arg: Any, context: Any, resolver: Resolver3) throws -> Any { try maker.makeInstance(arg: arg, context: context, resolver: resolver) } } extension SimpleBinding { public struct Builder { - private let builder: (Resolver, Context, Argument) throws -> Type + private let builder: (Resolver3, Context, Argument) throws -> Type - init(_ builder: @escaping (Resolver, Context, Argument) throws -> Type) { + init(_ builder: @escaping (Resolver3, Context, Argument) throws -> Type) { self.builder = builder } } @@ -30,7 +30,7 @@ extension SimpleBinding { extension SimpleBinding.Builder: InstanceMaker { public typealias MadeType = Type - public func makeInstance(arg: Argument, context: Context, resolver: Resolver) throws -> Type { + public func makeInstance(arg: Argument, context: Context, resolver: Resolver3) throws -> Type { try builder(resolver, context, arg) } } diff --git a/Sources/Core/Swinject.swift b/Sources/Core/Swinject.swift index d5f41a0b..2b7db023 100644 --- a/Sources/Core/Swinject.swift +++ b/Sources/Core/Swinject.swift @@ -10,7 +10,7 @@ public struct Swinject { } } -extension Swinject: Resolver { +extension Swinject: Resolver3 { public func resolve(_ request: InstanceRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { try instance(from: findBinding(for: request.key), context: request.context, arg: request.argument) } diff --git a/Sources/Core/TypeDescriptor.swift b/Sources/Core/TypeDescriptor.swift index 7bc118ea..aecba973 100644 --- a/Sources/Core/TypeDescriptor.swift +++ b/Sources/Core/TypeDescriptor.swift @@ -49,6 +49,4 @@ protocol OptionalProtocol { static var wrappedType: Any.Type { get } } -extension Optional: OptionalProtocol { - static var wrappedType: Any.Type { Wrapped.self } -} +extension Optional: OptionalProtocol {} diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 7d71b044..3f18fba5 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -56,7 +56,7 @@ 1A03A1D9524E8912AF1CEE11 /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = EA7A547FC60DBD02D132B3E6 /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 1ACC90951353E5F69899A833 /* SimpleBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */; }; 1AD4C43B074F736BBDADA8C9 /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; - 1B29712FD3C5FB3B372EE35F /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */; }; + 1B29712FD3C5FB3B372EE35F /* Resolver3.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver3.swift */; }; 1BBE296A616C1761DD76935C /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 443508AA18D686A564F59882 /* .swiftlint.yml */; }; 1C2F5A09F986586F85FAC3E8 /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; 1C8B304AAB75579AE100EDDF /* ServiceEntry.TypeForwarding.erb in Resources */ = {isa = PBXBuildFile; fileRef = E6B3186E0AE372A6663F41E9 /* ServiceEntry.TypeForwarding.erb */; }; @@ -227,7 +227,7 @@ 89613FDC2024EE34FD246A16 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ADC44E9312C3B974AFD8F07B /* Nimble.framework */; }; 89D83D5E42814659DFE8F518 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; 89F0AA65C3C9837A0A2452DF /* Quick.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = C765B92B00C0AC8625BB4AC9 /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 8A212C0486A514CF17B5F140 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */; }; + 8A212C0486A514CF17B5F140 /* Resolver3.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver3.swift */; }; 8AAC0C68038E02A6049ABDC0 /* StandardScopeRegistrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */; }; 8AEB5894656086C3E2F022FD /* SimpleBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */; }; 8D58DF5C6963153A8B17D325 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; @@ -350,7 +350,7 @@ D8E2986FB186B630E54B60CD /* GraphIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E95633441FFB44D8A05585C /* GraphIdentifier.swift */; }; D98CA679A3AAC176D291CA8E /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEE8FDF4B975A8F2A9FCC5FF /* Food.swift */; }; DA6CB0A98FE5968CAAFDE9BF /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9985BEF966DCBB28B12BE17B /* Person.swift */; }; - DAFA9AE69744F3C5DC71CF50 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */; }; + DAFA9AE69744F3C5DC71CF50 /* Resolver3.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver3.swift */; }; DB14CA46130A816F6FAADE92 /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C074BAC560F277E806146C60 /* SimpleBinding.swift */; }; DC5C3A946BDA224C388D2438 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 359BCD3DA6F0CC2241878C82 /* EmploymentAssembly.swift */; }; DD1B936DC7365917DCA09FC8 /* Quick.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 823617F3B8A9192F56B13331 /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -364,7 +364,7 @@ E423395FC7006DD82513F347 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; E484C3994AD91E91C454B11D /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; E584841CFD26155FB056C85A /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; - E62C6509D0B52001CC309068 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */; }; + E62C6509D0B52001CC309068 /* Resolver3.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver3.swift */; }; E63F31788438E1A43D480E84 /* Resolver.erb in Resources */ = {isa = PBXBuildFile; fileRef = B7DE2D7907C552B2C165E920 /* Resolver.erb */; }; E6E536A44F40492F42CA4044 /* ContainerSpec.DebugHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF340AF8DD2D821A225A36B3 /* ContainerSpec.DebugHelper.swift */; }; E7383E65C483ED1E66A49C5C /* InstanceStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06A8ED72CD6241A2CDEA8479 /* InstanceStorage.swift */; }; @@ -509,7 +509,7 @@ 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Behavior.swift; sourceTree = ""; }; 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Arguments.swift; sourceTree = ""; }; 2234FFBE7F556D1372AFB42D /* ServiceEntrySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServiceEntrySpec.swift; sourceTree = ""; }; - 24C19DEC1E7BDED41182B68C /* Container.Arguments.erb */ = {isa = PBXFileReference; path = Container.Arguments.erb; sourceTree = ""; }; + 24C19DEC1E7BDED41182B68C /* Container.Arguments.erb */ = {isa = PBXFileReference; lastKnownFileType = text; path = Container.Arguments.erb; sourceTree = ""; }; 273FB7A6277E0841E1570990 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; 2902FD4C1A50263340A51FFB /* ScopeRegistryKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistryKeySpec.swift; sourceTree = ""; }; 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; @@ -526,7 +526,7 @@ 4040F8D091ED67C84E2B8854 /* SynchronizedResolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SynchronizedResolver.swift; sourceTree = ""; }; 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingKeySpec.swift; sourceTree = ""; }; 42490D1D0C395951243F5CFF /* Container.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.swift; sourceTree = ""; }; - 443508AA18D686A564F59882 /* .swiftlint.yml */ = {isa = PBXFileReference; path = .swiftlint.yml; sourceTree = ""; }; + 443508AA18D686A564F59882 /* .swiftlint.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .swiftlint.yml; sourceTree = ""; }; 45CA41659767E1378A9F492B /* ServiceKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServiceKeySpec.swift; sourceTree = ""; }; 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTree.swift; sourceTree = ""; }; 494AA2AA587975747596C157 /* ProviderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProviderSpec.swift; sourceTree = ""; }; @@ -548,7 +548,7 @@ 6EA4ECB5E4CEC9751AD36854 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 715A7D1ADE43B7CB0EF80004 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 722CAC1761180366DE75A4A6 /* TestModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestModels.swift; sourceTree = ""; }; - 7395512173A1439ED411B188 /* SynchronizedResolver.Arguments.erb */ = {isa = PBXFileReference; path = SynchronizedResolver.Arguments.erb; sourceTree = ""; }; + 7395512173A1439ED411B188 /* SynchronizedResolver.Arguments.erb */ = {isa = PBXFileReference; lastKnownFileType = text; path = SynchronizedResolver.Arguments.erb; sourceTree = ""; }; 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.CustomStringConvertible.swift; sourceTree = ""; }; 74DE57FB3E8228904E6FE0D7 /* Swinject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Swinject.h; sourceTree = ""; }; 7BA261FF01C5F5510873B3EC /* Animal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Animal.swift; sourceTree = ""; }; @@ -568,12 +568,12 @@ A10187BB3A994165E7FC1528 /* ScopedBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopedBinding.swift; sourceTree = ""; }; A24B4E8F1CA18603DBB6884A /* BindingKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingKey.swift; sourceTree = ""; }; A3586A4987B7C7C8122D674E /* SwinjectError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectError.swift; sourceTree = ""; }; - A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Resolver.swift; sourceTree = ""; }; + A5583CF2602DDFB5E8A7D2DE /* Resolver3.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Resolver3.swift; sourceTree = ""; }; ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Circularity.swift; sourceTree = ""; }; ADC44E9312C3B974AFD8F07B /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; ADD71387EBA54D7EF60D0089 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AssemblerSpec.swift; sourceTree = ""; }; - B7DE2D7907C552B2C165E920 /* Resolver.erb */ = {isa = PBXFileReference; path = Resolver.erb; sourceTree = ""; }; + B7DE2D7907C552B2C165E920 /* Resolver.erb */ = {isa = PBXFileReference; lastKnownFileType = text; path = Resolver.erb; sourceTree = ""; }; B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderEnvironment.swift; sourceTree = ""; }; B92B8E618A08408404FB2A7A /* TypeBinder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinder.swift; sourceTree = ""; }; BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StandardScopeRegistrySpec.swift; sourceTree = ""; }; @@ -592,7 +592,7 @@ DF340AF8DD2D821A225A36B3 /* ContainerSpec.DebugHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.DebugHelper.swift; sourceTree = ""; }; E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRequest.swift; sourceTree = ""; }; E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; - E6B3186E0AE372A6663F41E9 /* ServiceEntry.TypeForwarding.erb */ = {isa = PBXFileReference; path = ServiceEntry.TypeForwarding.erb; sourceTree = ""; }; + E6B3186E0AE372A6663F41E9 /* ServiceEntry.TypeForwarding.erb */ = {isa = PBXFileReference; lastKnownFileType = text; path = ServiceEntry.TypeForwarding.erb; sourceTree = ""; }; EA7A547FC60DBD02D132B3E6 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; EBA3EF319F06A1B3B6C84C29 /* ContextedResolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextedResolver.swift; sourceTree = ""; }; ECE2B2EFBFDA910758EE1CA5 /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -884,7 +884,7 @@ CADDB3E9E363310028AA5920 /* InstanceMaker.swift */, E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */, 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */, - A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */, + A5583CF2602DDFB5E8A7D2DE /* Resolver3.swift */, 5057BAB33984E3E33469452B /* Scope.swift */, A10187BB3A994165E7FC1528 /* ScopedBinding.swift */, 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */, @@ -1297,7 +1297,7 @@ 3E13E204659AF2DCE94D75CB /* ObjectScope.Standard.swift in Sources */, 79772C34E5102A8E3003DBF8 /* ObjectScope.swift in Sources */, 5C4C106D138E771C872F5E80 /* Resolver+Injection.swift in Sources */, - DAFA9AE69744F3C5DC71CF50 /* Resolver.swift in Sources */, + DAFA9AE69744F3C5DC71CF50 /* Resolver3.swift in Sources */, E7E9DE84E1861D125F8D686A /* Resolver.swift in Sources */, 71C4A75D54446D844BA5FB85 /* Scope.swift in Sources */, 1AD4C43B074F736BBDADA8C9 /* ScopeRegistry.swift in Sources */, @@ -1447,7 +1447,7 @@ A2745DCB0ACE7714C65CA2A9 /* ObjectScope.Standard.swift in Sources */, 401A790CF8450924114D89ED /* ObjectScope.swift in Sources */, 741344C30785507B22DF703B /* Resolver+Injection.swift in Sources */, - E62C6509D0B52001CC309068 /* Resolver.swift in Sources */, + E62C6509D0B52001CC309068 /* Resolver3.swift in Sources */, FDCF96E2A442CDC6815B8127 /* Resolver.swift in Sources */, 1718A1577AB543174FD8E644 /* Scope.swift in Sources */, 1F4FBB9D795CE9D45E5A8BEE /* ScopeRegistry.swift in Sources */, @@ -1597,7 +1597,7 @@ 61FA449BF10682C9E89E767F /* ObjectScope.Standard.swift in Sources */, D688F61360D46A16B0678BA4 /* ObjectScope.swift in Sources */, 1C2F5A09F986586F85FAC3E8 /* Resolver+Injection.swift in Sources */, - 1B29712FD3C5FB3B372EE35F /* Resolver.swift in Sources */, + 1B29712FD3C5FB3B372EE35F /* Resolver3.swift in Sources */, 8108969F33C37040624E0D02 /* Resolver.swift in Sources */, D557A108A21751DF75542692 /* Scope.swift in Sources */, D7DE20CC15F3A6BD09E43A75 /* ScopeRegistry.swift in Sources */, @@ -1649,7 +1649,7 @@ 1F2E1C6B8F28C5441D52C033 /* ObjectScope.Standard.swift in Sources */, 3AC304A612ECAED02C58BBF5 /* ObjectScope.swift in Sources */, 90B4143005C86717AC76B6EE /* Resolver+Injection.swift in Sources */, - 8A212C0486A514CF17B5F140 /* Resolver.swift in Sources */, + 8A212C0486A514CF17B5F140 /* Resolver3.swift in Sources */, 66033468A5FC65C19B60086A /* Resolver.swift in Sources */, B2FCC51BB61148422256A14A /* Scope.swift in Sources */, 46A14FAA5AA73BE8A0397707 /* ScopeRegistry.swift in Sources */, @@ -1768,7 +1768,11 @@ ); INFOPLIST_FILE = "Tests/2.0 API/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SwinjectTests; SDKROOT = watchos; @@ -1792,7 +1796,10 @@ INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = Swinject; SDKROOT = macosx; @@ -1815,7 +1822,10 @@ INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = Swinject; SDKROOT = iphoneos; @@ -1862,7 +1872,10 @@ INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = Swinject; SDKROOT = appletvos; @@ -1884,7 +1897,11 @@ ); INFOPLIST_FILE = "Tests/2.0 API/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SwinjectTests; SDKROOT = appletvos; @@ -1954,7 +1971,11 @@ ); INFOPLIST_FILE = "Tests/2.0 API/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SwinjectTests; SDKROOT = iphoneos; @@ -1976,7 +1997,10 @@ INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = Swinject; SDKROOT = appletvos; @@ -2024,7 +2048,10 @@ INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = Swinject; SDKROOT = macosx; @@ -2047,7 +2074,10 @@ INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = Swinject; SDKROOT = iphoneos; @@ -2070,7 +2100,11 @@ ); INFOPLIST_FILE = "Tests/2.0 API/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SwinjectTests; SDKROOT = macosx; @@ -2089,7 +2123,11 @@ ); INFOPLIST_FILE = "Tests/2.0 API/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SwinjectTests; SDKROOT = appletvos; @@ -2110,7 +2148,11 @@ ); INFOPLIST_FILE = "Tests/2.0 API/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SwinjectTests; SDKROOT = macosx; @@ -2129,7 +2171,11 @@ ); INFOPLIST_FILE = "Tests/2.0 API/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SwinjectTests; SDKROOT = watchos; @@ -2150,7 +2196,11 @@ ); INFOPLIST_FILE = "Tests/2.0 API/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SwinjectTests; SDKROOT = iphoneos; diff --git a/Tests/Support/Convenience.swift b/Tests/Support/Convenience.swift index 783b0887..c2fce17b 100644 --- a/Tests/Support/Convenience.swift +++ b/Tests/Support/Convenience.swift @@ -6,19 +6,19 @@ import Nimble @testable import Swinject extension InstanceMaker where Argument == Void, Context == Any { - func makeInstance(resolver: Resolver) throws -> MadeType { + func makeInstance(resolver: Resolver3) throws -> MadeType { try makeInstance(arg: (), context: (), resolver: resolver) } } extension InstanceMaker where Argument == Void { - func makeInstance(context: Context, resolver: Resolver) throws -> MadeType { + func makeInstance(context: Context, resolver: Resolver3) throws -> MadeType { try makeInstance(arg: (), context: context, resolver: resolver) } } extension InstanceMaker where Context == Any { - func makeInstance(arg: Argument, resolver: Resolver) throws -> MadeType { + func makeInstance(arg: Argument, resolver: Resolver3) throws -> MadeType { try makeInstance(arg: arg, context: (), resolver: resolver) } } diff --git a/Tests/Support/GeneratedMocks.swift b/Tests/Support/GeneratedMocks.swift index b4e8b469..d71b0383 100644 --- a/Tests/Support/GeneratedMocks.swift +++ b/Tests/Support/GeneratedMocks.swift @@ -71,29 +71,29 @@ class AnyBindningMakerMock: AnyBindningMaker { class AnyInstanceMakerMock: AnyInstanceMaker { // MARK: - makeInstance - var makeInstanceArgContextResolverThrowableError: Error? - var makeInstanceArgContextResolverCallsCount = 0 - var makeInstanceArgContextResolverCalled: Bool { - return makeInstanceArgContextResolverCallsCount > 0 + var makeInstanceArgContextResolver3ThrowableError: Error? + var makeInstanceArgContextResolver3CallsCount = 0 + var makeInstanceArgContextResolver3Called: Bool { + return makeInstanceArgContextResolver3CallsCount > 0 } - var makeInstanceArgContextResolverReceivedArguments: (arg: Any, context: Any, resolver: Resolver)? - var makeInstanceArgContextResolverReceivedInvocations: [(arg: Any, context: Any, resolver: Resolver)] = [] - var makeInstanceArgContextResolverReturnValue: Any! - var makeInstanceArgContextResolverClosure: ((Any, Any, Resolver) throws -> Any)? + var makeInstanceArgContextResolver3ReceivedArguments: (arg: Any, context: Any, resolver: Resolver3)? + var makeInstanceArgContextResolver3ReceivedInvocations: [(arg: Any, context: Any, resolver: Resolver3)] = [] + var makeInstanceArgContextResolver3ReturnValue: Any! + var makeInstanceArgContextResolver3Closure: ((Any, Any, Resolver3) throws -> Any)? - func makeInstance(arg: Any, context: Any, resolver: Resolver) throws -> Any { - if let error = makeInstanceArgContextResolverThrowableError { + func makeInstance(arg: Any, context: Any, resolver: Resolver3) throws -> Any { + if let error = makeInstanceArgContextResolver3ThrowableError { throw error } - makeInstanceArgContextResolverCallsCount += 1 - makeInstanceArgContextResolverReceivedArguments = (arg: arg, context: context, resolver: resolver) - makeInstanceArgContextResolverReceivedInvocations.append((arg: arg, context: context, resolver: resolver)) - return try makeInstanceArgContextResolverClosure.map { try $0(arg, context, resolver) } ?? makeInstanceArgContextResolverReturnValue + makeInstanceArgContextResolver3CallsCount += 1 + makeInstanceArgContextResolver3ReceivedArguments = (arg: arg, context: context, resolver: resolver) + makeInstanceArgContextResolver3ReceivedInvocations.append((arg: arg, context: context, resolver: resolver)) + return try makeInstanceArgContextResolver3Closure.map { try $0(arg, context, resolver) } ?? makeInstanceArgContextResolver3ReturnValue } } -class AnyResolverMock: AnyResolver { +class AnyResolver3Mock: AnyResolver3 { // MARK: - resolve var resolveThrowableError: Error? @@ -189,25 +189,25 @@ class BindingMock: Binding { // MARK: - instance - var instanceArgContextResolverThrowableError: Error? - var instanceArgContextResolverCallsCount = 0 - var instanceArgContextResolverCalled: Bool { - return instanceArgContextResolverCallsCount > 0 + var instanceArgContextResolver3ThrowableError: Error? + var instanceArgContextResolver3CallsCount = 0 + var instanceArgContextResolver3Called: Bool { + return instanceArgContextResolver3CallsCount > 0 } - var instanceArgContextResolverReceivedArguments: (arg: Any, context: Any, resolver: Resolver)? - var instanceArgContextResolverReceivedInvocations: [(arg: Any, context: Any, resolver: Resolver)] = [] - var instanceArgContextResolverReturnValue: Any! - var instanceArgContextResolverClosure: ((Any, Any, Resolver) throws -> Any)? + var instanceArgContextResolver3ReceivedArguments: (arg: Any, context: Any, resolver: Resolver3)? + var instanceArgContextResolver3ReceivedInvocations: [(arg: Any, context: Any, resolver: Resolver3)] = [] + var instanceArgContextResolver3ReturnValue: Any! + var instanceArgContextResolver3Closure: ((Any, Any, Resolver3) throws -> Any)? - func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any { - if let error = instanceArgContextResolverThrowableError { + func instance(arg: Any, context: Any, resolver: Resolver3) throws -> Any { + if let error = instanceArgContextResolver3ThrowableError { throw error } - instanceArgContextResolverCallsCount += 1 - instanceArgContextResolverReceivedArguments = (arg: arg, context: context, resolver: resolver) - instanceArgContextResolverReceivedInvocations.append((arg: arg, context: context, resolver: resolver)) - return try instanceArgContextResolverClosure.map { try $0(arg, context, resolver) } ?? instanceArgContextResolverReturnValue + instanceArgContextResolver3CallsCount += 1 + instanceArgContextResolver3ReceivedArguments = (arg: arg, context: context, resolver: resolver) + instanceArgContextResolver3ReceivedInvocations.append((arg: arg, context: context, resolver: resolver)) + return try instanceArgContextResolver3Closure.map { try $0(arg, context, resolver) } ?? instanceArgContextResolver3ReturnValue } } diff --git a/Tests/Support/NonGeneratedMocks.swift b/Tests/Support/NonGeneratedMocks.swift index 95916080..5efbe08e 100644 --- a/Tests/Support/NonGeneratedMocks.swift +++ b/Tests/Support/NonGeneratedMocks.swift @@ -4,7 +4,7 @@ @testable import Swinject -class DummyResolver: Resolver { +class DummyResolver3: Resolver3 { func resolve(_: InstanceRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { fatalError() } @@ -19,17 +19,17 @@ extension AnyInstanceMakerMock: InstanceMaker { } class DummyMaker: InstanceMaker { - func makeInstance(arg _: Argument, context: Context, resolver _: Resolver) throws -> Any { + func makeInstance(arg _: Argument, context: Context, resolver _: Resolver3) throws -> Any { fatalError() } } // sourcery: AutoMockable -protocol AnyResolver { +protocol AnyResolver3 { func resolve(_ request: Any) throws -> Any } -extension AnyResolverMock: Resolver { +extension AnyResolver3Mock: Resolver3 { func resolve(_ request: InstanceRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { try resolve(request as Any) as! Descriptor.BaseType } diff --git a/Tests/Unit Specs/BinderEnvironmentSpec.swift b/Tests/Unit Specs/BinderEnvironmentSpec.swift index 188496ad..0cc1d6fb 100644 --- a/Tests/Unit Specs/BinderEnvironmentSpec.swift +++ b/Tests/Unit Specs/BinderEnvironmentSpec.swift @@ -16,7 +16,7 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { } it("returns given instance") { let maker = instance(42) - expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 + expect { try maker.makeInstance(resolver: DummyResolver3()) } == 42 } } describe("provider") { @@ -26,7 +26,7 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { } it("returns instance made by provider method") { let maker = provider { 42 } - expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 + expect { try maker.makeInstance(resolver: DummyResolver3()) } == 42 } it("does not call builder until instance is requested") { var called = false @@ -34,20 +34,20 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { expect(called).to(beFalse()) } it("calls builder with given resolver") { - var passedResolver: Resolver? - let resolver = DummyResolver() - let maker = provider { passedResolver = $0 } + var passedResolver3: Resolver3? + let resolver = DummyResolver3() + let maker = provider { passedResolver3 = $0 } _ = try? maker.makeInstance(resolver: resolver) - expect(passedResolver) === resolver + expect(passedResolver3) === resolver } it("rethrows error from builder") { let maker = provider { throw SwinjectError() } - expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) + expect { try maker.makeInstance(resolver: DummyResolver3()) }.to(throwError()) } it("does not reuse instance") { let maker = provider { Person() } - let instance1 = try? maker.makeInstance(resolver: DummyResolver()) - let instance2 = try? maker.makeInstance(resolver: DummyResolver()) + let instance1 = try? maker.makeInstance(resolver: DummyResolver3()) + let instance2 = try? maker.makeInstance(resolver: DummyResolver3()) expect(instance1) !== instance2 } } @@ -58,7 +58,7 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { } it("returns instance made by builder method") { let maker = factory { (_, _: Void) in 42 } - expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 + expect { try maker.makeInstance(resolver: DummyResolver3()) } == 42 } it("does not call builder until instance is requested") { var called = false @@ -66,48 +66,48 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { expect(called).to(beFalse()) } it("calls builder with given resolver") { - var passedResolver: Resolver? - let resolver = DummyResolver() - let maker = factory { (r, _: Void) in passedResolver = r } + var passedResolver3: Resolver3? + let resolver = DummyResolver3() + let maker = factory { (r, _: Void) in passedResolver3 = r } _ = try? maker.makeInstance(resolver: resolver) - expect(passedResolver) === resolver + expect(passedResolver3) === resolver } it("calls builder with given argument") { var passedArgument: Int? let maker = factory { (_, arg: Int) in passedArgument = arg } - _ = try? maker.makeInstance(arg: 42, resolver: DummyResolver()) + _ = try? maker.makeInstance(arg: 42, resolver: DummyResolver3()) expect(passedArgument) == 42 } it("rethrows error from builder") { let maker = factory { (_, _: Void) in throw SwinjectError() } - expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) + expect { try maker.makeInstance(resolver: DummyResolver3()) }.to(throwError()) } it("does not reuse instance") { let maker = factory { (_, _: Void) in Person() } - let instance1 = try? maker.makeInstance(resolver: DummyResolver()) - let instance2 = try? maker.makeInstance(resolver: DummyResolver()) + let instance1 = try? maker.makeInstance(resolver: DummyResolver3()) + let instance2 = try? maker.makeInstance(resolver: DummyResolver3()) expect(instance1) !== instance2 } describe("multiple arguments") { it("works with 2 arguments") { let maker = factory { (_, _: Int, _: Double) in 42 } let arguments = (1, 1.0) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver3()) } == 42 } it("works with 3 arguments") { let maker = factory { (_, _: Int, _: Double, _: String) in 42 } let arguments = (1, 1.0, "") - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver3()) } == 42 } it("works with 4 arguments") { let maker = factory { (_, _: Int, _: Double, _: String, _: Float) in 42 } let arguments = (1, 1.0, "", Float(1.0)) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver3()) } == 42 } it("works with 5 arguments") { let maker = factory { (_, _: Int, _: Double, _: String, _: Float, _: Int) in 42 } let arguments = (1, 1.0, "", Float(1.0), 5) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver3()) } == 42 } } } @@ -118,7 +118,7 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { } it("returns instance made by builder") { let maker = singleton { 42 } - expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 + expect { try maker.makeInstance(resolver: DummyResolver3()) } == 42 } it("does not call builder until instance is requested") { var called = false @@ -126,20 +126,20 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { expect(called).to(beFalse()) } it("calls builder with given resolver") { - var passedResolver: Resolver? - let resolver = DummyResolver() - let maker = singleton { passedResolver = $0 } + var passedResolver3: Resolver3? + let resolver = DummyResolver3() + let maker = singleton { passedResolver3 = $0 } _ = try? maker.makeInstance(resolver: resolver) - expect(passedResolver) === resolver + expect(passedResolver3) === resolver } it("rethrows error from builder") { let maker = singleton { throw SwinjectError() } - expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) + expect { try maker.makeInstance(resolver: DummyResolver3()) }.to(throwError()) } it("does not reuse instance") { let maker = singleton { Person() } - let instance1 = try? maker.makeInstance(resolver: DummyResolver()) - let instance2 = try? maker.makeInstance(resolver: DummyResolver()) + let instance1 = try? maker.makeInstance(resolver: DummyResolver3()) + let instance2 = try? maker.makeInstance(resolver: DummyResolver3()) expect(instance1) !== instance2 } } @@ -150,7 +150,7 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { } it("returns instance made by builder method") { let maker = multiton { (_, _: Void) in 42 } - expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 + expect { try maker.makeInstance(resolver: DummyResolver3()) } == 42 } it("does not call builder until instance is requested") { var called = false @@ -158,48 +158,48 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { expect(called).to(beFalse()) } it("calls builder with given resolver") { - var passedResolver: Resolver? - let resolver = DummyResolver() - let maker = multiton { (r, _: Void) in passedResolver = r } + var passedResolver3: Resolver3? + let resolver = DummyResolver3() + let maker = multiton { (r, _: Void) in passedResolver3 = r } _ = try? maker.makeInstance(resolver: resolver) - expect(passedResolver) === resolver + expect(passedResolver3) === resolver } it("calls builder with given argument") { var passedArgument: Int? let maker = multiton { (_, arg: Int) in passedArgument = arg } - _ = try? maker.makeInstance(arg: 42, resolver: DummyResolver()) + _ = try? maker.makeInstance(arg: 42, resolver: DummyResolver3()) expect(passedArgument) == 42 } it("rethrows error from builder") { let maker = multiton { (_, _: Void) in throw SwinjectError() } - expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) + expect { try maker.makeInstance(resolver: DummyResolver3()) }.to(throwError()) } it("does not reuse instance") { let maker = multiton { (_, _: Void) in Person() } - let instance1 = try? maker.makeInstance(resolver: DummyResolver()) - let instance2 = try? maker.makeInstance(resolver: DummyResolver()) + let instance1 = try? maker.makeInstance(resolver: DummyResolver3()) + let instance2 = try? maker.makeInstance(resolver: DummyResolver3()) expect(instance1) !== instance2 } describe("multiple arguments") { it("works with 2 arguments") { let maker = multiton { (_, _: Int, _: Double) in 42 } let arguments = (1, 1.0) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver3()) } == 42 } it("works with 3 arguments") { let maker = multiton { (_, _: Int, _: Double, _: String) in 42 } let arguments = (1, 1.0, "") - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver3()) } == 42 } it("works with 4 arguments") { let maker = multiton { (_, _: Int, _: Double, _: String, _: Float) in 42 } let arguments = (1, 1.0, "", Float(1.0)) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver3()) } == 42 } it("works with 5 arguments") { let maker = multiton { (_, _: Int, _: Double, _: String, _: Float, _: Int) in 42 } let arguments = (1, 1.0, "", Float(1.0), 5) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver3()) } == 42 } } } @@ -212,7 +212,7 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { describe("provider") { it("returns instance made by provider method") { let maker = environment.provider { _, _ in 42 } - expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 + expect { try maker.makeInstance(resolver: DummyResolver3()) } == 42 } it("does not call builder until instance is requested") { var called = false @@ -220,33 +220,33 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { expect(called).to(beFalse()) } it("calls builder with given resolver") { - var passedResolver: Resolver? - let resolver = DummyResolver() - let maker = environment.provider { r, _ in passedResolver = r } + var passedResolver3: Resolver3? + let resolver = DummyResolver3() + let maker = environment.provider { r, _ in passedResolver3 = r } _ = try? maker.makeInstance(resolver: resolver) - expect(passedResolver) === resolver + expect(passedResolver3) === resolver } it("calls builder with given context") { var passedContext: Any? let maker = environment.provider { _, c in passedContext = c } - _ = try? maker.makeInstance(context: 42, resolver: DummyResolver()) + _ = try? maker.makeInstance(context: 42, resolver: DummyResolver3()) expect(passedContext as? Int) == 42 } it("rethrows error from builder") { let maker = environment.provider { _, _ in throw SwinjectError() } - expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) + expect { try maker.makeInstance(resolver: DummyResolver3()) }.to(throwError()) } it("does not reuse instance") { let maker = environment.provider { _, _ in Person() } - let instance1 = try? maker.makeInstance(resolver: DummyResolver()) - let instance2 = try? maker.makeInstance(resolver: DummyResolver()) + let instance1 = try? maker.makeInstance(resolver: DummyResolver3()) + let instance2 = try? maker.makeInstance(resolver: DummyResolver3()) expect(instance1) !== instance2 } } describe("factory") { it("returns instance made by builder method") { let maker = environment.factory { (_, _, _: Void) in 42 } - expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 + expect { try maker.makeInstance(resolver: DummyResolver3()) } == 42 } it("does not call builder until instance is requested") { var called = false @@ -254,54 +254,54 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { expect(called).to(beFalse()) } it("calls builder with given resolver") { - var passedResolver: Resolver? - let resolver = DummyResolver() - let maker = environment.factory { (r, _, _: Void) in passedResolver = r } + var passedResolver3: Resolver3? + let resolver = DummyResolver3() + let maker = environment.factory { (r, _, _: Void) in passedResolver3 = r } _ = try? maker.makeInstance(resolver: resolver) - expect(passedResolver) === resolver + expect(passedResolver3) === resolver } it("calls builder with given context") { var passedContext: Any? let maker = environment.factory { (_, c, _: Void) in passedContext = c } - _ = try? maker.makeInstance(context: 42, resolver: DummyResolver()) + _ = try? maker.makeInstance(context: 42, resolver: DummyResolver3()) expect(passedContext as? Int) == 42 } it("calls builder with given argument") { var passedArgument: Int? let maker = environment.factory { (_, _, arg: Int) in passedArgument = arg } - _ = try? maker.makeInstance(arg: 42, resolver: DummyResolver()) + _ = try? maker.makeInstance(arg: 42, resolver: DummyResolver3()) expect(passedArgument) == 42 } it("rethrows error from builder") { let maker = environment.factory { (_, _, _: Void) in throw SwinjectError() } - expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) + expect { try maker.makeInstance(resolver: DummyResolver3()) }.to(throwError()) } it("does not reuse instance") { let maker = environment.factory { (_, _, _: Void) in Person() } - let instance1 = try? maker.makeInstance(resolver: DummyResolver()) - let instance2 = try? maker.makeInstance(resolver: DummyResolver()) + let instance1 = try? maker.makeInstance(resolver: DummyResolver3()) + let instance2 = try? maker.makeInstance(resolver: DummyResolver3()) expect(instance1) !== instance2 } describe("multiple arguments") { it("works with 2 arguments") { let maker = environment.factory { (_, _, _: Int, _: Double) in 42 } let arguments = (1, 1.0) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver3()) } == 42 } it("works with 3 arguments") { let maker = environment.factory { (_, _, _: Int, _: Double, _: String) in 42 } let arguments = (1, 1.0, "") - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver3()) } == 42 } it("works with 4 arguments") { let maker = environment.factory { (_, _, _: Int, _: Double, _: String, _: Float) in 42 } let arguments = (1, 1.0, "", Float(1.0)) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver3()) } == 42 } it("works with 5 arguments") { let maker = environment.factory { (_, _, _: Int, _: Double, _: String, _: Float, _: Int) in 42 } let arguments = (1, 1.0, "", Float(1.0), 5) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver3()) } == 42 } } } @@ -320,7 +320,7 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { } it("returns instance made by builder") { let maker = environment.singleton { 42 } - expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 + expect { try maker.makeInstance(resolver: DummyResolver3()) } == 42 } it("does not call builder until instance is requested") { var called = false @@ -328,26 +328,26 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { expect(called).to(beFalse()) } it("calls builder with given resolver") { - var passedResolver: Resolver? - let resolver = DummyResolver() - let maker = environment.singleton { passedResolver = $0 } + var passedResolver3: Resolver3? + let resolver = DummyResolver3() + let maker = environment.singleton { passedResolver3 = $0 } _ = try? maker.makeInstance(resolver: resolver) - expect(passedResolver) === resolver + expect(passedResolver3) === resolver } it("calls builder with given context") { var passedContext: Any? let maker = environment.singleton { _, c in passedContext = c } - _ = try? maker.makeInstance(context: "context", resolver: DummyResolver()) + _ = try? maker.makeInstance(context: "context", resolver: DummyResolver3()) expect(passedContext as? String) == "context" } it("rethrows error from builder") { let maker = environment.singleton { throw SwinjectError() } - expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) + expect { try maker.makeInstance(resolver: DummyResolver3()) }.to(throwError()) } it("does not reuse instance") { let maker = environment.singleton { _, _ in Person() } - let instance1 = try? maker.makeInstance(resolver: DummyResolver()) - let instance2 = try? maker.makeInstance(resolver: DummyResolver()) + let instance1 = try? maker.makeInstance(resolver: DummyResolver3()) + let instance2 = try? maker.makeInstance(resolver: DummyResolver3()) expect(instance1) !== instance2 } } @@ -358,7 +358,7 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { } it("returns instance made by builder method") { let maker = environment.multiton { (_, _, _: Void) in 42 } - expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 + expect { try maker.makeInstance(resolver: DummyResolver3()) } == 42 } it("does not call builder until instance is requested") { var called = false @@ -366,54 +366,54 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { expect(called).to(beFalse()) } it("calls builder with given resolver") { - var passedResolver: Resolver? - let resolver = DummyResolver() - let maker = environment.multiton { (r, _, _: Void) in passedResolver = r } + var passedResolver3: Resolver3? + let resolver = DummyResolver3() + let maker = environment.multiton { (r, _, _: Void) in passedResolver3 = r } _ = try? maker.makeInstance(resolver: resolver) - expect(passedResolver) === resolver + expect(passedResolver3) === resolver } it("calls builder with given context") { var passedContext: Any? let maker = environment.multiton { (_, c, _: Void) in passedContext = c } - _ = try? maker.makeInstance(context: "context", resolver: DummyResolver()) + _ = try? maker.makeInstance(context: "context", resolver: DummyResolver3()) expect(passedContext as? String) == "context" } it("calls builder with given argument") { var passedArgument: Int? let maker = environment.multiton { (_, _, arg: Int) in passedArgument = arg } - _ = try? maker.makeInstance(arg: 42, resolver: DummyResolver()) + _ = try? maker.makeInstance(arg: 42, resolver: DummyResolver3()) expect(passedArgument) == 42 } it("rethrows error from builder") { let maker = environment.multiton { (_, _, _: Void) in throw SwinjectError() } - expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) + expect { try maker.makeInstance(resolver: DummyResolver3()) }.to(throwError()) } it("does not reuse instance") { let maker = environment.multiton { (_, _, _: Void) in Person() } - let instance1 = try? maker.makeInstance(resolver: DummyResolver()) - let instance2 = try? maker.makeInstance(resolver: DummyResolver()) + let instance1 = try? maker.makeInstance(resolver: DummyResolver3()) + let instance2 = try? maker.makeInstance(resolver: DummyResolver3()) expect(instance1) !== instance2 } describe("multiple arguments") { it("works with 2 arguments") { let maker = environment.multiton { (_, _, _: Int, _: Double) in 42 } let arguments = (1, 1.0) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver3()) } == 42 } it("works with 3 arguments") { let maker = environment.multiton { (_, _, _: Int, _: Double, _: String) in 42 } let arguments = (1, 1.0, "") - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver3()) } == 42 } it("works with 4 arguments") { let maker = environment.multiton { (_, _, _: Int, _: Double, _: String, _: Float) in 42 } let arguments = (1, 1.0, "", Float(1.0)) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver3()) } == 42 } it("works with 5 arguments") { let maker = environment.multiton { (_, _, _: Int, _: Double, _: String, _: Float, _: Int) in 42 } let arguments = (1, 1.0, "", Float(1.0), 5) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver3()) } == 42 } } } diff --git a/Tests/Unit Specs/ContextedResolverSpec.swift b/Tests/Unit Specs/ContextedResolverSpec.swift index 109aeb40..7accc819 100644 --- a/Tests/Unit Specs/ContextedResolverSpec.swift +++ b/Tests/Unit Specs/ContextedResolverSpec.swift @@ -6,13 +6,13 @@ import Nimble import Quick @testable import Swinject -class ContextedResolverSpec: QuickSpec { override func spec() { - var resolver: ContextedResolver! - var wrapped = AnyResolverMock() +class ContextedResolver3Spec: QuickSpec { override func spec() { + var resolver: ContextedResolver3! + var wrapped = AnyResolver3Mock() beforeEach { - wrapped = AnyResolverMock() + wrapped = AnyResolver3Mock() wrapped.resolveReturnValue = 0 - resolver = ContextedResolver(context: (), resolver: wrapped) + resolver = ContextedResolver3(context: (), resolver: wrapped) } describe("resolve") { it("returns value from wrapped resolver") { @@ -33,7 +33,7 @@ class ContextedResolverSpec: QuickSpec { override func spec() { expect(receivedRequest?.argument) == "argument" } it("calls wrapped resolver with it's context") { - let resolver = ContextedResolver(context: "context", resolver: wrapped) + let resolver = ContextedResolver3(context: "context", resolver: wrapped) _ = try? resolver.resolve(request(type: Int.self, tag: NoTag(), arg: ())) let receivedRequest = wrapped.resolveReceivedRequest as? InstanceRequest, String, Void> expect(receivedRequest?.context) == "context" diff --git a/Tests/Unit Specs/ScopedBindingSpec.swift b/Tests/Unit Specs/ScopedBindingSpec.swift index 1e324db3..12d36918 100644 --- a/Tests/Unit Specs/ScopedBindingSpec.swift +++ b/Tests/Unit Specs/ScopedBindingSpec.swift @@ -65,13 +65,13 @@ class ScopedBindingSpec: QuickSpec { override func spec() { binding = ScopedBinding(key: key, maker: maker, scope: scope) } it("retrieves registry using passed context") { - _ = try? binding.instance(arg: (), context: "context", resolver: DummyResolver()) + _ = try? binding.instance(arg: (), context: "context", resolver: DummyResolver3()) expect(scope.registryForReceivedContext as? String) == "context" } it("retrieves instance from registry using a correct key") { let descriptor = AnyTypeDescriptorMock() key.descriptor = descriptor - _ = try? binding.instance(arg: 42, context: (), resolver: DummyResolver()) + _ = try? binding.instance(arg: 42, context: (), resolver: DummyResolver3()) expect(registry.instanceKeyReceivedKey?.argument as? Int) == 42 expect(registry.instanceKeyReceivedKey?.descriptor) === descriptor } @@ -80,22 +80,22 @@ class ScopedBindingSpec: QuickSpec { override func spec() { scope.registryForReturnValue = BuilderScopeRegistry() } it("returns instance produced by maker") { - maker.makeInstanceArgContextResolverReturnValue = 42 - let instance = try? binding.instance(arg: (), context: (), resolver: DummyResolver()) as? Int + maker.makeInstanceArgContextResolver3ReturnValue = 42 + let instance = try? binding.instance(arg: (), context: (), resolver: DummyResolver3()) as? Int expect(instance) == 42 } it("rethrows error from maker") { - maker.makeInstanceArgContextResolverThrowableError = TestError() + maker.makeInstanceArgContextResolver3ThrowableError = TestError() expect { - try binding.instance(arg: (), context: (), resolver: DummyResolver()) + try binding.instance(arg: (), context: (), resolver: DummyResolver3()) }.to(throwError(errorType: TestError.self)) } it("invokes maker with correct parameters") { - let resolver = DummyResolver() + let resolver = DummyResolver3() _ = try? binding.instance(arg: 42, context: "context", resolver: resolver) - expect(maker.makeInstanceArgContextResolverReceivedArguments?.arg as? Int) == 42 - expect(maker.makeInstanceArgContextResolverReceivedArguments?.context as? String) == "context" - expect(maker.makeInstanceArgContextResolverReceivedArguments?.resolver) === resolver + expect(maker.makeInstanceArgContextResolver3ReceivedArguments?.arg as? Int) == 42 + expect(maker.makeInstanceArgContextResolver3ReceivedArguments?.context as? String) == "context" + expect(maker.makeInstanceArgContextResolver3ReceivedArguments?.resolver) === resolver } } } diff --git a/Tests/Unit Specs/SwinjectSpec.swift b/Tests/Unit Specs/SwinjectSpec.swift index 4a90187c..6aaba6a5 100644 --- a/Tests/Unit Specs/SwinjectSpec.swift +++ b/Tests/Unit Specs/SwinjectSpec.swift @@ -24,41 +24,41 @@ class SwinjectSpec: QuickSpec { override func spec() { it("request instance from matching binding") { binding.matchesReturnValue = true _ = try? swinject.instance(of: Any.self) - expect(binding.instanceArgContextResolverCallsCount) == 1 + expect(binding.instanceArgContextResolver3CallsCount) == 1 } it("does not request instance from matching binding until instance is required") { binding.matchesReturnValue = true - expect(binding.instanceArgContextResolverCallsCount) == 0 + expect(binding.instanceArgContextResolver3CallsCount) == 0 } it("only requests instance from matching binding") { binding.matchesReturnValue = false _ = try? swinject.instance(of: Any.self) - expect(binding.instanceArgContextResolverCallsCount) == 0 + expect(binding.instanceArgContextResolver3CallsCount) == 0 } it("returns instance produced by binding") { binding.matchesReturnValue = true - binding.instanceArgContextResolverReturnValue = 42 + binding.instanceArgContextResolver3ReturnValue = 42 expect { try swinject.instance(of: Any.self) as? Int } == 42 } it("rethrows error from binding") { binding.matchesReturnValue = true - binding.instanceArgContextResolverThrowableError = TestError() + binding.instanceArgContextResolver3ThrowableError = TestError() expect { try swinject.instance(of: Any.self) }.to(throwError(errorType: TestError.self)) } it("crashes if bound type does not match requested type") { binding.matchesReturnValue = true - binding.instanceArgContextResolverReturnValue = "" + binding.instanceArgContextResolver3ReturnValue = "" expect { _ = try swinject.instance(of: Double.self) }.to(throwError()) } it("does not crash if bound type conforms to the requested type") { binding.matchesReturnValue = true - binding.instanceArgContextResolverReturnValue = 42 + binding.instanceArgContextResolver3ReturnValue = 42 expect { _ = try swinject.instance(of: CustomStringConvertible?.self) }.notTo(throwError()) } it("passes swinject as resolver") { binding.matchesReturnValue = true _ = try? swinject.instance(of: Any.self) - expect(binding.instanceArgContextResolverReceivedArguments?.resolver is Swinject).to(beTrue()) + expect(binding.instanceArgContextResolver3ReceivedArguments?.resolver is Swinject).to(beTrue()) } it("matches binding with correct key") { binding.matchesReturnValue = false @@ -95,7 +95,7 @@ class SwinjectSpec: QuickSpec { override func spec() { } it("returns instance from matching binding") { bindings[1].matchesReturnValue = true - bindings[1].instanceArgContextResolverReturnValue = 42 + bindings[1].instanceArgContextResolver3ReturnValue = 42 expect { try swinject.instance(of: Int.self) } == 42 } } @@ -109,7 +109,7 @@ class SwinjectSpec: QuickSpec { override func spec() { } it("does not throw if binding matches provided type") { binding.matchesReturnValue = true - binding.instanceArgContextResolverReturnValue = 42 + binding.instanceArgContextResolver3ReturnValue = 42 let provider = swinject.provider() as () throws -> Int expect { try provider() }.notTo(throwError()) } @@ -120,19 +120,19 @@ class SwinjectSpec: QuickSpec { override func spec() { } it("does not request provided type until provider is called") { binding.matchesReturnValue = true - binding.instanceArgContextResolverReturnValue = 42 + binding.instanceArgContextResolver3ReturnValue = 42 _ = swinject.provider(of: Int.self) - expect(binding.instanceArgContextResolverCallsCount) == 0 + expect(binding.instanceArgContextResolver3CallsCount) == 0 } it("returns instance from binding") { binding.matchesReturnValue = true - binding.instanceArgContextResolverReturnValue = 42 + binding.instanceArgContextResolver3ReturnValue = 42 let provider = swinject.provider(of: Int.self) expect { try provider() } == 42 } it("rethrows binding error from provider") { binding.matchesReturnValue = true - binding.instanceArgContextResolverThrowableError = TestError() + binding.instanceArgContextResolver3ThrowableError = TestError() let provider = swinject.provider(of: Int.self) expect { try provider() }.to(throwError(errorType: TestError.self)) } @@ -151,7 +151,7 @@ class SwinjectSpec: QuickSpec { override func spec() { it("passes given context to the binding") { binding.matchesReturnValue = true _ = try? swinject.on("context").provider()() as Int - expect(binding.instanceArgContextResolverReceivedArguments?.context as? String) == "context" + expect(binding.instanceArgContextResolver3ReceivedArguments?.context as? String) == "context" } } describe("factory injection") { @@ -168,33 +168,33 @@ class SwinjectSpec: QuickSpec { override func spec() { } it("does not throw if binding matches created type") { binding.matchesReturnValue = true - binding.instanceArgContextResolverReturnValue = 42 + binding.instanceArgContextResolver3ReturnValue = 42 let factory = swinject.factory() as (String) throws -> Int expect { try factory("arg") }.notTo(throwError()) } it("does not request created type until factory is called") { binding.matchesReturnValue = true - binding.instanceArgContextResolverReturnValue = 42 + binding.instanceArgContextResolver3ReturnValue = 42 _ = swinject.factory() as (String) throws -> Int - expect(binding.instanceArgContextResolverCallsCount) == 0 + expect(binding.instanceArgContextResolver3CallsCount) == 0 } it("rethrows binding error from factory") { binding.matchesReturnValue = true - binding.instanceArgContextResolverThrowableError = TestError() + binding.instanceArgContextResolver3ThrowableError = TestError() let factory = swinject.factory() as (String) throws -> Int expect { try factory("arg") }.to(throwError(errorType: TestError.self)) } it("returns instance from binding") { binding.matchesReturnValue = true - binding.instanceArgContextResolverReturnValue = 42 + binding.instanceArgContextResolver3ReturnValue = 42 let factory = swinject.factory() as (String) throws -> Int expect { try factory("arg") } == 42 } it("passes given factory argument to binding") { binding.matchesReturnValue = true - binding.instanceArgContextResolverReturnValue = 42 + binding.instanceArgContextResolver3ReturnValue = 42 _ = try? swinject.factory(of: Int.self)("arg") - expect(binding.instanceArgContextResolverReceivedArguments?.arg as? String) == "arg" + expect(binding.instanceArgContextResolver3ReceivedArguments?.arg as? String) == "arg" } it("matches binding with correct key") { binding.matchesReturnValue = false @@ -211,42 +211,42 @@ class SwinjectSpec: QuickSpec { override func spec() { it("passes given context to the bidndning") { binding.matchesReturnValue = true _ = try? swinject.on("context").factory()("arg") as Int - expect(binding.instanceArgContextResolverReceivedArguments?.context as? String) == "context" + expect(binding.instanceArgContextResolver3ReceivedArguments?.context as? String) == "context" } context("currying") { beforeEach { binding.matchesReturnValue = true - binding.instanceArgContextResolverReturnValue = 42 + binding.instanceArgContextResolver3ReturnValue = 42 } it("can curry 2-tuple as 0 / 2 argument") { _ = try? swinject.factory()("arg1", "arg2") as Int - let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? (String, String) + let receivedArg = binding.instanceArgContextResolver3ReceivedArguments?.arg as? (String, String) expect(receivedArg?.0) == "arg1" expect(receivedArg?.1) == "arg2" } it("can curry 2-tuple as 1 / 1 argument") { _ = try? swinject.factory(arg: "arg1")("arg2") as Int - let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? (String, String) + let receivedArg = binding.instanceArgContextResolver3ReceivedArguments?.arg as? (String, String) expect(receivedArg?.0) == "arg1" expect(receivedArg?.1) == "arg2" } it("can curry 3-tuple as 0 / 3 argument") { _ = try? swinject.factory()("arg1", 2, "arg3") as Int - let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? (String, Int, String) + let receivedArg = binding.instanceArgContextResolver3ReceivedArguments?.arg as? (String, Int, String) expect(receivedArg?.0) == "arg1" expect(receivedArg?.1) == 2 expect(receivedArg?.2) == "arg3" } it("can curry 3-tuple as 1 / 2 argument") { _ = try? swinject.factory(arg: "arg1")(2, "arg3") as Int - let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? (String, Int, String) + let receivedArg = binding.instanceArgContextResolver3ReceivedArguments?.arg as? (String, Int, String) expect(receivedArg?.0) == "arg1" expect(receivedArg?.1) == 2 expect(receivedArg?.2) == "arg3" } it("can curry 3-tuple as 2 / 1 argument") { _ = try? swinject.factory(args: "arg1", 2)("arg3") as Int - let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? (String, Int, String) + let receivedArg = binding.instanceArgContextResolver3ReceivedArguments?.arg as? (String, Int, String) expect(receivedArg?.0) == "arg1" expect(receivedArg?.1) == 2 expect(receivedArg?.2) == "arg3" diff --git a/Tests/Unit Specs/TypeBinderSpec.swift b/Tests/Unit Specs/TypeBinderSpec.swift index dc5dc819..1fd1d366 100644 --- a/Tests/Unit Specs/TypeBinderSpec.swift +++ b/Tests/Unit Specs/TypeBinderSpec.swift @@ -36,7 +36,7 @@ class TypeBinderSpec: QuickSpec { override func spec() { } it("works with passing instance directly") { let binding = bbind(descriptor).with(42) - expect { try binding.instance(arg: (), context: (), resolver: DummyResolver()) as? Int } == 42 + expect { try binding.instance(arg: (), context: (), resolver: DummyResolver3()) as? Int } == 42 } } describe("`&` method") { @@ -51,7 +51,7 @@ class TypeBinderSpec: QuickSpec { override func spec() { } it("works with passing instance directly") { let binding = bbind(descriptor) & 42 - expect { try binding.instance(arg: (), context: (), resolver: DummyResolver()) as? Int } == 42 + expect { try binding.instance(arg: (), context: (), resolver: DummyResolver3()) as? Int } == 42 } } } } From 3b1c8f33ccf6420c7914f45ce6a76225d53c2537 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 21 Jul 2019 16:10:29 +0200 Subject: [PATCH 083/239] Fix codestyle violations --- .swiftlint.yml | 9 +++++---- Sources/3.0 API/BinderEnvironment.swift | 3 +++ Sources/3.0 API/Resolver+Injection.swift | 1 + Sources/3.0 API/TypeBinder.swift | 4 +++- Sources/Core/ContextedResolver.swift | 4 +++- Sources/Core/InstanceRequest.swift | 6 +++++- Sources/Core/Matchable.swift | 2 +- Sources/Core/Resolver3.swift | 4 +++- Sources/Core/Swinject.swift | 8 ++++++-- Tests/{2.0 API => }/.swiftlint.yml | 3 +-- Tests/Support/NonGeneratedMocks.swift | 8 ++++++-- Tests/Unit Specs/BindingKeySpec.swift | 3 ++- Tests/Unit Specs/ContextedResolverSpec.swift | 4 +++- 13 files changed, 42 insertions(+), 17 deletions(-) rename Tests/{2.0 API => }/.swiftlint.yml (82%) diff --git a/.swiftlint.yml b/.swiftlint.yml index 33b64789..0a19e39b 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -6,7 +6,8 @@ included: - Sources - Tests excluded: - - Sources/Container.Arguments.swift - - Sources/SynchronizedResolver.Arguments.swift - - Sources/Resolver.swift - - Sources/ServiceEntry.TypeForwarding.swift + - Sources/2.0 API/Container.Arguments.swift + - Sources/2.0 API/SynchronizedResolver.Arguments.swift + - Sources/2.0 API/Resolver.swift + - Sources/2.0 API/ServiceEntry.TypeForwarding.swift + - Tests/Support/GeneratedMocks.swift diff --git a/Sources/3.0 API/BinderEnvironment.swift b/Sources/3.0 API/BinderEnvironment.swift index c3df31ff..8b77dbc4 100644 --- a/Sources/3.0 API/BinderEnvironment.swift +++ b/Sources/3.0 API/BinderEnvironment.swift @@ -14,6 +14,9 @@ public func scoped(_ scope: AScope) -> BinderEnvironment(_ builder: @escaping (Resolver3, Context) throws -> Type) -> SimpleBinding.Builder { .init { r, c, _ in try builder(r, c) } diff --git a/Sources/3.0 API/Resolver+Injection.swift b/Sources/3.0 API/Resolver+Injection.swift index c0d3f6db..803265f8 100644 --- a/Sources/3.0 API/Resolver+Injection.swift +++ b/Sources/3.0 API/Resolver+Injection.swift @@ -3,6 +3,7 @@ // // TODO: Overloads for multiple arguments & tag / notag combinations +// swiftlint:disable line_length public extension Resolver3 { func instance(of _: Type.Type = Type.self) throws -> Type { diff --git a/Sources/3.0 API/TypeBinder.swift b/Sources/3.0 API/TypeBinder.swift index 4bdc6970..01f4b69c 100644 --- a/Sources/3.0 API/TypeBinder.swift +++ b/Sources/3.0 API/TypeBinder.swift @@ -28,7 +28,9 @@ public extension TypeBinder { } } -public func & (lhs: TypeBinder, rhs: Maker) -> Binding where Maker: BindingMaker, Maker.BoundType == Descriptor.BaseType { +public func & ( + lhs: TypeBinder, rhs: Maker +) -> Binding where Maker: BindingMaker, Maker.BoundType == Descriptor.BaseType { lhs.with(rhs) } diff --git a/Sources/Core/ContextedResolver.swift b/Sources/Core/ContextedResolver.swift index 4754197a..3959ebd7 100644 --- a/Sources/Core/ContextedResolver.swift +++ b/Sources/Core/ContextedResolver.swift @@ -8,7 +8,9 @@ struct ContextedResolver3 { } extension ContextedResolver3: Resolver3 { - func resolve(_ request: InstanceRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { + func resolve( + _ request: InstanceRequest + ) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { try resolver.resolve( InstanceRequest( key: BindingKey(descriptor: request.key.descriptor), diff --git a/Sources/Core/InstanceRequest.swift b/Sources/Core/InstanceRequest.swift index b550052e..c5be5f79 100644 --- a/Sources/Core/InstanceRequest.swift +++ b/Sources/Core/InstanceRequest.swift @@ -8,6 +8,10 @@ public struct InstanceRequest where Descriptor: T let argument: Argument } -func request(type _: Type.Type = Type.self, tag: Tag, arg: Argument) -> InstanceRequest, Void, Argument> { +func request( + type _: Type.Type = Type.self, + tag: Tag, + arg: Argument +) -> InstanceRequest, Void, Argument> { InstanceRequest(key: BindingKey(descriptor: Tagged(tag: tag)), context: (), argument: arg) } diff --git a/Sources/Core/Matchable.swift b/Sources/Core/Matchable.swift index 7d1b128b..708435d2 100644 --- a/Sources/Core/Matchable.swift +++ b/Sources/Core/Matchable.swift @@ -5,7 +5,7 @@ // sourcery: AutoMockable public protocol Matchable { func matches(_ other: Any) -> Bool - var hashValue: Int { get } // FIXME: Use hash(into:) + var hashValue: Int { get } } // TODO: Box / Unbox internally all the arguments diff --git a/Sources/Core/Resolver3.swift b/Sources/Core/Resolver3.swift index 5862dcf9..80585641 100644 --- a/Sources/Core/Resolver3.swift +++ b/Sources/Core/Resolver3.swift @@ -4,7 +4,9 @@ // TODO: Rename public protocol Resolver3 { - func resolve(_ request: InstanceRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor + func resolve( + _ request: InstanceRequest + ) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor } public extension Resolver3 { diff --git a/Sources/Core/Swinject.swift b/Sources/Core/Swinject.swift index 2b7db023..b6f30629 100644 --- a/Sources/Core/Swinject.swift +++ b/Sources/Core/Swinject.swift @@ -11,7 +11,9 @@ public struct Swinject { } extension Swinject: Resolver3 { - public func resolve(_ request: InstanceRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { + public func resolve( + _ request: InstanceRequest + ) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { try instance(from: findBinding(for: request.key), context: request.context, arg: request.argument) } @@ -21,7 +23,9 @@ extension Swinject: Resolver3 { return bindings[0] } - private func instance(from binding: Binding, context: Context, arg: Argument) throws -> Type { + private func instance( + from binding: Binding, context: Context, arg: Argument + ) throws -> Type { try binding.instance(arg: arg, context: context, resolver: self) as? Type ?? { throw SwinjectError() }() } } diff --git a/Tests/2.0 API/.swiftlint.yml b/Tests/.swiftlint.yml similarity index 82% rename from Tests/2.0 API/.swiftlint.yml rename to Tests/.swiftlint.yml index db9940c8..44beb6de 100644 --- a/Tests/2.0 API/.swiftlint.yml +++ b/Tests/.swiftlint.yml @@ -1,5 +1,3 @@ -exclued: - - SwinjectTests disabled_rules: - force_cast - type_name @@ -7,4 +5,5 @@ disabled_rules: - function_body_length - type_body_length - identifier_name + - file_length diff --git a/Tests/Support/NonGeneratedMocks.swift b/Tests/Support/NonGeneratedMocks.swift index 5efbe08e..b3ade40e 100644 --- a/Tests/Support/NonGeneratedMocks.swift +++ b/Tests/Support/NonGeneratedMocks.swift @@ -5,7 +5,9 @@ @testable import Swinject class DummyResolver3: Resolver3 { - func resolve(_: InstanceRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { + func resolve( + _: InstanceRequest + ) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { fatalError() } } @@ -30,7 +32,9 @@ protocol AnyResolver3 { } extension AnyResolver3Mock: Resolver3 { - func resolve(_ request: InstanceRequest) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { + func resolve( + _ request: InstanceRequest + ) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { try resolve(request as Any) as! Descriptor.BaseType } } diff --git a/Tests/Unit Specs/BindingKeySpec.swift b/Tests/Unit Specs/BindingKeySpec.swift index dd0729a0..91cdee6a 100644 --- a/Tests/Unit Specs/BindingKeySpec.swift +++ b/Tests/Unit Specs/BindingKeySpec.swift @@ -6,11 +6,12 @@ import Nimble import Quick @testable import Swinject -class BindingKeySpec: QuickSpec { override func spec() { +class BindingKeySpec: QuickSpec { typealias AnyBindingKey = BindingKey typealias ArgumentBindingKey = BindingKey typealias ContextBindingKey = BindingKey +override func spec() { describe("matching") { var key: AnyBindingKey! var descriptor = AnyTypeDescriptorMock() diff --git a/Tests/Unit Specs/ContextedResolverSpec.swift b/Tests/Unit Specs/ContextedResolverSpec.swift index 7accc819..3e652950 100644 --- a/Tests/Unit Specs/ContextedResolverSpec.swift +++ b/Tests/Unit Specs/ContextedResolverSpec.swift @@ -22,7 +22,9 @@ class ContextedResolver3Spec: QuickSpec { override func spec() { } it("calls wrapped resolver with given type descriptor") { let descriptor = AnyTypeDescriptorMock() - let request = InstanceRequest(key: BindingKey(descriptor: descriptor), context: (), argument: ()) + let request = InstanceRequest( + key: BindingKey(descriptor: descriptor), context: (), argument: () + ) _ = try? resolver.resolve(request) let receivedRequest = wrapped.resolveReceivedRequest as? InstanceRequest expect(receivedRequest?.key.descriptor) === descriptor From 4651464ec51601f95e1742d044bc66c7f8f20f09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 21 Jul 2019 16:16:04 +0200 Subject: [PATCH 084/239] Resolve confilcts in tests --- .swiftformat | 1 + Swinject.xcodeproj/project.pbxproj | 146 ++++++---------- Tests/3.0 API/SwinjectApiSpec.swift | 28 ++-- Tests/{2.0 API => }/Info.plist | 0 Tests/Support/GeneratedMocks.swift | 157 +++++++++--------- Tests/Support/TestModels.swift | 4 +- Tests/Unit Specs/BinderEnvironmentSpec.swift | 16 +- Tests/Unit Specs/BindingKeySpec.swift | 12 +- Tests/Unit Specs/ScopedBindingSpec.swift | 10 +- .../StandardScopeRegistrySpec.swift | 16 +- Tests/Unit Specs/SwinjectSpec.swift | 58 +++---- 11 files changed, 202 insertions(+), 246 deletions(-) rename Tests/{2.0 API => }/Info.plist (100%) diff --git a/.swiftformat b/.swiftformat index 8debabb5..8d9c455d 100644 --- a/.swiftformat +++ b/.swiftformat @@ -1,2 +1,3 @@ --swiftversion 5.0 --header "\n Copyright © {created.year} Swinject Contributors. All rights reserved.\n" +--exclude Tests/Support/GeneratedMocks.swift diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 3f18fba5..b1b7c0ff 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -12,6 +12,7 @@ 0125E3E8A17D6F2F0CE2F893 /* ContainerSpec.GraphCaching.swift in Sources */ = {isa = PBXBuildFile; fileRef = D366825BB9272905C79AEA47 /* ContainerSpec.GraphCaching.swift */; }; 013A1E1096BD1305A3A14493 /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1910A1471C3CA9EA86F350BA /* LoadAwareAssembly.swift */; }; 01D985B5F99817DEE0E0DAD1 /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */; }; + 01F001388FD754499B18FFAC /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */; }; 02CBAAF2DD5E7D589F997A27 /* SpinLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 919757437CA99D0C506EC028 /* SpinLock.swift */; }; 03005DC48E35AEF37251FADC /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; 036C85135915C0847704947C /* ServiceEntry.TypeForwarding.erb in Resources */ = {isa = PBXBuildFile; fileRef = E6B3186E0AE372A6663F41E9 /* ServiceEntry.TypeForwarding.erb */; }; @@ -56,8 +57,6 @@ 1A03A1D9524E8912AF1CEE11 /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = EA7A547FC60DBD02D132B3E6 /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 1ACC90951353E5F69899A833 /* SimpleBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */; }; 1AD4C43B074F736BBDADA8C9 /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; - 1B29712FD3C5FB3B372EE35F /* Resolver3.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver3.swift */; }; - 1BBE296A616C1761DD76935C /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 443508AA18D686A564F59882 /* .swiftlint.yml */; }; 1C2F5A09F986586F85FAC3E8 /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; 1C8B304AAB75579AE100EDDF /* ServiceEntry.TypeForwarding.erb in Resources */ = {isa = PBXBuildFile; fileRef = E6B3186E0AE372A6663F41E9 /* ServiceEntry.TypeForwarding.erb */; }; 1CFCB38BC4EE2D3AAD40154E /* ScopedBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */; }; @@ -67,11 +66,13 @@ 20823C309A5C58900CDFA8C3 /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; 22837E727E47A3B8A588AB78 /* TypeBinderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDA62EEBC79ED2639C93A76B /* TypeBinderSpec.swift */; }; 240057137A0476B5874B0BCB /* DebugHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F4982F617A2FF202637E57C /* DebugHelper.swift */; }; + 2488CDD8D67CAC5C97BDF8B1 /* Resolver3.swift in Sources */ = {isa = PBXBuildFile; fileRef = C11D19C5F01647E4A576514A /* Resolver3.swift */; }; 25DE2596CC5387B9353FC204 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */; }; 261D54C316CB625359F7EE97 /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; 26AC238FC2FB5279ABF37C89 /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */; }; 26C8D37F26408DC308A0CDA3 /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; 2B386345150685F670BF04B1 /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9985BEF966DCBB28B12BE17B /* Person.swift */; }; + 2B571CF2267E90A42D32D264 /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */; }; 2B67E8B80A930E8598FAD10C /* Closable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D0BCCCD61CD9BECC29E064 /* Closable.swift */; }; 2BD8335377FA7F918849C815 /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; 2BE5AF2623B96992C74970F9 /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BA261FF01C5F5510873B3EC /* Animal.swift */; }; @@ -109,12 +110,12 @@ 401A790CF8450924114D89ED /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BFF4BA99493C54260878C4 /* ObjectScope.swift */; }; 418F111C8E128766AC8E33CC /* Closable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D0BCCCD61CD9BECC29E064 /* Closable.swift */; }; 41EEA4724CD401F38F9622E3 /* InstanceMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CADDB3E9E363310028AA5920 /* InstanceMaker.swift */; }; - 4281FDA4B4AFFC91F82B6B73 /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 443508AA18D686A564F59882 /* .swiftlint.yml */; }; 439254FAE8DF567DE9659ADA /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3586A4987B7C7C8122D674E /* SwinjectError.swift */; }; 4503217DA585B602EDE65742 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1FA0377AF4799D42E9462FA /* BasicAssembly.swift */; }; 457481A631CA1253094D108B /* GraphIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E95633441FFB44D8A05585C /* GraphIdentifier.swift */; }; 4578AA4291288B21ABD74735 /* ContextedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4021EB1EA6A2770920FAD979 /* ContextedResolverSpec.swift */; }; 45E5B568D6D0E7FC976DCDC1 /* ServiceKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45CA41659767E1378A9F492B /* ServiceKeySpec.swift */; }; + 462054EB9666775B13C36132 /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */; }; 46A14FAA5AA73BE8A0397707 /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; 4735419DE3D63E556D07C663 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B580B43E1891812C97209 /* Binding.swift */; }; 47B127ECD4209183E7E4A245 /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = A0157DBBD5E1F45963BB0932 /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -184,7 +185,6 @@ 6BFA0D58FD4131D3A2248208 /* ContextedResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBA3EF319F06A1B3B6C84C29 /* ContextedResolver.swift */; }; 6C59839F450D54DB72D0D726 /* ContainerSpec.CustomScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 332BC41A010B0C5AEAFDF545 /* ContainerSpec.CustomScope.swift */; }; 6C980EED98CBEADFD6DAA72A /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B3797A6BB56AE76CEC19F2A /* SwinjectApiSpec.swift */; }; - 6CBAFB568580240ECE9E1ECE /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 443508AA18D686A564F59882 /* .swiftlint.yml */; }; 6DCE3C30CAE0350C428154DC /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; 6F5323F408E5708076C02768 /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = A10187BB3A994165E7FC1528 /* ScopedBinding.swift */; }; 70268F222B8478BDC084E211 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; @@ -219,7 +219,6 @@ 86BE1ED67D6C0A493A9F141A /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 683A1FB7D7F4E9508D57E936 /* Quick.framework */; }; 86CD1F46C15A352BCF7CE396 /* ScopeRegistryKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2902FD4C1A50263340A51FFB /* ScopeRegistryKeySpec.swift */; }; 86E1845B6272AF95F1806CB4 /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; - 87008A3FBE4224F139BA3BC5 /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 443508AA18D686A564F59882 /* .swiftlint.yml */; }; 87056684D7F91917F6B0AC7A /* BinderEnvironmentSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */; }; 871BB9B8221656F0189ABEC6 /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; 876F90C64EA036596E797CB3 /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; @@ -227,7 +226,6 @@ 89613FDC2024EE34FD246A16 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ADC44E9312C3B974AFD8F07B /* Nimble.framework */; }; 89D83D5E42814659DFE8F518 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; 89F0AA65C3C9837A0A2452DF /* Quick.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = C765B92B00C0AC8625BB4AC9 /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 8A212C0486A514CF17B5F140 /* Resolver3.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver3.swift */; }; 8AAC0C68038E02A6049ABDC0 /* StandardScopeRegistrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */; }; 8AEB5894656086C3E2F022FD /* SimpleBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */; }; 8D58DF5C6963153A8B17D325 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; @@ -278,12 +276,14 @@ A19EFC58B60E547CC3A3A6BE /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 74DE57FB3E8228904E6FE0D7 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; A1B275A2EFA22C45AC46B31E /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; A2745DCB0ACE7714C65CA2A9 /* ObjectScope.Standard.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD433AFA21FF52AF81A9C9B8 /* ObjectScope.Standard.swift */; }; + A3815641CEB5A06759D288E0 /* Resolver3.swift in Sources */ = {isa = PBXBuildFile; fileRef = C11D19C5F01647E4A576514A /* Resolver3.swift */; }; A4490FF7ACCC5CBFB2C1896C /* Container.Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE4B1E4BA98573B6FED2D118 /* Container.Logging.swift */; }; A44D1B2E48E1C0FEF146933A /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; A4866802E1E597EEFEFDEB66 /* BindingKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = A24B4E8F1CA18603DBB6884A /* BindingKey.swift */; }; A4C25E4406175163B7C5B810 /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B3797A6BB56AE76CEC19F2A /* SwinjectApiSpec.swift */; }; A4CBDC3AA56FFC5719896568 /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; A4EA3E548D1CAB029697B0A9 /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; + A54B018EF21348D600F8ABD2 /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */; }; A600D3F52D38EBC5A3C75CC2 /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */; }; A6A470DC3A6D310AA0671075 /* ContainerSpec.CustomScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 332BC41A010B0C5AEAFDF545 /* ContainerSpec.CustomScope.swift */; }; A778AD223AF6C6E30BFFFC84 /* SpinLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 919757437CA99D0C506EC028 /* SpinLock.swift */; }; @@ -350,7 +350,6 @@ D8E2986FB186B630E54B60CD /* GraphIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E95633441FFB44D8A05585C /* GraphIdentifier.swift */; }; D98CA679A3AAC176D291CA8E /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEE8FDF4B975A8F2A9FCC5FF /* Food.swift */; }; DA6CB0A98FE5968CAAFDE9BF /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9985BEF966DCBB28B12BE17B /* Person.swift */; }; - DAFA9AE69744F3C5DC71CF50 /* Resolver3.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver3.swift */; }; DB14CA46130A816F6FAADE92 /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C074BAC560F277E806146C60 /* SimpleBinding.swift */; }; DC5C3A946BDA224C388D2438 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 359BCD3DA6F0CC2241878C82 /* EmploymentAssembly.swift */; }; DD1B936DC7365917DCA09FC8 /* Quick.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 823617F3B8A9192F56B13331 /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -364,7 +363,6 @@ E423395FC7006DD82513F347 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; E484C3994AD91E91C454B11D /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; E584841CFD26155FB056C85A /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; - E62C6509D0B52001CC309068 /* Resolver3.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver3.swift */; }; E63F31788438E1A43D480E84 /* Resolver.erb in Resources */ = {isa = PBXBuildFile; fileRef = B7DE2D7907C552B2C165E920 /* Resolver.erb */; }; E6E536A44F40492F42CA4044 /* ContainerSpec.DebugHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF340AF8DD2D821A225A36B3 /* ContainerSpec.DebugHelper.swift */; }; E7383E65C483ED1E66A49C5C /* InstanceStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06A8ED72CD6241A2CDEA8479 /* InstanceStorage.swift */; }; @@ -378,6 +376,7 @@ EAD0757CE0163D3549CB5405 /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; EC4EE4B0AECDBA8EC0B8F73D /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BA261FF01C5F5510873B3EC /* Animal.swift */; }; ED346CAABC0FF77612D9E186 /* SynchronizedResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4040F8D091ED67C84E2B8854 /* SynchronizedResolver.swift */; }; + EE5763938068B3FA56D1BA59 /* Resolver3.swift in Sources */ = {isa = PBXBuildFile; fileRef = C11D19C5F01647E4A576514A /* Resolver3.swift */; }; EEA8C20EB41C7FF5168941A5 /* SpinLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 919757437CA99D0C506EC028 /* SpinLock.swift */; }; EEB1E43EF50551F8B9793381 /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59111BE319C59E4CD6CF68CD /* Assembler.swift */; }; EEB3FA667B9103A8417F5EA4 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; @@ -398,6 +397,7 @@ FA44B27F082856C56051F088 /* InstanceStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06A8ED72CD6241A2CDEA8479 /* InstanceStorage.swift */; }; FAF8F8B75F63D43995A004E8 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; FB6FF5C5729B8E050616CCF6 /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 6EA4ECB5E4CEC9751AD36854 /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + FC120C659D0A6FB9CE757CB7 /* Resolver3.swift in Sources */ = {isa = PBXBuildFile; fileRef = C11D19C5F01647E4A576514A /* Resolver3.swift */; }; FCBA6B66A6BBA29B3EC6CDDD /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; FD1678ED0C9813A653D9C68B /* BinderEnvironmentSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */; }; FD792405FD95651F8205BB2D /* FunctionType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F2567098AC12010C308E26D /* FunctionType.swift */; }; @@ -497,6 +497,8 @@ 06A8ED72CD6241A2CDEA8479 /* InstanceStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceStorage.swift; sourceTree = ""; }; 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopedBindingSpec.swift; sourceTree = ""; }; 0E0B580B43E1891812C97209 /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; + 10480F2154EAA0414D4C1F55 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */ = {isa = PBXFileReference; path = .swiftlint.yml; sourceTree = ""; }; 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SynchronizedResolverSpec.swift; sourceTree = ""; }; 13513FA012659ADE699A3608 /* LazySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LazySpec.swift; sourceTree = ""; }; 17BEC193FDDE3BA488EA592E /* _Resolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = _Resolver.swift; sourceTree = ""; }; @@ -509,7 +511,7 @@ 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Behavior.swift; sourceTree = ""; }; 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Arguments.swift; sourceTree = ""; }; 2234FFBE7F556D1372AFB42D /* ServiceEntrySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServiceEntrySpec.swift; sourceTree = ""; }; - 24C19DEC1E7BDED41182B68C /* Container.Arguments.erb */ = {isa = PBXFileReference; lastKnownFileType = text; path = Container.Arguments.erb; sourceTree = ""; }; + 24C19DEC1E7BDED41182B68C /* Container.Arguments.erb */ = {isa = PBXFileReference; path = Container.Arguments.erb; sourceTree = ""; }; 273FB7A6277E0841E1570990 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; 2902FD4C1A50263340A51FFB /* ScopeRegistryKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistryKeySpec.swift; sourceTree = ""; }; 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; @@ -526,7 +528,6 @@ 4040F8D091ED67C84E2B8854 /* SynchronizedResolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SynchronizedResolver.swift; sourceTree = ""; }; 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingKeySpec.swift; sourceTree = ""; }; 42490D1D0C395951243F5CFF /* Container.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.swift; sourceTree = ""; }; - 443508AA18D686A564F59882 /* .swiftlint.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .swiftlint.yml; sourceTree = ""; }; 45CA41659767E1378A9F492B /* ServiceKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServiceKeySpec.swift; sourceTree = ""; }; 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTree.swift; sourceTree = ""; }; 494AA2AA587975747596C157 /* ProviderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProviderSpec.swift; sourceTree = ""; }; @@ -546,9 +547,8 @@ 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceWrapper.swift; sourceTree = ""; }; 6C13D01A2DE6F53DF3175D22 /* Container.Arguments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.Arguments.swift; sourceTree = ""; }; 6EA4ECB5E4CEC9751AD36854 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 715A7D1ADE43B7CB0EF80004 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 722CAC1761180366DE75A4A6 /* TestModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestModels.swift; sourceTree = ""; }; - 7395512173A1439ED411B188 /* SynchronizedResolver.Arguments.erb */ = {isa = PBXFileReference; lastKnownFileType = text; path = SynchronizedResolver.Arguments.erb; sourceTree = ""; }; + 7395512173A1439ED411B188 /* SynchronizedResolver.Arguments.erb */ = {isa = PBXFileReference; path = SynchronizedResolver.Arguments.erb; sourceTree = ""; }; 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.CustomStringConvertible.swift; sourceTree = ""; }; 74DE57FB3E8228904E6FE0D7 /* Swinject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Swinject.h; sourceTree = ""; }; 7BA261FF01C5F5510873B3EC /* Animal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Animal.swift; sourceTree = ""; }; @@ -568,12 +568,11 @@ A10187BB3A994165E7FC1528 /* ScopedBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopedBinding.swift; sourceTree = ""; }; A24B4E8F1CA18603DBB6884A /* BindingKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingKey.swift; sourceTree = ""; }; A3586A4987B7C7C8122D674E /* SwinjectError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectError.swift; sourceTree = ""; }; - A5583CF2602DDFB5E8A7D2DE /* Resolver3.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Resolver3.swift; sourceTree = ""; }; ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Circularity.swift; sourceTree = ""; }; ADC44E9312C3B974AFD8F07B /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; ADD71387EBA54D7EF60D0089 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AssemblerSpec.swift; sourceTree = ""; }; - B7DE2D7907C552B2C165E920 /* Resolver.erb */ = {isa = PBXFileReference; lastKnownFileType = text; path = Resolver.erb; sourceTree = ""; }; + B7DE2D7907C552B2C165E920 /* Resolver.erb */ = {isa = PBXFileReference; path = Resolver.erb; sourceTree = ""; }; B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderEnvironment.swift; sourceTree = ""; }; B92B8E618A08408404FB2A7A /* TypeBinder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinder.swift; sourceTree = ""; }; BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StandardScopeRegistrySpec.swift; sourceTree = ""; }; @@ -583,6 +582,7 @@ BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Behavior.swift; sourceTree = ""; }; C074BAC560F277E806146C60 /* SimpleBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleBinding.swift; sourceTree = ""; }; C07B4728F7C73CC5530956A2 /* Resolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Resolver.swift; sourceTree = ""; }; + C11D19C5F01647E4A576514A /* Resolver3.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Resolver3.swift; sourceTree = ""; }; C765B92B00C0AC8625BB4AC9 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; CADDB3E9E363310028AA5920 /* InstanceMaker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceMaker.swift; sourceTree = ""; }; CC85CB215058F95C0BC190B1 /* Bridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bridge.swift; sourceTree = ""; }; @@ -592,7 +592,7 @@ DF340AF8DD2D821A225A36B3 /* ContainerSpec.DebugHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.DebugHelper.swift; sourceTree = ""; }; E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRequest.swift; sourceTree = ""; }; E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; - E6B3186E0AE372A6663F41E9 /* ServiceEntry.TypeForwarding.erb */ = {isa = PBXFileReference; lastKnownFileType = text; path = ServiceEntry.TypeForwarding.erb; sourceTree = ""; }; + E6B3186E0AE372A6663F41E9 /* ServiceEntry.TypeForwarding.erb */ = {isa = PBXFileReference; path = ServiceEntry.TypeForwarding.erb; sourceTree = ""; }; EA7A547FC60DBD02D132B3E6 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; EBA3EF319F06A1B3B6C84C29 /* ContextedResolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextedResolver.swift; sourceTree = ""; }; ECE2B2EFBFDA910758EE1CA5 /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -809,6 +809,8 @@ C5602A1B64E47775AF8D5700 /* Tests */ = { isa = PBXGroup; children = ( + 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */, + 10480F2154EAA0414D4C1F55 /* Info.plist */, F64B4AFEC15ABABB3014A636 /* 2.0 API */, 9A6E5EB655CFE64BBCF5DED1 /* 3.0 API */, 4F46C48FA15F512EAED5F67A /* Support */, @@ -844,7 +846,6 @@ F64B4AFEC15ABABB3014A636 /* 2.0 API */ = { isa = PBXGroup; children = ( - 443508AA18D686A564F59882 /* .swiftlint.yml */, 7BA261FF01C5F5510873B3EC /* Animal.swift */, B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */, D1FA0377AF4799D42E9462FA /* BasicAssembly.swift */, @@ -861,7 +862,6 @@ F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */, 359BCD3DA6F0CC2241878C82 /* EmploymentAssembly.swift */, EEE8FDF4B975A8F2A9FCC5FF /* Food.swift */, - 715A7D1ADE43B7CB0EF80004 /* Info.plist */, 13513FA012659ADE699A3608 /* LazySpec.swift */, 1910A1471C3CA9EA86F350BA /* LoadAwareAssembly.swift */, 9985BEF966DCBB28B12BE17B /* Person.swift */, @@ -884,7 +884,7 @@ CADDB3E9E363310028AA5920 /* InstanceMaker.swift */, E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */, 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */, - A5583CF2602DDFB5E8A7D2DE /* Resolver3.swift */, + C11D19C5F01647E4A576514A /* Resolver3.swift */, 5057BAB33984E3E33469452B /* Scope.swift */, A10187BB3A994165E7FC1528 /* ScopedBinding.swift */, 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */, @@ -1120,7 +1120,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - 4281FDA4B4AFFC91F82B6B73 /* .swiftlint.yml in Resources */, + 01F001388FD754499B18FFAC /* .swiftlint.yml in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1128,7 +1128,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - 6CBAFB568580240ECE9E1ECE /* .swiftlint.yml in Resources */, + 462054EB9666775B13C36132 /* .swiftlint.yml in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1147,7 +1147,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - 87008A3FBE4224F139BA3BC5 /* .swiftlint.yml in Resources */, + A54B018EF21348D600F8ABD2 /* .swiftlint.yml in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1177,7 +1177,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - 1BBE296A616C1761DD76935C /* .swiftlint.yml in Resources */, + 2B571CF2267E90A42D32D264 /* .swiftlint.yml in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1297,8 +1297,8 @@ 3E13E204659AF2DCE94D75CB /* ObjectScope.Standard.swift in Sources */, 79772C34E5102A8E3003DBF8 /* ObjectScope.swift in Sources */, 5C4C106D138E771C872F5E80 /* Resolver+Injection.swift in Sources */, - DAFA9AE69744F3C5DC71CF50 /* Resolver3.swift in Sources */, E7E9DE84E1861D125F8D686A /* Resolver.swift in Sources */, + FC120C659D0A6FB9CE757CB7 /* Resolver3.swift in Sources */, 71C4A75D54446D844BA5FB85 /* Scope.swift in Sources */, 1AD4C43B074F736BBDADA8C9 /* ScopeRegistry.swift in Sources */, 971B97F191A9FF75A6586E0A /* ScopeRegistryKey.swift in Sources */, @@ -1447,8 +1447,8 @@ A2745DCB0ACE7714C65CA2A9 /* ObjectScope.Standard.swift in Sources */, 401A790CF8450924114D89ED /* ObjectScope.swift in Sources */, 741344C30785507B22DF703B /* Resolver+Injection.swift in Sources */, - E62C6509D0B52001CC309068 /* Resolver3.swift in Sources */, FDCF96E2A442CDC6815B8127 /* Resolver.swift in Sources */, + 2488CDD8D67CAC5C97BDF8B1 /* Resolver3.swift in Sources */, 1718A1577AB543174FD8E644 /* Scope.swift in Sources */, 1F4FBB9D795CE9D45E5A8BEE /* ScopeRegistry.swift in Sources */, 54A1FEE340AC3A2413876AD2 /* ScopeRegistryKey.swift in Sources */, @@ -1597,8 +1597,8 @@ 61FA449BF10682C9E89E767F /* ObjectScope.Standard.swift in Sources */, D688F61360D46A16B0678BA4 /* ObjectScope.swift in Sources */, 1C2F5A09F986586F85FAC3E8 /* Resolver+Injection.swift in Sources */, - 1B29712FD3C5FB3B372EE35F /* Resolver3.swift in Sources */, 8108969F33C37040624E0D02 /* Resolver.swift in Sources */, + EE5763938068B3FA56D1BA59 /* Resolver3.swift in Sources */, D557A108A21751DF75542692 /* Scope.swift in Sources */, D7DE20CC15F3A6BD09E43A75 /* ScopeRegistry.swift in Sources */, 9437AF5CAAD1A2D033AE3599 /* ScopeRegistryKey.swift in Sources */, @@ -1649,8 +1649,8 @@ 1F2E1C6B8F28C5441D52C033 /* ObjectScope.Standard.swift in Sources */, 3AC304A612ECAED02C58BBF5 /* ObjectScope.swift in Sources */, 90B4143005C86717AC76B6EE /* Resolver+Injection.swift in Sources */, - 8A212C0486A514CF17B5F140 /* Resolver3.swift in Sources */, 66033468A5FC65C19B60086A /* Resolver.swift in Sources */, + A3815641CEB5A06759D288E0 /* Resolver3.swift in Sources */, B2FCC51BB61148422256A14A /* Scope.swift in Sources */, 46A14FAA5AA73BE8A0397707 /* ScopeRegistry.swift in Sources */, 18A07EB6FB61F3CDCC766AF4 /* ScopeRegistryKey.swift in Sources */, @@ -1766,13 +1766,9 @@ "$(inherited)", "$(PROJECT_DIR)/Carthage/Build/watchOS", ); - INFOPLIST_FILE = "Tests/2.0 API/Info.plist"; + INFOPLIST_FILE = Tests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SwinjectTests; SDKROOT = watchos; @@ -1796,10 +1792,7 @@ INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = Swinject; SDKROOT = macosx; @@ -1822,10 +1815,7 @@ INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = Swinject; SDKROOT = iphoneos; @@ -1872,10 +1862,7 @@ INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = Swinject; SDKROOT = appletvos; @@ -1895,13 +1882,9 @@ "$(inherited)", "$(PROJECT_DIR)/Carthage/Build/tvOS", ); - INFOPLIST_FILE = "Tests/2.0 API/Info.plist"; + INFOPLIST_FILE = Tests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SwinjectTests; SDKROOT = appletvos; @@ -1969,13 +1952,9 @@ "$(inherited)", "$(PROJECT_DIR)/Carthage/Build/iOS", ); - INFOPLIST_FILE = "Tests/2.0 API/Info.plist"; + INFOPLIST_FILE = Tests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SwinjectTests; SDKROOT = iphoneos; @@ -1997,10 +1976,7 @@ INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = Swinject; SDKROOT = appletvos; @@ -2048,10 +2024,7 @@ INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = Swinject; SDKROOT = macosx; @@ -2074,10 +2047,7 @@ INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = Swinject; SDKROOT = iphoneos; @@ -2098,13 +2068,9 @@ "$(inherited)", "$(PROJECT_DIR)/Carthage/Build/Mac", ); - INFOPLIST_FILE = "Tests/2.0 API/Info.plist"; + INFOPLIST_FILE = Tests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - "@loader_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SwinjectTests; SDKROOT = macosx; @@ -2121,13 +2087,9 @@ "$(inherited)", "$(PROJECT_DIR)/Carthage/Build/tvOS", ); - INFOPLIST_FILE = "Tests/2.0 API/Info.plist"; + INFOPLIST_FILE = Tests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SwinjectTests; SDKROOT = appletvos; @@ -2146,13 +2108,9 @@ "$(inherited)", "$(PROJECT_DIR)/Carthage/Build/Mac", ); - INFOPLIST_FILE = "Tests/2.0 API/Info.plist"; + INFOPLIST_FILE = Tests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - "@loader_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SwinjectTests; SDKROOT = macosx; @@ -2169,13 +2127,9 @@ "$(inherited)", "$(PROJECT_DIR)/Carthage/Build/watchOS", ); - INFOPLIST_FILE = "Tests/2.0 API/Info.plist"; + INFOPLIST_FILE = Tests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SwinjectTests; SDKROOT = watchos; @@ -2194,13 +2148,9 @@ "$(inherited)", "$(PROJECT_DIR)/Carthage/Build/iOS", ); - INFOPLIST_FILE = "Tests/2.0 API/Info.plist"; + INFOPLIST_FILE = Tests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SwinjectTests; SDKROOT = iphoneos; diff --git a/Tests/3.0 API/SwinjectApiSpec.swift b/Tests/3.0 API/SwinjectApiSpec.swift index a8b8afa3..af3394ba 100644 --- a/Tests/3.0 API/SwinjectApiSpec.swift +++ b/Tests/3.0 API/SwinjectApiSpec.swift @@ -7,9 +7,9 @@ import Quick import Swinject class SwinjectApiSpec: QuickSpec { override func spec() { - var person = Person() + var human = Human() beforeEach { - person = Person() + human = Human() } it("returns instance if is bound") { let swinject = Swinject { @@ -32,9 +32,9 @@ class SwinjectApiSpec: QuickSpec { override func spec() { it("returns instance if all dependencies are bound") { let swinject = Swinject { bbind(Pet.self) & provider { Pet(owner: try $0.instance()) } - bbind(Person.self) & instance(person) + bbind(Human.self) & instance(human) } - expect { try swinject.instance(of: Pet.self).owner } === person + expect { try swinject.instance(of: Pet.self).owner } === human } it("throws if has multiple bindings for the same request") { let swinject = Swinject { @@ -118,33 +118,33 @@ class SwinjectApiSpec: QuickSpec { override func spec() { bbind(Int.self) & 42 } expect { try swinject.on("context").instance() as Int } == 42 - expect { try swinject.on(Person()).instance() as Int } == 42 + expect { try swinject.on(Human()).instance() as Int } == 42 } it("can bind singleton") { let swinject = Swinject { - bbind(Person.self) & singleton { Person() } + bbind(Human.self) & singleton { Human() } } - let first = try? swinject.instance() as Person - let second = try? swinject.instance() as Person + let first = try? swinject.instance() as Human + let second = try? swinject.instance() as Human expect(first) === second } it("can bind scoped singleton") { let scope = UnboundScope() let swinject = Swinject { - bbind(Person.self) & scoped(scope).singleton { Person() } + bbind(Human.self) & scoped(scope).singleton { Human() } } - let first = try? swinject.instance() as Person - let second = try? swinject.instance() as Person + let first = try? swinject.instance() as Human + let second = try? swinject.instance() as Human expect(first) === second } it("can close scopes") { let scope = UnboundScope() let swinject = Swinject { - bbind(Person.self) & scoped(scope).singleton { Person() } + bbind(Human.self) & scoped(scope).singleton { Human() } } - let first = try? swinject.instance() as Person + let first = try? swinject.instance() as Human scope.close() - let second = try? swinject.instance() as Person + let second = try? swinject.instance() as Human expect(first) !== second } it("notifies instances when scope is closed") { diff --git a/Tests/2.0 API/Info.plist b/Tests/Info.plist similarity index 100% rename from Tests/2.0 API/Info.plist rename to Tests/Info.plist diff --git a/Tests/Support/GeneratedMocks.swift b/Tests/Support/GeneratedMocks.swift index d71b0383..6fd07d26 100644 --- a/Tests/Support/GeneratedMocks.swift +++ b/Tests/Support/GeneratedMocks.swift @@ -1,39 +1,48 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// +// Generated using Sourcery 0.16.1 — https://github.com/krzysztofzablocki/Sourcery +// DO NOT EDIT + // swiftlint:disable line_length // swiftlint:disable variable_name @testable import Swinject + + + + + + + + + + + + + class AnyBindingKeyMock: AnyBindingKey { var contextType: Any.Type { get { return underlyingContextType } set(value) { underlyingContextType = value } } - var underlyingContextType: Any.Type! var argumentType: Any.Type { get { return underlyingArgumentType } set(value) { underlyingArgumentType = value } } - var underlyingArgumentType: Any.Type! var descriptor: AnyTypeDescriptor { get { return underlyingDescriptor } set(value) { underlyingDescriptor = value } } - var underlyingDescriptor: AnyTypeDescriptor! - // MARK: - matches + //MARK: - matches var matchesCallsCount = 0 var matchesCalled: Bool { return matchesCallsCount > 0 } - var matchesReceivedOther: AnyBindingKey? var matchesReceivedInvocations: [AnyBindingKey] = [] var matchesReturnValue: Bool! @@ -43,18 +52,18 @@ class AnyBindingKeyMock: AnyBindingKey { matchesCallsCount += 1 matchesReceivedOther = other matchesReceivedInvocations.append(other) - return matchesClosure.map { $0(other) } ?? matchesReturnValue + return matchesClosure.map({ $0(other) }) ?? matchesReturnValue } -} +} class AnyBindningMakerMock: AnyBindningMaker { - // MARK: - makeBinding + + //MARK: - makeBinding var makeBindingForCallsCount = 0 var makeBindingForCalled: Bool { return makeBindingForCallsCount > 0 } - var makeBindingForReceivedDescriptor: AnyTypeDescriptor? var makeBindingForReceivedInvocations: [AnyTypeDescriptor] = [] var makeBindingForReturnValue: Binding! @@ -64,44 +73,44 @@ class AnyBindningMakerMock: AnyBindningMaker { makeBindingForCallsCount += 1 makeBindingForReceivedDescriptor = descriptor makeBindingForReceivedInvocations.append(descriptor) - return makeBindingForClosure.map { $0(descriptor) } ?? makeBindingForReturnValue + return makeBindingForClosure.map({ $0(descriptor) }) ?? makeBindingForReturnValue } -} +} class AnyInstanceMakerMock: AnyInstanceMaker { - // MARK: - makeInstance - var makeInstanceArgContextResolver3ThrowableError: Error? - var makeInstanceArgContextResolver3CallsCount = 0 - var makeInstanceArgContextResolver3Called: Bool { - return makeInstanceArgContextResolver3CallsCount > 0 - } + //MARK: - makeInstance - var makeInstanceArgContextResolver3ReceivedArguments: (arg: Any, context: Any, resolver: Resolver3)? - var makeInstanceArgContextResolver3ReceivedInvocations: [(arg: Any, context: Any, resolver: Resolver3)] = [] - var makeInstanceArgContextResolver3ReturnValue: Any! - var makeInstanceArgContextResolver3Closure: ((Any, Any, Resolver3) throws -> Any)? + var makeInstanceArgContextResolverThrowableError: Error? + var makeInstanceArgContextResolverCallsCount = 0 + var makeInstanceArgContextResolverCalled: Bool { + return makeInstanceArgContextResolverCallsCount > 0 + } + var makeInstanceArgContextResolverReceivedArguments: (arg: Any, context: Any, resolver: Resolver3)? + var makeInstanceArgContextResolverReceivedInvocations: [(arg: Any, context: Any, resolver: Resolver3)] = [] + var makeInstanceArgContextResolverReturnValue: Any! + var makeInstanceArgContextResolverClosure: ((Any, Any, Resolver3) throws -> Any)? func makeInstance(arg: Any, context: Any, resolver: Resolver3) throws -> Any { - if let error = makeInstanceArgContextResolver3ThrowableError { + if let error = makeInstanceArgContextResolverThrowableError { throw error } - makeInstanceArgContextResolver3CallsCount += 1 - makeInstanceArgContextResolver3ReceivedArguments = (arg: arg, context: context, resolver: resolver) - makeInstanceArgContextResolver3ReceivedInvocations.append((arg: arg, context: context, resolver: resolver)) - return try makeInstanceArgContextResolver3Closure.map { try $0(arg, context, resolver) } ?? makeInstanceArgContextResolver3ReturnValue + makeInstanceArgContextResolverCallsCount += 1 + makeInstanceArgContextResolverReceivedArguments = (arg: arg, context: context, resolver: resolver) + makeInstanceArgContextResolverReceivedInvocations.append((arg: arg, context: context, resolver: resolver)) + return try makeInstanceArgContextResolverClosure.map({ try $0(arg, context, resolver) }) ?? makeInstanceArgContextResolverReturnValue } -} +} class AnyResolver3Mock: AnyResolver3 { - // MARK: - resolve + + //MARK: - resolve var resolveThrowableError: Error? var resolveCallsCount = 0 var resolveCalled: Bool { return resolveCallsCount > 0 } - var resolveReceivedRequest: Any? var resolveReceivedInvocations: [Any] = [] var resolveReturnValue: Any! @@ -114,18 +123,18 @@ class AnyResolver3Mock: AnyResolver3 { resolveCallsCount += 1 resolveReceivedRequest = request resolveReceivedInvocations.append(request) - return try resolveClosure.map { try $0(request) } ?? resolveReturnValue + return try resolveClosure.map({ try $0(request) }) ?? resolveReturnValue } -} +} class AnyScopeMock: AnyScope { - // MARK: - registry + + //MARK: - registry var registryForCallsCount = 0 var registryForCalled: Bool { return registryForCallsCount > 0 } - var registryForReceivedContext: Any? var registryForReceivedInvocations: [Any] = [] var registryForReturnValue: ScopeRegistry! @@ -135,25 +144,23 @@ class AnyScopeMock: AnyScope { registryForCallsCount += 1 registryForReceivedContext = context registryForReceivedInvocations.append(context) - return registryForClosure.map { $0(context) } ?? registryForReturnValue + return registryForClosure.map({ $0(context) }) ?? registryForReturnValue } -} +} class AnyTypeDescriptorMock: AnyTypeDescriptor { var hashValue: Int { get { return underlyingHashValue } set(value) { underlyingHashValue = value } } - var underlyingHashValue: Int! - // MARK: - matches + //MARK: - matches var matchesCallsCount = 0 var matchesCalled: Bool { return matchesCallsCount > 0 } - var matchesReceivedOther: Any? var matchesReceivedInvocations: [Any] = [] var matchesReturnValue: Bool! @@ -163,18 +170,18 @@ class AnyTypeDescriptorMock: AnyTypeDescriptor { matchesCallsCount += 1 matchesReceivedOther = other matchesReceivedInvocations.append(other) - return matchesClosure.map { $0(other) } ?? matchesReturnValue + return matchesClosure.map({ $0(other) }) ?? matchesReturnValue } -} +} class BindingMock: Binding { - // MARK: - matches + + //MARK: - matches var matchesCallsCount = 0 var matchesCalled: Bool { return matchesCallsCount > 0 } - var matchesReceivedKey: AnyBindingKey? var matchesReceivedInvocations: [AnyBindingKey] = [] var matchesReturnValue: Bool! @@ -184,64 +191,61 @@ class BindingMock: Binding { matchesCallsCount += 1 matchesReceivedKey = key matchesReceivedInvocations.append(key) - return matchesClosure.map { $0(key) } ?? matchesReturnValue + return matchesClosure.map({ $0(key) }) ?? matchesReturnValue } - // MARK: - instance + //MARK: - instance - var instanceArgContextResolver3ThrowableError: Error? - var instanceArgContextResolver3CallsCount = 0 - var instanceArgContextResolver3Called: Bool { - return instanceArgContextResolver3CallsCount > 0 + var instanceArgContextResolverThrowableError: Error? + var instanceArgContextResolverCallsCount = 0 + var instanceArgContextResolverCalled: Bool { + return instanceArgContextResolverCallsCount > 0 } - - var instanceArgContextResolver3ReceivedArguments: (arg: Any, context: Any, resolver: Resolver3)? - var instanceArgContextResolver3ReceivedInvocations: [(arg: Any, context: Any, resolver: Resolver3)] = [] - var instanceArgContextResolver3ReturnValue: Any! - var instanceArgContextResolver3Closure: ((Any, Any, Resolver3) throws -> Any)? + var instanceArgContextResolverReceivedArguments: (arg: Any, context: Any, resolver: Resolver3)? + var instanceArgContextResolverReceivedInvocations: [(arg: Any, context: Any, resolver: Resolver3)] = [] + var instanceArgContextResolverReturnValue: Any! + var instanceArgContextResolverClosure: ((Any, Any, Resolver3) throws -> Any)? func instance(arg: Any, context: Any, resolver: Resolver3) throws -> Any { - if let error = instanceArgContextResolver3ThrowableError { + if let error = instanceArgContextResolverThrowableError { throw error } - instanceArgContextResolver3CallsCount += 1 - instanceArgContextResolver3ReceivedArguments = (arg: arg, context: context, resolver: resolver) - instanceArgContextResolver3ReceivedInvocations.append((arg: arg, context: context, resolver: resolver)) - return try instanceArgContextResolver3Closure.map { try $0(arg, context, resolver) } ?? instanceArgContextResolver3ReturnValue + instanceArgContextResolverCallsCount += 1 + instanceArgContextResolverReceivedArguments = (arg: arg, context: context, resolver: resolver) + instanceArgContextResolverReceivedInvocations.append((arg: arg, context: context, resolver: resolver)) + return try instanceArgContextResolverClosure.map({ try $0(arg, context, resolver) }) ?? instanceArgContextResolverReturnValue } -} +} class ClosableMock: Closable { - // MARK: - close + + //MARK: - close var closeCallsCount = 0 var closeCalled: Bool { return closeCallsCount > 0 } - var closeClosure: (() -> Void)? func close() { closeCallsCount += 1 closeClosure?() } -} +} class MatchableMock: Matchable { var hashValue: Int { get { return underlyingHashValue } set(value) { underlyingHashValue = value } } - var underlyingHashValue: Int! - // MARK: - matches + //MARK: - matches var matchesCallsCount = 0 var matchesCalled: Bool { return matchesCallsCount > 0 } - var matchesReceivedOther: Any? var matchesReceivedInvocations: [Any] = [] var matchesReturnValue: Bool! @@ -251,20 +255,21 @@ class MatchableMock: Matchable { matchesCallsCount += 1 matchesReceivedOther = other matchesReceivedInvocations.append(other) - return matchesClosure.map { $0(other) } ?? matchesReturnValue + return matchesClosure.map({ $0(other) }) ?? matchesReturnValue } -} -class ModuleIncludeEntryMock: ModuleIncludeEntry {} +} +class ModuleIncludeEntryMock: ModuleIncludeEntry { +} class StaticScopeRegistryMock: StaticScopeRegistry { - // MARK: - instance + + //MARK: - instance var instanceKeyCallsCount = 0 var instanceKeyCalled: Bool { return instanceKeyCallsCount > 0 } - var instanceKeyReceivedKey: ScopeRegistryKey? var instanceKeyReceivedInvocations: [ScopeRegistryKey] = [] var instanceKeyReturnValue: Any! @@ -274,20 +279,20 @@ class StaticScopeRegistryMock: StaticScopeRegistry { instanceKeyCallsCount += 1 instanceKeyReceivedKey = key instanceKeyReceivedInvocations.append(key) - return instanceKeyClosure.map { $0(key) } ?? instanceKeyReturnValue + return instanceKeyClosure.map({ $0(key) }) ?? instanceKeyReturnValue } - // MARK: - clear + //MARK: - clear var clearCallsCount = 0 var clearCalled: Bool { return clearCallsCount > 0 } - var clearClosure: (() -> Void)? func clear() { clearCallsCount += 1 clearClosure?() } + } diff --git a/Tests/Support/TestModels.swift b/Tests/Support/TestModels.swift index f778c870..a11cc969 100644 --- a/Tests/Support/TestModels.swift +++ b/Tests/Support/TestModels.swift @@ -2,14 +2,14 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -class Person { +class Human { var age = 0 var height = 0.0 var name = "" } struct Pet { - let owner: Person + let owner: Human } struct TestError: Error, Equatable {} diff --git a/Tests/Unit Specs/BinderEnvironmentSpec.swift b/Tests/Unit Specs/BinderEnvironmentSpec.swift index 0cc1d6fb..76bed4ef 100644 --- a/Tests/Unit Specs/BinderEnvironmentSpec.swift +++ b/Tests/Unit Specs/BinderEnvironmentSpec.swift @@ -45,7 +45,7 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { expect { try maker.makeInstance(resolver: DummyResolver3()) }.to(throwError()) } it("does not reuse instance") { - let maker = provider { Person() } + let maker = provider { Human() } let instance1 = try? maker.makeInstance(resolver: DummyResolver3()) let instance2 = try? maker.makeInstance(resolver: DummyResolver3()) expect(instance1) !== instance2 @@ -83,7 +83,7 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { expect { try maker.makeInstance(resolver: DummyResolver3()) }.to(throwError()) } it("does not reuse instance") { - let maker = factory { (_, _: Void) in Person() } + let maker = factory { (_, _: Void) in Human() } let instance1 = try? maker.makeInstance(resolver: DummyResolver3()) let instance2 = try? maker.makeInstance(resolver: DummyResolver3()) expect(instance1) !== instance2 @@ -137,7 +137,7 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { expect { try maker.makeInstance(resolver: DummyResolver3()) }.to(throwError()) } it("does not reuse instance") { - let maker = singleton { Person() } + let maker = singleton { Human() } let instance1 = try? maker.makeInstance(resolver: DummyResolver3()) let instance2 = try? maker.makeInstance(resolver: DummyResolver3()) expect(instance1) !== instance2 @@ -175,7 +175,7 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { expect { try maker.makeInstance(resolver: DummyResolver3()) }.to(throwError()) } it("does not reuse instance") { - let maker = multiton { (_, _: Void) in Person() } + let maker = multiton { (_, _: Void) in Human() } let instance1 = try? maker.makeInstance(resolver: DummyResolver3()) let instance2 = try? maker.makeInstance(resolver: DummyResolver3()) expect(instance1) !== instance2 @@ -237,7 +237,7 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { expect { try maker.makeInstance(resolver: DummyResolver3()) }.to(throwError()) } it("does not reuse instance") { - let maker = environment.provider { _, _ in Person() } + let maker = environment.provider { _, _ in Human() } let instance1 = try? maker.makeInstance(resolver: DummyResolver3()) let instance2 = try? maker.makeInstance(resolver: DummyResolver3()) expect(instance1) !== instance2 @@ -277,7 +277,7 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { expect { try maker.makeInstance(resolver: DummyResolver3()) }.to(throwError()) } it("does not reuse instance") { - let maker = environment.factory { (_, _, _: Void) in Person() } + let maker = environment.factory { (_, _, _: Void) in Human() } let instance1 = try? maker.makeInstance(resolver: DummyResolver3()) let instance2 = try? maker.makeInstance(resolver: DummyResolver3()) expect(instance1) !== instance2 @@ -345,7 +345,7 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { expect { try maker.makeInstance(resolver: DummyResolver3()) }.to(throwError()) } it("does not reuse instance") { - let maker = environment.singleton { _, _ in Person() } + let maker = environment.singleton { _, _ in Human() } let instance1 = try? maker.makeInstance(resolver: DummyResolver3()) let instance2 = try? maker.makeInstance(resolver: DummyResolver3()) expect(instance1) !== instance2 @@ -389,7 +389,7 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { expect { try maker.makeInstance(resolver: DummyResolver3()) }.to(throwError()) } it("does not reuse instance") { - let maker = environment.multiton { (_, _, _: Void) in Person() } + let maker = environment.multiton { (_, _, _: Void) in Human() } let instance1 = try? maker.makeInstance(resolver: DummyResolver3()) let instance2 = try? maker.makeInstance(resolver: DummyResolver3()) expect(instance1) !== instance2 diff --git a/Tests/Unit Specs/BindingKeySpec.swift b/Tests/Unit Specs/BindingKeySpec.swift index 91cdee6a..fcb3bdad 100644 --- a/Tests/Unit Specs/BindingKeySpec.swift +++ b/Tests/Unit Specs/BindingKeySpec.swift @@ -6,12 +6,11 @@ import Nimble import Quick @testable import Swinject -class BindingKeySpec: QuickSpec { - typealias AnyBindingKey = BindingKey - typealias ArgumentBindingKey = BindingKey - typealias ContextBindingKey = BindingKey +private typealias AnyBindingKey = BindingKey +private typealias ArgumentBindingKey = BindingKey +private typealias ContextBindingKey = BindingKey -override func spec() { +class BindingKeySpec: QuickSpec { override func spec() { describe("matching") { var key: AnyBindingKey! var descriptor = AnyTypeDescriptorMock() @@ -64,4 +63,5 @@ override func spec() { expect(key.matches(otherKey)).to(beTrue()) } } -} } +} +} diff --git a/Tests/Unit Specs/ScopedBindingSpec.swift b/Tests/Unit Specs/ScopedBindingSpec.swift index 12d36918..aff0b347 100644 --- a/Tests/Unit Specs/ScopedBindingSpec.swift +++ b/Tests/Unit Specs/ScopedBindingSpec.swift @@ -80,12 +80,12 @@ class ScopedBindingSpec: QuickSpec { override func spec() { scope.registryForReturnValue = BuilderScopeRegistry() } it("returns instance produced by maker") { - maker.makeInstanceArgContextResolver3ReturnValue = 42 + maker.makeInstanceArgContextResolverReturnValue = 42 let instance = try? binding.instance(arg: (), context: (), resolver: DummyResolver3()) as? Int expect(instance) == 42 } it("rethrows error from maker") { - maker.makeInstanceArgContextResolver3ThrowableError = TestError() + maker.makeInstanceArgContextResolverThrowableError = TestError() expect { try binding.instance(arg: (), context: (), resolver: DummyResolver3()) }.to(throwError(errorType: TestError.self)) @@ -93,9 +93,9 @@ class ScopedBindingSpec: QuickSpec { override func spec() { it("invokes maker with correct parameters") { let resolver = DummyResolver3() _ = try? binding.instance(arg: 42, context: "context", resolver: resolver) - expect(maker.makeInstanceArgContextResolver3ReceivedArguments?.arg as? Int) == 42 - expect(maker.makeInstanceArgContextResolver3ReceivedArguments?.context as? String) == "context" - expect(maker.makeInstanceArgContextResolver3ReceivedArguments?.resolver) === resolver + expect(maker.makeInstanceArgContextResolverReceivedArguments?.arg as? Int) == 42 + expect(maker.makeInstanceArgContextResolverReceivedArguments?.context as? String) == "context" + expect(maker.makeInstanceArgContextResolverReceivedArguments?.resolver) === resolver } } } diff --git a/Tests/Unit Specs/StandardScopeRegistrySpec.swift b/Tests/Unit Specs/StandardScopeRegistrySpec.swift index 2a87be18..cd8e834d 100644 --- a/Tests/Unit Specs/StandardScopeRegistrySpec.swift +++ b/Tests/Unit Specs/StandardScopeRegistrySpec.swift @@ -55,11 +55,11 @@ class StandardScopeRegistrySpec: QuickSpec { override func spec() { expect(closable[1].closeCallsCount) == 1 } it("releases instance references when cleared") { - var person: Person? = Person() - weak var weakRef = person - _ = registry.instance(for: key[0]) { person! } + var human: Human? = Human() + weak var weakRef = human + _ = registry.instance(for: key[0]) { human! } registry.clear() - person = nil + human = nil expect(weakRef).to(beNil()) } } @@ -76,11 +76,11 @@ class StandardScopeRegistrySpec: QuickSpec { override func spec() { expect(closable[1].closeCallsCount) == 1 } it("releases instance references when closed") { - var person: Person? = Person() - weak var weakRef = person - _ = registry.instance(for: key[0]) { person! } + var human: Human? = Human() + weak var weakRef = human + _ = registry.instance(for: key[0]) { human! } registry.close() - person = nil + human = nil expect(weakRef).to(beNil()) } } diff --git a/Tests/Unit Specs/SwinjectSpec.swift b/Tests/Unit Specs/SwinjectSpec.swift index 6aaba6a5..4a90187c 100644 --- a/Tests/Unit Specs/SwinjectSpec.swift +++ b/Tests/Unit Specs/SwinjectSpec.swift @@ -24,41 +24,41 @@ class SwinjectSpec: QuickSpec { override func spec() { it("request instance from matching binding") { binding.matchesReturnValue = true _ = try? swinject.instance(of: Any.self) - expect(binding.instanceArgContextResolver3CallsCount) == 1 + expect(binding.instanceArgContextResolverCallsCount) == 1 } it("does not request instance from matching binding until instance is required") { binding.matchesReturnValue = true - expect(binding.instanceArgContextResolver3CallsCount) == 0 + expect(binding.instanceArgContextResolverCallsCount) == 0 } it("only requests instance from matching binding") { binding.matchesReturnValue = false _ = try? swinject.instance(of: Any.self) - expect(binding.instanceArgContextResolver3CallsCount) == 0 + expect(binding.instanceArgContextResolverCallsCount) == 0 } it("returns instance produced by binding") { binding.matchesReturnValue = true - binding.instanceArgContextResolver3ReturnValue = 42 + binding.instanceArgContextResolverReturnValue = 42 expect { try swinject.instance(of: Any.self) as? Int } == 42 } it("rethrows error from binding") { binding.matchesReturnValue = true - binding.instanceArgContextResolver3ThrowableError = TestError() + binding.instanceArgContextResolverThrowableError = TestError() expect { try swinject.instance(of: Any.self) }.to(throwError(errorType: TestError.self)) } it("crashes if bound type does not match requested type") { binding.matchesReturnValue = true - binding.instanceArgContextResolver3ReturnValue = "" + binding.instanceArgContextResolverReturnValue = "" expect { _ = try swinject.instance(of: Double.self) }.to(throwError()) } it("does not crash if bound type conforms to the requested type") { binding.matchesReturnValue = true - binding.instanceArgContextResolver3ReturnValue = 42 + binding.instanceArgContextResolverReturnValue = 42 expect { _ = try swinject.instance(of: CustomStringConvertible?.self) }.notTo(throwError()) } it("passes swinject as resolver") { binding.matchesReturnValue = true _ = try? swinject.instance(of: Any.self) - expect(binding.instanceArgContextResolver3ReceivedArguments?.resolver is Swinject).to(beTrue()) + expect(binding.instanceArgContextResolverReceivedArguments?.resolver is Swinject).to(beTrue()) } it("matches binding with correct key") { binding.matchesReturnValue = false @@ -95,7 +95,7 @@ class SwinjectSpec: QuickSpec { override func spec() { } it("returns instance from matching binding") { bindings[1].matchesReturnValue = true - bindings[1].instanceArgContextResolver3ReturnValue = 42 + bindings[1].instanceArgContextResolverReturnValue = 42 expect { try swinject.instance(of: Int.self) } == 42 } } @@ -109,7 +109,7 @@ class SwinjectSpec: QuickSpec { override func spec() { } it("does not throw if binding matches provided type") { binding.matchesReturnValue = true - binding.instanceArgContextResolver3ReturnValue = 42 + binding.instanceArgContextResolverReturnValue = 42 let provider = swinject.provider() as () throws -> Int expect { try provider() }.notTo(throwError()) } @@ -120,19 +120,19 @@ class SwinjectSpec: QuickSpec { override func spec() { } it("does not request provided type until provider is called") { binding.matchesReturnValue = true - binding.instanceArgContextResolver3ReturnValue = 42 + binding.instanceArgContextResolverReturnValue = 42 _ = swinject.provider(of: Int.self) - expect(binding.instanceArgContextResolver3CallsCount) == 0 + expect(binding.instanceArgContextResolverCallsCount) == 0 } it("returns instance from binding") { binding.matchesReturnValue = true - binding.instanceArgContextResolver3ReturnValue = 42 + binding.instanceArgContextResolverReturnValue = 42 let provider = swinject.provider(of: Int.self) expect { try provider() } == 42 } it("rethrows binding error from provider") { binding.matchesReturnValue = true - binding.instanceArgContextResolver3ThrowableError = TestError() + binding.instanceArgContextResolverThrowableError = TestError() let provider = swinject.provider(of: Int.self) expect { try provider() }.to(throwError(errorType: TestError.self)) } @@ -151,7 +151,7 @@ class SwinjectSpec: QuickSpec { override func spec() { it("passes given context to the binding") { binding.matchesReturnValue = true _ = try? swinject.on("context").provider()() as Int - expect(binding.instanceArgContextResolver3ReceivedArguments?.context as? String) == "context" + expect(binding.instanceArgContextResolverReceivedArguments?.context as? String) == "context" } } describe("factory injection") { @@ -168,33 +168,33 @@ class SwinjectSpec: QuickSpec { override func spec() { } it("does not throw if binding matches created type") { binding.matchesReturnValue = true - binding.instanceArgContextResolver3ReturnValue = 42 + binding.instanceArgContextResolverReturnValue = 42 let factory = swinject.factory() as (String) throws -> Int expect { try factory("arg") }.notTo(throwError()) } it("does not request created type until factory is called") { binding.matchesReturnValue = true - binding.instanceArgContextResolver3ReturnValue = 42 + binding.instanceArgContextResolverReturnValue = 42 _ = swinject.factory() as (String) throws -> Int - expect(binding.instanceArgContextResolver3CallsCount) == 0 + expect(binding.instanceArgContextResolverCallsCount) == 0 } it("rethrows binding error from factory") { binding.matchesReturnValue = true - binding.instanceArgContextResolver3ThrowableError = TestError() + binding.instanceArgContextResolverThrowableError = TestError() let factory = swinject.factory() as (String) throws -> Int expect { try factory("arg") }.to(throwError(errorType: TestError.self)) } it("returns instance from binding") { binding.matchesReturnValue = true - binding.instanceArgContextResolver3ReturnValue = 42 + binding.instanceArgContextResolverReturnValue = 42 let factory = swinject.factory() as (String) throws -> Int expect { try factory("arg") } == 42 } it("passes given factory argument to binding") { binding.matchesReturnValue = true - binding.instanceArgContextResolver3ReturnValue = 42 + binding.instanceArgContextResolverReturnValue = 42 _ = try? swinject.factory(of: Int.self)("arg") - expect(binding.instanceArgContextResolver3ReceivedArguments?.arg as? String) == "arg" + expect(binding.instanceArgContextResolverReceivedArguments?.arg as? String) == "arg" } it("matches binding with correct key") { binding.matchesReturnValue = false @@ -211,42 +211,42 @@ class SwinjectSpec: QuickSpec { override func spec() { it("passes given context to the bidndning") { binding.matchesReturnValue = true _ = try? swinject.on("context").factory()("arg") as Int - expect(binding.instanceArgContextResolver3ReceivedArguments?.context as? String) == "context" + expect(binding.instanceArgContextResolverReceivedArguments?.context as? String) == "context" } context("currying") { beforeEach { binding.matchesReturnValue = true - binding.instanceArgContextResolver3ReturnValue = 42 + binding.instanceArgContextResolverReturnValue = 42 } it("can curry 2-tuple as 0 / 2 argument") { _ = try? swinject.factory()("arg1", "arg2") as Int - let receivedArg = binding.instanceArgContextResolver3ReceivedArguments?.arg as? (String, String) + let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? (String, String) expect(receivedArg?.0) == "arg1" expect(receivedArg?.1) == "arg2" } it("can curry 2-tuple as 1 / 1 argument") { _ = try? swinject.factory(arg: "arg1")("arg2") as Int - let receivedArg = binding.instanceArgContextResolver3ReceivedArguments?.arg as? (String, String) + let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? (String, String) expect(receivedArg?.0) == "arg1" expect(receivedArg?.1) == "arg2" } it("can curry 3-tuple as 0 / 3 argument") { _ = try? swinject.factory()("arg1", 2, "arg3") as Int - let receivedArg = binding.instanceArgContextResolver3ReceivedArguments?.arg as? (String, Int, String) + let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? (String, Int, String) expect(receivedArg?.0) == "arg1" expect(receivedArg?.1) == 2 expect(receivedArg?.2) == "arg3" } it("can curry 3-tuple as 1 / 2 argument") { _ = try? swinject.factory(arg: "arg1")(2, "arg3") as Int - let receivedArg = binding.instanceArgContextResolver3ReceivedArguments?.arg as? (String, Int, String) + let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? (String, Int, String) expect(receivedArg?.0) == "arg1" expect(receivedArg?.1) == 2 expect(receivedArg?.2) == "arg3" } it("can curry 3-tuple as 2 / 1 argument") { _ = try? swinject.factory(args: "arg1", 2)("arg3") as Int - let receivedArg = binding.instanceArgContextResolver3ReceivedArguments?.arg as? (String, Int, String) + let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? (String, Int, String) expect(receivedArg?.0) == "arg1" expect(receivedArg?.1) == 2 expect(receivedArg?.2) == "arg3" From 35924f3995c3a36b318726b52585ab768b39ba0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 21 Jul 2019 16:31:14 +0200 Subject: [PATCH 085/239] Add sourcery as prebuild step --- Swinject.xcodeproj/project.pbxproj | 76 ++++++++++++++++++++++++++++++ project.yml | 8 ++++ 2 files changed, 84 insertions(+) diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index b1b7c0ff..1ca3e2a1 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -940,6 +940,7 @@ isa = PBXNativeTarget; buildConfigurationList = 6A7DEE71EE3B4A20D5EE5AD1 /* Build configuration list for PBXNativeTarget "Swinject_tvOS" */; buildPhases = ( + 2AB7CE6B2DF8658C3EF1D9B5 /* Sourcery */, 585AA4C5E589D1DCBB7F94E5 /* Headers */, 15C9FE5CAD693ADAC2CE7497 /* Sources */, 66D6B3BD3D539FA0C7A9CCA0 /* Swiftlint */, @@ -958,6 +959,7 @@ isa = PBXNativeTarget; buildConfigurationList = 3F17B42C30F10C9E3DB4D9D5 /* Build configuration list for PBXNativeTarget "Swinject_iOS" */; buildPhases = ( + F50F3DCA9EE4390D69780A5D /* Sourcery */, 54CB4C9F1A52910358025C89 /* Headers */, 604EA45A8BA53D9420351811 /* Sources */, 0001F3C7499902D8D5EB3077 /* Swiftlint */, @@ -976,6 +978,7 @@ isa = PBXNativeTarget; buildConfigurationList = 412562B7F5B4B12A7597D10E /* Build configuration list for PBXNativeTarget "Swinject_macOS" */; buildPhases = ( + 8F89A051B21745D585F21607 /* Sourcery */, 02763B86C881518A9271575B /* Headers */, 01C827BE688B831820F3BF57 /* Sources */, 07B6CBBA986B903471B2C38A /* Swiftlint */, @@ -994,6 +997,7 @@ isa = PBXNativeTarget; buildConfigurationList = 9D50D1B060E4711513611A4B /* Build configuration list for PBXNativeTarget "Swinject_watchOS" */; buildPhases = ( + 8B38A2A8E5A9177159728F8A /* Sourcery */, E896EE40D53913BA1CD0CA02 /* Headers */, A40C67870E9515117AC87B4F /* Sources */, DF58753EC2B1D8F6A5679F10 /* Swiftlint */, @@ -1231,6 +1235,24 @@ shellPath = /bin/sh; shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n"; }; + 2AB7CE6B2DF8658C3EF1D9B5 /* Sourcery */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + name = Sourcery; + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "if which sourcery >/dev/null; then\n sourcery\nelse\n echo \"warning: Sourcery not installed, download from https://github.com/krzysztofzablocki/Sourcery\"\nfi\n"; + }; 66D6B3BD3D539FA0C7A9CCA0 /* Swiftlint */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; @@ -1249,6 +1271,42 @@ shellPath = /bin/sh; shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n"; }; + 8B38A2A8E5A9177159728F8A /* Sourcery */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + name = Sourcery; + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "if which sourcery >/dev/null; then\n sourcery\nelse\n echo \"warning: Sourcery not installed, download from https://github.com/krzysztofzablocki/Sourcery\"\nfi\n"; + }; + 8F89A051B21745D585F21607 /* Sourcery */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + name = Sourcery; + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "if which sourcery >/dev/null; then\n sourcery\nelse\n echo \"warning: Sourcery not installed, download from https://github.com/krzysztofzablocki/Sourcery\"\nfi\n"; + }; DF58753EC2B1D8F6A5679F10 /* Swiftlint */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; @@ -1267,6 +1325,24 @@ shellPath = /bin/sh; shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n"; }; + F50F3DCA9EE4390D69780A5D /* Sourcery */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + name = Sourcery; + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "if which sourcery >/dev/null; then\n sourcery\nelse\n echo \"warning: Sourcery not installed, download from https://github.com/krzysztofzablocki/Sourcery\"\nfi\n"; + }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ diff --git a/project.yml b/project.yml index f19dc9a8..35cfbe17 100644 --- a/project.yml +++ b/project.yml @@ -18,6 +18,14 @@ targets: sources: - path: Sources excludes: ["*.erb"] + preBuildScripts: + - script: > + if which sourcery >/dev/null; then + sourcery + else + echo "warning: Sourcery not installed, download from https://github.com/krzysztofzablocki/Sourcery" + fi + name: Sourcery postCompileScripts: - script: > if which swiftlint >/dev/null; then From f7fc672bace05c29f37558635b5f072c743207d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 21 Jul 2019 16:53:13 +0200 Subject: [PATCH 086/239] Remove redundant files --- Sources/2.0 API/UnavailableItems.swift | 22 ------- Swinject.xcodeproj/project.pbxproj | 82 -------------------------- project.yml | 2 +- 3 files changed, 1 insertion(+), 105 deletions(-) delete mode 100644 Sources/2.0 API/UnavailableItems.swift diff --git a/Sources/2.0 API/UnavailableItems.swift b/Sources/2.0 API/UnavailableItems.swift deleted file mode 100644 index f4c3536f..00000000 --- a/Sources/2.0 API/UnavailableItems.swift +++ /dev/null @@ -1,22 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -// MARK: For auto migration from Swinject v1 to v2. - -extension ObjectScope { - @available(*, unavailable, renamed: "transient") - public static let none = transient - - @available(*, unavailable, renamed: "container") - public static let hierarchy = container -} - -@available(*, unavailable, renamed: "Resolver") -public protocol ResolverType {} - -@available(*, unavailable, renamed: "Assembly") -public protocol AssemblyType {} - -@available(*, unavailable, renamed: "ServiceKeyOption") -public protocol ServiceKeyOptionType {} diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 1ca3e2a1..7f45256a 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -15,9 +15,7 @@ 01F001388FD754499B18FFAC /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */; }; 02CBAAF2DD5E7D589F997A27 /* SpinLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 919757437CA99D0C506EC028 /* SpinLock.swift */; }; 03005DC48E35AEF37251FADC /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; - 036C85135915C0847704947C /* ServiceEntry.TypeForwarding.erb in Resources */ = {isa = PBXBuildFile; fileRef = E6B3186E0AE372A6663F41E9 /* ServiceEntry.TypeForwarding.erb */; }; 03E7834C4448A5D939948CCF /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; - 03F8F4469A12ED907FBDABE9 /* Resolver.erb in Resources */ = {isa = PBXBuildFile; fileRef = B7DE2D7907C552B2C165E920 /* Resolver.erb */; }; 04C24C140F2D0BBFE48C682C /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; 050982D62AE0244372456440 /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92B8E618A08408404FB2A7A /* TypeBinder.swift */; }; 0516305FEAEA5A677A6FA9B3 /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; @@ -31,7 +29,6 @@ 0CB9E677FDF7CF424A738F34 /* Container.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C13D01A2DE6F53DF3175D22 /* Container.Arguments.swift */; }; 0CED31C429BA9F9B23EB2B1F /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42490D1D0C395951243F5CFF /* Container.swift */; }; 0CFCEE57963529ECA1FFD8C2 /* SynchronizedResolver.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 869CA0001EA621843F1EF2BB /* SynchronizedResolver.Arguments.swift */; }; - 0D44E3E0902E51A7B25E946C /* SynchronizedResolver.Arguments.erb in Resources */ = {isa = PBXBuildFile; fileRef = 7395512173A1439ED411B188 /* SynchronizedResolver.Arguments.erb */; }; 0D6143A7732F1334275D3658 /* UnboundScopeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 671D5D89472DAFA916814506 /* UnboundScopeSpec.swift */; }; 0DFB6FB4DF6A713EA545930F /* Container.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C2DBC728B763B04CB25963 /* Container.TypeForwarding.swift */; }; 0E465ECE9EC970161D607F7F /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EA7A547FC60DBD02D132B3E6 /* Swinject.framework */; }; @@ -58,7 +55,6 @@ 1ACC90951353E5F69899A833 /* SimpleBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */; }; 1AD4C43B074F736BBDADA8C9 /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; 1C2F5A09F986586F85FAC3E8 /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; - 1C8B304AAB75579AE100EDDF /* ServiceEntry.TypeForwarding.erb in Resources */ = {isa = PBXBuildFile; fileRef = E6B3186E0AE372A6663F41E9 /* ServiceEntry.TypeForwarding.erb */; }; 1CFCB38BC4EE2D3AAD40154E /* ScopedBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */; }; 1F256E6920935F88C753F739 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; 1F2E1C6B8F28C5441D52C033 /* ObjectScope.Standard.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD433AFA21FF52AF81A9C9B8 /* ObjectScope.Standard.swift */; }; @@ -80,13 +76,11 @@ 2CA05A2362E0390075908A32 /* BinderEnvironmentSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */; }; 2D1BB3EDEBEA06A17138B298 /* TaggedTypeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */; }; 2DCEEF373F410202226D2DB5 /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */; }; - 2E147955709F10BA7E36F657 /* Resolver.erb in Resources */ = {isa = PBXBuildFile; fileRef = B7DE2D7907C552B2C165E920 /* Resolver.erb */; }; 30BD96CC0333463C71377C4B /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; 31266C4BA7CE6C3FBAFBACDD /* Container.Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE4B1E4BA98573B6FED2D118 /* Container.Logging.swift */; }; 35175F8F168EDB5EB83BD8E9 /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C074BAC560F277E806146C60 /* SimpleBinding.swift */; }; 3547656EF55D129316B7C5E2 /* InstanceMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CADDB3E9E363310028AA5920 /* InstanceMaker.swift */; }; 35847FDC65085C6741D2A132 /* SimpleBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */; }; - 36F9E405E993FFF9FF7BAEA7 /* Container.Arguments.erb in Resources */ = {isa = PBXBuildFile; fileRef = 24C19DEC1E7BDED41182B68C /* Container.Arguments.erb */; }; 375945E6CD15BC4D5C8654C9 /* TaggedTypeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */; }; 377EE35B80E8F91543B52F0C /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; 37E07236E0E63570242CE23F /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; @@ -102,11 +96,9 @@ 3B61931D1E9C0F7D1AAEDDF7 /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92B8E618A08408404FB2A7A /* TypeBinder.swift */; }; 3DA1F1126FD1FC935353F847 /* ServiceKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45CA41659767E1378A9F492B /* ServiceKeySpec.swift */; }; 3E13E204659AF2DCE94D75CB /* ObjectScope.Standard.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD433AFA21FF52AF81A9C9B8 /* ObjectScope.Standard.swift */; }; - 3EF86AD69EBCED9EAAAA5CF4 /* Container.Arguments.erb in Resources */ = {isa = PBXBuildFile; fileRef = 24C19DEC1E7BDED41182B68C /* Container.Arguments.erb */; }; 3F04B9C7812B5E21DCE4D36C /* GeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */; }; 3F1FB19A735BE6E1FA749E75 /* SwinjectSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9527A4CA5BCBA7AFA3596757 /* SwinjectSpec.swift */; }; 3F8EA877F153EE374FF8E31A /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = A10187BB3A994165E7FC1528 /* ScopedBinding.swift */; }; - 3FCA6D47DF9FC0CDC62B8404 /* UnavailableItems.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDE0E0309FE888FE251632A6 /* UnavailableItems.swift */; }; 401A790CF8450924114D89ED /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BFF4BA99493C54260878C4 /* ObjectScope.swift */; }; 418F111C8E128766AC8E33CC /* Closable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D0BCCCD61CD9BECC29E064 /* Closable.swift */; }; 41EEA4724CD401F38F9622E3 /* InstanceMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CADDB3E9E363310028AA5920 /* InstanceMaker.swift */; }; @@ -129,11 +121,9 @@ 4C55A4A0FFA4E251DC482E20 /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */; }; 4C6D7AE29CB7E16431AACFA2 /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; 4C89DEC934923C4BBF6A3616 /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; - 4CAAE6389422432C6BE5008C /* UnavailableItems.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDE0E0309FE888FE251632A6 /* UnavailableItems.swift */; }; 4D0ABCA733720469F2240C31 /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */; }; 4D591BB725EAB0ACF9436900 /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 4DA000959B4D60B509859810 /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; - 4F10C414D344D3FF9212D51F /* UnavailableItems.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDE0E0309FE888FE251632A6 /* UnavailableItems.swift */; }; 509CD01E61B453F238D33973 /* ContainerSpec.DebugHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF340AF8DD2D821A225A36B3 /* ContainerSpec.DebugHelper.swift */; }; 50B230799AFB8C24D1F5CD5D /* SwinjectSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9527A4CA5BCBA7AFA3596757 /* SwinjectSpec.swift */; }; 51F2CD3C07148069167AB6E9 /* ServiceEntry.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03CDF95C1EAFCD54450B34B6 /* ServiceEntry.TypeForwarding.swift */; }; @@ -148,13 +138,11 @@ 5570E14A839D4065FFBA7EF4 /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCAF491EC7DCD7477F9A0ECB /* SwinjectModule.swift */; }; 564B886D2A35AF26FC411922 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; 572CA6A9E19927F5D434BB6F /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; - 576AE1D429E00A58A4A56591 /* SynchronizedResolver.Arguments.erb in Resources */ = {isa = PBXBuildFile; fileRef = 7395512173A1439ED411B188 /* SynchronizedResolver.Arguments.erb */; }; 588A600231D894122A4D9C47 /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; 58C9D537D453BC7C7DC5C0C1 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 359BCD3DA6F0CC2241878C82 /* EmploymentAssembly.swift */; }; 58CFFB8C98C465B9101AA9A8 /* InstanceMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CADDB3E9E363310028AA5920 /* InstanceMaker.swift */; }; 58F7BDE8BB54898CA690BD24 /* StandardScopeRegistrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */; }; 59E450454D5403C171E8CD20 /* ServiceEntrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2234FFBE7F556D1372AFB42D /* ServiceEntrySpec.swift */; }; - 5ADE98E33813B9287DE1FCE6 /* ServiceEntry.TypeForwarding.erb in Resources */ = {isa = PBXBuildFile; fileRef = E6B3186E0AE372A6663F41E9 /* ServiceEntry.TypeForwarding.erb */; }; 5B0ECCEBC6CB23571A9EDA38 /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */; }; 5BBBB5E7162B0429D7332DD4 /* SwinjectSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9527A4CA5BCBA7AFA3596757 /* SwinjectSpec.swift */; }; 5C06BD3982896046EAA70C8C /* WeakStorageSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DECE1C39517B81037CC0D53 /* WeakStorageSpec.swift */; }; @@ -169,7 +157,6 @@ 60467C140BE3C99C1B872A55 /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 823617F3B8A9192F56B13331 /* Quick.framework */; }; 60AF45155775AA5E97AAB5C1 /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEE8FDF4B975A8F2A9FCC5FF /* Food.swift */; }; 60CEB9FCA08EFF202DD38096 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1FA0377AF4799D42E9462FA /* BasicAssembly.swift */; }; - 610AC1395A7576F46E470411 /* SynchronizedResolver.Arguments.erb in Resources */ = {isa = PBXBuildFile; fileRef = 7395512173A1439ED411B188 /* SynchronizedResolver.Arguments.erb */; }; 61FA449BF10682C9E89E767F /* ObjectScope.Standard.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD433AFA21FF52AF81A9C9B8 /* ObjectScope.Standard.swift */; }; 627F366F03B0D6E549AAE98F /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ADD71387EBA54D7EF60D0089 /* Swinject.framework */; }; 62986D0AAAE9D3934E125332 /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; @@ -197,7 +184,6 @@ 7472B748AEA9F4D1E5EF9A70 /* Container.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C13D01A2DE6F53DF3175D22 /* Container.Arguments.swift */; }; 7480A500FEC04BB9CB048AE1 /* BinderEnvironmentSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */; }; 748FE5C55FB93BFFA9012CD3 /* SynchronizedResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4040F8D091ED67C84E2B8854 /* SynchronizedResolver.swift */; }; - 75645864A9295D669631750E /* SynchronizedResolver.Arguments.erb in Resources */ = {isa = PBXBuildFile; fileRef = 7395512173A1439ED411B188 /* SynchronizedResolver.Arguments.erb */; }; 76B3D9DBF8D5593F67A7B7E6 /* ContextedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4021EB1EA6A2770920FAD979 /* ContextedResolverSpec.swift */; }; 782801544D9F468F536E045E /* Container.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C2DBC728B763B04CB25963 /* Container.TypeForwarding.swift */; }; 7845113EAF8FFAFD5EC10540 /* BindingKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */; }; @@ -209,7 +195,6 @@ 7DD047C203659BCA7F04E48D /* Container.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C13D01A2DE6F53DF3175D22 /* Container.Arguments.swift */; }; 7E0539C5CD130F0AC4B02096 /* Container.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C13D01A2DE6F53DF3175D22 /* Container.Arguments.swift */; }; 7E9CB14F7E723994920F6E44 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 34AFFAC41BA9D02A38BDB7A3 /* Nimble.framework */; }; - 7EF126DA0473C0062F388D6D /* Resolver.erb in Resources */ = {isa = PBXBuildFile; fileRef = B7DE2D7907C552B2C165E920 /* Resolver.erb */; }; 7F22099B321798EAD85DBC07 /* Container.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C2DBC728B763B04CB25963 /* Container.TypeForwarding.swift */; }; 8108969F33C37040624E0D02 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07B4728F7C73CC5530956A2 /* Resolver.swift */; }; 816F47E9D87CAE910091B484 /* Closable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D0BCCCD61CD9BECC29E064 /* Closable.swift */; }; @@ -236,7 +221,6 @@ 8E9E1BD32B056F472DA14E51 /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1C58FC14EEA170B0DC079DE4 /* Quick.framework */; }; 8F48909C95AA648D056A392B /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; 8F70C49F6F6D27A67CDB8F0C /* TypeBinderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDA62EEBC79ED2639C93A76B /* TypeBinderSpec.swift */; }; - 900A130E222A2FE479D8D348 /* UnavailableItems.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDE0E0309FE888FE251632A6 /* UnavailableItems.swift */; }; 908AE547955AE4432C1D161A /* ServiceEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38615FC8EEB466C5C1EAD21C /* ServiceEntry.swift */; }; 90B4143005C86717AC76B6EE /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; 9102F98F672DD39F304AFC3B /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9985BEF966DCBB28B12BE17B /* Person.swift */; }; @@ -254,7 +238,6 @@ 963D32297EE5CA9C18A0C246 /* NonGeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841D83ADB41363D1E38087B4 /* NonGeneratedMocks.swift */; }; 971B97F191A9FF75A6586E0A /* ScopeRegistryKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */; }; 982E4682C79B74226C03E0C9 /* ServiceEntry.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03CDF95C1EAFCD54450B34B6 /* ServiceEntry.TypeForwarding.swift */; }; - 98C8EA8C215D9CC0940AE725 /* Container.Arguments.erb in Resources */ = {isa = PBXBuildFile; fileRef = 24C19DEC1E7BDED41182B68C /* Container.Arguments.erb */; }; 9A551D43739EDE556FF3F9ED /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBDB67E0FC7B8BEE58EECFBB /* BehaviorFakes.swift */; }; 9AFDF0122A11B2E996B16C3D /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; 9B04477B2B117122CB99989A /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1910A1471C3CA9EA86F350BA /* LoadAwareAssembly.swift */; }; @@ -299,7 +282,6 @@ B61FAC17826BAFD2DC1C0E5E /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; B753AC265ABCEF3CBCE3C4CE /* ServiceKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = D101B42AE242A5A00C319FAE /* ServiceKey.swift */; }; B7CE6F32765FC472CE205458 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; - B89CFD4B5A564B7EC2DFC62E /* ServiceEntry.TypeForwarding.erb in Resources */ = {isa = PBXBuildFile; fileRef = E6B3186E0AE372A6663F41E9 /* ServiceEntry.TypeForwarding.erb */; }; B95786317494375C0E2D2044 /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; B9FAEC69210B352FC744079E /* TypeBinderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDA62EEBC79ED2639C93A76B /* TypeBinderSpec.swift */; }; BAFD66351A9ED8E7BFB19CD3 /* NonGeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841D83ADB41363D1E38087B4 /* NonGeneratedMocks.swift */; }; @@ -311,7 +293,6 @@ C37B885879F0D716B36E1C5B /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 74DE57FB3E8228904E6FE0D7 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; C3AD37D47C38E5EB20FAF917 /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; C493D6AD1D8748A2698F0B81 /* ContainerSpec.DebugHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF340AF8DD2D821A225A36B3 /* ContainerSpec.DebugHelper.swift */; }; - C4C2C38793731903F172D88E /* Container.Arguments.erb in Resources */ = {isa = PBXBuildFile; fileRef = 24C19DEC1E7BDED41182B68C /* Container.Arguments.erb */; }; C50BFD826112288F1D693A30 /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; C5584C2C04564AFC0BCD3710 /* GraphIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E95633441FFB44D8A05585C /* GraphIdentifier.swift */; }; C6ED278B6F0E08A4B1E57C45 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; @@ -363,7 +344,6 @@ E423395FC7006DD82513F347 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; E484C3994AD91E91C454B11D /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; E584841CFD26155FB056C85A /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; - E63F31788438E1A43D480E84 /* Resolver.erb in Resources */ = {isa = PBXBuildFile; fileRef = B7DE2D7907C552B2C165E920 /* Resolver.erb */; }; E6E536A44F40492F42CA4044 /* ContainerSpec.DebugHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF340AF8DD2D821A225A36B3 /* ContainerSpec.DebugHelper.swift */; }; E7383E65C483ED1E66A49C5C /* InstanceStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06A8ED72CD6241A2CDEA8479 /* InstanceStorage.swift */; }; E7E9DE84E1861D125F8D686A /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07B4728F7C73CC5530956A2 /* Resolver.swift */; }; @@ -511,7 +491,6 @@ 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Behavior.swift; sourceTree = ""; }; 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Arguments.swift; sourceTree = ""; }; 2234FFBE7F556D1372AFB42D /* ServiceEntrySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServiceEntrySpec.swift; sourceTree = ""; }; - 24C19DEC1E7BDED41182B68C /* Container.Arguments.erb */ = {isa = PBXFileReference; path = Container.Arguments.erb; sourceTree = ""; }; 273FB7A6277E0841E1570990 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; 2902FD4C1A50263340A51FFB /* ScopeRegistryKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistryKeySpec.swift; sourceTree = ""; }; 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; @@ -548,7 +527,6 @@ 6C13D01A2DE6F53DF3175D22 /* Container.Arguments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.Arguments.swift; sourceTree = ""; }; 6EA4ECB5E4CEC9751AD36854 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 722CAC1761180366DE75A4A6 /* TestModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestModels.swift; sourceTree = ""; }; - 7395512173A1439ED411B188 /* SynchronizedResolver.Arguments.erb */ = {isa = PBXFileReference; path = SynchronizedResolver.Arguments.erb; sourceTree = ""; }; 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.CustomStringConvertible.swift; sourceTree = ""; }; 74DE57FB3E8228904E6FE0D7 /* Swinject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Swinject.h; sourceTree = ""; }; 7BA261FF01C5F5510873B3EC /* Animal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Animal.swift; sourceTree = ""; }; @@ -572,12 +550,10 @@ ADC44E9312C3B974AFD8F07B /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; ADD71387EBA54D7EF60D0089 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AssemblerSpec.swift; sourceTree = ""; }; - B7DE2D7907C552B2C165E920 /* Resolver.erb */ = {isa = PBXFileReference; path = Resolver.erb; sourceTree = ""; }; B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderEnvironment.swift; sourceTree = ""; }; B92B8E618A08408404FB2A7A /* TypeBinder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinder.swift; sourceTree = ""; }; BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StandardScopeRegistrySpec.swift; sourceTree = ""; }; BBDB67E0FC7B8BEE58EECFBB /* BehaviorFakes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BehaviorFakes.swift; sourceTree = ""; }; - BDE0E0309FE888FE251632A6 /* UnavailableItems.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnavailableItems.swift; sourceTree = ""; }; BE4B1E4BA98573B6FED2D118 /* Container.Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.Logging.swift; sourceTree = ""; }; BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Behavior.swift; sourceTree = ""; }; C074BAC560F277E806146C60 /* SimpleBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleBinding.swift; sourceTree = ""; }; @@ -592,7 +568,6 @@ DF340AF8DD2D821A225A36B3 /* ContainerSpec.DebugHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.DebugHelper.swift; sourceTree = ""; }; E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRequest.swift; sourceTree = ""; }; E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; - E6B3186E0AE372A6663F41E9 /* ServiceEntry.TypeForwarding.erb */ = {isa = PBXFileReference; path = ServiceEntry.TypeForwarding.erb; sourceTree = ""; }; EA7A547FC60DBD02D132B3E6 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; EBA3EF319F06A1B3B6C84C29 /* ContextedResolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextedResolver.swift; sourceTree = ""; }; ECE2B2EFBFDA910758EE1CA5 /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -717,7 +692,6 @@ 59111BE319C59E4CD6CF68CD /* Assembler.swift */, F290F6B1207A0557A528220B /* Assembly.swift */, 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */, - 24C19DEC1E7BDED41182B68C /* Container.Arguments.erb */, 6C13D01A2DE6F53DF3175D22 /* Container.Arguments.swift */, BE4B1E4BA98573B6FED2D118 /* Container.Logging.swift */, 42490D1D0C395951243F5CFF /* Container.swift */, @@ -729,17 +703,13 @@ 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */, FD433AFA21FF52AF81A9C9B8 /* ObjectScope.Standard.swift */, 36BFF4BA99493C54260878C4 /* ObjectScope.swift */, - B7DE2D7907C552B2C165E920 /* Resolver.erb */, C07B4728F7C73CC5530956A2 /* Resolver.swift */, 38615FC8EEB466C5C1EAD21C /* ServiceEntry.swift */, - E6B3186E0AE372A6663F41E9 /* ServiceEntry.TypeForwarding.erb */, 03CDF95C1EAFCD54450B34B6 /* ServiceEntry.TypeForwarding.swift */, D101B42AE242A5A00C319FAE /* ServiceKey.swift */, 919757437CA99D0C506EC028 /* SpinLock.swift */, - 7395512173A1439ED411B188 /* SynchronizedResolver.Arguments.erb */, 869CA0001EA621843F1EF2BB /* SynchronizedResolver.Arguments.swift */, 4040F8D091ED67C84E2B8854 /* SynchronizedResolver.swift */, - BDE0E0309FE888FE251632A6 /* UnavailableItems.swift */, ); path = "2.0 API"; sourceTree = ""; @@ -944,7 +914,6 @@ 585AA4C5E589D1DCBB7F94E5 /* Headers */, 15C9FE5CAD693ADAC2CE7497 /* Sources */, 66D6B3BD3D539FA0C7A9CCA0 /* Swiftlint */, - D245CDD8138FA4393DF16F89 /* Resources */, ); buildRules = ( ); @@ -963,7 +932,6 @@ 54CB4C9F1A52910358025C89 /* Headers */, 604EA45A8BA53D9420351811 /* Sources */, 0001F3C7499902D8D5EB3077 /* Swiftlint */, - E9EF3170DCCA3B360FDA5671 /* Resources */, ); buildRules = ( ); @@ -982,7 +950,6 @@ 02763B86C881518A9271575B /* Headers */, 01C827BE688B831820F3BF57 /* Sources */, 07B6CBBA986B903471B2C38A /* Swiftlint */, - C95D6FDA3B52AAE89B739A57 /* Resources */, ); buildRules = ( ); @@ -1001,7 +968,6 @@ E896EE40D53913BA1CD0CA02 /* Headers */, A40C67870E9515117AC87B4F /* Sources */, DF58753EC2B1D8F6A5679F10 /* Swiftlint */, - 78E2087E6ED9E88E480F72BD /* Resources */, ); buildRules = ( ); @@ -1136,17 +1102,6 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - 78E2087E6ED9E88E480F72BD /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 36F9E405E993FFF9FF7BAEA7 /* Container.Arguments.erb in Resources */, - 2E147955709F10BA7E36F657 /* Resolver.erb in Resources */, - 5ADE98E33813B9287DE1FCE6 /* ServiceEntry.TypeForwarding.erb in Resources */, - 610AC1395A7576F46E470411 /* SynchronizedResolver.Arguments.erb in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; 7A529E244C2531EA2E24DAFC /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -1155,28 +1110,6 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - C95D6FDA3B52AAE89B739A57 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 98C8EA8C215D9CC0940AE725 /* Container.Arguments.erb in Resources */, - E63F31788438E1A43D480E84 /* Resolver.erb in Resources */, - 036C85135915C0847704947C /* ServiceEntry.TypeForwarding.erb in Resources */, - 576AE1D429E00A58A4A56591 /* SynchronizedResolver.Arguments.erb in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - D245CDD8138FA4393DF16F89 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 3EF86AD69EBCED9EAAAA5CF4 /* Container.Arguments.erb in Resources */, - 03F8F4469A12ED907FBDABE9 /* Resolver.erb in Resources */, - 1C8B304AAB75579AE100EDDF /* ServiceEntry.TypeForwarding.erb in Resources */, - 0D44E3E0902E51A7B25E946C /* SynchronizedResolver.Arguments.erb in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; D5F9594040A6B7CB9B7F97CA /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -1185,17 +1118,6 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - E9EF3170DCCA3B360FDA5671 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - C4C2C38793731903F172D88E /* Container.Arguments.erb in Resources */, - 7EF126DA0473C0062F388D6D /* Resolver.erb in Resources */, - B89CFD4B5A564B7EC2DFC62E /* ServiceEntry.TypeForwarding.erb in Resources */, - 75645864A9295D669631750E /* SynchronizedResolver.Arguments.erb in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ @@ -1393,7 +1315,6 @@ ED346CAABC0FF77612D9E186 /* SynchronizedResolver.swift in Sources */, 3B61931D1E9C0F7D1AAEDDF7 /* TypeBinder.swift in Sources */, 62986D0AAAE9D3934E125332 /* TypeDescriptor.swift in Sources */, - 900A130E222A2FE479D8D348 /* UnavailableItems.swift in Sources */, 39D7CF8F5563E3C1BDDEED93 /* _Resolver.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1543,7 +1464,6 @@ D7C2A6D05BD948EA1E3B26FB /* SynchronizedResolver.swift in Sources */, 5D2C492FD5088FCB2BA5CDB8 /* TypeBinder.swift in Sources */, 03005DC48E35AEF37251FADC /* TypeDescriptor.swift in Sources */, - 3FCA6D47DF9FC0CDC62B8404 /* UnavailableItems.swift in Sources */, 5541D9BB4DF2EBB3E7325359 /* _Resolver.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1693,7 +1613,6 @@ 9C81098E44AF728D63640DA1 /* SynchronizedResolver.swift in Sources */, 050982D62AE0244372456440 /* TypeBinder.swift in Sources */, 572CA6A9E19927F5D434BB6F /* TypeDescriptor.swift in Sources */, - 4F10C414D344D3FF9212D51F /* UnavailableItems.swift in Sources */, D0F428B5C92CA0C25EF4BE61 /* _Resolver.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1745,7 +1664,6 @@ 748FE5C55FB93BFFA9012CD3 /* SynchronizedResolver.swift in Sources */, D88D7841C5C84A2E34CE15FD /* TypeBinder.swift in Sources */, B95786317494375C0E2D2044 /* TypeDescriptor.swift in Sources */, - 4CAAE6389422432C6BE5008C /* UnavailableItems.swift in Sources */, CE62237127502CCD13CC22C2 /* _Resolver.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/project.yml b/project.yml index 35cfbe17..798c8e71 100644 --- a/project.yml +++ b/project.yml @@ -17,7 +17,7 @@ targets: - SwinjectTests_${platform} sources: - path: Sources - excludes: ["*.erb"] + excludes: ["**/*.erb"] preBuildScripts: - script: > if which sourcery >/dev/null; then From fbb6a2f2249ce36d60cf4fb148fe31aaf3f41a00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 21 Jul 2019 17:41:47 +0200 Subject: [PATCH 087/239] Enable instance finalization within scope registry --- Sources/Core/ScopeRegistry.swift | 27 ++++++++---- Tests/Support/NonGeneratedMocks.swift | 8 +++- .../StandardScopeRegistrySpec.swift | 42 +++++++++++++++++++ 3 files changed, 66 insertions(+), 11 deletions(-) diff --git a/Sources/Core/ScopeRegistry.swift b/Sources/Core/ScopeRegistry.swift index e5da7532..0852dff7 100644 --- a/Sources/Core/ScopeRegistry.swift +++ b/Sources/Core/ScopeRegistry.swift @@ -5,25 +5,34 @@ import Foundation public protocol ScopeRegistry { - func instance(for key: ScopeRegistryKey, builder: () throws -> Any) rethrows -> Any + func instance(for key: ScopeRegistryKey, builder: () throws -> Any, finalizer: (Any) throws -> Void) rethrows -> Any func clear() } +extension ScopeRegistry { + func instance(for key: ScopeRegistryKey, builder: () throws -> Any) rethrows -> Any { + try instance(for: key, builder: builder, finalizer: { _ in }) + } +} + public class StandardScopeRegistry: ScopeRegistry, Closable { private let lock = NSRecursiveLock() private var instances = [ScopeRegistryKey: Any]() public init() {} - public func instance(for key: ScopeRegistryKey, builder: () throws -> Any) rethrows -> Any { + public func instance( + for key: ScopeRegistryKey, + builder: () throws -> Any, + finalizer: (Any) throws -> Void + ) rethrows -> Any { try lock.sync { - if let instance = instances[key] { - return instance - } else { - let newInstance = try builder() - instances[key] = newInstance - return newInstance - } + if let instance = instances[key] { return instance } + let newInstance = try builder() + try finalizer(newInstance) + if let instance = instances[key] { return instance } + instances[key] = newInstance + return newInstance } } diff --git a/Tests/Support/NonGeneratedMocks.swift b/Tests/Support/NonGeneratedMocks.swift index b3ade40e..ac5bff12 100644 --- a/Tests/Support/NonGeneratedMocks.swift +++ b/Tests/Support/NonGeneratedMocks.swift @@ -67,13 +67,17 @@ protocol StaticScopeRegistry { } extension StaticScopeRegistryMock: ScopeRegistry { - func instance(for key: ScopeRegistryKey, builder _: () throws -> Any) rethrows -> Any { + func instance( + for key: ScopeRegistryKey, + builder _: () throws -> Any, + finalizer: (Any) throws -> Void + ) rethrows -> Any { instance(key: key) } } struct BuilderScopeRegistry: ScopeRegistry { - func instance(for _: ScopeRegistryKey, builder: () throws -> Any) rethrows -> Any { + func instance(for _: ScopeRegistryKey, builder: () throws -> Any, finalizer: (Any) throws -> Void) rethrows -> Any { try builder() } diff --git a/Tests/Unit Specs/StandardScopeRegistrySpec.swift b/Tests/Unit Specs/StandardScopeRegistrySpec.swift index cd8e834d..811ba159 100644 --- a/Tests/Unit Specs/StandardScopeRegistrySpec.swift +++ b/Tests/Unit Specs/StandardScopeRegistrySpec.swift @@ -16,9 +16,12 @@ class StandardScopeRegistrySpec: QuickSpec { override func spec() { } describe("instance") { var builderCallCount = 0 + var finalizerCallCount = 0 let countingBuilder: () -> Any = { builderCallCount += 1; return 0 } + let countingFinalizer: (Any) -> Void = { _ in finalizerCallCount += 1 } beforeEach { builderCallCount = 0 + finalizerCallCount = 0 } it("calls builder on first invocation for key") { _ = registry.instance(for: key[0], builder: countingBuilder) @@ -45,6 +48,35 @@ class StandardScopeRegistrySpec: QuickSpec { override func spec() { expect(registry.instance(for: key[0]) { 0 } as? Int) == 42 expect(registry.instance(for: key[1]) { 0 } as? Int) == 25 } + it("calls finalizer on first invocation for key") { + _ = registry.instance(for: key[0], builder: { 0 }, finalizer: countingFinalizer) + expect(finalizerCallCount) == 1 + } + it("rethrows error from finalizer") { + expect { + try registry.instance(for: key[0], builder: { 0 }, finalizer: { _ in throw TestError() }) + }.to(throwError(errorType: TestError.self)) + } + it("calls finalizer with instance from builder") { + var instance: Any? + _ = registry.instance(for: key[0], builder: { 42 }, finalizer: { instance = $0 }) + expect(instance as? Int) == 42 + } + it("only calls finalizer on first invocation for each key") { + _ = registry.instance(for: key[0], builder: { 0 }, finalizer: countingFinalizer) + _ = registry.instance(for: key[1], builder: { 0 }, finalizer: countingFinalizer) + _ = registry.instance(for: key[0], builder: { 0 }, finalizer: countingFinalizer) + _ = registry.instance(for: key[1], builder: { 0 }, finalizer: countingFinalizer) + expect(finalizerCallCount) == 2 + } + it("returns the last instance if the same key was used during finalization") { + let instance = registry.instance( + for: key[0], + builder: { 0 }, + finalizer: { _ in _ = registry.instance(for: key[0], builder: { 42 }) } + ) + expect(instance as? Int) == 42 + } } describe("clear") { it("closes instances when cleared") { @@ -112,5 +144,15 @@ class StandardScopeRegistrySpec: QuickSpec { override func spec() { concurrentPerform(iterations: 5, action: registry.close) expect(closable.closeCallsCount) == 1 } + it("does not deadlock if invoked inside builder") { + waitUntil { done in + DispatchQueue.global(qos: .background).async { + _ = registry.instance(for: key[0]) { + registry.instance(for: key[1]) { 42 } + } + done() + } + } + } } } } From 0608220f4fad317b45691839dda588c37b5e015b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 21 Jul 2019 18:30:56 +0200 Subject: [PATCH 088/239] Remove Implementations of 2.0 API --- Sources/2.0 API/Assembler.swift | 24 -- Sources/2.0 API/Container.Arguments.swift | 63 ++--- .../2.0 API/Container.TypeForwarding.swift | 9 +- Sources/2.0 API/Container.swift | 232 +----------------- Sources/2.0 API/DebugHelper.swift | 50 ---- Sources/2.0 API/FunctionType.swift | 6 - Sources/2.0 API/GraphIdentifier.swift | 16 -- Sources/2.0 API/InstanceStorage.swift | 130 ---------- Sources/2.0 API/InstanceWrapper.swift | 60 +---- Sources/2.0 API/ObjectScope.Standard.swift | 22 -- Sources/2.0 API/ObjectScope.swift | 45 +--- .../2.0 API/ServiceEntry.TypeForwarding.swift | 1 - Sources/2.0 API/ServiceEntry.swift | 66 +---- Sources/2.0 API/ServiceKey.swift | 61 ----- Sources/2.0 API/SpinLock.swift | 15 -- .../SynchronizedResolver.Arguments.swift | 186 -------------- Sources/2.0 API/SynchronizedResolver.swift | 38 --- Sources/2.0 API/_Resolver.swift | 24 -- Sources/Core/TypeDescriptor.swift | 4 +- Swinject.xcodeproj/project.pbxproj | 200 ++++++--------- 20 files changed, 136 insertions(+), 1116 deletions(-) delete mode 100644 Sources/2.0 API/DebugHelper.swift delete mode 100644 Sources/2.0 API/FunctionType.swift delete mode 100644 Sources/2.0 API/GraphIdentifier.swift delete mode 100644 Sources/2.0 API/InstanceStorage.swift delete mode 100644 Sources/2.0 API/ObjectScope.Standard.swift delete mode 100644 Sources/2.0 API/ServiceKey.swift delete mode 100644 Sources/2.0 API/SpinLock.swift delete mode 100644 Sources/2.0 API/SynchronizedResolver.Arguments.swift delete mode 100644 Sources/2.0 API/SynchronizedResolver.swift delete mode 100644 Sources/2.0 API/_Resolver.swift diff --git a/Sources/2.0 API/Assembler.swift b/Sources/2.0 API/Assembler.swift index 77929fb0..a680c1c0 100644 --- a/Sources/2.0 API/Assembler.swift +++ b/Sources/2.0 API/Assembler.swift @@ -33,20 +33,6 @@ public final class Assembler { ) } - /// Will create a new `Assembler` with the given `Assembly` instances to build a `Container` - /// - /// - parameter assemblies: the list of assemblies to build the container from - /// - parameter container: the baseline container - /// - @available(*, deprecated, message: "Use not throwing alternative: init(_:, container:)") - public convenience init(assemblies: [Assembly], container: Container? = Container()) throws { - if let container = container { - self.init(assemblies, container: container) - } else { - self.init(assemblies) - } - } - /// Will create a new `Assembler` with the given `Assembly` instances to build a `Container` /// /// - parameter assemblies: the list of assemblies to build the container from @@ -57,16 +43,6 @@ public final class Assembler { run(assemblies: assemblies) } - /// Will create a new `Assembler` with the given `Assembly` instances to build a `Container` - /// - /// - parameter assemblies: the list of assemblies to build the container from - /// - parameter parentAssembler: the baseline assembler - /// - @available(*, deprecated, message: "Use not throwing alternative: init(_:, parent:)") - public convenience init(assemblies: [Assembly], parentAssembler: Assembler?) throws { - self.init(_: assemblies, parent: parentAssembler) - } - /// Will create a new `Assembler` with the given `Assembly` instances to build a `Container` /// /// - parameter assemblies: the list of assemblies to build the container from diff --git a/Sources/2.0 API/Container.Arguments.swift b/Sources/2.0 API/Container.Arguments.swift index fe2cb0c6..db9963f5 100644 --- a/Sources/2.0 API/Container.Arguments.swift +++ b/Sources/2.0 API/Container.Arguments.swift @@ -33,7 +33,7 @@ extension Container { name: String? = nil, factory: @escaping (Resolver, Arg1) -> Service ) -> ServiceEntry { - return _register(serviceType, factory: factory, name: name) + fatalError() } /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. @@ -54,7 +54,7 @@ extension Container { name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2) -> Service ) -> ServiceEntry { - return _register(serviceType, factory: factory, name: name) + fatalError() } /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. @@ -75,7 +75,7 @@ extension Container { name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3) -> Service ) -> ServiceEntry { - return _register(serviceType, factory: factory, name: name) + fatalError() } /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. @@ -96,7 +96,7 @@ extension Container { name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) -> Service ) -> ServiceEntry { - return _register(serviceType, factory: factory, name: name) + fatalError() } /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. @@ -117,7 +117,7 @@ extension Container { name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) -> Service ) -> ServiceEntry { - return _register(serviceType, factory: factory, name: name) + fatalError() } /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. @@ -138,7 +138,7 @@ extension Container { name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6) -> Service ) -> ServiceEntry { - return _register(serviceType, factory: factory, name: name) + fatalError() } /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. @@ -159,7 +159,7 @@ extension Container { name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7) -> Service ) -> ServiceEntry { - return _register(serviceType, factory: factory, name: name) + fatalError() } /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. @@ -180,7 +180,7 @@ extension Container { name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8) -> Service ) -> ServiceEntry { - return _register(serviceType, factory: factory, name: name) + fatalError() } /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. @@ -201,7 +201,7 @@ extension Container { name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9) -> Service ) -> ServiceEntry { - return _register(serviceType, factory: factory, name: name) + fatalError() } } @@ -220,7 +220,7 @@ extension Container { _ serviceType: Service.Type, argument: Arg1 ) -> Service? { - return resolve(serviceType, name: nil, argument: argument) + fatalError() } /// Retrieves the instance with the specified service type, 1 argument to the factory closure and registration name. @@ -237,8 +237,7 @@ extension Container { name: String?, argument: Arg1 ) -> Service? { - typealias FactoryType = ((Resolver, Arg1)) -> Any - return _resolve(name: name) { (factory: FactoryType) in factory((self, argument)) } + fatalError() } /// Retrieves the instance with the specified service type and list of 2 arguments to the factory closure. @@ -253,7 +252,7 @@ extension Container { _ serviceType: Service.Type, arguments arg1: Arg1, _ arg2: Arg2 ) -> Service? { - return resolve(serviceType, name: nil, arguments: arg1, arg2) + fatalError() } /// Retrieves the instance with the specified service type, list of 2 arguments to the factory closure and registration name. @@ -270,8 +269,7 @@ extension Container { name: String?, arguments arg1: Arg1, _ arg2: Arg2 ) -> Service? { - typealias FactoryType = ((Resolver, Arg1, Arg2)) -> Any - return _resolve(name: name) { (factory: FactoryType) in factory((self, arg1, arg2)) } + fatalError() } /// Retrieves the instance with the specified service type and list of 3 arguments to the factory closure. @@ -286,7 +284,7 @@ extension Container { _ serviceType: Service.Type, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3 ) -> Service? { - return resolve(serviceType, name: nil, arguments: arg1, arg2, arg3) + fatalError() } /// Retrieves the instance with the specified service type, list of 3 arguments to the factory closure and registration name. @@ -303,8 +301,7 @@ extension Container { name: String?, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3 ) -> Service? { - typealias FactoryType = ((Resolver, Arg1, Arg2, Arg3)) -> Any - return _resolve(name: name) { (factory: FactoryType) in factory((self, arg1, arg2, arg3)) } + fatalError() } /// Retrieves the instance with the specified service type and list of 4 arguments to the factory closure. @@ -319,7 +316,7 @@ extension Container { _ serviceType: Service.Type, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4 ) -> Service? { - return resolve(serviceType, name: nil, arguments: arg1, arg2, arg3, arg4) + fatalError() } /// Retrieves the instance with the specified service type, list of 4 arguments to the factory closure and registration name. @@ -336,8 +333,7 @@ extension Container { name: String?, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4 ) -> Service? { - typealias FactoryType = ((Resolver, Arg1, Arg2, Arg3, Arg4)) -> Any - return _resolve(name: name) { (factory: FactoryType) in factory((self, arg1, arg2, arg3, arg4)) } + fatalError() } /// Retrieves the instance with the specified service type and list of 5 arguments to the factory closure. @@ -352,7 +348,7 @@ extension Container { _ serviceType: Service.Type, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5 ) -> Service? { - return resolve(serviceType, name: nil, arguments: arg1, arg2, arg3, arg4, arg5) + fatalError() } /// Retrieves the instance with the specified service type, list of 5 arguments to the factory closure and registration name. @@ -369,8 +365,7 @@ extension Container { name: String?, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5 ) -> Service? { - typealias FactoryType = ((Resolver, Arg1, Arg2, Arg3, Arg4, Arg5)) -> Any - return _resolve(name: name) { (factory: FactoryType) in factory((self, arg1, arg2, arg3, arg4, arg5)) } + fatalError() } /// Retrieves the instance with the specified service type and list of 6 arguments to the factory closure. @@ -385,7 +380,7 @@ extension Container { _ serviceType: Service.Type, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6 ) -> Service? { - return resolve(serviceType, name: nil, arguments: arg1, arg2, arg3, arg4, arg5, arg6) + fatalError() } /// Retrieves the instance with the specified service type, list of 6 arguments to the factory closure and registration name. @@ -402,8 +397,7 @@ extension Container { name: String?, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6 ) -> Service? { - typealias FactoryType = ((Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6)) -> Any - return _resolve(name: name) { (factory: FactoryType) in factory((self, arg1, arg2, arg3, arg4, arg5, arg6)) } + fatalError() } /// Retrieves the instance with the specified service type and list of 7 arguments to the factory closure. @@ -418,7 +412,7 @@ extension Container { _ serviceType: Service.Type, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7 ) -> Service? { - return resolve(serviceType, name: nil, arguments: arg1, arg2, arg3, arg4, arg5, arg6, arg7) + fatalError() } /// Retrieves the instance with the specified service type, list of 7 arguments to the factory closure and registration name. @@ -435,8 +429,7 @@ extension Container { name: String?, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7 ) -> Service? { - typealias FactoryType = ((Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7)) -> Any - return _resolve(name: name) { (factory: FactoryType) in factory((self, arg1, arg2, arg3, arg4, arg5, arg6, arg7)) } + fatalError() } /// Retrieves the instance with the specified service type and list of 8 arguments to the factory closure. @@ -451,7 +444,7 @@ extension Container { _ serviceType: Service.Type, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8 ) -> Service? { - return resolve(serviceType, name: nil, arguments: arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) + fatalError() } /// Retrieves the instance with the specified service type, list of 8 arguments to the factory closure and registration name. @@ -468,8 +461,7 @@ extension Container { name: String?, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8 ) -> Service? { - typealias FactoryType = ((Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8)) -> Any - return _resolve(name: name) { (factory: FactoryType) in factory((self, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)) } + fatalError() } /// Retrieves the instance with the specified service type and list of 9 arguments to the factory closure. @@ -484,7 +476,7 @@ extension Container { _ serviceType: Service.Type, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8, _ arg9: Arg9 ) -> Service? { - return resolve(serviceType, name: nil, arguments: arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) + fatalError() } /// Retrieves the instance with the specified service type, list of 9 arguments to the factory closure and registration name. @@ -501,7 +493,6 @@ extension Container { name: String?, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8, _ arg9: Arg9 ) -> Service? { - typealias FactoryType = ((Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9)) -> Any - return _resolve(name: name) { (factory: FactoryType) in factory((self, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)) } + fatalError() } } diff --git a/Sources/2.0 API/Container.TypeForwarding.swift b/Sources/2.0 API/Container.TypeForwarding.swift index 14813891..73e1c2a9 100644 --- a/Sources/2.0 API/Container.TypeForwarding.swift +++ b/Sources/2.0 API/Container.TypeForwarding.swift @@ -19,13 +19,6 @@ extension Container { /// - name: A registration name, which is used to differentiate from other registrations of the same `type` /// - service: ServiceEntry which should be used for resolution of `type` public func forward(_ type: T.Type, name: String? = nil, to service: ServiceEntry) { - let key = ServiceKey( - serviceType: T.self, - argumentsType: service.argumentsType, - name: name, - option: nil - ) - services[key] = service - behaviors.forEach { $0.container(self, didRegisterType: type, toService: service, withName: name) } + fatalError() } } diff --git a/Sources/2.0 API/Container.swift b/Sources/2.0 API/Container.swift index 0e4a6194..b187a263 100644 --- a/Sources/2.0 API/Container.swift +++ b/Sources/2.0 API/Container.swift @@ -20,26 +20,6 @@ import Foundation /// where `A` and `X` are protocols, `B` is a type conforming `A`, and `Y` is a type conforming `X` /// and depending on `A`. public final class Container { - internal var services = [ServiceKey: ServiceEntryProtocol]() - private let parent: Container? // Used by HierarchyObjectScope - private var resolutionDepth = 0 - private let debugHelper: DebugHelper - private let defaultObjectScope: ObjectScope - internal var currentObjectGraph: GraphIdentifier? - internal let lock: SpinLock // Used by SynchronizedResolver. - internal var behaviors = [Behavior]() - - internal init( - parent: Container? = nil, - debugHelper: DebugHelper, - defaultObjectScope: ObjectScope = .graph - ) { - self.parent = parent - self.debugHelper = debugHelper - lock = parent.map { $0.lock } ?? SpinLock() - self.defaultObjectScope = defaultObjectScope - } - /// Instantiates a `Container` /// /// - Parameters @@ -50,20 +30,18 @@ public final class Container { /// /// - Remark: Compile time may be long if you pass a long closure to this initializer. /// Use `init()` or `init(parent:)` instead. - public convenience init( + public init( parent: Container? = nil, defaultObjectScope: ObjectScope = .graph, behaviors: [Behavior] = [], registeringClosure: (Container) -> Void = { _ in } ) { - self.init(parent: parent, debugHelper: LoggingDebugHelper(), defaultObjectScope: defaultObjectScope) - behaviors.forEach(addBehavior) - registeringClosure(self) + fatalError() } /// Removes all registrations in the container. public func removeAll() { - services.removeAll() + fatalError() } /// Discards instances for services registered in the given `ObjectsScopeProtocol`. @@ -73,24 +51,8 @@ public final class Container { /// /// - Parameters: /// - objectScope: All instances registered in given `ObjectsScopeProtocol` will be discarded. - public func resetObjectScope(_ objectScope: ObjectScopeProtocol) { - services.values - .filter { $0.objectScope === objectScope } - .forEach { $0.storage.instance = nil } - - parent?.resetObjectScope(objectScope) - } - - /// Discards instances for services registered in the given `ObjectsScope`. It performs the same operation - /// as `resetObjectScope(_:ObjectScopeProtocol)`, but provides more convenient usage syntax. - /// - /// **Example usage:** - /// container.resetObjectScope(.container) - /// - /// - Parameters: - /// - objectScope: All instances registered in given `ObjectsScope` will be discarded. public func resetObjectScope(_ objectScope: ObjectScope) { - resetObjectScope(objectScope as ObjectScopeProtocol) + fatalError() } /// Adds a registration for the specified service with the factory closure to specify how the service is @@ -112,43 +74,7 @@ public final class Container { name: String? = nil, factory: @escaping (Resolver) -> Service ) -> ServiceEntry { - return _register(serviceType, factory: factory, name: name) - } - - /// This method is designed for the use to extend Swinject functionality. - /// Do NOT use this method unless you intend to write an extension or plugin to Swinject framework. - /// - /// - Parameters: - /// - serviceType: The service type to register. - /// - factory: The closure to specify how the service type is resolved with the dependencies of the type. - /// It is invoked when the `Container` needs to instantiate the instance. - /// It takes a `Resolver` to inject dependencies to the instance, - /// and returns the instance of the component type for the service. - /// - name: A registration name. - /// - option: A service key option for an extension/plugin. - /// - /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. - @discardableResult - // swiftlint:disable:next identifier_name - public func _register( - _ serviceType: Service.Type, - factory: @escaping (Arguments) -> Any, - name: String? = nil, - option: ServiceKeyOption? = nil - ) -> ServiceEntry { - let key = ServiceKey(serviceType: Service.self, argumentsType: Arguments.self, name: name, option: option) - let entry = ServiceEntry( - serviceType: serviceType, - argumentsType: Arguments.self, - factory: factory, - objectScope: defaultObjectScope - ) - entry.container = self - services[key] = entry - - behaviors.forEach { $0.container(self, didRegisterType: serviceType, toService: entry, withName: name) } - - return entry + fatalError() } /// Returns a synchronized view of the container for thread safety. @@ -157,7 +83,7 @@ public final class Container { /// /// - Returns: A synchronized container as `Resolver`. public func synchronize() -> Resolver { - return SynchronizedResolver(container: self) + fatalError() } /// Adds behavior to the container. `Behavior.container(_:didRegisterService:withName:)` will be invoked for @@ -166,95 +92,7 @@ public final class Container { /// - Parameters: /// - behavior: Behavior to be added to the container public func addBehavior(_ behavior: Behavior) { - behaviors.append(behavior) - } - - internal func restoreObjectGraph(_ identifier: GraphIdentifier) { - currentObjectGraph = identifier - } -} - -// MARK: - _Resolver - -extension Container: _Resolver { - // swiftlint:disable:next identifier_name - public func _resolve( - name: String?, - option: ServiceKeyOption? = nil, - invoker: @escaping ((Arguments) -> Any) -> Any - ) -> Service? { - var resolvedInstance: Service? - let key = ServiceKey(serviceType: Service.self, argumentsType: Arguments.self, name: name, option: option) - - if let entry = getEntry(for: key) { - resolvedInstance = resolve(entry: entry, invoker: invoker) - } - - if resolvedInstance == nil { - resolvedInstance = resolveAsWrapper(name: name, option: option, invoker: invoker) - } - - if resolvedInstance == nil { - debugHelper.resolutionFailed( - serviceType: Service.self, - key: key, - availableRegistrations: getRegistrations() - ) - } - - return resolvedInstance - } - - fileprivate func resolveAsWrapper( - name: String?, - option: ServiceKeyOption?, - invoker: @escaping ((Arguments) -> Any) -> Any - ) -> Wrapper? { - guard let wrapper = Wrapper.self as? InstanceWrapper.Type else { return nil } - - let key = ServiceKey( - serviceType: wrapper.wrappedType, argumentsType: Arguments.self, name: name, option: option - ) - - if let entry = getEntry(for: key) { - let factory = { [weak self] in self?.resolve(entry: entry, invoker: invoker) as Any? } - return wrapper.init(inContainer: self, withInstanceFactory: factory) as? Wrapper - } else { - return wrapper.init(inContainer: self, withInstanceFactory: nil) as? Wrapper - } - } - - fileprivate func getRegistrations() -> [ServiceKey: ServiceEntryProtocol] { - var registrations = parent?.getRegistrations() ?? [:] - services.forEach { key, value in registrations[key] = value } - return registrations - } - - fileprivate var maxResolutionDepth: Int { return 200 } - - fileprivate func incrementResolutionDepth() { - parent?.incrementResolutionDepth() - if resolutionDepth == 0, currentObjectGraph == nil { - currentObjectGraph = GraphIdentifier() - } - guard resolutionDepth < maxResolutionDepth else { - fatalError("Infinite recursive call for circular dependency has been detected. " + - "To avoid the infinite call, 'initCompleted' handler should be used to inject circular dependency.") - } - resolutionDepth += 1 - } - - fileprivate func decrementResolutionDepth() { - parent?.decrementResolutionDepth() - assert(resolutionDepth > 0, "The depth cannot be negative.") - - resolutionDepth -= 1 - if resolutionDepth == 0 { graphResolutionCompleted() } - } - - fileprivate func graphResolutionCompleted() { - services.values.forEach { $0.storage.graphResolutionCompleted() } - currentObjectGraph = nil + fatalError() } } @@ -268,7 +106,7 @@ extension Container: Resolver { /// - Returns: The resolved service type instance, or nil if no registration for the service type /// is found in the `Container`. public func resolve(_ serviceType: Service.Type) -> Service? { - return resolve(serviceType, name: nil) + fatalError() } /// Retrieves the instance with the specified service type and registration name. @@ -280,55 +118,7 @@ extension Container: Resolver { /// - Returns: The resolved service type instance, or nil if no registration for the service type and name /// is found in the `Container`. public func resolve(_: Service.Type, name: String?) -> Service? { - return _resolve(name: name) { (factory: (Resolver) -> Any) in factory(self) } - } - - fileprivate func getEntry(for key: ServiceKey) -> ServiceEntryProtocol? { - if let entry = services[key] { - return entry - } else { - return parent?.getEntry(for: key) - } - } - - fileprivate func resolve( - entry: ServiceEntryProtocol, - invoker: (Factory) -> Any - ) -> Service? { - incrementResolutionDepth() - defer { decrementResolutionDepth() } - - guard let currentObjectGraph = currentObjectGraph else { - fatalError("If accessing container from multiple threads, make sure to use a synchronized resolver.") - } - - if let persistedInstance = persistedInstance(Service.self, from: entry, in: currentObjectGraph) { - return persistedInstance - } - - let resolvedInstance = invoker(entry.factory as! Factory) - if let persistedInstance = persistedInstance(Service.self, from: entry, in: currentObjectGraph) { - // An instance for the key might be added by the factory invocation. - return persistedInstance - } - entry.storage.setInstance(resolvedInstance as Any, inGraph: currentObjectGraph) - - if let completed = entry.initCompleted as? (Resolver, Any) -> Void, - let resolvedInstance = resolvedInstance as? Service { - completed(self, resolvedInstance) - } - - return resolvedInstance as? Service - } - - private func persistedInstance( - _: Service.Type, from entry: ServiceEntryProtocol, in graph: GraphIdentifier - ) -> Service? { - if let instance = entry.storage.instance(inGraph: graph), let service = instance as? Service { - return service - } else { - return nil - } + fatalError() } } @@ -336,8 +126,6 @@ extension Container: Resolver { extension Container: CustomStringConvertible { public var description: String { - return "[" - + services.map { "\n { \($1.describeWithKey($0)) }" }.sorted().joined(separator: ",") - + "\n]" + fatalError() } } diff --git a/Sources/2.0 API/DebugHelper.swift b/Sources/2.0 API/DebugHelper.swift deleted file mode 100644 index 96e216b6..00000000 --- a/Sources/2.0 API/DebugHelper.swift +++ /dev/null @@ -1,50 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -internal protocol DebugHelper { - func resolutionFailed( - serviceType: Service.Type, - key: ServiceKey, - availableRegistrations: [ServiceKey: ServiceEntryProtocol] - ) -} - -internal final class LoggingDebugHelper: DebugHelper { - func resolutionFailed( - serviceType: Service.Type, - key: ServiceKey, - availableRegistrations: [ServiceKey: ServiceEntryProtocol] - ) { - var output = [ - "Swinject: Resolution failed. Expected registration:", - "\t{ \(description(serviceType: serviceType, serviceKey: key)) }", - "Available registrations:", - ] - output += availableRegistrations - .filter { $0.1 is ServiceEntry } - .map { "\t{ " + $0.1.describeWithKey($0.0) + " }" } - - Container.log(output.joined(separator: "\n")) - } -} - -internal func description( - serviceType: Any.Type, - serviceKey: ServiceKey, - objectScope: ObjectScopeProtocol? = nil, - initCompleted: [Any] = [] -) -> String { - // The protocol order in "protocol<>" is non-deterministic. - let nameDescription = serviceKey.name.map { ", Name: \"\($0)\"" } ?? "" - let optionDescription = serviceKey.option.map { ", \($0)" } ?? "" - let initCompletedDescription = initCompleted.isEmpty ? - "" : ", InitCompleted: Specified \(initCompleted.count) closures" - let objectScopeDescription = objectScope.map { ", ObjectScope: \($0)" } ?? "" - return "Service: \(serviceType)" - + nameDescription - + optionDescription - + ", Factory: \(serviceKey.argumentsType) -> \(serviceKey.serviceType)" - + objectScopeDescription - + initCompletedDescription -} diff --git a/Sources/2.0 API/FunctionType.swift b/Sources/2.0 API/FunctionType.swift deleted file mode 100644 index ace6b50f..00000000 --- a/Sources/2.0 API/FunctionType.swift +++ /dev/null @@ -1,6 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -// Type alias to expect a closure. -internal typealias FunctionType = Any diff --git a/Sources/2.0 API/GraphIdentifier.swift b/Sources/2.0 API/GraphIdentifier.swift deleted file mode 100644 index 675109bd..00000000 --- a/Sources/2.0 API/GraphIdentifier.swift +++ /dev/null @@ -1,16 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -/// Unique identifier of an object graph during a resolution process. -public final class GraphIdentifier {} - -extension GraphIdentifier: Equatable, Hashable { - public static func == (lhs: GraphIdentifier, rhs: GraphIdentifier) -> Bool { - return lhs === rhs - } - - public func hash(into hasher: inout Hasher) { - hasher.combine(ObjectIdentifier(self).hashValue) - } -} diff --git a/Sources/2.0 API/InstanceStorage.swift b/Sources/2.0 API/InstanceStorage.swift deleted file mode 100644 index 2d930b83..00000000 --- a/Sources/2.0 API/InstanceStorage.swift +++ /dev/null @@ -1,130 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -/// Storage provided by `ObjectScope`. It is used by `Container` to persist resolved instances. -public protocol InstanceStorage: AnyObject { - var instance: Any? { get set } - func graphResolutionCompleted() - func instance(inGraph graph: GraphIdentifier) -> Any? - func setInstance(_ instance: Any?, inGraph graph: GraphIdentifier) -} - -extension InstanceStorage { - public func graphResolutionCompleted() {} - public func instance(inGraph _: GraphIdentifier) -> Any? { return instance } - public func setInstance(_ instance: Any?, inGraph _: GraphIdentifier) { self.instance = instance } -} - -/// Persists storage during the resolution of the object graph -public final class GraphStorage: InstanceStorage { - private var instances = [GraphIdentifier: Weak]() - public var instance: Any? - - public init() {} - - public func graphResolutionCompleted() { - instance = nil - } - - public func instance(inGraph graph: GraphIdentifier) -> Any? { - return instances[graph]?.value - } - - public func setInstance(_ instance: Any?, inGraph graph: GraphIdentifier) { - self.instance = instance - - if instances[graph] == nil { instances[graph] = Weak() } - instances[graph]?.value = instance - } -} - -/// Persists stored instance until it is explicitly discarded. -public final class PermanentStorage: InstanceStorage { - public var instance: Any? - - public init() {} -} - -/// Does not persist stored instance. -public final class TransientStorage: InstanceStorage { - public var instance: Any? { - get { return nil } - set {} // swiftlint:disable:this unused_setter_value - } - - public init() {} -} - -/// Does not persist value types. -/// Persists reference types as long as there are strong references to given instance. -public final class WeakStorage: InstanceStorage { - private var _instance = Weak() - - public var instance: Any? { - get { return _instance.value } - set { _instance.value = newValue } - } - - public init() {} -} - -/// Combines the behavior of multiple instance storages. -/// Instance is persisted as long as at least one of the underlying storages is persisting it. -public final class CompositeStorage: InstanceStorage { - private let components: [InstanceStorage] - - public var instance: Any? { - get { - #if swift(>=4.1) - return components.compactMap { $0.instance }.first - #else - return components.flatMap { $0.instance }.first - #endif - } - set { components.forEach { $0.instance = newValue } } - } - - public init(_ components: [InstanceStorage]) { - self.components = components - } - - public func graphResolutionCompleted() { - components.forEach { $0.graphResolutionCompleted() } - } - - public func setInstance(_ instance: Any?, inGraph graph: GraphIdentifier) { - components.forEach { $0.setInstance(instance, inGraph: graph) } - } - - public func instance(inGraph graph: GraphIdentifier) -> Any? { - #if swift(>=4.1) - return components.compactMap { $0.instance(inGraph: graph) }.first - #else - return components.flatMap { $0.instance(inGraph: graph) }.first - #endif - } -} - -private class Weak { - private weak var object: AnyObject? - - #if os(Linux) - var value: Wrapped? { - get { - guard let object = object else { return nil } - return object as? Wrapped - } - set { object = newValue.flatMap { $0 as? AnyObject } } - } - - #else - var value: Wrapped? { - get { - guard let object = object else { return nil } - return object as? Wrapped - } - set { object = newValue as AnyObject? } - } - #endif -} diff --git a/Sources/2.0 API/InstanceWrapper.swift b/Sources/2.0 API/InstanceWrapper.swift index aa0a1745..64c2de8e 100644 --- a/Sources/2.0 API/InstanceWrapper.swift +++ b/Sources/2.0 API/InstanceWrapper.swift @@ -2,76 +2,24 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -protocol InstanceWrapper { - static var wrappedType: Any.Type { get } - init?(inContainer container: Container, withInstanceFactory factory: (() -> Any?)?) -} - /// Wrapper to enable delayed dependency instantiation. /// `Lazy` does not need to be explicitly registered into the `Container` - resolution will work /// as long as there is a registration for the `Type`. -public final class Lazy: InstanceWrapper { - static var wrappedType: Any.Type { return Service.self } - - private let factory: () -> Any? - private let graphIdentifier: GraphIdentifier? - private weak var container: Container? - - init?(inContainer container: Container, withInstanceFactory factory: (() -> Any?)?) { - guard let factory = factory else { return nil } - self.factory = factory - graphIdentifier = container.currentObjectGraph - self.container = container - } - - private var _instance: Service? - +public final class Lazy { /// Getter for the wrapped object. /// It will be resolved from the `Container` when first accessed, all other calls will return the same instance. public var instance: Service { - if let instance = _instance { - return instance - } else { - _instance = makeInstance() - return _instance! - } - } - - private func makeInstance() -> Service? { - guard let container = container else { - return nil - } - if let graphIdentifier = graphIdentifier { - container.restoreObjectGraph(graphIdentifier) - } - return factory() as? Service + fatalError() } } /// Wrapper to enable delayed dependency instantiation. /// `Provider` does not need to be explicitly registered into the `Container` - resolution will work /// as long as there is a registration for the `Type`. -public final class Provider: InstanceWrapper { - static var wrappedType: Any.Type { return Service.self } - - private let factory: () -> Any? - - init?(inContainer _: Container, withInstanceFactory factory: (() -> Any?)?) { - guard let factory = factory else { return nil } - self.factory = factory - } - +public final class Provider { /// Getter for the wrapped object. /// New instance will be resolved from the `Container` every time it is accessed. public var instance: Service { - return factory() as! Service - } -} - -extension Optional: InstanceWrapper { - static var wrappedType: Any.Type { return Wrapped.self } - - init?(inContainer _: Container, withInstanceFactory factory: (() -> Any?)?) { - self = factory?() as? Wrapped + fatalError() } } diff --git a/Sources/2.0 API/ObjectScope.Standard.swift b/Sources/2.0 API/ObjectScope.Standard.swift deleted file mode 100644 index 72aa375f..00000000 --- a/Sources/2.0 API/ObjectScope.Standard.swift +++ /dev/null @@ -1,22 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -extension ObjectScope { - /// A new instance is always created by the `Container` when a type is resolved. - /// The instance is not shared. - public static let transient = ObjectScope(storageFactory: TransientStorage.init, description: "transient") - - /// Instances are shared only when an object graph is being created, - /// otherwise a new instance is created by the `Container`. This is the default scope. - public static let graph = ObjectScope(storageFactory: GraphStorage.init, description: "graph") - - /// An instance provided by the `Container` is shared within the `Container` and its child `Containers`. - public static let container = ObjectScope(storageFactory: PermanentStorage.init, description: "container") - - /// An instance provided by the `Container` is shared within the `Container` and its child `Container`s - /// as long as there are strong references to given instance. Otherwise new instance is created - /// when resolving the type. - public static let weak = ObjectScope(storageFactory: WeakStorage.init, description: "weak", - parent: ObjectScope.graph) -} diff --git a/Sources/2.0 API/ObjectScope.swift b/Sources/2.0 API/ObjectScope.swift index c87e7ee6..c010aecb 100644 --- a/Sources/2.0 API/ObjectScope.swift +++ b/Sources/2.0 API/ObjectScope.swift @@ -4,39 +4,20 @@ /// A configuration how an instance provided by a `Container` is shared in the system. /// The configuration is ignored if it is applied to a value type. -public protocol ObjectScopeProtocol: AnyObject { - /// Used to create `InstanceStorage` to persist an instance for single service. - /// Will be invoked once for each service registered in given scope. - func makeStorage() -> InstanceStorage -} +public enum ObjectScope { + /// A new instance is always created by the `Container` when a type is resolved. + /// The instance is not shared. + case transient -/// Basic implementation of `ObjectScopeProtocol`. -public class ObjectScope: ObjectScopeProtocol, CustomStringConvertible { - public private(set) var description: String - private var storageFactory: () -> InstanceStorage - private let parent: ObjectScopeProtocol? + /// Instances are shared only when an object graph is being created, + /// otherwise a new instance is created by the `Container`. This is the default scope. + case graph - /// Instantiates an `ObjectScope` with storage factory and description. - /// - Parameters: - /// - storageFactory: Closure for creating an `InstanceStorage` - /// - description: Description of object scope for `CustomStringConvertible` implementation - /// - parent: If provided, its storage will be composed with the result of `storageFactory` - public init( - storageFactory: @escaping () -> InstanceStorage, - description: String = "", - parent: ObjectScopeProtocol? = nil - ) { - self.storageFactory = storageFactory - self.description = description - self.parent = parent - } + /// An instance provided by the `Container` is shared within the `Container` and its child `Containers`. + case container - /// Will invoke and return the result of `storageFactory` closure provided during initialisation. - public func makeStorage() -> InstanceStorage { - if let parent = parent { - return CompositeStorage([storageFactory(), parent.makeStorage()]) - } else { - return storageFactory() - } - } + /// An instance provided by the `Container` is shared within the `Container` and its child `Container`s + /// as long as there are strong references to given instance. Otherwise new instance is created + /// when resolving the type. + case weak } diff --git a/Sources/2.0 API/ServiceEntry.TypeForwarding.swift b/Sources/2.0 API/ServiceEntry.TypeForwarding.swift index 82297b6b..f192e1d1 100644 --- a/Sources/2.0 API/ServiceEntry.TypeForwarding.swift +++ b/Sources/2.0 API/ServiceEntry.TypeForwarding.swift @@ -19,7 +19,6 @@ extension ServiceEntry { /// - name: A registration name, which is used to differentiate from other registrations of the same `type` @discardableResult public func implements(_ type: T.Type, name: String? = nil) -> ServiceEntry { - container?.forward(type, name: name, to: self) return self } diff --git a/Sources/2.0 API/ServiceEntry.swift b/Sources/2.0 API/ServiceEntry.swift index 1414dcb5..499bc248 100644 --- a/Sources/2.0 API/ServiceEntry.swift +++ b/Sources/2.0 API/ServiceEntry.swift @@ -2,66 +2,16 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -import Foundation - -// A generic-type-free protocol to be the type of values in a strongly-typed collection. -internal protocol ServiceEntryProtocol: AnyObject { - func describeWithKey(_ serviceKey: ServiceKey) -> String - var objectScope: ObjectScopeProtocol { get } - var storage: InstanceStorage { get } - var factory: FunctionType { get } - var initCompleted: (FunctionType)? { get } - var serviceType: Any.Type { get } -} - /// The `ServiceEntry` class represents an entry of a registered service type. /// As a returned instance from a `register` method of a `Container`, some configurations can be added. -public final class ServiceEntry: ServiceEntryProtocol { - fileprivate var initCompletedActions: [(Resolver, Service) -> Void] = [] - internal let serviceType: Any.Type - internal let argumentsType: Any.Type - - internal let factory: FunctionType - internal weak var container: Container? - - internal var objectScope: ObjectScopeProtocol = ObjectScope.graph - internal lazy var storage: InstanceStorage = { [unowned self] in - self.objectScope.makeStorage() - }() - - internal var initCompleted: FunctionType? { - guard !initCompletedActions.isEmpty else { return nil } - - return { [weak self] (resolver: Resolver, service: Any) -> Void in - guard let strongSelf = self else { return } - strongSelf.initCompletedActions.forEach { $0(resolver, service as! Service) } - } - } - - internal init(serviceType: Service.Type, argumentsType: Any.Type, factory: FunctionType) { - self.serviceType = serviceType - self.argumentsType = argumentsType - self.factory = factory - } - - internal convenience init( - serviceType: Service.Type, - argumentsType: Any.Type, - factory: FunctionType, - objectScope: ObjectScope - ) { - self.init(serviceType: serviceType, argumentsType: argumentsType, factory: factory) - self.objectScope = objectScope - } - +public final class ServiceEntry { /// Specifies the object scope to resolve the service. /// /// - Parameter scope: The `ObjectScopeProtocol` value. /// /// - Returns: `self` to add another configuration fluently. @discardableResult - public func inObjectScope(_ objectScope: ObjectScopeProtocol) -> Self { - self.objectScope = objectScope + public func inObjectScope(_ scope: ObjectScope) -> Self where ObjectScope: Scope { return self } @@ -74,7 +24,7 @@ public final class ServiceEntry: ServiceEntryProtocol { /// - Returns: `self` to add another configuration fluently. @discardableResult public func inObjectScope(_ objectScope: ObjectScope) -> Self { - return inObjectScope(objectScope as ObjectScopeProtocol) + return self } /// Adds the callback to setup the instance after its `init` completes. @@ -86,16 +36,6 @@ public final class ServiceEntry: ServiceEntryProtocol { /// - Returns: `self` to add another configuration fluently. @discardableResult public func initCompleted(_ completed: @escaping (Resolver, Service) -> Void) -> Self { - initCompletedActions.append(completed) return self } - - internal func describeWithKey(_ serviceKey: ServiceKey) -> String { - return description( - serviceType: serviceType, - serviceKey: serviceKey, - objectScope: objectScope, - initCompleted: initCompletedActions - ) - } } diff --git a/Sources/2.0 API/ServiceKey.swift b/Sources/2.0 API/ServiceKey.swift deleted file mode 100644 index 87343c3b..00000000 --- a/Sources/2.0 API/ServiceKey.swift +++ /dev/null @@ -1,61 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -import Foundation - -// MARK: ServiceKeyOption - -public protocol ServiceKeyOption: CustomStringConvertible { - func isEqualTo(_ another: ServiceKeyOption) -> Bool - func hash(into: inout Hasher) -} - -// MARK: - ServiceKey - -internal struct ServiceKey { - internal let serviceType: Any.Type - internal let argumentsType: Any.Type - internal let name: String? - internal let option: ServiceKeyOption? // Used for SwinjectStoryboard or other extensions. - - internal init( - serviceType: Any.Type, - argumentsType: Any.Type, - name: String? = nil, - option: ServiceKeyOption? = nil - ) { - self.serviceType = serviceType - self.argumentsType = argumentsType - self.name = name - self.option = option - } -} - -// MARK: Hashable - -extension ServiceKey: Hashable { - public func hash(into hasher: inout Hasher) { - ObjectIdentifier(serviceType).hash(into: &hasher) - ObjectIdentifier(argumentsType).hash(into: &hasher) - name?.hash(into: &hasher) - option?.hash(into: &hasher) - } -} - -// MARK: Equatable - -func == (lhs: ServiceKey, rhs: ServiceKey) -> Bool { - return lhs.serviceType == rhs.serviceType - && lhs.argumentsType == rhs.argumentsType - && lhs.name == rhs.name - && equalOptions(opt1: lhs.option, opt2: rhs.option) -} - -private func equalOptions(opt1: ServiceKeyOption?, opt2: ServiceKeyOption?) -> Bool { - switch (opt1, opt2) { - case let (opt1?, opt2?): return opt1.isEqualTo(opt2) - case (nil, nil): return true - default: return false - } -} diff --git a/Sources/2.0 API/SpinLock.swift b/Sources/2.0 API/SpinLock.swift deleted file mode 100644 index ed4d01ea..00000000 --- a/Sources/2.0 API/SpinLock.swift +++ /dev/null @@ -1,15 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -import Foundation - -internal final class SpinLock { - private let lock = NSRecursiveLock() - - func sync(action: () -> T) -> T { - lock.lock() - defer { lock.unlock() } - return action() - } -} diff --git a/Sources/2.0 API/SynchronizedResolver.Arguments.swift b/Sources/2.0 API/SynchronizedResolver.Arguments.swift deleted file mode 100644 index 4bab61ee..00000000 --- a/Sources/2.0 API/SynchronizedResolver.Arguments.swift +++ /dev/null @@ -1,186 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -// -// NOTICE: -// -// SynchronizedResolver.Arguments.swift is generated from SynchronizedResolver.Arguments.erb by ERB. -// Do NOT modify SynchronizedResolver.Arguments.swift directly. -// Instead, modify SynchronizedResolver.Arguments.erb and run `script/gencode` at the project root directory to generate the code. -// - -// MARK: - Resolver with Arguments - -extension SynchronizedResolver { - internal func resolve( - _ serviceType: Service.Type, - argument: Arg1 - ) -> Service? { - return container.lock.sync { - self.container.resolve(serviceType, argument: argument) - } - } - - internal func resolve( - _ serviceType: Service.Type, - name: String?, - argument: Arg1 - ) -> Service? { - return container.lock.sync { - self.container.resolve(serviceType, name: name, argument: argument) - } - } - - internal func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2 - ) -> Service? { - return container.lock.sync { - self.container.resolve(serviceType, arguments: arg1, arg2) - } - } - - internal func resolve( - _ serviceType: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2 - ) -> Service? { - return container.lock.sync { - self.container.resolve(serviceType, name: name, arguments: arg1, arg2) - } - } - - internal func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3 - ) -> Service? { - return container.lock.sync { - self.container.resolve(serviceType, arguments: arg1, arg2, arg3) - } - } - - internal func resolve( - _ serviceType: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3 - ) -> Service? { - return container.lock.sync { - self.container.resolve(serviceType, name: name, arguments: arg1, arg2, arg3) - } - } - - internal func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4 - ) -> Service? { - return container.lock.sync { - self.container.resolve(serviceType, arguments: arg1, arg2, arg3, arg4) - } - } - - internal func resolve( - _ serviceType: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4 - ) -> Service? { - return container.lock.sync { - self.container.resolve(serviceType, name: name, arguments: arg1, arg2, arg3, arg4) - } - } - - internal func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5 - ) -> Service? { - return container.lock.sync { - self.container.resolve(serviceType, arguments: arg1, arg2, arg3, arg4, arg5) - } - } - - internal func resolve( - _ serviceType: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5 - ) -> Service? { - return container.lock.sync { - self.container.resolve(serviceType, name: name, arguments: arg1, arg2, arg3, arg4, arg5) - } - } - - internal func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6 - ) -> Service? { - return container.lock.sync { - self.container.resolve(serviceType, arguments: arg1, arg2, arg3, arg4, arg5, arg6) - } - } - - internal func resolve( - _ serviceType: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6 - ) -> Service? { - return container.lock.sync { - self.container.resolve(serviceType, name: name, arguments: arg1, arg2, arg3, arg4, arg5, arg6) - } - } - - internal func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7 - ) -> Service? { - return container.lock.sync { - self.container.resolve(serviceType, arguments: arg1, arg2, arg3, arg4, arg5, arg6, arg7) - } - } - - internal func resolve( - _ serviceType: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7 - ) -> Service? { - return container.lock.sync { - self.container.resolve(serviceType, name: name, arguments: arg1, arg2, arg3, arg4, arg5, arg6, arg7) - } - } - - internal func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8 - ) -> Service? { - return container.lock.sync { - self.container.resolve(serviceType, arguments: arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) - } - } - - internal func resolve( - _ serviceType: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8 - ) -> Service? { - return container.lock.sync { - self.container.resolve(serviceType, name: name, arguments: arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) - } - } - - internal func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8, _ arg9: Arg9 - ) -> Service? { - return container.lock.sync { - self.container.resolve(serviceType, arguments: arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - } - } - - internal func resolve( - _ serviceType: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8, _ arg9: Arg9 - ) -> Service? { - return container.lock.sync { - self.container.resolve(serviceType, name: name, arguments: arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - } - } -} diff --git a/Sources/2.0 API/SynchronizedResolver.swift b/Sources/2.0 API/SynchronizedResolver.swift deleted file mode 100644 index cda65a4f..00000000 --- a/Sources/2.0 API/SynchronizedResolver.swift +++ /dev/null @@ -1,38 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -internal final class SynchronizedResolver { - internal let container: Container - - internal init(container: Container) { - self.container = container - } -} - -extension SynchronizedResolver: _Resolver { - // swiftlint:disable:next identifier_name - internal func _resolve( - name: String?, - option: ServiceKeyOption?, - invoker: @escaping ((Arguments) -> Any) -> Any - ) -> Service? { - return container.lock.sync { - self.container._resolve(name: name, option: option, invoker: invoker) - } - } -} - -extension SynchronizedResolver: Resolver { - internal func resolve(_ serviceType: Service.Type) -> Service? { - return container.lock.sync { - self.container.resolve(serviceType) - } - } - - internal func resolve(_ serviceType: Service.Type, name: String?) -> Service? { - return container.lock.sync { - self.container.resolve(serviceType, name: name) - } - } -} diff --git a/Sources/2.0 API/_Resolver.swift b/Sources/2.0 API/_Resolver.swift deleted file mode 100644 index 3a1dcd43..00000000 --- a/Sources/2.0 API/_Resolver.swift +++ /dev/null @@ -1,24 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -/// This protocol is designed for the use to extend Swinject functionality. -/// Do NOT use this protocol unless you intend to write an extension or plugin to Swinject framework. -/// -/// A type conforming Resolver protocol must conform _Resolver protocol too. -public protocol _Resolver { - /// This method is designed for the use to extend Swinject functionality. - /// Do NOT use this method unless you intend to write an extension or plugin to Swinject framework. - /// - /// - Parameter name: The registration name. - /// - Parameter option: A service key option for an extension/plugin. - /// - Parameter invoker: A closure to execute service resolution. - /// - /// - Returns: The resolved service type instance, or nil if no service is found. - // swiftlint:disable:next identifier_name - func _resolve( - name: String?, - option: ServiceKeyOption?, - invoker: @escaping ((Arguments) -> Any) -> Any - ) -> Service? -} diff --git a/Sources/Core/TypeDescriptor.swift b/Sources/Core/TypeDescriptor.swift index aecba973..19d4a63b 100644 --- a/Sources/Core/TypeDescriptor.swift +++ b/Sources/Core/TypeDescriptor.swift @@ -49,4 +49,6 @@ protocol OptionalProtocol { static var wrappedType: Any.Type { get } } -extension Optional: OptionalProtocol {} +extension Optional: OptionalProtocol { + static var wrappedType: Any.Type { return Wrapped.self } +} diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 7f45256a..6a0f36db 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -7,13 +7,11 @@ objects = { /* Begin PBXBuildFile section */ - 01146C3ECC9A6B1973EED93F /* SynchronizedResolver.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 869CA0001EA621843F1EF2BB /* SynchronizedResolver.Arguments.swift */; }; 01197582F81B8D30D7D4A8AF /* NonGeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841D83ADB41363D1E38087B4 /* NonGeneratedMocks.swift */; }; 0125E3E8A17D6F2F0CE2F893 /* ContainerSpec.GraphCaching.swift in Sources */ = {isa = PBXBuildFile; fileRef = D366825BB9272905C79AEA47 /* ContainerSpec.GraphCaching.swift */; }; 013A1E1096BD1305A3A14493 /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1910A1471C3CA9EA86F350BA /* LoadAwareAssembly.swift */; }; 01D985B5F99817DEE0E0DAD1 /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */; }; 01F001388FD754499B18FFAC /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */; }; - 02CBAAF2DD5E7D589F997A27 /* SpinLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 919757437CA99D0C506EC028 /* SpinLock.swift */; }; 03005DC48E35AEF37251FADC /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; 03E7834C4448A5D939948CCF /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; 04C24C140F2D0BBFE48C682C /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; @@ -23,18 +21,15 @@ 0568E116A56DA02DA92BAC8E /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; 07538993A345EEC62228247E /* ServiceEntrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2234FFBE7F556D1372AFB42D /* ServiceEntrySpec.swift */; }; 084187169E13A6E9E709297C /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; - 087E0E3216DB7D53DE7A6BE0 /* FunctionType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F2567098AC12010C308E26D /* FunctionType.swift */; }; 0C24BE87E4F1CF7482DB3468 /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 273FB7A6277E0841E1570990 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 0C7996FAC479BA40B124F470 /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = ADD71387EBA54D7EF60D0089 /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 0CB9E677FDF7CF424A738F34 /* Container.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C13D01A2DE6F53DF3175D22 /* Container.Arguments.swift */; }; 0CED31C429BA9F9B23EB2B1F /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42490D1D0C395951243F5CFF /* Container.swift */; }; - 0CFCEE57963529ECA1FFD8C2 /* SynchronizedResolver.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 869CA0001EA621843F1EF2BB /* SynchronizedResolver.Arguments.swift */; }; 0D6143A7732F1334275D3658 /* UnboundScopeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 671D5D89472DAFA916814506 /* UnboundScopeSpec.swift */; }; 0DFB6FB4DF6A713EA545930F /* Container.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C2DBC728B763B04CB25963 /* Container.TypeForwarding.swift */; }; 0E465ECE9EC970161D607F7F /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EA7A547FC60DBD02D132B3E6 /* Swinject.framework */; }; 0E8E5B08478EB883D9B52947 /* ScopedBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */; }; 100DC02D61F72A611B7CF6E3 /* UnboundScopeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 671D5D89472DAFA916814506 /* UnboundScopeSpec.swift */; }; - 10EB88F976AC1025DC22FE8A /* InstanceStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06A8ED72CD6241A2CDEA8479 /* InstanceStorage.swift */; }; 124369E08D4848D05E3EA6B1 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1FA0377AF4799D42E9462FA /* BasicAssembly.swift */; }; 13379D1C70FC17FE2F949341 /* BindingKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */; }; 133D41B8AD245B9DBAFC6606 /* Quick.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 683A1FB7D7F4E9508D57E936 /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -42,7 +37,6 @@ 151340C24653963B97464BA9 /* ContextedResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBA3EF319F06A1B3B6C84C29 /* ContextedResolver.swift */; }; 15FA8361AB335F4CC372A52C /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; 166CBBCA1E1441AD87A60EFF /* BindingKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */; }; - 16727D477E4258A547C21D93 /* DebugHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F4982F617A2FF202637E57C /* DebugHelper.swift */; }; 16FE1BC18A9DD0D21CAF2806 /* ScopeRegistryKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2902FD4C1A50263340A51FFB /* ScopeRegistryKeySpec.swift */; }; 1718A1577AB543174FD8E644 /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; 173F76A64BF34826968532DC /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59111BE319C59E4CD6CF68CD /* Assembler.swift */; }; @@ -57,11 +51,9 @@ 1C2F5A09F986586F85FAC3E8 /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; 1CFCB38BC4EE2D3AAD40154E /* ScopedBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */; }; 1F256E6920935F88C753F739 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; - 1F2E1C6B8F28C5441D52C033 /* ObjectScope.Standard.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD433AFA21FF52AF81A9C9B8 /* ObjectScope.Standard.swift */; }; 1F4FBB9D795CE9D45E5A8BEE /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; 20823C309A5C58900CDFA8C3 /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; 22837E727E47A3B8A588AB78 /* TypeBinderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDA62EEBC79ED2639C93A76B /* TypeBinderSpec.swift */; }; - 240057137A0476B5874B0BCB /* DebugHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F4982F617A2FF202637E57C /* DebugHelper.swift */; }; 2488CDD8D67CAC5C97BDF8B1 /* Resolver3.swift in Sources */ = {isa = PBXBuildFile; fileRef = C11D19C5F01647E4A576514A /* Resolver3.swift */; }; 25DE2596CC5387B9353FC204 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */; }; 261D54C316CB625359F7EE97 /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; @@ -87,24 +79,19 @@ 37FE9A9C76DB50ABB28AF9BE /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; 38FACA739BA59278725FAE67 /* ServiceEntry.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03CDF95C1EAFCD54450B34B6 /* ServiceEntry.TypeForwarding.swift */; }; 39431794D93EA4DDD0BBB2C5 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; - 39D7CF8F5563E3C1BDDEED93 /* _Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17BEC193FDDE3BA488EA592E /* _Resolver.swift */; }; 39F9BBD670C944E1331FAB13 /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */; }; 3A149A223FA316F68C0A486A /* NonGeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841D83ADB41363D1E38087B4 /* NonGeneratedMocks.swift */; }; 3A2FE7C2BA76C096122F92ED /* UnboundScopeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 671D5D89472DAFA916814506 /* UnboundScopeSpec.swift */; }; - 3AC304A612ECAED02C58BBF5 /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BFF4BA99493C54260878C4 /* ObjectScope.swift */; }; 3B2E8B8CF4825DB05B0233F8 /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */; }; 3B61931D1E9C0F7D1AAEDDF7 /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92B8E618A08408404FB2A7A /* TypeBinder.swift */; }; 3DA1F1126FD1FC935353F847 /* ServiceKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45CA41659767E1378A9F492B /* ServiceKeySpec.swift */; }; - 3E13E204659AF2DCE94D75CB /* ObjectScope.Standard.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD433AFA21FF52AF81A9C9B8 /* ObjectScope.Standard.swift */; }; 3F04B9C7812B5E21DCE4D36C /* GeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */; }; 3F1FB19A735BE6E1FA749E75 /* SwinjectSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9527A4CA5BCBA7AFA3596757 /* SwinjectSpec.swift */; }; 3F8EA877F153EE374FF8E31A /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = A10187BB3A994165E7FC1528 /* ScopedBinding.swift */; }; - 401A790CF8450924114D89ED /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BFF4BA99493C54260878C4 /* ObjectScope.swift */; }; 418F111C8E128766AC8E33CC /* Closable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D0BCCCD61CD9BECC29E064 /* Closable.swift */; }; 41EEA4724CD401F38F9622E3 /* InstanceMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CADDB3E9E363310028AA5920 /* InstanceMaker.swift */; }; 439254FAE8DF567DE9659ADA /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3586A4987B7C7C8122D674E /* SwinjectError.swift */; }; 4503217DA585B602EDE65742 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1FA0377AF4799D42E9462FA /* BasicAssembly.swift */; }; - 457481A631CA1253094D108B /* GraphIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E95633441FFB44D8A05585C /* GraphIdentifier.swift */; }; 4578AA4291288B21ABD74735 /* ContextedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4021EB1EA6A2770920FAD979 /* ContextedResolverSpec.swift */; }; 45E5B568D6D0E7FC976DCDC1 /* ServiceKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45CA41659767E1378A9F492B /* ServiceKeySpec.swift */; }; 462054EB9666775B13C36132 /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */; }; @@ -116,7 +103,6 @@ 49FB15929F16836D51779A1D /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B580B43E1891812C97209 /* Binding.swift */; }; 4A9FFFF0FF25724AC5A0BB52 /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; 4B35CE8BAA88DCAE7D36BC4B /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; - 4BB09CCBB703AADD728BD796 /* ServiceKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = D101B42AE242A5A00C319FAE /* ServiceKey.swift */; }; 4BCB79EECFCA81178439A85C /* Quick.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 1C58FC14EEA170B0DC079DE4 /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 4C55A4A0FFA4E251DC482E20 /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */; }; 4C6D7AE29CB7E16431AACFA2 /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; @@ -134,7 +120,6 @@ 53F72D1C7E26B52E5D548206 /* WeakStorageSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DECE1C39517B81037CC0D53 /* WeakStorageSpec.swift */; }; 549227903CFDDF4E8272C691 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; 54A1FEE340AC3A2413876AD2 /* ScopeRegistryKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */; }; - 5541D9BB4DF2EBB3E7325359 /* _Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17BEC193FDDE3BA488EA592E /* _Resolver.swift */; }; 5570E14A839D4065FFBA7EF4 /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCAF491EC7DCD7477F9A0ECB /* SwinjectModule.swift */; }; 564B886D2A35AF26FC411922 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; 572CA6A9E19927F5D434BB6F /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; @@ -157,7 +142,6 @@ 60467C140BE3C99C1B872A55 /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 823617F3B8A9192F56B13331 /* Quick.framework */; }; 60AF45155775AA5E97AAB5C1 /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEE8FDF4B975A8F2A9FCC5FF /* Food.swift */; }; 60CEB9FCA08EFF202DD38096 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1FA0377AF4799D42E9462FA /* BasicAssembly.swift */; }; - 61FA449BF10682C9E89E767F /* ObjectScope.Standard.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD433AFA21FF52AF81A9C9B8 /* ObjectScope.Standard.swift */; }; 627F366F03B0D6E549AAE98F /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ADD71387EBA54D7EF60D0089 /* Swinject.framework */; }; 62986D0AAAE9D3934E125332 /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; 648FDC2A1E3DC75CB47D31E1 /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; @@ -183,13 +167,11 @@ 741344C30785507B22DF703B /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; 7472B748AEA9F4D1E5EF9A70 /* Container.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C13D01A2DE6F53DF3175D22 /* Container.Arguments.swift */; }; 7480A500FEC04BB9CB048AE1 /* BinderEnvironmentSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */; }; - 748FE5C55FB93BFFA9012CD3 /* SynchronizedResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4040F8D091ED67C84E2B8854 /* SynchronizedResolver.swift */; }; 76B3D9DBF8D5593F67A7B7E6 /* ContextedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4021EB1EA6A2770920FAD979 /* ContextedResolverSpec.swift */; }; 782801544D9F468F536E045E /* Container.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C2DBC728B763B04CB25963 /* Container.TypeForwarding.swift */; }; 7845113EAF8FFAFD5EC10540 /* BindingKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */; }; 788AE378F10DA216265FFF52 /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; 78ACD9EBF8625ECD24103A17 /* ServiceEntry.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03CDF95C1EAFCD54450B34B6 /* ServiceEntry.TypeForwarding.swift */; }; - 79772C34E5102A8E3003DBF8 /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BFF4BA99493C54260878C4 /* ObjectScope.swift */; }; 79814146B3796F42B447326D /* ServiceEntrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2234FFBE7F556D1372AFB42D /* ServiceEntrySpec.swift */; }; 7A9246A43400FC1504683E20 /* ServiceKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45CA41659767E1378A9F492B /* ServiceKeySpec.swift */; }; 7DD047C203659BCA7F04E48D /* Container.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C13D01A2DE6F53DF3175D22 /* Container.Arguments.swift */; }; @@ -228,7 +210,6 @@ 91FED72828F68263D599B6C0 /* SimpleBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */; }; 920EF7689DA7C81235B75CE7 /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 34AFFAC41BA9D02A38BDB7A3 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 9264E4C053A699FE01EAD232 /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; - 939769201BD93B84E6BAD258 /* SpinLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 919757437CA99D0C506EC028 /* SpinLock.swift */; }; 93DCA2A58C4067D5E60F7ED1 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; 9437AF5CAAD1A2D033AE3599 /* ScopeRegistryKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */; }; 944F92334ADBCBB7C6A89F20 /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 74DE57FB3E8228904E6FE0D7 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -245,20 +226,16 @@ 9B9AA902B80620568D732D7B /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; 9BAAD1DEBA041700C921A589 /* WeakStorageSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DECE1C39517B81037CC0D53 /* WeakStorageSpec.swift */; }; 9C08C2D57E0B0B46D5748B6C /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; - 9C81098E44AF728D63640DA1 /* SynchronizedResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4040F8D091ED67C84E2B8854 /* SynchronizedResolver.swift */; }; 9CEF62C5A3EC3CB8034F08BB /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1910A1471C3CA9EA86F350BA /* LoadAwareAssembly.swift */; }; 9D1AD9CBA32CEE29EF6C68C2 /* GeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */; }; - 9D99BBDFE65AC69067BC569C /* InstanceStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06A8ED72CD6241A2CDEA8479 /* InstanceStorage.swift */; }; 9DD1C1273B38FCF4FFE9BCC2 /* BindingKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */; }; 9E084F679592ADFA28D3AD6D /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; 9EF6DF530041FC494572D3DB /* ContextedResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBA3EF319F06A1B3B6C84C29 /* ContextedResolver.swift */; }; 9F1C7A652660EA87BF599126 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; 9FEC055DC6BE1D844FE5F082 /* Closable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D0BCCCD61CD9BECC29E064 /* Closable.swift */; }; A014793C56F8966AD2D7CC50 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; - A1650894E467EA95327AEF5E /* FunctionType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F2567098AC12010C308E26D /* FunctionType.swift */; }; A19EFC58B60E547CC3A3A6BE /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 74DE57FB3E8228904E6FE0D7 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; A1B275A2EFA22C45AC46B31E /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; - A2745DCB0ACE7714C65CA2A9 /* ObjectScope.Standard.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD433AFA21FF52AF81A9C9B8 /* ObjectScope.Standard.swift */; }; A3815641CEB5A06759D288E0 /* Resolver3.swift in Sources */ = {isa = PBXBuildFile; fileRef = C11D19C5F01647E4A576514A /* Resolver3.swift */; }; A4490FF7ACCC5CBFB2C1896C /* Container.Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE4B1E4BA98573B6FED2D118 /* Container.Logging.swift */; }; A44D1B2E48E1C0FEF146933A /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; @@ -269,32 +246,26 @@ A54B018EF21348D600F8ABD2 /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */; }; A600D3F52D38EBC5A3C75CC2 /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */; }; A6A470DC3A6D310AA0671075 /* ContainerSpec.CustomScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 332BC41A010B0C5AEAFDF545 /* ContainerSpec.CustomScope.swift */; }; - A778AD223AF6C6E30BFFFC84 /* SpinLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 919757437CA99D0C506EC028 /* SpinLock.swift */; }; AA6651CFD4090465E7CB7871 /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCAF491EC7DCD7477F9A0ECB /* SwinjectModule.swift */; }; AAB6386F88442B22E9F7FF0E /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42490D1D0C395951243F5CFF /* Container.swift */; }; AAC84D757FE8F601FF053923 /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3586A4987B7C7C8122D674E /* SwinjectError.swift */; }; - ABA204BE7AEAC01BF1D6002E /* ServiceKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = D101B42AE242A5A00C319FAE /* ServiceKey.swift */; }; AF5F860DBFE2607EF4157CF7 /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; B1B107E3FA2DC2E985160D75 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; B1B1A13B6792198E4E835034 /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */; }; B2FCC51BB61148422256A14A /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; B5048A00D49FD5C1C098EE01 /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; B61FAC17826BAFD2DC1C0E5E /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; - B753AC265ABCEF3CBCE3C4CE /* ServiceKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = D101B42AE242A5A00C319FAE /* ServiceKey.swift */; }; B7CE6F32765FC472CE205458 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; B95786317494375C0E2D2044 /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; B9FAEC69210B352FC744079E /* TypeBinderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDA62EEBC79ED2639C93A76B /* TypeBinderSpec.swift */; }; BAFD66351A9ED8E7BFB19CD3 /* NonGeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841D83ADB41363D1E38087B4 /* NonGeneratedMocks.swift */; }; BB3AAADF214D5FF3E25E3974 /* SwinjectSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9527A4CA5BCBA7AFA3596757 /* SwinjectSpec.swift */; }; - BF8E048DADB28763928A2ACC /* SynchronizedResolver.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 869CA0001EA621843F1EF2BB /* SynchronizedResolver.Arguments.swift */; }; C0CCC43D2CDFF01CF0FF9F89 /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = ADC44E9312C3B974AFD8F07B /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; C15318646655D97EBDCAA67B /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B3797A6BB56AE76CEC19F2A /* SwinjectApiSpec.swift */; }; - C16D64C4A1ABCF441BEB2EBE /* GraphIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E95633441FFB44D8A05585C /* GraphIdentifier.swift */; }; C37B885879F0D716B36E1C5B /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 74DE57FB3E8228904E6FE0D7 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; C3AD37D47C38E5EB20FAF917 /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; C493D6AD1D8748A2698F0B81 /* ContainerSpec.DebugHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF340AF8DD2D821A225A36B3 /* ContainerSpec.DebugHelper.swift */; }; C50BFD826112288F1D693A30 /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; - C5584C2C04564AFC0BCD3710 /* GraphIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E95633441FFB44D8A05585C /* GraphIdentifier.swift */; }; C6ED278B6F0E08A4B1E57C45 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; C75EC8F8DD60676B120917EA /* ContextedResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBA3EF319F06A1B3B6C84C29 /* ContextedResolver.swift */; }; C797CCF413DF181935DAB58C /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; @@ -302,14 +273,13 @@ C8F1F075F5792C9936B0577D /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42490D1D0C395951243F5CFF /* Container.swift */; }; C9DD3F5C59F6A8833279F790 /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6EA4ECB5E4CEC9751AD36854 /* Swinject.framework */; }; CA202C787FE269EF63ADC449 /* TaggedTypeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */; }; - CA7DED9FF907336CB6091795 /* ServiceKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = D101B42AE242A5A00C319FAE /* ServiceKey.swift */; }; - CC5509F4681D4489DB0D447E /* DebugHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F4982F617A2FF202637E57C /* DebugHelper.swift */; }; - CE62237127502CCD13CC22C2 /* _Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17BEC193FDDE3BA488EA592E /* _Resolver.swift */; }; + CD4D866522E4C8A50042ACDC /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD4D866322E4C6DB0042ACDC /* ObjectScope.swift */; }; + CD4D866622E4C8A70042ACDC /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD4D866322E4C6DB0042ACDC /* ObjectScope.swift */; }; + CD4D866722E4C8A80042ACDC /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD4D866322E4C6DB0042ACDC /* ObjectScope.swift */; }; + CD4D866822E4C8A80042ACDC /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD4D866322E4C6DB0042ACDC /* ObjectScope.swift */; }; CFC3CDB46CD8FFA22EB0FADD /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A0157DBBD5E1F45963BB0932 /* Swinject.framework */; }; - D0F428B5C92CA0C25EF4BE61 /* _Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17BEC193FDDE3BA488EA592E /* _Resolver.swift */; }; D10FFA4B80F4BE6024B1DCEE /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1910A1471C3CA9EA86F350BA /* LoadAwareAssembly.swift */; }; D18275ADB0E56D3087894518 /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; - D1E4114EED19E341BB80869A /* FunctionType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F2567098AC12010C308E26D /* FunctionType.swift */; }; D2391A103E7356AD7E08F5BA /* ScopedBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */; }; D267BD55BBEDE3ECEC449472 /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; D29AAB45717CC7988EC72163 /* WeakStorageSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DECE1C39517B81037CC0D53 /* WeakStorageSpec.swift */; }; @@ -319,33 +289,27 @@ D557A108A21751DF75542692 /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; D5BD321738E03967CA8E27C6 /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; D628C0489129065C23B33107 /* ServiceEntrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2234FFBE7F556D1372AFB42D /* ServiceEntrySpec.swift */; }; - D688F61360D46A16B0678BA4 /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BFF4BA99493C54260878C4 /* ObjectScope.swift */; }; D6AA597218691F1FE87724E7 /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = A10187BB3A994165E7FC1528 /* ScopedBinding.swift */; }; - D7C2A6D05BD948EA1E3B26FB /* SynchronizedResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4040F8D091ED67C84E2B8854 /* SynchronizedResolver.swift */; }; D7D5560E4F790F41126F61CF /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; D7DE20CC15F3A6BD09E43A75 /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; D7DFD1B77BFB5FABAE165A11 /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; D86ACC6D9B9C62FF398F8293 /* TaggedTypeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */; }; D88115BD7D62C38F04045EF0 /* ContainerSpec.GraphCaching.swift in Sources */ = {isa = PBXBuildFile; fileRef = D366825BB9272905C79AEA47 /* ContainerSpec.GraphCaching.swift */; }; D88D7841C5C84A2E34CE15FD /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92B8E618A08408404FB2A7A /* TypeBinder.swift */; }; - D8E2986FB186B630E54B60CD /* GraphIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E95633441FFB44D8A05585C /* GraphIdentifier.swift */; }; D98CA679A3AAC176D291CA8E /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEE8FDF4B975A8F2A9FCC5FF /* Food.swift */; }; DA6CB0A98FE5968CAAFDE9BF /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9985BEF966DCBB28B12BE17B /* Person.swift */; }; DB14CA46130A816F6FAADE92 /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C074BAC560F277E806146C60 /* SimpleBinding.swift */; }; DC5C3A946BDA224C388D2438 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 359BCD3DA6F0CC2241878C82 /* EmploymentAssembly.swift */; }; DD1B936DC7365917DCA09FC8 /* Quick.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 823617F3B8A9192F56B13331 /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; DD4783AE23A8C2A89F591605 /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59111BE319C59E4CD6CF68CD /* Assembler.swift */; }; - DDFC9466110B6C18B2DCCD34 /* SynchronizedResolver.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 869CA0001EA621843F1EF2BB /* SynchronizedResolver.Arguments.swift */; }; DE0A534B660AA93F73A2CB41 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; DEB3F135FFAEBF825881E886 /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; E0D7B3285AA1FE51E14A52A1 /* BindingKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = A24B4E8F1CA18603DBB6884A /* BindingKey.swift */; }; - E2E66C47DB6C2F99B13F01CF /* DebugHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F4982F617A2FF202637E57C /* DebugHelper.swift */; }; E34C98A8BF87513994A6AD86 /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; E423395FC7006DD82513F347 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; E484C3994AD91E91C454B11D /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; E584841CFD26155FB056C85A /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; E6E536A44F40492F42CA4044 /* ContainerSpec.DebugHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF340AF8DD2D821A225A36B3 /* ContainerSpec.DebugHelper.swift */; }; - E7383E65C483ED1E66A49C5C /* InstanceStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06A8ED72CD6241A2CDEA8479 /* InstanceStorage.swift */; }; E7E9DE84E1861D125F8D686A /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07B4728F7C73CC5530956A2 /* Resolver.swift */; }; E80558941BC2149C25A17495 /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; E8A89383E1D1106DEABB778B /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; @@ -355,9 +319,7 @@ EAC4EA9BAC87B34AD5BA2110 /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3586A4987B7C7C8122D674E /* SwinjectError.swift */; }; EAD0757CE0163D3549CB5405 /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; EC4EE4B0AECDBA8EC0B8F73D /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BA261FF01C5F5510873B3EC /* Animal.swift */; }; - ED346CAABC0FF77612D9E186 /* SynchronizedResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4040F8D091ED67C84E2B8854 /* SynchronizedResolver.swift */; }; EE5763938068B3FA56D1BA59 /* Resolver3.swift in Sources */ = {isa = PBXBuildFile; fileRef = C11D19C5F01647E4A576514A /* Resolver3.swift */; }; - EEA8C20EB41C7FF5168941A5 /* SpinLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 919757437CA99D0C506EC028 /* SpinLock.swift */; }; EEB1E43EF50551F8B9793381 /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59111BE319C59E4CD6CF68CD /* Assembler.swift */; }; EEB3FA667B9103A8417F5EA4 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; EEC04BEF02E6776003CC2003 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B580B43E1891812C97209 /* Binding.swift */; }; @@ -374,13 +336,11 @@ F78892037CEB565626A69451 /* ContainerSpec.DebugHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF340AF8DD2D821A225A36B3 /* ContainerSpec.DebugHelper.swift */; }; F7F9B3DB89AC8EC05B6A2B89 /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; F8DB4EDA0367BCC6832E4AA6 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; - FA44B27F082856C56051F088 /* InstanceStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06A8ED72CD6241A2CDEA8479 /* InstanceStorage.swift */; }; FAF8F8B75F63D43995A004E8 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; FB6FF5C5729B8E050616CCF6 /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 6EA4ECB5E4CEC9751AD36854 /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; FC120C659D0A6FB9CE757CB7 /* Resolver3.swift in Sources */ = {isa = PBXBuildFile; fileRef = C11D19C5F01647E4A576514A /* Resolver3.swift */; }; FCBA6B66A6BBA29B3EC6CDDD /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; FD1678ED0C9813A653D9C68B /* BinderEnvironmentSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */; }; - FD792405FD95651F8205BB2D /* FunctionType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F2567098AC12010C308E26D /* FunctionType.swift */; }; FDB7873663CEFBF7BE76ECFF /* BindingKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = A24B4E8F1CA18603DBB6884A /* BindingKey.swift */; }; FDCF96E2A442CDC6815B8127 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07B4728F7C73CC5530956A2 /* Resolver.swift */; }; /* End PBXBuildFile section */ @@ -474,14 +434,12 @@ /* Begin PBXFileReference section */ 03CDF95C1EAFCD54450B34B6 /* ServiceEntry.TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServiceEntry.TypeForwarding.swift; sourceTree = ""; }; 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.swift; sourceTree = ""; }; - 06A8ED72CD6241A2CDEA8479 /* InstanceStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceStorage.swift; sourceTree = ""; }; 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopedBindingSpec.swift; sourceTree = ""; }; 0E0B580B43E1891812C97209 /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; 10480F2154EAA0414D4C1F55 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */ = {isa = PBXFileReference; path = .swiftlint.yml; sourceTree = ""; }; + 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .swiftlint.yml; sourceTree = ""; }; 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SynchronizedResolverSpec.swift; sourceTree = ""; }; 13513FA012659ADE699A3608 /* LazySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LazySpec.swift; sourceTree = ""; }; - 17BEC193FDDE3BA488EA592E /* _Resolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = _Resolver.swift; sourceTree = ""; }; 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleBindingSpec.swift; sourceTree = ""; }; 1910A1471C3CA9EA86F350BA /* LoadAwareAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadAwareAssembly.swift; sourceTree = ""; }; 1AAFEBED373D3DD8E29B1131 /* SwinjectTests.xctest */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.cfbundle; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -498,27 +456,22 @@ 34AFFAC41BA9D02A38BDB7A3 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; 359BCD3DA6F0CC2241878C82 /* EmploymentAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmploymentAssembly.swift; sourceTree = ""; }; 36322E7DDA56C7E6DF006787 /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - 36BFF4BA99493C54260878C4 /* ObjectScope.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObjectScope.swift; sourceTree = ""; }; 38615FC8EEB466C5C1EAD21C /* ServiceEntry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServiceEntry.swift; sourceTree = ""; }; 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Swinject+Builder.swift"; sourceTree = ""; }; 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaggedTypeSpec.swift; sourceTree = ""; }; 3DECE1C39517B81037CC0D53 /* WeakStorageSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeakStorageSpec.swift; sourceTree = ""; }; 4021EB1EA6A2770920FAD979 /* ContextedResolverSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextedResolverSpec.swift; sourceTree = ""; }; - 4040F8D091ED67C84E2B8854 /* SynchronizedResolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SynchronizedResolver.swift; sourceTree = ""; }; 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingKeySpec.swift; sourceTree = ""; }; 42490D1D0C395951243F5CFF /* Container.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.swift; sourceTree = ""; }; 45CA41659767E1378A9F492B /* ServiceKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServiceKeySpec.swift; sourceTree = ""; }; 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTree.swift; sourceTree = ""; }; 494AA2AA587975747596C157 /* ProviderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProviderSpec.swift; sourceTree = ""; }; - 4E95633441FFB44D8A05585C /* GraphIdentifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphIdentifier.swift; sourceTree = ""; }; - 4F2567098AC12010C308E26D /* FunctionType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FunctionType.swift; sourceTree = ""; }; 5057BAB33984E3E33469452B /* Scope.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Scope.swift; sourceTree = ""; }; 5543571F82B41D79C35A0871 /* SwinjectTests.xctest */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.cfbundle; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Resolver+Injection.swift"; sourceTree = ""; }; 59111BE319C59E4CD6CF68CD /* Assembler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Assembler.swift; sourceTree = ""; }; 5AB605ED0F735221D0EB1D5F /* Convenience.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Convenience.swift; sourceTree = ""; }; 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Matchable.swift; sourceTree = ""; }; - 5F4982F617A2FF202637E57C /* DebugHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DebugHelper.swift; sourceTree = ""; }; 5F7BC1C4169BB4382C6D3E1F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 65D0BCCCD61CD9BECC29E064 /* Closable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Closable.swift; sourceTree = ""; }; 671D5D89472DAFA916814506 /* UnboundScopeSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnboundScopeSpec.swift; sourceTree = ""; }; @@ -533,10 +486,8 @@ 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistry.swift; sourceTree = ""; }; 823617F3B8A9192F56B13331 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; 841D83ADB41363D1E38087B4 /* NonGeneratedMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonGeneratedMocks.swift; sourceTree = ""; }; - 869CA0001EA621843F1EF2BB /* SynchronizedResolver.Arguments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SynchronizedResolver.Arguments.swift; sourceTree = ""; }; 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeneratedMocks.swift; sourceTree = ""; }; 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTreeBuilderSpec.swift; sourceTree = ""; }; - 919757437CA99D0C506EC028 /* SpinLock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpinLock.swift; sourceTree = ""; }; 9527A4CA5BCBA7AFA3596757 /* SwinjectSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectSpec.swift; sourceTree = ""; }; 95C2DBC728B763B04CB25963 /* Container.TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.TypeForwarding.swift; sourceTree = ""; }; 9620155728133F451B31C0AD /* Swinject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Swinject.swift; sourceTree = ""; }; @@ -562,7 +513,7 @@ C765B92B00C0AC8625BB4AC9 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; CADDB3E9E363310028AA5920 /* InstanceMaker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceMaker.swift; sourceTree = ""; }; CC85CB215058F95C0BC190B1 /* Bridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bridge.swift; sourceTree = ""; }; - D101B42AE242A5A00C319FAE /* ServiceKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServiceKey.swift; sourceTree = ""; }; + CD4D866322E4C6DB0042ACDC /* ObjectScope.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObjectScope.swift; sourceTree = ""; }; D1FA0377AF4799D42E9462FA /* BasicAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BasicAssembly.swift; sourceTree = ""; }; D366825BB9272905C79AEA47 /* ContainerSpec.GraphCaching.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.GraphCaching.swift; sourceTree = ""; }; DF340AF8DD2D821A225A36B3 /* ContainerSpec.DebugHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.DebugHelper.swift; sourceTree = ""; }; @@ -577,7 +528,6 @@ F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.TypeForwarding.swift; sourceTree = ""; }; FCAF491EC7DCD7477F9A0ECB /* SwinjectModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectModule.swift; sourceTree = ""; }; FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderEnvironmentSpec.swift; sourceTree = ""; }; - FD433AFA21FF52AF81A9C9B8 /* ObjectScope.Standard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObjectScope.Standard.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -688,7 +638,6 @@ 5F6AA1259C61A4D472220C36 /* 2.0 API */ = { isa = PBXGroup; children = ( - 17BEC193FDDE3BA488EA592E /* _Resolver.swift */, 59111BE319C59E4CD6CF68CD /* Assembler.swift */, F290F6B1207A0557A528220B /* Assembly.swift */, 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */, @@ -696,20 +645,11 @@ BE4B1E4BA98573B6FED2D118 /* Container.Logging.swift */, 42490D1D0C395951243F5CFF /* Container.swift */, 95C2DBC728B763B04CB25963 /* Container.TypeForwarding.swift */, - 5F4982F617A2FF202637E57C /* DebugHelper.swift */, - 4F2567098AC12010C308E26D /* FunctionType.swift */, - 4E95633441FFB44D8A05585C /* GraphIdentifier.swift */, - 06A8ED72CD6241A2CDEA8479 /* InstanceStorage.swift */, 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */, - FD433AFA21FF52AF81A9C9B8 /* ObjectScope.Standard.swift */, - 36BFF4BA99493C54260878C4 /* ObjectScope.swift */, + CD4D866322E4C6DB0042ACDC /* ObjectScope.swift */, C07B4728F7C73CC5530956A2 /* Resolver.swift */, 38615FC8EEB466C5C1EAD21C /* ServiceEntry.swift */, 03CDF95C1EAFCD54450B34B6 /* ServiceEntry.TypeForwarding.swift */, - D101B42AE242A5A00C319FAE /* ServiceKey.swift */, - 919757437CA99D0C506EC028 /* SpinLock.swift */, - 869CA0001EA621843F1EF2BB /* SynchronizedResolver.Arguments.swift */, - 4040F8D091ED67C84E2B8854 /* SynchronizedResolver.swift */, ); path = "2.0 API"; sourceTree = ""; @@ -1284,16 +1224,10 @@ 7F22099B321798EAD85DBC07 /* Container.TypeForwarding.swift in Sources */, 0CED31C429BA9F9B23EB2B1F /* Container.swift in Sources */, 9EF6DF530041FC494572D3DB /* ContextedResolver.swift in Sources */, - 240057137A0476B5874B0BCB /* DebugHelper.swift in Sources */, - A1650894E467EA95327AEF5E /* FunctionType.swift in Sources */, - C5584C2C04564AFC0BCD3710 /* GraphIdentifier.swift in Sources */, 3547656EF55D129316B7C5E2 /* InstanceMaker.swift in Sources */, B61FAC17826BAFD2DC1C0E5E /* InstanceRequest.swift in Sources */, - FA44B27F082856C56051F088 /* InstanceStorage.swift in Sources */, 2DCEEF373F410202226D2DB5 /* InstanceWrapper.swift in Sources */, 9264E4C053A699FE01EAD232 /* Matchable.swift in Sources */, - 3E13E204659AF2DCE94D75CB /* ObjectScope.Standard.swift in Sources */, - 79772C34E5102A8E3003DBF8 /* ObjectScope.swift in Sources */, 5C4C106D138E771C872F5E80 /* Resolver+Injection.swift in Sources */, E7E9DE84E1861D125F8D686A /* Resolver.swift in Sources */, FC120C659D0A6FB9CE757CB7 /* Resolver3.swift in Sources */, @@ -1303,19 +1237,15 @@ 3F8EA877F153EE374FF8E31A /* ScopedBinding.swift in Sources */, 38FACA739BA59278725FAE67 /* ServiceEntry.TypeForwarding.swift in Sources */, EF25C3A81E568411233E6867 /* ServiceEntry.swift in Sources */, - 4BB09CCBB703AADD728BD796 /* ServiceKey.swift in Sources */, 8D71D83DB3F5D3655FB6C71D /* SimpleBinding.swift in Sources */, - A778AD223AF6C6E30BFFFC84 /* SpinLock.swift in Sources */, 15FA8361AB335F4CC372A52C /* Swinject+Builder.swift in Sources */, + CD4D866622E4C8A70042ACDC /* ObjectScope.swift in Sources */, 828C5B0915A8D08CF98F5F4C /* Swinject.swift in Sources */, EAC4EA9BAC87B34AD5BA2110 /* SwinjectError.swift in Sources */, 94615DB1AD57F1547933D8A5 /* SwinjectModule.swift in Sources */, 8F48909C95AA648D056A392B /* SwinjectTree.swift in Sources */, - 0CFCEE57963529ECA1FFD8C2 /* SynchronizedResolver.Arguments.swift in Sources */, - ED346CAABC0FF77612D9E186 /* SynchronizedResolver.swift in Sources */, 3B61931D1E9C0F7D1AAEDDF7 /* TypeBinder.swift in Sources */, 62986D0AAAE9D3934E125332 /* TypeDescriptor.swift in Sources */, - 39D7CF8F5563E3C1BDDEED93 /* _Resolver.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1433,16 +1363,10 @@ 5381C2CDA084C5BEF82D7521 /* Container.TypeForwarding.swift in Sources */, AAB6386F88442B22E9F7FF0E /* Container.swift in Sources */, C75EC8F8DD60676B120917EA /* ContextedResolver.swift in Sources */, - CC5509F4681D4489DB0D447E /* DebugHelper.swift in Sources */, - FD792405FD95651F8205BB2D /* FunctionType.swift in Sources */, - C16D64C4A1ABCF441BEB2EBE /* GraphIdentifier.swift in Sources */, 58CFFB8C98C465B9101AA9A8 /* InstanceMaker.swift in Sources */, 9AFDF0122A11B2E996B16C3D /* InstanceRequest.swift in Sources */, - E7383E65C483ED1E66A49C5C /* InstanceStorage.swift in Sources */, 3B2E8B8CF4825DB05B0233F8 /* InstanceWrapper.swift in Sources */, C50BFD826112288F1D693A30 /* Matchable.swift in Sources */, - A2745DCB0ACE7714C65CA2A9 /* ObjectScope.Standard.swift in Sources */, - 401A790CF8450924114D89ED /* ObjectScope.swift in Sources */, 741344C30785507B22DF703B /* Resolver+Injection.swift in Sources */, FDCF96E2A442CDC6815B8127 /* Resolver.swift in Sources */, 2488CDD8D67CAC5C97BDF8B1 /* Resolver3.swift in Sources */, @@ -1452,19 +1376,15 @@ 73214A0BF7D4AE8B78DEB4FD /* ScopedBinding.swift in Sources */, 982E4682C79B74226C03E0C9 /* ServiceEntry.TypeForwarding.swift in Sources */, 908AE547955AE4432C1D161A /* ServiceEntry.swift in Sources */, - CA7DED9FF907336CB6091795 /* ServiceKey.swift in Sources */, DB14CA46130A816F6FAADE92 /* SimpleBinding.swift in Sources */, - EEA8C20EB41C7FF5168941A5 /* SpinLock.swift in Sources */, FCBA6B66A6BBA29B3EC6CDDD /* Swinject+Builder.swift in Sources */, + CD4D866822E4C8A80042ACDC /* ObjectScope.swift in Sources */, B5048A00D49FD5C1C098EE01 /* Swinject.swift in Sources */, 439254FAE8DF567DE9659ADA /* SwinjectError.swift in Sources */, AA6651CFD4090465E7CB7871 /* SwinjectModule.swift in Sources */, 4DA000959B4D60B509859810 /* SwinjectTree.swift in Sources */, - DDFC9466110B6C18B2DCCD34 /* SynchronizedResolver.Arguments.swift in Sources */, - D7C2A6D05BD948EA1E3B26FB /* SynchronizedResolver.swift in Sources */, 5D2C492FD5088FCB2BA5CDB8 /* TypeBinder.swift in Sources */, 03005DC48E35AEF37251FADC /* TypeDescriptor.swift in Sources */, - 5541D9BB4DF2EBB3E7325359 /* _Resolver.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1582,16 +1502,10 @@ 0DFB6FB4DF6A713EA545930F /* Container.TypeForwarding.swift in Sources */, C8F1F075F5792C9936B0577D /* Container.swift in Sources */, 6BFA0D58FD4131D3A2248208 /* ContextedResolver.swift in Sources */, - E2E66C47DB6C2F99B13F01CF /* DebugHelper.swift in Sources */, - D1E4114EED19E341BB80869A /* FunctionType.swift in Sources */, - D8E2986FB186B630E54B60CD /* GraphIdentifier.swift in Sources */, 48714C7B99D346C83E1E8293 /* InstanceMaker.swift in Sources */, 04C24C140F2D0BBFE48C682C /* InstanceRequest.swift in Sources */, - 9D99BBDFE65AC69067BC569C /* InstanceStorage.swift in Sources */, 53DC7093FD7C2FEE16154DED /* InstanceWrapper.swift in Sources */, DEB3F135FFAEBF825881E886 /* Matchable.swift in Sources */, - 61FA449BF10682C9E89E767F /* ObjectScope.Standard.swift in Sources */, - D688F61360D46A16B0678BA4 /* ObjectScope.swift in Sources */, 1C2F5A09F986586F85FAC3E8 /* Resolver+Injection.swift in Sources */, 8108969F33C37040624E0D02 /* Resolver.swift in Sources */, EE5763938068B3FA56D1BA59 /* Resolver3.swift in Sources */, @@ -1601,19 +1515,15 @@ D6AA597218691F1FE87724E7 /* ScopedBinding.swift in Sources */, 78ACD9EBF8625ECD24103A17 /* ServiceEntry.TypeForwarding.swift in Sources */, EABC31077D2369311E6C14C3 /* ServiceEntry.swift in Sources */, - ABA204BE7AEAC01BF1D6002E /* ServiceKey.swift in Sources */, 35175F8F168EDB5EB83BD8E9 /* SimpleBinding.swift in Sources */, - 939769201BD93B84E6BAD258 /* SpinLock.swift in Sources */, D18275ADB0E56D3087894518 /* Swinject+Builder.swift in Sources */, + CD4D866522E4C8A50042ACDC /* ObjectScope.swift in Sources */, 9E084F679592ADFA28D3AD6D /* Swinject.swift in Sources */, AAC84D757FE8F601FF053923 /* SwinjectError.swift in Sources */, 5570E14A839D4065FFBA7EF4 /* SwinjectModule.swift in Sources */, E8A89383E1D1106DEABB778B /* SwinjectTree.swift in Sources */, - 01146C3ECC9A6B1973EED93F /* SynchronizedResolver.Arguments.swift in Sources */, - 9C81098E44AF728D63640DA1 /* SynchronizedResolver.swift in Sources */, 050982D62AE0244372456440 /* TypeBinder.swift in Sources */, 572CA6A9E19927F5D434BB6F /* TypeDescriptor.swift in Sources */, - D0F428B5C92CA0C25EF4BE61 /* _Resolver.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1633,16 +1543,10 @@ 782801544D9F468F536E045E /* Container.TypeForwarding.swift in Sources */, 91DAE32F86CEA897AD52AEDB /* Container.swift in Sources */, 151340C24653963B97464BA9 /* ContextedResolver.swift in Sources */, - 16727D477E4258A547C21D93 /* DebugHelper.swift in Sources */, - 087E0E3216DB7D53DE7A6BE0 /* FunctionType.swift in Sources */, - 457481A631CA1253094D108B /* GraphIdentifier.swift in Sources */, 41EEA4724CD401F38F9622E3 /* InstanceMaker.swift in Sources */, 5E74770DDD69EAFE5D187F90 /* InstanceRequest.swift in Sources */, - 10EB88F976AC1025DC22FE8A /* InstanceStorage.swift in Sources */, 39F9BBD670C944E1331FAB13 /* InstanceWrapper.swift in Sources */, D3828F01A014F3A06B1141D7 /* Matchable.swift in Sources */, - 1F2E1C6B8F28C5441D52C033 /* ObjectScope.Standard.swift in Sources */, - 3AC304A612ECAED02C58BBF5 /* ObjectScope.swift in Sources */, 90B4143005C86717AC76B6EE /* Resolver+Injection.swift in Sources */, 66033468A5FC65C19B60086A /* Resolver.swift in Sources */, A3815641CEB5A06759D288E0 /* Resolver3.swift in Sources */, @@ -1652,19 +1556,15 @@ 6F5323F408E5708076C02768 /* ScopedBinding.swift in Sources */, 51F2CD3C07148069167AB6E9 /* ServiceEntry.TypeForwarding.swift in Sources */, 4939B8B795061A74ADFC02D8 /* ServiceEntry.swift in Sources */, - B753AC265ABCEF3CBCE3C4CE /* ServiceKey.swift in Sources */, 87F8C64D9E8B4317C0C036E0 /* SimpleBinding.swift in Sources */, - 02CBAAF2DD5E7D589F997A27 /* SpinLock.swift in Sources */, D267BD55BBEDE3ECEC449472 /* Swinject+Builder.swift in Sources */, + CD4D866722E4C8A80042ACDC /* ObjectScope.swift in Sources */, 26C8D37F26408DC308A0CDA3 /* Swinject.swift in Sources */, 14AECF24B26ECEC8E9086FBB /* SwinjectError.swift in Sources */, 699DB780BD90A5AAAD5B4646 /* SwinjectModule.swift in Sources */, 192278AA7165EC3C2C12A4C2 /* SwinjectTree.swift in Sources */, - BF8E048DADB28763928A2ACC /* SynchronizedResolver.Arguments.swift in Sources */, - 748FE5C55FB93BFFA9012CD3 /* SynchronizedResolver.swift in Sources */, D88D7841C5C84A2E34CE15FD /* TypeBinder.swift in Sources */, B95786317494375C0E2D2044 /* TypeDescriptor.swift in Sources */, - CE62237127502CCD13CC22C2 /* _Resolver.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1762,7 +1662,11 @@ ); INFOPLIST_FILE = Tests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SwinjectTests; SDKROOT = watchos; @@ -1786,7 +1690,10 @@ INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = Swinject; SDKROOT = macosx; @@ -1809,7 +1716,10 @@ INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = Swinject; SDKROOT = iphoneos; @@ -1856,7 +1766,10 @@ INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = Swinject; SDKROOT = appletvos; @@ -1878,7 +1791,11 @@ ); INFOPLIST_FILE = Tests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SwinjectTests; SDKROOT = appletvos; @@ -1948,7 +1865,11 @@ ); INFOPLIST_FILE = Tests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SwinjectTests; SDKROOT = iphoneos; @@ -1970,7 +1891,10 @@ INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = Swinject; SDKROOT = appletvos; @@ -2018,7 +1942,10 @@ INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = Swinject; SDKROOT = macosx; @@ -2041,7 +1968,10 @@ INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = Swinject; SDKROOT = iphoneos; @@ -2064,7 +1994,11 @@ ); INFOPLIST_FILE = Tests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SwinjectTests; SDKROOT = macosx; @@ -2083,7 +2017,11 @@ ); INFOPLIST_FILE = Tests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SwinjectTests; SDKROOT = appletvos; @@ -2104,7 +2042,11 @@ ); INFOPLIST_FILE = Tests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SwinjectTests; SDKROOT = macosx; @@ -2123,7 +2065,11 @@ ); INFOPLIST_FILE = Tests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SwinjectTests; SDKROOT = watchos; @@ -2144,7 +2090,11 @@ ); INFOPLIST_FILE = Tests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SwinjectTests; SDKROOT = iphoneos; From 1ee34680c16df1bce2e054784483939484247390 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 21 Jul 2019 18:40:28 +0200 Subject: [PATCH 089/239] Remove specs testing implementation details of 2.0 API --- Sources/2.0 API/ServiceEntry.swift | 4 +- Swinject.xcodeproj/project.pbxproj | 60 ------- Tests/2.0 API/BehaviorFakes.swift | 2 +- Tests/2.0 API/ContainerSpec.CustomScope.swift | 87 ----------- Tests/2.0 API/ContainerSpec.DebugHelper.swift | 69 --------- .../2.0 API/ContainerSpec.GraphCaching.swift | 128 --------------- Tests/2.0 API/ContainerSpec.swift | 2 +- Tests/2.0 API/EmploymentAssembly.swift | 2 +- Tests/2.0 API/ServiceEntrySpec.swift | 26 ---- Tests/2.0 API/ServiceKeySpec.swift | 146 ------------------ Tests/2.0 API/SynchronizedResolverSpec.swift | 13 -- Tests/2.0 API/WeakStorageSpec.swift | 56 ------- 12 files changed, 6 insertions(+), 589 deletions(-) delete mode 100644 Tests/2.0 API/ContainerSpec.CustomScope.swift delete mode 100644 Tests/2.0 API/ContainerSpec.DebugHelper.swift delete mode 100644 Tests/2.0 API/ContainerSpec.GraphCaching.swift delete mode 100644 Tests/2.0 API/ServiceEntrySpec.swift delete mode 100644 Tests/2.0 API/ServiceKeySpec.swift delete mode 100644 Tests/2.0 API/WeakStorageSpec.swift diff --git a/Sources/2.0 API/ServiceEntry.swift b/Sources/2.0 API/ServiceEntry.swift index 499bc248..3bfe3651 100644 --- a/Sources/2.0 API/ServiceEntry.swift +++ b/Sources/2.0 API/ServiceEntry.swift @@ -4,7 +4,9 @@ /// The `ServiceEntry` class represents an entry of a registered service type. /// As a returned instance from a `register` method of a `Container`, some configurations can be added. -public final class ServiceEntry { +public struct ServiceEntry { + let objectScope: ObjectScope + /// Specifies the object scope to resolve the service. /// /// - Parameter scope: The `ObjectScopeProtocol` value. diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 6a0f36db..c92d5394 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -8,7 +8,6 @@ /* Begin PBXBuildFile section */ 01197582F81B8D30D7D4A8AF /* NonGeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841D83ADB41363D1E38087B4 /* NonGeneratedMocks.swift */; }; - 0125E3E8A17D6F2F0CE2F893 /* ContainerSpec.GraphCaching.swift in Sources */ = {isa = PBXBuildFile; fileRef = D366825BB9272905C79AEA47 /* ContainerSpec.GraphCaching.swift */; }; 013A1E1096BD1305A3A14493 /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1910A1471C3CA9EA86F350BA /* LoadAwareAssembly.swift */; }; 01D985B5F99817DEE0E0DAD1 /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */; }; 01F001388FD754499B18FFAC /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */; }; @@ -19,7 +18,6 @@ 0516305FEAEA5A677A6FA9B3 /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; 0539332D989C37CA34A5FB4F /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEE8FDF4B975A8F2A9FCC5FF /* Food.swift */; }; 0568E116A56DA02DA92BAC8E /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; - 07538993A345EEC62228247E /* ServiceEntrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2234FFBE7F556D1372AFB42D /* ServiceEntrySpec.swift */; }; 084187169E13A6E9E709297C /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; 0C24BE87E4F1CF7482DB3468 /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 273FB7A6277E0841E1570990 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 0C7996FAC479BA40B124F470 /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = ADD71387EBA54D7EF60D0089 /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -84,7 +82,6 @@ 3A2FE7C2BA76C096122F92ED /* UnboundScopeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 671D5D89472DAFA916814506 /* UnboundScopeSpec.swift */; }; 3B2E8B8CF4825DB05B0233F8 /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */; }; 3B61931D1E9C0F7D1AAEDDF7 /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92B8E618A08408404FB2A7A /* TypeBinder.swift */; }; - 3DA1F1126FD1FC935353F847 /* ServiceKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45CA41659767E1378A9F492B /* ServiceKeySpec.swift */; }; 3F04B9C7812B5E21DCE4D36C /* GeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */; }; 3F1FB19A735BE6E1FA749E75 /* SwinjectSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9527A4CA5BCBA7AFA3596757 /* SwinjectSpec.swift */; }; 3F8EA877F153EE374FF8E31A /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = A10187BB3A994165E7FC1528 /* ScopedBinding.swift */; }; @@ -93,7 +90,6 @@ 439254FAE8DF567DE9659ADA /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3586A4987B7C7C8122D674E /* SwinjectError.swift */; }; 4503217DA585B602EDE65742 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1FA0377AF4799D42E9462FA /* BasicAssembly.swift */; }; 4578AA4291288B21ABD74735 /* ContextedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4021EB1EA6A2770920FAD979 /* ContextedResolverSpec.swift */; }; - 45E5B568D6D0E7FC976DCDC1 /* ServiceKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45CA41659767E1378A9F492B /* ServiceKeySpec.swift */; }; 462054EB9666775B13C36132 /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */; }; 46A14FAA5AA73BE8A0397707 /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; 4735419DE3D63E556D07C663 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B580B43E1891812C97209 /* Binding.swift */; }; @@ -110,14 +106,11 @@ 4D0ABCA733720469F2240C31 /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */; }; 4D591BB725EAB0ACF9436900 /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 4DA000959B4D60B509859810 /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; - 509CD01E61B453F238D33973 /* ContainerSpec.DebugHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF340AF8DD2D821A225A36B3 /* ContainerSpec.DebugHelper.swift */; }; 50B230799AFB8C24D1F5CD5D /* SwinjectSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9527A4CA5BCBA7AFA3596757 /* SwinjectSpec.swift */; }; 51F2CD3C07148069167AB6E9 /* ServiceEntry.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03CDF95C1EAFCD54450B34B6 /* ServiceEntry.TypeForwarding.swift */; }; - 52E8D60BBA9177F35E823779 /* ContainerSpec.CustomScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 332BC41A010B0C5AEAFDF545 /* ContainerSpec.CustomScope.swift */; }; 5329D4D400755935B22C0881 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1FA0377AF4799D42E9462FA /* BasicAssembly.swift */; }; 5381C2CDA084C5BEF82D7521 /* Container.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C2DBC728B763B04CB25963 /* Container.TypeForwarding.swift */; }; 53DC7093FD7C2FEE16154DED /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */; }; - 53F72D1C7E26B52E5D548206 /* WeakStorageSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DECE1C39517B81037CC0D53 /* WeakStorageSpec.swift */; }; 549227903CFDDF4E8272C691 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; 54A1FEE340AC3A2413876AD2 /* ScopeRegistryKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */; }; 5570E14A839D4065FFBA7EF4 /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCAF491EC7DCD7477F9A0ECB /* SwinjectModule.swift */; }; @@ -127,10 +120,8 @@ 58C9D537D453BC7C7DC5C0C1 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 359BCD3DA6F0CC2241878C82 /* EmploymentAssembly.swift */; }; 58CFFB8C98C465B9101AA9A8 /* InstanceMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CADDB3E9E363310028AA5920 /* InstanceMaker.swift */; }; 58F7BDE8BB54898CA690BD24 /* StandardScopeRegistrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */; }; - 59E450454D5403C171E8CD20 /* ServiceEntrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2234FFBE7F556D1372AFB42D /* ServiceEntrySpec.swift */; }; 5B0ECCEBC6CB23571A9EDA38 /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */; }; 5BBBB5E7162B0429D7332DD4 /* SwinjectSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9527A4CA5BCBA7AFA3596757 /* SwinjectSpec.swift */; }; - 5C06BD3982896046EAA70C8C /* WeakStorageSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DECE1C39517B81037CC0D53 /* WeakStorageSpec.swift */; }; 5C4C106D138E771C872F5E80 /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; 5CADD5B13173034498BF4A5F /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BA261FF01C5F5510873B3EC /* Animal.swift */; }; 5CB4448E66F839C3915D6927 /* StandardScopeRegistrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */; }; @@ -154,13 +145,11 @@ 68A42DF14E0117A95B44148F /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C765B92B00C0AC8625BB4AC9 /* Quick.framework */; }; 699DB780BD90A5AAAD5B4646 /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCAF491EC7DCD7477F9A0ECB /* SwinjectModule.swift */; }; 6BFA0D58FD4131D3A2248208 /* ContextedResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBA3EF319F06A1B3B6C84C29 /* ContextedResolver.swift */; }; - 6C59839F450D54DB72D0D726 /* ContainerSpec.CustomScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 332BC41A010B0C5AEAFDF545 /* ContainerSpec.CustomScope.swift */; }; 6C980EED98CBEADFD6DAA72A /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B3797A6BB56AE76CEC19F2A /* SwinjectApiSpec.swift */; }; 6DCE3C30CAE0350C428154DC /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; 6F5323F408E5708076C02768 /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = A10187BB3A994165E7FC1528 /* ScopedBinding.swift */; }; 70268F222B8478BDC084E211 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; 705F51FD21F7E1536BFC0C41 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B580B43E1891812C97209 /* Binding.swift */; }; - 714EFF2818A5DE7278A522BB /* ContainerSpec.CustomScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 332BC41A010B0C5AEAFDF545 /* ContainerSpec.CustomScope.swift */; }; 71674FB84CBE1E97B72123BF /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9985BEF966DCBB28B12BE17B /* Person.swift */; }; 71C4A75D54446D844BA5FB85 /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; 73214A0BF7D4AE8B78DEB4FD /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = A10187BB3A994165E7FC1528 /* ScopedBinding.swift */; }; @@ -172,15 +161,12 @@ 7845113EAF8FFAFD5EC10540 /* BindingKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */; }; 788AE378F10DA216265FFF52 /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; 78ACD9EBF8625ECD24103A17 /* ServiceEntry.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03CDF95C1EAFCD54450B34B6 /* ServiceEntry.TypeForwarding.swift */; }; - 79814146B3796F42B447326D /* ServiceEntrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2234FFBE7F556D1372AFB42D /* ServiceEntrySpec.swift */; }; - 7A9246A43400FC1504683E20 /* ServiceKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45CA41659767E1378A9F492B /* ServiceKeySpec.swift */; }; 7DD047C203659BCA7F04E48D /* Container.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C13D01A2DE6F53DF3175D22 /* Container.Arguments.swift */; }; 7E0539C5CD130F0AC4B02096 /* Container.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C13D01A2DE6F53DF3175D22 /* Container.Arguments.swift */; }; 7E9CB14F7E723994920F6E44 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 34AFFAC41BA9D02A38BDB7A3 /* Nimble.framework */; }; 7F22099B321798EAD85DBC07 /* Container.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C2DBC728B763B04CB25963 /* Container.TypeForwarding.swift */; }; 8108969F33C37040624E0D02 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07B4728F7C73CC5530956A2 /* Resolver.swift */; }; 816F47E9D87CAE910091B484 /* Closable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D0BCCCD61CD9BECC29E064 /* Closable.swift */; }; - 81CCC69088D0ADF8E0DC72AC /* ServiceKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45CA41659767E1378A9F492B /* ServiceKeySpec.swift */; }; 828C5B0915A8D08CF98F5F4C /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; 833635A5D695AA696559C250 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 359BCD3DA6F0CC2241878C82 /* EmploymentAssembly.swift */; }; 86BE1ED67D6C0A493A9F141A /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 683A1FB7D7F4E9508D57E936 /* Quick.framework */; }; @@ -198,7 +184,6 @@ 8D58DF5C6963153A8B17D325 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; 8D71D83DB3F5D3655FB6C71D /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C074BAC560F277E806146C60 /* SimpleBinding.swift */; }; 8D75A0A4A84E2B46E264B5FB /* ContextedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4021EB1EA6A2770920FAD979 /* ContextedResolverSpec.swift */; }; - 8DBFFFD80828247AED253B0D /* ContainerSpec.GraphCaching.swift in Sources */ = {isa = PBXBuildFile; fileRef = D366825BB9272905C79AEA47 /* ContainerSpec.GraphCaching.swift */; }; 8E1BBA6F7B45E1DF056670AC /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 273FB7A6277E0841E1570990 /* Nimble.framework */; }; 8E9E1BD32B056F472DA14E51 /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1C58FC14EEA170B0DC079DE4 /* Quick.framework */; }; 8F48909C95AA648D056A392B /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; @@ -224,7 +209,6 @@ 9B04477B2B117122CB99989A /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1910A1471C3CA9EA86F350BA /* LoadAwareAssembly.swift */; }; 9B83FF80C5BE658ED0F7B709 /* ScopedBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */; }; 9B9AA902B80620568D732D7B /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; - 9BAAD1DEBA041700C921A589 /* WeakStorageSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DECE1C39517B81037CC0D53 /* WeakStorageSpec.swift */; }; 9C08C2D57E0B0B46D5748B6C /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; 9CEF62C5A3EC3CB8034F08BB /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1910A1471C3CA9EA86F350BA /* LoadAwareAssembly.swift */; }; 9D1AD9CBA32CEE29EF6C68C2 /* GeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */; }; @@ -245,7 +229,6 @@ A4EA3E548D1CAB029697B0A9 /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; A54B018EF21348D600F8ABD2 /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */; }; A600D3F52D38EBC5A3C75CC2 /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */; }; - A6A470DC3A6D310AA0671075 /* ContainerSpec.CustomScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 332BC41A010B0C5AEAFDF545 /* ContainerSpec.CustomScope.swift */; }; AA6651CFD4090465E7CB7871 /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCAF491EC7DCD7477F9A0ECB /* SwinjectModule.swift */; }; AAB6386F88442B22E9F7FF0E /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42490D1D0C395951243F5CFF /* Container.swift */; }; AAC84D757FE8F601FF053923 /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3586A4987B7C7C8122D674E /* SwinjectError.swift */; }; @@ -264,7 +247,6 @@ C15318646655D97EBDCAA67B /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B3797A6BB56AE76CEC19F2A /* SwinjectApiSpec.swift */; }; C37B885879F0D716B36E1C5B /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 74DE57FB3E8228904E6FE0D7 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; C3AD37D47C38E5EB20FAF917 /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; - C493D6AD1D8748A2698F0B81 /* ContainerSpec.DebugHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF340AF8DD2D821A225A36B3 /* ContainerSpec.DebugHelper.swift */; }; C50BFD826112288F1D693A30 /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; C6ED278B6F0E08A4B1E57C45 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; C75EC8F8DD60676B120917EA /* ContextedResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBA3EF319F06A1B3B6C84C29 /* ContextedResolver.swift */; }; @@ -282,19 +264,16 @@ D18275ADB0E56D3087894518 /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; D2391A103E7356AD7E08F5BA /* ScopedBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */; }; D267BD55BBEDE3ECEC449472 /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; - D29AAB45717CC7988EC72163 /* WeakStorageSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DECE1C39517B81037CC0D53 /* WeakStorageSpec.swift */; }; D3828F01A014F3A06B1141D7 /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; D42D98955F4F78E3FC91803E /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; D4939ABFFDAE2A5768D23C65 /* StandardScopeRegistrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */; }; D557A108A21751DF75542692 /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; D5BD321738E03967CA8E27C6 /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; - D628C0489129065C23B33107 /* ServiceEntrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2234FFBE7F556D1372AFB42D /* ServiceEntrySpec.swift */; }; D6AA597218691F1FE87724E7 /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = A10187BB3A994165E7FC1528 /* ScopedBinding.swift */; }; D7D5560E4F790F41126F61CF /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; D7DE20CC15F3A6BD09E43A75 /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; D7DFD1B77BFB5FABAE165A11 /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; D86ACC6D9B9C62FF398F8293 /* TaggedTypeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */; }; - D88115BD7D62C38F04045EF0 /* ContainerSpec.GraphCaching.swift in Sources */ = {isa = PBXBuildFile; fileRef = D366825BB9272905C79AEA47 /* ContainerSpec.GraphCaching.swift */; }; D88D7841C5C84A2E34CE15FD /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92B8E618A08408404FB2A7A /* TypeBinder.swift */; }; D98CA679A3AAC176D291CA8E /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEE8FDF4B975A8F2A9FCC5FF /* Food.swift */; }; DA6CB0A98FE5968CAAFDE9BF /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9985BEF966DCBB28B12BE17B /* Person.swift */; }; @@ -309,7 +288,6 @@ E423395FC7006DD82513F347 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; E484C3994AD91E91C454B11D /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; E584841CFD26155FB056C85A /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; - E6E536A44F40492F42CA4044 /* ContainerSpec.DebugHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF340AF8DD2D821A225A36B3 /* ContainerSpec.DebugHelper.swift */; }; E7E9DE84E1861D125F8D686A /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07B4728F7C73CC5530956A2 /* Resolver.swift */; }; E80558941BC2149C25A17495 /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; E8A89383E1D1106DEABB778B /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; @@ -328,12 +306,10 @@ EFCA30870DA55BC3572AF634 /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BA261FF01C5F5510873B3EC /* Animal.swift */; }; EFE89A258FE9EDFFE5F88FD0 /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 74DE57FB3E8228904E6FE0D7 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; F151A5040BB76E8E909D9D6B /* Container.Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE4B1E4BA98573B6FED2D118 /* Container.Logging.swift */; }; - F1931BC25DA64EF32EC42F86 /* ContainerSpec.GraphCaching.swift in Sources */ = {isa = PBXBuildFile; fileRef = D366825BB9272905C79AEA47 /* ContainerSpec.GraphCaching.swift */; }; F1D5D6A0A7679A14317617E1 /* GeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */; }; F4D2218805AEBF797A2945AB /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEE8FDF4B975A8F2A9FCC5FF /* Food.swift */; }; F4D7CC563B9C212A418C4EBC /* ScopeRegistryKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2902FD4C1A50263340A51FFB /* ScopeRegistryKeySpec.swift */; }; F50BA96120EDA5D470F4265C /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBDB67E0FC7B8BEE58EECFBB /* BehaviorFakes.swift */; }; - F78892037CEB565626A69451 /* ContainerSpec.DebugHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF340AF8DD2D821A225A36B3 /* ContainerSpec.DebugHelper.swift */; }; F7F9B3DB89AC8EC05B6A2B89 /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; F8DB4EDA0367BCC6832E4AA6 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; FAF8F8B75F63D43995A004E8 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; @@ -448,22 +424,18 @@ 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Circularity.swift; sourceTree = ""; }; 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Behavior.swift; sourceTree = ""; }; 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Arguments.swift; sourceTree = ""; }; - 2234FFBE7F556D1372AFB42D /* ServiceEntrySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServiceEntrySpec.swift; sourceTree = ""; }; 273FB7A6277E0841E1570990 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; 2902FD4C1A50263340A51FFB /* ScopeRegistryKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistryKeySpec.swift; sourceTree = ""; }; 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; - 332BC41A010B0C5AEAFDF545 /* ContainerSpec.CustomScope.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.CustomScope.swift; sourceTree = ""; }; 34AFFAC41BA9D02A38BDB7A3 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; 359BCD3DA6F0CC2241878C82 /* EmploymentAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmploymentAssembly.swift; sourceTree = ""; }; 36322E7DDA56C7E6DF006787 /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 38615FC8EEB466C5C1EAD21C /* ServiceEntry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServiceEntry.swift; sourceTree = ""; }; 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Swinject+Builder.swift"; sourceTree = ""; }; 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaggedTypeSpec.swift; sourceTree = ""; }; - 3DECE1C39517B81037CC0D53 /* WeakStorageSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeakStorageSpec.swift; sourceTree = ""; }; 4021EB1EA6A2770920FAD979 /* ContextedResolverSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextedResolverSpec.swift; sourceTree = ""; }; 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingKeySpec.swift; sourceTree = ""; }; 42490D1D0C395951243F5CFF /* Container.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.swift; sourceTree = ""; }; - 45CA41659767E1378A9F492B /* ServiceKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServiceKeySpec.swift; sourceTree = ""; }; 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTree.swift; sourceTree = ""; }; 494AA2AA587975747596C157 /* ProviderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProviderSpec.swift; sourceTree = ""; }; 5057BAB33984E3E33469452B /* Scope.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Scope.swift; sourceTree = ""; }; @@ -515,8 +487,6 @@ CC85CB215058F95C0BC190B1 /* Bridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bridge.swift; sourceTree = ""; }; CD4D866322E4C6DB0042ACDC /* ObjectScope.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObjectScope.swift; sourceTree = ""; }; D1FA0377AF4799D42E9462FA /* BasicAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BasicAssembly.swift; sourceTree = ""; }; - D366825BB9272905C79AEA47 /* ContainerSpec.GraphCaching.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.GraphCaching.swift; sourceTree = ""; }; - DF340AF8DD2D821A225A36B3 /* ContainerSpec.DebugHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.DebugHelper.swift; sourceTree = ""; }; E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRequest.swift; sourceTree = ""; }; E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; EA7A547FC60DBD02D132B3E6 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -764,10 +734,7 @@ 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */, BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */, ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */, - 332BC41A010B0C5AEAFDF545 /* ContainerSpec.CustomScope.swift */, 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */, - DF340AF8DD2D821A225A36B3 /* ContainerSpec.DebugHelper.swift */, - D366825BB9272905C79AEA47 /* ContainerSpec.GraphCaching.swift */, 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */, F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */, 359BCD3DA6F0CC2241878C82 /* EmploymentAssembly.swift */, @@ -776,10 +743,7 @@ 1910A1471C3CA9EA86F350BA /* LoadAwareAssembly.swift */, 9985BEF966DCBB28B12BE17B /* Person.swift */, 494AA2AA587975747596C157 /* ProviderSpec.swift */, - 2234FFBE7F556D1372AFB42D /* ServiceEntrySpec.swift */, - 45CA41659767E1378A9F492B /* ServiceKeySpec.swift */, 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */, - 3DECE1C39517B81037CC0D53 /* WeakStorageSpec.swift */, ); path = "2.0 API"; sourceTree = ""; @@ -1264,10 +1228,7 @@ 4A9FFFF0FF25724AC5A0BB52 /* ContainerSpec.Arguments.swift in Sources */, A4EA3E548D1CAB029697B0A9 /* ContainerSpec.Behavior.swift in Sources */, 86E1845B6272AF95F1806CB4 /* ContainerSpec.Circularity.swift in Sources */, - 6C59839F450D54DB72D0D726 /* ContainerSpec.CustomScope.swift in Sources */, 93DCA2A58C4067D5E60F7ED1 /* ContainerSpec.CustomStringConvertible.swift in Sources */, - F78892037CEB565626A69451 /* ContainerSpec.DebugHelper.swift in Sources */, - F1931BC25DA64EF32EC42F86 /* ContainerSpec.GraphCaching.swift in Sources */, F8DB4EDA0367BCC6832E4AA6 /* ContainerSpec.TypeForwarding.swift in Sources */, 4C6D7AE29CB7E16431AACFA2 /* ContainerSpec.swift in Sources */, 8D75A0A4A84E2B46E264B5FB /* ContextedResolverSpec.swift in Sources */, @@ -1282,8 +1243,6 @@ 788AE378F10DA216265FFF52 /* ProviderSpec.swift in Sources */, 16FE1BC18A9DD0D21CAF2806 /* ScopeRegistryKeySpec.swift in Sources */, D2391A103E7356AD7E08F5BA /* ScopedBindingSpec.swift in Sources */, - 79814146B3796F42B447326D /* ServiceEntrySpec.swift in Sources */, - 45E5B568D6D0E7FC976DCDC1 /* ServiceKeySpec.swift in Sources */, 91FED72828F68263D599B6C0 /* SimpleBindingSpec.swift in Sources */, 5CB4448E66F839C3915D6927 /* StandardScopeRegistrySpec.swift in Sources */, A4C25E4406175163B7C5B810 /* SwinjectApiSpec.swift in Sources */, @@ -1294,7 +1253,6 @@ B1B107E3FA2DC2E985160D75 /* TestModels.swift in Sources */, B9FAEC69210B352FC744079E /* TypeBinderSpec.swift in Sources */, 3A2FE7C2BA76C096122F92ED /* UnboundScopeSpec.swift in Sources */, - 5C06BD3982896046EAA70C8C /* WeakStorageSpec.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1313,10 +1271,7 @@ 0516305FEAEA5A677A6FA9B3 /* ContainerSpec.Arguments.swift in Sources */, 2BD8335377FA7F918849C815 /* ContainerSpec.Behavior.swift in Sources */, 37FE9A9C76DB50ABB28AF9BE /* ContainerSpec.Circularity.swift in Sources */, - 714EFF2818A5DE7278A522BB /* ContainerSpec.CustomScope.swift in Sources */, E423395FC7006DD82513F347 /* ContainerSpec.CustomStringConvertible.swift in Sources */, - E6E536A44F40492F42CA4044 /* ContainerSpec.DebugHelper.swift in Sources */, - 0125E3E8A17D6F2F0CE2F893 /* ContainerSpec.GraphCaching.swift in Sources */, FAF8F8B75F63D43995A004E8 /* ContainerSpec.TypeForwarding.swift in Sources */, C797CCF413DF181935DAB58C /* ContainerSpec.swift in Sources */, 76B3D9DBF8D5593F67A7B7E6 /* ContextedResolverSpec.swift in Sources */, @@ -1331,8 +1286,6 @@ 03E7834C4448A5D939948CCF /* ProviderSpec.swift in Sources */, 86CD1F46C15A352BCF7CE396 /* ScopeRegistryKeySpec.swift in Sources */, 9B83FF80C5BE658ED0F7B709 /* ScopedBindingSpec.swift in Sources */, - D628C0489129065C23B33107 /* ServiceEntrySpec.swift in Sources */, - 7A9246A43400FC1504683E20 /* ServiceKeySpec.swift in Sources */, 8AEB5894656086C3E2F022FD /* SimpleBindingSpec.swift in Sources */, D4939ABFFDAE2A5768D23C65 /* StandardScopeRegistrySpec.swift in Sources */, 6C980EED98CBEADFD6DAA72A /* SwinjectApiSpec.swift in Sources */, @@ -1343,7 +1296,6 @@ 549227903CFDDF4E8272C691 /* TestModels.swift in Sources */, 22837E727E47A3B8A588AB78 /* TypeBinderSpec.swift in Sources */, 0D6143A7732F1334275D3658 /* UnboundScopeSpec.swift in Sources */, - 53F72D1C7E26B52E5D548206 /* WeakStorageSpec.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1403,10 +1355,7 @@ C7BB5752C697E748B828C03B /* ContainerSpec.Arguments.swift in Sources */, 4C89DEC934923C4BBF6A3616 /* ContainerSpec.Behavior.swift in Sources */, EAD0757CE0163D3549CB5405 /* ContainerSpec.Circularity.swift in Sources */, - 52E8D60BBA9177F35E823779 /* ContainerSpec.CustomScope.swift in Sources */, 377EE35B80E8F91543B52F0C /* ContainerSpec.CustomStringConvertible.swift in Sources */, - 509CD01E61B453F238D33973 /* ContainerSpec.DebugHelper.swift in Sources */, - D88115BD7D62C38F04045EF0 /* ContainerSpec.GraphCaching.swift in Sources */, 5D241BBB39F54B8FA2BFF595 /* ContainerSpec.TypeForwarding.swift in Sources */, 37E07236E0E63570242CE23F /* ContainerSpec.swift in Sources */, 4578AA4291288B21ABD74735 /* ContextedResolverSpec.swift in Sources */, @@ -1421,8 +1370,6 @@ 261D54C316CB625359F7EE97 /* ProviderSpec.swift in Sources */, 9623C7F8B9FED0541D959708 /* ScopeRegistryKeySpec.swift in Sources */, 1CFCB38BC4EE2D3AAD40154E /* ScopedBindingSpec.swift in Sources */, - 59E450454D5403C171E8CD20 /* ServiceEntrySpec.swift in Sources */, - 3DA1F1126FD1FC935353F847 /* ServiceKeySpec.swift in Sources */, 35847FDC65085C6741D2A132 /* SimpleBindingSpec.swift in Sources */, 58F7BDE8BB54898CA690BD24 /* StandardScopeRegistrySpec.swift in Sources */, C15318646655D97EBDCAA67B /* SwinjectApiSpec.swift in Sources */, @@ -1433,7 +1380,6 @@ B7CE6F32765FC472CE205458 /* TestModels.swift in Sources */, EEE1C6EB43E2F4D480A7156A /* TypeBinderSpec.swift in Sources */, 65764CCFA94D4C0A0822507A /* UnboundScopeSpec.swift in Sources */, - D29AAB45717CC7988EC72163 /* WeakStorageSpec.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1452,10 +1398,7 @@ 871BB9B8221656F0189ABEC6 /* ContainerSpec.Arguments.swift in Sources */, 20823C309A5C58900CDFA8C3 /* ContainerSpec.Behavior.swift in Sources */, 9B9AA902B80620568D732D7B /* ContainerSpec.Circularity.swift in Sources */, - A6A470DC3A6D310AA0671075 /* ContainerSpec.CustomScope.swift in Sources */, E8D70420E8A3C91D01BC3B5B /* ContainerSpec.CustomStringConvertible.swift in Sources */, - C493D6AD1D8748A2698F0B81 /* ContainerSpec.DebugHelper.swift in Sources */, - 8DBFFFD80828247AED253B0D /* ContainerSpec.GraphCaching.swift in Sources */, 9F1C7A652660EA87BF599126 /* ContainerSpec.TypeForwarding.swift in Sources */, E80558941BC2149C25A17495 /* ContainerSpec.swift in Sources */, 199D71D592CEDF7400DA3D0A /* ContextedResolverSpec.swift in Sources */, @@ -1470,8 +1413,6 @@ E484C3994AD91E91C454B11D /* ProviderSpec.swift in Sources */, F4D7CC563B9C212A418C4EBC /* ScopeRegistryKeySpec.swift in Sources */, 0E8E5B08478EB883D9B52947 /* ScopedBindingSpec.swift in Sources */, - 07538993A345EEC62228247E /* ServiceEntrySpec.swift in Sources */, - 81CCC69088D0ADF8E0DC72AC /* ServiceKeySpec.swift in Sources */, 1ACC90951353E5F69899A833 /* SimpleBindingSpec.swift in Sources */, 8AAC0C68038E02A6049ABDC0 /* StandardScopeRegistrySpec.swift in Sources */, 5F008535F981266945B3968B /* SwinjectApiSpec.swift in Sources */, @@ -1482,7 +1423,6 @@ 8D58DF5C6963153A8B17D325 /* TestModels.swift in Sources */, 8F70C49F6F6D27A67CDB8F0C /* TypeBinderSpec.swift in Sources */, 100DC02D61F72A611B7CF6E3 /* UnboundScopeSpec.swift in Sources */, - 9BAAD1DEBA041700C921A589 /* WeakStorageSpec.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Tests/2.0 API/BehaviorFakes.swift b/Tests/2.0 API/BehaviorFakes.swift index 659d45ca..e9444ba5 100644 --- a/Tests/2.0 API/BehaviorFakes.swift +++ b/Tests/2.0 API/BehaviorFakes.swift @@ -5,7 +5,7 @@ @testable import Swinject class BehaviorSpy: Behavior { - var entries = [ServiceEntryProtocol]() + var entries = [Any]() var names = [String?]() var types = [Any.Type]() diff --git a/Tests/2.0 API/ContainerSpec.CustomScope.swift b/Tests/2.0 API/ContainerSpec.CustomScope.swift deleted file mode 100644 index 9d55abdb..00000000 --- a/Tests/2.0 API/ContainerSpec.CustomScope.swift +++ /dev/null @@ -1,87 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -import Nimble -import Quick -@testable import Swinject - -class ContainerSpec_CustomScope: QuickSpec { - override func spec() { - var container: Container! - beforeEach { - container = Container() - } - - describe("Resolving from custom scope") { - it("creates new instance storage for each service") { - var instances = 0 - let custom = ObjectScope(storageFactory: { instances += 1; return FakeStorage() }) - - container.register(Int.self) { _ in 0 }.inObjectScope(custom) - container.register(Double.self) { _ in 0 }.inObjectScope(custom) - _ = container.resolve(Int.self) - _ = container.resolve(Double.self) - - expect(instances) == 2 - } - it("stores instance to storage during resolution") { - let storage = FakeStorage() - let custom = ObjectScope(storageFactory: { storage }) - - container.register(Int.self) { _ in 42 }.inObjectScope(custom) - _ = container.resolve(Int.self) - - expect(storage.instance as? Int) == 42 - } - it("returns stored instance if storage is not empty") { - let storage = FakeStorage() - let custom = ObjectScope(storageFactory: { storage }) - - container.register(Int.self) { _ in 0 }.inObjectScope(custom) - storage.instance = 42 - let result = container.resolve(Int.self) - - expect(result) == 42 - } - } - describe("Resetting scope") { - it("removes instance from services in given scope") { - let storage = FakeStorage() - let custom = ObjectScope(storageFactory: { storage }) - - container.register(Int.self) { _ in 0 }.inObjectScope(custom) - storage.instance = 42 - container.resetObjectScope(custom) - - expect(storage.instance).to(beNil()) - } - it("does not remove instances from other scopes") { - let storage = FakeStorage() - let custom1 = ObjectScope(storageFactory: { storage }) - let custom2 = ObjectScope(storageFactory: FakeStorage.init) - - container.register(Int.self) { _ in 0 }.inObjectScope(custom1) - storage.instance = 42 - container.resetObjectScope(custom2) - - expect(storage.instance as? Int) == 42 - } - it("removes instance from service registered in parent container") { - let storage = FakeStorage() - let custom = ObjectScope(storageFactory: { storage }) - let child = Container(parent: container) - - container.register(Int.self) { _ in 0 }.inObjectScope(custom) - storage.instance = 42 - child.resetObjectScope(custom) - - expect(storage.instance).to(beNil()) - } - } - } -} - -private class FakeStorage: InstanceStorage { - var instance: Any? -} diff --git a/Tests/2.0 API/ContainerSpec.DebugHelper.swift b/Tests/2.0 API/ContainerSpec.DebugHelper.swift deleted file mode 100644 index ef05b34e..00000000 --- a/Tests/2.0 API/ContainerSpec.DebugHelper.swift +++ /dev/null @@ -1,69 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -import Nimble -import Quick -@testable import Swinject - -class ContainerSpec_DebugHelper: QuickSpec { - override func spec() { - var spy: DebugHelperSpy! - beforeEach { spy = DebugHelperSpy() } - - describe("resolution fails") { - it("should call debug helper with failing service and key") { - let container = Container(debugHelper: spy) - - _ = container._resolve(name: "name") { (_: (Int) -> Any) in 1 as Double } as Double? - - expect("\(spy.serviceType)") == "Double" - expect(spy.key) == ServiceKey( - serviceType: Double.self, - argumentsType: Int.self, - name: "name", - option: nil - ) - } - - it("should call helper with all registrations") { - let container = Container(debugHelper: spy) - container.register(Int.self) { _ in 0 } - container.register(Double.self) { _ in 0 } - - _ = container.resolve(String.self) - - expect(spy.availableRegistrations?.count) == 2 - } - - context("has parent container") { - it("should call helper with parent registrations") { - let parent = Container() - parent.register(Int.self) { _ in 0 } - let container = Container(parent: parent, debugHelper: spy) - container.register(Double.self) { _ in 0 } - - _ = container.resolve(String.self) - - expect(spy.availableRegistrations?.count) == 2 - } - } - } - } -} - -private class DebugHelperSpy: DebugHelper { - var serviceType: Any = "" - var key: ServiceKey? - var availableRegistrations: [ServiceKey: ServiceEntryProtocol]? - - func resolutionFailed( - serviceType: Service.Type, - key: ServiceKey, - availableRegistrations: [ServiceKey: ServiceEntryProtocol] - ) { - self.serviceType = serviceType - self.key = key - self.availableRegistrations = availableRegistrations - } -} diff --git a/Tests/2.0 API/ContainerSpec.GraphCaching.swift b/Tests/2.0 API/ContainerSpec.GraphCaching.swift deleted file mode 100644 index 457e4218..00000000 --- a/Tests/2.0 API/ContainerSpec.GraphCaching.swift +++ /dev/null @@ -1,128 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -import Nimble -import Quick -@testable import Swinject - -class ContainerSpec_GraphCaching: QuickSpec { - override func spec() { - var container: Container! - beforeEach { - container = Container() - } - - it("has a method for restoring a graph") { - container.restoreObjectGraph(GraphIdentifier()) - } - - describe("current object graph") { - it("is not nil during graph resolution") { - var identifier: GraphIdentifier? - container.register(Dog.self) { - identifier = ($0 as? Container)?.currentObjectGraph - return Dog() - } - - _ = container.resolve(Dog.self) - - expect(identifier).notTo(beNil()) - } - it("is different for separate graph resolutions") { - var identifiers = [GraphIdentifier?]() - container.register(Dog.self) { - identifiers.append(($0 as? Container)?.currentObjectGraph) - return Dog() - } - - _ = container.resolve(Dog.self) - _ = container.resolve(Dog.self) - - expect(identifiers).to(haveCount(2)) - expect(identifiers[0]) != identifiers[1] - } - it("is the same during graph resolution") { - var identifiers = [GraphIdentifier?]() - container.register(Dog.self) { - identifiers.append(($0 as? Container)?.currentObjectGraph) - _ = $0.resolve(Cat.self) - return Dog() - } - container.register(Cat.self) { - identifiers.append(($0 as? Container)?.currentObjectGraph) - return Cat() - } - - _ = container.resolve(Dog.self) - - expect(identifiers).to(haveCount(2)) - expect(identifiers[0]) == identifiers[1] - } - it("is nil outside the graph resolution") { - container.register(Dog.self) { _ in Dog() } - - expect(container.currentObjectGraph).to(beNil()) - _ = container.resolve(Dog.self) - expect(container.currentObjectGraph).to(beNil()) - } - } - describe("object graph restoration") { - it("uses restored identifier during graph resolution") { - let restoredIdentifier = GraphIdentifier() - var identifier: GraphIdentifier? - container.register(Dog.self) { - identifier = ($0 as? Container)?.currentObjectGraph - return Dog() - } - - container.restoreObjectGraph(restoredIdentifier) - _ = container.resolve(Dog.self) - - expect(identifier) == restoredIdentifier - } - } - describe("instance storage interaction") { - it("uses current graph identifier when manipulating instances") { - let spy = StorageSpy() - let graph = GraphIdentifier() - let scope = ObjectScope(storageFactory: { spy }) - container.register(Dog.self) { _ in Dog() }.inObjectScope(scope) - container.restoreObjectGraph(graph) - - _ = container.resolve(Dog.self) - - expect(spy.setterGraphs.last) == graph - expect(spy.getterGraphs.last) == graph - } - it("restores instances from previous graphs if available") { - var graph: GraphIdentifier! - container.register(Dog.self) { - graph = ($0 as? Container)?.currentObjectGraph - return Dog() - }.inObjectScope(.graph) - - let dog1 = container.resolve(Dog.self)! - container.restoreObjectGraph(graph) - let dog2 = container.resolve(Dog.self)! - - expect(dog1) === dog2 - } - } - } -} - -private class StorageSpy: InstanceStorage { - var setterGraphs = [GraphIdentifier]() - var getterGraphs = [GraphIdentifier]() - - var instance: Any? - func setInstance(_: Any?, inGraph graph: GraphIdentifier) { - setterGraphs.append(graph) - } - - func instance(inGraph graph: GraphIdentifier) -> Any? { - getterGraphs.append(graph) - return nil - } -} diff --git a/Tests/2.0 API/ContainerSpec.swift b/Tests/2.0 API/ContainerSpec.swift index b6f5e162..f765cbb9 100644 --- a/Tests/2.0 API/ContainerSpec.swift +++ b/Tests/2.0 API/ContainerSpec.swift @@ -366,7 +366,7 @@ class ContainerSpec: QuickSpec { } describe("Default object scope") { it("registers services with given object scope") { - let container = Container(parent: nil, debugHelper: LoggingDebugHelper(), defaultObjectScope: .weak) + let container = Container(parent: nil, defaultObjectScope: .weak) let serviceEntry = container.register(Animal.self) { _ in Siamese(name: "Siam") } expect(serviceEntry.objectScope) === ObjectScope.weak diff --git a/Tests/2.0 API/EmploymentAssembly.swift b/Tests/2.0 API/EmploymentAssembly.swift index 3f35e6e4..1259a77c 100644 --- a/Tests/2.0 API/EmploymentAssembly.swift +++ b/Tests/2.0 API/EmploymentAssembly.swift @@ -61,7 +61,7 @@ final class EmploymentAssembly: Assembly { providedCustomer: $0.resolve(Provider.self)! ) }.initCompleted { - if self.scope !== ObjectScope.transient { + if self.scope != ObjectScope.transient { $1.employer = $0.resolve(Employer.self) } }.inObjectScope(scope) diff --git a/Tests/2.0 API/ServiceEntrySpec.swift b/Tests/2.0 API/ServiceEntrySpec.swift deleted file mode 100644 index 546e8cd6..00000000 --- a/Tests/2.0 API/ServiceEntrySpec.swift +++ /dev/null @@ -1,26 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -import Nimble -import Quick -@testable import Swinject - -class ServiceEntrySpec: QuickSpec { - override func spec() { - it("has ObjectScope.graph as a default value of scope property.") { - let entry = ServiceEntry(serviceType: Int.self, argumentsType: Any.self, factory: { 0 }) - expect(entry.objectScope) === ObjectScope.graph - } - - it("has ObjectScope set to value from init.") { - let entry = ServiceEntry( - serviceType: Int.self, - argumentsType: Any.self, - factory: { 0 }, - objectScope: .weak - ) - expect(entry.objectScope) === ObjectScope.weak - } - } -} diff --git a/Tests/2.0 API/ServiceKeySpec.swift b/Tests/2.0 API/ServiceKeySpec.swift deleted file mode 100644 index 5d51159a..00000000 --- a/Tests/2.0 API/ServiceKeySpec.swift +++ /dev/null @@ -1,146 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -import Nimble -import Quick -@testable import Swinject - -// MARK: Option - -private struct Option: ServiceKeyOption { - let option: Int - - func isEqualTo(_ another: ServiceKeyOption) -> Bool { - guard let another = another as? Option else { - return false - } - - return option == another.option - } - - func hash(into hasher: inout Hasher) { - option.hash(into: &hasher) - } - - var description: String { - return "" - } -} - -// MARK: ServiceKeySpec - -class ServiceKeySpec: QuickSpec { - override func spec() { - describe("Without name") { - it("equals with the same factory type.") { - let key1 = ServiceKey(serviceType: Animal.self, argumentsType: Resolver.self) - let key2 = ServiceKey(serviceType: Animal.self, argumentsType: Resolver.self) - expect(key1) == key2 - expect(key1.hashValue) == key2.hashValue - - let key3 = ServiceKey(serviceType: Animal.self, argumentsType: (Resolver, String, Bool).self) - let key4 = ServiceKey(serviceType: Animal.self, argumentsType: (Resolver, String, Bool).self) - expect(key3) == key4 - expect(key3.hashValue) == key4.hashValue - } - it("does not equal with different service types in factory types.") { - let key1 = ServiceKey(serviceType: Person.self, argumentsType: Resolver.self) - let key2 = ServiceKey(serviceType: Animal.self, argumentsType: Resolver.self) - expect(key1) != key2 - expect(key1.hashValue) != key2.hashValue - } - it("does not equal with different arg types in factory types.") { - let key1 = ServiceKey(serviceType: Animal.self, argumentsType: (Resolver, String).self) - let key2 = ServiceKey(serviceType: Animal.self, argumentsType: (Resolver, String, Bool).self) - expect(key1) != key2 - expect(key1.hashValue) != key2.hashValue - - let key3 = ServiceKey(serviceType: Animal.self, argumentsType: (Resolver, String, Bool).self) - let key4 = ServiceKey(serviceType: Animal.self, argumentsType: (Resolver, String, Int).self) - expect(key3) != key4 - expect(key3.hashValue) != key4.hashValue - } - } - describe("With name") { - it("equals with the same name.") { - let key1 = ServiceKey(serviceType: Animal.self, argumentsType: Resolver.self, name: "my factory") - let key2 = ServiceKey(serviceType: Animal.self, argumentsType: Resolver.self, name: "my factory") - expect(key1) == key2 - expect(key1.hashValue) == key2.hashValue - - let key3 = ServiceKey( - serviceType: Animal.self, - argumentsType: (Resolver, String, Bool).self, - name: "my factory" - ) - let key4 = ServiceKey( - serviceType: Animal.self, - argumentsType: (Resolver, String, Bool).self, - name: "my factory" - ) - expect(key3) == key4 - expect(key3.hashValue) == key4.hashValue - } - it("does not equal with different names.") { - let key1 = ServiceKey(serviceType: Animal.self, argumentsType: Resolver.self, name: "my factory") - let key2 = ServiceKey(serviceType: Animal.self, argumentsType: Resolver.self, name: "your factory") - expect(key1) != key2 - expect(key1.hashValue) != key2.hashValue - - let key3 = ServiceKey( - serviceType: Animal.self, - argumentsType: (Resolver, String, Bool).self, - name: "my factory" - ) - let key4 = ServiceKey( - serviceType: Animal.self, - argumentsType: (Resolver, String, Bool).self, - name: "your factory" - ) - expect(key3) != key4 - expect(key3.hashValue) != key4.hashValue - } - } - describe("With option") { - it("equals with the same option.") { - let key1 = ServiceKey(serviceType: Animal.self, argumentsType: Resolver.self, option: Option(option: 1)) - let key2 = ServiceKey(serviceType: Animal.self, argumentsType: Resolver.self, option: Option(option: 1)) - expect(key1) == key2 - expect(key1.hashValue) == key2.hashValue - - let key3 = ServiceKey( - serviceType: Animal.self, - argumentsType: (Resolver, String, Bool).self, - option: Option(option: 1) - ) - let key4 = ServiceKey( - serviceType: Animal.self, - argumentsType: (Resolver, String, Bool).self, - option: Option(option: 1) - ) - expect(key3) == key4 - expect(key3.hashValue) == key4.hashValue - } - it("does not equal with different options.") { - let key1 = ServiceKey(serviceType: Animal.self, argumentsType: Resolver.self, option: Option(option: 1)) - let key2 = ServiceKey(serviceType: Animal.self, argumentsType: Resolver.self, option: Option(option: 2)) - expect(key1) != key2 - expect(key1.hashValue) != key2.hashValue - - let key3 = ServiceKey( - serviceType: Animal.self, - argumentsType: (Resolver, String, Bool).self, - option: Option(option: 1) - ) - let key4 = ServiceKey( - serviceType: Animal.self, - argumentsType: (Resolver, String, Bool).self, - option: Option(option: 2) - ) - expect(key3) != key4 - expect(key3.hashValue) != key4.hashValue - } - } - } -} diff --git a/Tests/2.0 API/SynchronizedResolverSpec.swift b/Tests/2.0 API/SynchronizedResolverSpec.swift index 5c833b39..d1bfa7cc 100644 --- a/Tests/2.0 API/SynchronizedResolverSpec.swift +++ b/Tests/2.0 API/SynchronizedResolverSpec.swift @@ -52,19 +52,6 @@ class SynchronizedResolverSpec: QuickSpec { runInObjectScope(.graph) runInObjectScope(.container) } - it("uses distinct graph identifier") { - var graphs = Set() - let container = Container { - $0.register(Dog.self) { - graphs.insert(($0 as! Container).currentObjectGraph!) - return Dog() - } - }.synchronize() - - onMultipleThreads { _ = container.resolve(Dog.self) } - - expect(graphs.count) == totalThreads - } } describe("Nested resolve") { it("can make it without deadlock") { diff --git a/Tests/2.0 API/WeakStorageSpec.swift b/Tests/2.0 API/WeakStorageSpec.swift deleted file mode 100644 index 1e49fd0d..00000000 --- a/Tests/2.0 API/WeakStorageSpec.swift +++ /dev/null @@ -1,56 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -import Foundation -import Nimble -import Quick -@testable import Swinject - -class WeakStorageSpec: QuickSpec { - override func spec() { - var storage: WeakStorage! - beforeEach { - storage = WeakStorage() - } - - describe("Storing reference type") { - context("there is strong reference to instance") { - it("should provide stored instance") { - let object = DummyObject() - storage.instance = object - expect(storage.instance as? DummyObject) === object - } - } - context("there is no strong reference to instace") { - it("should not persist instance") { - storage.instance = DummyObject() - expect(storage.instance).to(beNil()) - } - } - context("there is weak reference to instace") { - it("should not persist instance") { - var object: DummyObject? = DummyObject() - weak var weakObject = object - storage.instance = object - - object = nil - - expect(storage.instance).to(beNil()) - expect(weakObject).to(beNil()) - } - } - } - - describe("Storing value type") { - it("should not persist instance") { - let value = DummyStruct() - storage.instance = value - expect(storage.instance).to(beNil()) - } - } - } -} - -private struct DummyStruct {} -private class DummyObject {} From 52b89d034fa9716df33bd9849376c5be6998a94b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 21 Jul 2019 19:11:03 +0200 Subject: [PATCH 090/239] Draft service entry --- Sources/2.0 API/Container.swift | 19 +++++++++++----- Sources/2.0 API/ObjectScope.swift | 6 +++++ Sources/2.0 API/ServiceEntry.swift | 7 +++++- Swinject.xcodeproj/project.pbxproj | 22 +++++++++++++------ Tests/{2.0 API => Support/2.0}/Animal.swift | 0 .../2.0}/BasicAssembly.swift | 0 .../2.0}/BehaviorFakes.swift | 0 .../2.0}/EmploymentAssembly.swift | 0 Tests/{2.0 API => Support/2.0}/Food.swift | 0 .../2.0}/LoadAwareAssembly.swift | 0 Tests/{2.0 API => Support/2.0}/Person.swift | 0 11 files changed, 41 insertions(+), 13 deletions(-) rename Tests/{2.0 API => Support/2.0}/Animal.swift (100%) rename Tests/{2.0 API => Support/2.0}/BasicAssembly.swift (100%) rename Tests/{2.0 API => Support/2.0}/BehaviorFakes.swift (100%) rename Tests/{2.0 API => Support/2.0}/EmploymentAssembly.swift (100%) rename Tests/{2.0 API => Support/2.0}/Food.swift (100%) rename Tests/{2.0 API => Support/2.0}/LoadAwareAssembly.swift (100%) rename Tests/{2.0 API => Support/2.0}/Person.swift (100%) diff --git a/Sources/2.0 API/Container.swift b/Sources/2.0 API/Container.swift index b187a263..6e0e8199 100644 --- a/Sources/2.0 API/Container.swift +++ b/Sources/2.0 API/Container.swift @@ -20,6 +20,13 @@ import Foundation /// where `A` and `X` are protocols, `B` is a type conforming `A`, and `Y` is a type conforming `X` /// and depending on `A`. public final class Container { + private let defaultObjectScope: ObjectScope + private var bindings = [Binding]() + private var behaviors = [Behavior]() + private var swinject: Swinject { + Swinject(tree: SwinjectTree(bindings: bindings, includeEntries: [])) + } + /// Instantiates a `Container` /// /// - Parameters @@ -36,12 +43,14 @@ public final class Container { behaviors: [Behavior] = [], registeringClosure: (Container) -> Void = { _ in } ) { - fatalError() + self.defaultObjectScope = defaultObjectScope + self.behaviors = behaviors + registeringClosure(self) } /// Removes all registrations in the container. public func removeAll() { - fatalError() + bindings = [] } /// Discards instances for services registered in the given `ObjectsScopeProtocol`. @@ -52,7 +61,7 @@ public final class Container { /// - Parameters: /// - objectScope: All instances registered in given `ObjectsScopeProtocol` will be discarded. public func resetObjectScope(_ objectScope: ObjectScope) { - fatalError() + (objectScope.scope as? Closable)?.close() } /// Adds a registration for the specified service with the factory closure to specify how the service is @@ -83,7 +92,7 @@ public final class Container { /// /// - Returns: A synchronized container as `Resolver`. public func synchronize() -> Resolver { - fatalError() + self } /// Adds behavior to the container. `Behavior.container(_:didRegisterService:withName:)` will be invoked for @@ -92,7 +101,7 @@ public final class Container { /// - Parameters: /// - behavior: Behavior to be added to the container public func addBehavior(_ behavior: Behavior) { - fatalError() + behaviors.append(behavior) } } diff --git a/Sources/2.0 API/ObjectScope.swift b/Sources/2.0 API/ObjectScope.swift index c010aecb..8f4af814 100644 --- a/Sources/2.0 API/ObjectScope.swift +++ b/Sources/2.0 API/ObjectScope.swift @@ -21,3 +21,9 @@ public enum ObjectScope { /// when resolving the type. case weak } + + + +extension ObjectScope { + var scope: AnyScope? { nil } +} diff --git a/Sources/2.0 API/ServiceEntry.swift b/Sources/2.0 API/ServiceEntry.swift index 3bfe3651..17912e9c 100644 --- a/Sources/2.0 API/ServiceEntry.swift +++ b/Sources/2.0 API/ServiceEntry.swift @@ -5,7 +5,12 @@ /// The `ServiceEntry` class represents an entry of a registered service type. /// As a returned instance from a `register` method of a `Container`, some configurations can be added. public struct ServiceEntry { - let objectScope: ObjectScope + let key: AnyBindingKey + let maker: AnyInstanceMaker + var scope: AnyScope? + var initCompleted = [(Resolver, Service) -> Void]() + + var objectScope: ObjectScope? { return nil } /// Specifies the object scope to resolve the service. /// diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index c92d5394..f4b5a5f3 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -596,6 +596,7 @@ 4F46C48FA15F512EAED5F67A /* Support */ = { isa = PBXGroup; children = ( + CD4D866922E4CD990042ACDC /* 2.0 */, CC85CB215058F95C0BC190B1 /* Bridge.swift */, 5AB605ED0F735221D0EB1D5F /* Convenience.swift */, 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */, @@ -711,6 +712,20 @@ path = Carthage/Build; sourceTree = ""; }; + CD4D866922E4CD990042ACDC /* 2.0 */ = { + isa = PBXGroup; + children = ( + D1FA0377AF4799D42E9462FA /* BasicAssembly.swift */, + BBDB67E0FC7B8BEE58EECFBB /* BehaviorFakes.swift */, + 359BCD3DA6F0CC2241878C82 /* EmploymentAssembly.swift */, + EEE8FDF4B975A8F2A9FCC5FF /* Food.swift */, + 1910A1471C3CA9EA86F350BA /* LoadAwareAssembly.swift */, + 9985BEF966DCBB28B12BE17B /* Person.swift */, + 7BA261FF01C5F5510873B3EC /* Animal.swift */, + ); + path = 2.0; + sourceTree = ""; + }; D026A6699A2A932511D29E14 /* Sources */ = { isa = PBXGroup; children = ( @@ -726,10 +741,7 @@ F64B4AFEC15ABABB3014A636 /* 2.0 API */ = { isa = PBXGroup; children = ( - 7BA261FF01C5F5510873B3EC /* Animal.swift */, B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */, - D1FA0377AF4799D42E9462FA /* BasicAssembly.swift */, - BBDB67E0FC7B8BEE58EECFBB /* BehaviorFakes.swift */, 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */, 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */, BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */, @@ -737,11 +749,7 @@ 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */, 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */, F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */, - 359BCD3DA6F0CC2241878C82 /* EmploymentAssembly.swift */, - EEE8FDF4B975A8F2A9FCC5FF /* Food.swift */, 13513FA012659ADE699A3608 /* LazySpec.swift */, - 1910A1471C3CA9EA86F350BA /* LoadAwareAssembly.swift */, - 9985BEF966DCBB28B12BE17B /* Person.swift */, 494AA2AA587975747596C157 /* ProviderSpec.swift */, 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */, ); diff --git a/Tests/2.0 API/Animal.swift b/Tests/Support/2.0/Animal.swift similarity index 100% rename from Tests/2.0 API/Animal.swift rename to Tests/Support/2.0/Animal.swift diff --git a/Tests/2.0 API/BasicAssembly.swift b/Tests/Support/2.0/BasicAssembly.swift similarity index 100% rename from Tests/2.0 API/BasicAssembly.swift rename to Tests/Support/2.0/BasicAssembly.swift diff --git a/Tests/2.0 API/BehaviorFakes.swift b/Tests/Support/2.0/BehaviorFakes.swift similarity index 100% rename from Tests/2.0 API/BehaviorFakes.swift rename to Tests/Support/2.0/BehaviorFakes.swift diff --git a/Tests/2.0 API/EmploymentAssembly.swift b/Tests/Support/2.0/EmploymentAssembly.swift similarity index 100% rename from Tests/2.0 API/EmploymentAssembly.swift rename to Tests/Support/2.0/EmploymentAssembly.swift diff --git a/Tests/2.0 API/Food.swift b/Tests/Support/2.0/Food.swift similarity index 100% rename from Tests/2.0 API/Food.swift rename to Tests/Support/2.0/Food.swift diff --git a/Tests/2.0 API/LoadAwareAssembly.swift b/Tests/Support/2.0/LoadAwareAssembly.swift similarity index 100% rename from Tests/2.0 API/LoadAwareAssembly.swift rename to Tests/Support/2.0/LoadAwareAssembly.swift diff --git a/Tests/2.0 API/Person.swift b/Tests/Support/2.0/Person.swift similarity index 100% rename from Tests/2.0 API/Person.swift rename to Tests/Support/2.0/Person.swift From 33069f390bcd634423fbbf1a1a354c0f3a8137a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 21 Jul 2019 20:22:17 +0200 Subject: [PATCH 091/239] Use sourcery for code generation --- .swiftlint.yml | 8 +- Sources/2.0 API/Container+Arguments.swift | 161 ++++++ ....Logging.swift => Container+Logging.swift} | 0 ...g.swift => Container+TypeForwarding.swift} | 0 Sources/2.0 API/Container.Arguments.erb | 93 ---- Sources/2.0 API/Container.Arguments.swift | 498 ------------------ Sources/2.0 API/Container.swift | 36 +- Sources/2.0 API/ObjectScope.swift | 2 - ...esolver.swift => Resolver+LegacyApi.swift} | 192 +++---- ...wift => ServiceEntry+TypeForwarding.swift} | 43 +- .../SynchronizedResolver.Arguments.erb | 46 -- Sources/3.0 API/BinderEnvironment.swift | 50 +- Sources/3.0 API/Resolver+Injection.swift | 6 +- Sources/Core/Binding.swift | 2 +- Sources/Core/ContextedResolver.swift | 6 +- Sources/Core/InstanceMaker.swift | 6 +- .../Core/{Resolver3.swift => Resolver.swift} | 8 +- Sources/Core/ScopedBinding.swift | 8 +- Sources/Core/SimpleBinding.swift | 8 +- Sources/Core/Swinject.swift | 2 +- Swinject.xcodeproj/project.pbxproj | 136 ++--- Templates/Container+Arguments.swifttemplate | 27 + .../Resolver+LegacyApi.swifttemplate | 64 +-- .../ServiceEntry+TypeForwarding.swifttemplate | 35 +- Tests/Support/Convenience.swift | 6 +- Tests/Support/GeneratedMocks.swift | 24 +- Tests/Support/NonGeneratedMocks.swift | 8 +- Tests/Unit Specs/BinderEnvironmentSpec.swift | 178 +++---- Tests/Unit Specs/ContextedResolverSpec.swift | 12 +- Tests/Unit Specs/ScopedBindingSpec.swift | 10 +- Tests/Unit Specs/TypeBinderSpec.swift | 4 +- script/gencode | 8 - 32 files changed, 588 insertions(+), 1099 deletions(-) create mode 100644 Sources/2.0 API/Container+Arguments.swift rename Sources/2.0 API/{Container.Logging.swift => Container+Logging.swift} (100%) rename Sources/2.0 API/{Container.TypeForwarding.swift => Container+TypeForwarding.swift} (100%) delete mode 100644 Sources/2.0 API/Container.Arguments.erb delete mode 100644 Sources/2.0 API/Container.Arguments.swift rename Sources/2.0 API/{Resolver.swift => Resolver+LegacyApi.swift} (63%) rename Sources/2.0 API/{ServiceEntry.TypeForwarding.swift => ServiceEntry+TypeForwarding.swift} (78%) delete mode 100644 Sources/2.0 API/SynchronizedResolver.Arguments.erb rename Sources/Core/{Resolver3.swift => Resolver.swift} (62%) create mode 100644 Templates/Container+Arguments.swifttemplate rename Sources/2.0 API/Resolver.erb => Templates/Resolver+LegacyApi.swifttemplate (58%) rename Sources/2.0 API/ServiceEntry.TypeForwarding.erb => Templates/ServiceEntry+TypeForwarding.swifttemplate (53%) delete mode 100755 script/gencode diff --git a/.swiftlint.yml b/.swiftlint.yml index 0a19e39b..405f6902 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -6,8 +6,8 @@ included: - Sources - Tests excluded: - - Sources/2.0 API/Container.Arguments.swift - - Sources/2.0 API/SynchronizedResolver.Arguments.swift - - Sources/2.0 API/Resolver.swift - - Sources/2.0 API/ServiceEntry.TypeForwarding.swift + - Sources/2.0 API/Container+Arguments.swift + - Sources/2.0 API/SynchronizedResolver+Arguments.swift + - Sources/2.0 API/Resolver+LegacyApi.swift + - Sources/2.0 API/ServiceEntry+TypeForwarding.swift - Tests/Support/GeneratedMocks.swift diff --git a/Sources/2.0 API/Container+Arguments.swift b/Sources/2.0 API/Container+Arguments.swift new file mode 100644 index 00000000..7805ed3c --- /dev/null +++ b/Sources/2.0 API/Container+Arguments.swift @@ -0,0 +1,161 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +// sourcery:inline:ContainerArgumentsApi +extension Container { + /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. + /// + /// - Parameters: + /// - serviceType: The service type to register. + /// - name: A registration name, which is used to differentiate from other registrations + /// that have the same service and factory types. + /// - factory: The closure to specify how the service type is resolved with the dependencies of the type. + /// It is invoked when the `Container` needs to instantiate the instance. + /// It takes a `Resolver` instance and 1 argument to inject dependencies to the instance, + /// and returns the instance of the component type for the service. + /// + /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. + @discardableResult + public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1) -> Service) -> ServiceEntry { + fatalError() + } + + /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. + /// + /// - Parameters: + /// - serviceType: The service type to register. + /// - name: A registration name, which is used to differentiate from other registrations + /// that have the same service and factory types. + /// - factory: The closure to specify how the service type is resolved with the dependencies of the type. + /// It is invoked when the `Container` needs to instantiate the instance. + /// It takes a `Resolver` instance and 2 arguments to inject dependencies to the instance, + /// and returns the instance of the component type for the service. + /// + /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. + @discardableResult + public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2) -> Service) -> ServiceEntry { + fatalError() + } + + /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. + /// + /// - Parameters: + /// - serviceType: The service type to register. + /// - name: A registration name, which is used to differentiate from other registrations + /// that have the same service and factory types. + /// - factory: The closure to specify how the service type is resolved with the dependencies of the type. + /// It is invoked when the `Container` needs to instantiate the instance. + /// It takes a `Resolver` instance and 3 arguments to inject dependencies to the instance, + /// and returns the instance of the component type for the service. + /// + /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. + @discardableResult + public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3) -> Service) -> ServiceEntry { + fatalError() + } + + /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. + /// + /// - Parameters: + /// - serviceType: The service type to register. + /// - name: A registration name, which is used to differentiate from other registrations + /// that have the same service and factory types. + /// - factory: The closure to specify how the service type is resolved with the dependencies of the type. + /// It is invoked when the `Container` needs to instantiate the instance. + /// It takes a `Resolver` instance and 4 arguments to inject dependencies to the instance, + /// and returns the instance of the component type for the service. + /// + /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. + @discardableResult + public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) -> Service) -> ServiceEntry { + fatalError() + } + + /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. + /// + /// - Parameters: + /// - serviceType: The service type to register. + /// - name: A registration name, which is used to differentiate from other registrations + /// that have the same service and factory types. + /// - factory: The closure to specify how the service type is resolved with the dependencies of the type. + /// It is invoked when the `Container` needs to instantiate the instance. + /// It takes a `Resolver` instance and 5 arguments to inject dependencies to the instance, + /// and returns the instance of the component type for the service. + /// + /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. + @discardableResult + public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) -> Service) -> ServiceEntry { + fatalError() + } + + /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. + /// + /// - Parameters: + /// - serviceType: The service type to register. + /// - name: A registration name, which is used to differentiate from other registrations + /// that have the same service and factory types. + /// - factory: The closure to specify how the service type is resolved with the dependencies of the type. + /// It is invoked when the `Container` needs to instantiate the instance. + /// It takes a `Resolver` instance and 6 arguments to inject dependencies to the instance, + /// and returns the instance of the component type for the service. + /// + /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. + @discardableResult + public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6) -> Service) -> ServiceEntry { + fatalError() + } + + /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. + /// + /// - Parameters: + /// - serviceType: The service type to register. + /// - name: A registration name, which is used to differentiate from other registrations + /// that have the same service and factory types. + /// - factory: The closure to specify how the service type is resolved with the dependencies of the type. + /// It is invoked when the `Container` needs to instantiate the instance. + /// It takes a `Resolver` instance and 7 arguments to inject dependencies to the instance, + /// and returns the instance of the component type for the service. + /// + /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. + @discardableResult + public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7) -> Service) -> ServiceEntry { + fatalError() + } + + /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. + /// + /// - Parameters: + /// - serviceType: The service type to register. + /// - name: A registration name, which is used to differentiate from other registrations + /// that have the same service and factory types. + /// - factory: The closure to specify how the service type is resolved with the dependencies of the type. + /// It is invoked when the `Container` needs to instantiate the instance. + /// It takes a `Resolver` instance and 8 arguments to inject dependencies to the instance, + /// and returns the instance of the component type for the service. + /// + /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. + @discardableResult + public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8) -> Service) -> ServiceEntry { + fatalError() + } + + /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. + /// + /// - Parameters: + /// - serviceType: The service type to register. + /// - name: A registration name, which is used to differentiate from other registrations + /// that have the same service and factory types. + /// - factory: The closure to specify how the service type is resolved with the dependencies of the type. + /// It is invoked when the `Container` needs to instantiate the instance. + /// It takes a `Resolver` instance and 9 arguments to inject dependencies to the instance, + /// and returns the instance of the component type for the service. + /// + /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. + @discardableResult + public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9) -> Service) -> ServiceEntry { + fatalError() + } + +} +// sourcery:end diff --git a/Sources/2.0 API/Container.Logging.swift b/Sources/2.0 API/Container+Logging.swift similarity index 100% rename from Sources/2.0 API/Container.Logging.swift rename to Sources/2.0 API/Container+Logging.swift diff --git a/Sources/2.0 API/Container.TypeForwarding.swift b/Sources/2.0 API/Container+TypeForwarding.swift similarity index 100% rename from Sources/2.0 API/Container.TypeForwarding.swift rename to Sources/2.0 API/Container+TypeForwarding.swift diff --git a/Sources/2.0 API/Container.Arguments.erb b/Sources/2.0 API/Container.Arguments.erb deleted file mode 100644 index 4d32c739..00000000 --- a/Sources/2.0 API/Container.Arguments.erb +++ /dev/null @@ -1,93 +0,0 @@ -// -// Container.Arguments.swift -// Swinject -// -// Created by Yoichi Tagaya on 8/18/15. -// Copyright © 2015 Swinject Contributors. All rights reserved. -// - -// -// NOTICE: -// -// Container.Arguments.swift is generated from Container.Arguments.erb by ERB. -// Do NOT modify Container.Arguments.swift directly. -// Instead, modify Container.Arguments.erb and run `script/gencode` at the project root directory to generate the code. -// - -<% arg_count = 9 %> - -import Foundation - -// MARK: - Registeration with Arguments -extension Container { -<% (1..arg_count).each do |i| %> -<% arg_types = (1..i).map { |n| "Arg#{n}" }.join(", ") %> -<% arg_description = i == 1 ? "#{i} argument" : "#{i} arguments" %> - /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. - /// - /// - Parameters: - /// - serviceType: The service type to register. - /// - name: A registration name, which is used to differentiate from other registrations - /// that have the same service and factory types. - /// - factory: The closure to specify how the service type is resolved with the dependencies of the type. - /// It is invoked when the `Container` needs to instantiate the instance. - /// It takes a `Resolver` instance and <%= arg_description %> to inject dependencies to the instance, - /// and returns the instance of the component type for the service. - /// - /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. - @discardableResult - public func register>( - _ serviceType: Service.Type, - name: String? = nil, - factory: @escaping (Resolver, <%= arg_types %>) -> Service) -> ServiceEntry - { - return _register(serviceType, factory: factory, name: name) - } - -<% end %> -} - -// MARK: - Resolver with Arguments -extension Container { -<% (1..arg_count).each do |i| %> -<% arg_types = (1..i).map { |n| "Arg#{n}" }.join(", ") %> -<% arg_param_def = i == 1 ? "argument: Arg1" : "arguments arg1: Arg1, " + (2..i).map{ |n| "_ arg#{n}: Arg#{n}" }.join(", ") %> -<% arg_param_call = i == 1 ? "argument" : (1..i).map{ |n| "arg#{n}" }.join(", ") %> -<% arg_param_name = i == 1 ? "argument" : "arguments" %> -<% arg_param_type = i == 1 ? arg_types : "(" + arg_types + ")" %> -<% arg_param_description = i == 1 ? "#{i} argument" : "list of #{i} arguments" %> - /// Retrieves the instance with the specified service type and <%= arg_param_description %> to the factory closure. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - <%= arg_param_name %>: <%= arg_param_description.capitalize %> to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// and <%= arg_param_description %> is found in the `Container`. - public func resolve>( - _ serviceType: Service.Type, - <%= arg_param_def %>) -> Service? - { - return resolve(serviceType, name: nil, <%= arg_param_name %>: <%= arg_param_call %>) - } - - /// Retrieves the instance with the specified service type, <%= arg_param_description %> to the factory closure and registration name. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - name: The registration name. - /// - <%= arg_param_name %>: <%= arg_param_description.capitalize %> to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type, - /// <%= arg_param_description %> and name is found in the `Container`. - public func resolve>( - _ serviceType: Service.Type, - name: String?, - <%= arg_param_def %>) -> Service? - { - typealias FactoryType = ((Resolver, <%= arg_types %>)) -> Any - return _resolve(name: name) { (factory: FactoryType) in factory((self, <%= arg_param_call %>)) } - } - -<% end %> -} diff --git a/Sources/2.0 API/Container.Arguments.swift b/Sources/2.0 API/Container.Arguments.swift deleted file mode 100644 index db9963f5..00000000 --- a/Sources/2.0 API/Container.Arguments.swift +++ /dev/null @@ -1,498 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -// -// NOTICE: -// -// Container.Arguments.swift is generated from Container.Arguments.erb by ERB. -// Do NOT modify Container.Arguments.swift directly. -// Instead, modify Container.Arguments.erb and run `script/gencode` at the project root directory to generate the code. -// - -import Foundation - -// MARK: - Registeration with Arguments - -extension Container { - /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. - /// - /// - Parameters: - /// - serviceType: The service type to register. - /// - name: A registration name, which is used to differentiate from other registrations - /// that have the same service and factory types. - /// - factory: The closure to specify how the service type is resolved with the dependencies of the type. - /// It is invoked when the `Container` needs to instantiate the instance. - /// It takes a `Resolver` instance and 1 argument to inject dependencies to the instance, - /// and returns the instance of the component type for the service. - /// - /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. - @discardableResult - public func register( - _ serviceType: Service.Type, - name: String? = nil, - factory: @escaping (Resolver, Arg1) -> Service - ) -> ServiceEntry { - fatalError() - } - - /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. - /// - /// - Parameters: - /// - serviceType: The service type to register. - /// - name: A registration name, which is used to differentiate from other registrations - /// that have the same service and factory types. - /// - factory: The closure to specify how the service type is resolved with the dependencies of the type. - /// It is invoked when the `Container` needs to instantiate the instance. - /// It takes a `Resolver` instance and 2 arguments to inject dependencies to the instance, - /// and returns the instance of the component type for the service. - /// - /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. - @discardableResult - public func register( - _ serviceType: Service.Type, - name: String? = nil, - factory: @escaping (Resolver, Arg1, Arg2) -> Service - ) -> ServiceEntry { - fatalError() - } - - /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. - /// - /// - Parameters: - /// - serviceType: The service type to register. - /// - name: A registration name, which is used to differentiate from other registrations - /// that have the same service and factory types. - /// - factory: The closure to specify how the service type is resolved with the dependencies of the type. - /// It is invoked when the `Container` needs to instantiate the instance. - /// It takes a `Resolver` instance and 3 arguments to inject dependencies to the instance, - /// and returns the instance of the component type for the service. - /// - /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. - @discardableResult - public func register( - _ serviceType: Service.Type, - name: String? = nil, - factory: @escaping (Resolver, Arg1, Arg2, Arg3) -> Service - ) -> ServiceEntry { - fatalError() - } - - /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. - /// - /// - Parameters: - /// - serviceType: The service type to register. - /// - name: A registration name, which is used to differentiate from other registrations - /// that have the same service and factory types. - /// - factory: The closure to specify how the service type is resolved with the dependencies of the type. - /// It is invoked when the `Container` needs to instantiate the instance. - /// It takes a `Resolver` instance and 4 arguments to inject dependencies to the instance, - /// and returns the instance of the component type for the service. - /// - /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. - @discardableResult - public func register( - _ serviceType: Service.Type, - name: String? = nil, - factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) -> Service - ) -> ServiceEntry { - fatalError() - } - - /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. - /// - /// - Parameters: - /// - serviceType: The service type to register. - /// - name: A registration name, which is used to differentiate from other registrations - /// that have the same service and factory types. - /// - factory: The closure to specify how the service type is resolved with the dependencies of the type. - /// It is invoked when the `Container` needs to instantiate the instance. - /// It takes a `Resolver` instance and 5 arguments to inject dependencies to the instance, - /// and returns the instance of the component type for the service. - /// - /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. - @discardableResult - public func register( - _ serviceType: Service.Type, - name: String? = nil, - factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) -> Service - ) -> ServiceEntry { - fatalError() - } - - /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. - /// - /// - Parameters: - /// - serviceType: The service type to register. - /// - name: A registration name, which is used to differentiate from other registrations - /// that have the same service and factory types. - /// - factory: The closure to specify how the service type is resolved with the dependencies of the type. - /// It is invoked when the `Container` needs to instantiate the instance. - /// It takes a `Resolver` instance and 6 arguments to inject dependencies to the instance, - /// and returns the instance of the component type for the service. - /// - /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. - @discardableResult - public func register( - _ serviceType: Service.Type, - name: String? = nil, - factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6) -> Service - ) -> ServiceEntry { - fatalError() - } - - /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. - /// - /// - Parameters: - /// - serviceType: The service type to register. - /// - name: A registration name, which is used to differentiate from other registrations - /// that have the same service and factory types. - /// - factory: The closure to specify how the service type is resolved with the dependencies of the type. - /// It is invoked when the `Container` needs to instantiate the instance. - /// It takes a `Resolver` instance and 7 arguments to inject dependencies to the instance, - /// and returns the instance of the component type for the service. - /// - /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. - @discardableResult - public func register( - _ serviceType: Service.Type, - name: String? = nil, - factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7) -> Service - ) -> ServiceEntry { - fatalError() - } - - /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. - /// - /// - Parameters: - /// - serviceType: The service type to register. - /// - name: A registration name, which is used to differentiate from other registrations - /// that have the same service and factory types. - /// - factory: The closure to specify how the service type is resolved with the dependencies of the type. - /// It is invoked when the `Container` needs to instantiate the instance. - /// It takes a `Resolver` instance and 8 arguments to inject dependencies to the instance, - /// and returns the instance of the component type for the service. - /// - /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. - @discardableResult - public func register( - _ serviceType: Service.Type, - name: String? = nil, - factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8) -> Service - ) -> ServiceEntry { - fatalError() - } - - /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. - /// - /// - Parameters: - /// - serviceType: The service type to register. - /// - name: A registration name, which is used to differentiate from other registrations - /// that have the same service and factory types. - /// - factory: The closure to specify how the service type is resolved with the dependencies of the type. - /// It is invoked when the `Container` needs to instantiate the instance. - /// It takes a `Resolver` instance and 9 arguments to inject dependencies to the instance, - /// and returns the instance of the component type for the service. - /// - /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. - @discardableResult - public func register( - _ serviceType: Service.Type, - name: String? = nil, - factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9) -> Service - ) -> ServiceEntry { - fatalError() - } -} - -// MARK: - Resolver with Arguments - -extension Container { - /// Retrieves the instance with the specified service type and 1 argument to the factory closure. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - argument: 1 argument to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// and 1 argument is found in the `Container`. - public func resolve( - _ serviceType: Service.Type, - argument: Arg1 - ) -> Service? { - fatalError() - } - - /// Retrieves the instance with the specified service type, 1 argument to the factory closure and registration name. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - name: The registration name. - /// - argument: 1 argument to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type, - /// 1 argument and name is found in the `Container`. - public func resolve( - _: Service.Type, - name: String?, - argument: Arg1 - ) -> Service? { - fatalError() - } - - /// Retrieves the instance with the specified service type and list of 2 arguments to the factory closure. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - arguments: List of 2 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// and list of 2 arguments is found in the `Container`. - public func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2 - ) -> Service? { - fatalError() - } - - /// Retrieves the instance with the specified service type, list of 2 arguments to the factory closure and registration name. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - name: The registration name. - /// - arguments: List of 2 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type, - /// list of 2 arguments and name is found in the `Container`. - public func resolve( - _: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2 - ) -> Service? { - fatalError() - } - - /// Retrieves the instance with the specified service type and list of 3 arguments to the factory closure. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - arguments: List of 3 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// and list of 3 arguments is found in the `Container`. - public func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3 - ) -> Service? { - fatalError() - } - - /// Retrieves the instance with the specified service type, list of 3 arguments to the factory closure and registration name. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - name: The registration name. - /// - arguments: List of 3 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type, - /// list of 3 arguments and name is found in the `Container`. - public func resolve( - _: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3 - ) -> Service? { - fatalError() - } - - /// Retrieves the instance with the specified service type and list of 4 arguments to the factory closure. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - arguments: List of 4 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// and list of 4 arguments is found in the `Container`. - public func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4 - ) -> Service? { - fatalError() - } - - /// Retrieves the instance with the specified service type, list of 4 arguments to the factory closure and registration name. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - name: The registration name. - /// - arguments: List of 4 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type, - /// list of 4 arguments and name is found in the `Container`. - public func resolve( - _: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4 - ) -> Service? { - fatalError() - } - - /// Retrieves the instance with the specified service type and list of 5 arguments to the factory closure. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - arguments: List of 5 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// and list of 5 arguments is found in the `Container`. - public func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5 - ) -> Service? { - fatalError() - } - - /// Retrieves the instance with the specified service type, list of 5 arguments to the factory closure and registration name. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - name: The registration name. - /// - arguments: List of 5 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type, - /// list of 5 arguments and name is found in the `Container`. - public func resolve( - _: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5 - ) -> Service? { - fatalError() - } - - /// Retrieves the instance with the specified service type and list of 6 arguments to the factory closure. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - arguments: List of 6 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// and list of 6 arguments is found in the `Container`. - public func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6 - ) -> Service? { - fatalError() - } - - /// Retrieves the instance with the specified service type, list of 6 arguments to the factory closure and registration name. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - name: The registration name. - /// - arguments: List of 6 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type, - /// list of 6 arguments and name is found in the `Container`. - public func resolve( - _: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6 - ) -> Service? { - fatalError() - } - - /// Retrieves the instance with the specified service type and list of 7 arguments to the factory closure. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - arguments: List of 7 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// and list of 7 arguments is found in the `Container`. - public func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7 - ) -> Service? { - fatalError() - } - - /// Retrieves the instance with the specified service type, list of 7 arguments to the factory closure and registration name. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - name: The registration name. - /// - arguments: List of 7 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type, - /// list of 7 arguments and name is found in the `Container`. - public func resolve( - _: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7 - ) -> Service? { - fatalError() - } - - /// Retrieves the instance with the specified service type and list of 8 arguments to the factory closure. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - arguments: List of 8 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// and list of 8 arguments is found in the `Container`. - public func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8 - ) -> Service? { - fatalError() - } - - /// Retrieves the instance with the specified service type, list of 8 arguments to the factory closure and registration name. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - name: The registration name. - /// - arguments: List of 8 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type, - /// list of 8 arguments and name is found in the `Container`. - public func resolve( - _: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8 - ) -> Service? { - fatalError() - } - - /// Retrieves the instance with the specified service type and list of 9 arguments to the factory closure. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - arguments: List of 9 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// and list of 9 arguments is found in the `Container`. - public func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8, _ arg9: Arg9 - ) -> Service? { - fatalError() - } - - /// Retrieves the instance with the specified service type, list of 9 arguments to the factory closure and registration name. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - name: The registration name. - /// - arguments: List of 9 arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type, - /// list of 9 arguments and name is found in the `Container`. - public func resolve( - _: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8, _ arg9: Arg9 - ) -> Service? { - fatalError() - } -} diff --git a/Sources/2.0 API/Container.swift b/Sources/2.0 API/Container.swift index 6e0e8199..5a127764 100644 --- a/Sources/2.0 API/Container.swift +++ b/Sources/2.0 API/Container.swift @@ -105,36 +105,20 @@ public final class Container { } } -// MARK: - Resolver - -extension Container: Resolver { - /// Retrieves the instance with the specified service type. - /// - /// - Parameter serviceType: The service type to resolve. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// is found in the `Container`. - public func resolve(_ serviceType: Service.Type) -> Service? { - fatalError() - } +// MARK: CustomStringConvertible - /// Retrieves the instance with the specified service type and registration name. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - name: The registration name. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type and name - /// is found in the `Container`. - public func resolve(_: Service.Type, name: String?) -> Service? { - fatalError() +extension Container: CustomStringConvertible { + public var description: String { + "" } } -// MARK: CustomStringConvertible +// MARK: Resolver -extension Container: CustomStringConvertible { - public var description: String { - fatalError() +extension Container: Resolver { + public func resolve( + _ request: InstanceRequest + ) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { + try swinject.resolve(request) } } diff --git a/Sources/2.0 API/ObjectScope.swift b/Sources/2.0 API/ObjectScope.swift index 8f4af814..fbb2f75a 100644 --- a/Sources/2.0 API/ObjectScope.swift +++ b/Sources/2.0 API/ObjectScope.swift @@ -22,8 +22,6 @@ public enum ObjectScope { case weak } - - extension ObjectScope { var scope: AnyScope? { nil } } diff --git a/Sources/2.0 API/Resolver.swift b/Sources/2.0 API/Resolver+LegacyApi.swift similarity index 63% rename from Sources/2.0 API/Resolver.swift rename to Sources/2.0 API/Resolver+LegacyApi.swift index 8bc55587..e9ba2a7f 100644 --- a/Sources/2.0 API/Resolver.swift +++ b/Sources/2.0 API/Resolver+LegacyApi.swift @@ -2,21 +2,16 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -// -// NOTICE: -// -// Resolver.swift is generated from Resolver.erb by ERB. -// Do NOT modify Resolver.swift directly. -// Instead, modify Resolver.erb and run `script/gencode` at the project root directory to generate the code. -// - -public protocol Resolver { +// sourcery:inline:ResolverLegacyApi +public extension Resolver { /// Retrieves the instance with the specified service type. /// /// - Parameter serviceType: The service type to resolve. /// /// - Returns: The resolved service type instance, or nil if no service is found. - func resolve(_ serviceType: Service.Type) -> Service? + func resolve(_ serviceType: Service.Type) -> Service? { + fatalError() + } /// Retrieves the instance with the specified service type and registration name. /// @@ -25,257 +20,234 @@ public protocol Resolver { /// - name: The registration name. /// /// - Returns: The resolved service type instance, or nil if no service with the name is found. - func resolve(_ serviceType: Service.Type, name: String?) -> Service? + func resolve(_ serviceType: Service.Type, name: String?) -> Service? { + fatalError() + } /// Retrieves the instance with the specified service type and 1 argument to the factory closure. /// /// - Parameters: /// - serviceType: The service type to resolve. - /// - argument: 1 argument to pass to the factory closure. + /// - argument: 1 Argument to pass to the factory closure. /// /// - Returns: The resolved service type instance, or nil if no registration for the service type /// and 1 argument is found. - func resolve( - _ serviceType: Service.Type, - argument: Arg1 - ) -> Service? + func resolve(_ serviceType: Service.Type, argument: Arg1) -> Service? { + fatalError() + } /// Retrieves the instance with the specified service type, 1 argument to the factory closure and registration name. /// /// - Parameters: /// - serviceType: The service type to resolve. /// - name: The registration name. - /// - argument: 1 argument to pass to the factory closure. + /// - argument: 1 Argument to pass to the factory closure. /// /// - Returns: The resolved service type instance, or nil if no registration for the service type, /// 1 argument and name is found. - func resolve( - _ serviceType: Service.Type, - name: String?, - argument: Arg1 - ) -> Service? + func resolve(_ serviceType: Service.Type, name: String?, argument: Arg1) -> Service? { + fatalError() + } /// Retrieves the instance with the specified service type and list of 2 arguments to the factory closure. /// /// - Parameters: /// - serviceType: The service type to resolve. - /// - arguments: List of 2 arguments to pass to the factory closure. + /// - arguments: List Of 2 Arguments to pass to the factory closure. /// /// - Returns: The resolved service type instance, or nil if no registration for the service type /// and list of 2 arguments is found. - func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2 - ) -> Service? + func resolve(_ serviceType: Service.Type, arguments arg1: Arg1, _ arg2: Arg2) -> Service? { + fatalError() + } /// Retrieves the instance with the specified service type, list of 2 arguments to the factory closure and registration name. /// /// - Parameters: /// - serviceType: The service type to resolve. /// - name: The registration name. - /// - arguments: List of 2 arguments to pass to the factory closure. + /// - arguments: List Of 2 Arguments to pass to the factory closure. /// /// - Returns: The resolved service type instance, or nil if no registration for the service type, /// list of 2 arguments and name is found. - func resolve( - _ serviceType: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2 - ) -> Service? + func resolve(_ serviceType: Service.Type, name: String?, arguments arg1: Arg1, _ arg2: Arg2) -> Service? { + fatalError() + } /// Retrieves the instance with the specified service type and list of 3 arguments to the factory closure. /// /// - Parameters: /// - serviceType: The service type to resolve. - /// - arguments: List of 3 arguments to pass to the factory closure. + /// - arguments: List Of 3 Arguments to pass to the factory closure. /// /// - Returns: The resolved service type instance, or nil if no registration for the service type /// and list of 3 arguments is found. - func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3 - ) -> Service? + func resolve(_ serviceType: Service.Type, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> Service? { + fatalError() + } /// Retrieves the instance with the specified service type, list of 3 arguments to the factory closure and registration name. /// /// - Parameters: /// - serviceType: The service type to resolve. /// - name: The registration name. - /// - arguments: List of 3 arguments to pass to the factory closure. + /// - arguments: List Of 3 Arguments to pass to the factory closure. /// /// - Returns: The resolved service type instance, or nil if no registration for the service type, /// list of 3 arguments and name is found. - func resolve( - _ serviceType: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3 - ) -> Service? + func resolve(_ serviceType: Service.Type, name: String?, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> Service? { + fatalError() + } /// Retrieves the instance with the specified service type and list of 4 arguments to the factory closure. /// /// - Parameters: /// - serviceType: The service type to resolve. - /// - arguments: List of 4 arguments to pass to the factory closure. + /// - arguments: List Of 4 Arguments to pass to the factory closure. /// /// - Returns: The resolved service type instance, or nil if no registration for the service type /// and list of 4 arguments is found. - func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4 - ) -> Service? + func resolve(_ serviceType: Service.Type, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> Service? { + fatalError() + } /// Retrieves the instance with the specified service type, list of 4 arguments to the factory closure and registration name. /// /// - Parameters: /// - serviceType: The service type to resolve. /// - name: The registration name. - /// - arguments: List of 4 arguments to pass to the factory closure. + /// - arguments: List Of 4 Arguments to pass to the factory closure. /// /// - Returns: The resolved service type instance, or nil if no registration for the service type, /// list of 4 arguments and name is found. - func resolve( - _ serviceType: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4 - ) -> Service? + func resolve(_ serviceType: Service.Type, name: String?, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> Service? { + fatalError() + } /// Retrieves the instance with the specified service type and list of 5 arguments to the factory closure. /// /// - Parameters: /// - serviceType: The service type to resolve. - /// - arguments: List of 5 arguments to pass to the factory closure. + /// - arguments: List Of 5 Arguments to pass to the factory closure. /// /// - Returns: The resolved service type instance, or nil if no registration for the service type /// and list of 5 arguments is found. - func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5 - ) -> Service? + func resolve(_ serviceType: Service.Type, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> Service? { + fatalError() + } /// Retrieves the instance with the specified service type, list of 5 arguments to the factory closure and registration name. /// /// - Parameters: /// - serviceType: The service type to resolve. /// - name: The registration name. - /// - arguments: List of 5 arguments to pass to the factory closure. + /// - arguments: List Of 5 Arguments to pass to the factory closure. /// /// - Returns: The resolved service type instance, or nil if no registration for the service type, /// list of 5 arguments and name is found. - func resolve( - _ serviceType: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5 - ) -> Service? + func resolve(_ serviceType: Service.Type, name: String?, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> Service? { + fatalError() + } /// Retrieves the instance with the specified service type and list of 6 arguments to the factory closure. /// /// - Parameters: /// - serviceType: The service type to resolve. - /// - arguments: List of 6 arguments to pass to the factory closure. + /// - arguments: List Of 6 Arguments to pass to the factory closure. /// /// - Returns: The resolved service type instance, or nil if no registration for the service type /// and list of 6 arguments is found. - func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6 - ) -> Service? + func resolve(_ serviceType: Service.Type, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6) -> Service? { + fatalError() + } /// Retrieves the instance with the specified service type, list of 6 arguments to the factory closure and registration name. /// /// - Parameters: /// - serviceType: The service type to resolve. /// - name: The registration name. - /// - arguments: List of 6 arguments to pass to the factory closure. + /// - arguments: List Of 6 Arguments to pass to the factory closure. /// /// - Returns: The resolved service type instance, or nil if no registration for the service type, /// list of 6 arguments and name is found. - func resolve( - _ serviceType: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6 - ) -> Service? + func resolve(_ serviceType: Service.Type, name: String?, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6) -> Service? { + fatalError() + } /// Retrieves the instance with the specified service type and list of 7 arguments to the factory closure. /// /// - Parameters: /// - serviceType: The service type to resolve. - /// - arguments: List of 7 arguments to pass to the factory closure. + /// - arguments: List Of 7 Arguments to pass to the factory closure. /// /// - Returns: The resolved service type instance, or nil if no registration for the service type /// and list of 7 arguments is found. - func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7 - ) -> Service? + func resolve(_ serviceType: Service.Type, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7) -> Service? { + fatalError() + } /// Retrieves the instance with the specified service type, list of 7 arguments to the factory closure and registration name. /// /// - Parameters: /// - serviceType: The service type to resolve. /// - name: The registration name. - /// - arguments: List of 7 arguments to pass to the factory closure. + /// - arguments: List Of 7 Arguments to pass to the factory closure. /// /// - Returns: The resolved service type instance, or nil if no registration for the service type, /// list of 7 arguments and name is found. - func resolve( - _ serviceType: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7 - ) -> Service? + func resolve(_ serviceType: Service.Type, name: String?, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7) -> Service? { + fatalError() + } /// Retrieves the instance with the specified service type and list of 8 arguments to the factory closure. /// /// - Parameters: /// - serviceType: The service type to resolve. - /// - arguments: List of 8 arguments to pass to the factory closure. + /// - arguments: List Of 8 Arguments to pass to the factory closure. /// /// - Returns: The resolved service type instance, or nil if no registration for the service type /// and list of 8 arguments is found. - func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8 - ) -> Service? + func resolve(_ serviceType: Service.Type, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8) -> Service? { + fatalError() + } /// Retrieves the instance with the specified service type, list of 8 arguments to the factory closure and registration name. /// /// - Parameters: /// - serviceType: The service type to resolve. /// - name: The registration name. - /// - arguments: List of 8 arguments to pass to the factory closure. + /// - arguments: List Of 8 Arguments to pass to the factory closure. /// /// - Returns: The resolved service type instance, or nil if no registration for the service type, /// list of 8 arguments and name is found. - func resolve( - _ serviceType: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8 - ) -> Service? + func resolve(_ serviceType: Service.Type, name: String?, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8) -> Service? { + fatalError() + } /// Retrieves the instance with the specified service type and list of 9 arguments to the factory closure. /// /// - Parameters: /// - serviceType: The service type to resolve. - /// - arguments: List of 9 arguments to pass to the factory closure. + /// - arguments: List Of 9 Arguments to pass to the factory closure. /// /// - Returns: The resolved service type instance, or nil if no registration for the service type /// and list of 9 arguments is found. - func resolve( - _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8, _ arg9: Arg9 - ) -> Service? + func resolve(_ serviceType: Service.Type, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8, _ arg9: Arg9) -> Service? { + fatalError() + } /// Retrieves the instance with the specified service type, list of 9 arguments to the factory closure and registration name. /// /// - Parameters: /// - serviceType: The service type to resolve. /// - name: The registration name. - /// - arguments: List of 9 arguments to pass to the factory closure. + /// - arguments: List Of 9 Arguments to pass to the factory closure. /// /// - Returns: The resolved service type instance, or nil if no registration for the service type, /// list of 9 arguments and name is found. - func resolve( - _ serviceType: Service.Type, - name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8, _ arg9: Arg9 - ) -> Service? + func resolve(_ serviceType: Service.Type, name: String?, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8, _ arg9: Arg9) -> Service? { + fatalError() + } + } +// sourcery:end diff --git a/Sources/2.0 API/ServiceEntry.TypeForwarding.swift b/Sources/2.0 API/ServiceEntry+TypeForwarding.swift similarity index 78% rename from Sources/2.0 API/ServiceEntry.TypeForwarding.swift rename to Sources/2.0 API/ServiceEntry+TypeForwarding.swift index f192e1d1..25c73294 100644 --- a/Sources/2.0 API/ServiceEntry.TypeForwarding.swift +++ b/Sources/2.0 API/ServiceEntry+TypeForwarding.swift @@ -2,14 +2,7 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -// -// NOTICE: -// -// ServiceEntry.TypeForwarding.swift is generated from ServiceEntry.TypeForwarding.erb by ERB. -// Do NOT modify ServiceEntry.TypeForwarding.swift directly. -// Instead, modify ServiceEntry.TypeForwarding.erb and run `script/gencode` at the project root directory to generate the code. -// - +// sourcery:inline:ServiceEntryTypeForwarding extension ServiceEntry { /// Adds another type which should be resolved using this ServiceEntry - i.e. using the same object scope, /// arguments and `initCompleted` closures @@ -19,6 +12,7 @@ extension ServiceEntry { /// - name: A registration name, which is used to differentiate from other registrations of the same `type` @discardableResult public func implements(_ type: T.Type, name: String? = nil) -> ServiceEntry { + fatalError() return self } @@ -29,9 +23,9 @@ extension ServiceEntry { /// - types: List of 2 types resolution of which should be forwarded @discardableResult public func implements(_ type1: T1.Type, _ type2: T2.Type) -> ServiceEntry { - return implements(type1).implements(type2) + return self.implements(type1).implements(type2) } - + /// Adds multiple types which should be resolved using this ServiceEntry - i.e. using the same object scope, /// arguments and `initCompleted` closures /// @@ -39,9 +33,9 @@ extension ServiceEntry { /// - types: List of 3 types resolution of which should be forwarded @discardableResult public func implements(_ type1: T1.Type, _ type2: T2.Type, _ type3: T3.Type) -> ServiceEntry { - return implements(type1).implements(type2).implements(type3) + return self.implements(type1).implements(type2).implements(type3) } - + /// Adds multiple types which should be resolved using this ServiceEntry - i.e. using the same object scope, /// arguments and `initCompleted` closures /// @@ -49,9 +43,9 @@ extension ServiceEntry { /// - types: List of 4 types resolution of which should be forwarded @discardableResult public func implements(_ type1: T1.Type, _ type2: T2.Type, _ type3: T3.Type, _ type4: T4.Type) -> ServiceEntry { - return implements(type1).implements(type2).implements(type3).implements(type4) + return self.implements(type1).implements(type2).implements(type3).implements(type4) } - + /// Adds multiple types which should be resolved using this ServiceEntry - i.e. using the same object scope, /// arguments and `initCompleted` closures /// @@ -59,9 +53,9 @@ extension ServiceEntry { /// - types: List of 5 types resolution of which should be forwarded @discardableResult public func implements(_ type1: T1.Type, _ type2: T2.Type, _ type3: T3.Type, _ type4: T4.Type, _ type5: T5.Type) -> ServiceEntry { - return implements(type1).implements(type2).implements(type3).implements(type4).implements(type5) + return self.implements(type1).implements(type2).implements(type3).implements(type4).implements(type5) } - + /// Adds multiple types which should be resolved using this ServiceEntry - i.e. using the same object scope, /// arguments and `initCompleted` closures /// @@ -69,9 +63,9 @@ extension ServiceEntry { /// - types: List of 6 types resolution of which should be forwarded @discardableResult public func implements(_ type1: T1.Type, _ type2: T2.Type, _ type3: T3.Type, _ type4: T4.Type, _ type5: T5.Type, _ type6: T6.Type) -> ServiceEntry { - return implements(type1).implements(type2).implements(type3).implements(type4).implements(type5).implements(type6) + return self.implements(type1).implements(type2).implements(type3).implements(type4).implements(type5).implements(type6) } - + /// Adds multiple types which should be resolved using this ServiceEntry - i.e. using the same object scope, /// arguments and `initCompleted` closures /// @@ -79,9 +73,9 @@ extension ServiceEntry { /// - types: List of 7 types resolution of which should be forwarded @discardableResult public func implements(_ type1: T1.Type, _ type2: T2.Type, _ type3: T3.Type, _ type4: T4.Type, _ type5: T5.Type, _ type6: T6.Type, _ type7: T7.Type) -> ServiceEntry { - return implements(type1).implements(type2).implements(type3).implements(type4).implements(type5).implements(type6).implements(type7) + return self.implements(type1).implements(type2).implements(type3).implements(type4).implements(type5).implements(type6).implements(type7) } - + /// Adds multiple types which should be resolved using this ServiceEntry - i.e. using the same object scope, /// arguments and `initCompleted` closures /// @@ -89,9 +83,9 @@ extension ServiceEntry { /// - types: List of 8 types resolution of which should be forwarded @discardableResult public func implements(_ type1: T1.Type, _ type2: T2.Type, _ type3: T3.Type, _ type4: T4.Type, _ type5: T5.Type, _ type6: T6.Type, _ type7: T7.Type, _ type8: T8.Type) -> ServiceEntry { - return implements(type1).implements(type2).implements(type3).implements(type4).implements(type5).implements(type6).implements(type7).implements(type8) + return self.implements(type1).implements(type2).implements(type3).implements(type4).implements(type5).implements(type6).implements(type7).implements(type8) } - + /// Adds multiple types which should be resolved using this ServiceEntry - i.e. using the same object scope, /// arguments and `initCompleted` closures /// @@ -99,6 +93,9 @@ extension ServiceEntry { /// - types: List of 9 types resolution of which should be forwarded @discardableResult public func implements(_ type1: T1.Type, _ type2: T2.Type, _ type3: T3.Type, _ type4: T4.Type, _ type5: T5.Type, _ type6: T6.Type, _ type7: T7.Type, _ type8: T8.Type, _ type9: T9.Type) -> ServiceEntry { - return implements(type1).implements(type2).implements(type3).implements(type4).implements(type5).implements(type6).implements(type7).implements(type8).implements(type9) + return self.implements(type1).implements(type2).implements(type3).implements(type4).implements(type5).implements(type6).implements(type7).implements(type8).implements(type9) } + + } +// sourcery:end diff --git a/Sources/2.0 API/SynchronizedResolver.Arguments.erb b/Sources/2.0 API/SynchronizedResolver.Arguments.erb deleted file mode 100644 index 840aa80f..00000000 --- a/Sources/2.0 API/SynchronizedResolver.Arguments.erb +++ /dev/null @@ -1,46 +0,0 @@ -// -// SynchronizedResolver.Arguments.swift -// Swinject -// -// Created by Yoichi Tagaya on 11/23/15. -// Copyright © 2015 Swinject Contributors. All rights reserved. -// - -// -// NOTICE: -// -// SynchronizedResolver.Arguments.swift is generated from SynchronizedResolver.Arguments.erb by ERB. -// Do NOT modify SynchronizedResolver.Arguments.swift directly. -// Instead, modify SynchronizedResolver.Arguments.erb and run `script/gencode` at the project root directory to generate the code. -// - -<% arg_count = 9 %> - -// MARK: - Resolver with Arguments -extension SynchronizedResolver { -<% (1..arg_count).each do |i| %> -<% arg_types = (1..i).map { |n| "Arg#{n}" }.join(", ") %> -<% arg_param_name = i == 1 ? "argument" : "arguments" %> -<% arg_param_def = i == 1 ? "argument: Arg1" : "arguments arg1: Arg1, " + (2..i).map{ |n| "_ arg#{n}: Arg#{n}" }.join(", ") %> -<% arg_param_call = i == 1 ? "argument" : (1..i).map{ |n| "arg#{n}" }.join(", ") %> - internal func resolve>( - _ serviceType: Service.Type, - <%= arg_param_def %>) -> Service? - { - return container.lock.sync { - return self.container.resolve(serviceType, <%= arg_param_name %>: <%= arg_param_call %>) - } - } - - internal func resolve>( - _ serviceType: Service.Type, - name: String?, - <%= arg_param_def %>) -> Service? - { - return container.lock.sync { - return self.container.resolve(serviceType, name: name, <%= arg_param_name %>: <%= arg_param_call %>) - } - } - -<% end %> -} diff --git a/Sources/3.0 API/BinderEnvironment.swift b/Sources/3.0 API/BinderEnvironment.swift index 8b77dbc4..9418634a 100644 --- a/Sources/3.0 API/BinderEnvironment.swift +++ b/Sources/3.0 API/BinderEnvironment.swift @@ -18,29 +18,29 @@ public func scoped(_ scope: AScope) -> BinderEnvironment(_ builder: @escaping (Resolver3, Context) throws -> Type) -> SimpleBinding.Builder { + func provider(_ builder: @escaping (Resolver, Context) throws -> Type) -> SimpleBinding.Builder { .init { r, c, _ in try builder(r, c) } } - func factory(_ builder: @escaping (Resolver3, Context, Arg1) throws -> Type) -> SimpleBinding.Builder { + func factory(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SimpleBinding.Builder { .init(builder) } } public extension BinderEnvironment where AScope == Void { - func factory(_ builder: @escaping (Resolver3, Context, Arg1, Arg2) throws -> Type) -> SimpleBinding.Builder { + func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SimpleBinding.Builder { .init { try builder($0, $1, $2.0, $2.1) } } - func factory(_ builder: @escaping (Resolver3, Context, Arg1, Arg2, Arg3) throws -> Type) -> SimpleBinding.Builder { + func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SimpleBinding.Builder { .init { try builder($0, $1, $2.0, $2.1, $2.2) } } - func factory(_ builder: @escaping (Resolver3, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SimpleBinding.Builder { + func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SimpleBinding.Builder { .init { try builder($0, $1, $2.0, $2.1, $2.2, $2.3) } } - func factory(_ builder: @escaping (Resolver3, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SimpleBinding.Builder { + func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SimpleBinding.Builder { .init { try builder($0, $1, $2.0, $2.1, $2.2, $2.3, $2.4) } } } @@ -50,33 +50,33 @@ public extension BinderEnvironment where AScope: Scope, Context == AScope.Contex .init(scope) { _, _, _ in try builder() } } - func singleton(_ builder: @escaping (Resolver3) throws -> Type) -> ScopedBinding.Builder { + func singleton(_ builder: @escaping (Resolver) throws -> Type) -> ScopedBinding.Builder { .init(scope) { r, _, _ in try builder(r) } } - func singleton(_ builder: @escaping (Resolver3, Context) throws -> Type) -> ScopedBinding.Builder { + func singleton(_ builder: @escaping (Resolver, Context) throws -> Type) -> ScopedBinding.Builder { .init(scope) { r, c, _ in try builder(r, c) } } } public extension BinderEnvironment where AScope: Scope, Context == AScope.Context { - func multiton(_ builder: @escaping (Resolver3, Context, Arg1) throws -> Type) -> ScopedBinding.Builder { + func multiton(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> ScopedBinding.Builder { .init(scope, builder) } - func multiton(_ builder: @escaping (Resolver3, Context, Arg1, Arg2) throws -> Type) -> ScopedBinding.Builder { + func multiton(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> ScopedBinding.Builder { .init(scope) { try builder($0, $1, $2.0, $2.1) } } - func multiton(_ builder: @escaping (Resolver3, Context, Arg1, Arg2, Arg3) throws -> Type) -> ScopedBinding.Builder { + func multiton(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> ScopedBinding.Builder { .init(scope) { try builder($0, $1, $2.0, $2.1, $2.2) } } - func multiton(_ builder: @escaping (Resolver3, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> ScopedBinding.Builder { + func multiton(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> ScopedBinding.Builder { .init(scope) { try builder($0, $1, $2.0, $2.1, $2.2, $2.3) } } - func multiton(_ builder: @escaping (Resolver3, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> ScopedBinding.Builder { + func multiton(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> ScopedBinding.Builder { .init(scope) { try builder($0, $1, $2.0, $2.1, $2.2, $2.3, $2.4) } } } @@ -89,27 +89,27 @@ public func provider(_ builder: @escaping () throws -> Type) -> SimpleBind .init { _, _, _ in try builder() } } -public func provider(_ builder: @escaping (Resolver3) throws -> Type) -> SimpleBinding.Builder { +public func provider(_ builder: @escaping (Resolver) throws -> Type) -> SimpleBinding.Builder { .init { r, _, _ in try builder(r) } } -public func factory(_ builder: @escaping (Resolver3, Arg1) throws -> Type) -> SimpleBinding.Builder { +public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> SimpleBinding.Builder { .init { try builder($0, $2) } } -public func factory(_ builder: @escaping (Resolver3, Arg1, Arg2) throws -> Type) -> SimpleBinding.Builder { +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SimpleBinding.Builder { .init { try builder($0, $2.0, $2.1) } } -public func factory(_ builder: @escaping (Resolver3, Arg1, Arg2, Arg3) throws -> Type) -> SimpleBinding.Builder { +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SimpleBinding.Builder { .init { try builder($0, $2.0, $2.1, $2.2) } } -public func factory(_ builder: @escaping (Resolver3, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SimpleBinding.Builder { +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SimpleBinding.Builder { SimpleBinding.Builder { try builder($0, $2.0, $2.1, $2.2, $2.3) } } -public func factory(_ builder: @escaping (Resolver3, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SimpleBinding.Builder { +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SimpleBinding.Builder { SimpleBinding.Builder { try builder($0, $2.0, $2.1, $2.2, $2.3, $2.4) } } @@ -117,26 +117,26 @@ public func singleton(_ builder: @escaping () throws -> Type) -> ScopedBin .init(.root) { _, _, _ in try builder() } } -public func singleton(_ builder: @escaping (Resolver3) throws -> Type) -> ScopedBinding.Builder { +public func singleton(_ builder: @escaping (Resolver) throws -> Type) -> ScopedBinding.Builder { .init(.root) { r, _, _ in try builder(r) } } -public func multiton(_ builder: @escaping (Resolver3, Arg1) throws -> Type) -> ScopedBinding.Builder { +public func multiton(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> ScopedBinding.Builder { .init(.root) { try builder($0, $2) } } -public func multiton(_ builder: @escaping (Resolver3, Arg1, Arg2) throws -> Type) -> ScopedBinding.Builder { +public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> ScopedBinding.Builder { .init(.root) { try builder($0, $2.0, $2.1) } } -public func multiton(_ builder: @escaping (Resolver3, Arg1, Arg2, Arg3) throws -> Type) -> ScopedBinding.Builder { +public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> ScopedBinding.Builder { .init(.root) { try builder($0, $2.0, $2.1, $2.2) } } -public func multiton(_ builder: @escaping (Resolver3, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> ScopedBinding.Builder { +public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> ScopedBinding.Builder { .init(.root) { try builder($0, $2.0, $2.1, $2.2, $2.3) } } -public func multiton(_ builder: @escaping (Resolver3, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> ScopedBinding.Builder { +public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> ScopedBinding.Builder { .init(.root) { try builder($0, $2.0, $2.1, $2.2, $2.3, $2.4) } } diff --git a/Sources/3.0 API/Resolver+Injection.swift b/Sources/3.0 API/Resolver+Injection.swift index 803265f8..261c9572 100644 --- a/Sources/3.0 API/Resolver+Injection.swift +++ b/Sources/3.0 API/Resolver+Injection.swift @@ -5,7 +5,7 @@ // TODO: Overloads for multiple arguments & tag / notag combinations // swiftlint:disable line_length -public extension Resolver3 { +public extension Resolver { func instance(of _: Type.Type = Type.self) throws -> Type { try instance(tagged: NoTag(), arg: ()) } @@ -23,7 +23,7 @@ public extension Resolver3 { } } -public extension Resolver3 { +public extension Resolver { func provider(of _: Type.Type = Type.self) -> () throws -> Type { provider(tagged: NoTag(), arg: ()) } @@ -41,7 +41,7 @@ public extension Resolver3 { } } -public extension Resolver3 { +public extension Resolver { func factory(of _: Type.Type = Type.self) -> (Argument) throws -> Type { factory(tagged: NoTag()) } diff --git a/Sources/Core/Binding.swift b/Sources/Core/Binding.swift index 65080d8e..247877b1 100644 --- a/Sources/Core/Binding.swift +++ b/Sources/Core/Binding.swift @@ -5,7 +5,7 @@ // sourcery: AutoMockable public protocol Binding: SwinjectEntry { func matches(_ key: AnyBindingKey) -> Bool - func instance(arg: Any, context: Any, resolver: Resolver3) throws -> Any + func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any } public protocol BindingMaker { diff --git a/Sources/Core/ContextedResolver.swift b/Sources/Core/ContextedResolver.swift index 3959ebd7..37defe91 100644 --- a/Sources/Core/ContextedResolver.swift +++ b/Sources/Core/ContextedResolver.swift @@ -2,12 +2,12 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -struct ContextedResolver3 { +struct ContextedResolver { let context: Context - let resolver: Resolver3 + let resolver: Resolver } -extension ContextedResolver3: Resolver3 { +extension ContextedResolver: Resolver { func resolve( _ request: InstanceRequest ) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { diff --git a/Sources/Core/InstanceMaker.swift b/Sources/Core/InstanceMaker.swift index f758c5fe..3851716b 100644 --- a/Sources/Core/InstanceMaker.swift +++ b/Sources/Core/InstanceMaker.swift @@ -4,7 +4,7 @@ // sourcery: AutoMockable public protocol AnyInstanceMaker { - func makeInstance(arg: Any, context: Any, resolver: Resolver3) throws -> Any + func makeInstance(arg: Any, context: Any, resolver: Resolver) throws -> Any } // FIXME: "Maker" is not a typical concept @@ -13,11 +13,11 @@ public protocol InstanceMaker: AnyInstanceMaker { associatedtype MadeType associatedtype Argument associatedtype Context - func makeInstance(arg: Argument, context: Context, resolver: Resolver3) throws -> MadeType + func makeInstance(arg: Argument, context: Context, resolver: Resolver) throws -> MadeType } public extension InstanceMaker { - func makeInstance(arg: Any, context: Any, resolver: Resolver3) throws -> Any { + func makeInstance(arg: Any, context: Any, resolver: Resolver) throws -> Any { guard let arg = arg as? Argument, let context = context as? Context else { throw SwinjectError() } return try makeInstance(arg: arg, context: context, resolver: resolver) as MadeType } diff --git a/Sources/Core/Resolver3.swift b/Sources/Core/Resolver.swift similarity index 62% rename from Sources/Core/Resolver3.swift rename to Sources/Core/Resolver.swift index 80585641..b547f4d7 100644 --- a/Sources/Core/Resolver3.swift +++ b/Sources/Core/Resolver.swift @@ -3,14 +3,14 @@ // // TODO: Rename -public protocol Resolver3 { +public protocol Resolver { func resolve( _ request: InstanceRequest ) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor } -public extension Resolver3 { - func on(_ context: Context) -> Resolver3 { - ContextedResolver3(context: context, resolver: self) +public extension Resolver { + func on(_ context: Context) -> Resolver { + ContextedResolver(context: context, resolver: self) } } diff --git a/Sources/Core/ScopedBinding.swift b/Sources/Core/ScopedBinding.swift index b754472f..928190a9 100644 --- a/Sources/Core/ScopedBinding.swift +++ b/Sources/Core/ScopedBinding.swift @@ -13,7 +13,7 @@ extension ScopedBinding: Binding { self.key.matches(key) } - public func instance(arg: Any, context: Any, resolver: Resolver3) throws -> Any { + public func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any { try scope .registry(for: context) .instance(for: ScopeRegistryKey(descriptor: key.descriptor, argument: arg)) { @@ -25,9 +25,9 @@ extension ScopedBinding: Binding { extension ScopedBinding { public struct Builder where AScope: Scope { let scope: AScope - private let builder: (Resolver3, Context, Argument) throws -> Type + private let builder: (Resolver, Context, Argument) throws -> Type - init(_ scope: AScope, _ builder: @escaping (Resolver3, Context, Argument) throws -> Type) { + init(_ scope: AScope, _ builder: @escaping (Resolver, Context, Argument) throws -> Type) { self.scope = scope self.builder = builder } @@ -38,7 +38,7 @@ extension ScopedBinding.Builder: InstanceMaker { public typealias MadeType = Type public typealias Context = AScope.Context - public func makeInstance(arg: Argument, context: Context, resolver: Resolver3) throws -> Type { + public func makeInstance(arg: Argument, context: Context, resolver: Resolver) throws -> Type { try builder(resolver, context, arg) } } diff --git a/Sources/Core/SimpleBinding.swift b/Sources/Core/SimpleBinding.swift index 5e688ba1..d673d2f9 100644 --- a/Sources/Core/SimpleBinding.swift +++ b/Sources/Core/SimpleBinding.swift @@ -12,16 +12,16 @@ extension SimpleBinding: Binding { self.key.matches(key) } - public func instance(arg: Any, context: Any, resolver: Resolver3) throws -> Any { + public func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any { try maker.makeInstance(arg: arg, context: context, resolver: resolver) } } extension SimpleBinding { public struct Builder { - private let builder: (Resolver3, Context, Argument) throws -> Type + private let builder: (Resolver, Context, Argument) throws -> Type - init(_ builder: @escaping (Resolver3, Context, Argument) throws -> Type) { + init(_ builder: @escaping (Resolver, Context, Argument) throws -> Type) { self.builder = builder } } @@ -30,7 +30,7 @@ extension SimpleBinding { extension SimpleBinding.Builder: InstanceMaker { public typealias MadeType = Type - public func makeInstance(arg: Argument, context: Context, resolver: Resolver3) throws -> Type { + public func makeInstance(arg: Argument, context: Context, resolver: Resolver) throws -> Type { try builder(resolver, context, arg) } } diff --git a/Sources/Core/Swinject.swift b/Sources/Core/Swinject.swift index b6f30629..36cd83b0 100644 --- a/Sources/Core/Swinject.swift +++ b/Sources/Core/Swinject.swift @@ -10,7 +10,7 @@ public struct Swinject { } } -extension Swinject: Resolver3 { +extension Swinject: Resolver { public func resolve( _ request: InstanceRequest ) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index f4b5a5f3..0bb485a6 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -21,10 +21,10 @@ 084187169E13A6E9E709297C /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; 0C24BE87E4F1CF7482DB3468 /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 273FB7A6277E0841E1570990 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 0C7996FAC479BA40B124F470 /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = ADD71387EBA54D7EF60D0089 /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 0CB9E677FDF7CF424A738F34 /* Container.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C13D01A2DE6F53DF3175D22 /* Container.Arguments.swift */; }; + 0CB9E677FDF7CF424A738F34 /* Container+Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C13D01A2DE6F53DF3175D22 /* Container+Arguments.swift */; }; 0CED31C429BA9F9B23EB2B1F /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42490D1D0C395951243F5CFF /* Container.swift */; }; 0D6143A7732F1334275D3658 /* UnboundScopeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 671D5D89472DAFA916814506 /* UnboundScopeSpec.swift */; }; - 0DFB6FB4DF6A713EA545930F /* Container.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C2DBC728B763B04CB25963 /* Container.TypeForwarding.swift */; }; + 0DFB6FB4DF6A713EA545930F /* Container+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C2DBC728B763B04CB25963 /* Container+TypeForwarding.swift */; }; 0E465ECE9EC970161D607F7F /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EA7A547FC60DBD02D132B3E6 /* Swinject.framework */; }; 0E8E5B08478EB883D9B52947 /* ScopedBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */; }; 100DC02D61F72A611B7CF6E3 /* UnboundScopeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 671D5D89472DAFA916814506 /* UnboundScopeSpec.swift */; }; @@ -52,7 +52,7 @@ 1F4FBB9D795CE9D45E5A8BEE /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; 20823C309A5C58900CDFA8C3 /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; 22837E727E47A3B8A588AB78 /* TypeBinderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDA62EEBC79ED2639C93A76B /* TypeBinderSpec.swift */; }; - 2488CDD8D67CAC5C97BDF8B1 /* Resolver3.swift in Sources */ = {isa = PBXBuildFile; fileRef = C11D19C5F01647E4A576514A /* Resolver3.swift */; }; + 2488CDD8D67CAC5C97BDF8B1 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = C11D19C5F01647E4A576514A /* Resolver.swift */; }; 25DE2596CC5387B9353FC204 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */; }; 261D54C316CB625359F7EE97 /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; 26AC238FC2FB5279ABF37C89 /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */; }; @@ -67,7 +67,7 @@ 2D1BB3EDEBEA06A17138B298 /* TaggedTypeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */; }; 2DCEEF373F410202226D2DB5 /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */; }; 30BD96CC0333463C71377C4B /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; - 31266C4BA7CE6C3FBAFBACDD /* Container.Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE4B1E4BA98573B6FED2D118 /* Container.Logging.swift */; }; + 31266C4BA7CE6C3FBAFBACDD /* Container+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE4B1E4BA98573B6FED2D118 /* Container+Logging.swift */; }; 35175F8F168EDB5EB83BD8E9 /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C074BAC560F277E806146C60 /* SimpleBinding.swift */; }; 3547656EF55D129316B7C5E2 /* InstanceMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CADDB3E9E363310028AA5920 /* InstanceMaker.swift */; }; 35847FDC65085C6741D2A132 /* SimpleBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */; }; @@ -75,7 +75,7 @@ 377EE35B80E8F91543B52F0C /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; 37E07236E0E63570242CE23F /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; 37FE9A9C76DB50ABB28AF9BE /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; - 38FACA739BA59278725FAE67 /* ServiceEntry.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03CDF95C1EAFCD54450B34B6 /* ServiceEntry.TypeForwarding.swift */; }; + 38FACA739BA59278725FAE67 /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03CDF95C1EAFCD54450B34B6 /* ServiceEntry+TypeForwarding.swift */; }; 39431794D93EA4DDD0BBB2C5 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; 39F9BBD670C944E1331FAB13 /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */; }; 3A149A223FA316F68C0A486A /* NonGeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841D83ADB41363D1E38087B4 /* NonGeneratedMocks.swift */; }; @@ -107,9 +107,9 @@ 4D591BB725EAB0ACF9436900 /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 4DA000959B4D60B509859810 /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; 50B230799AFB8C24D1F5CD5D /* SwinjectSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9527A4CA5BCBA7AFA3596757 /* SwinjectSpec.swift */; }; - 51F2CD3C07148069167AB6E9 /* ServiceEntry.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03CDF95C1EAFCD54450B34B6 /* ServiceEntry.TypeForwarding.swift */; }; + 51F2CD3C07148069167AB6E9 /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03CDF95C1EAFCD54450B34B6 /* ServiceEntry+TypeForwarding.swift */; }; 5329D4D400755935B22C0881 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1FA0377AF4799D42E9462FA /* BasicAssembly.swift */; }; - 5381C2CDA084C5BEF82D7521 /* Container.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C2DBC728B763B04CB25963 /* Container.TypeForwarding.swift */; }; + 5381C2CDA084C5BEF82D7521 /* Container+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C2DBC728B763B04CB25963 /* Container+TypeForwarding.swift */; }; 53DC7093FD7C2FEE16154DED /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */; }; 549227903CFDDF4E8272C691 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; 54A1FEE340AC3A2413876AD2 /* ScopeRegistryKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */; }; @@ -139,7 +139,7 @@ 64A8413AD2ED65BB25BD0113 /* BindingKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = A24B4E8F1CA18603DBB6884A /* BindingKey.swift */; }; 64BC606D6414CB4BE8834B08 /* GeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */; }; 65764CCFA94D4C0A0822507A /* UnboundScopeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 671D5D89472DAFA916814506 /* UnboundScopeSpec.swift */; }; - 66033468A5FC65C19B60086A /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07B4728F7C73CC5530956A2 /* Resolver.swift */; }; + 66033468A5FC65C19B60086A /* Resolver+LegacyApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07B4728F7C73CC5530956A2 /* Resolver+LegacyApi.swift */; }; 661B5A18940BA6E67D9BA65E /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; 67A89300EA08B0FB7AB0FBF8 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; 68A42DF14E0117A95B44148F /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C765B92B00C0AC8625BB4AC9 /* Quick.framework */; }; @@ -154,18 +154,18 @@ 71C4A75D54446D844BA5FB85 /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; 73214A0BF7D4AE8B78DEB4FD /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = A10187BB3A994165E7FC1528 /* ScopedBinding.swift */; }; 741344C30785507B22DF703B /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; - 7472B748AEA9F4D1E5EF9A70 /* Container.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C13D01A2DE6F53DF3175D22 /* Container.Arguments.swift */; }; + 7472B748AEA9F4D1E5EF9A70 /* Container+Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C13D01A2DE6F53DF3175D22 /* Container+Arguments.swift */; }; 7480A500FEC04BB9CB048AE1 /* BinderEnvironmentSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */; }; 76B3D9DBF8D5593F67A7B7E6 /* ContextedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4021EB1EA6A2770920FAD979 /* ContextedResolverSpec.swift */; }; - 782801544D9F468F536E045E /* Container.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C2DBC728B763B04CB25963 /* Container.TypeForwarding.swift */; }; + 782801544D9F468F536E045E /* Container+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C2DBC728B763B04CB25963 /* Container+TypeForwarding.swift */; }; 7845113EAF8FFAFD5EC10540 /* BindingKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */; }; 788AE378F10DA216265FFF52 /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; - 78ACD9EBF8625ECD24103A17 /* ServiceEntry.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03CDF95C1EAFCD54450B34B6 /* ServiceEntry.TypeForwarding.swift */; }; - 7DD047C203659BCA7F04E48D /* Container.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C13D01A2DE6F53DF3175D22 /* Container.Arguments.swift */; }; - 7E0539C5CD130F0AC4B02096 /* Container.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C13D01A2DE6F53DF3175D22 /* Container.Arguments.swift */; }; + 78ACD9EBF8625ECD24103A17 /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03CDF95C1EAFCD54450B34B6 /* ServiceEntry+TypeForwarding.swift */; }; + 7DD047C203659BCA7F04E48D /* Container+Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C13D01A2DE6F53DF3175D22 /* Container+Arguments.swift */; }; + 7E0539C5CD130F0AC4B02096 /* Container+Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C13D01A2DE6F53DF3175D22 /* Container+Arguments.swift */; }; 7E9CB14F7E723994920F6E44 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 34AFFAC41BA9D02A38BDB7A3 /* Nimble.framework */; }; - 7F22099B321798EAD85DBC07 /* Container.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C2DBC728B763B04CB25963 /* Container.TypeForwarding.swift */; }; - 8108969F33C37040624E0D02 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07B4728F7C73CC5530956A2 /* Resolver.swift */; }; + 7F22099B321798EAD85DBC07 /* Container+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C2DBC728B763B04CB25963 /* Container+TypeForwarding.swift */; }; + 8108969F33C37040624E0D02 /* Resolver+LegacyApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07B4728F7C73CC5530956A2 /* Resolver+LegacyApi.swift */; }; 816F47E9D87CAE910091B484 /* Closable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D0BCCCD61CD9BECC29E064 /* Closable.swift */; }; 828C5B0915A8D08CF98F5F4C /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; 833635A5D695AA696559C250 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 359BCD3DA6F0CC2241878C82 /* EmploymentAssembly.swift */; }; @@ -203,7 +203,7 @@ 9623C7F8B9FED0541D959708 /* ScopeRegistryKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2902FD4C1A50263340A51FFB /* ScopeRegistryKeySpec.swift */; }; 963D32297EE5CA9C18A0C246 /* NonGeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841D83ADB41363D1E38087B4 /* NonGeneratedMocks.swift */; }; 971B97F191A9FF75A6586E0A /* ScopeRegistryKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */; }; - 982E4682C79B74226C03E0C9 /* ServiceEntry.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03CDF95C1EAFCD54450B34B6 /* ServiceEntry.TypeForwarding.swift */; }; + 982E4682C79B74226C03E0C9 /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03CDF95C1EAFCD54450B34B6 /* ServiceEntry+TypeForwarding.swift */; }; 9A551D43739EDE556FF3F9ED /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBDB67E0FC7B8BEE58EECFBB /* BehaviorFakes.swift */; }; 9AFDF0122A11B2E996B16C3D /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; 9B04477B2B117122CB99989A /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1910A1471C3CA9EA86F350BA /* LoadAwareAssembly.swift */; }; @@ -220,8 +220,8 @@ A014793C56F8966AD2D7CC50 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; A19EFC58B60E547CC3A3A6BE /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 74DE57FB3E8228904E6FE0D7 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; A1B275A2EFA22C45AC46B31E /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; - A3815641CEB5A06759D288E0 /* Resolver3.swift in Sources */ = {isa = PBXBuildFile; fileRef = C11D19C5F01647E4A576514A /* Resolver3.swift */; }; - A4490FF7ACCC5CBFB2C1896C /* Container.Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE4B1E4BA98573B6FED2D118 /* Container.Logging.swift */; }; + A3815641CEB5A06759D288E0 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = C11D19C5F01647E4A576514A /* Resolver.swift */; }; + A4490FF7ACCC5CBFB2C1896C /* Container+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE4B1E4BA98573B6FED2D118 /* Container+Logging.swift */; }; A44D1B2E48E1C0FEF146933A /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; A4866802E1E597EEFEFDEB66 /* BindingKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = A24B4E8F1CA18603DBB6884A /* BindingKey.swift */; }; A4C25E4406175163B7C5B810 /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B3797A6BB56AE76CEC19F2A /* SwinjectApiSpec.swift */; }; @@ -288,16 +288,16 @@ E423395FC7006DD82513F347 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; E484C3994AD91E91C454B11D /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; E584841CFD26155FB056C85A /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; - E7E9DE84E1861D125F8D686A /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07B4728F7C73CC5530956A2 /* Resolver.swift */; }; + E7E9DE84E1861D125F8D686A /* Resolver+LegacyApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07B4728F7C73CC5530956A2 /* Resolver+LegacyApi.swift */; }; E80558941BC2149C25A17495 /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; E8A89383E1D1106DEABB778B /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; E8D70420E8A3C91D01BC3B5B /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; - E9F5DF3C8AA3A9651D504AF7 /* Container.Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE4B1E4BA98573B6FED2D118 /* Container.Logging.swift */; }; + E9F5DF3C8AA3A9651D504AF7 /* Container+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE4B1E4BA98573B6FED2D118 /* Container+Logging.swift */; }; EABC31077D2369311E6C14C3 /* ServiceEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38615FC8EEB466C5C1EAD21C /* ServiceEntry.swift */; }; EAC4EA9BAC87B34AD5BA2110 /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3586A4987B7C7C8122D674E /* SwinjectError.swift */; }; EAD0757CE0163D3549CB5405 /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; EC4EE4B0AECDBA8EC0B8F73D /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BA261FF01C5F5510873B3EC /* Animal.swift */; }; - EE5763938068B3FA56D1BA59 /* Resolver3.swift in Sources */ = {isa = PBXBuildFile; fileRef = C11D19C5F01647E4A576514A /* Resolver3.swift */; }; + EE5763938068B3FA56D1BA59 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = C11D19C5F01647E4A576514A /* Resolver.swift */; }; EEB1E43EF50551F8B9793381 /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59111BE319C59E4CD6CF68CD /* Assembler.swift */; }; EEB3FA667B9103A8417F5EA4 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; EEC04BEF02E6776003CC2003 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B580B43E1891812C97209 /* Binding.swift */; }; @@ -305,7 +305,7 @@ EF25C3A81E568411233E6867 /* ServiceEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38615FC8EEB466C5C1EAD21C /* ServiceEntry.swift */; }; EFCA30870DA55BC3572AF634 /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BA261FF01C5F5510873B3EC /* Animal.swift */; }; EFE89A258FE9EDFFE5F88FD0 /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 74DE57FB3E8228904E6FE0D7 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; - F151A5040BB76E8E909D9D6B /* Container.Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE4B1E4BA98573B6FED2D118 /* Container.Logging.swift */; }; + F151A5040BB76E8E909D9D6B /* Container+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE4B1E4BA98573B6FED2D118 /* Container+Logging.swift */; }; F1D5D6A0A7679A14317617E1 /* GeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */; }; F4D2218805AEBF797A2945AB /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEE8FDF4B975A8F2A9FCC5FF /* Food.swift */; }; F4D7CC563B9C212A418C4EBC /* ScopeRegistryKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2902FD4C1A50263340A51FFB /* ScopeRegistryKeySpec.swift */; }; @@ -314,11 +314,11 @@ F8DB4EDA0367BCC6832E4AA6 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; FAF8F8B75F63D43995A004E8 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; FB6FF5C5729B8E050616CCF6 /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 6EA4ECB5E4CEC9751AD36854 /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - FC120C659D0A6FB9CE757CB7 /* Resolver3.swift in Sources */ = {isa = PBXBuildFile; fileRef = C11D19C5F01647E4A576514A /* Resolver3.swift */; }; + FC120C659D0A6FB9CE757CB7 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = C11D19C5F01647E4A576514A /* Resolver.swift */; }; FCBA6B66A6BBA29B3EC6CDDD /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; FD1678ED0C9813A653D9C68B /* BinderEnvironmentSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */; }; FDB7873663CEFBF7BE76ECFF /* BindingKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = A24B4E8F1CA18603DBB6884A /* BindingKey.swift */; }; - FDCF96E2A442CDC6815B8127 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07B4728F7C73CC5530956A2 /* Resolver.swift */; }; + FDCF96E2A442CDC6815B8127 /* Resolver+LegacyApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07B4728F7C73CC5530956A2 /* Resolver+LegacyApi.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -408,7 +408,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 03CDF95C1EAFCD54450B34B6 /* ServiceEntry.TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServiceEntry.TypeForwarding.swift; sourceTree = ""; }; + 03CDF95C1EAFCD54450B34B6 /* ServiceEntry+TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ServiceEntry+TypeForwarding.swift"; sourceTree = ""; }; 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.swift; sourceTree = ""; }; 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopedBindingSpec.swift; sourceTree = ""; }; 0E0B580B43E1891812C97209 /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; @@ -449,7 +449,7 @@ 671D5D89472DAFA916814506 /* UnboundScopeSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnboundScopeSpec.swift; sourceTree = ""; }; 683A1FB7D7F4E9508D57E936 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceWrapper.swift; sourceTree = ""; }; - 6C13D01A2DE6F53DF3175D22 /* Container.Arguments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.Arguments.swift; sourceTree = ""; }; + 6C13D01A2DE6F53DF3175D22 /* Container+Arguments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Arguments.swift"; sourceTree = ""; }; 6EA4ECB5E4CEC9751AD36854 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 722CAC1761180366DE75A4A6 /* TestModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestModels.swift; sourceTree = ""; }; 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.CustomStringConvertible.swift; sourceTree = ""; }; @@ -461,7 +461,7 @@ 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeneratedMocks.swift; sourceTree = ""; }; 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTreeBuilderSpec.swift; sourceTree = ""; }; 9527A4CA5BCBA7AFA3596757 /* SwinjectSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectSpec.swift; sourceTree = ""; }; - 95C2DBC728B763B04CB25963 /* Container.TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.TypeForwarding.swift; sourceTree = ""; }; + 95C2DBC728B763B04CB25963 /* Container+TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+TypeForwarding.swift"; sourceTree = ""; }; 9620155728133F451B31C0AD /* Swinject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Swinject.swift; sourceTree = ""; }; 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistryKey.swift; sourceTree = ""; }; 9985BEF966DCBB28B12BE17B /* Person.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Person.swift; sourceTree = ""; }; @@ -477,15 +477,19 @@ B92B8E618A08408404FB2A7A /* TypeBinder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinder.swift; sourceTree = ""; }; BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StandardScopeRegistrySpec.swift; sourceTree = ""; }; BBDB67E0FC7B8BEE58EECFBB /* BehaviorFakes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BehaviorFakes.swift; sourceTree = ""; }; - BE4B1E4BA98573B6FED2D118 /* Container.Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.Logging.swift; sourceTree = ""; }; + BE4B1E4BA98573B6FED2D118 /* Container+Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Logging.swift"; sourceTree = ""; }; BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Behavior.swift; sourceTree = ""; }; C074BAC560F277E806146C60 /* SimpleBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleBinding.swift; sourceTree = ""; }; - C07B4728F7C73CC5530956A2 /* Resolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Resolver.swift; sourceTree = ""; }; - C11D19C5F01647E4A576514A /* Resolver3.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Resolver3.swift; sourceTree = ""; }; + C07B4728F7C73CC5530956A2 /* Resolver+LegacyApi.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Resolver+LegacyApi.swift"; sourceTree = ""; }; + C11D19C5F01647E4A576514A /* Resolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Resolver.swift; sourceTree = ""; }; C765B92B00C0AC8625BB4AC9 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; CADDB3E9E363310028AA5920 /* InstanceMaker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceMaker.swift; sourceTree = ""; }; CC85CB215058F95C0BC190B1 /* Bridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bridge.swift; sourceTree = ""; }; CD4D866322E4C6DB0042ACDC /* ObjectScope.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObjectScope.swift; sourceTree = ""; }; + CD4D866B22E4D4E00042ACDC /* AutoMockable.stencil */ = {isa = PBXFileReference; lastKnownFileType = text; path = AutoMockable.stencil; sourceTree = ""; }; + CD4D866C22E4D54D0042ACDC /* Resolver+LegacyApi.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+LegacyApi.swifttemplate"; sourceTree = ""; }; + CD4D866D22E4D54D0042ACDC /* Container+Arguments.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Container+Arguments.swifttemplate"; sourceTree = ""; }; + CD4D866F22E4D54D0042ACDC /* ServiceEntry+TypeForwarding.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "ServiceEntry+TypeForwarding.swifttemplate"; sourceTree = ""; }; D1FA0377AF4799D42E9462FA /* BasicAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BasicAssembly.swift; sourceTree = ""; }; E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRequest.swift; sourceTree = ""; }; E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; @@ -612,15 +616,15 @@ 59111BE319C59E4CD6CF68CD /* Assembler.swift */, F290F6B1207A0557A528220B /* Assembly.swift */, 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */, - 6C13D01A2DE6F53DF3175D22 /* Container.Arguments.swift */, - BE4B1E4BA98573B6FED2D118 /* Container.Logging.swift */, + 6C13D01A2DE6F53DF3175D22 /* Container+Arguments.swift */, + BE4B1E4BA98573B6FED2D118 /* Container+Logging.swift */, 42490D1D0C395951243F5CFF /* Container.swift */, - 95C2DBC728B763B04CB25963 /* Container.TypeForwarding.swift */, + 95C2DBC728B763B04CB25963 /* Container+TypeForwarding.swift */, 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */, CD4D866322E4C6DB0042ACDC /* ObjectScope.swift */, - C07B4728F7C73CC5530956A2 /* Resolver.swift */, + C07B4728F7C73CC5530956A2 /* Resolver+LegacyApi.swift */, 38615FC8EEB466C5C1EAD21C /* ServiceEntry.swift */, - 03CDF95C1EAFCD54450B34B6 /* ServiceEntry.TypeForwarding.swift */, + 03CDF95C1EAFCD54450B34B6 /* ServiceEntry+TypeForwarding.swift */, ); path = "2.0 API"; sourceTree = ""; @@ -679,6 +683,7 @@ children = ( D026A6699A2A932511D29E14 /* Sources */, C5602A1B64E47775AF8D5700 /* Tests */, + CD4D866A22E4D4E00042ACDC /* Templates */, 80E97D8FD5574A96B6BC9EB9 /* Frameworks */, 8EB6E58A3F28FAEBBC372598 /* Products */, ); @@ -726,6 +731,17 @@ path = 2.0; sourceTree = ""; }; + CD4D866A22E4D4E00042ACDC /* Templates */ = { + isa = PBXGroup; + children = ( + CD4D866D22E4D54D0042ACDC /* Container+Arguments.swifttemplate */, + CD4D866C22E4D54D0042ACDC /* Resolver+LegacyApi.swifttemplate */, + CD4D866F22E4D54D0042ACDC /* ServiceEntry+TypeForwarding.swifttemplate */, + CD4D866B22E4D4E00042ACDC /* AutoMockable.stencil */, + ); + path = Templates; + sourceTree = ""; + }; D026A6699A2A932511D29E14 /* Sources */ = { isa = PBXGroup; children = ( @@ -766,7 +782,7 @@ CADDB3E9E363310028AA5920 /* InstanceMaker.swift */, E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */, 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */, - C11D19C5F01647E4A576514A /* Resolver3.swift */, + C11D19C5F01647E4A576514A /* Resolver.swift */, 5057BAB33984E3E33469452B /* Scope.swift */, A10187BB3A994165E7FC1528 /* ScopedBinding.swift */, 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */, @@ -1191,9 +1207,9 @@ 49FB15929F16836D51779A1D /* Binding.swift in Sources */, 64A8413AD2ED65BB25BD0113 /* BindingKey.swift in Sources */, 9FEC055DC6BE1D844FE5F082 /* Closable.swift in Sources */, - 0CB9E677FDF7CF424A738F34 /* Container.Arguments.swift in Sources */, - A4490FF7ACCC5CBFB2C1896C /* Container.Logging.swift in Sources */, - 7F22099B321798EAD85DBC07 /* Container.TypeForwarding.swift in Sources */, + 0CB9E677FDF7CF424A738F34 /* Container+Arguments.swift in Sources */, + A4490FF7ACCC5CBFB2C1896C /* Container+Logging.swift in Sources */, + 7F22099B321798EAD85DBC07 /* Container+TypeForwarding.swift in Sources */, 0CED31C429BA9F9B23EB2B1F /* Container.swift in Sources */, 9EF6DF530041FC494572D3DB /* ContextedResolver.swift in Sources */, 3547656EF55D129316B7C5E2 /* InstanceMaker.swift in Sources */, @@ -1201,13 +1217,13 @@ 2DCEEF373F410202226D2DB5 /* InstanceWrapper.swift in Sources */, 9264E4C053A699FE01EAD232 /* Matchable.swift in Sources */, 5C4C106D138E771C872F5E80 /* Resolver+Injection.swift in Sources */, - E7E9DE84E1861D125F8D686A /* Resolver.swift in Sources */, - FC120C659D0A6FB9CE757CB7 /* Resolver3.swift in Sources */, + E7E9DE84E1861D125F8D686A /* Resolver+LegacyApi.swift in Sources */, + FC120C659D0A6FB9CE757CB7 /* Resolver.swift in Sources */, 71C4A75D54446D844BA5FB85 /* Scope.swift in Sources */, 1AD4C43B074F736BBDADA8C9 /* ScopeRegistry.swift in Sources */, 971B97F191A9FF75A6586E0A /* ScopeRegistryKey.swift in Sources */, 3F8EA877F153EE374FF8E31A /* ScopedBinding.swift in Sources */, - 38FACA739BA59278725FAE67 /* ServiceEntry.TypeForwarding.swift in Sources */, + 38FACA739BA59278725FAE67 /* ServiceEntry+TypeForwarding.swift in Sources */, EF25C3A81E568411233E6867 /* ServiceEntry.swift in Sources */, 8D71D83DB3F5D3655FB6C71D /* SimpleBinding.swift in Sources */, 15FA8361AB335F4CC372A52C /* Swinject+Builder.swift in Sources */, @@ -1318,9 +1334,9 @@ 4735419DE3D63E556D07C663 /* Binding.swift in Sources */, FDB7873663CEFBF7BE76ECFF /* BindingKey.swift in Sources */, 2B67E8B80A930E8598FAD10C /* Closable.swift in Sources */, - 7E0539C5CD130F0AC4B02096 /* Container.Arguments.swift in Sources */, - E9F5DF3C8AA3A9651D504AF7 /* Container.Logging.swift in Sources */, - 5381C2CDA084C5BEF82D7521 /* Container.TypeForwarding.swift in Sources */, + 7E0539C5CD130F0AC4B02096 /* Container+Arguments.swift in Sources */, + E9F5DF3C8AA3A9651D504AF7 /* Container+Logging.swift in Sources */, + 5381C2CDA084C5BEF82D7521 /* Container+TypeForwarding.swift in Sources */, AAB6386F88442B22E9F7FF0E /* Container.swift in Sources */, C75EC8F8DD60676B120917EA /* ContextedResolver.swift in Sources */, 58CFFB8C98C465B9101AA9A8 /* InstanceMaker.swift in Sources */, @@ -1328,13 +1344,13 @@ 3B2E8B8CF4825DB05B0233F8 /* InstanceWrapper.swift in Sources */, C50BFD826112288F1D693A30 /* Matchable.swift in Sources */, 741344C30785507B22DF703B /* Resolver+Injection.swift in Sources */, - FDCF96E2A442CDC6815B8127 /* Resolver.swift in Sources */, - 2488CDD8D67CAC5C97BDF8B1 /* Resolver3.swift in Sources */, + FDCF96E2A442CDC6815B8127 /* Resolver+LegacyApi.swift in Sources */, + 2488CDD8D67CAC5C97BDF8B1 /* Resolver.swift in Sources */, 1718A1577AB543174FD8E644 /* Scope.swift in Sources */, 1F4FBB9D795CE9D45E5A8BEE /* ScopeRegistry.swift in Sources */, 54A1FEE340AC3A2413876AD2 /* ScopeRegistryKey.swift in Sources */, 73214A0BF7D4AE8B78DEB4FD /* ScopedBinding.swift in Sources */, - 982E4682C79B74226C03E0C9 /* ServiceEntry.TypeForwarding.swift in Sources */, + 982E4682C79B74226C03E0C9 /* ServiceEntry+TypeForwarding.swift in Sources */, 908AE547955AE4432C1D161A /* ServiceEntry.swift in Sources */, DB14CA46130A816F6FAADE92 /* SimpleBinding.swift in Sources */, FCBA6B66A6BBA29B3EC6CDDD /* Swinject+Builder.swift in Sources */, @@ -1445,9 +1461,9 @@ 705F51FD21F7E1536BFC0C41 /* Binding.swift in Sources */, A4866802E1E597EEFEFDEB66 /* BindingKey.swift in Sources */, 816F47E9D87CAE910091B484 /* Closable.swift in Sources */, - 7472B748AEA9F4D1E5EF9A70 /* Container.Arguments.swift in Sources */, - 31266C4BA7CE6C3FBAFBACDD /* Container.Logging.swift in Sources */, - 0DFB6FB4DF6A713EA545930F /* Container.TypeForwarding.swift in Sources */, + 7472B748AEA9F4D1E5EF9A70 /* Container+Arguments.swift in Sources */, + 31266C4BA7CE6C3FBAFBACDD /* Container+Logging.swift in Sources */, + 0DFB6FB4DF6A713EA545930F /* Container+TypeForwarding.swift in Sources */, C8F1F075F5792C9936B0577D /* Container.swift in Sources */, 6BFA0D58FD4131D3A2248208 /* ContextedResolver.swift in Sources */, 48714C7B99D346C83E1E8293 /* InstanceMaker.swift in Sources */, @@ -1455,13 +1471,13 @@ 53DC7093FD7C2FEE16154DED /* InstanceWrapper.swift in Sources */, DEB3F135FFAEBF825881E886 /* Matchable.swift in Sources */, 1C2F5A09F986586F85FAC3E8 /* Resolver+Injection.swift in Sources */, - 8108969F33C37040624E0D02 /* Resolver.swift in Sources */, - EE5763938068B3FA56D1BA59 /* Resolver3.swift in Sources */, + 8108969F33C37040624E0D02 /* Resolver+LegacyApi.swift in Sources */, + EE5763938068B3FA56D1BA59 /* Resolver.swift in Sources */, D557A108A21751DF75542692 /* Scope.swift in Sources */, D7DE20CC15F3A6BD09E43A75 /* ScopeRegistry.swift in Sources */, 9437AF5CAAD1A2D033AE3599 /* ScopeRegistryKey.swift in Sources */, D6AA597218691F1FE87724E7 /* ScopedBinding.swift in Sources */, - 78ACD9EBF8625ECD24103A17 /* ServiceEntry.TypeForwarding.swift in Sources */, + 78ACD9EBF8625ECD24103A17 /* ServiceEntry+TypeForwarding.swift in Sources */, EABC31077D2369311E6C14C3 /* ServiceEntry.swift in Sources */, 35175F8F168EDB5EB83BD8E9 /* SimpleBinding.swift in Sources */, D18275ADB0E56D3087894518 /* Swinject+Builder.swift in Sources */, @@ -1486,9 +1502,9 @@ EEC04BEF02E6776003CC2003 /* Binding.swift in Sources */, E0D7B3285AA1FE51E14A52A1 /* BindingKey.swift in Sources */, 418F111C8E128766AC8E33CC /* Closable.swift in Sources */, - 7DD047C203659BCA7F04E48D /* Container.Arguments.swift in Sources */, - F151A5040BB76E8E909D9D6B /* Container.Logging.swift in Sources */, - 782801544D9F468F536E045E /* Container.TypeForwarding.swift in Sources */, + 7DD047C203659BCA7F04E48D /* Container+Arguments.swift in Sources */, + F151A5040BB76E8E909D9D6B /* Container+Logging.swift in Sources */, + 782801544D9F468F536E045E /* Container+TypeForwarding.swift in Sources */, 91DAE32F86CEA897AD52AEDB /* Container.swift in Sources */, 151340C24653963B97464BA9 /* ContextedResolver.swift in Sources */, 41EEA4724CD401F38F9622E3 /* InstanceMaker.swift in Sources */, @@ -1496,13 +1512,13 @@ 39F9BBD670C944E1331FAB13 /* InstanceWrapper.swift in Sources */, D3828F01A014F3A06B1141D7 /* Matchable.swift in Sources */, 90B4143005C86717AC76B6EE /* Resolver+Injection.swift in Sources */, - 66033468A5FC65C19B60086A /* Resolver.swift in Sources */, - A3815641CEB5A06759D288E0 /* Resolver3.swift in Sources */, + 66033468A5FC65C19B60086A /* Resolver+LegacyApi.swift in Sources */, + A3815641CEB5A06759D288E0 /* Resolver.swift in Sources */, B2FCC51BB61148422256A14A /* Scope.swift in Sources */, 46A14FAA5AA73BE8A0397707 /* ScopeRegistry.swift in Sources */, 18A07EB6FB61F3CDCC766AF4 /* ScopeRegistryKey.swift in Sources */, 6F5323F408E5708076C02768 /* ScopedBinding.swift in Sources */, - 51F2CD3C07148069167AB6E9 /* ServiceEntry.TypeForwarding.swift in Sources */, + 51F2CD3C07148069167AB6E9 /* ServiceEntry+TypeForwarding.swift in Sources */, 4939B8B795061A74ADFC02D8 /* ServiceEntry.swift in Sources */, 87F8C64D9E8B4317C0C036E0 /* SimpleBinding.swift in Sources */, D267BD55BBEDE3ECEC449472 /* Swinject+Builder.swift in Sources */, diff --git a/Templates/Container+Arguments.swifttemplate b/Templates/Container+Arguments.swifttemplate new file mode 100644 index 00000000..dc72f8cb --- /dev/null +++ b/Templates/Container+Arguments.swifttemplate @@ -0,0 +1,27 @@ +<% let arg_count = 9 %> +// sourcery:inline:ContainerArgumentsApi +extension Container { +<%_ (1...arg_count).forEach { i in + let arg_types = (1...i).map { "Arg\($0)" }.joined(separator: ", ") + let arg_description = i == 1 ? "\(i) argument" : "\(i) arguments" +-%> + /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. + /// + /// - Parameters: + /// - serviceType: The service type to register. + /// - name: A registration name, which is used to differentiate from other registrations + /// that have the same service and factory types. + /// - factory: The closure to specify how the service type is resolved with the dependencies of the type. + /// It is invoked when the `Container` needs to instantiate the instance. + /// It takes a `Resolver` instance and <%= arg_description %> to inject dependencies to the instance, + /// and returns the instance of the component type for the service. + /// + /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. + @discardableResult + public func register>(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, <%= arg_types %>) -> Service) -> ServiceEntry { + fatalError() + } + +<%_ } -%> +} +// sourcery:end diff --git a/Sources/2.0 API/Resolver.erb b/Templates/Resolver+LegacyApi.swifttemplate similarity index 58% rename from Sources/2.0 API/Resolver.erb rename to Templates/Resolver+LegacyApi.swifttemplate index 0eeb0369..086990f0 100644 --- a/Sources/2.0 API/Resolver.erb +++ b/Templates/Resolver+LegacyApi.swifttemplate @@ -1,28 +1,14 @@ -// -// Resolver.swift -// Swinject -// -// Created by Yoichi Tagaya on 8/18/15. -// Copyright (c) 2015 Swinject Contributors. All rights reserved. -// - -// -// NOTICE: -// -// Resolver.swift is generated from Resolver.erb by ERB. -// Do NOT modify Container.Arguments.swift directly. -// Instead, modify Resolver.erb and run `script/gencode` at the project root directory to generate the code. -// - -<% arg_count = 9 %> - -public protocol Resolver { +<% let arg_count = 9 %> +// sourcery:inline:ResolverLegacyApi +public extension Resolver { /// Retrieves the instance with the specified service type. /// /// - Parameter serviceType: The service type to resolve. /// /// - Returns: The resolved service type instance, or nil if no service is found. - func resolve(_ serviceType: Service.Type) -> Service? + func resolve(_ serviceType: Service.Type) -> Service? { + fatalError() + } /// Retrieves the instance with the specified service type and registration name. /// @@ -31,39 +17,41 @@ public protocol Resolver { /// - name: The registration name. /// /// - Returns: The resolved service type instance, or nil if no service with the name is found. - func resolve(_ serviceType: Service.Type, name: String?) -> Service? - -<% (1..arg_count).each do |i| %> -<% arg_types = (1..i).map { |n| "Arg#{n}" }.join(", ") %> -<% arg_param = i == 1 ? "argument: Arg1" : "arguments arg1: Arg1, " + (2..i).map{ |n| "_ arg#{n}: Arg#{n}" }.join(", ") %> -<% arg_param_name = i == 1 ? "argument" : "arguments" %> -<% arg_param_description = i == 1 ? "#{i} argument" : "list of #{i} arguments" %> + func resolve(_ serviceType: Service.Type, name: String?) -> Service? { + fatalError() + } + +<%_ (1...arg_count).forEach { i in + let arg_types = (1...i).map { "Arg\($0)" }.joined(separator: ", ") + let arg_param = i == 1 ? "argument: Arg1" : "arguments arg1: Arg1, " + (2...i).map{ "_ arg\($0): Arg\($0)" }.joined(separator: ", ") + let arg_param_name = i == 1 ? "argument" : "arguments" + let arg_param_description = i == 1 ? "\(i) argument" : "list of \(i) arguments" +-%> /// Retrieves the instance with the specified service type and <%= arg_param_description %> to the factory closure. /// /// - Parameters: /// - serviceType: The service type to resolve. - /// - <%= arg_param_name %>: <%= arg_param_description.capitalize %> to pass to the factory closure. + /// - <%= arg_param_name %>: <%= arg_param_description.capitalized %> to pass to the factory closure. /// /// - Returns: The resolved service type instance, or nil if no registration for the service type /// and <%= arg_param_description %> is found. - func resolve>( - _ serviceType: Service.Type, - <%= arg_param %>) -> Service? + func resolve>(_ serviceType: Service.Type, <%= arg_param %>) -> Service? { + fatalError() + } /// Retrieves the instance with the specified service type, <%= arg_param_description %> to the factory closure and registration name. /// /// - Parameters: /// - serviceType: The service type to resolve. /// - name: The registration name. - /// - <%= arg_param_name %>: <%= arg_param_description.capitalize %> to pass to the factory closure. + /// - <%= arg_param_name %>: <%= arg_param_description.capitalized %> to pass to the factory closure. /// /// - Returns: The resolved service type instance, or nil if no registration for the service type, /// <%= arg_param_description %> and name is found. - func resolve>( - _ serviceType: Service.Type, - name: String?, - <%= arg_param %>) -> Service? - -<% end %> + func resolve>(_ serviceType: Service.Type, name: String?, <%= arg_param %>) -> Service? { + fatalError() + } +<%_ } -%> } +// sourcery:end diff --git a/Sources/2.0 API/ServiceEntry.TypeForwarding.erb b/Templates/ServiceEntry+TypeForwarding.swifttemplate similarity index 53% rename from Sources/2.0 API/ServiceEntry.TypeForwarding.erb rename to Templates/ServiceEntry+TypeForwarding.swifttemplate index 6ea81699..587a4018 100644 --- a/Sources/2.0 API/ServiceEntry.TypeForwarding.erb +++ b/Templates/ServiceEntry+TypeForwarding.swifttemplate @@ -1,21 +1,5 @@ -// -// ServiceEntry.TypeForwarding.swift -// Swinject-iOS -// -// Created by Jakub Vaňo on 16/02/2018. -// Copyright © 2018 Swinject Contributors. All rights reserved. -// - -// -// NOTICE: -// -// ServiceEntry.TypeForwarding.swift is generated from ServiceEntry.TypeForwarding.erb by ERB. -// Do NOT modify ServiceEntry.TypeForwarding.swift directly. -// Instead, modify ServiceEntry.TypeForwarding.erb and run `script/gencode` at the project root directory to generate the code. -// - -<% type_count = 9 %> - +<% let type_count = 9 %> +// sourcery:inline:ServiceEntryTypeForwarding extension ServiceEntry { /// Adds another type which should be resolved using this ServiceEntry - i.e. using the same object scope, /// arguments and `initCompleted` closures @@ -25,13 +9,14 @@ extension ServiceEntry { /// - name: A registration name, which is used to differentiate from other registrations of the same `type` @discardableResult public func implements(_ type: T.Type, name: String? = nil) -> ServiceEntry { - container?.forward(type, name: name, to: self) + fatalError() return self } -<% (2..type_count).each do |i| %> -<% types = (1..i).map { |n| "T#{n}" }.join(", ") %> -<% params = (1..i).map { |n| "_ type#{n}: T#{n}.Type"}.join(", ") %> +<%_ (2...type_count).forEach { i in + let types = (1...i).map { "T\($0)" }.joined(separator: ", ") + let params = (1...i).map { "_ type\($0): T\($0).Type"}.joined(separator: ", ") +-%> /// Adds multiple types which should be resolved using this ServiceEntry - i.e. using the same object scope, /// arguments and `initCompleted` closures /// @@ -39,9 +24,9 @@ extension ServiceEntry { /// - types: List of <%= i %> types resolution of which should be forwarded @discardableResult public func implements<<%= types %>>(<%= params %>) -> ServiceEntry { - return self<% (1..i).each do |k| %>.implements(type<%= k %>)<% end %> - + return self<% (1...i).forEach { %>.implements(type<%= $0 %>)<% } %> } -<% end %> +<% } %> } +// sourcery:end diff --git a/Tests/Support/Convenience.swift b/Tests/Support/Convenience.swift index c2fce17b..783b0887 100644 --- a/Tests/Support/Convenience.swift +++ b/Tests/Support/Convenience.swift @@ -6,19 +6,19 @@ import Nimble @testable import Swinject extension InstanceMaker where Argument == Void, Context == Any { - func makeInstance(resolver: Resolver3) throws -> MadeType { + func makeInstance(resolver: Resolver) throws -> MadeType { try makeInstance(arg: (), context: (), resolver: resolver) } } extension InstanceMaker where Argument == Void { - func makeInstance(context: Context, resolver: Resolver3) throws -> MadeType { + func makeInstance(context: Context, resolver: Resolver) throws -> MadeType { try makeInstance(arg: (), context: context, resolver: resolver) } } extension InstanceMaker where Context == Any { - func makeInstance(arg: Argument, resolver: Resolver3) throws -> MadeType { + func makeInstance(arg: Argument, resolver: Resolver) throws -> MadeType { try makeInstance(arg: arg, context: (), resolver: resolver) } } diff --git a/Tests/Support/GeneratedMocks.swift b/Tests/Support/GeneratedMocks.swift index 6fd07d26..2e9a38c6 100644 --- a/Tests/Support/GeneratedMocks.swift +++ b/Tests/Support/GeneratedMocks.swift @@ -86,12 +86,12 @@ class AnyInstanceMakerMock: AnyInstanceMaker { var makeInstanceArgContextResolverCalled: Bool { return makeInstanceArgContextResolverCallsCount > 0 } - var makeInstanceArgContextResolverReceivedArguments: (arg: Any, context: Any, resolver: Resolver3)? - var makeInstanceArgContextResolverReceivedInvocations: [(arg: Any, context: Any, resolver: Resolver3)] = [] + var makeInstanceArgContextResolverReceivedArguments: (arg: Any, context: Any, resolver: Resolver)? + var makeInstanceArgContextResolverReceivedInvocations: [(arg: Any, context: Any, resolver: Resolver)] = [] var makeInstanceArgContextResolverReturnValue: Any! - var makeInstanceArgContextResolverClosure: ((Any, Any, Resolver3) throws -> Any)? + var makeInstanceArgContextResolverClosure: ((Any, Any, Resolver) throws -> Any)? - func makeInstance(arg: Any, context: Any, resolver: Resolver3) throws -> Any { + func makeInstance(arg: Any, context: Any, resolver: Resolver) throws -> Any { if let error = makeInstanceArgContextResolverThrowableError { throw error } @@ -102,7 +102,7 @@ class AnyInstanceMakerMock: AnyInstanceMaker { } } -class AnyResolver3Mock: AnyResolver3 { +class AnyResolverMock: AnyResolver { //MARK: - resolve @@ -201,12 +201,12 @@ class BindingMock: Binding { var instanceArgContextResolverCalled: Bool { return instanceArgContextResolverCallsCount > 0 } - var instanceArgContextResolverReceivedArguments: (arg: Any, context: Any, resolver: Resolver3)? - var instanceArgContextResolverReceivedInvocations: [(arg: Any, context: Any, resolver: Resolver3)] = [] + var instanceArgContextResolverReceivedArguments: (arg: Any, context: Any, resolver: Resolver)? + var instanceArgContextResolverReceivedInvocations: [(arg: Any, context: Any, resolver: Resolver)] = [] var instanceArgContextResolverReturnValue: Any! - var instanceArgContextResolverClosure: ((Any, Any, Resolver3) throws -> Any)? + var instanceArgContextResolverClosure: ((Any, Any, Resolver) throws -> Any)? - func instance(arg: Any, context: Any, resolver: Resolver3) throws -> Any { + func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any { if let error = instanceArgContextResolverThrowableError { throw error } @@ -296,3 +296,9 @@ class StaticScopeRegistryMock: StaticScopeRegistry { } } + + + + + + diff --git a/Tests/Support/NonGeneratedMocks.swift b/Tests/Support/NonGeneratedMocks.swift index ac5bff12..d7d019ba 100644 --- a/Tests/Support/NonGeneratedMocks.swift +++ b/Tests/Support/NonGeneratedMocks.swift @@ -4,7 +4,7 @@ @testable import Swinject -class DummyResolver3: Resolver3 { +class DummyResolver: Resolver { func resolve( _: InstanceRequest ) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { @@ -21,17 +21,17 @@ extension AnyInstanceMakerMock: InstanceMaker { } class DummyMaker: InstanceMaker { - func makeInstance(arg _: Argument, context: Context, resolver _: Resolver3) throws -> Any { + func makeInstance(arg _: Argument, context: Context, resolver _: Resolver) throws -> Any { fatalError() } } // sourcery: AutoMockable -protocol AnyResolver3 { +protocol AnyResolver { func resolve(_ request: Any) throws -> Any } -extension AnyResolver3Mock: Resolver3 { +extension AnyResolverMock: Resolver { func resolve( _ request: InstanceRequest ) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { diff --git a/Tests/Unit Specs/BinderEnvironmentSpec.swift b/Tests/Unit Specs/BinderEnvironmentSpec.swift index 76bed4ef..09da8a37 100644 --- a/Tests/Unit Specs/BinderEnvironmentSpec.swift +++ b/Tests/Unit Specs/BinderEnvironmentSpec.swift @@ -16,7 +16,7 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { } it("returns given instance") { let maker = instance(42) - expect { try maker.makeInstance(resolver: DummyResolver3()) } == 42 + expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 } } describe("provider") { @@ -26,7 +26,7 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { } it("returns instance made by provider method") { let maker = provider { 42 } - expect { try maker.makeInstance(resolver: DummyResolver3()) } == 42 + expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 } it("does not call builder until instance is requested") { var called = false @@ -34,20 +34,20 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { expect(called).to(beFalse()) } it("calls builder with given resolver") { - var passedResolver3: Resolver3? - let resolver = DummyResolver3() - let maker = provider { passedResolver3 = $0 } + var passedResolver: Resolver? + let resolver = DummyResolver() + let maker = provider { passedResolver = $0 } _ = try? maker.makeInstance(resolver: resolver) - expect(passedResolver3) === resolver + expect(passedResolver) === resolver } it("rethrows error from builder") { let maker = provider { throw SwinjectError() } - expect { try maker.makeInstance(resolver: DummyResolver3()) }.to(throwError()) + expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) } it("does not reuse instance") { let maker = provider { Human() } - let instance1 = try? maker.makeInstance(resolver: DummyResolver3()) - let instance2 = try? maker.makeInstance(resolver: DummyResolver3()) + let instance1 = try? maker.makeInstance(resolver: DummyResolver()) + let instance2 = try? maker.makeInstance(resolver: DummyResolver()) expect(instance1) !== instance2 } } @@ -58,7 +58,7 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { } it("returns instance made by builder method") { let maker = factory { (_, _: Void) in 42 } - expect { try maker.makeInstance(resolver: DummyResolver3()) } == 42 + expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 } it("does not call builder until instance is requested") { var called = false @@ -66,48 +66,48 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { expect(called).to(beFalse()) } it("calls builder with given resolver") { - var passedResolver3: Resolver3? - let resolver = DummyResolver3() - let maker = factory { (r, _: Void) in passedResolver3 = r } + var passedResolver: Resolver? + let resolver = DummyResolver() + let maker = factory { (r, _: Void) in passedResolver = r } _ = try? maker.makeInstance(resolver: resolver) - expect(passedResolver3) === resolver + expect(passedResolver) === resolver } it("calls builder with given argument") { var passedArgument: Int? let maker = factory { (_, arg: Int) in passedArgument = arg } - _ = try? maker.makeInstance(arg: 42, resolver: DummyResolver3()) + _ = try? maker.makeInstance(arg: 42, resolver: DummyResolver()) expect(passedArgument) == 42 } it("rethrows error from builder") { let maker = factory { (_, _: Void) in throw SwinjectError() } - expect { try maker.makeInstance(resolver: DummyResolver3()) }.to(throwError()) + expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) } it("does not reuse instance") { let maker = factory { (_, _: Void) in Human() } - let instance1 = try? maker.makeInstance(resolver: DummyResolver3()) - let instance2 = try? maker.makeInstance(resolver: DummyResolver3()) + let instance1 = try? maker.makeInstance(resolver: DummyResolver()) + let instance2 = try? maker.makeInstance(resolver: DummyResolver()) expect(instance1) !== instance2 } describe("multiple arguments") { it("works with 2 arguments") { let maker = factory { (_, _: Int, _: Double) in 42 } let arguments = (1, 1.0) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver3()) } == 42 + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 } it("works with 3 arguments") { let maker = factory { (_, _: Int, _: Double, _: String) in 42 } let arguments = (1, 1.0, "") - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver3()) } == 42 + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 } it("works with 4 arguments") { let maker = factory { (_, _: Int, _: Double, _: String, _: Float) in 42 } let arguments = (1, 1.0, "", Float(1.0)) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver3()) } == 42 + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 } it("works with 5 arguments") { let maker = factory { (_, _: Int, _: Double, _: String, _: Float, _: Int) in 42 } let arguments = (1, 1.0, "", Float(1.0), 5) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver3()) } == 42 + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 } } } @@ -118,7 +118,7 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { } it("returns instance made by builder") { let maker = singleton { 42 } - expect { try maker.makeInstance(resolver: DummyResolver3()) } == 42 + expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 } it("does not call builder until instance is requested") { var called = false @@ -126,20 +126,20 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { expect(called).to(beFalse()) } it("calls builder with given resolver") { - var passedResolver3: Resolver3? - let resolver = DummyResolver3() - let maker = singleton { passedResolver3 = $0 } + var passedResolver: Resolver? + let resolver = DummyResolver() + let maker = singleton { passedResolver = $0 } _ = try? maker.makeInstance(resolver: resolver) - expect(passedResolver3) === resolver + expect(passedResolver) === resolver } it("rethrows error from builder") { let maker = singleton { throw SwinjectError() } - expect { try maker.makeInstance(resolver: DummyResolver3()) }.to(throwError()) + expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) } it("does not reuse instance") { let maker = singleton { Human() } - let instance1 = try? maker.makeInstance(resolver: DummyResolver3()) - let instance2 = try? maker.makeInstance(resolver: DummyResolver3()) + let instance1 = try? maker.makeInstance(resolver: DummyResolver()) + let instance2 = try? maker.makeInstance(resolver: DummyResolver()) expect(instance1) !== instance2 } } @@ -150,7 +150,7 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { } it("returns instance made by builder method") { let maker = multiton { (_, _: Void) in 42 } - expect { try maker.makeInstance(resolver: DummyResolver3()) } == 42 + expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 } it("does not call builder until instance is requested") { var called = false @@ -158,48 +158,48 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { expect(called).to(beFalse()) } it("calls builder with given resolver") { - var passedResolver3: Resolver3? - let resolver = DummyResolver3() - let maker = multiton { (r, _: Void) in passedResolver3 = r } + var passedResolver: Resolver? + let resolver = DummyResolver() + let maker = multiton { (r, _: Void) in passedResolver = r } _ = try? maker.makeInstance(resolver: resolver) - expect(passedResolver3) === resolver + expect(passedResolver) === resolver } it("calls builder with given argument") { var passedArgument: Int? let maker = multiton { (_, arg: Int) in passedArgument = arg } - _ = try? maker.makeInstance(arg: 42, resolver: DummyResolver3()) + _ = try? maker.makeInstance(arg: 42, resolver: DummyResolver()) expect(passedArgument) == 42 } it("rethrows error from builder") { let maker = multiton { (_, _: Void) in throw SwinjectError() } - expect { try maker.makeInstance(resolver: DummyResolver3()) }.to(throwError()) + expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) } it("does not reuse instance") { let maker = multiton { (_, _: Void) in Human() } - let instance1 = try? maker.makeInstance(resolver: DummyResolver3()) - let instance2 = try? maker.makeInstance(resolver: DummyResolver3()) + let instance1 = try? maker.makeInstance(resolver: DummyResolver()) + let instance2 = try? maker.makeInstance(resolver: DummyResolver()) expect(instance1) !== instance2 } describe("multiple arguments") { it("works with 2 arguments") { let maker = multiton { (_, _: Int, _: Double) in 42 } let arguments = (1, 1.0) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver3()) } == 42 + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 } it("works with 3 arguments") { let maker = multiton { (_, _: Int, _: Double, _: String) in 42 } let arguments = (1, 1.0, "") - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver3()) } == 42 + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 } it("works with 4 arguments") { let maker = multiton { (_, _: Int, _: Double, _: String, _: Float) in 42 } let arguments = (1, 1.0, "", Float(1.0)) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver3()) } == 42 + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 } it("works with 5 arguments") { let maker = multiton { (_, _: Int, _: Double, _: String, _: Float, _: Int) in 42 } let arguments = (1, 1.0, "", Float(1.0), 5) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver3()) } == 42 + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 } } } @@ -212,7 +212,7 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { describe("provider") { it("returns instance made by provider method") { let maker = environment.provider { _, _ in 42 } - expect { try maker.makeInstance(resolver: DummyResolver3()) } == 42 + expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 } it("does not call builder until instance is requested") { var called = false @@ -220,33 +220,33 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { expect(called).to(beFalse()) } it("calls builder with given resolver") { - var passedResolver3: Resolver3? - let resolver = DummyResolver3() - let maker = environment.provider { r, _ in passedResolver3 = r } + var passedResolver: Resolver? + let resolver = DummyResolver() + let maker = environment.provider { r, _ in passedResolver = r } _ = try? maker.makeInstance(resolver: resolver) - expect(passedResolver3) === resolver + expect(passedResolver) === resolver } it("calls builder with given context") { var passedContext: Any? let maker = environment.provider { _, c in passedContext = c } - _ = try? maker.makeInstance(context: 42, resolver: DummyResolver3()) + _ = try? maker.makeInstance(context: 42, resolver: DummyResolver()) expect(passedContext as? Int) == 42 } it("rethrows error from builder") { let maker = environment.provider { _, _ in throw SwinjectError() } - expect { try maker.makeInstance(resolver: DummyResolver3()) }.to(throwError()) + expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) } it("does not reuse instance") { let maker = environment.provider { _, _ in Human() } - let instance1 = try? maker.makeInstance(resolver: DummyResolver3()) - let instance2 = try? maker.makeInstance(resolver: DummyResolver3()) + let instance1 = try? maker.makeInstance(resolver: DummyResolver()) + let instance2 = try? maker.makeInstance(resolver: DummyResolver()) expect(instance1) !== instance2 } } describe("factory") { it("returns instance made by builder method") { let maker = environment.factory { (_, _, _: Void) in 42 } - expect { try maker.makeInstance(resolver: DummyResolver3()) } == 42 + expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 } it("does not call builder until instance is requested") { var called = false @@ -254,54 +254,54 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { expect(called).to(beFalse()) } it("calls builder with given resolver") { - var passedResolver3: Resolver3? - let resolver = DummyResolver3() - let maker = environment.factory { (r, _, _: Void) in passedResolver3 = r } + var passedResolver: Resolver? + let resolver = DummyResolver() + let maker = environment.factory { (r, _, _: Void) in passedResolver = r } _ = try? maker.makeInstance(resolver: resolver) - expect(passedResolver3) === resolver + expect(passedResolver) === resolver } it("calls builder with given context") { var passedContext: Any? let maker = environment.factory { (_, c, _: Void) in passedContext = c } - _ = try? maker.makeInstance(context: 42, resolver: DummyResolver3()) + _ = try? maker.makeInstance(context: 42, resolver: DummyResolver()) expect(passedContext as? Int) == 42 } it("calls builder with given argument") { var passedArgument: Int? let maker = environment.factory { (_, _, arg: Int) in passedArgument = arg } - _ = try? maker.makeInstance(arg: 42, resolver: DummyResolver3()) + _ = try? maker.makeInstance(arg: 42, resolver: DummyResolver()) expect(passedArgument) == 42 } it("rethrows error from builder") { let maker = environment.factory { (_, _, _: Void) in throw SwinjectError() } - expect { try maker.makeInstance(resolver: DummyResolver3()) }.to(throwError()) + expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) } it("does not reuse instance") { let maker = environment.factory { (_, _, _: Void) in Human() } - let instance1 = try? maker.makeInstance(resolver: DummyResolver3()) - let instance2 = try? maker.makeInstance(resolver: DummyResolver3()) + let instance1 = try? maker.makeInstance(resolver: DummyResolver()) + let instance2 = try? maker.makeInstance(resolver: DummyResolver()) expect(instance1) !== instance2 } describe("multiple arguments") { it("works with 2 arguments") { let maker = environment.factory { (_, _, _: Int, _: Double) in 42 } let arguments = (1, 1.0) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver3()) } == 42 + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 } it("works with 3 arguments") { let maker = environment.factory { (_, _, _: Int, _: Double, _: String) in 42 } let arguments = (1, 1.0, "") - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver3()) } == 42 + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 } it("works with 4 arguments") { let maker = environment.factory { (_, _, _: Int, _: Double, _: String, _: Float) in 42 } let arguments = (1, 1.0, "", Float(1.0)) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver3()) } == 42 + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 } it("works with 5 arguments") { let maker = environment.factory { (_, _, _: Int, _: Double, _: String, _: Float, _: Int) in 42 } let arguments = (1, 1.0, "", Float(1.0), 5) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver3()) } == 42 + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 } } } @@ -320,7 +320,7 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { } it("returns instance made by builder") { let maker = environment.singleton { 42 } - expect { try maker.makeInstance(resolver: DummyResolver3()) } == 42 + expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 } it("does not call builder until instance is requested") { var called = false @@ -328,26 +328,26 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { expect(called).to(beFalse()) } it("calls builder with given resolver") { - var passedResolver3: Resolver3? - let resolver = DummyResolver3() - let maker = environment.singleton { passedResolver3 = $0 } + var passedResolver: Resolver? + let resolver = DummyResolver() + let maker = environment.singleton { passedResolver = $0 } _ = try? maker.makeInstance(resolver: resolver) - expect(passedResolver3) === resolver + expect(passedResolver) === resolver } it("calls builder with given context") { var passedContext: Any? let maker = environment.singleton { _, c in passedContext = c } - _ = try? maker.makeInstance(context: "context", resolver: DummyResolver3()) + _ = try? maker.makeInstance(context: "context", resolver: DummyResolver()) expect(passedContext as? String) == "context" } it("rethrows error from builder") { let maker = environment.singleton { throw SwinjectError() } - expect { try maker.makeInstance(resolver: DummyResolver3()) }.to(throwError()) + expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) } it("does not reuse instance") { let maker = environment.singleton { _, _ in Human() } - let instance1 = try? maker.makeInstance(resolver: DummyResolver3()) - let instance2 = try? maker.makeInstance(resolver: DummyResolver3()) + let instance1 = try? maker.makeInstance(resolver: DummyResolver()) + let instance2 = try? maker.makeInstance(resolver: DummyResolver()) expect(instance1) !== instance2 } } @@ -358,7 +358,7 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { } it("returns instance made by builder method") { let maker = environment.multiton { (_, _, _: Void) in 42 } - expect { try maker.makeInstance(resolver: DummyResolver3()) } == 42 + expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 } it("does not call builder until instance is requested") { var called = false @@ -366,54 +366,54 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { expect(called).to(beFalse()) } it("calls builder with given resolver") { - var passedResolver3: Resolver3? - let resolver = DummyResolver3() - let maker = environment.multiton { (r, _, _: Void) in passedResolver3 = r } + var passedResolver: Resolver? + let resolver = DummyResolver() + let maker = environment.multiton { (r, _, _: Void) in passedResolver = r } _ = try? maker.makeInstance(resolver: resolver) - expect(passedResolver3) === resolver + expect(passedResolver) === resolver } it("calls builder with given context") { var passedContext: Any? let maker = environment.multiton { (_, c, _: Void) in passedContext = c } - _ = try? maker.makeInstance(context: "context", resolver: DummyResolver3()) + _ = try? maker.makeInstance(context: "context", resolver: DummyResolver()) expect(passedContext as? String) == "context" } it("calls builder with given argument") { var passedArgument: Int? let maker = environment.multiton { (_, _, arg: Int) in passedArgument = arg } - _ = try? maker.makeInstance(arg: 42, resolver: DummyResolver3()) + _ = try? maker.makeInstance(arg: 42, resolver: DummyResolver()) expect(passedArgument) == 42 } it("rethrows error from builder") { let maker = environment.multiton { (_, _, _: Void) in throw SwinjectError() } - expect { try maker.makeInstance(resolver: DummyResolver3()) }.to(throwError()) + expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) } it("does not reuse instance") { let maker = environment.multiton { (_, _, _: Void) in Human() } - let instance1 = try? maker.makeInstance(resolver: DummyResolver3()) - let instance2 = try? maker.makeInstance(resolver: DummyResolver3()) + let instance1 = try? maker.makeInstance(resolver: DummyResolver()) + let instance2 = try? maker.makeInstance(resolver: DummyResolver()) expect(instance1) !== instance2 } describe("multiple arguments") { it("works with 2 arguments") { let maker = environment.multiton { (_, _, _: Int, _: Double) in 42 } let arguments = (1, 1.0) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver3()) } == 42 + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 } it("works with 3 arguments") { let maker = environment.multiton { (_, _, _: Int, _: Double, _: String) in 42 } let arguments = (1, 1.0, "") - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver3()) } == 42 + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 } it("works with 4 arguments") { let maker = environment.multiton { (_, _, _: Int, _: Double, _: String, _: Float) in 42 } let arguments = (1, 1.0, "", Float(1.0)) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver3()) } == 42 + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 } it("works with 5 arguments") { let maker = environment.multiton { (_, _, _: Int, _: Double, _: String, _: Float, _: Int) in 42 } let arguments = (1, 1.0, "", Float(1.0), 5) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver3()) } == 42 + expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 } } } diff --git a/Tests/Unit Specs/ContextedResolverSpec.swift b/Tests/Unit Specs/ContextedResolverSpec.swift index 3e652950..76cff98e 100644 --- a/Tests/Unit Specs/ContextedResolverSpec.swift +++ b/Tests/Unit Specs/ContextedResolverSpec.swift @@ -6,13 +6,13 @@ import Nimble import Quick @testable import Swinject -class ContextedResolver3Spec: QuickSpec { override func spec() { - var resolver: ContextedResolver3! - var wrapped = AnyResolver3Mock() +class ContextedResolverSpec: QuickSpec { override func spec() { + var resolver: ContextedResolver! + var wrapped = AnyResolverMock() beforeEach { - wrapped = AnyResolver3Mock() + wrapped = AnyResolverMock() wrapped.resolveReturnValue = 0 - resolver = ContextedResolver3(context: (), resolver: wrapped) + resolver = ContextedResolver(context: (), resolver: wrapped) } describe("resolve") { it("returns value from wrapped resolver") { @@ -35,7 +35,7 @@ class ContextedResolver3Spec: QuickSpec { override func spec() { expect(receivedRequest?.argument) == "argument" } it("calls wrapped resolver with it's context") { - let resolver = ContextedResolver3(context: "context", resolver: wrapped) + let resolver = ContextedResolver(context: "context", resolver: wrapped) _ = try? resolver.resolve(request(type: Int.self, tag: NoTag(), arg: ())) let receivedRequest = wrapped.resolveReceivedRequest as? InstanceRequest, String, Void> expect(receivedRequest?.context) == "context" diff --git a/Tests/Unit Specs/ScopedBindingSpec.swift b/Tests/Unit Specs/ScopedBindingSpec.swift index aff0b347..1e324db3 100644 --- a/Tests/Unit Specs/ScopedBindingSpec.swift +++ b/Tests/Unit Specs/ScopedBindingSpec.swift @@ -65,13 +65,13 @@ class ScopedBindingSpec: QuickSpec { override func spec() { binding = ScopedBinding(key: key, maker: maker, scope: scope) } it("retrieves registry using passed context") { - _ = try? binding.instance(arg: (), context: "context", resolver: DummyResolver3()) + _ = try? binding.instance(arg: (), context: "context", resolver: DummyResolver()) expect(scope.registryForReceivedContext as? String) == "context" } it("retrieves instance from registry using a correct key") { let descriptor = AnyTypeDescriptorMock() key.descriptor = descriptor - _ = try? binding.instance(arg: 42, context: (), resolver: DummyResolver3()) + _ = try? binding.instance(arg: 42, context: (), resolver: DummyResolver()) expect(registry.instanceKeyReceivedKey?.argument as? Int) == 42 expect(registry.instanceKeyReceivedKey?.descriptor) === descriptor } @@ -81,17 +81,17 @@ class ScopedBindingSpec: QuickSpec { override func spec() { } it("returns instance produced by maker") { maker.makeInstanceArgContextResolverReturnValue = 42 - let instance = try? binding.instance(arg: (), context: (), resolver: DummyResolver3()) as? Int + let instance = try? binding.instance(arg: (), context: (), resolver: DummyResolver()) as? Int expect(instance) == 42 } it("rethrows error from maker") { maker.makeInstanceArgContextResolverThrowableError = TestError() expect { - try binding.instance(arg: (), context: (), resolver: DummyResolver3()) + try binding.instance(arg: (), context: (), resolver: DummyResolver()) }.to(throwError(errorType: TestError.self)) } it("invokes maker with correct parameters") { - let resolver = DummyResolver3() + let resolver = DummyResolver() _ = try? binding.instance(arg: 42, context: "context", resolver: resolver) expect(maker.makeInstanceArgContextResolverReceivedArguments?.arg as? Int) == 42 expect(maker.makeInstanceArgContextResolverReceivedArguments?.context as? String) == "context" diff --git a/Tests/Unit Specs/TypeBinderSpec.swift b/Tests/Unit Specs/TypeBinderSpec.swift index 1fd1d366..dc5dc819 100644 --- a/Tests/Unit Specs/TypeBinderSpec.swift +++ b/Tests/Unit Specs/TypeBinderSpec.swift @@ -36,7 +36,7 @@ class TypeBinderSpec: QuickSpec { override func spec() { } it("works with passing instance directly") { let binding = bbind(descriptor).with(42) - expect { try binding.instance(arg: (), context: (), resolver: DummyResolver3()) as? Int } == 42 + expect { try binding.instance(arg: (), context: (), resolver: DummyResolver()) as? Int } == 42 } } describe("`&` method") { @@ -51,7 +51,7 @@ class TypeBinderSpec: QuickSpec { override func spec() { } it("works with passing instance directly") { let binding = bbind(descriptor) & 42 - expect { try binding.instance(arg: (), context: (), resolver: DummyResolver3()) as? Int } == 42 + expect { try binding.instance(arg: (), context: (), resolver: DummyResolver()) as? Int } == 42 } } } } diff --git a/script/gencode b/script/gencode deleted file mode 100755 index ff72dd0a..00000000 --- a/script/gencode +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -files="Sources/Container.Arguments Sources/SynchronizedResolver.Arguments Sources/Resolver Sources/ServiceEntry.TypeForwarding" - -for file in $files; do - echo "Generating code to $file.swift" - erb -v -T 1 $file.erb > $file.swift -done From 85580aeb653e97c7819e9d4d29baffaa4d557c69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 21 Jul 2019 20:47:51 +0200 Subject: [PATCH 092/239] Implement ServiceEntry entry conformance to Binding --- Sources/2.0 API/ServiceEntry.swift | 44 +++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/Sources/2.0 API/ServiceEntry.swift b/Sources/2.0 API/ServiceEntry.swift index 17912e9c..52b78771 100644 --- a/Sources/2.0 API/ServiceEntry.swift +++ b/Sources/2.0 API/ServiceEntry.swift @@ -5,13 +5,31 @@ /// The `ServiceEntry` class represents an entry of a registered service type. /// As a returned instance from a `register` method of a `Container`, some configurations can be added. public struct ServiceEntry { - let key: AnyBindingKey - let maker: AnyInstanceMaker - var scope: AnyScope? - var initCompleted = [(Resolver, Service) -> Void]() + private let builder: (Resolver, Any, Any) throws -> Service + private var key: AnyBindingKey + private var scope: AnyScope? + private var initCompleted = [(Resolver, Any) throws -> Void]() var objectScope: ObjectScope? { return nil } + init( + contextType: Context.Type, + argumentType: Argument.Type, + name: String?, + builder: @escaping (Resolver, Any, Any) throws -> Service, + scope: AnyScope? + ) { + self.builder = builder + if let name = name { + self.key = BindingKey, Context, Argument>( + descriptor: tagged(Service.self, with: name) + ) + } else { + self.key = BindingKey, Context, Argument>(descriptor: plain(Service.self)) + } + self.scope = scope + } + /// Specifies the object scope to resolve the service. /// /// - Parameter scope: The `ObjectScopeProtocol` value. @@ -46,3 +64,21 @@ public struct ServiceEntry { return self } } + +extension ServiceEntry: Binding { + public func matches(_ key: AnyBindingKey) -> Bool { + self.key.matches(key) + } + + public func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any { + if let scope = scope { + return try scope.registry(for: context).instance( + for: ScopeRegistryKey(descriptor: key.descriptor, argument: arg), + builder: { try builder(resolver, context, arg) }, + finalizer: { instance in try initCompleted.forEach { try $0(resolver, instance) } } + ) + } else { + return try builder(resolver, context, arg) + } + } +} From c34dccad17c55cdaa1a55944b9513d0ddda4f052 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 21 Jul 2019 21:41:00 +0200 Subject: [PATCH 093/239] Implement container registration --- .swiftlint.yml | 2 +- ...nts.swift => Container+Registration.swift} | 58 +++++++++++++++---- Sources/2.0 API/Container.swift | 32 ++-------- Sources/2.0 API/ServiceEntry.swift | 28 ++++----- Swinject.xcodeproj/project.pbxproj | 26 +++++---- Templates/Container+Arguments.swifttemplate | 27 --------- .../Container+Registration.swifttemplate | 51 ++++++++++++++++ 7 files changed, 131 insertions(+), 93 deletions(-) rename Sources/2.0 API/{Container+Arguments.swift => Container+Registration.swift} (76%) delete mode 100644 Templates/Container+Arguments.swifttemplate create mode 100644 Templates/Container+Registration.swifttemplate diff --git a/.swiftlint.yml b/.swiftlint.yml index 405f6902..17213f40 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -6,7 +6,7 @@ included: - Sources - Tests excluded: - - Sources/2.0 API/Container+Arguments.swift + - Sources/2.0 API/Container+Registration.swift - Sources/2.0 API/SynchronizedResolver+Arguments.swift - Sources/2.0 API/Resolver+LegacyApi.swift - Sources/2.0 API/ServiceEntry+TypeForwarding.swift diff --git a/Sources/2.0 API/Container+Arguments.swift b/Sources/2.0 API/Container+Registration.swift similarity index 76% rename from Sources/2.0 API/Container+Arguments.swift rename to Sources/2.0 API/Container+Registration.swift index 7805ed3c..355b91a5 100644 --- a/Sources/2.0 API/Container+Arguments.swift +++ b/Sources/2.0 API/Container+Registration.swift @@ -2,8 +2,28 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -// sourcery:inline:ContainerArgumentsApi +// sourcery:inline:ContainerRegistrationApi extension Container { + /// Adds a registration for the specified service with the factory closure to specify how the service is + /// resolved with dependencies. + /// + /// - Parameters: + /// - serviceType: The service type to register. + /// - name: A registration name, which is used to differentiate from other registrations + /// that have the same service and factory types. + /// - factory: The closure to specify how the service type is resolved with the dependencies of the type. + /// It is invoked when the `Container` needs to instantiate the instance. + /// It takes a `Resolver` to inject dependencies to the instance, + /// and returns the instance of the component type for the service. + /// + /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. + @discardableResult + public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver) -> Service) -> ServiceEntry { + let entry = ServiceEntry(name: name, scope: defaultScope) { (r, _, _: Void) in factory(r) } + bindings.append(entry) + return entry + } + /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. /// /// - Parameters: @@ -18,7 +38,9 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1) -> Service) -> ServiceEntry { - fatalError() + let entry = ServiceEntry(name: name, scope: defaultScope) { (r, _, a: Arg1) in factory(r, a) } + bindings.append(entry) + return entry } /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. @@ -35,7 +57,9 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2) -> Service) -> ServiceEntry { - fatalError() + let entry = ServiceEntry(name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2)) in factory(r, a.0, a.1) } + bindings.append(entry) + return entry } /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. @@ -52,7 +76,9 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3) -> Service) -> ServiceEntry { - fatalError() + let entry = ServiceEntry(name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3)) in factory(r, a.0, a.1, a.2) } + bindings.append(entry) + return entry } /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. @@ -69,7 +95,9 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) -> Service) -> ServiceEntry { - fatalError() + let entry = ServiceEntry(name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3, Arg4)) in factory(r, a.0, a.1, a.2, a.3) } + bindings.append(entry) + return entry } /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. @@ -86,7 +114,9 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) -> Service) -> ServiceEntry { - fatalError() + let entry = ServiceEntry(name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5)) in factory(r, a.0, a.1, a.2, a.3, a.4) } + bindings.append(entry) + return entry } /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. @@ -103,7 +133,9 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6) -> Service) -> ServiceEntry { - fatalError() + let entry = ServiceEntry(name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5) } + bindings.append(entry) + return entry } /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. @@ -120,7 +152,9 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7) -> Service) -> ServiceEntry { - fatalError() + let entry = ServiceEntry(name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6) } + bindings.append(entry) + return entry } /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. @@ -137,7 +171,9 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8) -> Service) -> ServiceEntry { - fatalError() + let entry = ServiceEntry(name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6, a.7) } + bindings.append(entry) + return entry } /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. @@ -154,7 +190,9 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9) -> Service) -> ServiceEntry { - fatalError() + let entry = ServiceEntry(name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6, a.7, a.8) } + bindings.append(entry) + return entry } } diff --git a/Sources/2.0 API/Container.swift b/Sources/2.0 API/Container.swift index 5a127764..796d8df9 100644 --- a/Sources/2.0 API/Container.swift +++ b/Sources/2.0 API/Container.swift @@ -20,10 +20,10 @@ import Foundation /// where `A` and `X` are protocols, `B` is a type conforming `A`, and `Y` is a type conforming `X` /// and depending on `A`. public final class Container { - private let defaultObjectScope: ObjectScope - private var bindings = [Binding]() - private var behaviors = [Behavior]() - private var swinject: Swinject { + let defaultScope: AnyScope? + var bindings = [Binding]() + var behaviors = [Behavior]() + var swinject: Swinject { Swinject(tree: SwinjectTree(bindings: bindings, includeEntries: [])) } @@ -43,7 +43,7 @@ public final class Container { behaviors: [Behavior] = [], registeringClosure: (Container) -> Void = { _ in } ) { - self.defaultObjectScope = defaultObjectScope + self.defaultScope = defaultObjectScope.scope self.behaviors = behaviors registeringClosure(self) } @@ -64,28 +64,6 @@ public final class Container { (objectScope.scope as? Closable)?.close() } - /// Adds a registration for the specified service with the factory closure to specify how the service is - /// resolved with dependencies. - /// - /// - Parameters: - /// - serviceType: The service type to register. - /// - name: A registration name, which is used to differentiate from other registrations - /// that have the same service and factory types. - /// - factory: The closure to specify how the service type is resolved with the dependencies of the type. - /// It is invoked when the `Container` needs to instantiate the instance. - /// It takes a `Resolver` to inject dependencies to the instance, - /// and returns the instance of the component type for the service. - /// - /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. - @discardableResult - public func register( - _ serviceType: Service.Type, - name: String? = nil, - factory: @escaping (Resolver) -> Service - ) -> ServiceEntry { - fatalError() - } - /// Returns a synchronized view of the container for thread safety. /// The returned container is `Resolver` type. Call this method after you finish all service registrations /// to the original container. diff --git a/Sources/2.0 API/ServiceEntry.swift b/Sources/2.0 API/ServiceEntry.swift index 52b78771..456a7a17 100644 --- a/Sources/2.0 API/ServiceEntry.swift +++ b/Sources/2.0 API/ServiceEntry.swift @@ -5,27 +5,23 @@ /// The `ServiceEntry` class represents an entry of a registered service type. /// As a returned instance from a `register` method of a `Container`, some configurations can be added. public struct ServiceEntry { - private let builder: (Resolver, Any, Any) throws -> Service + private let builder: (Resolver, Any, Any) -> Service private var key: AnyBindingKey private var scope: AnyScope? - private var initCompleted = [(Resolver, Any) throws -> Void]() + private var initCompleted = [(Resolver, Any) -> Void]() var objectScope: ObjectScope? { return nil } - init( - contextType: Context.Type, - argumentType: Argument.Type, + init( name: String?, - builder: @escaping (Resolver, Any, Any) throws -> Service, - scope: AnyScope? + scope: AnyScope?, + builder: @escaping (Resolver, Any, Argument) -> Service ) { - self.builder = builder + self.builder = { builder($0, $1, $2 as! Argument) } if let name = name { - self.key = BindingKey, Context, Argument>( - descriptor: tagged(Service.self, with: name) - ) + self.key = BindingKey, Any, Argument>(descriptor: tagged(Service.self, with: name)) } else { - self.key = BindingKey, Context, Argument>(descriptor: plain(Service.self)) + self.key = BindingKey, Any, Argument>(descriptor: plain(Service.self)) } self.scope = scope } @@ -72,13 +68,13 @@ extension ServiceEntry: Binding { public func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any { if let scope = scope { - return try scope.registry(for: context).instance( + return scope.registry(for: context).instance( for: ScopeRegistryKey(descriptor: key.descriptor, argument: arg), - builder: { try builder(resolver, context, arg) }, - finalizer: { instance in try initCompleted.forEach { try $0(resolver, instance) } } + builder: { builder(resolver, context, arg) }, + finalizer: { instance in initCompleted.forEach { $0(resolver, instance) } } ) } else { - return try builder(resolver, context, arg) + return builder(resolver, context, arg) } } } diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 0bb485a6..17dfd386 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -21,7 +21,7 @@ 084187169E13A6E9E709297C /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; 0C24BE87E4F1CF7482DB3468 /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 273FB7A6277E0841E1570990 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 0C7996FAC479BA40B124F470 /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = ADD71387EBA54D7EF60D0089 /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 0CB9E677FDF7CF424A738F34 /* Container+Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C13D01A2DE6F53DF3175D22 /* Container+Arguments.swift */; }; + 0CB9E677FDF7CF424A738F34 /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C13D01A2DE6F53DF3175D22 /* Container+Registration.swift */; }; 0CED31C429BA9F9B23EB2B1F /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42490D1D0C395951243F5CFF /* Container.swift */; }; 0D6143A7732F1334275D3658 /* UnboundScopeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 671D5D89472DAFA916814506 /* UnboundScopeSpec.swift */; }; 0DFB6FB4DF6A713EA545930F /* Container+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C2DBC728B763B04CB25963 /* Container+TypeForwarding.swift */; }; @@ -154,15 +154,15 @@ 71C4A75D54446D844BA5FB85 /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; 73214A0BF7D4AE8B78DEB4FD /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = A10187BB3A994165E7FC1528 /* ScopedBinding.swift */; }; 741344C30785507B22DF703B /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; - 7472B748AEA9F4D1E5EF9A70 /* Container+Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C13D01A2DE6F53DF3175D22 /* Container+Arguments.swift */; }; + 7472B748AEA9F4D1E5EF9A70 /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C13D01A2DE6F53DF3175D22 /* Container+Registration.swift */; }; 7480A500FEC04BB9CB048AE1 /* BinderEnvironmentSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */; }; 76B3D9DBF8D5593F67A7B7E6 /* ContextedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4021EB1EA6A2770920FAD979 /* ContextedResolverSpec.swift */; }; 782801544D9F468F536E045E /* Container+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C2DBC728B763B04CB25963 /* Container+TypeForwarding.swift */; }; 7845113EAF8FFAFD5EC10540 /* BindingKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */; }; 788AE378F10DA216265FFF52 /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; 78ACD9EBF8625ECD24103A17 /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03CDF95C1EAFCD54450B34B6 /* ServiceEntry+TypeForwarding.swift */; }; - 7DD047C203659BCA7F04E48D /* Container+Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C13D01A2DE6F53DF3175D22 /* Container+Arguments.swift */; }; - 7E0539C5CD130F0AC4B02096 /* Container+Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C13D01A2DE6F53DF3175D22 /* Container+Arguments.swift */; }; + 7DD047C203659BCA7F04E48D /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C13D01A2DE6F53DF3175D22 /* Container+Registration.swift */; }; + 7E0539C5CD130F0AC4B02096 /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C13D01A2DE6F53DF3175D22 /* Container+Registration.swift */; }; 7E9CB14F7E723994920F6E44 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 34AFFAC41BA9D02A38BDB7A3 /* Nimble.framework */; }; 7F22099B321798EAD85DBC07 /* Container+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C2DBC728B763B04CB25963 /* Container+TypeForwarding.swift */; }; 8108969F33C37040624E0D02 /* Resolver+LegacyApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07B4728F7C73CC5530956A2 /* Resolver+LegacyApi.swift */; }; @@ -449,7 +449,7 @@ 671D5D89472DAFA916814506 /* UnboundScopeSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnboundScopeSpec.swift; sourceTree = ""; }; 683A1FB7D7F4E9508D57E936 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceWrapper.swift; sourceTree = ""; }; - 6C13D01A2DE6F53DF3175D22 /* Container+Arguments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Arguments.swift"; sourceTree = ""; }; + 6C13D01A2DE6F53DF3175D22 /* Container+Registration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Registration.swift"; sourceTree = ""; }; 6EA4ECB5E4CEC9751AD36854 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 722CAC1761180366DE75A4A6 /* TestModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestModels.swift; sourceTree = ""; }; 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.CustomStringConvertible.swift; sourceTree = ""; }; @@ -485,10 +485,11 @@ C765B92B00C0AC8625BB4AC9 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; CADDB3E9E363310028AA5920 /* InstanceMaker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceMaker.swift; sourceTree = ""; }; CC85CB215058F95C0BC190B1 /* Bridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bridge.swift; sourceTree = ""; }; + CD38F90522E4EC1400A9EEFF /* .swiftlint.yml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = .swiftlint.yml; sourceTree = ""; }; CD4D866322E4C6DB0042ACDC /* ObjectScope.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObjectScope.swift; sourceTree = ""; }; CD4D866B22E4D4E00042ACDC /* AutoMockable.stencil */ = {isa = PBXFileReference; lastKnownFileType = text; path = AutoMockable.stencil; sourceTree = ""; }; CD4D866C22E4D54D0042ACDC /* Resolver+LegacyApi.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+LegacyApi.swifttemplate"; sourceTree = ""; }; - CD4D866D22E4D54D0042ACDC /* Container+Arguments.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Container+Arguments.swifttemplate"; sourceTree = ""; }; + CD4D866D22E4D54D0042ACDC /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; CD4D866F22E4D54D0042ACDC /* ServiceEntry+TypeForwarding.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "ServiceEntry+TypeForwarding.swifttemplate"; sourceTree = ""; }; D1FA0377AF4799D42E9462FA /* BasicAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BasicAssembly.swift; sourceTree = ""; }; E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRequest.swift; sourceTree = ""; }; @@ -616,7 +617,7 @@ 59111BE319C59E4CD6CF68CD /* Assembler.swift */, F290F6B1207A0557A528220B /* Assembly.swift */, 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */, - 6C13D01A2DE6F53DF3175D22 /* Container+Arguments.swift */, + 6C13D01A2DE6F53DF3175D22 /* Container+Registration.swift */, BE4B1E4BA98573B6FED2D118 /* Container+Logging.swift */, 42490D1D0C395951243F5CFF /* Container.swift */, 95C2DBC728B763B04CB25963 /* Container+TypeForwarding.swift */, @@ -681,6 +682,7 @@ A4F7E56739BB9CB479DDDBF6 = { isa = PBXGroup; children = ( + CD38F90522E4EC1400A9EEFF /* .swiftlint.yml */, D026A6699A2A932511D29E14 /* Sources */, C5602A1B64E47775AF8D5700 /* Tests */, CD4D866A22E4D4E00042ACDC /* Templates */, @@ -734,7 +736,7 @@ CD4D866A22E4D4E00042ACDC /* Templates */ = { isa = PBXGroup; children = ( - CD4D866D22E4D54D0042ACDC /* Container+Arguments.swifttemplate */, + CD4D866D22E4D54D0042ACDC /* Container+Registration.swifttemplate */, CD4D866C22E4D54D0042ACDC /* Resolver+LegacyApi.swifttemplate */, CD4D866F22E4D54D0042ACDC /* ServiceEntry+TypeForwarding.swifttemplate */, CD4D866B22E4D4E00042ACDC /* AutoMockable.stencil */, @@ -1207,7 +1209,7 @@ 49FB15929F16836D51779A1D /* Binding.swift in Sources */, 64A8413AD2ED65BB25BD0113 /* BindingKey.swift in Sources */, 9FEC055DC6BE1D844FE5F082 /* Closable.swift in Sources */, - 0CB9E677FDF7CF424A738F34 /* Container+Arguments.swift in Sources */, + 0CB9E677FDF7CF424A738F34 /* Container+Registration.swift in Sources */, A4490FF7ACCC5CBFB2C1896C /* Container+Logging.swift in Sources */, 7F22099B321798EAD85DBC07 /* Container+TypeForwarding.swift in Sources */, 0CED31C429BA9F9B23EB2B1F /* Container.swift in Sources */, @@ -1334,7 +1336,7 @@ 4735419DE3D63E556D07C663 /* Binding.swift in Sources */, FDB7873663CEFBF7BE76ECFF /* BindingKey.swift in Sources */, 2B67E8B80A930E8598FAD10C /* Closable.swift in Sources */, - 7E0539C5CD130F0AC4B02096 /* Container+Arguments.swift in Sources */, + 7E0539C5CD130F0AC4B02096 /* Container+Registration.swift in Sources */, E9F5DF3C8AA3A9651D504AF7 /* Container+Logging.swift in Sources */, 5381C2CDA084C5BEF82D7521 /* Container+TypeForwarding.swift in Sources */, AAB6386F88442B22E9F7FF0E /* Container.swift in Sources */, @@ -1461,7 +1463,7 @@ 705F51FD21F7E1536BFC0C41 /* Binding.swift in Sources */, A4866802E1E597EEFEFDEB66 /* BindingKey.swift in Sources */, 816F47E9D87CAE910091B484 /* Closable.swift in Sources */, - 7472B748AEA9F4D1E5EF9A70 /* Container+Arguments.swift in Sources */, + 7472B748AEA9F4D1E5EF9A70 /* Container+Registration.swift in Sources */, 31266C4BA7CE6C3FBAFBACDD /* Container+Logging.swift in Sources */, 0DFB6FB4DF6A713EA545930F /* Container+TypeForwarding.swift in Sources */, C8F1F075F5792C9936B0577D /* Container.swift in Sources */, @@ -1502,7 +1504,7 @@ EEC04BEF02E6776003CC2003 /* Binding.swift in Sources */, E0D7B3285AA1FE51E14A52A1 /* BindingKey.swift in Sources */, 418F111C8E128766AC8E33CC /* Closable.swift in Sources */, - 7DD047C203659BCA7F04E48D /* Container+Arguments.swift in Sources */, + 7DD047C203659BCA7F04E48D /* Container+Registration.swift in Sources */, F151A5040BB76E8E909D9D6B /* Container+Logging.swift in Sources */, 782801544D9F468F536E045E /* Container+TypeForwarding.swift in Sources */, 91DAE32F86CEA897AD52AEDB /* Container.swift in Sources */, diff --git a/Templates/Container+Arguments.swifttemplate b/Templates/Container+Arguments.swifttemplate deleted file mode 100644 index dc72f8cb..00000000 --- a/Templates/Container+Arguments.swifttemplate +++ /dev/null @@ -1,27 +0,0 @@ -<% let arg_count = 9 %> -// sourcery:inline:ContainerArgumentsApi -extension Container { -<%_ (1...arg_count).forEach { i in - let arg_types = (1...i).map { "Arg\($0)" }.joined(separator: ", ") - let arg_description = i == 1 ? "\(i) argument" : "\(i) arguments" --%> - /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. - /// - /// - Parameters: - /// - serviceType: The service type to register. - /// - name: A registration name, which is used to differentiate from other registrations - /// that have the same service and factory types. - /// - factory: The closure to specify how the service type is resolved with the dependencies of the type. - /// It is invoked when the `Container` needs to instantiate the instance. - /// It takes a `Resolver` instance and <%= arg_description %> to inject dependencies to the instance, - /// and returns the instance of the component type for the service. - /// - /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. - @discardableResult - public func register>(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, <%= arg_types %>) -> Service) -> ServiceEntry { - fatalError() - } - -<%_ } -%> -} -// sourcery:end diff --git a/Templates/Container+Registration.swifttemplate b/Templates/Container+Registration.swifttemplate new file mode 100644 index 00000000..a5ed32f4 --- /dev/null +++ b/Templates/Container+Registration.swifttemplate @@ -0,0 +1,51 @@ +<% let arg_count = 9 %> +// sourcery:inline:ContainerRegistrationApi +extension Container { + /// Adds a registration for the specified service with the factory closure to specify how the service is + /// resolved with dependencies. + /// + /// - Parameters: + /// - serviceType: The service type to register. + /// - name: A registration name, which is used to differentiate from other registrations + /// that have the same service and factory types. + /// - factory: The closure to specify how the service type is resolved with the dependencies of the type. + /// It is invoked when the `Container` needs to instantiate the instance. + /// It takes a `Resolver` to inject dependencies to the instance, + /// and returns the instance of the component type for the service. + /// + /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. + @discardableResult + public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver) -> Service) -> ServiceEntry { + let entry = ServiceEntry(name: name, scope: defaultScope) { (r, _, _: Void) in factory(r) } + bindings.append(entry) + return entry + } + +<%_ (1...arg_count).forEach { i in + let arg_types = (1...i).map { "Arg\($0)" }.joined(separator: ", ") + let arg_closure_type = i == 1 ? "Arg1" : "(\(arg_types))" + let arg_description = i == 1 ? "\(i) argument" : "\(i) arguments" + let arg_vars = i == 1 ? "a" : (0.. + /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. + /// + /// - Parameters: + /// - serviceType: The service type to register. + /// - name: A registration name, which is used to differentiate from other registrations + /// that have the same service and factory types. + /// - factory: The closure to specify how the service type is resolved with the dependencies of the type. + /// It is invoked when the `Container` needs to instantiate the instance. + /// It takes a `Resolver` instance and <%= arg_description %> to inject dependencies to the instance, + /// and returns the instance of the component type for the service. + /// + /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. + @discardableResult + public func register>(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, <%= arg_types %>) -> Service) -> ServiceEntry { + let entry = ServiceEntry(name: name, scope: defaultScope) { (r, _, a: <%= arg_closure_type %>) in factory(r, <%= arg_vars %>) } + bindings.append(entry) + return entry + } + +<%_ } -%> +} +// sourcery:end From ba5c8e8419f7710c7b32c1fb967c7799c79dd9f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 21 Jul 2019 21:50:58 +0200 Subject: [PATCH 094/239] Implement resolver legacy api --- Sources/2.0 API/Resolver+LegacyApi.swift | 197 +++++++-------------- Templates/Resolver+LegacyApi.swifttemplate | 38 ++-- 2 files changed, 73 insertions(+), 162 deletions(-) diff --git a/Sources/2.0 API/Resolver+LegacyApi.swift b/Sources/2.0 API/Resolver+LegacyApi.swift index e9ba2a7f..23c07e7b 100644 --- a/Sources/2.0 API/Resolver+LegacyApi.swift +++ b/Sources/2.0 API/Resolver+LegacyApi.swift @@ -4,15 +4,6 @@ // sourcery:inline:ResolverLegacyApi public extension Resolver { - /// Retrieves the instance with the specified service type. - /// - /// - Parameter serviceType: The service type to resolve. - /// - /// - Returns: The resolved service type instance, or nil if no service is found. - func resolve(_ serviceType: Service.Type) -> Service? { - fatalError() - } - /// Retrieves the instance with the specified service type and registration name. /// /// - Parameters: @@ -20,20 +11,12 @@ public extension Resolver { /// - name: The registration name. /// /// - Returns: The resolved service type instance, or nil if no service with the name is found. - func resolve(_ serviceType: Service.Type, name: String?) -> Service? { - fatalError() - } - - /// Retrieves the instance with the specified service type and 1 argument to the factory closure. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - argument: 1 Argument to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// and 1 argument is found. - func resolve(_ serviceType: Service.Type, argument: Arg1) -> Service? { - fatalError() + func resolve(_ serviceType: Service.Type, name: String? = nil) -> Service? { + if let name = name { + return try? resolve(request(tag: name, arg: ())) + } else { + return try? resolve(request(tag: NoTag(), arg: ())) + } } /// Retrieves the instance with the specified service type, 1 argument to the factory closure and registration name. @@ -45,20 +28,12 @@ public extension Resolver { /// /// - Returns: The resolved service type instance, or nil if no registration for the service type, /// 1 argument and name is found. - func resolve(_ serviceType: Service.Type, name: String?, argument: Arg1) -> Service? { - fatalError() - } - - /// Retrieves the instance with the specified service type and list of 2 arguments to the factory closure. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - arguments: List Of 2 Arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// and list of 2 arguments is found. - func resolve(_ serviceType: Service.Type, arguments arg1: Arg1, _ arg2: Arg2) -> Service? { - fatalError() + func resolve(_ serviceType: Service.Type, name: String? = nil, argument: Arg1) -> Service? { + if let name = name { + return try? resolve(request(tag: name, arg: ())) + } else { + return try? resolve(request(tag: NoTag(), arg: argument)) + } } /// Retrieves the instance with the specified service type, list of 2 arguments to the factory closure and registration name. @@ -70,20 +45,12 @@ public extension Resolver { /// /// - Returns: The resolved service type instance, or nil if no registration for the service type, /// list of 2 arguments and name is found. - func resolve(_ serviceType: Service.Type, name: String?, arguments arg1: Arg1, _ arg2: Arg2) -> Service? { - fatalError() - } - - /// Retrieves the instance with the specified service type and list of 3 arguments to the factory closure. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - arguments: List Of 3 Arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// and list of 3 arguments is found. - func resolve(_ serviceType: Service.Type, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> Service? { - fatalError() + func resolve(_ serviceType: Service.Type, name: String? = nil, arguments arg1: Arg1, _ arg2: Arg2) -> Service? { + if let name = name { + return try? resolve(request(tag: name, arg: ())) + } else { + return try? resolve(request(tag: NoTag(), arg: (arg1, arg2))) + } } /// Retrieves the instance with the specified service type, list of 3 arguments to the factory closure and registration name. @@ -95,20 +62,12 @@ public extension Resolver { /// /// - Returns: The resolved service type instance, or nil if no registration for the service type, /// list of 3 arguments and name is found. - func resolve(_ serviceType: Service.Type, name: String?, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> Service? { - fatalError() - } - - /// Retrieves the instance with the specified service type and list of 4 arguments to the factory closure. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - arguments: List Of 4 Arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// and list of 4 arguments is found. - func resolve(_ serviceType: Service.Type, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> Service? { - fatalError() + func resolve(_ serviceType: Service.Type, name: String? = nil, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> Service? { + if let name = name { + return try? resolve(request(tag: name, arg: ())) + } else { + return try? resolve(request(tag: NoTag(), arg: (arg1, arg2, arg3))) + } } /// Retrieves the instance with the specified service type, list of 4 arguments to the factory closure and registration name. @@ -120,20 +79,12 @@ public extension Resolver { /// /// - Returns: The resolved service type instance, or nil if no registration for the service type, /// list of 4 arguments and name is found. - func resolve(_ serviceType: Service.Type, name: String?, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> Service? { - fatalError() - } - - /// Retrieves the instance with the specified service type and list of 5 arguments to the factory closure. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - arguments: List Of 5 Arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// and list of 5 arguments is found. - func resolve(_ serviceType: Service.Type, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> Service? { - fatalError() + func resolve(_ serviceType: Service.Type, name: String? = nil, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> Service? { + if let name = name { + return try? resolve(request(tag: name, arg: ())) + } else { + return try? resolve(request(tag: NoTag(), arg: (arg1, arg2, arg3, arg4))) + } } /// Retrieves the instance with the specified service type, list of 5 arguments to the factory closure and registration name. @@ -145,20 +96,12 @@ public extension Resolver { /// /// - Returns: The resolved service type instance, or nil if no registration for the service type, /// list of 5 arguments and name is found. - func resolve(_ serviceType: Service.Type, name: String?, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> Service? { - fatalError() - } - - /// Retrieves the instance with the specified service type and list of 6 arguments to the factory closure. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - arguments: List Of 6 Arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// and list of 6 arguments is found. - func resolve(_ serviceType: Service.Type, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6) -> Service? { - fatalError() + func resolve(_ serviceType: Service.Type, name: String? = nil, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> Service? { + if let name = name { + return try? resolve(request(tag: name, arg: ())) + } else { + return try? resolve(request(tag: NoTag(), arg: (arg1, arg2, arg3, arg4, arg5))) + } } /// Retrieves the instance with the specified service type, list of 6 arguments to the factory closure and registration name. @@ -170,20 +113,12 @@ public extension Resolver { /// /// - Returns: The resolved service type instance, or nil if no registration for the service type, /// list of 6 arguments and name is found. - func resolve(_ serviceType: Service.Type, name: String?, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6) -> Service? { - fatalError() - } - - /// Retrieves the instance with the specified service type and list of 7 arguments to the factory closure. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - arguments: List Of 7 Arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// and list of 7 arguments is found. - func resolve(_ serviceType: Service.Type, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7) -> Service? { - fatalError() + func resolve(_ serviceType: Service.Type, name: String? = nil, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6) -> Service? { + if let name = name { + return try? resolve(request(tag: name, arg: ())) + } else { + return try? resolve(request(tag: NoTag(), arg: (arg1, arg2, arg3, arg4, arg5, arg6))) + } } /// Retrieves the instance with the specified service type, list of 7 arguments to the factory closure and registration name. @@ -195,20 +130,12 @@ public extension Resolver { /// /// - Returns: The resolved service type instance, or nil if no registration for the service type, /// list of 7 arguments and name is found. - func resolve(_ serviceType: Service.Type, name: String?, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7) -> Service? { - fatalError() - } - - /// Retrieves the instance with the specified service type and list of 8 arguments to the factory closure. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - arguments: List Of 8 Arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// and list of 8 arguments is found. - func resolve(_ serviceType: Service.Type, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8) -> Service? { - fatalError() + func resolve(_ serviceType: Service.Type, name: String? = nil, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7) -> Service? { + if let name = name { + return try? resolve(request(tag: name, arg: ())) + } else { + return try? resolve(request(tag: NoTag(), arg: (arg1, arg2, arg3, arg4, arg5, arg6, arg7))) + } } /// Retrieves the instance with the specified service type, list of 8 arguments to the factory closure and registration name. @@ -220,20 +147,12 @@ public extension Resolver { /// /// - Returns: The resolved service type instance, or nil if no registration for the service type, /// list of 8 arguments and name is found. - func resolve(_ serviceType: Service.Type, name: String?, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8) -> Service? { - fatalError() - } - - /// Retrieves the instance with the specified service type and list of 9 arguments to the factory closure. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - arguments: List Of 9 Arguments to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// and list of 9 arguments is found. - func resolve(_ serviceType: Service.Type, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8, _ arg9: Arg9) -> Service? { - fatalError() + func resolve(_ serviceType: Service.Type, name: String? = nil, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8) -> Service? { + if let name = name { + return try? resolve(request(tag: name, arg: ())) + } else { + return try? resolve(request(tag: NoTag(), arg: (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8))) + } } /// Retrieves the instance with the specified service type, list of 9 arguments to the factory closure and registration name. @@ -245,8 +164,12 @@ public extension Resolver { /// /// - Returns: The resolved service type instance, or nil if no registration for the service type, /// list of 9 arguments and name is found. - func resolve(_ serviceType: Service.Type, name: String?, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8, _ arg9: Arg9) -> Service? { - fatalError() + func resolve(_ serviceType: Service.Type, name: String? = nil, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8, _ arg9: Arg9) -> Service? { + if let name = name { + return try? resolve(request(tag: name, arg: ())) + } else { + return try? resolve(request(tag: NoTag(), arg: (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9))) + } } } diff --git a/Templates/Resolver+LegacyApi.swifttemplate b/Templates/Resolver+LegacyApi.swifttemplate index 086990f0..efa3fab9 100644 --- a/Templates/Resolver+LegacyApi.swifttemplate +++ b/Templates/Resolver+LegacyApi.swifttemplate @@ -1,15 +1,6 @@ <% let arg_count = 9 %> // sourcery:inline:ResolverLegacyApi public extension Resolver { - /// Retrieves the instance with the specified service type. - /// - /// - Parameter serviceType: The service type to resolve. - /// - /// - Returns: The resolved service type instance, or nil if no service is found. - func resolve(_ serviceType: Service.Type) -> Service? { - fatalError() - } - /// Retrieves the instance with the specified service type and registration name. /// /// - Parameters: @@ -17,8 +8,12 @@ public extension Resolver { /// - name: The registration name. /// /// - Returns: The resolved service type instance, or nil if no service with the name is found. - func resolve(_ serviceType: Service.Type, name: String?) -> Service? { - fatalError() + func resolve(_ serviceType: Service.Type, name: String? = nil) -> Service? { + if let name = name { + return try? resolve(request(tag: name, arg: ())) + } else { + return try? resolve(request(tag: NoTag(), arg: ())) + } } <%_ (1...arg_count).forEach { i in @@ -26,19 +21,8 @@ public extension Resolver { let arg_param = i == 1 ? "argument: Arg1" : "arguments arg1: Arg1, " + (2...i).map{ "_ arg\($0): Arg\($0)" }.joined(separator: ", ") let arg_param_name = i == 1 ? "argument" : "arguments" let arg_param_description = i == 1 ? "\(i) argument" : "list of \(i) arguments" + let arg_vars = i == 1 ? "argument" : ("(" + (1...i).map { "arg\($0)" }.joined(separator: ", ") + ")") -%> - /// Retrieves the instance with the specified service type and <%= arg_param_description %> to the factory closure. - /// - /// - Parameters: - /// - serviceType: The service type to resolve. - /// - <%= arg_param_name %>: <%= arg_param_description.capitalized %> to pass to the factory closure. - /// - /// - Returns: The resolved service type instance, or nil if no registration for the service type - /// and <%= arg_param_description %> is found. - func resolve>(_ serviceType: Service.Type, <%= arg_param %>) -> Service? { - fatalError() - } - /// Retrieves the instance with the specified service type, <%= arg_param_description %> to the factory closure and registration name. /// /// - Parameters: @@ -48,8 +32,12 @@ public extension Resolver { /// /// - Returns: The resolved service type instance, or nil if no registration for the service type, /// <%= arg_param_description %> and name is found. - func resolve>(_ serviceType: Service.Type, name: String?, <%= arg_param %>) -> Service? { - fatalError() + func resolve>(_ serviceType: Service.Type, name: String? = nil, <%= arg_param %>) -> Service? { + if let name = name { + return try? resolve(request(tag: name, arg: ())) + } else { + return try? resolve(request(tag: NoTag(), arg: <%= arg_vars %>)) + } } <%_ } -%> From 255dff0c2819a98db961c7c9a81b12e04b66d8c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 21 Jul 2019 21:53:43 +0200 Subject: [PATCH 095/239] Support parent container --- Sources/2.0 API/Container.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sources/2.0 API/Container.swift b/Sources/2.0 API/Container.swift index 796d8df9..5e54292d 100644 --- a/Sources/2.0 API/Container.swift +++ b/Sources/2.0 API/Container.swift @@ -20,11 +20,15 @@ import Foundation /// where `A` and `X` are protocols, `B` is a type conforming `A`, and `Y` is a type conforming `X` /// and depending on `A`. public final class Container { + let parent: Container? let defaultScope: AnyScope? var bindings = [Binding]() var behaviors = [Behavior]() var swinject: Swinject { - Swinject(tree: SwinjectTree(bindings: bindings, includeEntries: [])) + Swinject(tree: SwinjectTree(bindings: allBindings, includeEntries: [])) + } + var allBindings: [Binding] { + return bindings + (parent?.allBindings ?? []) } /// Instantiates a `Container` @@ -43,6 +47,7 @@ public final class Container { behaviors: [Behavior] = [], registeringClosure: (Container) -> Void = { _ in } ) { + self.parent = parent self.defaultScope = defaultObjectScope.scope self.behaviors = behaviors registeringClosure(self) From 8d2aac6abb51b487683836247fc45fa1bcda90cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 21 Jul 2019 22:04:24 +0200 Subject: [PATCH 096/239] Implement behaviors --- Sources/2.0 API/Container+Registration.swift | 20 +++++++++---------- Sources/2.0 API/Container.swift | 7 +++++++ .../Container+Registration.swifttemplate | 4 ++-- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/Sources/2.0 API/Container+Registration.swift b/Sources/2.0 API/Container+Registration.swift index 355b91a5..ae2c2fe4 100644 --- a/Sources/2.0 API/Container+Registration.swift +++ b/Sources/2.0 API/Container+Registration.swift @@ -20,7 +20,7 @@ extension Container { @discardableResult public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver) -> Service) -> ServiceEntry { let entry = ServiceEntry(name: name, scope: defaultScope) { (r, _, _: Void) in factory(r) } - bindings.append(entry) + addEntry(entry, with: name) return entry } @@ -39,7 +39,7 @@ extension Container { @discardableResult public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1) -> Service) -> ServiceEntry { let entry = ServiceEntry(name: name, scope: defaultScope) { (r, _, a: Arg1) in factory(r, a) } - bindings.append(entry) + addEntry(entry, with: name) return entry } @@ -58,7 +58,7 @@ extension Container { @discardableResult public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2) -> Service) -> ServiceEntry { let entry = ServiceEntry(name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2)) in factory(r, a.0, a.1) } - bindings.append(entry) + addEntry(entry, with: name) return entry } @@ -77,7 +77,7 @@ extension Container { @discardableResult public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3) -> Service) -> ServiceEntry { let entry = ServiceEntry(name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3)) in factory(r, a.0, a.1, a.2) } - bindings.append(entry) + addEntry(entry, with: name) return entry } @@ -96,7 +96,7 @@ extension Container { @discardableResult public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) -> Service) -> ServiceEntry { let entry = ServiceEntry(name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3, Arg4)) in factory(r, a.0, a.1, a.2, a.3) } - bindings.append(entry) + addEntry(entry, with: name) return entry } @@ -115,7 +115,7 @@ extension Container { @discardableResult public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) -> Service) -> ServiceEntry { let entry = ServiceEntry(name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5)) in factory(r, a.0, a.1, a.2, a.3, a.4) } - bindings.append(entry) + addEntry(entry, with: name) return entry } @@ -134,7 +134,7 @@ extension Container { @discardableResult public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6) -> Service) -> ServiceEntry { let entry = ServiceEntry(name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5) } - bindings.append(entry) + addEntry(entry, with: name) return entry } @@ -153,7 +153,7 @@ extension Container { @discardableResult public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7) -> Service) -> ServiceEntry { let entry = ServiceEntry(name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6) } - bindings.append(entry) + addEntry(entry, with: name) return entry } @@ -172,7 +172,7 @@ extension Container { @discardableResult public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8) -> Service) -> ServiceEntry { let entry = ServiceEntry(name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6, a.7) } - bindings.append(entry) + addEntry(entry, with: name) return entry } @@ -191,7 +191,7 @@ extension Container { @discardableResult public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9) -> Service) -> ServiceEntry { let entry = ServiceEntry(name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6, a.7, a.8) } - bindings.append(entry) + addEntry(entry, with: name) return entry } diff --git a/Sources/2.0 API/Container.swift b/Sources/2.0 API/Container.swift index 5e54292d..4c46a2ca 100644 --- a/Sources/2.0 API/Container.swift +++ b/Sources/2.0 API/Container.swift @@ -86,6 +86,13 @@ public final class Container { public func addBehavior(_ behavior: Behavior) { behaviors.append(behavior) } + + func addEntry(_ entry: ServiceEntry, with name: String?) { + bindings.append(entry) + behaviors.forEach { + $0.container(self, didRegisterType: Service.self, toService: entry, withName: name) + } + } } // MARK: CustomStringConvertible diff --git a/Templates/Container+Registration.swifttemplate b/Templates/Container+Registration.swifttemplate index a5ed32f4..e039a88b 100644 --- a/Templates/Container+Registration.swifttemplate +++ b/Templates/Container+Registration.swifttemplate @@ -17,7 +17,7 @@ extension Container { @discardableResult public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver) -> Service) -> ServiceEntry { let entry = ServiceEntry(name: name, scope: defaultScope) { (r, _, _: Void) in factory(r) } - bindings.append(entry) + addEntry(entry, with: name) return entry } @@ -42,7 +42,7 @@ extension Container { @discardableResult public func register>(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, <%= arg_types %>) -> Service) -> ServiceEntry { let entry = ServiceEntry(name: name, scope: defaultScope) { (r, _, a: <%= arg_closure_type %>) in factory(r, <%= arg_vars %>) } - bindings.append(entry) + addEntry(entry, with: name) return entry } From 8079f9dc245bf0003437c4f52be604714f9357b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 21 Jul 2019 22:32:52 +0200 Subject: [PATCH 097/239] Disable type forwarding test --- Tests/2.0 API/ContainerSpec.Behavior.swift | 69 ++-- .../ContainerSpec.TypeForwarding.swift | 321 +++++++++--------- 2 files changed, 197 insertions(+), 193 deletions(-) diff --git a/Tests/2.0 API/ContainerSpec.Behavior.swift b/Tests/2.0 API/ContainerSpec.Behavior.swift index a1ac2882..1ab38c29 100644 --- a/Tests/2.0 API/ContainerSpec.Behavior.swift +++ b/Tests/2.0 API/ContainerSpec.Behavior.swift @@ -43,40 +43,41 @@ class ContainerSpec_Behavior: QuickSpec { expect(spy.types.first == Animal.self).to(beTrue()) } } - describe("forwarding service") { - it("should be invoked") { - let spy1 = BehaviorSpy() - let spy2 = BehaviorSpy() - container.addBehavior(spy1) - container.addBehavior(spy2) - - container.register(Dog.self) { _ in Dog() } - .implements(Animal.self) - - expect(spy1.entries).to(haveCount(2)) - expect(spy2.entries).to(haveCount(2)) - } - it("should be invoked using proper name") { - let spy = BehaviorSpy() - container.addBehavior(spy) - - container.register(Dog.self, name: "Hachi") { _ in Dog() } - .implements(Animal.self) - - expect(spy.names[0]).to(equal("Hachi")) - expect(spy.names[1]).to(beNil()) - } - it("should be invoked using proper type") { - let spy = BehaviorSpy() - container.addBehavior(spy) - - container.register(Dog.self, name: "Hachi") { _ in Dog() } - .implements(Animal.self) - - expect(spy.types[0] == Dog.self).to(beTrue()) - expect(spy.types[1] == Animal.self).to(beTrue()) - } - } + // TODO: Type forwarding +// describe("forwarding service") { +// it("should be invoked") { +// let spy1 = BehaviorSpy() +// let spy2 = BehaviorSpy() +// container.addBehavior(spy1) +// container.addBehavior(spy2) +// +// container.register(Dog.self) { _ in Dog() } +// .implements(Animal.self) +// +// expect(spy1.entries).to(haveCount(2)) +// expect(spy2.entries).to(haveCount(2)) +// } +// it("should be invoked using proper name") { +// let spy = BehaviorSpy() +// container.addBehavior(spy) +// +// container.register(Dog.self, name: "Hachi") { _ in Dog() } +// .implements(Animal.self) +// +// expect(spy.names[0]).to(equal("Hachi")) +// expect(spy.names[1]).to(beNil()) +// } +// it("should be invoked using proper type") { +// let spy = BehaviorSpy() +// container.addBehavior(spy) +// +// container.register(Dog.self, name: "Hachi") { _ in Dog() } +// .implements(Animal.self) +// +// expect(spy.types[0] == Dog.self).to(beTrue()) +// expect(spy.types[1] == Animal.self).to(beTrue()) +// } +// } describe("convenience initialiser") { it("adds behaviors to the container") { let spy1 = BehaviorSpy() diff --git a/Tests/2.0 API/ContainerSpec.TypeForwarding.swift b/Tests/2.0 API/ContainerSpec.TypeForwarding.swift index de61d9d1..de6a2e5e 100644 --- a/Tests/2.0 API/ContainerSpec.TypeForwarding.swift +++ b/Tests/2.0 API/ContainerSpec.TypeForwarding.swift @@ -2,162 +2,165 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -import Nimble -import Quick -@testable import Swinject - -class ContainerSpec_TypeForwarding: QuickSpec { - override func spec() { - var container: Container! - beforeEach { - container = Container() - } - - describe("container method") { - it("resolves forwarded type") { - let service = container.register(Dog.self) { _ in Dog() } - container.forward(Animal.self, to: service) - - let animal = container.resolve(Animal.self) - - expect(animal).notTo(beNil()) - } - it("resolves forwarded type with arguments") { - let service = container.register(Cat.self) { _, name, sleeping in Cat(name: name, sleeping: sleeping) } - container.forward(Animal.self, to: service) - - let animal = container.resolve(Animal.self, arguments: "Mimi", true) as? Cat - - expect(animal?.name) == "Mimi" - expect(animal?.sleeping).to(beTrue()) - } - it("resolves forwarded type given correct name") { - let service = container.register(Dog.self) { _ in Dog() } - container.forward(Animal.self, name: "Hachi", to: service) - - let animal = container.resolve(Animal.self, name: "Hachi") - - expect(animal).notTo(beNil()) - } - it("does not resolve forwarded type given incorrect name") { - let service = container.register(Dog.self) { _ in Dog() } - container.forward(Animal.self, name: "Hachi", to: service) - - let animal = container.resolve(Animal.self, name: "Mimi") - - expect(animal).to(beNil()) - } - it("does not resolve when forwarding incompatible types") { - let service = container.register(Dog.self) { _ in Dog() } - container.forward(Cat.self, to: service) - - let cat = container.resolve(Cat.self) - - expect(cat).to(beNil()) - } - it("does not resolve when forwarding incompatible types with arguments") { - let service = container.register(Dog.self) { (_, _: String) in Dog() } - container.forward(Cat.self, to: service) - - let cat = container.resolve(Cat.self, argument: "") - - expect(cat).to(beNil()) - } - it("resolves forwarded type even if only implementation type conforms to it") { - let service = container.register(Animal.self) { _ in Dog() } - container.forward(Dog.self, to: service) - let dog = container.resolve(Dog.self) - expect(dog).notTo(beNil()) - } - } - describe("service entry method") { - it("resolves forwarded type") { - container.register(Dog.self) { _ in Dog() } - .implements(Animal.self) - - let animal = container.resolve(Animal.self) - - expect(animal).notTo(beNil()) - } - it("suports multiple forwarding definitions") { - container.register(Dog.self) { _ in Dog() } - .implements(DogProtocol1.self) - .implements(DogProtocol2.self) - .implements(DogProtocol3.self) - - let dog1 = container.resolve(DogProtocol1.self) - let dog2 = container.resolve(DogProtocol2.self) - let dog3 = container.resolve(DogProtocol3.self) - - expect(dog1).notTo(beNil()) - expect(dog2).notTo(beNil()) - expect(dog3).notTo(beNil()) - } - it("resolves forwarded types only when correct name is given") { - container.register(Dog.self) { _ in Dog() } - .implements(DogProtocol1.self, name: "1") - .implements(DogProtocol2.self, name: "2") - .implements(DogProtocol3.self, name: "3") - - let dog1 = container.resolve(DogProtocol1.self, name: "1") - let dog2 = container.resolve(DogProtocol2.self) - let dog3 = container.resolve(DogProtocol3.self, name: "2") - - expect(dog1).notTo(beNil()) - expect(dog2).to(beNil()) - expect(dog3).to(beNil()) - } - it("supports defining multiple types at once") { - container.register(Dog.self) { _ in Dog() } - .implements(DogProtocol1.self, DogProtocol2.self, DogProtocol3.self) - - let dog1 = container.resolve(DogProtocol1.self) - let dog2 = container.resolve(DogProtocol2.self) - let dog3 = container.resolve(DogProtocol3.self) - - expect(dog1).notTo(beNil()) - expect(dog2).notTo(beNil()) - expect(dog3).notTo(beNil()) - } - } - describe("Optional resolving") { - it("resolves optional when wrapped type is registered") { - container.register(Dog.self) { _ in Dog() } - let optionalDog = container.resolve(Dog?.self) - expect(optionalDog ?? nil).notTo(beNil()) - } - it("resolves optional to nil when wrapped type is not registered") { - let optionalDog = container.resolve(Dog?.self) - expect(optionalDog).notTo(beNil()) - } - it("resolves optional with name") { - container.register(Dog.self, name: "Hachi") { _ in Dog() } - let optionalDog = container.resolve(Dog?.self, name: "Hachi") - expect(optionalDog ?? nil).notTo(beNil()) - } - it("resolves optional to nil with wrong name") { - container.register(Dog.self, name: "Hachi") { _ in Dog() } - let optionalDog = container.resolve(Dog?.self, name: "Mimi") - expect(optionalDog ?? nil).to(beNil()) - expect(optionalDog).notTo(beNil()) - } - it("resolves optional with arguments") { - container.register(Dog.self) { _, name in Dog(name: name) } - let optionalDog = container.resolve(Dog?.self, argument: "Hachi") - expect(optionalDog ?? nil).notTo(beNil()) - } - it("resolves optional of fowrarded type") { - container.register(Dog.self) { _ in Dog() }.implements(Animal.self) - let optionalAnimal = container.resolve(Animal?.self) - let unwrappedAnimal = container.resolve(Animal?.self) - expect(optionalAnimal ?? nil).notTo(beNil()) - expect(unwrappedAnimal ?? nil).notTo(beNil()) - } - } - } -} - -private protocol DogProtocol1 {} -private protocol DogProtocol2 {} -private protocol DogProtocol3 {} -extension Dog: DogProtocol1, DogProtocol2, DogProtocol3 {} +// TODO: Implement type forwaring +//import Nimble +//import Quick +//@testable import Swinject +// +//class ContainerSpec_TypeForwarding: QuickSpec { +// override func spec() { +// var container: Container! +// beforeEach { +// container = Container() +// } +// +// describe("container method") { +// it("resolves forwarded type") { +// let service = container.register(Dog.self) { _ in Dog() } +// container.forward(Animal.self, to: service) +// +// let animal = container.resolve(Animal.self) +// +// expect(animal).notTo(beNil()) +// } +// it("resolves forwarded type with arguments") { +// let service = container.register(Cat.self) { _, name, sleeping in +// Cat(name: name, sleeping: sleeping) +// } +// container.forward(Animal.self, to: service) +// +// let animal = container.resolve(Animal.self, arguments: "Mimi", true) as? Cat +// +// expect(animal?.name) == "Mimi" +// expect(animal?.sleeping).to(beTrue()) +// } +// it("resolves forwarded type given correct name") { +// let service = container.register(Dog.self) { _ in Dog() } +// container.forward(Animal.self, name: "Hachi", to: service) +// +// let animal = container.resolve(Animal.self, name: "Hachi") +// +// expect(animal).notTo(beNil()) +// } +// it("does not resolve forwarded type given incorrect name") { +// let service = container.register(Dog.self) { _ in Dog() } +// container.forward(Animal.self, name: "Hachi", to: service) +// +// let animal = container.resolve(Animal.self, name: "Mimi") +// +// expect(animal).to(beNil()) +// } +// it("does not resolve when forwarding incompatible types") { +// let service = container.register(Dog.self) { _ in Dog() } +// container.forward(Cat.self, to: service) +// +// let cat = container.resolve(Cat.self) +// +// expect(cat).to(beNil()) +// } +// it("does not resolve when forwarding incompatible types with arguments") { +// let service = container.register(Dog.self) { (_, _: String) in Dog() } +// container.forward(Cat.self, to: service) +// +// let cat = container.resolve(Cat.self, argument: "") +// +// expect(cat).to(beNil()) +// } +// it("resolves forwarded type even if only implementation type conforms to it") { +// let service = container.register(Animal.self) { _ in Dog() } +// container.forward(Dog.self, to: service) +// let dog = container.resolve(Dog.self) +// expect(dog).notTo(beNil()) +// } +// } +// describe("service entry method") { +// it("resolves forwarded type") { +// container.register(Dog.self) { _ in Dog() } +// .implements(Animal.self) +// +// let animal = container.resolve(Animal.self) +// +// expect(animal).notTo(beNil()) +// } +// it("suports multiple forwarding definitions") { +// container.register(Dog.self) { _ in Dog() } +// .implements(DogProtocol1.self) +// .implements(DogProtocol2.self) +// .implements(DogProtocol3.self) +// +// let dog1 = container.resolve(DogProtocol1.self) +// let dog2 = container.resolve(DogProtocol2.self) +// let dog3 = container.resolve(DogProtocol3.self) +// +// expect(dog1).notTo(beNil()) +// expect(dog2).notTo(beNil()) +// expect(dog3).notTo(beNil()) +// } +// it("resolves forwarded types only when correct name is given") { +// container.register(Dog.self) { _ in Dog() } +// .implements(DogProtocol1.self, name: "1") +// .implements(DogProtocol2.self, name: "2") +// .implements(DogProtocol3.self, name: "3") +// +// let dog1 = container.resolve(DogProtocol1.self, name: "1") +// let dog2 = container.resolve(DogProtocol2.self) +// let dog3 = container.resolve(DogProtocol3.self, name: "2") +// +// expect(dog1).notTo(beNil()) +// expect(dog2).to(beNil()) +// expect(dog3).to(beNil()) +// } +// it("supports defining multiple types at once") { +// container.register(Dog.self) { _ in Dog() } +// .implements(DogProtocol1.self, DogProtocol2.self, DogProtocol3.self) +// +// let dog1 = container.resolve(DogProtocol1.self) +// let dog2 = container.resolve(DogProtocol2.self) +// let dog3 = container.resolve(DogProtocol3.self) +// +// expect(dog1).notTo(beNil()) +// expect(dog2).notTo(beNil()) +// expect(dog3).notTo(beNil()) +// } +// } +// describe("Optional resolving") { +// it("resolves optional when wrapped type is registered") { +// container.register(Dog.self) { _ in Dog() } +// let optionalDog = container.resolve(Dog?.self) +// expect(optionalDog ?? nil).notTo(beNil()) +// } +// it("resolves optional to nil when wrapped type is not registered") { +// let optionalDog = container.resolve(Dog?.self) +// expect(optionalDog).notTo(beNil()) +// } +// it("resolves optional with name") { +// container.register(Dog.self, name: "Hachi") { _ in Dog() } +// let optionalDog = container.resolve(Dog?.self, name: "Hachi") +// expect(optionalDog ?? nil).notTo(beNil()) +// } +// it("resolves optional to nil with wrong name") { +// container.register(Dog.self, name: "Hachi") { _ in Dog() } +// let optionalDog = container.resolve(Dog?.self, name: "Mimi") +// expect(optionalDog ?? nil).to(beNil()) +// expect(optionalDog).notTo(beNil()) +// } +// it("resolves optional with arguments") { +// container.register(Dog.self) { _, name in Dog(name: name) } +// let optionalDog = container.resolve(Dog?.self, argument: "Hachi") +// expect(optionalDog ?? nil).notTo(beNil()) +// } +// it("resolves optional of fowrarded type") { +// container.register(Dog.self) { _ in Dog() }.implements(Animal.self) +// let optionalAnimal = container.resolve(Animal?.self) +// let unwrappedAnimal = container.resolve(Animal?.self) +// expect(optionalAnimal ?? nil).notTo(beNil()) +// expect(unwrappedAnimal ?? nil).notTo(beNil()) +// } +// } +// } +//} +// +//private protocol DogProtocol1 {} +//private protocol DogProtocol2 {} +//private protocol DogProtocol3 {} +//extension Dog: DogProtocol1, DogProtocol2, DogProtocol3 {} From 01c9b25b8700d074f5097c22e3dd7d42d80312f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 21 Jul 2019 23:06:27 +0200 Subject: [PATCH 098/239] Implement graph resolution [wip] --- Sources/2.0 API/Container.swift | 2 +- Sources/2.0 API/ObjectScope.swift | 17 ++++++++++++++++- Tests/Unit Specs/ContextedResolverSpec.swift | 13 +++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Sources/2.0 API/Container.swift b/Sources/2.0 API/Container.swift index 4c46a2ca..194916e4 100644 --- a/Sources/2.0 API/Container.swift +++ b/Sources/2.0 API/Container.swift @@ -109,6 +109,6 @@ extension Container: Resolver { public func resolve( _ request: InstanceRequest ) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { - try swinject.resolve(request) + try swinject.on(Graph()).resolve(request) } } diff --git a/Sources/2.0 API/ObjectScope.swift b/Sources/2.0 API/ObjectScope.swift index fbb2f75a..4fd49434 100644 --- a/Sources/2.0 API/ObjectScope.swift +++ b/Sources/2.0 API/ObjectScope.swift @@ -23,5 +23,20 @@ public enum ObjectScope { } extension ObjectScope { - var scope: AnyScope? { nil } + var scope: AnyScope? { + switch self { + case .graph: return GraphScope() + default: return nil + } + } +} + +final class Graph { + let registry = StandardScopeRegistry() +} + +final class GraphScope: Scope { + func registry(for graph: Graph) -> ScopeRegistry { + return graph.registry + } } diff --git a/Tests/Unit Specs/ContextedResolverSpec.swift b/Tests/Unit Specs/ContextedResolverSpec.swift index 76cff98e..41d89b67 100644 --- a/Tests/Unit Specs/ContextedResolverSpec.swift +++ b/Tests/Unit Specs/ContextedResolverSpec.swift @@ -41,4 +41,17 @@ class ContextedResolverSpec: QuickSpec { override func spec() { expect(receivedRequest?.context) == "context" } } + describe("on context") { + it("passes context to dependency resolution") { + let binding = BindingMock() + binding.matchesClosure = { $0.descriptor.matches(plain(Double.self)) } + binding.instanceArgContextResolverReturnValue = 0.0 + let swinject = Swinject { + bbind(Int.self) & provider { Int(try $0.instance() as Double) } + binding + } + _ = try? swinject.on(42).instance(of: Int.self) + expect(binding.instanceArgContextResolverReceivedArguments?.context as? Int) == 42 + } + } } } From 681b69f767451a27d00bab53f21ab383ae6a94f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Mon, 22 Jul 2019 17:47:53 +0200 Subject: [PATCH 099/239] Refactor context handling --- Sources/2.0 API/Container.swift | 4 +- Sources/2.0 API/ServiceEntry.swift | 4 +- Sources/Core/BindingKey.swift | 6 +-- Sources/Core/ContextedResolver.swift | 22 -------- Sources/Core/InstanceRequest.swift | 11 ++-- Sources/Core/Resolver.swift | 11 +--- Sources/Core/ScopedBinding.swift | 2 +- Sources/Core/SimpleBinding.swift | 2 +- Sources/Core/Swinject.swift | 25 +++++++-- Swinject.xcodeproj/project.pbxproj | 20 ------- Tests/Support/NonGeneratedMocks.swift | 8 +-- Tests/Unit Specs/BindingKeySpec.swift | 29 +++++----- Tests/Unit Specs/ContextedResolverSpec.swift | 57 -------------------- Tests/Unit Specs/SwinjectSpec.swift | 20 ++++--- 14 files changed, 72 insertions(+), 149 deletions(-) delete mode 100644 Sources/Core/ContextedResolver.swift delete mode 100644 Tests/Unit Specs/ContextedResolverSpec.swift diff --git a/Sources/2.0 API/Container.swift b/Sources/2.0 API/Container.swift index 194916e4..fe48cb31 100644 --- a/Sources/2.0 API/Container.swift +++ b/Sources/2.0 API/Container.swift @@ -106,8 +106,8 @@ extension Container: CustomStringConvertible { // MARK: Resolver extension Container: Resolver { - public func resolve( - _ request: InstanceRequest + public func resolve( + _ request: InstanceRequest ) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { try swinject.on(Graph()).resolve(request) } diff --git a/Sources/2.0 API/ServiceEntry.swift b/Sources/2.0 API/ServiceEntry.swift index 456a7a17..be73688d 100644 --- a/Sources/2.0 API/ServiceEntry.swift +++ b/Sources/2.0 API/ServiceEntry.swift @@ -19,9 +19,9 @@ public struct ServiceEntry { ) { self.builder = { builder($0, $1, $2 as! Argument) } if let name = name { - self.key = BindingKey, Any, Argument>(descriptor: tagged(Service.self, with: name)) + self.key = BindingKey(descriptor: tagged(Service.self, with: name), contextType: Any.self, argumentType: Argument.self) } else { - self.key = BindingKey, Any, Argument>(descriptor: plain(Service.self)) + self.key = BindingKey(descriptor: plain(Service.self), contextType: Any.self, argumentType: Argument.self) } self.scope = scope } diff --git a/Sources/Core/BindingKey.swift b/Sources/Core/BindingKey.swift index ce352db4..8078c9ae 100644 --- a/Sources/Core/BindingKey.swift +++ b/Sources/Core/BindingKey.swift @@ -11,10 +11,10 @@ public protocol AnyBindingKey { func matches(_ other: AnyBindingKey) -> Bool } -struct BindingKey: AnyBindingKey where Descriptor: TypeDescriptor { - let contextType: Any.Type = Context.self - let argumentType: Any.Type = Argument.self +struct BindingKey: AnyBindingKey { let descriptor: AnyTypeDescriptor + let contextType: Any.Type + let argumentType: Any.Type func matches(_ other: AnyBindingKey) -> Bool { descriptor.matches(other.descriptor) diff --git a/Sources/Core/ContextedResolver.swift b/Sources/Core/ContextedResolver.swift deleted file mode 100644 index 37defe91..00000000 --- a/Sources/Core/ContextedResolver.swift +++ /dev/null @@ -1,22 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -struct ContextedResolver { - let context: Context - let resolver: Resolver -} - -extension ContextedResolver: Resolver { - func resolve( - _ request: InstanceRequest - ) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { - try resolver.resolve( - InstanceRequest( - key: BindingKey(descriptor: request.key.descriptor), - context: context, - argument: request.argument - ) - ) - } -} diff --git a/Sources/Core/InstanceRequest.swift b/Sources/Core/InstanceRequest.swift index c5be5f79..6efaa9aa 100644 --- a/Sources/Core/InstanceRequest.swift +++ b/Sources/Core/InstanceRequest.swift @@ -2,16 +2,15 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -public struct InstanceRequest where Descriptor: TypeDescriptor { - let key: BindingKey - let context: Context +public struct InstanceRequest where Descriptor: TypeDescriptor { + let descriptor: Descriptor let argument: Argument } func request( - type _: Type.Type = Type.self, + type: Type.Type = Type.self, tag: Tag, arg: Argument -) -> InstanceRequest, Void, Argument> { - InstanceRequest(key: BindingKey(descriptor: Tagged(tag: tag)), context: (), argument: arg) +) -> InstanceRequest, Argument> { + InstanceRequest(descriptor: tagged(type, with: tag), argument: arg) } diff --git a/Sources/Core/Resolver.swift b/Sources/Core/Resolver.swift index b547f4d7..8b9b85ae 100644 --- a/Sources/Core/Resolver.swift +++ b/Sources/Core/Resolver.swift @@ -2,15 +2,8 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -// TODO: Rename public protocol Resolver { - func resolve( - _ request: InstanceRequest + func resolve( + _ request: InstanceRequest ) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor } - -public extension Resolver { - func on(_ context: Context) -> Resolver { - ContextedResolver(context: context, resolver: self) - } -} diff --git a/Sources/Core/ScopedBinding.swift b/Sources/Core/ScopedBinding.swift index 928190a9..648b0ca7 100644 --- a/Sources/Core/ScopedBinding.swift +++ b/Sources/Core/ScopedBinding.swift @@ -48,7 +48,7 @@ extension ScopedBinding.Builder: BindingMaker { public func makeBinding(for descriptor: Descriptor) -> Binding where Descriptor: TypeDescriptor { ScopedBinding( - key: BindingKey(descriptor: descriptor), + key: BindingKey(descriptor: descriptor, contextType: Context.self, argumentType: Argument.self), maker: self, scope: scope ) diff --git a/Sources/Core/SimpleBinding.swift b/Sources/Core/SimpleBinding.swift index d673d2f9..c57ff105 100644 --- a/Sources/Core/SimpleBinding.swift +++ b/Sources/Core/SimpleBinding.swift @@ -40,7 +40,7 @@ extension SimpleBinding.Builder: BindingMaker { public func makeBinding(for descriptor: Descriptor) -> Binding where Descriptor: TypeDescriptor { SimpleBinding( - key: BindingKey(descriptor: descriptor), + key: BindingKey(descriptor: descriptor, contextType: Context.self, argumentType: Argument.self), maker: self ) } diff --git a/Sources/Core/Swinject.swift b/Sources/Core/Swinject.swift index 36cd83b0..165c771f 100644 --- a/Sources/Core/Swinject.swift +++ b/Sources/Core/Swinject.swift @@ -4,17 +4,36 @@ public struct Swinject { let tree: SwinjectTree + let context: Any + let contextType: Any.Type init(tree: SwinjectTree) { + self.init(tree: tree, context: ()) + } + + init(tree: SwinjectTree, context: Context) { self.tree = tree + self.context = context + self.contextType = Context.self + } +} + +extension Swinject { + public func on(_ context: Context) -> Swinject { + return Swinject(tree: tree, context: context) } } extension Swinject: Resolver { - public func resolve( - _ request: InstanceRequest + public func resolve( + _ request: InstanceRequest ) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { - try instance(from: findBinding(for: request.key), context: request.context, arg: request.argument) + let key = BindingKey( + descriptor: request.descriptor, + contextType: contextType, + argumentType: Argument.self + ) + return try instance(from: findBinding(for: key), context: context, arg: request.argument) } private func findBinding(for key: AnyBindingKey) throws -> Binding { diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 17dfd386..d9cdb9fb 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -32,7 +32,6 @@ 13379D1C70FC17FE2F949341 /* BindingKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */; }; 133D41B8AD245B9DBAFC6606 /* Quick.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 683A1FB7D7F4E9508D57E936 /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 14AECF24B26ECEC8E9086FBB /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3586A4987B7C7C8122D674E /* SwinjectError.swift */; }; - 151340C24653963B97464BA9 /* ContextedResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBA3EF319F06A1B3B6C84C29 /* ContextedResolver.swift */; }; 15FA8361AB335F4CC372A52C /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; 166CBBCA1E1441AD87A60EFF /* BindingKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */; }; 16FE1BC18A9DD0D21CAF2806 /* ScopeRegistryKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2902FD4C1A50263340A51FFB /* ScopeRegistryKeySpec.swift */; }; @@ -42,7 +41,6 @@ 18A07EB6FB61F3CDCC766AF4 /* ScopeRegistryKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */; }; 192278AA7165EC3C2C12A4C2 /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; 196AA219BB35334B07B34F37 /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */; }; - 199D71D592CEDF7400DA3D0A /* ContextedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4021EB1EA6A2770920FAD979 /* ContextedResolverSpec.swift */; }; 1A03A1D9524E8912AF1CEE11 /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = EA7A547FC60DBD02D132B3E6 /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 1ACC90951353E5F69899A833 /* SimpleBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */; }; 1AD4C43B074F736BBDADA8C9 /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; @@ -89,7 +87,6 @@ 41EEA4724CD401F38F9622E3 /* InstanceMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CADDB3E9E363310028AA5920 /* InstanceMaker.swift */; }; 439254FAE8DF567DE9659ADA /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3586A4987B7C7C8122D674E /* SwinjectError.swift */; }; 4503217DA585B602EDE65742 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1FA0377AF4799D42E9462FA /* BasicAssembly.swift */; }; - 4578AA4291288B21ABD74735 /* ContextedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4021EB1EA6A2770920FAD979 /* ContextedResolverSpec.swift */; }; 462054EB9666775B13C36132 /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */; }; 46A14FAA5AA73BE8A0397707 /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; 4735419DE3D63E556D07C663 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B580B43E1891812C97209 /* Binding.swift */; }; @@ -144,7 +141,6 @@ 67A89300EA08B0FB7AB0FBF8 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; 68A42DF14E0117A95B44148F /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C765B92B00C0AC8625BB4AC9 /* Quick.framework */; }; 699DB780BD90A5AAAD5B4646 /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCAF491EC7DCD7477F9A0ECB /* SwinjectModule.swift */; }; - 6BFA0D58FD4131D3A2248208 /* ContextedResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBA3EF319F06A1B3B6C84C29 /* ContextedResolver.swift */; }; 6C980EED98CBEADFD6DAA72A /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B3797A6BB56AE76CEC19F2A /* SwinjectApiSpec.swift */; }; 6DCE3C30CAE0350C428154DC /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; 6F5323F408E5708076C02768 /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = A10187BB3A994165E7FC1528 /* ScopedBinding.swift */; }; @@ -156,7 +152,6 @@ 741344C30785507B22DF703B /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; 7472B748AEA9F4D1E5EF9A70 /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C13D01A2DE6F53DF3175D22 /* Container+Registration.swift */; }; 7480A500FEC04BB9CB048AE1 /* BinderEnvironmentSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */; }; - 76B3D9DBF8D5593F67A7B7E6 /* ContextedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4021EB1EA6A2770920FAD979 /* ContextedResolverSpec.swift */; }; 782801544D9F468F536E045E /* Container+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C2DBC728B763B04CB25963 /* Container+TypeForwarding.swift */; }; 7845113EAF8FFAFD5EC10540 /* BindingKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */; }; 788AE378F10DA216265FFF52 /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; @@ -183,7 +178,6 @@ 8AEB5894656086C3E2F022FD /* SimpleBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */; }; 8D58DF5C6963153A8B17D325 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; 8D71D83DB3F5D3655FB6C71D /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C074BAC560F277E806146C60 /* SimpleBinding.swift */; }; - 8D75A0A4A84E2B46E264B5FB /* ContextedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4021EB1EA6A2770920FAD979 /* ContextedResolverSpec.swift */; }; 8E1BBA6F7B45E1DF056670AC /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 273FB7A6277E0841E1570990 /* Nimble.framework */; }; 8E9E1BD32B056F472DA14E51 /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1C58FC14EEA170B0DC079DE4 /* Quick.framework */; }; 8F48909C95AA648D056A392B /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; @@ -214,7 +208,6 @@ 9D1AD9CBA32CEE29EF6C68C2 /* GeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */; }; 9DD1C1273B38FCF4FFE9BCC2 /* BindingKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */; }; 9E084F679592ADFA28D3AD6D /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; - 9EF6DF530041FC494572D3DB /* ContextedResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBA3EF319F06A1B3B6C84C29 /* ContextedResolver.swift */; }; 9F1C7A652660EA87BF599126 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; 9FEC055DC6BE1D844FE5F082 /* Closable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D0BCCCD61CD9BECC29E064 /* Closable.swift */; }; A014793C56F8966AD2D7CC50 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; @@ -249,7 +242,6 @@ C3AD37D47C38E5EB20FAF917 /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; C50BFD826112288F1D693A30 /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; C6ED278B6F0E08A4B1E57C45 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; - C75EC8F8DD60676B120917EA /* ContextedResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBA3EF319F06A1B3B6C84C29 /* ContextedResolver.swift */; }; C797CCF413DF181935DAB58C /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; C7BB5752C697E748B828C03B /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; C8F1F075F5792C9936B0577D /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42490D1D0C395951243F5CFF /* Container.swift */; }; @@ -433,7 +425,6 @@ 38615FC8EEB466C5C1EAD21C /* ServiceEntry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServiceEntry.swift; sourceTree = ""; }; 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Swinject+Builder.swift"; sourceTree = ""; }; 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaggedTypeSpec.swift; sourceTree = ""; }; - 4021EB1EA6A2770920FAD979 /* ContextedResolverSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextedResolverSpec.swift; sourceTree = ""; }; 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingKeySpec.swift; sourceTree = ""; }; 42490D1D0C395951243F5CFF /* Container.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.swift; sourceTree = ""; }; 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTree.swift; sourceTree = ""; }; @@ -495,7 +486,6 @@ E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRequest.swift; sourceTree = ""; }; E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; EA7A547FC60DBD02D132B3E6 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - EBA3EF319F06A1B3B6C84C29 /* ContextedResolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextedResolver.swift; sourceTree = ""; }; ECE2B2EFBFDA910758EE1CA5 /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; EDA62EEBC79ED2639C93A76B /* TypeBinderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinderSpec.swift; sourceTree = ""; }; EEE8FDF4B975A8F2A9FCC5FF /* Food.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Food.swift; sourceTree = ""; }; @@ -554,7 +544,6 @@ children = ( FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */, 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */, - 4021EB1EA6A2770920FAD979 /* ContextedResolverSpec.swift */, 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */, 2902FD4C1A50263340A51FFB /* ScopeRegistryKeySpec.swift */, 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */, @@ -780,7 +769,6 @@ 0E0B580B43E1891812C97209 /* Binding.swift */, A24B4E8F1CA18603DBB6884A /* BindingKey.swift */, 65D0BCCCD61CD9BECC29E064 /* Closable.swift */, - EBA3EF319F06A1B3B6C84C29 /* ContextedResolver.swift */, CADDB3E9E363310028AA5920 /* InstanceMaker.swift */, E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */, 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */, @@ -1213,7 +1201,6 @@ A4490FF7ACCC5CBFB2C1896C /* Container+Logging.swift in Sources */, 7F22099B321798EAD85DBC07 /* Container+TypeForwarding.swift in Sources */, 0CED31C429BA9F9B23EB2B1F /* Container.swift in Sources */, - 9EF6DF530041FC494572D3DB /* ContextedResolver.swift in Sources */, 3547656EF55D129316B7C5E2 /* InstanceMaker.swift in Sources */, B61FAC17826BAFD2DC1C0E5E /* InstanceRequest.swift in Sources */, 2DCEEF373F410202226D2DB5 /* InstanceWrapper.swift in Sources */, @@ -1257,7 +1244,6 @@ 93DCA2A58C4067D5E60F7ED1 /* ContainerSpec.CustomStringConvertible.swift in Sources */, F8DB4EDA0367BCC6832E4AA6 /* ContainerSpec.TypeForwarding.swift in Sources */, 4C6D7AE29CB7E16431AACFA2 /* ContainerSpec.swift in Sources */, - 8D75A0A4A84E2B46E264B5FB /* ContextedResolverSpec.swift in Sources */, A014793C56F8966AD2D7CC50 /* Convenience.swift in Sources */, DC5C3A946BDA224C388D2438 /* EmploymentAssembly.swift in Sources */, 60AF45155775AA5E97AAB5C1 /* Food.swift in Sources */, @@ -1300,7 +1286,6 @@ E423395FC7006DD82513F347 /* ContainerSpec.CustomStringConvertible.swift in Sources */, FAF8F8B75F63D43995A004E8 /* ContainerSpec.TypeForwarding.swift in Sources */, C797CCF413DF181935DAB58C /* ContainerSpec.swift in Sources */, - 76B3D9DBF8D5593F67A7B7E6 /* ContextedResolverSpec.swift in Sources */, DE0A534B660AA93F73A2CB41 /* Convenience.swift in Sources */, 833635A5D695AA696559C250 /* EmploymentAssembly.swift in Sources */, F4D2218805AEBF797A2945AB /* Food.swift in Sources */, @@ -1340,7 +1325,6 @@ E9F5DF3C8AA3A9651D504AF7 /* Container+Logging.swift in Sources */, 5381C2CDA084C5BEF82D7521 /* Container+TypeForwarding.swift in Sources */, AAB6386F88442B22E9F7FF0E /* Container.swift in Sources */, - C75EC8F8DD60676B120917EA /* ContextedResolver.swift in Sources */, 58CFFB8C98C465B9101AA9A8 /* InstanceMaker.swift in Sources */, 9AFDF0122A11B2E996B16C3D /* InstanceRequest.swift in Sources */, 3B2E8B8CF4825DB05B0233F8 /* InstanceWrapper.swift in Sources */, @@ -1384,7 +1368,6 @@ 377EE35B80E8F91543B52F0C /* ContainerSpec.CustomStringConvertible.swift in Sources */, 5D241BBB39F54B8FA2BFF595 /* ContainerSpec.TypeForwarding.swift in Sources */, 37E07236E0E63570242CE23F /* ContainerSpec.swift in Sources */, - 4578AA4291288B21ABD74735 /* ContextedResolverSpec.swift in Sources */, 564B886D2A35AF26FC411922 /* Convenience.swift in Sources */, 58C9D537D453BC7C7DC5C0C1 /* EmploymentAssembly.swift in Sources */, 0539332D989C37CA34A5FB4F /* Food.swift in Sources */, @@ -1427,7 +1410,6 @@ E8D70420E8A3C91D01BC3B5B /* ContainerSpec.CustomStringConvertible.swift in Sources */, 9F1C7A652660EA87BF599126 /* ContainerSpec.TypeForwarding.swift in Sources */, E80558941BC2149C25A17495 /* ContainerSpec.swift in Sources */, - 199D71D592CEDF7400DA3D0A /* ContextedResolverSpec.swift in Sources */, A1B275A2EFA22C45AC46B31E /* Convenience.swift in Sources */, 187BD516162B3FBB1158E015 /* EmploymentAssembly.swift in Sources */, D98CA679A3AAC176D291CA8E /* Food.swift in Sources */, @@ -1467,7 +1449,6 @@ 31266C4BA7CE6C3FBAFBACDD /* Container+Logging.swift in Sources */, 0DFB6FB4DF6A713EA545930F /* Container+TypeForwarding.swift in Sources */, C8F1F075F5792C9936B0577D /* Container.swift in Sources */, - 6BFA0D58FD4131D3A2248208 /* ContextedResolver.swift in Sources */, 48714C7B99D346C83E1E8293 /* InstanceMaker.swift in Sources */, 04C24C140F2D0BBFE48C682C /* InstanceRequest.swift in Sources */, 53DC7093FD7C2FEE16154DED /* InstanceWrapper.swift in Sources */, @@ -1508,7 +1489,6 @@ F151A5040BB76E8E909D9D6B /* Container+Logging.swift in Sources */, 782801544D9F468F536E045E /* Container+TypeForwarding.swift in Sources */, 91DAE32F86CEA897AD52AEDB /* Container.swift in Sources */, - 151340C24653963B97464BA9 /* ContextedResolver.swift in Sources */, 41EEA4724CD401F38F9622E3 /* InstanceMaker.swift in Sources */, 5E74770DDD69EAFE5D187F90 /* InstanceRequest.swift in Sources */, 39F9BBD670C944E1331FAB13 /* InstanceWrapper.swift in Sources */, diff --git a/Tests/Support/NonGeneratedMocks.swift b/Tests/Support/NonGeneratedMocks.swift index d7d019ba..27976eb0 100644 --- a/Tests/Support/NonGeneratedMocks.swift +++ b/Tests/Support/NonGeneratedMocks.swift @@ -5,8 +5,8 @@ @testable import Swinject class DummyResolver: Resolver { - func resolve( - _: InstanceRequest + func resolve( + _: InstanceRequest ) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { fatalError() } @@ -32,8 +32,8 @@ protocol AnyResolver { } extension AnyResolverMock: Resolver { - func resolve( - _ request: InstanceRequest + func resolve( + _ request: InstanceRequest ) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { try resolve(request as Any) as! Descriptor.BaseType } diff --git a/Tests/Unit Specs/BindingKeySpec.swift b/Tests/Unit Specs/BindingKeySpec.swift index fcb3bdad..14f286e0 100644 --- a/Tests/Unit Specs/BindingKeySpec.swift +++ b/Tests/Unit Specs/BindingKeySpec.swift @@ -6,19 +6,15 @@ import Nimble import Quick @testable import Swinject -private typealias AnyBindingKey = BindingKey -private typealias ArgumentBindingKey = BindingKey -private typealias ContextBindingKey = BindingKey - class BindingKeySpec: QuickSpec { override func spec() { describe("matching") { - var key: AnyBindingKey! + var key: BindingKey! var descriptor = AnyTypeDescriptorMock() var otherKey = AnyBindingKeyMock() beforeEach { descriptor = AnyTypeDescriptorMock() descriptor.matchesReturnValue = true - key = AnyBindingKey(descriptor: descriptor) + key = makeKey(descriptor: descriptor) otherKey = AnyBindingKeyMock() otherKey.descriptor = AnyTypeDescriptorMock() otherKey.argumentType = Void.self @@ -30,7 +26,7 @@ class BindingKeySpec: QuickSpec { override func spec() { } it("it checks if descriptors match") { let otherDescriptor = AnyTypeDescriptorMock() - _ = key.matches(AnyBindingKey(descriptor: otherDescriptor)) + _ = key.matches(makeKey(descriptor: otherDescriptor)) expect(descriptor.matchesReceivedOther) === otherDescriptor } it("matches if descriptors match") { @@ -38,30 +34,37 @@ class BindingKeySpec: QuickSpec { override func spec() { expect { key.matches(otherKey) }.to(beTrue()) } it("does not match if argument types are different") { - let key = ArgumentBindingKey(descriptor: descriptor) + let key = makeKey(descriptor: descriptor, argumentType: Int.self) otherKey.argumentType = Double.self expect(key.matches(otherKey)).to(beFalse()) } it("matches if argument types are the same") { - let key = ArgumentBindingKey(descriptor: descriptor) + let key = makeKey(descriptor: descriptor, argumentType: Int.self) otherKey.argumentType = Int.self expect(key.matches(otherKey)).to(beTrue()) } it("does not match if context types are different") { - let key = ContextBindingKey(descriptor: descriptor) + let key = makeKey(descriptor: descriptor, contextType: Int.self) otherKey.contextType = Double.self expect(key.matches(otherKey)).to(beFalse()) } it("matches if argument context are the same") { - let key = ContextBindingKey(descriptor: descriptor) + let key = makeKey(descriptor: descriptor, contextType: Int.self) otherKey.contextType = Int.self expect(key.matches(otherKey)).to(beTrue()) } it("matches if context is Any") { - let key = ContextBindingKey(descriptor: descriptor) + let key = makeKey(descriptor: descriptor, contextType: Any.self) otherKey.contextType = Int.self expect(key.matches(otherKey)).to(beTrue()) } } -} +} } + +private func makeKey( + descriptor: AnyTypeDescriptor, + contextType: Any.Type = Void.self, + argumentType: Any.Type = Void.self +) -> BindingKey { + BindingKey(descriptor: descriptor, contextType: contextType, argumentType: argumentType) } diff --git a/Tests/Unit Specs/ContextedResolverSpec.swift b/Tests/Unit Specs/ContextedResolverSpec.swift deleted file mode 100644 index 41d89b67..00000000 --- a/Tests/Unit Specs/ContextedResolverSpec.swift +++ /dev/null @@ -1,57 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -import Nimble -import Quick -@testable import Swinject - -class ContextedResolverSpec: QuickSpec { override func spec() { - var resolver: ContextedResolver! - var wrapped = AnyResolverMock() - beforeEach { - wrapped = AnyResolverMock() - wrapped.resolveReturnValue = 0 - resolver = ContextedResolver(context: (), resolver: wrapped) - } - describe("resolve") { - it("returns value from wrapped resolver") { - let intRequest = request(type: Int.self, tag: NoTag(), arg: ()) - wrapped.resolveReturnValue = 42 - expect { try resolver.resolve(intRequest) } == 42 - } - it("calls wrapped resolver with given type descriptor") { - let descriptor = AnyTypeDescriptorMock() - let request = InstanceRequest( - key: BindingKey(descriptor: descriptor), context: (), argument: () - ) - _ = try? resolver.resolve(request) - let receivedRequest = wrapped.resolveReceivedRequest as? InstanceRequest - expect(receivedRequest?.key.descriptor) === descriptor - } - it("calls wrapped resolver with given argument") { - _ = try? resolver.resolve(request(type: Int.self, tag: NoTag(), arg: "argument")) - let receivedRequest = wrapped.resolveReceivedRequest as? InstanceRequest, Void, String> - expect(receivedRequest?.argument) == "argument" - } - it("calls wrapped resolver with it's context") { - let resolver = ContextedResolver(context: "context", resolver: wrapped) - _ = try? resolver.resolve(request(type: Int.self, tag: NoTag(), arg: ())) - let receivedRequest = wrapped.resolveReceivedRequest as? InstanceRequest, String, Void> - expect(receivedRequest?.context) == "context" - } - } - describe("on context") { - it("passes context to dependency resolution") { - let binding = BindingMock() - binding.matchesClosure = { $0.descriptor.matches(plain(Double.self)) } - binding.instanceArgContextResolverReturnValue = 0.0 - let swinject = Swinject { - bbind(Int.self) & provider { Int(try $0.instance() as Double) } - binding - } - _ = try? swinject.on(42).instance(of: Int.self) - expect(binding.instanceArgContextResolverReceivedArguments?.context as? Int) == 42 - } - } -} } diff --git a/Tests/Unit Specs/SwinjectSpec.swift b/Tests/Unit Specs/SwinjectSpec.swift index 4a90187c..672494a3 100644 --- a/Tests/Unit Specs/SwinjectSpec.swift +++ b/Tests/Unit Specs/SwinjectSpec.swift @@ -63,8 +63,7 @@ class SwinjectSpec: QuickSpec { override func spec() { it("matches binding with correct key") { binding.matchesReturnValue = false _ = try? swinject.instance(tagged: "tag") as Int - let otherKey = binding.matchesReceivedKey as? BindingKey, Void, Void> - let descriptor = otherKey?.descriptor as? Tagged + let descriptor = binding.matchesReceivedKey?.descriptor as? Tagged expect(descriptor?.tag) == "tag" } it("matches binding with correct context") { @@ -139,8 +138,7 @@ class SwinjectSpec: QuickSpec { override func spec() { it("matches binding with correct key") { binding.matchesReturnValue = true _ = try? swinject.provider(of: Any.self, tagged: "tag")() - let otherKey = binding.matchesReceivedKey as? BindingKey, Void, Void> - let descriptor = otherKey?.descriptor as? Tagged + let descriptor = binding.matchesReceivedKey?.descriptor as? Tagged expect(descriptor?.tag) == "tag" } it("matches binding with correct context") { @@ -153,6 +151,17 @@ class SwinjectSpec: QuickSpec { override func spec() { _ = try? swinject.on("context").provider()() as Int expect(binding.instanceArgContextResolverReceivedArguments?.context as? String) == "context" } + it("passes given context to dependency binding") { + let binding = BindingMock() + binding.matchesClosure = { $0.descriptor.matches(plain(Double.self)) } + binding.instanceArgContextResolverReturnValue = 0.0 + let swinject = Swinject { + bbind(Int.self) & provider { Int(try $0.instance() as Double) } + binding + } + _ = try? swinject.on("context").instance(of: Int.self) + expect(binding.instanceArgContextResolverReceivedArguments?.context as? String) == "context" + } } describe("factory injection") { var swinject: Swinject! @@ -199,8 +208,7 @@ class SwinjectSpec: QuickSpec { override func spec() { it("matches binding with correct key") { binding.matchesReturnValue = false _ = try? swinject.factory(tagged: "tag")("arg") as Int - let otherKey = binding.matchesReceivedKey as? BindingKey, Void, String> - let descriptor = otherKey?.descriptor as? Tagged + let descriptor = binding.matchesReceivedKey?.descriptor as? Tagged expect(descriptor?.tag) == "tag" } it("matches binding with correct context") { From 439c5e9cbab07e7a7c38db71ba9276d931c43662 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Mon, 22 Jul 2019 18:22:57 +0200 Subject: [PATCH 100/239] Make cyclic depdenencies work --- Sources/2.0 API/ServiceEntry.swift | 23 ++++++++++++------- Sources/Core/ScopeRegistry.swift | 2 +- .../StandardScopeRegistrySpec.swift | 15 +++++++++--- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/Sources/2.0 API/ServiceEntry.swift b/Sources/2.0 API/ServiceEntry.swift index be73688d..d6e3abf6 100644 --- a/Sources/2.0 API/ServiceEntry.swift +++ b/Sources/2.0 API/ServiceEntry.swift @@ -4,11 +4,11 @@ /// The `ServiceEntry` class represents an entry of a registered service type. /// As a returned instance from a `register` method of a `Container`, some configurations can be added. -public struct ServiceEntry { +public class ServiceEntry { private let builder: (Resolver, Any, Any) -> Service private var key: AnyBindingKey private var scope: AnyScope? - private var initCompleted = [(Resolver, Any) -> Void]() + private var finalizers = [(Resolver, Service) -> Void]() var objectScope: ObjectScope? { return nil } @@ -18,11 +18,17 @@ public struct ServiceEntry { builder: @escaping (Resolver, Any, Argument) -> Service ) { self.builder = { builder($0, $1, $2 as! Argument) } - if let name = name { - self.key = BindingKey(descriptor: tagged(Service.self, with: name), contextType: Any.self, argumentType: Argument.self) - } else { - self.key = BindingKey(descriptor: plain(Service.self), contextType: Any.self, argumentType: Argument.self) - } + self.key = BindingKey( + descriptor: { + if let name = name { + return tagged(Service.self, with: name) + } else { + return plain(Service.self) + } + }(), + contextType: Any.self, + argumentType: Argument.self + ) self.scope = scope } @@ -57,6 +63,7 @@ public struct ServiceEntry { /// - Returns: `self` to add another configuration fluently. @discardableResult public func initCompleted(_ completed: @escaping (Resolver, Service) -> Void) -> Self { + finalizers.append { completed($0, $1) } return self } } @@ -71,7 +78,7 @@ extension ServiceEntry: Binding { return scope.registry(for: context).instance( for: ScopeRegistryKey(descriptor: key.descriptor, argument: arg), builder: { builder(resolver, context, arg) }, - finalizer: { instance in initCompleted.forEach { $0(resolver, instance) } } + finalizer: { instance in finalizers.forEach { $0(resolver, instance as! Service) } } ) } else { return builder(resolver, context, arg) diff --git a/Sources/Core/ScopeRegistry.swift b/Sources/Core/ScopeRegistry.swift index 0852dff7..7b0fded4 100644 --- a/Sources/Core/ScopeRegistry.swift +++ b/Sources/Core/ScopeRegistry.swift @@ -29,9 +29,9 @@ public class StandardScopeRegistry: ScopeRegistry, Closable { try lock.sync { if let instance = instances[key] { return instance } let newInstance = try builder() - try finalizer(newInstance) if let instance = instances[key] { return instance } instances[key] = newInstance + try finalizer(newInstance) return newInstance } } diff --git a/Tests/Unit Specs/StandardScopeRegistrySpec.swift b/Tests/Unit Specs/StandardScopeRegistrySpec.swift index 811ba159..97dd95c5 100644 --- a/Tests/Unit Specs/StandardScopeRegistrySpec.swift +++ b/Tests/Unit Specs/StandardScopeRegistrySpec.swift @@ -69,14 +69,23 @@ class StandardScopeRegistrySpec: QuickSpec { override func spec() { _ = registry.instance(for: key[1], builder: { 0 }, finalizer: countingFinalizer) expect(finalizerCallCount) == 2 } - it("returns the last instance if the same key was used during finalization") { + it("returns the last instance if the same key was used from builder") { let instance = registry.instance( for: key[0], - builder: { 0 }, - finalizer: { _ in _ = registry.instance(for: key[0], builder: { 42 }) } + builder: { + _ = registry.instance(for: key[0], builder: { 42 }) + return 0 + }, + finalizer: { _ in } ) expect(instance as? Int) == 42 } + it("calls builder only once if the same key was used from finalizer") { + _ = registry.instance(for: key[0], builder: countingBuilder) { _ in + _ = registry.instance(for: key[0], builder: countingBuilder, finalizer: { _ in }) + } + expect(builderCallCount) == 1 + } } describe("clear") { it("closes instances when cleared") { From 99ffb8f70076234dad98427ced85584bd4a9c528 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Mon, 22 Jul 2019 20:20:13 +0200 Subject: [PATCH 101/239] Disable tests for instance wrappers --- Tests/2.0 API/LazySpec.swift | 201 ++++++++++++++--------------- Tests/2.0 API/ProviderSpec.swift | 211 ++++++++++++++++--------------- 2 files changed, 207 insertions(+), 205 deletions(-) diff --git a/Tests/2.0 API/LazySpec.swift b/Tests/2.0 API/LazySpec.swift index 24d523fe..59635155 100644 --- a/Tests/2.0 API/LazySpec.swift +++ b/Tests/2.0 API/LazySpec.swift @@ -6,103 +6,104 @@ import Nimble import Quick import Swinject -class LazySpec: QuickSpec { - override func spec() { - var container: Container! - beforeEach { - container = Container() - } - - describe("instance production") { - it("provides instance from container") { - container.register(Animal.self) { _ in Dog() } - let lazy = container.resolve(Lazy.self) - expect(lazy?.instance is Dog).to(beTrue()) - } - it("does not create instance until requested") { - var created = false - container.register(Animal.self) { _ in created = true; return Dog() } - - _ = container.resolve(Lazy.self) - - expect(created).to(beFalse()) - } - it("resolves instance from container only once") { - var created = 0 - container.register(Animal.self) { _ in created += 1; return Dog() } - - let lazy = container.resolve(Lazy.self) - _ = lazy?.instance - _ = lazy?.instance - - expect(created) == 1 - } - it("does not resolve lazy if base type is not registered") { - let lazy = container.resolve(Lazy.self) - expect(lazy).to(beNil()) - } - } - describe("object scopes") { - context("in transient scope") { - it("always produces different instance for related objects") { - EmploymentAssembly(scope: .transient).assemble(container: container) - let employer = container.resolve(Employer.self)! - expect(employer.lazyCustomer.instance).notTo(beIdenticalTo(employer.employee.lazyCustomer.instance)) - expect(employer.lazyCustomer.instance).notTo(beIdenticalTo(employer.customer)) - } - } - context("in container scope") { - it("always produces the same instance for related objects") { - EmploymentAssembly(scope: .container).assemble(container: container) - let employer = container.resolve(Employer.self)! - expect(employer.lazyCustomer.instance).to(beIdenticalTo(employer.employee.lazyCustomer.instance)) - expect(employer.lazyCustomer.instance).to(beIdenticalTo(employer.customer)) - } - } - context("in graph scope") { - it("always produces the same instance for related objects") { - EmploymentAssembly(scope: .graph).assemble(container: container) - let employer = container.resolve(Employer.self)! - expect(employer.lazyCustomer.instance).to(beIdenticalTo(employer.employee.lazyCustomer.instance)) - expect(employer.lazyCustomer.instance).to(beIdenticalTo(employer.customer)) - } - } - } - describe("complex registrations") { - it("resolves lazy with arguments") { - container.register(Dog.self) { (_, name, _: Int) in Dog(name: name) } - let lazy = container.resolve(Lazy.self, arguments: "Hachi", 42) - expect(lazy?.instance.name) == "Hachi" - } - it("resolves lazy with name") { - container.register(Dog.self, name: "Hachi") { _ in Dog() } - let lazy = container.resolve(Lazy.self, name: "Hachi") - expect(lazy).notTo(beNil()) - } - it("does not resolve lazy with wrong name") { - container.register(Dog.self, name: "Hachi") { _ in Dog() } - let lazy = container.resolve(Lazy.self, name: "Mimi") - expect(lazy).to(beNil()) - } - it("does resolve forwarded lazy type") { - container.register(Dog.self) { _ in Dog() }.implements(Animal.self) - let lazy = container.resolve(Lazy.self) - expect(lazy).notTo(beNil()) - } - } - describe("circular dependencies") { - beforeEach { - EmploymentAssembly(scope: .graph).assemble(container: container) - } - it("resolves dependencies to same instance") { - let employer = container.resolve(Employer.self) - expect(employer?.employee.employer) === employer - expect(employer?.lazyEmployee.instance.employer) === employer - } - it("resolves circular dependencies for lazy instance") { - let employee = container.resolve(Lazy.self) - expect(employee?.instance.employer).notTo(beNil()) - } - } - } -} +// TODO: Enable Lazy injection +//class LazySpec: QuickSpec { +// override func spec() { +// var container: Container! +// beforeEach { +// container = Container() +// } +// +// describe("instance production") { +// it("provides instance from container") { +// container.register(Animal.self) { _ in Dog() } +// let lazy = container.resolve(Lazy.self) +// expect(lazy?.instance is Dog).to(beTrue()) +// } +// it("does not create instance until requested") { +// var created = false +// container.register(Animal.self) { _ in created = true; return Dog() } +// +// _ = container.resolve(Lazy.self) +// +// expect(created).to(beFalse()) +// } +// it("resolves instance from container only once") { +// var created = 0 +// container.register(Animal.self) { _ in created += 1; return Dog() } +// +// let lazy = container.resolve(Lazy.self) +// _ = lazy?.instance +// _ = lazy?.instance +// +// expect(created) == 1 +// } +// it("does not resolve lazy if base type is not registered") { +// let lazy = container.resolve(Lazy.self) +// expect(lazy).to(beNil()) +// } +// } +// describe("object scopes") { +// context("in transient scope") { +// it("always produces different instance for related objects") { +// EmploymentAssembly(scope: .transient).assemble(container: container) +// let employer = container.resolve(Employer.self)! +// expect(employer.lazyCustomer.instance).notTo(beIdenticalTo(employer.employee.lazyCustomer.instance)) +// expect(employer.lazyCustomer.instance).notTo(beIdenticalTo(employer.customer)) +// } +// } +// context("in container scope") { +// it("always produces the same instance for related objects") { +// EmploymentAssembly(scope: .container).assemble(container: container) +// let employer = container.resolve(Employer.self)! +// expect(employer.lazyCustomer.instance).to(beIdenticalTo(employer.employee.lazyCustomer.instance)) +// expect(employer.lazyCustomer.instance).to(beIdenticalTo(employer.customer)) +// } +// } +// context("in graph scope") { +// it("always produces the same instance for related objects") { +// EmploymentAssembly(scope: .graph).assemble(container: container) +// let employer = container.resolve(Employer.self)! +// expect(employer.lazyCustomer.instance).to(beIdenticalTo(employer.employee.lazyCustomer.instance)) +// expect(employer.lazyCustomer.instance).to(beIdenticalTo(employer.customer)) +// } +// } +// } +// describe("complex registrations") { +// it("resolves lazy with arguments") { +// container.register(Dog.self) { (_, name, _: Int) in Dog(name: name) } +// let lazy = container.resolve(Lazy.self, arguments: "Hachi", 42) +// expect(lazy?.instance.name) == "Hachi" +// } +// it("resolves lazy with name") { +// container.register(Dog.self, name: "Hachi") { _ in Dog() } +// let lazy = container.resolve(Lazy.self, name: "Hachi") +// expect(lazy).notTo(beNil()) +// } +// it("does not resolve lazy with wrong name") { +// container.register(Dog.self, name: "Hachi") { _ in Dog() } +// let lazy = container.resolve(Lazy.self, name: "Mimi") +// expect(lazy).to(beNil()) +// } +// it("does resolve forwarded lazy type") { +// container.register(Dog.self) { _ in Dog() }.implements(Animal.self) +// let lazy = container.resolve(Lazy.self) +// expect(lazy).notTo(beNil()) +// } +// } +// describe("circular dependencies") { +// beforeEach { +// EmploymentAssembly(scope: .graph).assemble(container: container) +// } +// it("resolves dependencies to same instance") { +// let employer = container.resolve(Employer.self) +// expect(employer?.employee.employer) === employer +// expect(employer?.lazyEmployee.instance.employer) === employer +// } +// it("resolves circular dependencies for lazy instance") { +// let employee = container.resolve(Lazy.self) +// expect(employee?.instance.employer).notTo(beNil()) +// } +// } +// } +//} diff --git a/Tests/2.0 API/ProviderSpec.swift b/Tests/2.0 API/ProviderSpec.swift index fd202068..da0dd193 100644 --- a/Tests/2.0 API/ProviderSpec.swift +++ b/Tests/2.0 API/ProviderSpec.swift @@ -6,108 +6,109 @@ import Nimble import Quick import Swinject -class ProviderSpec: QuickSpec { - override func spec() { - var container: Container! - beforeEach { - container = Container() - } - - describe("instance production") { - it("provides instance from container") { - container.register(Animal.self) { _ in Dog() } - let provider = container.resolve(Provider.self) - expect(provider?.instance is Dog).to(beTrue()) - } - it("does not create instance until requested") { - var created = false - container.register(Animal.self) { _ in created = true; return Dog() } - - _ = container.resolve(Provider.self) - - expect(created).to(beFalse()) - } - it("resolves instance from the container each time") { - var created = 0 - container.register(Animal.self) { _ in created += 1; return Dog() } - - let provider = container.resolve(Provider.self) - _ = provider?.instance - _ = provider?.instance - - expect(created) == 2 - } - it("does not resolve provider if base type is not registered") { - let provider = container.resolve(Provider.self) - expect(provider).to(beNil()) - } - } - describe("object scopes") { - context("in transient scope") { - beforeEach { - EmploymentAssembly(scope: .transient).assemble(container: container) - } - it("always produces different instance") { - let employer = container.resolve(Employer.self)! - expect(employer.providedEmployee.instance) !== employer.providedEmployee.instance - expect(employer.employee.providedCustomer.instance) !== employer.providedCustomer.instance - } - } - context("in graph scope") { - beforeEach { - EmploymentAssembly(scope: .graph).assemble(container: container) - } - it("always produces different instance") { - let employer = container.resolve(Employer.self)! - expect(employer.providedEmployee.instance) !== employer.providedEmployee.instance - expect(employer.employee.providedCustomer.instance) !== employer.providedCustomer.instance - } - } - context("in container scope") { - beforeEach { - EmploymentAssembly(scope: .container).assemble(container: container) - } - it("always produces the same instance") { - let employer = container.resolve(Employer.self)! - expect(employer.providedEmployee.instance) === employer.providedEmployee.instance - expect(employer.employee.providedCustomer.instance) === employer.providedCustomer.instance - } - } - } - describe("complex registrations") { - it("resolves provider with arguments") { - container.register(Dog.self) { (_, name, _: Int) in Dog(name: name) } - let provider = container.resolve(Provider.self, arguments: "Hachi", 42) - expect(provider?.instance.name) == "Hachi" - } - it("resolves provider with name") { - container.register(Dog.self, name: "Hachi") { _ in Dog() } - let provider = container.resolve(Provider.self, name: "Hachi") - expect(provider).notTo(beNil()) - } - it("does not resolve provider with wrong name") { - container.register(Dog.self, name: "Hachi") { _ in Dog() } - let provider = container.resolve(Provider.self, name: "Mimi") - expect(provider).to(beNil()) - } - it("does resolve forwarded provider type") { - container.register(Dog.self) { _ in Dog() }.implements(Animal.self) - let provider = container.resolve(Provider.self) - expect(provider).notTo(beNil()) - } - } - describe("circular dependencies") { - beforeEach { - EmploymentAssembly(scope: .graph).assemble(container: container) - } - it("resolves non-provided dependencies to the same instance") { - let employer = container.resolve(Provider.self)?.instance - expect(employer?.employee.employer) === employer - } - it("resolves provided dependencies to different instances") { - let employer = container.resolve(Employer.self) - expect(employer?.providedEmployee.instance.employer) !== employer - } - } - } -} +// TODO: Enable Provider injection +//class ProviderSpec: QuickSpec { +// override func spec() { +// var container: Container! +// beforeEach { +// container = Container() +// } +// +// describe("instance production") { +// it("provides instance from container") { +// container.register(Animal.self) { _ in Dog() } +// let provider = container.resolve(Provider.self) +// expect(provider?.instance is Dog).to(beTrue()) +// } +// it("does not create instance until requested") { +// var created = false +// container.register(Animal.self) { _ in created = true; return Dog() } +// +// _ = container.resolve(Provider.self) +// +// expect(created).to(beFalse()) +// } +// it("resolves instance from the container each time") { +// var created = 0 +// container.register(Animal.self) { _ in created += 1; return Dog() } +// +// let provider = container.resolve(Provider.self) +// _ = provider?.instance +// _ = provider?.instance +// +// expect(created) == 2 +// } +// it("does not resolve provider if base type is not registered") { +// let provider = container.resolve(Provider.self) +// expect(provider).to(beNil()) +// } +// } +// describe("object scopes") { +// context("in transient scope") { +// beforeEach { +// EmploymentAssembly(scope: .transient).assemble(container: container) +// } +// it("always produces different instance") { +// let employer = container.resolve(Employer.self)! +// expect(employer.providedEmployee.instance) !== employer.providedEmployee.instance +// expect(employer.employee.providedCustomer.instance) !== employer.providedCustomer.instance +// } +// } +// context("in graph scope") { +// beforeEach { +// EmploymentAssembly(scope: .graph).assemble(container: container) +// } +// it("always produces different instance") { +// let employer = container.resolve(Employer.self)! +// expect(employer.providedEmployee.instance) !== employer.providedEmployee.instance +// expect(employer.employee.providedCustomer.instance) !== employer.providedCustomer.instance +// } +// } +// context("in container scope") { +// beforeEach { +// EmploymentAssembly(scope: .container).assemble(container: container) +// } +// it("always produces the same instance") { +// let employer = container.resolve(Employer.self)! +// expect(employer.providedEmployee.instance) === employer.providedEmployee.instance +// expect(employer.employee.providedCustomer.instance) === employer.providedCustomer.instance +// } +// } +// } +// describe("complex registrations") { +// it("resolves provider with arguments") { +// container.register(Dog.self) { (_, name, _: Int) in Dog(name: name) } +// let provider = container.resolve(Provider.self, arguments: "Hachi", 42) +// expect(provider?.instance.name) == "Hachi" +// } +// it("resolves provider with name") { +// container.register(Dog.self, name: "Hachi") { _ in Dog() } +// let provider = container.resolve(Provider.self, name: "Hachi") +// expect(provider).notTo(beNil()) +// } +// it("does not resolve provider with wrong name") { +// container.register(Dog.self, name: "Hachi") { _ in Dog() } +// let provider = container.resolve(Provider.self, name: "Mimi") +// expect(provider).to(beNil()) +// } +// it("does resolve forwarded provider type") { +// container.register(Dog.self) { _ in Dog() }.implements(Animal.self) +// let provider = container.resolve(Provider.self) +// expect(provider).notTo(beNil()) +// } +// } +// describe("circular dependencies") { +// beforeEach { +// EmploymentAssembly(scope: .graph).assemble(container: container) +// } +// it("resolves non-provided dependencies to the same instance") { +// let employer = container.resolve(Provider.self)?.instance +// expect(employer?.employee.employer) === employer +// } +// it("resolves provided dependencies to different instances") { +// let employer = container.resolve(Employer.self) +// expect(employer?.providedEmployee.instance.employer) !== employer +// } +// } +// } +//} From cad3999c2dc823d279b4fe7186173569d56a1a32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Mon, 22 Jul 2019 20:28:53 +0200 Subject: [PATCH 102/239] Disable description tests --- ...ontainerSpec.CustomStringConvertible.swift | 131 +++++++++--------- 1 file changed, 66 insertions(+), 65 deletions(-) diff --git a/Tests/2.0 API/ContainerSpec.CustomStringConvertible.swift b/Tests/2.0 API/ContainerSpec.CustomStringConvertible.swift index 99c664d9..76871cf0 100644 --- a/Tests/2.0 API/ContainerSpec.CustomStringConvertible.swift +++ b/Tests/2.0 API/ContainerSpec.CustomStringConvertible.swift @@ -6,68 +6,69 @@ import Nimble import Quick @testable import Swinject -class ContainerSpec_CustomStringConvertible: QuickSpec { - override func spec() { - var container: Container! - beforeEach { - container = Container() - } - - it("describes empty description without service registrations.") { - expect(container.description) == "[\n]" - } - it("describes a registration.") { - container.register(Animal.self) { _ in Cat() } - - expect(container.description) == - "[\n" - + " { Service: Animal, Factory: Resolver -> Animal, ObjectScope: graph }\n" - + "]" - } - it("describes a registration with name.") { - container.register(Animal.self, name: "My Cat") { _ in Cat() } - - expect(container.description) == - "[\n" - + " { Service: Animal, Name: \"My Cat\", Factory: Resolver -> Animal, ObjectScope: graph }\n" - + "]" - } - it("describes a registration with arguments.") { - container.register(Animal.self) { _, arg1, arg2 in Cat(name: arg1, sleeping: arg2) } - - expect(container.description) == - "[\n" - + " { Service: Animal, Factory: (Resolver, String, Bool) -> Animal, ObjectScope: graph }\n" - + "]" - } - it("describes a registration with a specified object scope.") { - container.register(Animal.self) { _ in Cat() } - .inObjectScope(.container) - - expect(container.description) == - "[\n" - + " { Service: Animal, Factory: Resolver -> Animal, ObjectScope: container }\n" - + "]" - } - it("describes a registration with initCompleted.") { - container.register(Animal.self) { _ in Cat() } - .initCompleted { _, _ in } - - expect(container.description) == - "[\n" - + " { Service: Animal, Factory: Resolver -> Animal, ObjectScope: graph, " - + "InitCompleted: Specified 1 closures }\n" - + "]" - } - it("describes multiple registrations.") { - container.register(Animal.self, name: "1") { _ in Cat() } - container.register(Animal.self, name: "2") { _ in Cat() } - - expect(container.description) == - "[\n" - + " { Service: Animal, Name: \"1\", Factory: Resolver -> Animal, ObjectScope: graph },\n" - + " { Service: Animal, Name: \"2\", Factory: Resolver -> Animal, ObjectScope: graph }\n" - + "]" - } - } -} +// TODO: Implement debug description +//class ContainerSpec_CustomStringConvertible: QuickSpec { +// override func spec() { +// var container: Container! +// beforeEach { +// container = Container() +// } +// +// it("describes empty description without service registrations.") { +// expect(container.description) == "[\n]" +// } +// it("describes a registration.") { +// container.register(Animal.self) { _ in Cat() } +// +// expect(container.description) == +// "[\n" +// + " { Service: Animal, Factory: Resolver -> Animal, ObjectScope: graph }\n" +// + "]" +// } +// it("describes a registration with name.") { +// container.register(Animal.self, name: "My Cat") { _ in Cat() } +// +// expect(container.description) == +// "[\n" +// + " { Service: Animal, Name: \"My Cat\", Factory: Resolver -> Animal, ObjectScope: graph }\n" +// + "]" +// } +// it("describes a registration with arguments.") { +// container.register(Animal.self) { _, arg1, arg2 in Cat(name: arg1, sleeping: arg2) } +// +// expect(container.description) == +// "[\n" +// + " { Service: Animal, Factory: (Resolver, String, Bool) -> Animal, ObjectScope: graph }\n" +// + "]" +// } +// it("describes a registration with a specified object scope.") { +// container.register(Animal.self) { _ in Cat() } +// .inObjectScope(.container) +// +// expect(container.description) == +// "[\n" +// + " { Service: Animal, Factory: Resolver -> Animal, ObjectScope: container }\n" +// + "]" +// } +// it("describes a registration with initCompleted.") { +// container.register(Animal.self) { _ in Cat() } +// .initCompleted { _, _ in } +// +// expect(container.description) == +// "[\n" +// + " { Service: Animal, Factory: Resolver -> Animal, ObjectScope: graph, " +// + "InitCompleted: Specified 1 closures }\n" +// + "]" +// } +// it("describes multiple registrations.") { +// container.register(Animal.self, name: "1") { _ in Cat() } +// container.register(Animal.self, name: "2") { _ in Cat() } +// +// expect(container.description) == +// "[\n" +// + " { Service: Animal, Name: \"1\", Factory: Resolver -> Animal, ObjectScope: graph },\n" +// + " { Service: Animal, Name: \"2\", Factory: Resolver -> Animal, ObjectScope: graph }\n" +// + "]" +// } +// } +//} From 92549495ddf6e4ec5e1beb63912bbbbbecbc3c36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Mon, 22 Jul 2019 20:45:04 +0200 Subject: [PATCH 103/239] Implement partial support for object scopes --- Sources/2.0 API/Assembler.swift | 2 ++ Sources/2.0 API/Container.swift | 2 ++ Sources/2.0 API/ObjectScope.swift | 9 ++++++++- Sources/2.0 API/ServiceEntry.swift | 12 ++++++------ Tests/2.0 API/AssemblerSpec.swift | 8 ++++---- Tests/2.0 API/ContainerSpec.swift | 2 +- 6 files changed, 23 insertions(+), 12 deletions(-) diff --git a/Sources/2.0 API/Assembler.swift b/Sources/2.0 API/Assembler.swift index a680c1c0..a6c8c6f6 100644 --- a/Sources/2.0 API/Assembler.swift +++ b/Sources/2.0 API/Assembler.swift @@ -25,6 +25,8 @@ public final class Assembler { /// - parameter parentAssembler: the baseline assembler /// - parameter defaultObjectScope: default object scope for container /// - parameter behaviors: list of behaviors to be added to the container + /// + // TODO: Enable to use any scope as default public init(parentAssembler: Assembler?, defaultObjectScope: ObjectScope = .graph, behaviors: [Behavior] = []) { container = Container( parent: parentAssembler?.container, diff --git a/Sources/2.0 API/Container.swift b/Sources/2.0 API/Container.swift index fe48cb31..654b0911 100644 --- a/Sources/2.0 API/Container.swift +++ b/Sources/2.0 API/Container.swift @@ -20,6 +20,7 @@ import Foundation /// where `A` and `X` are protocols, `B` is a type conforming `A`, and `Y` is a type conforming `X` /// and depending on `A`. public final class Container { + let registry: ScopeRegistry let parent: Container? let defaultScope: AnyScope? var bindings = [Binding]() @@ -50,6 +51,7 @@ public final class Container { self.parent = parent self.defaultScope = defaultObjectScope.scope self.behaviors = behaviors + self.registry = parent?.registry ?? StandardScopeRegistry() registeringClosure(self) } diff --git a/Sources/2.0 API/ObjectScope.swift b/Sources/2.0 API/ObjectScope.swift index 4fd49434..a5d8daca 100644 --- a/Sources/2.0 API/ObjectScope.swift +++ b/Sources/2.0 API/ObjectScope.swift @@ -25,17 +25,24 @@ public enum ObjectScope { extension ObjectScope { var scope: AnyScope? { switch self { - case .graph: return GraphScope() + case .graph: return GraphScope.shared + case .container: return UnboundScope.container default: return nil } } } +extension UnboundScope { + static let container = UnboundScope() +} + final class Graph { let registry = StandardScopeRegistry() } final class GraphScope: Scope { + static let shared = GraphScope() + func registry(for graph: Graph) -> ScopeRegistry { return graph.registry } diff --git a/Sources/2.0 API/ServiceEntry.swift b/Sources/2.0 API/ServiceEntry.swift index d6e3abf6..33287ef8 100644 --- a/Sources/2.0 API/ServiceEntry.swift +++ b/Sources/2.0 API/ServiceEntry.swift @@ -5,12 +5,10 @@ /// The `ServiceEntry` class represents an entry of a registered service type. /// As a returned instance from a `register` method of a `Container`, some configurations can be added. public class ServiceEntry { - private let builder: (Resolver, Any, Any) -> Service - private var key: AnyBindingKey - private var scope: AnyScope? - private var finalizers = [(Resolver, Service) -> Void]() - - var objectScope: ObjectScope? { return nil } + let builder: (Resolver, Any, Any) -> Service + var key: AnyBindingKey + var scope: AnyScope? + var finalizers = [(Resolver, Service) -> Void]() init( name: String?, @@ -39,6 +37,7 @@ public class ServiceEntry { /// - Returns: `self` to add another configuration fluently. @discardableResult public func inObjectScope(_ scope: ObjectScope) -> Self where ObjectScope: Scope { + self.scope = scope return self } @@ -51,6 +50,7 @@ public class ServiceEntry { /// - Returns: `self` to add another configuration fluently. @discardableResult public func inObjectScope(_ objectScope: ObjectScope) -> Self { + self.scope = objectScope.scope return self } diff --git a/Tests/2.0 API/AssemblerSpec.swift b/Tests/2.0 API/AssemblerSpec.swift index e540ed82..ca1c1c7d 100644 --- a/Tests/2.0 API/AssemblerSpec.swift +++ b/Tests/2.0 API/AssemblerSpec.swift @@ -48,7 +48,7 @@ class AssemblerSpec: QuickSpec { let container = assembler.resolver.resolve(Container.self) let serviceEntry = container?.register(Animal.self) { _ in Siamese(name: "Siam") } - expect(serviceEntry?.objectScope) === ObjectScope.container + expect(serviceEntry?.scope) === ObjectScope.container.scope } it("uses graph scope if no default object scope is injected") { @@ -58,7 +58,7 @@ class AssemblerSpec: QuickSpec { let container = assembler.resolver.resolve(Container.self) let serviceEntry = container?.register(Animal.self) { _ in Siamese(name: "Siam") } - expect(serviceEntry?.objectScope) === ObjectScope.graph + expect(serviceEntry?.scope) === ObjectScope.graph.scope } it("can assembly a multiple container") { @@ -294,7 +294,7 @@ class AssemblerSpec: QuickSpec { let container = childAssembler.resolver.resolve(Container.self) let serviceEntry = container?.register(Animal.self) { _ in Siamese(name: "Siam") } - expect(serviceEntry?.objectScope) === ObjectScope.container + expect(serviceEntry?.scope) === ObjectScope.container.scope } it("has default object scope of graph type") { @@ -306,7 +306,7 @@ class AssemblerSpec: QuickSpec { let container = childAssembler.resolver.resolve(Container.self) let serviceEntry = container?.register(Animal.self) { _ in Siamese(name: "Siam") } - expect(serviceEntry?.objectScope) === ObjectScope.graph + expect(serviceEntry?.scope) === ObjectScope.graph.scope } it("uses given list of behaviors to container") { diff --git a/Tests/2.0 API/ContainerSpec.swift b/Tests/2.0 API/ContainerSpec.swift index f765cbb9..33ed59e6 100644 --- a/Tests/2.0 API/ContainerSpec.swift +++ b/Tests/2.0 API/ContainerSpec.swift @@ -369,7 +369,7 @@ class ContainerSpec: QuickSpec { let container = Container(parent: nil, defaultObjectScope: .weak) let serviceEntry = container.register(Animal.self) { _ in Siamese(name: "Siam") } - expect(serviceEntry.objectScope) === ObjectScope.weak + expect(serviceEntry.scope) === ObjectScope.weak.scope } } } From 7670e3567983c9f2598f832f3772c7aa4ddae1f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Mon, 22 Jul 2019 21:41:50 +0200 Subject: [PATCH 104/239] Disable failing tests --- Tests/2.0 API/ContainerSpec.Circularity.swift | 27 +-- Tests/2.0 API/ContainerSpec.swift | 165 +++++++++--------- Tests/Support/GeneratedMocks.swift | 35 ++++ 3 files changed, 133 insertions(+), 94 deletions(-) diff --git a/Tests/2.0 API/ContainerSpec.Circularity.swift b/Tests/2.0 API/ContainerSpec.Circularity.swift index 6855ac4a..ca0941b1 100644 --- a/Tests/2.0 API/ContainerSpec.Circularity.swift +++ b/Tests/2.0 API/ContainerSpec.Circularity.swift @@ -116,18 +116,19 @@ class ContainerSpec_Circularity: QuickSpec { expect(d.c as? CDependingOnAD === c).to(beTrue()) // Workaround for crash in Nimble } } - describe("Graph root is in weak object scope") { - it("does not deallocate during graph resolution") { - container.register(B.self) { r in BDependingOnC(c: r.resolve(C.self)!) } - .inObjectScope(.weak) - container.register(C.self) { _ in CDependingOnWeakB() } - .initCompleted { r, c in (c as! CDependingOnWeakB).b = r.resolve(B.self) } - - let b = container.resolve(B.self) as? BDependingOnC - let c = b?.c as? CDependingOnWeakB - - expect(c?.b).notTo(beNil()) - } - } + // TODO: Implement weak scope +// describe("Graph root is in weak object scope") { +// it("does not deallocate during graph resolution") { +// container.register(B.self) { r in BDependingOnC(c: r.resolve(C.self)!) } +// .inObjectScope(.weak) +// container.register(C.self) { _ in CDependingOnWeakB() } +// .initCompleted { r, c in (c as! CDependingOnWeakB).b = r.resolve(B.self) } +// +// let b = container.resolve(B.self) as? BDependingOnC +// let c = b?.c as? CDependingOnWeakB +// +// expect(c?.b).notTo(beNil()) +// } +// } } } diff --git a/Tests/2.0 API/ContainerSpec.swift b/Tests/2.0 API/ContainerSpec.swift index 33ed59e6..8f426380 100644 --- a/Tests/2.0 API/ContainerSpec.swift +++ b/Tests/2.0 API/ContainerSpec.swift @@ -187,24 +187,25 @@ class ContainerSpec: QuickSpec { expect(ownersSushi === catsSushi).to(beTrue()) // Workaround for crash in Nimble. } } - context("in weak scope") { - it("shares the object in the container") { - container.register(Animal.self) { _ in Cat() } - .inObjectScope(.weak) - - let cat1 = container.resolve(Animal.self) as? Cat - let cat2 = container.resolve(Animal.self) as? Cat - expect(cat1).notTo(beNil()) - expect(cat1 === cat2).to(beTrue()) // Workaround for crash in Nimble. - } - it("does not maintain a strong reference to the object") { - container.register(Animal.self) { _ in Cat() } - .inObjectScope(.weak) - - weak var cat = container.resolve(Animal.self) as? Cat - expect(cat).to(beNil()) - } - } + // TODO: implement weak scope +// context("in weak scope") { +// it("shares the object in the container") { +// container.register(Animal.self) { _ in Cat() } +// .inObjectScope(.weak) +// +// let cat1 = container.resolve(Animal.self) as? Cat +// let cat2 = container.resolve(Animal.self) as? Cat +// expect(cat1).notTo(beNil()) +// expect(cat1 === cat2).to(beTrue()) // Workaround for crash in Nimble. +// } +// it("does not maintain a strong reference to the object") { +// container.register(Animal.self) { _ in Cat() } +// .inObjectScope(.weak) +// +// weak var cat = container.resolve(Animal.self) as? Cat +// expect(cat).to(beNil()) +// } +// } } describe("Init completed event") { it("raises the event when a new instance is created.") { @@ -284,61 +285,62 @@ class ContainerSpec: QuickSpec { expect(owner?.pet).notTo(beNil()) } } - describe("Value type resolution") { - it("resolves struct instances ignoring object scopes.") { - let runInObjectScope: (ObjectScope) -> Void = { scope in - container.removeAll() - container.register(Animal.self) { _ in Turtle(name: "Ninja") } - .inObjectScope(scope) - var turtle1 = container.resolve(Animal.self)! - let turtle2 = container.resolve(Animal.self)! - turtle1.name = "Samurai" - expect(turtle1.name) == "Samurai" - expect(turtle2.name) == "Ninja" - } - - runInObjectScope(.transient) - runInObjectScope(.graph) - runInObjectScope(.container) - } - it("resolves struct instances defined in the parent container ignoring object scopes.") { - let runInObjectScope: (ObjectScope) -> Void = { scope in - container.removeAll() - container.register(Animal.self) { _ in Turtle(name: "Ninja") } - .inObjectScope(scope) - let childContainer = Container(parent: container) - - var turtle1 = childContainer.resolve(Animal.self)! - let turtle2 = childContainer.resolve(Animal.self)! - turtle1.name = "Samurai" - expect(turtle1.name) == "Samurai" - expect(turtle2.name) == "Ninja" - } - - runInObjectScope(.transient) - runInObjectScope(.graph) - runInObjectScope(.container) - } - context("object scope is container or hierarchy") { - it("resolves only once to simulate singleton (instantiation only once).") { - let runInObjectScope: (ObjectScope, Int) -> Void = { scope, expectation in - var invokedCount = 0 - container.removeAll() - container.register(Animal.self) { _ in - invokedCount += 1 - return Turtle(name: "Ninja") - }.inObjectScope(scope) - _ = container.resolve(Animal.self)! - _ = container.resolve(Animal.self)! - expect(invokedCount) == expectation - } - - runInObjectScope(.transient, 2) - runInObjectScope(.graph, 2) - runInObjectScope(.container, 1) - } - } - } + // TODO: Implement context translation +// describe("Value type resolution") { +// it("resolves struct instances ignoring object scopes.") { +// let runInObjectScope: (ObjectScope) -> Void = { scope in +// container.removeAll() +// container.register(Animal.self) { _ in Turtle(name: "Ninja") } +// .inObjectScope(scope) +// var turtle1 = container.resolve(Animal.self)! +// let turtle2 = container.resolve(Animal.self)! +// turtle1.name = "Samurai" +// expect(turtle1.name) == "Samurai" +// expect(turtle2.name) == "Ninja" +// } +// +// runInObjectScope(.transient) +// runInObjectScope(.graph) +// runInObjectScope(.container) +// } +// it("resolves struct instances defined in the parent container ignoring object scopes.") { +// let runInObjectScope: (ObjectScope) -> Void = { scope in +// container.removeAll() +// container.register(Animal.self) { _ in Turtle(name: "Ninja") } +// .inObjectScope(scope) +// let childContainer = Container(parent: container) +// +// var turtle1 = childContainer.resolve(Animal.self)! +// let turtle2 = childContainer.resolve(Animal.self)! +// turtle1.name = "Samurai" +// expect(turtle1.name) == "Samurai" +// expect(turtle2.name) == "Ninja" +// } +// +// runInObjectScope(.transient) +// runInObjectScope(.graph) +// runInObjectScope(.container) +// } +// context("object scope is container or hierarchy") { +// it("resolves only once to simulate singleton (instantiation only once).") { +// let runInObjectScope: (ObjectScope, Int) -> Void = { scope, expectation in +// var invokedCount = 0 +// container.removeAll() +// container.register(Animal.self) { _ in +// invokedCount += 1 +// return Turtle(name: "Ninja") +// }.inObjectScope(scope) +// _ = container.resolve(Animal.self)! +// _ = container.resolve(Animal.self)! +// expect(invokedCount) == expectation +// } +// +// runInObjectScope(.transient, 2) +// runInObjectScope(.graph, 2) +// runInObjectScope(.container, 1) +// } +// } +// } describe("Class as a service type") { it("resolves a registred subclass of a service type class.") { container.register(Cat.self) { _ in Siamese(name: "Siam") } @@ -364,13 +366,14 @@ class ContainerSpec: QuickSpec { expect(container.resolve(Animal.self) as? Cat).notTo(beNil()) } } - describe("Default object scope") { - it("registers services with given object scope") { - let container = Container(parent: nil, defaultObjectScope: .weak) - - let serviceEntry = container.register(Animal.self) { _ in Siamese(name: "Siam") } - expect(serviceEntry.scope) === ObjectScope.weak.scope - } - } + // TODO: Implement weak scope +// describe("Default object scope") { +// it("registers services with given object scope") { +// let container = Container(parent: nil, defaultObjectScope: .weak) +// +// let serviceEntry = container.register(Animal.self) { _ in Siamese(name: "Siam") } +// expect(serviceEntry.scope) === ObjectScope.weak.scope +// } +// } } } diff --git a/Tests/Support/GeneratedMocks.swift b/Tests/Support/GeneratedMocks.swift index 2e9a38c6..70aa8eac 100644 --- a/Tests/Support/GeneratedMocks.swift +++ b/Tests/Support/GeneratedMocks.swift @@ -76,6 +76,41 @@ class AnyBindningMakerMock: AnyBindningMaker { return makeBindingForClosure.map({ $0(descriptor) }) ?? makeBindingForReturnValue } +} +class AnyContextTranslatorMock: AnyContextTranslator { + var sourceType: Any.Type { + get { return underlyingSourceType } + set(value) { underlyingSourceType = value } + } + var underlyingSourceType: Any.Type! + var targetType: Any.Type { + get { return underlyingTargetType } + set(value) { underlyingTargetType = value } + } + var underlyingTargetType: Any.Type! + + //MARK: - translate + + var translateThrowableError: Error? + var translateCallsCount = 0 + var translateCalled: Bool { + return translateCallsCount > 0 + } + var translateReceivedContext: Any? + var translateReceivedInvocations: [Any] = [] + var translateReturnValue: Any! + var translateClosure: ((Any) throws -> Any)? + + func translate(_ context: Any) throws -> Any { + if let error = translateThrowableError { + throw error + } + translateCallsCount += 1 + translateReceivedContext = context + translateReceivedInvocations.append(context) + return try translateClosure.map({ try $0(context) }) ?? translateReturnValue + } + } class AnyInstanceMakerMock: AnyInstanceMaker { From fd5291b3e10b0ec48a512b3dc37378cd18102a4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Mon, 22 Jul 2019 23:08:02 +0200 Subject: [PATCH 105/239] Use context translators during request resolution --- Sources/2.0 API/Container.swift | 2 +- Sources/Core/ContextTranslator.swift | 33 +++++++ Sources/Core/InstanceRequest.swift | 6 ++ Sources/Core/Swinject.swift | 40 ++++++-- Sources/Core/SwinjectTree.swift | 4 +- Swinject.xcodeproj/project.pbxproj | 10 ++ Tests/Unit Specs/SwinjectSpec.swift | 94 +++++++++++++++---- .../Unit Specs/SwinjectTreeBuilderSpec.swift | 8 ++ 8 files changed, 169 insertions(+), 28 deletions(-) create mode 100644 Sources/Core/ContextTranslator.swift diff --git a/Sources/2.0 API/Container.swift b/Sources/2.0 API/Container.swift index 654b0911..29b716e8 100644 --- a/Sources/2.0 API/Container.swift +++ b/Sources/2.0 API/Container.swift @@ -26,7 +26,7 @@ public final class Container { var bindings = [Binding]() var behaviors = [Behavior]() var swinject: Swinject { - Swinject(tree: SwinjectTree(bindings: allBindings, includeEntries: [])) + Swinject(tree: SwinjectTree(bindings: allBindings, includeEntries: [], translators: [])) } var allBindings: [Binding] { return bindings + (parent?.allBindings ?? []) diff --git a/Sources/Core/ContextTranslator.swift b/Sources/Core/ContextTranslator.swift new file mode 100644 index 00000000..865855c0 --- /dev/null +++ b/Sources/Core/ContextTranslator.swift @@ -0,0 +1,33 @@ +// +// Created by Jakub Vaňo on 22/07/2019. +// + +// sourcery: AutoMockable +protocol AnyContextTranslator: SwinjectEntry { + var sourceType: Any.Type { get } + var targetType: Any.Type { get } + func translate(_ context: Any) throws -> Any +} + +struct ContextTranslator: AnyContextTranslator { + let sourceType: Any.Type = Source.self + let targetType: Any.Type = Target.self + let translation: (Source) -> Target + + func translate(_ context: Any) throws -> Any { + guard let context = context as? Source else { throw SwinjectError() } + return translation(context) + } +} + +struct IdentityTranslator: AnyContextTranslator { + let sourceType: Any.Type + let targetType: Any.Type + + init(for contextType: Any.Type) { + sourceType = contextType + targetType = contextType + } + + func translate(_ context: Any) throws -> Any { context } +} diff --git a/Sources/Core/InstanceRequest.swift b/Sources/Core/InstanceRequest.swift index 6efaa9aa..8a69b63a 100644 --- a/Sources/Core/InstanceRequest.swift +++ b/Sources/Core/InstanceRequest.swift @@ -14,3 +14,9 @@ func request( ) -> InstanceRequest, Argument> { InstanceRequest(descriptor: tagged(type, with: tag), argument: arg) } + +extension InstanceRequest { + func key(forContextType contextType: Any.Type) -> BindingKey { + BindingKey(descriptor: descriptor, contextType: contextType, argumentType: Argument.self) + } +} diff --git a/Sources/Core/Swinject.swift b/Sources/Core/Swinject.swift index 165c771f..5bde5301 100644 --- a/Sources/Core/Swinject.swift +++ b/Sources/Core/Swinject.swift @@ -25,15 +25,37 @@ extension Swinject { } extension Swinject: Resolver { + struct Resolution { + let binding: Binding + let translator: AnyContextTranslator + } + public func resolve( _ request: InstanceRequest ) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { - let key = BindingKey( - descriptor: request.descriptor, - contextType: contextType, - argumentType: Argument.self + try instance( + resolution: findResolution(for: request.descriptor, and: Argument.self), + context: context, + arg: request.argument ) - return try instance(from: findBinding(for: key), context: context, arg: request.argument) + } + + private func findResolution(for descriptor: AnyTypeDescriptor, and argumentType: Any.Type) throws -> Resolution { + let translators = (tree.translators + [IdentityTranslator(for: contextType)]).filter { + $0.sourceType == contextType + } + let keys = translators.map { + BindingKey(descriptor: descriptor, contextType: $0.targetType, argumentType: argumentType) + } + let bindings = keys.map { + try? findBinding(for: $0) + } + let resolutions = zip(bindings, translators) + .filter { $0.0 != nil } + .map { Resolution(binding: $0.0!, translator: $0.1) } + + guard resolutions.count == 1 else { throw SwinjectError() } + return resolutions[0] } private func findBinding(for key: AnyBindingKey) throws -> Binding { @@ -43,8 +65,12 @@ extension Swinject: Resolver { } private func instance( - from binding: Binding, context: Context, arg: Argument + resolution: Resolution, context: Context, arg: Argument ) throws -> Type { - try binding.instance(arg: arg, context: context, resolver: self) as? Type ?? { throw SwinjectError() }() + try resolution.binding.instance( + arg: arg, + context: resolution.translator.translate(context), + resolver: self + ) as? Type ?? { throw SwinjectError() }() } } diff --git a/Sources/Core/SwinjectTree.swift b/Sources/Core/SwinjectTree.swift index 588b1e04..cc67a249 100644 --- a/Sources/Core/SwinjectTree.swift +++ b/Sources/Core/SwinjectTree.swift @@ -7,6 +7,7 @@ public protocol SwinjectEntry {} public struct SwinjectTree { let bindings: [Binding] let includeEntries: [ModuleIncludeEntry] + let translators: [AnyContextTranslator] } @_functionBuilder @@ -34,7 +35,8 @@ public enum SwinjectTreeBuilder { let entries = input.flatMap(unpack) return SwinjectTree( bindings: entries.compactMap { $0 as? Binding }, - includeEntries: entries.compactMap { $0 as? ModuleIncludeEntry } + includeEntries: entries.compactMap { $0 as? ModuleIncludeEntry }, + translators: entries.compactMap { $0 as? AnyContextTranslator } ) // TODO: Validate } diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index d9cdb9fb..3c271f02 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -251,6 +251,10 @@ CD4D866622E4C8A70042ACDC /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD4D866322E4C6DB0042ACDC /* ObjectScope.swift */; }; CD4D866722E4C8A80042ACDC /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD4D866322E4C6DB0042ACDC /* ObjectScope.swift */; }; CD4D866822E4C8A80042ACDC /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD4D866322E4C6DB0042ACDC /* ObjectScope.swift */; }; + CDF8F35622E64694008B2AF5 /* ContextTranslator.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDF8F35522E64694008B2AF5 /* ContextTranslator.swift */; }; + CDF8F35722E64694008B2AF5 /* ContextTranslator.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDF8F35522E64694008B2AF5 /* ContextTranslator.swift */; }; + CDF8F35822E64694008B2AF5 /* ContextTranslator.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDF8F35522E64694008B2AF5 /* ContextTranslator.swift */; }; + CDF8F35922E64694008B2AF5 /* ContextTranslator.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDF8F35522E64694008B2AF5 /* ContextTranslator.swift */; }; CFC3CDB46CD8FFA22EB0FADD /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A0157DBBD5E1F45963BB0932 /* Swinject.framework */; }; D10FFA4B80F4BE6024B1DCEE /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1910A1471C3CA9EA86F350BA /* LoadAwareAssembly.swift */; }; D18275ADB0E56D3087894518 /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; @@ -482,6 +486,7 @@ CD4D866C22E4D54D0042ACDC /* Resolver+LegacyApi.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+LegacyApi.swifttemplate"; sourceTree = ""; }; CD4D866D22E4D54D0042ACDC /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; CD4D866F22E4D54D0042ACDC /* ServiceEntry+TypeForwarding.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "ServiceEntry+TypeForwarding.swifttemplate"; sourceTree = ""; }; + CDF8F35522E64694008B2AF5 /* ContextTranslator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextTranslator.swift; sourceTree = ""; }; D1FA0377AF4799D42E9462FA /* BasicAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BasicAssembly.swift; sourceTree = ""; }; E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRequest.swift; sourceTree = ""; }; E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; @@ -782,6 +787,7 @@ A3586A4987B7C7C8122D674E /* SwinjectError.swift */, 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */, E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */, + CDF8F35522E64694008B2AF5 /* ContextTranslator.swift */, ); path = Core; sourceTree = ""; @@ -1195,6 +1201,7 @@ 0568E116A56DA02DA92BAC8E /* Behavior.swift in Sources */, 5B0ECCEBC6CB23571A9EDA38 /* BinderEnvironment.swift in Sources */, 49FB15929F16836D51779A1D /* Binding.swift in Sources */, + CDF8F35722E64694008B2AF5 /* ContextTranslator.swift in Sources */, 64A8413AD2ED65BB25BD0113 /* BindingKey.swift in Sources */, 9FEC055DC6BE1D844FE5F082 /* Closable.swift in Sources */, 0CB9E677FDF7CF424A738F34 /* Container+Registration.swift in Sources */, @@ -1319,6 +1326,7 @@ 588A600231D894122A4D9C47 /* Behavior.swift in Sources */, 196AA219BB35334B07B34F37 /* BinderEnvironment.swift in Sources */, 4735419DE3D63E556D07C663 /* Binding.swift in Sources */, + CDF8F35822E64694008B2AF5 /* ContextTranslator.swift in Sources */, FDB7873663CEFBF7BE76ECFF /* BindingKey.swift in Sources */, 2B67E8B80A930E8598FAD10C /* Closable.swift in Sources */, 7E0539C5CD130F0AC4B02096 /* Container+Registration.swift in Sources */, @@ -1443,6 +1451,7 @@ C3AD37D47C38E5EB20FAF917 /* Behavior.swift in Sources */, 01D985B5F99817DEE0E0DAD1 /* BinderEnvironment.swift in Sources */, 705F51FD21F7E1536BFC0C41 /* Binding.swift in Sources */, + CDF8F35622E64694008B2AF5 /* ContextTranslator.swift in Sources */, A4866802E1E597EEFEFDEB66 /* BindingKey.swift in Sources */, 816F47E9D87CAE910091B484 /* Closable.swift in Sources */, 7472B748AEA9F4D1E5EF9A70 /* Container+Registration.swift in Sources */, @@ -1483,6 +1492,7 @@ AF5F860DBFE2607EF4157CF7 /* Behavior.swift in Sources */, 4D0ABCA733720469F2240C31 /* BinderEnvironment.swift in Sources */, EEC04BEF02E6776003CC2003 /* Binding.swift in Sources */, + CDF8F35922E64694008B2AF5 /* ContextTranslator.swift in Sources */, E0D7B3285AA1FE51E14A52A1 /* BindingKey.swift in Sources */, 418F111C8E128766AC8E33CC /* Closable.swift in Sources */, 7DD047C203659BCA7F04E48D /* Container+Registration.swift in Sources */, diff --git a/Tests/Unit Specs/SwinjectSpec.swift b/Tests/Unit Specs/SwinjectSpec.swift index 672494a3..8dc95083 100644 --- a/Tests/Unit Specs/SwinjectSpec.swift +++ b/Tests/Unit Specs/SwinjectSpec.swift @@ -7,6 +7,12 @@ import Quick @testable import Swinject class SwinjectSpec: QuickSpec { override func spec() { + var swinject: Swinject! + var binding = BindingMock() + beforeEach { + binding = BindingMock() + swinject = Swinject { binding } + } describe("instance injection") { context("no bindings") { it("throws") { @@ -15,12 +21,6 @@ class SwinjectSpec: QuickSpec { override func spec() { } } context("single binding") { - var swinject: Swinject! - var binding = BindingMock() - beforeEach { - binding = BindingMock() - swinject = Swinject { binding } - } it("request instance from matching binding") { binding.matchesReturnValue = true _ = try? swinject.instance(of: Any.self) @@ -73,7 +73,6 @@ class SwinjectSpec: QuickSpec { override func spec() { } } context("multiple bindings") { - var swinject: Swinject! var bindings = [BindingMock]() beforeEach { bindings = Array(0 ..< 3).map { _ in BindingMock() } @@ -100,12 +99,6 @@ class SwinjectSpec: QuickSpec { override func spec() { } } describe("provider injection") { - var swinject: Swinject! - var binding = BindingMock() - beforeEach { - binding = BindingMock() - swinject = Swinject { binding } - } it("does not throw if binding matches provided type") { binding.matchesReturnValue = true binding.instanceArgContextResolverReturnValue = 42 @@ -164,12 +157,6 @@ class SwinjectSpec: QuickSpec { override func spec() { } } describe("factory injection") { - var swinject: Swinject! - var binding = BindingMock() - beforeEach { - binding = BindingMock() - swinject = Swinject { binding } - } it("throws if missing binding for created type") { binding.matchesReturnValue = false let factory = swinject.factory() as (String) throws -> Int @@ -261,4 +248,73 @@ class SwinjectSpec: QuickSpec { override func spec() { } } } + describe("context translators") { + var translators = [AnyContextTranslatorMock]() + var bindings = [BindingMock]() + beforeEach { + translators = (1...3).map { _ in AnyContextTranslatorMock() } + translators.forEach { + $0.sourceType = Void.self + $0.targetType = Void.self + $0.translateReturnValue = 0 + } + bindings = Array(0 ..< 3).map { _ in BindingMock() } + bindings.forEach { $0.matchesReturnValue = false } + swinject = Swinject { + bindings[0]; bindings[1]; bindings[2] + translators[0]; translators[1]; translators[2] + } + } + it("does not throw if one of context translators has correct context translation") { + bindings[0].matchesClosure = { $0.contextType == Int.self } + translators[1].sourceType = String.self + translators[1].targetType = Int.self + expect { try swinject.on("context").instance() }.notTo(throwError()) + } + it("throws if translator has incorrect source type") { + bindings[0].matchesClosure = { $0.contextType == Int.self } + translators[1].sourceType = Double.self + translators[1].targetType = Int.self + expect { try swinject.on("context").instance() }.to(throwError()) + } + it("throws if multiple translators have correct translation") { + bindings[0].matchesClosure = { $0.contextType == Int.self } + translators[1...2].forEach { + $0.sourceType = String.self + $0.targetType = Int.self + $0.translateReturnValue = 0 + } + expect { try swinject.on("context").instance() }.to(throwError()) + } + it("does not throw if multiple translators have correct target type but not source type") { + bindings[0].matchesClosure = { $0.contextType == Int.self } + translators[0].sourceType = String.self + translators[0].targetType = Int.self + translators[1].sourceType = Double.self + translators[1].targetType = Int.self + expect { try swinject.on("context").instance() }.notTo(throwError()) + } + it("throws if has binding for given context and translator with correct context translation") { + bindings[0].matchesClosure = { $0.contextType == Int.self } + bindings[1].matchesClosure = { $0.contextType == String.self } + translators[0].sourceType = String.self + translators[0].targetType = Int.self + expect { try swinject.on("context").instance() }.to(throwError()) + } + it("passes translated context to binding") { + bindings[0].matchesClosure = { $0.contextType == Int.self } + translators[0].sourceType = String.self + translators[0].targetType = Int.self + translators[0].translateReturnValue = 42 + _ = try? swinject.on("context").instance() as Void + expect(bindings[0].instanceArgContextResolverReceivedArguments?.context as? Int) == 42 + } + it("passes original context to context resolver") { + bindings[0].matchesClosure = { $0.contextType == Int.self } + translators[0].sourceType = String.self + translators[0].targetType = Int.self + _ = try? swinject.on("context").instance() as Void + expect(translators[0].translateReceivedContext as? String) == "context" + } + } } } diff --git a/Tests/Unit Specs/SwinjectTreeBuilderSpec.swift b/Tests/Unit Specs/SwinjectTreeBuilderSpec.swift index f7c85d5a..f80b0ec7 100644 --- a/Tests/Unit Specs/SwinjectTreeBuilderSpec.swift +++ b/Tests/Unit Specs/SwinjectTreeBuilderSpec.swift @@ -52,6 +52,14 @@ class SwinjectTreeBuilderSpec: QuickSpec { override func spec() { expect(tree.includeEntries.count) == 2 expect(tree.bindings.count) == 3 } + it("builds closure with translator entries") { + let tree = makeTree { + AnyContextTranslatorMock() + AnyContextTranslatorMock() + AnyContextTranslatorMock() + } + expect(tree.translators.count) == 3 + } } } } From ac72198da07a263d6796c709410ee890b6188f04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Mon, 22 Jul 2019 23:30:05 +0200 Subject: [PATCH 106/239] Describe context translator in api spec --- Sources/Core/ContextTranslator.swift | 10 +++++++++- Tests/3.0 API/SwinjectApiSpec.swift | 13 +++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Sources/Core/ContextTranslator.swift b/Sources/Core/ContextTranslator.swift index 865855c0..168e3e85 100644 --- a/Sources/Core/ContextTranslator.swift +++ b/Sources/Core/ContextTranslator.swift @@ -9,7 +9,7 @@ protocol AnyContextTranslator: SwinjectEntry { func translate(_ context: Any) throws -> Any } -struct ContextTranslator: AnyContextTranslator { +public struct ContextTranslator: AnyContextTranslator { let sourceType: Any.Type = Source.self let targetType: Any.Type = Target.self let translation: (Source) -> Target @@ -31,3 +31,11 @@ struct IdentityTranslator: AnyContextTranslator { func translate(_ context: Any) throws -> Any { context } } + +public func registerContextTranslator( + from _: Source.Type = Source.self, + to _: Target.Type = Target.self, + using translation: @escaping (Source) -> Target +) -> ContextTranslator { + ContextTranslator(translation: translation) +} diff --git a/Tests/3.0 API/SwinjectApiSpec.swift b/Tests/3.0 API/SwinjectApiSpec.swift index af3394ba..4adc878a 100644 --- a/Tests/3.0 API/SwinjectApiSpec.swift +++ b/Tests/3.0 API/SwinjectApiSpec.swift @@ -120,6 +120,19 @@ class SwinjectApiSpec: QuickSpec { override func spec() { expect { try swinject.on("context").instance() as Int } == 42 expect { try swinject.on(Human()).instance() as Int } == 42 } + it("can translate contexts") { + // FIXME: compiler segfaults if declaring these providers inside function builder + let intProvider = contexted(String.self).provider { _, string in Int(string)! } + let doubleProvider = contexted(Int.self).provider { _, int in Double(int) } + let swinject = Swinject { + bbind(Int.self) & intProvider + bbind(Double.self) & doubleProvider + registerContextTranslator(from: String.self) { Int($0)! } + } + let contexted = swinject.on("42") + expect { try contexted.instance(of: Int.self) } == 42 + expect { try contexted.instance(of: Double.self) } == 42 + } it("can bind singleton") { let swinject = Swinject { bbind(Human.self) & singleton { Human() } From 078acd30fa15f806f9daef4507ce9f858465a153 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Tue, 23 Jul 2019 00:20:19 +0200 Subject: [PATCH 107/239] Fix resolution when single binding matches multiple contexts --- Sources/Core/InstanceRequest.swift | 17 ++++++++---- Sources/Core/Swinject.swift | 41 +++++++++-------------------- Tests/Unit Specs/SwinjectSpec.swift | 22 +++++++++++----- 3 files changed, 40 insertions(+), 40 deletions(-) diff --git a/Sources/Core/InstanceRequest.swift b/Sources/Core/InstanceRequest.swift index 8a69b63a..533484ca 100644 --- a/Sources/Core/InstanceRequest.swift +++ b/Sources/Core/InstanceRequest.swift @@ -2,9 +2,16 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -public struct InstanceRequest where Descriptor: TypeDescriptor { - let descriptor: Descriptor - let argument: Argument +protocol AnyInstanceRequest { + var descriptor: AnyTypeDescriptor { get } + var argument: Any { get } + var argumentType: Any.Type { get } +} + +public struct InstanceRequest: AnyInstanceRequest where Descriptor: TypeDescriptor { + let argumentType: Any.Type = Argument.self + let descriptor: AnyTypeDescriptor + let argument: Any } func request( @@ -15,8 +22,8 @@ func request( InstanceRequest(descriptor: tagged(type, with: tag), argument: arg) } -extension InstanceRequest { +extension AnyInstanceRequest { func key(forContextType contextType: Any.Type) -> BindingKey { - BindingKey(descriptor: descriptor, contextType: contextType, argumentType: Argument.self) + BindingKey(descriptor: descriptor, contextType: contextType, argumentType: argumentType) } } diff --git a/Sources/Core/Swinject.swift b/Sources/Core/Swinject.swift index 5bde5301..5a79cfa4 100644 --- a/Sources/Core/Swinject.swift +++ b/Sources/Core/Swinject.swift @@ -33,44 +33,27 @@ extension Swinject: Resolver { public func resolve( _ request: InstanceRequest ) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { - try instance( - resolution: findResolution(for: request.descriptor, and: Argument.self), - context: context, - arg: request.argument - ) + let binding = try findBinding(for: request) + let translator = try findTranslator(for: request, and: binding) + return try instance(from: binding, context: translator.translate(context), arg: request.argument) } - private func findResolution(for descriptor: AnyTypeDescriptor, and argumentType: Any.Type) throws -> Resolution { - let translators = (tree.translators + [IdentityTranslator(for: contextType)]).filter { - $0.sourceType == contextType - } - let keys = translators.map { - BindingKey(descriptor: descriptor, contextType: $0.targetType, argumentType: argumentType) - } - let bindings = keys.map { - try? findBinding(for: $0) - } - let resolutions = zip(bindings, translators) - .filter { $0.0 != nil } - .map { Resolution(binding: $0.0!, translator: $0.1) } - - guard resolutions.count == 1 else { throw SwinjectError() } - return resolutions[0] + private func findTranslator(for request: AnyInstanceRequest, and binding: Binding) throws -> AnyContextTranslator { + return try (tree.translators + [IdentityTranslator(for: contextType)]) + .filter { $0.sourceType == contextType } + .filter { binding.matches(request.key(forContextType: $0.targetType)) } + .first ?? { throw SwinjectError() }() } - private func findBinding(for key: AnyBindingKey) throws -> Binding { - let bindings = tree.bindings.filter { $0.matches(key) } + private func findBinding(for request: AnyInstanceRequest) throws -> Binding { + let bindings = tree.bindings.filter { (try? findTranslator(for: request, and: $0)) != nil } guard bindings.count == 1 else { throw SwinjectError() } return bindings[0] } private func instance( - resolution: Resolution, context: Context, arg: Argument + from binding: Binding, context: Context, arg: Argument ) throws -> Type { - try resolution.binding.instance( - arg: arg, - context: resolution.translator.translate(context), - resolver: self - ) as? Type ?? { throw SwinjectError() }() + try binding.instance(arg: arg, context: context, resolver: self) as? Type ?? { throw SwinjectError() }() } } diff --git a/Tests/Unit Specs/SwinjectSpec.swift b/Tests/Unit Specs/SwinjectSpec.swift index 8dc95083..a1688eae 100644 --- a/Tests/Unit Specs/SwinjectSpec.swift +++ b/Tests/Unit Specs/SwinjectSpec.swift @@ -279,19 +279,20 @@ class SwinjectSpec: QuickSpec { override func spec() { } it("throws if multiple translators have correct translation") { bindings[0].matchesClosure = { $0.contextType == Int.self } - translators[1...2].forEach { - $0.sourceType = String.self - $0.targetType = Int.self - $0.translateReturnValue = 0 - } + bindings[1].matchesClosure = { $0.contextType == Float.self } + translators[0].sourceType = String.self + translators[0].targetType = Int.self + translators[1].sourceType = String.self + translators[1].targetType = Float.self expect { try swinject.on("context").instance() }.to(throwError()) } it("does not throw if multiple translators have correct target type but not source type") { bindings[0].matchesClosure = { $0.contextType == Int.self } + bindings[1].matchesClosure = { $0.contextType == Float.self } translators[0].sourceType = String.self translators[0].targetType = Int.self translators[1].sourceType = Double.self - translators[1].targetType = Int.self + translators[1].targetType = Float.self expect { try swinject.on("context").instance() }.notTo(throwError()) } it("throws if has binding for given context and translator with correct context translation") { @@ -316,5 +317,14 @@ class SwinjectSpec: QuickSpec { override func spec() { _ = try? swinject.on("context").instance() as Void expect(translators[0].translateReceivedContext as? String) == "context" } + it("does not throw if single binding can be used with multiple translated contexts") { + bindings[0].matchesReturnValue = true + translators[1...2].forEach { + $0.sourceType = String.self + $0.targetType = Int.self + $0.translateReturnValue = 0 + } + expect { try swinject.on("context").instance() }.notTo(throwError()) + } } } } From 089e74ed17d17abc87e7fceabc61369f349798e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Tue, 23 Jul 2019 00:30:22 +0200 Subject: [PATCH 108/239] Fix ServiceEntry's binding key --- Sources/2.0 API/ServiceEntry.swift | 30 ++++++++++++++++++------------ Sources/Core/Scope.swift | 3 +++ Tests/Support/GeneratedMocks.swift | 5 +++++ 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/Sources/2.0 API/ServiceEntry.swift b/Sources/2.0 API/ServiceEntry.swift index 33287ef8..4180c259 100644 --- a/Sources/2.0 API/ServiceEntry.swift +++ b/Sources/2.0 API/ServiceEntry.swift @@ -6,7 +6,8 @@ /// As a returned instance from a `register` method of a `Container`, some configurations can be added. public class ServiceEntry { let builder: (Resolver, Any, Any) -> Service - var key: AnyBindingKey + let argumentType: Any.Type + let name: String? var scope: AnyScope? var finalizers = [(Resolver, Service) -> Void]() @@ -16,17 +17,8 @@ public class ServiceEntry { builder: @escaping (Resolver, Any, Argument) -> Service ) { self.builder = { builder($0, $1, $2 as! Argument) } - self.key = BindingKey( - descriptor: { - if let name = name { - return tagged(Service.self, with: name) - } else { - return plain(Service.self) - } - }(), - contextType: Any.self, - argumentType: Argument.self - ) + self.argumentType = Argument.self + self.name = name self.scope = scope } @@ -84,4 +76,18 @@ extension ServiceEntry: Binding { return builder(resolver, context, arg) } } + + private var key: BindingKey { + BindingKey( + descriptor: { + if let name = name { + return tagged(Service.self, with: name) + } else { + return plain(Service.self) + } + }(), + contextType: scope?.contextType ?? Any.self, + argumentType: argumentType + ) + } } diff --git a/Sources/Core/Scope.swift b/Sources/Core/Scope.swift index 614a4898..603cfdc2 100644 --- a/Sources/Core/Scope.swift +++ b/Sources/Core/Scope.swift @@ -4,6 +4,7 @@ // sourcery: AutoMockable public protocol AnyScope { + var contextType: Any.Type { get } func registry(for context: Any) -> ScopeRegistry } @@ -13,6 +14,8 @@ public protocol Scope: AnyScope { } extension Scope { + public var contextType: Any.Type { return Context.self } + func registry(for context: Any) -> ScopeRegistry { registry(for: context as! Context) } diff --git a/Tests/Support/GeneratedMocks.swift b/Tests/Support/GeneratedMocks.swift index 70aa8eac..25bd6e9f 100644 --- a/Tests/Support/GeneratedMocks.swift +++ b/Tests/Support/GeneratedMocks.swift @@ -163,6 +163,11 @@ class AnyResolverMock: AnyResolver { } class AnyScopeMock: AnyScope { + var contextType: Any.Type { + get { return underlyingContextType } + set(value) { underlyingContextType = value } + } + var underlyingContextType: Any.Type! //MARK: - registry From b056ed8cae542ed665957003db0ada5c3dc42384 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Tue, 23 Jul 2019 00:33:53 +0200 Subject: [PATCH 109/239] Implement container object scope --- Sources/2.0 API/Container.swift | 10 +-- Sources/2.0 API/ObjectScope.swift | 19 +++-- Tests/2.0 API/ContainerSpec.swift | 111 +++++++++++++++--------------- 3 files changed, 75 insertions(+), 65 deletions(-) diff --git a/Sources/2.0 API/Container.swift b/Sources/2.0 API/Container.swift index 29b716e8..682bc14a 100644 --- a/Sources/2.0 API/Container.swift +++ b/Sources/2.0 API/Container.swift @@ -25,9 +25,11 @@ public final class Container { let defaultScope: AnyScope? var bindings = [Binding]() var behaviors = [Behavior]() - var swinject: Swinject { - Swinject(tree: SwinjectTree(bindings: allBindings, includeEntries: [], translators: [])) - } + var swinject: Swinject { Swinject(tree: SwinjectTree( + bindings: allBindings, + includeEntries: [], + translators: [registerContextTranslator(from: Graph.self) { $0.container }] + )) } var allBindings: [Binding] { return bindings + (parent?.allBindings ?? []) } @@ -111,6 +113,6 @@ extension Container: Resolver { public func resolve( _ request: InstanceRequest ) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { - try swinject.on(Graph()).resolve(request) + try swinject.on(Graph(on: self)).resolve(request) } } diff --git a/Sources/2.0 API/ObjectScope.swift b/Sources/2.0 API/ObjectScope.swift index a5d8daca..47bd0328 100644 --- a/Sources/2.0 API/ObjectScope.swift +++ b/Sources/2.0 API/ObjectScope.swift @@ -26,18 +26,19 @@ extension ObjectScope { var scope: AnyScope? { switch self { case .graph: return GraphScope.shared - case .container: return UnboundScope.container + case .container: return ContainerScope.shared default: return nil } } } -extension UnboundScope { - static let container = UnboundScope() -} - final class Graph { let registry = StandardScopeRegistry() + let container: Container + + init(on container: Container) { + self.container = container + } } final class GraphScope: Scope { @@ -47,3 +48,11 @@ final class GraphScope: Scope { return graph.registry } } + +final class ContainerScope: Scope { + static let shared = ContainerScope() + + func registry(for container: Container) -> ScopeRegistry { + container.registry + } +} diff --git a/Tests/2.0 API/ContainerSpec.swift b/Tests/2.0 API/ContainerSpec.swift index 8f426380..711b6d5e 100644 --- a/Tests/2.0 API/ContainerSpec.swift +++ b/Tests/2.0 API/ContainerSpec.swift @@ -285,62 +285,61 @@ class ContainerSpec: QuickSpec { expect(owner?.pet).notTo(beNil()) } } - // TODO: Implement context translation -// describe("Value type resolution") { -// it("resolves struct instances ignoring object scopes.") { -// let runInObjectScope: (ObjectScope) -> Void = { scope in -// container.removeAll() -// container.register(Animal.self) { _ in Turtle(name: "Ninja") } -// .inObjectScope(scope) -// var turtle1 = container.resolve(Animal.self)! -// let turtle2 = container.resolve(Animal.self)! -// turtle1.name = "Samurai" -// expect(turtle1.name) == "Samurai" -// expect(turtle2.name) == "Ninja" -// } -// -// runInObjectScope(.transient) -// runInObjectScope(.graph) -// runInObjectScope(.container) -// } -// it("resolves struct instances defined in the parent container ignoring object scopes.") { -// let runInObjectScope: (ObjectScope) -> Void = { scope in -// container.removeAll() -// container.register(Animal.self) { _ in Turtle(name: "Ninja") } -// .inObjectScope(scope) -// let childContainer = Container(parent: container) -// -// var turtle1 = childContainer.resolve(Animal.self)! -// let turtle2 = childContainer.resolve(Animal.self)! -// turtle1.name = "Samurai" -// expect(turtle1.name) == "Samurai" -// expect(turtle2.name) == "Ninja" -// } -// -// runInObjectScope(.transient) -// runInObjectScope(.graph) -// runInObjectScope(.container) -// } -// context("object scope is container or hierarchy") { -// it("resolves only once to simulate singleton (instantiation only once).") { -// let runInObjectScope: (ObjectScope, Int) -> Void = { scope, expectation in -// var invokedCount = 0 -// container.removeAll() -// container.register(Animal.self) { _ in -// invokedCount += 1 -// return Turtle(name: "Ninja") -// }.inObjectScope(scope) -// _ = container.resolve(Animal.self)! -// _ = container.resolve(Animal.self)! -// expect(invokedCount) == expectation -// } -// -// runInObjectScope(.transient, 2) -// runInObjectScope(.graph, 2) -// runInObjectScope(.container, 1) -// } -// } -// } + describe("Value type resolution") { + it("resolves struct instances ignoring object scopes.") { + let runInObjectScope: (ObjectScope) -> Void = { scope in + container.removeAll() + container.register(Animal.self) { _ in Turtle(name: "Ninja") } + .inObjectScope(scope) + var turtle1 = container.resolve(Animal.self)! + let turtle2 = container.resolve(Animal.self)! + turtle1.name = "Samurai" + expect(turtle1.name) == "Samurai" + expect(turtle2.name) == "Ninja" + } + + runInObjectScope(.transient) + runInObjectScope(.graph) + runInObjectScope(.container) + } + it("resolves struct instances defined in the parent container ignoring object scopes.") { + let runInObjectScope: (ObjectScope) -> Void = { scope in + container.removeAll() + container.register(Animal.self) { _ in Turtle(name: "Ninja") } + .inObjectScope(scope) + let childContainer = Container(parent: container) + + var turtle1 = childContainer.resolve(Animal.self)! + let turtle2 = childContainer.resolve(Animal.self)! + turtle1.name = "Samurai" + expect(turtle1.name) == "Samurai" + expect(turtle2.name) == "Ninja" + } + + runInObjectScope(.transient) + runInObjectScope(.graph) + runInObjectScope(.container) + } + context("object scope is container or hierarchy") { + it("resolves only once to simulate singleton (instantiation only once).") { + let runInObjectScope: (ObjectScope, Int) -> Void = { scope, expectation in + var invokedCount = 0 + container.removeAll() + container.register(Animal.self) { _ in + invokedCount += 1 + return Turtle(name: "Ninja") + }.inObjectScope(scope) + _ = container.resolve(Animal.self)! + _ = container.resolve(Animal.self)! + expect(invokedCount) == expectation + } + + runInObjectScope(.transient, 2) + runInObjectScope(.graph, 2) + runInObjectScope(.container, 1) + } + } + } describe("Class as a service type") { it("resolves a registred subclass of a service type class.") { container.register(Cat.self) { _ in Siamese(name: "Siam") } From 3241356c024d7e35d8418f5fde721400650c8456 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Tue, 23 Jul 2019 00:37:54 +0200 Subject: [PATCH 110/239] FIx codestyle violations --- Sources/2.0 API/Container.swift | 4 ++-- Sources/2.0 API/ServiceEntry.swift | 4 ++-- Sources/Core/ContextTranslator.swift | 2 +- Sources/Core/Scope.swift | 2 +- Sources/Core/Swinject.swift | 2 +- Tests/Unit Specs/SwinjectSpec.swift | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Sources/2.0 API/Container.swift b/Sources/2.0 API/Container.swift index 682bc14a..f330a3c5 100644 --- a/Sources/2.0 API/Container.swift +++ b/Sources/2.0 API/Container.swift @@ -51,9 +51,9 @@ public final class Container { registeringClosure: (Container) -> Void = { _ in } ) { self.parent = parent - self.defaultScope = defaultObjectScope.scope + defaultScope = defaultObjectScope.scope self.behaviors = behaviors - self.registry = parent?.registry ?? StandardScopeRegistry() + registry = parent?.registry ?? StandardScopeRegistry() registeringClosure(self) } diff --git a/Sources/2.0 API/ServiceEntry.swift b/Sources/2.0 API/ServiceEntry.swift index 4180c259..a3ba17ad 100644 --- a/Sources/2.0 API/ServiceEntry.swift +++ b/Sources/2.0 API/ServiceEntry.swift @@ -17,7 +17,7 @@ public class ServiceEntry { builder: @escaping (Resolver, Any, Argument) -> Service ) { self.builder = { builder($0, $1, $2 as! Argument) } - self.argumentType = Argument.self + argumentType = Argument.self self.name = name self.scope = scope } @@ -42,7 +42,7 @@ public class ServiceEntry { /// - Returns: `self` to add another configuration fluently. @discardableResult public func inObjectScope(_ objectScope: ObjectScope) -> Self { - self.scope = objectScope.scope + scope = objectScope.scope return self } diff --git a/Sources/Core/ContextTranslator.swift b/Sources/Core/ContextTranslator.swift index 168e3e85..2954ebfe 100644 --- a/Sources/Core/ContextTranslator.swift +++ b/Sources/Core/ContextTranslator.swift @@ -1,5 +1,5 @@ // -// Created by Jakub Vaňo on 22/07/2019. +// Copyright © 2019 Swinject Contributors. All rights reserved. // // sourcery: AutoMockable diff --git a/Sources/Core/Scope.swift b/Sources/Core/Scope.swift index 603cfdc2..060a4b3f 100644 --- a/Sources/Core/Scope.swift +++ b/Sources/Core/Scope.swift @@ -15,7 +15,7 @@ public protocol Scope: AnyScope { extension Scope { public var contextType: Any.Type { return Context.self } - + func registry(for context: Any) -> ScopeRegistry { registry(for: context as! Context) } diff --git a/Sources/Core/Swinject.swift b/Sources/Core/Swinject.swift index 5a79cfa4..5e2a4672 100644 --- a/Sources/Core/Swinject.swift +++ b/Sources/Core/Swinject.swift @@ -14,7 +14,7 @@ public struct Swinject { init(tree: SwinjectTree, context: Context) { self.tree = tree self.context = context - self.contextType = Context.self + contextType = Context.self } } diff --git a/Tests/Unit Specs/SwinjectSpec.swift b/Tests/Unit Specs/SwinjectSpec.swift index a1688eae..3f5ec8dc 100644 --- a/Tests/Unit Specs/SwinjectSpec.swift +++ b/Tests/Unit Specs/SwinjectSpec.swift @@ -252,7 +252,7 @@ class SwinjectSpec: QuickSpec { override func spec() { var translators = [AnyContextTranslatorMock]() var bindings = [BindingMock]() beforeEach { - translators = (1...3).map { _ in AnyContextTranslatorMock() } + translators = (1 ... 3).map { _ in AnyContextTranslatorMock() } translators.forEach { $0.sourceType = Void.self $0.targetType = Void.self @@ -319,7 +319,7 @@ class SwinjectSpec: QuickSpec { override func spec() { } it("does not throw if single binding can be used with multiple translated contexts") { bindings[0].matchesReturnValue = true - translators[1...2].forEach { + translators[1 ... 2].forEach { $0.sourceType = String.self $0.targetType = Int.self $0.translateReturnValue = 0 From efbd5d2e777ac33b1f951197cc9b878c100ec630 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Tue, 23 Jul 2019 22:16:36 +0200 Subject: [PATCH 111/239] Implement type forwarding --- .../2.0 API/Container+TypeForwarding.swift | 2 +- .../2.0 API/ServiceEntry+TypeForwarding.swift | 6 +- Sources/2.0 API/ServiceEntry.swift | 6 +- .../ServiceEntry+TypeForwarding.swifttemplate | 6 +- .../ContainerSpec.TypeForwarding.swift | 323 +++++++++--------- 5 files changed, 177 insertions(+), 166 deletions(-) diff --git a/Sources/2.0 API/Container+TypeForwarding.swift b/Sources/2.0 API/Container+TypeForwarding.swift index 73e1c2a9..8eff6a21 100644 --- a/Sources/2.0 API/Container+TypeForwarding.swift +++ b/Sources/2.0 API/Container+TypeForwarding.swift @@ -19,6 +19,6 @@ extension Container { /// - name: A registration name, which is used to differentiate from other registrations of the same `type` /// - service: ServiceEntry which should be used for resolution of `type` public func forward(_ type: T.Type, name: String? = nil, to service: ServiceEntry) { - fatalError() + service.implements(type, name: name) } } diff --git a/Sources/2.0 API/ServiceEntry+TypeForwarding.swift b/Sources/2.0 API/ServiceEntry+TypeForwarding.swift index 25c73294..413a65e4 100644 --- a/Sources/2.0 API/ServiceEntry+TypeForwarding.swift +++ b/Sources/2.0 API/ServiceEntry+TypeForwarding.swift @@ -12,7 +12,11 @@ extension ServiceEntry { /// - name: A registration name, which is used to differentiate from other registrations of the same `type` @discardableResult public func implements(_ type: T.Type, name: String? = nil) -> ServiceEntry { - fatalError() + if let name = name { + forwardedDescriptors.append(tagged(type, with: name)) + } else { + forwardedDescriptors.append(plain(type)) + } return self } diff --git a/Sources/2.0 API/ServiceEntry.swift b/Sources/2.0 API/ServiceEntry.swift index a3ba17ad..240e29ab 100644 --- a/Sources/2.0 API/ServiceEntry.swift +++ b/Sources/2.0 API/ServiceEntry.swift @@ -10,6 +10,7 @@ public class ServiceEntry { let name: String? var scope: AnyScope? var finalizers = [(Resolver, Service) -> Void]() + var forwardedDescriptors = [AnyTypeDescriptor]() init( name: String?, @@ -62,7 +63,10 @@ public class ServiceEntry { extension ServiceEntry: Binding { public func matches(_ key: AnyBindingKey) -> Bool { - self.key.matches(key) + let forwardedKeys = forwardedDescriptors.map { + BindingKey(descriptor: $0, contextType: scope?.contextType ?? Any.self, argumentType: argumentType) + } + return ([self.key] + forwardedKeys).contains { $0.matches(key) } } public func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any { diff --git a/Templates/ServiceEntry+TypeForwarding.swifttemplate b/Templates/ServiceEntry+TypeForwarding.swifttemplate index 587a4018..9489c742 100644 --- a/Templates/ServiceEntry+TypeForwarding.swifttemplate +++ b/Templates/ServiceEntry+TypeForwarding.swifttemplate @@ -9,7 +9,11 @@ extension ServiceEntry { /// - name: A registration name, which is used to differentiate from other registrations of the same `type` @discardableResult public func implements(_ type: T.Type, name: String? = nil) -> ServiceEntry { - fatalError() + if let name = name { + forwardedDescriptors.append(tagged(type, with: name)) + } else { + forwardedDescriptors.append(plain(type)) + } return self } diff --git a/Tests/2.0 API/ContainerSpec.TypeForwarding.swift b/Tests/2.0 API/ContainerSpec.TypeForwarding.swift index de6a2e5e..861ccd43 100644 --- a/Tests/2.0 API/ContainerSpec.TypeForwarding.swift +++ b/Tests/2.0 API/ContainerSpec.TypeForwarding.swift @@ -2,165 +2,164 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -// TODO: Implement type forwaring -//import Nimble -//import Quick -//@testable import Swinject -// -//class ContainerSpec_TypeForwarding: QuickSpec { -// override func spec() { -// var container: Container! -// beforeEach { -// container = Container() -// } -// -// describe("container method") { -// it("resolves forwarded type") { -// let service = container.register(Dog.self) { _ in Dog() } -// container.forward(Animal.self, to: service) -// -// let animal = container.resolve(Animal.self) -// -// expect(animal).notTo(beNil()) -// } -// it("resolves forwarded type with arguments") { -// let service = container.register(Cat.self) { _, name, sleeping in -// Cat(name: name, sleeping: sleeping) -// } -// container.forward(Animal.self, to: service) -// -// let animal = container.resolve(Animal.self, arguments: "Mimi", true) as? Cat -// -// expect(animal?.name) == "Mimi" -// expect(animal?.sleeping).to(beTrue()) -// } -// it("resolves forwarded type given correct name") { -// let service = container.register(Dog.self) { _ in Dog() } -// container.forward(Animal.self, name: "Hachi", to: service) -// -// let animal = container.resolve(Animal.self, name: "Hachi") -// -// expect(animal).notTo(beNil()) -// } -// it("does not resolve forwarded type given incorrect name") { -// let service = container.register(Dog.self) { _ in Dog() } -// container.forward(Animal.self, name: "Hachi", to: service) -// -// let animal = container.resolve(Animal.self, name: "Mimi") -// -// expect(animal).to(beNil()) -// } -// it("does not resolve when forwarding incompatible types") { -// let service = container.register(Dog.self) { _ in Dog() } -// container.forward(Cat.self, to: service) -// -// let cat = container.resolve(Cat.self) -// -// expect(cat).to(beNil()) -// } -// it("does not resolve when forwarding incompatible types with arguments") { -// let service = container.register(Dog.self) { (_, _: String) in Dog() } -// container.forward(Cat.self, to: service) -// -// let cat = container.resolve(Cat.self, argument: "") -// -// expect(cat).to(beNil()) -// } -// it("resolves forwarded type even if only implementation type conforms to it") { -// let service = container.register(Animal.self) { _ in Dog() } -// container.forward(Dog.self, to: service) -// let dog = container.resolve(Dog.self) -// expect(dog).notTo(beNil()) -// } -// } -// describe("service entry method") { -// it("resolves forwarded type") { -// container.register(Dog.self) { _ in Dog() } -// .implements(Animal.self) -// -// let animal = container.resolve(Animal.self) -// -// expect(animal).notTo(beNil()) -// } -// it("suports multiple forwarding definitions") { -// container.register(Dog.self) { _ in Dog() } -// .implements(DogProtocol1.self) -// .implements(DogProtocol2.self) -// .implements(DogProtocol3.self) -// -// let dog1 = container.resolve(DogProtocol1.self) -// let dog2 = container.resolve(DogProtocol2.self) -// let dog3 = container.resolve(DogProtocol3.self) -// -// expect(dog1).notTo(beNil()) -// expect(dog2).notTo(beNil()) -// expect(dog3).notTo(beNil()) -// } -// it("resolves forwarded types only when correct name is given") { -// container.register(Dog.self) { _ in Dog() } -// .implements(DogProtocol1.self, name: "1") -// .implements(DogProtocol2.self, name: "2") -// .implements(DogProtocol3.self, name: "3") -// -// let dog1 = container.resolve(DogProtocol1.self, name: "1") -// let dog2 = container.resolve(DogProtocol2.self) -// let dog3 = container.resolve(DogProtocol3.self, name: "2") -// -// expect(dog1).notTo(beNil()) -// expect(dog2).to(beNil()) -// expect(dog3).to(beNil()) -// } -// it("supports defining multiple types at once") { -// container.register(Dog.self) { _ in Dog() } -// .implements(DogProtocol1.self, DogProtocol2.self, DogProtocol3.self) -// -// let dog1 = container.resolve(DogProtocol1.self) -// let dog2 = container.resolve(DogProtocol2.self) -// let dog3 = container.resolve(DogProtocol3.self) -// -// expect(dog1).notTo(beNil()) -// expect(dog2).notTo(beNil()) -// expect(dog3).notTo(beNil()) -// } -// } -// describe("Optional resolving") { -// it("resolves optional when wrapped type is registered") { -// container.register(Dog.self) { _ in Dog() } -// let optionalDog = container.resolve(Dog?.self) -// expect(optionalDog ?? nil).notTo(beNil()) -// } -// it("resolves optional to nil when wrapped type is not registered") { -// let optionalDog = container.resolve(Dog?.self) -// expect(optionalDog).notTo(beNil()) -// } -// it("resolves optional with name") { -// container.register(Dog.self, name: "Hachi") { _ in Dog() } -// let optionalDog = container.resolve(Dog?.self, name: "Hachi") -// expect(optionalDog ?? nil).notTo(beNil()) -// } -// it("resolves optional to nil with wrong name") { -// container.register(Dog.self, name: "Hachi") { _ in Dog() } -// let optionalDog = container.resolve(Dog?.self, name: "Mimi") -// expect(optionalDog ?? nil).to(beNil()) -// expect(optionalDog).notTo(beNil()) -// } -// it("resolves optional with arguments") { -// container.register(Dog.self) { _, name in Dog(name: name) } -// let optionalDog = container.resolve(Dog?.self, argument: "Hachi") -// expect(optionalDog ?? nil).notTo(beNil()) -// } -// it("resolves optional of fowrarded type") { -// container.register(Dog.self) { _ in Dog() }.implements(Animal.self) -// let optionalAnimal = container.resolve(Animal?.self) -// let unwrappedAnimal = container.resolve(Animal?.self) -// expect(optionalAnimal ?? nil).notTo(beNil()) -// expect(unwrappedAnimal ?? nil).notTo(beNil()) -// } -// } -// } -//} -// -//private protocol DogProtocol1 {} -//private protocol DogProtocol2 {} -//private protocol DogProtocol3 {} -//extension Dog: DogProtocol1, DogProtocol2, DogProtocol3 {} +import Nimble +import Quick +@testable import Swinject + +class ContainerSpec_TypeForwarding: QuickSpec { + override func spec() { + var container: Container! + beforeEach { + container = Container() + } + + describe("container method") { + it("resolves forwarded type") { + let service = container.register(Dog.self) { _ in Dog() } + container.forward(Animal.self, to: service) + + let animal = container.resolve(Animal.self) + + expect(animal).notTo(beNil()) + } + it("resolves forwarded type with arguments") { + let service = container.register(Cat.self) { _, name, sleeping in + Cat(name: name, sleeping: sleeping) + } + container.forward(Animal.self, to: service) + + let animal = container.resolve(Animal.self, arguments: "Mimi", true) as? Cat + + expect(animal?.name) == "Mimi" + expect(animal?.sleeping).to(beTrue()) + } + it("resolves forwarded type given correct name") { + let service = container.register(Dog.self) { _ in Dog() } + container.forward(Animal.self, name: "Hachi", to: service) + + let animal = container.resolve(Animal.self, name: "Hachi") + + expect(animal).notTo(beNil()) + } + it("does not resolve forwarded type given incorrect name") { + let service = container.register(Dog.self) { _ in Dog() } + container.forward(Animal.self, name: "Hachi", to: service) + + let animal = container.resolve(Animal.self, name: "Mimi") + + expect(animal).to(beNil()) + } + it("does not resolve when forwarding incompatible types") { + let service = container.register(Dog.self) { _ in Dog() } + container.forward(Cat.self, to: service) + + let cat = container.resolve(Cat.self) + + expect(cat).to(beNil()) + } + it("does not resolve when forwarding incompatible types with arguments") { + let service = container.register(Dog.self) { (_, _: String) in Dog() } + container.forward(Cat.self, to: service) + + let cat = container.resolve(Cat.self, argument: "") + + expect(cat).to(beNil()) + } + it("resolves forwarded type even if only implementation type conforms to it") { + let service = container.register(Animal.self) { _ in Dog() } + container.forward(Dog.self, to: service) + let dog = container.resolve(Dog.self) + expect(dog).notTo(beNil()) + } + } + describe("service entry method") { + it("resolves forwarded type") { + container.register(Dog.self) { _ in Dog() } + .implements(Animal.self) + + let animal = container.resolve(Animal.self) + + expect(animal).notTo(beNil()) + } + it("suports multiple forwarding definitions") { + container.register(Dog.self) { _ in Dog() } + .implements(DogProtocol1.self) + .implements(DogProtocol2.self) + .implements(DogProtocol3.self) + + let dog1 = container.resolve(DogProtocol1.self) + let dog2 = container.resolve(DogProtocol2.self) + let dog3 = container.resolve(DogProtocol3.self) + + expect(dog1).notTo(beNil()) + expect(dog2).notTo(beNil()) + expect(dog3).notTo(beNil()) + } + it("resolves forwarded types only when correct name is given") { + container.register(Dog.self) { _ in Dog() } + .implements(DogProtocol1.self, name: "1") + .implements(DogProtocol2.self, name: "2") + .implements(DogProtocol3.self, name: "3") + + let dog1 = container.resolve(DogProtocol1.self, name: "1") + let dog2 = container.resolve(DogProtocol2.self) + let dog3 = container.resolve(DogProtocol3.self, name: "2") + + expect(dog1).notTo(beNil()) + expect(dog2).to(beNil()) + expect(dog3).to(beNil()) + } + it("supports defining multiple types at once") { + container.register(Dog.self) { _ in Dog() } + .implements(DogProtocol1.self, DogProtocol2.self, DogProtocol3.self) + + let dog1 = container.resolve(DogProtocol1.self) + let dog2 = container.resolve(DogProtocol2.self) + let dog3 = container.resolve(DogProtocol3.self) + + expect(dog1).notTo(beNil()) + expect(dog2).notTo(beNil()) + expect(dog3).notTo(beNil()) + } + } + describe("Optional resolving") { + it("resolves optional when wrapped type is registered") { + container.register(Dog.self) { _ in Dog() } + let optionalDog = container.resolve(Dog?.self) + expect(optionalDog ?? nil).notTo(beNil()) + } + it("resolves optional to nil when wrapped type is not registered") { + let optionalDog = container.resolve(Dog?.self) + expect(optionalDog).notTo(beNil()) + } + it("resolves optional with name") { + container.register(Dog.self, name: "Hachi") { _ in Dog() } + let optionalDog = container.resolve(Dog?.self, name: "Hachi") + expect(optionalDog ?? nil).notTo(beNil()) + } + it("resolves optional to nil with wrong name") { + container.register(Dog.self, name: "Hachi") { _ in Dog() } + let optionalDog = container.resolve(Dog?.self, name: "Mimi") + expect(optionalDog ?? nil).to(beNil()) + expect(optionalDog).notTo(beNil()) + } + it("resolves optional with arguments") { + container.register(Dog.self) { _, name in Dog(name: name) } + let optionalDog = container.resolve(Dog?.self, argument: "Hachi") + expect(optionalDog ?? nil).notTo(beNil()) + } + it("resolves optional of fowrarded type") { + container.register(Dog.self) { _ in Dog() }.implements(Animal.self) + let optionalAnimal = container.resolve(Animal?.self) + let unwrappedAnimal = container.resolve(Animal?.self) + expect(optionalAnimal ?? nil).notTo(beNil()) + expect(unwrappedAnimal ?? nil).notTo(beNil()) + } + } + } +} + +private protocol DogProtocol1 {} +private protocol DogProtocol2 {} +private protocol DogProtocol3 {} +extension Dog: DogProtocol1, DogProtocol2, DogProtocol3 {} From ff5d99da63cf29f277a8c4edf602b56b19e776fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Tue, 23 Jul 2019 22:18:07 +0200 Subject: [PATCH 112/239] Support double optional injection --- Sources/Core/TypeDescriptor.swift | 9 ++++++++- Tests/Unit Specs/TaggedTypeSpec.swift | 10 ++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Sources/Core/TypeDescriptor.swift b/Sources/Core/TypeDescriptor.swift index 19d4a63b..1abf5bb0 100644 --- a/Sources/Core/TypeDescriptor.swift +++ b/Sources/Core/TypeDescriptor.swift @@ -21,6 +21,9 @@ public struct Tagged: TypeDescriptor where Tag: Hashable { if let other = other as? Tagged { return tag == other.tag } + if let other = other as? Tagged { + return tag == other.tag + } return false } @@ -30,7 +33,11 @@ public struct Tagged: TypeDescriptor where Tag: Hashable { private var hashedType: Any.Type { if let optional = BaseType.self as? OptionalProtocol.Type { - return optional.wrappedType + if let doubleOptional = optional.wrappedType as? OptionalProtocol.Type { + return doubleOptional.wrappedType + } else { + return optional.wrappedType + } } else { return BaseType.self } diff --git a/Tests/Unit Specs/TaggedTypeSpec.swift b/Tests/Unit Specs/TaggedTypeSpec.swift index 3e461c9c..0cbfafca 100644 --- a/Tests/Unit Specs/TaggedTypeSpec.swift +++ b/Tests/Unit Specs/TaggedTypeSpec.swift @@ -28,6 +28,11 @@ class TaggedTypeSpec: QuickSpec { override func spec() { let second = plain(Int?.self) expect(first.hashValue) == second.hashValue } + it("is same for the type and it's double optional") { + let first = plain(Int.self) + let second = plain(Int??.self) + expect(first.hashValue) == second.hashValue + } } describe("matches") { it("doesn't match if base type is different") { @@ -50,5 +55,10 @@ class TaggedTypeSpec: QuickSpec { override func spec() { let second = plain(Int?.self) expect(first.matches(second)) == true } + it("matches if second type is double optional of first type") { + let first = plain(Int.self) + let second = plain(Int??.self) + expect(first.matches(second)) == true + } } } } From cb9cbb4a13bac8cf770b7184d5863ccd38e95636 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Tue, 23 Jul 2019 22:51:26 +0200 Subject: [PATCH 113/239] Implement optional resolution --- Sources/2.0 API/Resolver+LegacyApi.swift | 40 +++++++++++----------- Sources/Core/Swinject.swift | 17 ++++++--- Sources/Core/SwinjectError.swift | 5 ++- Sources/Core/TypeDescriptor.swift | 2 ++ Templates/Resolver+LegacyApi.swifttemplate | 8 ++--- Tests/Unit Specs/SwinjectSpec.swift | 31 +++++++++++++---- 6 files changed, 67 insertions(+), 36 deletions(-) diff --git a/Sources/2.0 API/Resolver+LegacyApi.swift b/Sources/2.0 API/Resolver+LegacyApi.swift index 23c07e7b..fb04aa72 100644 --- a/Sources/2.0 API/Resolver+LegacyApi.swift +++ b/Sources/2.0 API/Resolver+LegacyApi.swift @@ -13,9 +13,9 @@ public extension Resolver { /// - Returns: The resolved service type instance, or nil if no service with the name is found. func resolve(_ serviceType: Service.Type, name: String? = nil) -> Service? { if let name = name { - return try? resolve(request(tag: name, arg: ())) + return try? resolve(request(type: serviceType, tag: name, arg: ())) } else { - return try? resolve(request(tag: NoTag(), arg: ())) + return try? resolve(request(type: serviceType, tag: NoTag(), arg: ())) } } @@ -30,9 +30,9 @@ public extension Resolver { /// 1 argument and name is found. func resolve(_ serviceType: Service.Type, name: String? = nil, argument: Arg1) -> Service? { if let name = name { - return try? resolve(request(tag: name, arg: ())) + return try? resolve(request(type: serviceType, tag: name, arg: ())) } else { - return try? resolve(request(tag: NoTag(), arg: argument)) + return try? resolve(request(type: serviceType, tag: NoTag(), arg: argument)) } } @@ -47,9 +47,9 @@ public extension Resolver { /// list of 2 arguments and name is found. func resolve(_ serviceType: Service.Type, name: String? = nil, arguments arg1: Arg1, _ arg2: Arg2) -> Service? { if let name = name { - return try? resolve(request(tag: name, arg: ())) + return try? resolve(request(type: serviceType, tag: name, arg: ())) } else { - return try? resolve(request(tag: NoTag(), arg: (arg1, arg2))) + return try? resolve(request(type: serviceType, tag: NoTag(), arg: (arg1, arg2))) } } @@ -64,9 +64,9 @@ public extension Resolver { /// list of 3 arguments and name is found. func resolve(_ serviceType: Service.Type, name: String? = nil, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> Service? { if let name = name { - return try? resolve(request(tag: name, arg: ())) + return try? resolve(request(type: serviceType, tag: name, arg: ())) } else { - return try? resolve(request(tag: NoTag(), arg: (arg1, arg2, arg3))) + return try? resolve(request(type: serviceType, tag: NoTag(), arg: (arg1, arg2, arg3))) } } @@ -81,9 +81,9 @@ public extension Resolver { /// list of 4 arguments and name is found. func resolve(_ serviceType: Service.Type, name: String? = nil, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> Service? { if let name = name { - return try? resolve(request(tag: name, arg: ())) + return try? resolve(request(type: serviceType, tag: name, arg: ())) } else { - return try? resolve(request(tag: NoTag(), arg: (arg1, arg2, arg3, arg4))) + return try? resolve(request(type: serviceType, tag: NoTag(), arg: (arg1, arg2, arg3, arg4))) } } @@ -98,9 +98,9 @@ public extension Resolver { /// list of 5 arguments and name is found. func resolve(_ serviceType: Service.Type, name: String? = nil, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> Service? { if let name = name { - return try? resolve(request(tag: name, arg: ())) + return try? resolve(request(type: serviceType, tag: name, arg: ())) } else { - return try? resolve(request(tag: NoTag(), arg: (arg1, arg2, arg3, arg4, arg5))) + return try? resolve(request(type: serviceType, tag: NoTag(), arg: (arg1, arg2, arg3, arg4, arg5))) } } @@ -115,9 +115,9 @@ public extension Resolver { /// list of 6 arguments and name is found. func resolve(_ serviceType: Service.Type, name: String? = nil, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6) -> Service? { if let name = name { - return try? resolve(request(tag: name, arg: ())) + return try? resolve(request(type: serviceType, tag: name, arg: ())) } else { - return try? resolve(request(tag: NoTag(), arg: (arg1, arg2, arg3, arg4, arg5, arg6))) + return try? resolve(request(type: serviceType, tag: NoTag(), arg: (arg1, arg2, arg3, arg4, arg5, arg6))) } } @@ -132,9 +132,9 @@ public extension Resolver { /// list of 7 arguments and name is found. func resolve(_ serviceType: Service.Type, name: String? = nil, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7) -> Service? { if let name = name { - return try? resolve(request(tag: name, arg: ())) + return try? resolve(request(type: serviceType, tag: name, arg: ())) } else { - return try? resolve(request(tag: NoTag(), arg: (arg1, arg2, arg3, arg4, arg5, arg6, arg7))) + return try? resolve(request(type: serviceType, tag: NoTag(), arg: (arg1, arg2, arg3, arg4, arg5, arg6, arg7))) } } @@ -149,9 +149,9 @@ public extension Resolver { /// list of 8 arguments and name is found. func resolve(_ serviceType: Service.Type, name: String? = nil, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8) -> Service? { if let name = name { - return try? resolve(request(tag: name, arg: ())) + return try? resolve(request(type: serviceType, tag: name, arg: ())) } else { - return try? resolve(request(tag: NoTag(), arg: (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8))) + return try? resolve(request(type: serviceType, tag: NoTag(), arg: (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8))) } } @@ -166,9 +166,9 @@ public extension Resolver { /// list of 9 arguments and name is found. func resolve(_ serviceType: Service.Type, name: String? = nil, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8, _ arg9: Arg9) -> Service? { if let name = name { - return try? resolve(request(tag: name, arg: ())) + return try? resolve(request(type: serviceType, tag: name, arg: ())) } else { - return try? resolve(request(tag: NoTag(), arg: (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9))) + return try? resolve(request(type: serviceType, tag: NoTag(), arg: (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9))) } } diff --git a/Sources/Core/Swinject.swift b/Sources/Core/Swinject.swift index 5e2a4672..8cbd47ac 100644 --- a/Sources/Core/Swinject.swift +++ b/Sources/Core/Swinject.swift @@ -33,9 +33,17 @@ extension Swinject: Resolver { public func resolve( _ request: InstanceRequest ) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { - let binding = try findBinding(for: request) - let translator = try findTranslator(for: request, and: binding) - return try instance(from: binding, context: translator.translate(context), arg: request.argument) + do { + let binding = try findBinding(for: request) + let translator = try findTranslator(for: request, and: binding) + return try instance(from: binding, context: translator.translate(context), arg: request.argument) + } catch let error as NoBindingError { + if let optional = Descriptor.BaseType.self as? OptionalProtocol.Type { + return optional.init() as! Descriptor.BaseType + } else { + throw error + } + } } private func findTranslator(for request: AnyInstanceRequest, and binding: Binding) throws -> AnyContextTranslator { @@ -47,7 +55,8 @@ extension Swinject: Resolver { private func findBinding(for request: AnyInstanceRequest) throws -> Binding { let bindings = tree.bindings.filter { (try? findTranslator(for: request, and: $0)) != nil } - guard bindings.count == 1 else { throw SwinjectError() } + if bindings.isEmpty { throw NoBindingError() } + if bindings.count > 1 { throw MultipleBindingsError() } return bindings[0] } diff --git a/Sources/Core/SwinjectError.swift b/Sources/Core/SwinjectError.swift index ee16c729..45adbe87 100644 --- a/Sources/Core/SwinjectError.swift +++ b/Sources/Core/SwinjectError.swift @@ -2,7 +2,7 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -public struct SwinjectError: Error { +public class SwinjectError: Error { let file: String let line: Int @@ -12,4 +12,7 @@ public struct SwinjectError: Error { } } +public class NoBindingError: SwinjectError {} +public class MultipleBindingsError: SwinjectError {} + // TODO: Debugging error description diff --git a/Sources/Core/TypeDescriptor.swift b/Sources/Core/TypeDescriptor.swift index 1abf5bb0..ff73d8d1 100644 --- a/Sources/Core/TypeDescriptor.swift +++ b/Sources/Core/TypeDescriptor.swift @@ -54,8 +54,10 @@ func plain(_: Type.Type) -> Tagged { protocol OptionalProtocol { static var wrappedType: Any.Type { get } + init() } extension Optional: OptionalProtocol { static var wrappedType: Any.Type { return Wrapped.self } + init() { self = .none } } diff --git a/Templates/Resolver+LegacyApi.swifttemplate b/Templates/Resolver+LegacyApi.swifttemplate index efa3fab9..343d5af6 100644 --- a/Templates/Resolver+LegacyApi.swifttemplate +++ b/Templates/Resolver+LegacyApi.swifttemplate @@ -10,9 +10,9 @@ public extension Resolver { /// - Returns: The resolved service type instance, or nil if no service with the name is found. func resolve(_ serviceType: Service.Type, name: String? = nil) -> Service? { if let name = name { - return try? resolve(request(tag: name, arg: ())) + return try? resolve(request(type: serviceType, tag: name, arg: ())) } else { - return try? resolve(request(tag: NoTag(), arg: ())) + return try? resolve(request(type: serviceType, tag: NoTag(), arg: ())) } } @@ -34,9 +34,9 @@ public extension Resolver { /// <%= arg_param_description %> and name is found. func resolve>(_ serviceType: Service.Type, name: String? = nil, <%= arg_param %>) -> Service? { if let name = name { - return try? resolve(request(tag: name, arg: ())) + return try? resolve(request(type: serviceType, tag: name, arg: ())) } else { - return try? resolve(request(tag: NoTag(), arg: <%= arg_vars %>)) + return try? resolve(request(type: serviceType, tag: NoTag(), arg: <%= arg_vars %>)) } } diff --git a/Tests/Unit Specs/SwinjectSpec.swift b/Tests/Unit Specs/SwinjectSpec.swift index 3f5ec8dc..8ad27d22 100644 --- a/Tests/Unit Specs/SwinjectSpec.swift +++ b/Tests/Unit Specs/SwinjectSpec.swift @@ -71,6 +71,15 @@ class SwinjectSpec: QuickSpec { override func spec() { _ = try? swinject.on("context").instance() as Int expect(binding.matchesReceivedKey?.contextType is String.Type).to(beTrue()) } + it("does not throw if has no binding for optional") { + binding.matchesReturnValue = false + expect { try swinject.instance() as Int? }.notTo(throwError()) + } + it("throws if has throwing binding for optional") { + binding.matchesReturnValue = true + binding.instanceArgContextResolverThrowableError = TestError() + expect { try swinject.instance() as Int? }.to(throwError()) + } } context("multiple bindings") { var bindings = [BindingMock]() @@ -96,6 +105,11 @@ class SwinjectSpec: QuickSpec { override func spec() { bindings[1].instanceArgContextResolverReturnValue = 42 expect { try swinject.instance(of: Int.self) } == 42 } + it("throws if has multiple bindings for optional") { + bindings[0].matchesReturnValue = true + bindings[1].matchesReturnValue = true + expect { try swinject.instance() as Int? }.to(throwError()) + } } } describe("provider injection") { @@ -259,7 +273,10 @@ class SwinjectSpec: QuickSpec { override func spec() { $0.translateReturnValue = 0 } bindings = Array(0 ..< 3).map { _ in BindingMock() } - bindings.forEach { $0.matchesReturnValue = false } + bindings.forEach { + $0.matchesReturnValue = false + $0.instanceArgContextResolverReturnValue = 0 + } swinject = Swinject { bindings[0]; bindings[1]; bindings[2] translators[0]; translators[1]; translators[2] @@ -269,13 +286,13 @@ class SwinjectSpec: QuickSpec { override func spec() { bindings[0].matchesClosure = { $0.contextType == Int.self } translators[1].sourceType = String.self translators[1].targetType = Int.self - expect { try swinject.on("context").instance() }.notTo(throwError()) + expect { try swinject.on("context").instance() as Int }.notTo(throwError()) } it("throws if translator has incorrect source type") { bindings[0].matchesClosure = { $0.contextType == Int.self } translators[1].sourceType = Double.self translators[1].targetType = Int.self - expect { try swinject.on("context").instance() }.to(throwError()) + expect { try swinject.on("context").instance() as Int }.to(throwError()) } it("throws if multiple translators have correct translation") { bindings[0].matchesClosure = { $0.contextType == Int.self } @@ -284,7 +301,7 @@ class SwinjectSpec: QuickSpec { override func spec() { translators[0].targetType = Int.self translators[1].sourceType = String.self translators[1].targetType = Float.self - expect { try swinject.on("context").instance() }.to(throwError()) + expect { try swinject.on("context").instance() as Int }.to(throwError()) } it("does not throw if multiple translators have correct target type but not source type") { bindings[0].matchesClosure = { $0.contextType == Int.self } @@ -300,21 +317,21 @@ class SwinjectSpec: QuickSpec { override func spec() { bindings[1].matchesClosure = { $0.contextType == String.self } translators[0].sourceType = String.self translators[0].targetType = Int.self - expect { try swinject.on("context").instance() }.to(throwError()) + expect { try swinject.on("context").instance() as Int }.to(throwError()) } it("passes translated context to binding") { bindings[0].matchesClosure = { $0.contextType == Int.self } translators[0].sourceType = String.self translators[0].targetType = Int.self translators[0].translateReturnValue = 42 - _ = try? swinject.on("context").instance() as Void + _ = try? swinject.on("context").instance() as Int expect(bindings[0].instanceArgContextResolverReceivedArguments?.context as? Int) == 42 } it("passes original context to context resolver") { bindings[0].matchesClosure = { $0.contextType == Int.self } translators[0].sourceType = String.self translators[0].targetType = Int.self - _ = try? swinject.on("context").instance() as Void + _ = try? swinject.on("context").instance() as Int expect(translators[0].translateReceivedContext as? String) == "context" } it("does not throw if single binding can be used with multiple translated contexts") { From e1185ce45cdea55095803d6f138e5dc34d21a20b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Tue, 23 Jul 2019 23:00:28 +0200 Subject: [PATCH 114/239] Invoke behaviors for forwarded types --- Sources/2.0 API/Container+Registration.swift | 20 +++--- .../2.0 API/Container+TypeForwarding.swift | 9 ++- .../2.0 API/ServiceEntry+TypeForwarding.swift | 6 +- Sources/2.0 API/ServiceEntry.swift | 3 + .../Container+Registration.swifttemplate | 4 +- .../ServiceEntry+TypeForwarding.swifttemplate | 6 +- Tests/2.0 API/ContainerSpec.Behavior.swift | 69 +++++++++---------- 7 files changed, 59 insertions(+), 58 deletions(-) diff --git a/Sources/2.0 API/Container+Registration.swift b/Sources/2.0 API/Container+Registration.swift index ae2c2fe4..aa92cd64 100644 --- a/Sources/2.0 API/Container+Registration.swift +++ b/Sources/2.0 API/Container+Registration.swift @@ -19,7 +19,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver) -> Service) -> ServiceEntry { - let entry = ServiceEntry(name: name, scope: defaultScope) { (r, _, _: Void) in factory(r) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope) { (r, _, _: Void) in factory(r) } addEntry(entry, with: name) return entry } @@ -38,7 +38,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1) -> Service) -> ServiceEntry { - let entry = ServiceEntry(name: name, scope: defaultScope) { (r, _, a: Arg1) in factory(r, a) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope) { (r, _, a: Arg1) in factory(r, a) } addEntry(entry, with: name) return entry } @@ -57,7 +57,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2) -> Service) -> ServiceEntry { - let entry = ServiceEntry(name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2)) in factory(r, a.0, a.1) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2)) in factory(r, a.0, a.1) } addEntry(entry, with: name) return entry } @@ -76,7 +76,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3) -> Service) -> ServiceEntry { - let entry = ServiceEntry(name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3)) in factory(r, a.0, a.1, a.2) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3)) in factory(r, a.0, a.1, a.2) } addEntry(entry, with: name) return entry } @@ -95,7 +95,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) -> Service) -> ServiceEntry { - let entry = ServiceEntry(name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3, Arg4)) in factory(r, a.0, a.1, a.2, a.3) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3, Arg4)) in factory(r, a.0, a.1, a.2, a.3) } addEntry(entry, with: name) return entry } @@ -114,7 +114,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) -> Service) -> ServiceEntry { - let entry = ServiceEntry(name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5)) in factory(r, a.0, a.1, a.2, a.3, a.4) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5)) in factory(r, a.0, a.1, a.2, a.3, a.4) } addEntry(entry, with: name) return entry } @@ -133,7 +133,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6) -> Service) -> ServiceEntry { - let entry = ServiceEntry(name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5) } addEntry(entry, with: name) return entry } @@ -152,7 +152,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7) -> Service) -> ServiceEntry { - let entry = ServiceEntry(name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6) } addEntry(entry, with: name) return entry } @@ -171,7 +171,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8) -> Service) -> ServiceEntry { - let entry = ServiceEntry(name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6, a.7) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6, a.7) } addEntry(entry, with: name) return entry } @@ -190,7 +190,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9) -> Service) -> ServiceEntry { - let entry = ServiceEntry(name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6, a.7, a.8) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6, a.7, a.8) } addEntry(entry, with: name) return entry } diff --git a/Sources/2.0 API/Container+TypeForwarding.swift b/Sources/2.0 API/Container+TypeForwarding.swift index 8eff6a21..de9cea5a 100644 --- a/Sources/2.0 API/Container+TypeForwarding.swift +++ b/Sources/2.0 API/Container+TypeForwarding.swift @@ -19,6 +19,13 @@ extension Container { /// - name: A registration name, which is used to differentiate from other registrations of the same `type` /// - service: ServiceEntry which should be used for resolution of `type` public func forward(_ type: T.Type, name: String? = nil, to service: ServiceEntry) { - service.implements(type, name: name) + if let name = name { + service.forwardedDescriptors.append(tagged(type, with: name)) + } else { + service.forwardedDescriptors.append(plain(type)) + } + behaviors.forEach { + $0.container(self, didRegisterType: T.self, toService: service, withName: name) + } } } diff --git a/Sources/2.0 API/ServiceEntry+TypeForwarding.swift b/Sources/2.0 API/ServiceEntry+TypeForwarding.swift index 413a65e4..b8d54564 100644 --- a/Sources/2.0 API/ServiceEntry+TypeForwarding.swift +++ b/Sources/2.0 API/ServiceEntry+TypeForwarding.swift @@ -12,11 +12,7 @@ extension ServiceEntry { /// - name: A registration name, which is used to differentiate from other registrations of the same `type` @discardableResult public func implements(_ type: T.Type, name: String? = nil) -> ServiceEntry { - if let name = name { - forwardedDescriptors.append(tagged(type, with: name)) - } else { - forwardedDescriptors.append(plain(type)) - } + container?.forward(type, name: name, to: self) return self } diff --git a/Sources/2.0 API/ServiceEntry.swift b/Sources/2.0 API/ServiceEntry.swift index 240e29ab..3b9c7ab2 100644 --- a/Sources/2.0 API/ServiceEntry.swift +++ b/Sources/2.0 API/ServiceEntry.swift @@ -5,6 +5,7 @@ /// The `ServiceEntry` class represents an entry of a registered service type. /// As a returned instance from a `register` method of a `Container`, some configurations can be added. public class ServiceEntry { + weak var container: Container? let builder: (Resolver, Any, Any) -> Service let argumentType: Any.Type let name: String? @@ -13,10 +14,12 @@ public class ServiceEntry { var forwardedDescriptors = [AnyTypeDescriptor]() init( + container: Container, name: String?, scope: AnyScope?, builder: @escaping (Resolver, Any, Argument) -> Service ) { + self.container = container self.builder = { builder($0, $1, $2 as! Argument) } argumentType = Argument.self self.name = name diff --git a/Templates/Container+Registration.swifttemplate b/Templates/Container+Registration.swifttemplate index e039a88b..b46ebe14 100644 --- a/Templates/Container+Registration.swifttemplate +++ b/Templates/Container+Registration.swifttemplate @@ -16,7 +16,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver) -> Service) -> ServiceEntry { - let entry = ServiceEntry(name: name, scope: defaultScope) { (r, _, _: Void) in factory(r) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope) { (r, _, _: Void) in factory(r) } addEntry(entry, with: name) return entry } @@ -41,7 +41,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register>(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, <%= arg_types %>) -> Service) -> ServiceEntry { - let entry = ServiceEntry(name: name, scope: defaultScope) { (r, _, a: <%= arg_closure_type %>) in factory(r, <%= arg_vars %>) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope) { (r, _, a: <%= arg_closure_type %>) in factory(r, <%= arg_vars %>) } addEntry(entry, with: name) return entry } diff --git a/Templates/ServiceEntry+TypeForwarding.swifttemplate b/Templates/ServiceEntry+TypeForwarding.swifttemplate index 9489c742..48121e06 100644 --- a/Templates/ServiceEntry+TypeForwarding.swifttemplate +++ b/Templates/ServiceEntry+TypeForwarding.swifttemplate @@ -9,11 +9,7 @@ extension ServiceEntry { /// - name: A registration name, which is used to differentiate from other registrations of the same `type` @discardableResult public func implements(_ type: T.Type, name: String? = nil) -> ServiceEntry { - if let name = name { - forwardedDescriptors.append(tagged(type, with: name)) - } else { - forwardedDescriptors.append(plain(type)) - } + container?.forward(type, name: name, to: self) return self } diff --git a/Tests/2.0 API/ContainerSpec.Behavior.swift b/Tests/2.0 API/ContainerSpec.Behavior.swift index 1ab38c29..a1ac2882 100644 --- a/Tests/2.0 API/ContainerSpec.Behavior.swift +++ b/Tests/2.0 API/ContainerSpec.Behavior.swift @@ -43,41 +43,40 @@ class ContainerSpec_Behavior: QuickSpec { expect(spy.types.first == Animal.self).to(beTrue()) } } - // TODO: Type forwarding -// describe("forwarding service") { -// it("should be invoked") { -// let spy1 = BehaviorSpy() -// let spy2 = BehaviorSpy() -// container.addBehavior(spy1) -// container.addBehavior(spy2) -// -// container.register(Dog.self) { _ in Dog() } -// .implements(Animal.self) -// -// expect(spy1.entries).to(haveCount(2)) -// expect(spy2.entries).to(haveCount(2)) -// } -// it("should be invoked using proper name") { -// let spy = BehaviorSpy() -// container.addBehavior(spy) -// -// container.register(Dog.self, name: "Hachi") { _ in Dog() } -// .implements(Animal.self) -// -// expect(spy.names[0]).to(equal("Hachi")) -// expect(spy.names[1]).to(beNil()) -// } -// it("should be invoked using proper type") { -// let spy = BehaviorSpy() -// container.addBehavior(spy) -// -// container.register(Dog.self, name: "Hachi") { _ in Dog() } -// .implements(Animal.self) -// -// expect(spy.types[0] == Dog.self).to(beTrue()) -// expect(spy.types[1] == Animal.self).to(beTrue()) -// } -// } + describe("forwarding service") { + it("should be invoked") { + let spy1 = BehaviorSpy() + let spy2 = BehaviorSpy() + container.addBehavior(spy1) + container.addBehavior(spy2) + + container.register(Dog.self) { _ in Dog() } + .implements(Animal.self) + + expect(spy1.entries).to(haveCount(2)) + expect(spy2.entries).to(haveCount(2)) + } + it("should be invoked using proper name") { + let spy = BehaviorSpy() + container.addBehavior(spy) + + container.register(Dog.self, name: "Hachi") { _ in Dog() } + .implements(Animal.self) + + expect(spy.names[0]).to(equal("Hachi")) + expect(spy.names[1]).to(beNil()) + } + it("should be invoked using proper type") { + let spy = BehaviorSpy() + container.addBehavior(spy) + + container.register(Dog.self, name: "Hachi") { _ in Dog() } + .implements(Animal.self) + + expect(spy.types[0] == Dog.self).to(beTrue()) + expect(spy.types[1] == Animal.self).to(beTrue()) + } + } describe("convenience initialiser") { it("adds behaviors to the container") { let spy1 = BehaviorSpy() From 6279795202458275e7fb506e1e8e7e8b34d6165d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Wed, 24 Jul 2019 19:26:19 +0200 Subject: [PATCH 115/239] Enable definition of custom default scope for container / assembler --- Sources/2.0 API/Assembler.swift | 43 +++++++++++++++++-------------- Sources/2.0 API/Container.swift | 30 ++++++++++++++++++--- Tests/2.0 API/AssemblerSpec.swift | 21 +++++++++++---- Tests/2.0 API/ContainerSpec.swift | 24 ++++++++++------- 4 files changed, 82 insertions(+), 36 deletions(-) diff --git a/Sources/2.0 API/Assembler.swift b/Sources/2.0 API/Assembler.swift index a6c8c6f6..721edd30 100644 --- a/Sources/2.0 API/Assembler.swift +++ b/Sources/2.0 API/Assembler.swift @@ -20,21 +20,6 @@ public final class Assembler { self.container = container! } - /// Will create an empty `Assembler` - /// - /// - parameter parentAssembler: the baseline assembler - /// - parameter defaultObjectScope: default object scope for container - /// - parameter behaviors: list of behaviors to be added to the container - /// - // TODO: Enable to use any scope as default - public init(parentAssembler: Assembler?, defaultObjectScope: ObjectScope = .graph, behaviors: [Behavior] = []) { - container = Container( - parent: parentAssembler?.container, - defaultObjectScope: defaultObjectScope, - behaviors: behaviors - ) - } - /// Will create a new `Assembler` with the given `Assembly` instances to build a `Container` /// /// - parameter assemblies: the list of assemblies to build the container from @@ -51,13 +36,33 @@ public final class Assembler { /// - parameter parent: the baseline assembler /// - parameter defaultObjectScope: default object scope for container /// - parameter behaviors: list of behaviors to be added to the container - public init( - _ assemblies: [Assembly], - parent: Assembler?, + public convenience init( + _ assemblies: [Assembly] = [], + parent: Assembler? = nil, defaultObjectScope: ObjectScope = .graph, behaviors: [Behavior] = [] ) { - container = Container(parent: parent?.container, defaultObjectScope: defaultObjectScope, behaviors: behaviors) + self.init( + assemblies, + parent: parent, + defaultScope: defaultObjectScope.scope, + behaviors: behaviors + ) + } + + /// Will create a new `Assembler` with the given `Assembly` instances to build a `Container` + /// + /// - parameter assemblies: the list of assemblies to build the container from + /// - parameter parent: the baseline assembler + /// - parameter defaultScope: default object scope for container + /// - parameter behaviors: list of behaviors to be added to the container + public init( + _ assemblies: [Assembly] = [], + parent: Assembler? = nil, + defaultScope: AnyScope?, + behaviors: [Behavior] = [] + ) { + container = Container(parent: parent?.container, defaultScope: defaultScope, behaviors: behaviors) run(assemblies: assemblies) } diff --git a/Sources/2.0 API/Container.swift b/Sources/2.0 API/Container.swift index f330a3c5..1ffc3e0b 100644 --- a/Sources/2.0 API/Container.swift +++ b/Sources/2.0 API/Container.swift @@ -38,7 +38,7 @@ public final class Container { /// /// - Parameters /// - parent: The optional parent `Container`. - /// - defaultObjectScope: Default object scope (graph if no scope is injected) + /// - defaultScope: Default scope /// - behaviors: List of behaviors to be added to the container /// - registeringClosure: The closure registering services to the new container instance. /// @@ -46,17 +46,41 @@ public final class Container { /// Use `init()` or `init(parent:)` instead. public init( parent: Container? = nil, - defaultObjectScope: ObjectScope = .graph, + defaultScope: AnyScope?, behaviors: [Behavior] = [], registeringClosure: (Container) -> Void = { _ in } ) { self.parent = parent - defaultScope = defaultObjectScope.scope + self.defaultScope = defaultScope self.behaviors = behaviors registry = parent?.registry ?? StandardScopeRegistry() registeringClosure(self) } + /// Instantiates a `Container` + /// + /// - Parameters + /// - parent: The optional parent `Container`. + /// - defaultObjectScope: Default object scope (graph if no scope is injected) + /// - behaviors: List of behaviors to be added to the container + /// - registeringClosure: The closure registering services to the new container instance. + /// + /// - Remark: Compile time may be long if you pass a long closure to this initializer. + /// Use `init()` or `init(parent:)` instead. + public convenience init( + parent: Container? = nil, + defaultObjectScope: ObjectScope = .graph, + behaviors: [Behavior] = [], + registeringClosure: (Container) -> Void = { _ in } + ) { + self.init( + parent: parent, + defaultScope: defaultObjectScope.scope, + behaviors: behaviors, + registeringClosure: registeringClosure + ) + } + /// Removes all registrations in the container. public func removeAll() { bindings = [] diff --git a/Tests/2.0 API/AssemblerSpec.swift b/Tests/2.0 API/AssemblerSpec.swift index ca1c1c7d..64866d1c 100644 --- a/Tests/2.0 API/AssemblerSpec.swift +++ b/Tests/2.0 API/AssemblerSpec.swift @@ -23,7 +23,7 @@ class AssemblerSpec: QuickSpec { } it("can assembly a container with nil parent") { - let assembler = Assembler(parentAssembler: nil) + let assembler = Assembler(parent: nil) let sushi = assembler.resolver.resolve(Food.self) expect(sushi).to(beNil()) @@ -51,6 +51,17 @@ class AssemblerSpec: QuickSpec { expect(serviceEntry?.scope) === ObjectScope.container.scope } + it("uses injected default custom scope") { + let scope = UnboundScope() + let assembler = Assembler(parent: nil, defaultScope: scope) + + assembler.apply(assembly: ContainerSpyAssembly()) + let container = assembler.resolver.resolve(Container.self) + let serviceEntry = container?.register(Animal.self) { _ in Siamese(name: "Siam") } + + expect(serviceEntry?.scope) === scope + } + it("uses graph scope if no default object scope is injected") { let assembler = Assembler([], parent: nil) @@ -256,7 +267,7 @@ class AssemblerSpec: QuickSpec { AnimalAssembly(), ]) - let childAssembler = Assembler(parentAssembler: assembler) + let childAssembler = Assembler(parent: assembler) let cat = assembler.resolver.resolve(Animal.self) expect(cat).toNot(beNil()) @@ -287,7 +298,7 @@ class AssemblerSpec: QuickSpec { it("uses injected default object scope") { let parentContainer = Container() let parentAssembler = Assembler(container: parentContainer) - let childAssembler = Assembler(parentAssembler: parentAssembler, + let childAssembler = Assembler(parent: parentAssembler, defaultObjectScope: ObjectScope.container) childAssembler.apply(assembly: ContainerSpyAssembly()) @@ -300,7 +311,7 @@ class AssemblerSpec: QuickSpec { it("has default object scope of graph type") { let parentContainer = Container() let parentAssembler = Assembler(container: parentContainer) - let childAssembler = Assembler(parentAssembler: parentAssembler) + let childAssembler = Assembler(parent: parentAssembler) childAssembler.apply(assembly: ContainerSpyAssembly()) let container = childAssembler.resolver.resolve(Container.self) @@ -311,7 +322,7 @@ class AssemblerSpec: QuickSpec { it("uses given list of behaviors to container") { let spy = BehaviorSpy() - let assembler = Assembler(parentAssembler: Assembler(), behaviors: [spy]) + let assembler = Assembler(parent: Assembler(), behaviors: [spy]) assembler.apply(assembly: ContainerSpyAssembly()) diff --git a/Tests/2.0 API/ContainerSpec.swift b/Tests/2.0 API/ContainerSpec.swift index 711b6d5e..6cd2cadf 100644 --- a/Tests/2.0 API/ContainerSpec.swift +++ b/Tests/2.0 API/ContainerSpec.swift @@ -365,14 +365,20 @@ class ContainerSpec: QuickSpec { expect(container.resolve(Animal.self) as? Cat).notTo(beNil()) } } - // TODO: Implement weak scope -// describe("Default object scope") { -// it("registers services with given object scope") { -// let container = Container(parent: nil, defaultObjectScope: .weak) -// -// let serviceEntry = container.register(Animal.self) { _ in Siamese(name: "Siam") } -// expect(serviceEntry.scope) === ObjectScope.weak.scope -// } -// } + describe("Default scope") { + it("registers services with given object scope") { + let container = Container(parent: nil, defaultObjectScope: .container) + + let serviceEntry = container.register(Animal.self) { _ in Siamese(name: "Siam") } + expect(serviceEntry.scope) === ObjectScope.container.scope + } + it("registers services with given custom scope") { + let scope = UnboundScope() + let container = Container(parent: nil, defaultScope: scope) + + let serviceEntry = container.register(Animal.self) { _ in Siamese(name: "Siam") } + expect(serviceEntry.scope) === scope + } + } } } From d1ee8bff22ea5e073bd998e0455a6fca6d53ba86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Wed, 24 Jul 2019 20:20:05 +0200 Subject: [PATCH 116/239] Implement strong reference --- Sources/Core/Reference.swift | 25 +++++++++++++++++++++++ Swinject.xcodeproj/project.pbxproj | 20 ++++++++++++++++++ Tests/Support/GeneratedMocks.swift | 25 +++++++++++++++++++++++ Tests/Unit Specs/ReferenceMakerSpec.swift | 21 +++++++++++++++++++ 4 files changed, 91 insertions(+) create mode 100644 Sources/Core/Reference.swift create mode 100644 Tests/Unit Specs/ReferenceMakerSpec.swift diff --git a/Sources/Core/Reference.swift b/Sources/Core/Reference.swift new file mode 100644 index 00000000..58f816ac --- /dev/null +++ b/Sources/Core/Reference.swift @@ -0,0 +1,25 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +// sourcery: AutoMockable +public protocol Reference { + var value: Any? { get } +} + +// sourcery: AutoMockable +public protocol ReferenceMaker { + func makeReference(for value: Any) -> Reference +} + +struct StrongReference: Reference { + let value: Any? + + struct Maker: ReferenceMaker { + func makeReference(for value: Any) -> Reference { + StrongReference(value: value) + } + } +} + +public let strongRef: ReferenceMaker = StrongReference.Maker() diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 3c271f02..c4675323 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -255,6 +255,14 @@ CDF8F35722E64694008B2AF5 /* ContextTranslator.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDF8F35522E64694008B2AF5 /* ContextTranslator.swift */; }; CDF8F35822E64694008B2AF5 /* ContextTranslator.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDF8F35522E64694008B2AF5 /* ContextTranslator.swift */; }; CDF8F35922E64694008B2AF5 /* ContextTranslator.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDF8F35522E64694008B2AF5 /* ContextTranslator.swift */; }; + CDF8F36522E8D881008B2AF5 /* Reference.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDF8F36422E8D881008B2AF5 /* Reference.swift */; }; + CDF8F36622E8D881008B2AF5 /* Reference.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDF8F36422E8D881008B2AF5 /* Reference.swift */; }; + CDF8F36722E8D881008B2AF5 /* Reference.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDF8F36422E8D881008B2AF5 /* Reference.swift */; }; + CDF8F36822E8D881008B2AF5 /* Reference.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDF8F36422E8D881008B2AF5 /* Reference.swift */; }; + CDF8F36A22E8D89E008B2AF5 /* ReferenceMakerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDF8F36922E8D89E008B2AF5 /* ReferenceMakerSpec.swift */; }; + CDF8F36B22E8D89E008B2AF5 /* ReferenceMakerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDF8F36922E8D89E008B2AF5 /* ReferenceMakerSpec.swift */; }; + CDF8F36C22E8D89E008B2AF5 /* ReferenceMakerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDF8F36922E8D89E008B2AF5 /* ReferenceMakerSpec.swift */; }; + CDF8F36D22E8D89E008B2AF5 /* ReferenceMakerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDF8F36922E8D89E008B2AF5 /* ReferenceMakerSpec.swift */; }; CFC3CDB46CD8FFA22EB0FADD /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A0157DBBD5E1F45963BB0932 /* Swinject.framework */; }; D10FFA4B80F4BE6024B1DCEE /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1910A1471C3CA9EA86F350BA /* LoadAwareAssembly.swift */; }; D18275ADB0E56D3087894518 /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; @@ -487,6 +495,8 @@ CD4D866D22E4D54D0042ACDC /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; CD4D866F22E4D54D0042ACDC /* ServiceEntry+TypeForwarding.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "ServiceEntry+TypeForwarding.swifttemplate"; sourceTree = ""; }; CDF8F35522E64694008B2AF5 /* ContextTranslator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextTranslator.swift; sourceTree = ""; }; + CDF8F36422E8D881008B2AF5 /* Reference.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Reference.swift; sourceTree = ""; }; + CDF8F36922E8D89E008B2AF5 /* ReferenceMakerSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReferenceMakerSpec.swift; sourceTree = ""; }; D1FA0377AF4799D42E9462FA /* BasicAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BasicAssembly.swift; sourceTree = ""; }; E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRequest.swift; sourceTree = ""; }; E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; @@ -547,6 +557,7 @@ 0A05322134E988A4593B5122 /* Unit Specs */ = { isa = PBXGroup; children = ( + CDF8F36922E8D89E008B2AF5 /* ReferenceMakerSpec.swift */, FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */, 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */, 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */, @@ -771,6 +782,7 @@ FCA9C6262A4D071C8E7EEBD0 /* Core */ = { isa = PBXGroup; children = ( + CDF8F36422E8D881008B2AF5 /* Reference.swift */, 0E0B580B43E1891812C97209 /* Binding.swift */, A24B4E8F1CA18603DBB6884A /* BindingKey.swift */, 65D0BCCCD61CD9BECC29E064 /* Closable.swift */, @@ -1226,6 +1238,7 @@ CD4D866622E4C8A70042ACDC /* ObjectScope.swift in Sources */, 828C5B0915A8D08CF98F5F4C /* Swinject.swift in Sources */, EAC4EA9BAC87B34AD5BA2110 /* SwinjectError.swift in Sources */, + CDF8F36622E8D881008B2AF5 /* Reference.swift in Sources */, 94615DB1AD57F1547933D8A5 /* SwinjectModule.swift in Sources */, 8F48909C95AA648D056A392B /* SwinjectTree.swift in Sources */, 3B61931D1E9C0F7D1AAEDDF7 /* TypeBinder.swift in Sources */, @@ -1250,6 +1263,7 @@ 86E1845B6272AF95F1806CB4 /* ContainerSpec.Circularity.swift in Sources */, 93DCA2A58C4067D5E60F7ED1 /* ContainerSpec.CustomStringConvertible.swift in Sources */, F8DB4EDA0367BCC6832E4AA6 /* ContainerSpec.TypeForwarding.swift in Sources */, + CDF8F36A22E8D89E008B2AF5 /* ReferenceMakerSpec.swift in Sources */, 4C6D7AE29CB7E16431AACFA2 /* ContainerSpec.swift in Sources */, A014793C56F8966AD2D7CC50 /* Convenience.swift in Sources */, DC5C3A946BDA224C388D2438 /* EmploymentAssembly.swift in Sources */, @@ -1292,6 +1306,7 @@ 37FE9A9C76DB50ABB28AF9BE /* ContainerSpec.Circularity.swift in Sources */, E423395FC7006DD82513F347 /* ContainerSpec.CustomStringConvertible.swift in Sources */, FAF8F8B75F63D43995A004E8 /* ContainerSpec.TypeForwarding.swift in Sources */, + CDF8F36D22E8D89E008B2AF5 /* ReferenceMakerSpec.swift in Sources */, C797CCF413DF181935DAB58C /* ContainerSpec.swift in Sources */, DE0A534B660AA93F73A2CB41 /* Convenience.swift in Sources */, 833635A5D695AA696559C250 /* EmploymentAssembly.swift in Sources */, @@ -1351,6 +1366,7 @@ CD4D866822E4C8A80042ACDC /* ObjectScope.swift in Sources */, B5048A00D49FD5C1C098EE01 /* Swinject.swift in Sources */, 439254FAE8DF567DE9659ADA /* SwinjectError.swift in Sources */, + CDF8F36722E8D881008B2AF5 /* Reference.swift in Sources */, AA6651CFD4090465E7CB7871 /* SwinjectModule.swift in Sources */, 4DA000959B4D60B509859810 /* SwinjectTree.swift in Sources */, 5D2C492FD5088FCB2BA5CDB8 /* TypeBinder.swift in Sources */, @@ -1375,6 +1391,7 @@ EAD0757CE0163D3549CB5405 /* ContainerSpec.Circularity.swift in Sources */, 377EE35B80E8F91543B52F0C /* ContainerSpec.CustomStringConvertible.swift in Sources */, 5D241BBB39F54B8FA2BFF595 /* ContainerSpec.TypeForwarding.swift in Sources */, + CDF8F36B22E8D89E008B2AF5 /* ReferenceMakerSpec.swift in Sources */, 37E07236E0E63570242CE23F /* ContainerSpec.swift in Sources */, 564B886D2A35AF26FC411922 /* Convenience.swift in Sources */, 58C9D537D453BC7C7DC5C0C1 /* EmploymentAssembly.swift in Sources */, @@ -1417,6 +1434,7 @@ 9B9AA902B80620568D732D7B /* ContainerSpec.Circularity.swift in Sources */, E8D70420E8A3C91D01BC3B5B /* ContainerSpec.CustomStringConvertible.swift in Sources */, 9F1C7A652660EA87BF599126 /* ContainerSpec.TypeForwarding.swift in Sources */, + CDF8F36C22E8D89E008B2AF5 /* ReferenceMakerSpec.swift in Sources */, E80558941BC2149C25A17495 /* ContainerSpec.swift in Sources */, A1B275A2EFA22C45AC46B31E /* Convenience.swift in Sources */, 187BD516162B3FBB1158E015 /* EmploymentAssembly.swift in Sources */, @@ -1476,6 +1494,7 @@ CD4D866522E4C8A50042ACDC /* ObjectScope.swift in Sources */, 9E084F679592ADFA28D3AD6D /* Swinject.swift in Sources */, AAC84D757FE8F601FF053923 /* SwinjectError.swift in Sources */, + CDF8F36522E8D881008B2AF5 /* Reference.swift in Sources */, 5570E14A839D4065FFBA7EF4 /* SwinjectModule.swift in Sources */, E8A89383E1D1106DEABB778B /* SwinjectTree.swift in Sources */, 050982D62AE0244372456440 /* TypeBinder.swift in Sources */, @@ -1517,6 +1536,7 @@ CD4D866722E4C8A80042ACDC /* ObjectScope.swift in Sources */, 26C8D37F26408DC308A0CDA3 /* Swinject.swift in Sources */, 14AECF24B26ECEC8E9086FBB /* SwinjectError.swift in Sources */, + CDF8F36822E8D881008B2AF5 /* Reference.swift in Sources */, 699DB780BD90A5AAAD5B4646 /* SwinjectModule.swift in Sources */, 192278AA7165EC3C2C12A4C2 /* SwinjectTree.swift in Sources */, D88D7841C5C84A2E34CE15FD /* TypeBinder.swift in Sources */, diff --git a/Tests/Support/GeneratedMocks.swift b/Tests/Support/GeneratedMocks.swift index 25bd6e9f..aeacf1f6 100644 --- a/Tests/Support/GeneratedMocks.swift +++ b/Tests/Support/GeneratedMocks.swift @@ -301,6 +301,31 @@ class MatchableMock: Matchable { } class ModuleIncludeEntryMock: ModuleIncludeEntry { +} +class ReferenceMock: Reference { + var value: Any? + +} +class ReferenceMakerMock: ReferenceMaker { + + //MARK: - makeReference + + var makeReferenceForCallsCount = 0 + var makeReferenceForCalled: Bool { + return makeReferenceForCallsCount > 0 + } + var makeReferenceForReceivedValue: Any? + var makeReferenceForReceivedInvocations: [Any] = [] + var makeReferenceForReturnValue: Reference! + var makeReferenceForClosure: ((Any) -> Reference)? + + func makeReference(for value: Any) -> Reference { + makeReferenceForCallsCount += 1 + makeReferenceForReceivedValue = value + makeReferenceForReceivedInvocations.append(value) + return makeReferenceForClosure.map({ $0(value) }) ?? makeReferenceForReturnValue + } + } class StaticScopeRegistryMock: StaticScopeRegistry { diff --git a/Tests/Unit Specs/ReferenceMakerSpec.swift b/Tests/Unit Specs/ReferenceMakerSpec.swift new file mode 100644 index 00000000..a4a6efb7 --- /dev/null +++ b/Tests/Unit Specs/ReferenceMakerSpec.swift @@ -0,0 +1,21 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +import Nimble +import Quick +@testable import Swinject + +class ReferenceMakerSpec: QuickSpec { override func spec() { + describe("strongRef") { + it("returns given value") { + let human = Human() + let reference = strongRef.makeReference(for: human) + expect(reference.value) === human + } + it("persists given value") { + let reference = strongRef.makeReference(for: Human()) + expect(reference.value).notTo(beNil()) + } + } +} } From ae06c8d3542bb910588ef8e377a690ff9179bc0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Wed, 24 Jul 2019 20:31:09 +0200 Subject: [PATCH 117/239] Integrate autocorrect & swiftformat as build phase --- Sources/2.0 API/Container+Registration.swift | 22 +- Sources/2.0 API/Resolver+LegacyApi.swift | 2 +- .../2.0 API/ServiceEntry+TypeForwarding.swift | 33 +- Swinject.xcodeproj/project.pbxproj | 568 +++++++++--------- .../Container+Registration.swifttemplate | 4 +- .../ServiceEntry+TypeForwarding.swifttemplate | 6 +- ...ontainerSpec.CustomStringConvertible.swift | 4 +- Tests/2.0 API/LazySpec.swift | 4 +- Tests/2.0 API/ProviderSpec.swift | 4 +- Tests/Support/{2.0 => Legacy}/Animal.swift | 0 .../{2.0 => Legacy}/BasicAssembly.swift | 0 .../{2.0 => Legacy}/BehaviorFakes.swift | 0 .../{2.0 => Legacy}/EmploymentAssembly.swift | 0 Tests/Support/{2.0 => Legacy}/Food.swift | 0 .../{2.0 => Legacy}/LoadAwareAssembly.swift | 0 Tests/Support/{2.0 => Legacy}/Person.swift | 0 project.yml | 10 +- 17 files changed, 336 insertions(+), 321 deletions(-) rename Tests/Support/{2.0 => Legacy}/Animal.swift (100%) rename Tests/Support/{2.0 => Legacy}/BasicAssembly.swift (100%) rename Tests/Support/{2.0 => Legacy}/BehaviorFakes.swift (100%) rename Tests/Support/{2.0 => Legacy}/EmploymentAssembly.swift (100%) rename Tests/Support/{2.0 => Legacy}/Food.swift (100%) rename Tests/Support/{2.0 => Legacy}/LoadAwareAssembly.swift (100%) rename Tests/Support/{2.0 => Legacy}/Person.swift (100%) diff --git a/Sources/2.0 API/Container+Registration.swift b/Sources/2.0 API/Container+Registration.swift index aa92cd64..7c759bc0 100644 --- a/Sources/2.0 API/Container+Registration.swift +++ b/Sources/2.0 API/Container+Registration.swift @@ -18,7 +18,7 @@ extension Container { /// /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult - public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver) -> Service) -> ServiceEntry { + public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver) -> Service) -> ServiceEntry { let entry = ServiceEntry(container: self, name: name, scope: defaultScope) { (r, _, _: Void) in factory(r) } addEntry(entry, with: name) return entry @@ -37,7 +37,7 @@ extension Container { /// /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult - public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1) -> Service) -> ServiceEntry { + public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1) -> Service) -> ServiceEntry { let entry = ServiceEntry(container: self, name: name, scope: defaultScope) { (r, _, a: Arg1) in factory(r, a) } addEntry(entry, with: name) return entry @@ -56,7 +56,7 @@ extension Container { /// /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult - public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2) -> Service) -> ServiceEntry { + public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2) -> Service) -> ServiceEntry { let entry = ServiceEntry(container: self, name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2)) in factory(r, a.0, a.1) } addEntry(entry, with: name) return entry @@ -75,7 +75,7 @@ extension Container { /// /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult - public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3) -> Service) -> ServiceEntry { + public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3) -> Service) -> ServiceEntry { let entry = ServiceEntry(container: self, name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3)) in factory(r, a.0, a.1, a.2) } addEntry(entry, with: name) return entry @@ -94,7 +94,7 @@ extension Container { /// /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult - public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) -> Service) -> ServiceEntry { + public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) -> Service) -> ServiceEntry { let entry = ServiceEntry(container: self, name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3, Arg4)) in factory(r, a.0, a.1, a.2, a.3) } addEntry(entry, with: name) return entry @@ -113,7 +113,7 @@ extension Container { /// /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult - public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) -> Service) -> ServiceEntry { + public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) -> Service) -> ServiceEntry { let entry = ServiceEntry(container: self, name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5)) in factory(r, a.0, a.1, a.2, a.3, a.4) } addEntry(entry, with: name) return entry @@ -132,7 +132,7 @@ extension Container { /// /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult - public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6) -> Service) -> ServiceEntry { + public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6) -> Service) -> ServiceEntry { let entry = ServiceEntry(container: self, name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5) } addEntry(entry, with: name) return entry @@ -151,7 +151,7 @@ extension Container { /// /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult - public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7) -> Service) -> ServiceEntry { + public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7) -> Service) -> ServiceEntry { let entry = ServiceEntry(container: self, name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6) } addEntry(entry, with: name) return entry @@ -170,7 +170,7 @@ extension Container { /// /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult - public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8) -> Service) -> ServiceEntry { + public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8) -> Service) -> ServiceEntry { let entry = ServiceEntry(container: self, name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6, a.7) } addEntry(entry, with: name) return entry @@ -189,11 +189,11 @@ extension Container { /// /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult - public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9) -> Service) -> ServiceEntry { + public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9) -> Service) -> ServiceEntry { let entry = ServiceEntry(container: self, name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6, a.7, a.8) } addEntry(entry, with: name) return entry } - } + // sourcery:end diff --git a/Sources/2.0 API/Resolver+LegacyApi.swift b/Sources/2.0 API/Resolver+LegacyApi.swift index fb04aa72..d2dfebb3 100644 --- a/Sources/2.0 API/Resolver+LegacyApi.swift +++ b/Sources/2.0 API/Resolver+LegacyApi.swift @@ -171,6 +171,6 @@ public extension Resolver { return try? resolve(request(type: serviceType, tag: NoTag(), arg: (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9))) } } - } + // sourcery:end diff --git a/Sources/2.0 API/ServiceEntry+TypeForwarding.swift b/Sources/2.0 API/ServiceEntry+TypeForwarding.swift index b8d54564..9cc173e2 100644 --- a/Sources/2.0 API/ServiceEntry+TypeForwarding.swift +++ b/Sources/2.0 API/ServiceEntry+TypeForwarding.swift @@ -23,9 +23,9 @@ extension ServiceEntry { /// - types: List of 2 types resolution of which should be forwarded @discardableResult public func implements(_ type1: T1.Type, _ type2: T2.Type) -> ServiceEntry { - return self.implements(type1).implements(type2) + return implements(type1).implements(type2) } - + /// Adds multiple types which should be resolved using this ServiceEntry - i.e. using the same object scope, /// arguments and `initCompleted` closures /// @@ -33,9 +33,9 @@ extension ServiceEntry { /// - types: List of 3 types resolution of which should be forwarded @discardableResult public func implements(_ type1: T1.Type, _ type2: T2.Type, _ type3: T3.Type) -> ServiceEntry { - return self.implements(type1).implements(type2).implements(type3) + return implements(type1).implements(type2).implements(type3) } - + /// Adds multiple types which should be resolved using this ServiceEntry - i.e. using the same object scope, /// arguments and `initCompleted` closures /// @@ -43,9 +43,9 @@ extension ServiceEntry { /// - types: List of 4 types resolution of which should be forwarded @discardableResult public func implements(_ type1: T1.Type, _ type2: T2.Type, _ type3: T3.Type, _ type4: T4.Type) -> ServiceEntry { - return self.implements(type1).implements(type2).implements(type3).implements(type4) + return implements(type1).implements(type2).implements(type3).implements(type4) } - + /// Adds multiple types which should be resolved using this ServiceEntry - i.e. using the same object scope, /// arguments and `initCompleted` closures /// @@ -53,9 +53,9 @@ extension ServiceEntry { /// - types: List of 5 types resolution of which should be forwarded @discardableResult public func implements(_ type1: T1.Type, _ type2: T2.Type, _ type3: T3.Type, _ type4: T4.Type, _ type5: T5.Type) -> ServiceEntry { - return self.implements(type1).implements(type2).implements(type3).implements(type4).implements(type5) + return implements(type1).implements(type2).implements(type3).implements(type4).implements(type5) } - + /// Adds multiple types which should be resolved using this ServiceEntry - i.e. using the same object scope, /// arguments and `initCompleted` closures /// @@ -63,9 +63,9 @@ extension ServiceEntry { /// - types: List of 6 types resolution of which should be forwarded @discardableResult public func implements(_ type1: T1.Type, _ type2: T2.Type, _ type3: T3.Type, _ type4: T4.Type, _ type5: T5.Type, _ type6: T6.Type) -> ServiceEntry { - return self.implements(type1).implements(type2).implements(type3).implements(type4).implements(type5).implements(type6) + return implements(type1).implements(type2).implements(type3).implements(type4).implements(type5).implements(type6) } - + /// Adds multiple types which should be resolved using this ServiceEntry - i.e. using the same object scope, /// arguments and `initCompleted` closures /// @@ -73,9 +73,9 @@ extension ServiceEntry { /// - types: List of 7 types resolution of which should be forwarded @discardableResult public func implements(_ type1: T1.Type, _ type2: T2.Type, _ type3: T3.Type, _ type4: T4.Type, _ type5: T5.Type, _ type6: T6.Type, _ type7: T7.Type) -> ServiceEntry { - return self.implements(type1).implements(type2).implements(type3).implements(type4).implements(type5).implements(type6).implements(type7) + return implements(type1).implements(type2).implements(type3).implements(type4).implements(type5).implements(type6).implements(type7) } - + /// Adds multiple types which should be resolved using this ServiceEntry - i.e. using the same object scope, /// arguments and `initCompleted` closures /// @@ -83,9 +83,9 @@ extension ServiceEntry { /// - types: List of 8 types resolution of which should be forwarded @discardableResult public func implements(_ type1: T1.Type, _ type2: T2.Type, _ type3: T3.Type, _ type4: T4.Type, _ type5: T5.Type, _ type6: T6.Type, _ type7: T7.Type, _ type8: T8.Type) -> ServiceEntry { - return self.implements(type1).implements(type2).implements(type3).implements(type4).implements(type5).implements(type6).implements(type7).implements(type8) + return implements(type1).implements(type2).implements(type3).implements(type4).implements(type5).implements(type6).implements(type7).implements(type8) } - + /// Adds multiple types which should be resolved using this ServiceEntry - i.e. using the same object scope, /// arguments and `initCompleted` closures /// @@ -93,9 +93,8 @@ extension ServiceEntry { /// - types: List of 9 types resolution of which should be forwarded @discardableResult public func implements(_ type1: T1.Type, _ type2: T2.Type, _ type3: T3.Type, _ type4: T4.Type, _ type5: T5.Type, _ type6: T6.Type, _ type7: T7.Type, _ type8: T8.Type, _ type9: T9.Type) -> ServiceEntry { - return self.implements(type1).implements(type2).implements(type3).implements(type4).implements(type5).implements(type6).implements(type7).implements(type8).implements(type9) + return implements(type1).implements(type2).implements(type3).implements(type4).implements(type5).implements(type6).implements(type7).implements(type8).implements(type9) } - - } + // sourcery:end diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index c4675323..fa991b0c 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -8,7 +8,6 @@ /* Begin PBXBuildFile section */ 01197582F81B8D30D7D4A8AF /* NonGeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841D83ADB41363D1E38087B4 /* NonGeneratedMocks.swift */; }; - 013A1E1096BD1305A3A14493 /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1910A1471C3CA9EA86F350BA /* LoadAwareAssembly.swift */; }; 01D985B5F99817DEE0E0DAD1 /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */; }; 01F001388FD754499B18FFAC /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */; }; 03005DC48E35AEF37251FADC /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; @@ -16,19 +15,17 @@ 04C24C140F2D0BBFE48C682C /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; 050982D62AE0244372456440 /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92B8E618A08408404FB2A7A /* TypeBinder.swift */; }; 0516305FEAEA5A677A6FA9B3 /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; - 0539332D989C37CA34A5FB4F /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEE8FDF4B975A8F2A9FCC5FF /* Food.swift */; }; 0568E116A56DA02DA92BAC8E /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; 084187169E13A6E9E709297C /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; + 0862B3AD1CE95CA4A9854E8F /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 351C4221896DDB8572BD6CB5 /* Person.swift */; }; + 0874FBEE3E260F862C4AC54A /* Resolver+LegacyApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A784E2DEC7691D14DDBECD8 /* Resolver+LegacyApi.swift */; }; 0C24BE87E4F1CF7482DB3468 /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 273FB7A6277E0841E1570990 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 0C7996FAC479BA40B124F470 /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = ADD71387EBA54D7EF60D0089 /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 0CB9E677FDF7CF424A738F34 /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C13D01A2DE6F53DF3175D22 /* Container+Registration.swift */; }; 0CED31C429BA9F9B23EB2B1F /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42490D1D0C395951243F5CFF /* Container.swift */; }; 0D6143A7732F1334275D3658 /* UnboundScopeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 671D5D89472DAFA916814506 /* UnboundScopeSpec.swift */; }; - 0DFB6FB4DF6A713EA545930F /* Container+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C2DBC728B763B04CB25963 /* Container+TypeForwarding.swift */; }; 0E465ECE9EC970161D607F7F /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EA7A547FC60DBD02D132B3E6 /* Swinject.framework */; }; 0E8E5B08478EB883D9B52947 /* ScopedBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */; }; 100DC02D61F72A611B7CF6E3 /* UnboundScopeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 671D5D89472DAFA916814506 /* UnboundScopeSpec.swift */; }; - 124369E08D4848D05E3EA6B1 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1FA0377AF4799D42E9462FA /* BasicAssembly.swift */; }; 13379D1C70FC17FE2F949341 /* BindingKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */; }; 133D41B8AD245B9DBAFC6606 /* Quick.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 683A1FB7D7F4E9508D57E936 /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 14AECF24B26ECEC8E9086FBB /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3586A4987B7C7C8122D674E /* SwinjectError.swift */; }; @@ -37,56 +34,62 @@ 16FE1BC18A9DD0D21CAF2806 /* ScopeRegistryKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2902FD4C1A50263340A51FFB /* ScopeRegistryKeySpec.swift */; }; 1718A1577AB543174FD8E644 /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; 173F76A64BF34826968532DC /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59111BE319C59E4CD6CF68CD /* Assembler.swift */; }; - 187BD516162B3FBB1158E015 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 359BCD3DA6F0CC2241878C82 /* EmploymentAssembly.swift */; }; 18A07EB6FB61F3CDCC766AF4 /* ScopeRegistryKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */; }; 192278AA7165EC3C2C12A4C2 /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; 196AA219BB35334B07B34F37 /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */; }; 1A03A1D9524E8912AF1CEE11 /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = EA7A547FC60DBD02D132B3E6 /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 1ACC90951353E5F69899A833 /* SimpleBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */; }; 1AD4C43B074F736BBDADA8C9 /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; + 1B29712FD3C5FB3B372EE35F /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */; }; 1C2F5A09F986586F85FAC3E8 /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; 1CFCB38BC4EE2D3AAD40154E /* ScopedBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */; }; 1F256E6920935F88C753F739 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; 1F4FBB9D795CE9D45E5A8BEE /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; 20823C309A5C58900CDFA8C3 /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; 22837E727E47A3B8A588AB78 /* TypeBinderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDA62EEBC79ED2639C93A76B /* TypeBinderSpec.swift */; }; - 2488CDD8D67CAC5C97BDF8B1 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = C11D19C5F01647E4A576514A /* Resolver.swift */; }; + 250B276C7FF6E5FCB194C6BE /* Resolver+LegacyApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A784E2DEC7691D14DDBECD8 /* Resolver+LegacyApi.swift */; }; + 2565CB32BBAD60BD198150C7 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62682D6ED38742996624B041 /* BasicAssembly.swift */; }; 25DE2596CC5387B9353FC204 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */; }; 261D54C316CB625359F7EE97 /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; 26AC238FC2FB5279ABF37C89 /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */; }; 26C8D37F26408DC308A0CDA3 /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; - 2B386345150685F670BF04B1 /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9985BEF966DCBB28B12BE17B /* Person.swift */; }; + 29F709EF28B169C291135C04 /* Resolver+LegacyApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A784E2DEC7691D14DDBECD8 /* Resolver+LegacyApi.swift */; }; 2B571CF2267E90A42D32D264 /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */; }; 2B67E8B80A930E8598FAD10C /* Closable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D0BCCCD61CD9BECC29E064 /* Closable.swift */; }; 2BD8335377FA7F918849C815 /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; - 2BE5AF2623B96992C74970F9 /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BA261FF01C5F5510873B3EC /* Animal.swift */; }; - 2C6047BB84D52FC94F63B7C8 /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBDB67E0FC7B8BEE58EECFBB /* BehaviorFakes.swift */; }; 2CA05A2362E0390075908A32 /* BinderEnvironmentSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */; }; 2D1BB3EDEBEA06A17138B298 /* TaggedTypeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */; }; 2DCEEF373F410202226D2DB5 /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */; }; + 2E962A972989EAEB03ECDDB4 /* ReferenceMakerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 388605A438343F7BB80D521E /* ReferenceMakerSpec.swift */; }; 30BD96CC0333463C71377C4B /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; - 31266C4BA7CE6C3FBAFBACDD /* Container+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE4B1E4BA98573B6FED2D118 /* Container+Logging.swift */; }; 35175F8F168EDB5EB83BD8E9 /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C074BAC560F277E806146C60 /* SimpleBinding.swift */; }; 3547656EF55D129316B7C5E2 /* InstanceMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CADDB3E9E363310028AA5920 /* InstanceMaker.swift */; }; 35847FDC65085C6741D2A132 /* SimpleBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */; }; 375945E6CD15BC4D5C8654C9 /* TaggedTypeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */; }; 377EE35B80E8F91543B52F0C /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; + 37B6C0608A8879226D25585F /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 351C4221896DDB8572BD6CB5 /* Person.swift */; }; 37E07236E0E63570242CE23F /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; 37FE9A9C76DB50ABB28AF9BE /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; - 38FACA739BA59278725FAE67 /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03CDF95C1EAFCD54450B34B6 /* ServiceEntry+TypeForwarding.swift */; }; + 393EC075C105E906430F15DF /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */; }; + 394199DBE804A34B14D9D48C /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61EE5DDBE705B47AFC9A6986 /* LoadAwareAssembly.swift */; }; 39431794D93EA4DDD0BBB2C5 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; 39F9BBD670C944E1331FAB13 /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */; }; 3A149A223FA316F68C0A486A /* NonGeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841D83ADB41363D1E38087B4 /* NonGeneratedMocks.swift */; }; 3A2FE7C2BA76C096122F92ED /* UnboundScopeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 671D5D89472DAFA916814506 /* UnboundScopeSpec.swift */; }; + 3AC304A612ECAED02C58BBF5 /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BFF4BA99493C54260878C4 /* ObjectScope.swift */; }; 3B2E8B8CF4825DB05B0233F8 /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */; }; 3B61931D1E9C0F7D1AAEDDF7 /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92B8E618A08408404FB2A7A /* TypeBinder.swift */; }; 3F04B9C7812B5E21DCE4D36C /* GeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */; }; 3F1FB19A735BE6E1FA749E75 /* SwinjectSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9527A4CA5BCBA7AFA3596757 /* SwinjectSpec.swift */; }; 3F8EA877F153EE374FF8E31A /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = A10187BB3A994165E7FC1528 /* ScopedBinding.swift */; }; + 401A790CF8450924114D89ED /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BFF4BA99493C54260878C4 /* ObjectScope.swift */; }; + 406147FA5D2FBBD2BA9C8FEB /* ContextTranslator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */; }; 418F111C8E128766AC8E33CC /* Closable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D0BCCCD61CD9BECC29E064 /* Closable.swift */; }; 41EEA4724CD401F38F9622E3 /* InstanceMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CADDB3E9E363310028AA5920 /* InstanceMaker.swift */; }; + 4229FBE59AF2769A0BF2ED65 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62682D6ED38742996624B041 /* BasicAssembly.swift */; }; + 42813F8FA6786279AF2C9DC7 /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADA1541ABC1365DFD7E3377F /* Food.swift */; }; + 4374382E77C73DB48164592F /* ReferenceMakerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 388605A438343F7BB80D521E /* ReferenceMakerSpec.swift */; }; 439254FAE8DF567DE9659ADA /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3586A4987B7C7C8122D674E /* SwinjectError.swift */; }; - 4503217DA585B602EDE65742 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1FA0377AF4799D42E9462FA /* BasicAssembly.swift */; }; 462054EB9666775B13C36132 /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */; }; 46A14FAA5AA73BE8A0397707 /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; 4735419DE3D63E556D07C663 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B580B43E1891812C97209 /* Binding.swift */; }; @@ -104,9 +107,6 @@ 4D591BB725EAB0ACF9436900 /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 4DA000959B4D60B509859810 /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; 50B230799AFB8C24D1F5CD5D /* SwinjectSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9527A4CA5BCBA7AFA3596757 /* SwinjectSpec.swift */; }; - 51F2CD3C07148069167AB6E9 /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03CDF95C1EAFCD54450B34B6 /* ServiceEntry+TypeForwarding.swift */; }; - 5329D4D400755935B22C0881 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1FA0377AF4799D42E9462FA /* BasicAssembly.swift */; }; - 5381C2CDA084C5BEF82D7521 /* Container+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C2DBC728B763B04CB25963 /* Container+TypeForwarding.swift */; }; 53DC7093FD7C2FEE16154DED /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */; }; 549227903CFDDF4E8272C691 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; 54A1FEE340AC3A2413876AD2 /* ScopeRegistryKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */; }; @@ -114,29 +114,27 @@ 564B886D2A35AF26FC411922 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; 572CA6A9E19927F5D434BB6F /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; 588A600231D894122A4D9C47 /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; - 58C9D537D453BC7C7DC5C0C1 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 359BCD3DA6F0CC2241878C82 /* EmploymentAssembly.swift */; }; 58CFFB8C98C465B9101AA9A8 /* InstanceMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CADDB3E9E363310028AA5920 /* InstanceMaker.swift */; }; 58F7BDE8BB54898CA690BD24 /* StandardScopeRegistrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */; }; + 5AC3FAAAAB1B899F1661B3D4 /* ContextTranslator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */; }; 5B0ECCEBC6CB23571A9EDA38 /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */; }; 5BBBB5E7162B0429D7332DD4 /* SwinjectSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9527A4CA5BCBA7AFA3596757 /* SwinjectSpec.swift */; }; 5C4C106D138E771C872F5E80 /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; - 5CADD5B13173034498BF4A5F /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BA261FF01C5F5510873B3EC /* Animal.swift */; }; 5CB4448E66F839C3915D6927 /* StandardScopeRegistrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */; }; 5D241BBB39F54B8FA2BFF595 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; 5D2C492FD5088FCB2BA5CDB8 /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92B8E618A08408404FB2A7A /* TypeBinder.swift */; }; 5E74770DDD69EAFE5D187F90 /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; - 5E983707B893B9A8EF94B33E /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBDB67E0FC7B8BEE58EECFBB /* BehaviorFakes.swift */; }; 5F008535F981266945B3968B /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B3797A6BB56AE76CEC19F2A /* SwinjectApiSpec.swift */; }; + 5FCE3C447CE0CD2211A5EB3D /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */; }; 60467C140BE3C99C1B872A55 /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 823617F3B8A9192F56B13331 /* Quick.framework */; }; - 60AF45155775AA5E97AAB5C1 /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEE8FDF4B975A8F2A9FCC5FF /* Food.swift */; }; - 60CEB9FCA08EFF202DD38096 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1FA0377AF4799D42E9462FA /* BasicAssembly.swift */; }; + 61BBC25BC709F5A57CC592BA /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59A3946B59EB4D787CCE9F2 /* Container+Registration.swift */; }; 627F366F03B0D6E549AAE98F /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ADD71387EBA54D7EF60D0089 /* Swinject.framework */; }; 62986D0AAAE9D3934E125332 /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; + 648CB5DEA239EA225A39A20A /* Container+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDA78290D6D60BD0B808571F /* Container+Logging.swift */; }; 648FDC2A1E3DC75CB47D31E1 /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; 64A8413AD2ED65BB25BD0113 /* BindingKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = A24B4E8F1CA18603DBB6884A /* BindingKey.swift */; }; 64BC606D6414CB4BE8834B08 /* GeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */; }; 65764CCFA94D4C0A0822507A /* UnboundScopeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 671D5D89472DAFA916814506 /* UnboundScopeSpec.swift */; }; - 66033468A5FC65C19B60086A /* Resolver+LegacyApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07B4728F7C73CC5530956A2 /* Resolver+LegacyApi.swift */; }; 661B5A18940BA6E67D9BA65E /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; 67A89300EA08B0FB7AB0FBF8 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; 68A42DF14E0117A95B44148F /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C765B92B00C0AC8625BB4AC9 /* Quick.framework */; }; @@ -146,45 +144,44 @@ 6F5323F408E5708076C02768 /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = A10187BB3A994165E7FC1528 /* ScopedBinding.swift */; }; 70268F222B8478BDC084E211 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; 705F51FD21F7E1536BFC0C41 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B580B43E1891812C97209 /* Binding.swift */; }; - 71674FB84CBE1E97B72123BF /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9985BEF966DCBB28B12BE17B /* Person.swift */; }; 71C4A75D54446D844BA5FB85 /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; 73214A0BF7D4AE8B78DEB4FD /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = A10187BB3A994165E7FC1528 /* ScopedBinding.swift */; }; 741344C30785507B22DF703B /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; - 7472B748AEA9F4D1E5EF9A70 /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C13D01A2DE6F53DF3175D22 /* Container+Registration.swift */; }; 7480A500FEC04BB9CB048AE1 /* BinderEnvironmentSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */; }; - 782801544D9F468F536E045E /* Container+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C2DBC728B763B04CB25963 /* Container+TypeForwarding.swift */; }; 7845113EAF8FFAFD5EC10540 /* BindingKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */; }; 788AE378F10DA216265FFF52 /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; - 78ACD9EBF8625ECD24103A17 /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03CDF95C1EAFCD54450B34B6 /* ServiceEntry+TypeForwarding.swift */; }; - 7DD047C203659BCA7F04E48D /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C13D01A2DE6F53DF3175D22 /* Container+Registration.swift */; }; - 7E0539C5CD130F0AC4B02096 /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C13D01A2DE6F53DF3175D22 /* Container+Registration.swift */; }; + 78D311E69E44F242CCB66287 /* Reference.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73B4B777290FF5D38A8914CC /* Reference.swift */; }; + 791591AEE261B40F4A04BA07 /* ContextTranslator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */; }; + 79772C34E5102A8E3003DBF8 /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BFF4BA99493C54260878C4 /* ObjectScope.swift */; }; + 7C4EDB197C821D1A7FE1FAB3 /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 351C4221896DDB8572BD6CB5 /* Person.swift */; }; 7E9CB14F7E723994920F6E44 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 34AFFAC41BA9D02A38BDB7A3 /* Nimble.framework */; }; - 7F22099B321798EAD85DBC07 /* Container+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C2DBC728B763B04CB25963 /* Container+TypeForwarding.swift */; }; - 8108969F33C37040624E0D02 /* Resolver+LegacyApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07B4728F7C73CC5530956A2 /* Resolver+LegacyApi.swift */; }; 816F47E9D87CAE910091B484 /* Closable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D0BCCCD61CD9BECC29E064 /* Closable.swift */; }; 828C5B0915A8D08CF98F5F4C /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; - 833635A5D695AA696559C250 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 359BCD3DA6F0CC2241878C82 /* EmploymentAssembly.swift */; }; + 846CA938C957BA8623D2069C /* Container+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDA78290D6D60BD0B808571F /* Container+Logging.swift */; }; 86BE1ED67D6C0A493A9F141A /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 683A1FB7D7F4E9508D57E936 /* Quick.framework */; }; 86CD1F46C15A352BCF7CE396 /* ScopeRegistryKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2902FD4C1A50263340A51FFB /* ScopeRegistryKeySpec.swift */; }; 86E1845B6272AF95F1806CB4 /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; 87056684D7F91917F6B0AC7A /* BinderEnvironmentSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */; }; 871BB9B8221656F0189ABEC6 /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; 876F90C64EA036596E797CB3 /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; + 87C665DAF0CC607F0D022B50 /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BC5108ED11A3A3084D864CC /* Animal.swift */; }; 87F8C64D9E8B4317C0C036E0 /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C074BAC560F277E806146C60 /* SimpleBinding.swift */; }; + 886D2A54B2857FF52AB5CA56 /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59A3946B59EB4D787CCE9F2 /* Container+Registration.swift */; }; 89613FDC2024EE34FD246A16 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ADC44E9312C3B974AFD8F07B /* Nimble.framework */; }; 89D83D5E42814659DFE8F518 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; 89F0AA65C3C9837A0A2452DF /* Quick.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = C765B92B00C0AC8625BB4AC9 /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 8A212C0486A514CF17B5F140 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */; }; 8AAC0C68038E02A6049ABDC0 /* StandardScopeRegistrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */; }; 8AEB5894656086C3E2F022FD /* SimpleBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */; }; 8D58DF5C6963153A8B17D325 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; 8D71D83DB3F5D3655FB6C71D /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C074BAC560F277E806146C60 /* SimpleBinding.swift */; }; 8E1BBA6F7B45E1DF056670AC /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 273FB7A6277E0841E1570990 /* Nimble.framework */; }; + 8E92150DFA758FD3E32CC0A7 /* ContextTranslator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */; }; 8E9E1BD32B056F472DA14E51 /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1C58FC14EEA170B0DC079DE4 /* Quick.framework */; }; 8F48909C95AA648D056A392B /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; 8F70C49F6F6D27A67CDB8F0C /* TypeBinderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDA62EEBC79ED2639C93A76B /* TypeBinderSpec.swift */; }; 908AE547955AE4432C1D161A /* ServiceEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38615FC8EEB466C5C1EAD21C /* ServiceEntry.swift */; }; 90B4143005C86717AC76B6EE /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; - 9102F98F672DD39F304AFC3B /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9985BEF966DCBB28B12BE17B /* Person.swift */; }; 91DAE32F86CEA897AD52AEDB /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42490D1D0C395951243F5CFF /* Container.swift */; }; 91FED72828F68263D599B6C0 /* SimpleBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */; }; 920EF7689DA7C81235B75CE7 /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 34AFFAC41BA9D02A38BDB7A3 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -197,14 +194,11 @@ 9623C7F8B9FED0541D959708 /* ScopeRegistryKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2902FD4C1A50263340A51FFB /* ScopeRegistryKeySpec.swift */; }; 963D32297EE5CA9C18A0C246 /* NonGeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841D83ADB41363D1E38087B4 /* NonGeneratedMocks.swift */; }; 971B97F191A9FF75A6586E0A /* ScopeRegistryKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */; }; - 982E4682C79B74226C03E0C9 /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03CDF95C1EAFCD54450B34B6 /* ServiceEntry+TypeForwarding.swift */; }; - 9A551D43739EDE556FF3F9ED /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBDB67E0FC7B8BEE58EECFBB /* BehaviorFakes.swift */; }; + 9925498BDD0C9CA36116292F /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61EE5DDBE705B47AFC9A6986 /* LoadAwareAssembly.swift */; }; 9AFDF0122A11B2E996B16C3D /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; - 9B04477B2B117122CB99989A /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1910A1471C3CA9EA86F350BA /* LoadAwareAssembly.swift */; }; 9B83FF80C5BE658ED0F7B709 /* ScopedBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */; }; 9B9AA902B80620568D732D7B /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; 9C08C2D57E0B0B46D5748B6C /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; - 9CEF62C5A3EC3CB8034F08BB /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1910A1471C3CA9EA86F350BA /* LoadAwareAssembly.swift */; }; 9D1AD9CBA32CEE29EF6C68C2 /* GeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */; }; 9DD1C1273B38FCF4FFE9BCC2 /* BindingKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */; }; 9E084F679592ADFA28D3AD6D /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; @@ -213,8 +207,9 @@ A014793C56F8966AD2D7CC50 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; A19EFC58B60E547CC3A3A6BE /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 74DE57FB3E8228904E6FE0D7 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; A1B275A2EFA22C45AC46B31E /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; - A3815641CEB5A06759D288E0 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = C11D19C5F01647E4A576514A /* Resolver.swift */; }; - A4490FF7ACCC5CBFB2C1896C /* Container+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE4B1E4BA98573B6FED2D118 /* Container+Logging.swift */; }; + A24F290A74A85DD34BE05141 /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61EE5DDBE705B47AFC9A6986 /* LoadAwareAssembly.swift */; }; + A3F070412E120E31DB0529FB /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59A3946B59EB4D787CCE9F2 /* Container+Registration.swift */; }; + A4432BDF84F354954D3C4597 /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADA1541ABC1365DFD7E3377F /* Food.swift */; }; A44D1B2E48E1C0FEF146933A /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; A4866802E1E597EEFEFDEB66 /* BindingKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = A24B4E8F1CA18603DBB6884A /* BindingKey.swift */; }; A4C25E4406175163B7C5B810 /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B3797A6BB56AE76CEC19F2A /* SwinjectApiSpec.swift */; }; @@ -222,50 +217,50 @@ A4EA3E548D1CAB029697B0A9 /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; A54B018EF21348D600F8ABD2 /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */; }; A600D3F52D38EBC5A3C75CC2 /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */; }; + A6E0CFB53B2EEAE0E89084E2 /* Reference.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73B4B777290FF5D38A8914CC /* Reference.swift */; }; + A9C0FE53F80BF341EA1F0B04 /* ReferenceMakerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 388605A438343F7BB80D521E /* ReferenceMakerSpec.swift */; }; AA6651CFD4090465E7CB7871 /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCAF491EC7DCD7477F9A0ECB /* SwinjectModule.swift */; }; AAB6386F88442B22E9F7FF0E /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42490D1D0C395951243F5CFF /* Container.swift */; }; AAC84D757FE8F601FF053923 /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3586A4987B7C7C8122D674E /* SwinjectError.swift */; }; + AB8A04BA95434DF26D637B47 /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 351C4221896DDB8572BD6CB5 /* Person.swift */; }; + AD89FFF56D87A23AD74BC7F1 /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BC5108ED11A3A3084D864CC /* Animal.swift */; }; + AEEF98CB6977B472C384BC82 /* Resolver+LegacyApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A784E2DEC7691D14DDBECD8 /* Resolver+LegacyApi.swift */; }; + AF1BA0CE40742BA6C19320B5 /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EA566CD336DB8343ADFAF9B /* BehaviorFakes.swift */; }; AF5F860DBFE2607EF4157CF7 /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; B1B107E3FA2DC2E985160D75 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; B1B1A13B6792198E4E835034 /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */; }; B2FCC51BB61148422256A14A /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; + B40F2E0BF341A31ADA195CB0 /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EA566CD336DB8343ADFAF9B /* BehaviorFakes.swift */; }; + B446D0B72AED8D4E051FF57B /* Reference.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73B4B777290FF5D38A8914CC /* Reference.swift */; }; B5048A00D49FD5C1C098EE01 /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; B61FAC17826BAFD2DC1C0E5E /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; B7CE6F32765FC472CE205458 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; + B85ADC1EA6298966819FD6D0 /* Container+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F446D6BD4C44E16A1D608BFB /* Container+TypeForwarding.swift */; }; B95786317494375C0E2D2044 /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; + B9B7AF8C0E13B9D80635F1EF /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61EE5DDBE705B47AFC9A6986 /* LoadAwareAssembly.swift */; }; B9FAEC69210B352FC744079E /* TypeBinderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDA62EEBC79ED2639C93A76B /* TypeBinderSpec.swift */; }; BAFD66351A9ED8E7BFB19CD3 /* NonGeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841D83ADB41363D1E38087B4 /* NonGeneratedMocks.swift */; }; + BAFE51FEADADF31B0DB513A6 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62682D6ED38742996624B041 /* BasicAssembly.swift */; }; BB3AAADF214D5FF3E25E3974 /* SwinjectSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9527A4CA5BCBA7AFA3596757 /* SwinjectSpec.swift */; }; + C032FA4CB2D35904C513D27A /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */; }; C0CCC43D2CDFF01CF0FF9F89 /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = ADC44E9312C3B974AFD8F07B /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; C15318646655D97EBDCAA67B /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B3797A6BB56AE76CEC19F2A /* SwinjectApiSpec.swift */; }; + C295515C38C93A82B7F54915 /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADA1541ABC1365DFD7E3377F /* Food.swift */; }; C37B885879F0D716B36E1C5B /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 74DE57FB3E8228904E6FE0D7 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; C3AD37D47C38E5EB20FAF917 /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; C50BFD826112288F1D693A30 /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; + C6D9ADDCEBD26C3DF6DAD4D9 /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59A3946B59EB4D787CCE9F2 /* Container+Registration.swift */; }; C6ED278B6F0E08A4B1E57C45 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; C797CCF413DF181935DAB58C /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; C7BB5752C697E748B828C03B /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; C8F1F075F5792C9936B0577D /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42490D1D0C395951243F5CFF /* Container.swift */; }; + C9B440CFC0B944D25F7EE57E /* Container+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F446D6BD4C44E16A1D608BFB /* Container+TypeForwarding.swift */; }; C9DD3F5C59F6A8833279F790 /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6EA4ECB5E4CEC9751AD36854 /* Swinject.framework */; }; CA202C787FE269EF63ADC449 /* TaggedTypeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */; }; - CD4D866522E4C8A50042ACDC /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD4D866322E4C6DB0042ACDC /* ObjectScope.swift */; }; - CD4D866622E4C8A70042ACDC /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD4D866322E4C6DB0042ACDC /* ObjectScope.swift */; }; - CD4D866722E4C8A80042ACDC /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD4D866322E4C6DB0042ACDC /* ObjectScope.swift */; }; - CD4D866822E4C8A80042ACDC /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD4D866322E4C6DB0042ACDC /* ObjectScope.swift */; }; - CDF8F35622E64694008B2AF5 /* ContextTranslator.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDF8F35522E64694008B2AF5 /* ContextTranslator.swift */; }; - CDF8F35722E64694008B2AF5 /* ContextTranslator.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDF8F35522E64694008B2AF5 /* ContextTranslator.swift */; }; - CDF8F35822E64694008B2AF5 /* ContextTranslator.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDF8F35522E64694008B2AF5 /* ContextTranslator.swift */; }; - CDF8F35922E64694008B2AF5 /* ContextTranslator.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDF8F35522E64694008B2AF5 /* ContextTranslator.swift */; }; - CDF8F36522E8D881008B2AF5 /* Reference.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDF8F36422E8D881008B2AF5 /* Reference.swift */; }; - CDF8F36622E8D881008B2AF5 /* Reference.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDF8F36422E8D881008B2AF5 /* Reference.swift */; }; - CDF8F36722E8D881008B2AF5 /* Reference.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDF8F36422E8D881008B2AF5 /* Reference.swift */; }; - CDF8F36822E8D881008B2AF5 /* Reference.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDF8F36422E8D881008B2AF5 /* Reference.swift */; }; - CDF8F36A22E8D89E008B2AF5 /* ReferenceMakerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDF8F36922E8D89E008B2AF5 /* ReferenceMakerSpec.swift */; }; - CDF8F36B22E8D89E008B2AF5 /* ReferenceMakerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDF8F36922E8D89E008B2AF5 /* ReferenceMakerSpec.swift */; }; - CDF8F36C22E8D89E008B2AF5 /* ReferenceMakerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDF8F36922E8D89E008B2AF5 /* ReferenceMakerSpec.swift */; }; - CDF8F36D22E8D89E008B2AF5 /* ReferenceMakerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDF8F36922E8D89E008B2AF5 /* ReferenceMakerSpec.swift */; }; CFC3CDB46CD8FFA22EB0FADD /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A0157DBBD5E1F45963BB0932 /* Swinject.framework */; }; - D10FFA4B80F4BE6024B1DCEE /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1910A1471C3CA9EA86F350BA /* LoadAwareAssembly.swift */; }; + D0BA6CF98B7F0ECE9FA95055 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */; }; D18275ADB0E56D3087894518 /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; + D1DB8BA2F9F0B832865688E6 /* Container+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDA78290D6D60BD0B808571F /* Container+Logging.swift */; }; D2391A103E7356AD7E08F5BA /* ScopedBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */; }; D267BD55BBEDE3ECEC449472 /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; D3828F01A014F3A06B1141D7 /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; @@ -273,56 +268,61 @@ D4939ABFFDAE2A5768D23C65 /* StandardScopeRegistrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */; }; D557A108A21751DF75542692 /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; D5BD321738E03967CA8E27C6 /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; + D688F61360D46A16B0678BA4 /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BFF4BA99493C54260878C4 /* ObjectScope.swift */; }; D6AA597218691F1FE87724E7 /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = A10187BB3A994165E7FC1528 /* ScopedBinding.swift */; }; + D7313C07419E511B66E5A56C /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADA1541ABC1365DFD7E3377F /* Food.swift */; }; D7D5560E4F790F41126F61CF /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; D7DE20CC15F3A6BD09E43A75 /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; D7DFD1B77BFB5FABAE165A11 /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; + D815847229F70F0AE7D0D2F9 /* Container+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F446D6BD4C44E16A1D608BFB /* Container+TypeForwarding.swift */; }; D86ACC6D9B9C62FF398F8293 /* TaggedTypeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */; }; D88D7841C5C84A2E34CE15FD /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92B8E618A08408404FB2A7A /* TypeBinder.swift */; }; - D98CA679A3AAC176D291CA8E /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEE8FDF4B975A8F2A9FCC5FF /* Food.swift */; }; - DA6CB0A98FE5968CAAFDE9BF /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9985BEF966DCBB28B12BE17B /* Person.swift */; }; + D9A92063A905E6EDBEA6B7CF /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62682D6ED38742996624B041 /* BasicAssembly.swift */; }; + DAFA9AE69744F3C5DC71CF50 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */; }; DB14CA46130A816F6FAADE92 /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C074BAC560F277E806146C60 /* SimpleBinding.swift */; }; - DC5C3A946BDA224C388D2438 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 359BCD3DA6F0CC2241878C82 /* EmploymentAssembly.swift */; }; DD1B936DC7365917DCA09FC8 /* Quick.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 823617F3B8A9192F56B13331 /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; DD4783AE23A8C2A89F591605 /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59111BE319C59E4CD6CF68CD /* Assembler.swift */; }; DE0A534B660AA93F73A2CB41 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; DEB3F135FFAEBF825881E886 /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; + E02056E5E8F896E3C330B531 /* Container+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F446D6BD4C44E16A1D608BFB /* Container+TypeForwarding.swift */; }; E0D7B3285AA1FE51E14A52A1 /* BindingKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = A24B4E8F1CA18603DBB6884A /* BindingKey.swift */; }; + E2594F32273350049629A349 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */; }; E34C98A8BF87513994A6AD86 /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; E423395FC7006DD82513F347 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; E484C3994AD91E91C454B11D /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; E584841CFD26155FB056C85A /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; - E7E9DE84E1861D125F8D686A /* Resolver+LegacyApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07B4728F7C73CC5530956A2 /* Resolver+LegacyApi.swift */; }; + E62C6509D0B52001CC309068 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */; }; E80558941BC2149C25A17495 /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; + E81B712F36E326A7905272F3 /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BC5108ED11A3A3084D864CC /* Animal.swift */; }; E8A89383E1D1106DEABB778B /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; E8D70420E8A3C91D01BC3B5B /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; - E9F5DF3C8AA3A9651D504AF7 /* Container+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE4B1E4BA98573B6FED2D118 /* Container+Logging.swift */; }; + EA5AC0A3555E0D65D178ED82 /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */; }; EABC31077D2369311E6C14C3 /* ServiceEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38615FC8EEB466C5C1EAD21C /* ServiceEntry.swift */; }; EAC4EA9BAC87B34AD5BA2110 /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3586A4987B7C7C8122D674E /* SwinjectError.swift */; }; EAD0757CE0163D3549CB5405 /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; - EC4EE4B0AECDBA8EC0B8F73D /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BA261FF01C5F5510873B3EC /* Animal.swift */; }; - EE5763938068B3FA56D1BA59 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = C11D19C5F01647E4A576514A /* Resolver.swift */; }; + EC19876AC6526691345DA389 /* ReferenceMakerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 388605A438343F7BB80D521E /* ReferenceMakerSpec.swift */; }; + EC3E297BC24CB5D39A731136 /* Reference.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73B4B777290FF5D38A8914CC /* Reference.swift */; }; + EC6830FA962E84DD737D8885 /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EA566CD336DB8343ADFAF9B /* BehaviorFakes.swift */; }; + EC6D316B79FE51336B771139 /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BC5108ED11A3A3084D864CC /* Animal.swift */; }; EEB1E43EF50551F8B9793381 /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59111BE319C59E4CD6CF68CD /* Assembler.swift */; }; EEB3FA667B9103A8417F5EA4 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; EEC04BEF02E6776003CC2003 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B580B43E1891812C97209 /* Binding.swift */; }; EEE1C6EB43E2F4D480A7156A /* TypeBinderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDA62EEBC79ED2639C93A76B /* TypeBinderSpec.swift */; }; EF25C3A81E568411233E6867 /* ServiceEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38615FC8EEB466C5C1EAD21C /* ServiceEntry.swift */; }; - EFCA30870DA55BC3572AF634 /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BA261FF01C5F5510873B3EC /* Animal.swift */; }; EFE89A258FE9EDFFE5F88FD0 /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 74DE57FB3E8228904E6FE0D7 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; - F151A5040BB76E8E909D9D6B /* Container+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE4B1E4BA98573B6FED2D118 /* Container+Logging.swift */; }; F1D5D6A0A7679A14317617E1 /* GeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */; }; - F4D2218805AEBF797A2945AB /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEE8FDF4B975A8F2A9FCC5FF /* Food.swift */; }; F4D7CC563B9C212A418C4EBC /* ScopeRegistryKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2902FD4C1A50263340A51FFB /* ScopeRegistryKeySpec.swift */; }; - F50BA96120EDA5D470F4265C /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBDB67E0FC7B8BEE58EECFBB /* BehaviorFakes.swift */; }; F7F9B3DB89AC8EC05B6A2B89 /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; F8DB4EDA0367BCC6832E4AA6 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; + F96FD82F093567BA0CB891F1 /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */; }; FAF8F8B75F63D43995A004E8 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; FB6FF5C5729B8E050616CCF6 /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 6EA4ECB5E4CEC9751AD36854 /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - FC120C659D0A6FB9CE757CB7 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = C11D19C5F01647E4A576514A /* Resolver.swift */; }; + FC07362CFB0C849BD5A7B4BC /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EA566CD336DB8343ADFAF9B /* BehaviorFakes.swift */; }; FCBA6B66A6BBA29B3EC6CDDD /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; + FCBDE573A9BBFC0245D25895 /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */; }; FD1678ED0C9813A653D9C68B /* BinderEnvironmentSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */; }; FDB7873663CEFBF7BE76ECFF /* BindingKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = A24B4E8F1CA18603DBB6884A /* BindingKey.swift */; }; - FDCF96E2A442CDC6815B8127 /* Resolver+LegacyApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07B4728F7C73CC5530956A2 /* Resolver+LegacyApi.swift */; }; + FDF173EB90F7764887841A6B /* Container+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDA78290D6D60BD0B808571F /* Container+Logging.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -412,16 +412,14 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 03CDF95C1EAFCD54450B34B6 /* ServiceEntry+TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ServiceEntry+TypeForwarding.swift"; sourceTree = ""; }; 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.swift; sourceTree = ""; }; 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopedBindingSpec.swift; sourceTree = ""; }; 0E0B580B43E1891812C97209 /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; 10480F2154EAA0414D4C1F55 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .swiftlint.yml; sourceTree = ""; }; + 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */ = {isa = PBXFileReference; path = .swiftlint.yml; sourceTree = ""; }; 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SynchronizedResolverSpec.swift; sourceTree = ""; }; 13513FA012659ADE699A3608 /* LazySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LazySpec.swift; sourceTree = ""; }; 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleBindingSpec.swift; sourceTree = ""; }; - 1910A1471C3CA9EA86F350BA /* LoadAwareAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadAwareAssembly.swift; sourceTree = ""; }; 1AAFEBED373D3DD8E29B1131 /* SwinjectTests.xctest */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.cfbundle; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 1B3797A6BB56AE76CEC19F2A /* SwinjectApiSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectApiSpec.swift; sourceTree = ""; }; 1C58FC14EEA170B0DC079DE4 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; @@ -432,79 +430,76 @@ 2902FD4C1A50263340A51FFB /* ScopeRegistryKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistryKeySpec.swift; sourceTree = ""; }; 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; 34AFFAC41BA9D02A38BDB7A3 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; - 359BCD3DA6F0CC2241878C82 /* EmploymentAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmploymentAssembly.swift; sourceTree = ""; }; + 351C4221896DDB8572BD6CB5 /* Person.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Person.swift; sourceTree = ""; }; 36322E7DDA56C7E6DF006787 /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 36BFF4BA99493C54260878C4 /* ObjectScope.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObjectScope.swift; sourceTree = ""; }; 38615FC8EEB466C5C1EAD21C /* ServiceEntry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServiceEntry.swift; sourceTree = ""; }; 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Swinject+Builder.swift"; sourceTree = ""; }; + 388605A438343F7BB80D521E /* ReferenceMakerSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReferenceMakerSpec.swift; sourceTree = ""; }; 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaggedTypeSpec.swift; sourceTree = ""; }; 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingKeySpec.swift; sourceTree = ""; }; 42490D1D0C395951243F5CFF /* Container.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.swift; sourceTree = ""; }; + 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmploymentAssembly.swift; sourceTree = ""; }; 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTree.swift; sourceTree = ""; }; 494AA2AA587975747596C157 /* ProviderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProviderSpec.swift; sourceTree = ""; }; + 4A784E2DEC7691D14DDBECD8 /* Resolver+LegacyApi.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Resolver+LegacyApi.swift"; sourceTree = ""; }; + 4BC5108ED11A3A3084D864CC /* Animal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Animal.swift; sourceTree = ""; }; 5057BAB33984E3E33469452B /* Scope.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Scope.swift; sourceTree = ""; }; 5543571F82B41D79C35A0871 /* SwinjectTests.xctest */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.cfbundle; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Resolver+Injection.swift"; sourceTree = ""; }; 59111BE319C59E4CD6CF68CD /* Assembler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Assembler.swift; sourceTree = ""; }; 5AB605ED0F735221D0EB1D5F /* Convenience.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Convenience.swift; sourceTree = ""; }; 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Matchable.swift; sourceTree = ""; }; + 5EA566CD336DB8343ADFAF9B /* BehaviorFakes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BehaviorFakes.swift; sourceTree = ""; }; 5F7BC1C4169BB4382C6D3E1F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 61EE5DDBE705B47AFC9A6986 /* LoadAwareAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadAwareAssembly.swift; sourceTree = ""; }; + 62682D6ED38742996624B041 /* BasicAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BasicAssembly.swift; sourceTree = ""; }; 65D0BCCCD61CD9BECC29E064 /* Closable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Closable.swift; sourceTree = ""; }; 671D5D89472DAFA916814506 /* UnboundScopeSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnboundScopeSpec.swift; sourceTree = ""; }; 683A1FB7D7F4E9508D57E936 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceWrapper.swift; sourceTree = ""; }; - 6C13D01A2DE6F53DF3175D22 /* Container+Registration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Registration.swift"; sourceTree = ""; }; 6EA4ECB5E4CEC9751AD36854 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 722CAC1761180366DE75A4A6 /* TestModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestModels.swift; sourceTree = ""; }; + 73B4B777290FF5D38A8914CC /* Reference.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Reference.swift; sourceTree = ""; }; 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.CustomStringConvertible.swift; sourceTree = ""; }; 74DE57FB3E8228904E6FE0D7 /* Swinject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Swinject.h; sourceTree = ""; }; - 7BA261FF01C5F5510873B3EC /* Animal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Animal.swift; sourceTree = ""; }; + 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ServiceEntry+TypeForwarding.swift"; sourceTree = ""; }; + 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextTranslator.swift; sourceTree = ""; }; 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistry.swift; sourceTree = ""; }; 823617F3B8A9192F56B13331 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; 841D83ADB41363D1E38087B4 /* NonGeneratedMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonGeneratedMocks.swift; sourceTree = ""; }; 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeneratedMocks.swift; sourceTree = ""; }; 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTreeBuilderSpec.swift; sourceTree = ""; }; 9527A4CA5BCBA7AFA3596757 /* SwinjectSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectSpec.swift; sourceTree = ""; }; - 95C2DBC728B763B04CB25963 /* Container+TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+TypeForwarding.swift"; sourceTree = ""; }; 9620155728133F451B31C0AD /* Swinject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Swinject.swift; sourceTree = ""; }; 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistryKey.swift; sourceTree = ""; }; - 9985BEF966DCBB28B12BE17B /* Person.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Person.swift; sourceTree = ""; }; A0157DBBD5E1F45963BB0932 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; A10187BB3A994165E7FC1528 /* ScopedBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopedBinding.swift; sourceTree = ""; }; A24B4E8F1CA18603DBB6884A /* BindingKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingKey.swift; sourceTree = ""; }; A3586A4987B7C7C8122D674E /* SwinjectError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectError.swift; sourceTree = ""; }; + A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Resolver.swift; sourceTree = ""; }; ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Circularity.swift; sourceTree = ""; }; + ADA1541ABC1365DFD7E3377F /* Food.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Food.swift; sourceTree = ""; }; ADC44E9312C3B974AFD8F07B /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; ADD71387EBA54D7EF60D0089 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AssemblerSpec.swift; sourceTree = ""; }; + B59A3946B59EB4D787CCE9F2 /* Container+Registration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Registration.swift"; sourceTree = ""; }; B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderEnvironment.swift; sourceTree = ""; }; B92B8E618A08408404FB2A7A /* TypeBinder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinder.swift; sourceTree = ""; }; BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StandardScopeRegistrySpec.swift; sourceTree = ""; }; - BBDB67E0FC7B8BEE58EECFBB /* BehaviorFakes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BehaviorFakes.swift; sourceTree = ""; }; - BE4B1E4BA98573B6FED2D118 /* Container+Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Logging.swift"; sourceTree = ""; }; BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Behavior.swift; sourceTree = ""; }; C074BAC560F277E806146C60 /* SimpleBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleBinding.swift; sourceTree = ""; }; - C07B4728F7C73CC5530956A2 /* Resolver+LegacyApi.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Resolver+LegacyApi.swift"; sourceTree = ""; }; - C11D19C5F01647E4A576514A /* Resolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Resolver.swift; sourceTree = ""; }; C765B92B00C0AC8625BB4AC9 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; CADDB3E9E363310028AA5920 /* InstanceMaker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceMaker.swift; sourceTree = ""; }; CC85CB215058F95C0BC190B1 /* Bridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bridge.swift; sourceTree = ""; }; - CD38F90522E4EC1400A9EEFF /* .swiftlint.yml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = .swiftlint.yml; sourceTree = ""; }; - CD4D866322E4C6DB0042ACDC /* ObjectScope.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObjectScope.swift; sourceTree = ""; }; - CD4D866B22E4D4E00042ACDC /* AutoMockable.stencil */ = {isa = PBXFileReference; lastKnownFileType = text; path = AutoMockable.stencil; sourceTree = ""; }; - CD4D866C22E4D54D0042ACDC /* Resolver+LegacyApi.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+LegacyApi.swifttemplate"; sourceTree = ""; }; - CD4D866D22E4D54D0042ACDC /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; - CD4D866F22E4D54D0042ACDC /* ServiceEntry+TypeForwarding.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "ServiceEntry+TypeForwarding.swifttemplate"; sourceTree = ""; }; - CDF8F35522E64694008B2AF5 /* ContextTranslator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextTranslator.swift; sourceTree = ""; }; - CDF8F36422E8D881008B2AF5 /* Reference.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Reference.swift; sourceTree = ""; }; - CDF8F36922E8D89E008B2AF5 /* ReferenceMakerSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReferenceMakerSpec.swift; sourceTree = ""; }; - D1FA0377AF4799D42E9462FA /* BasicAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BasicAssembly.swift; sourceTree = ""; }; + CDA78290D6D60BD0B808571F /* Container+Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Logging.swift"; sourceTree = ""; }; E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRequest.swift; sourceTree = ""; }; E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; EA7A547FC60DBD02D132B3E6 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; ECE2B2EFBFDA910758EE1CA5 /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; EDA62EEBC79ED2639C93A76B /* TypeBinderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinderSpec.swift; sourceTree = ""; }; - EEE8FDF4B975A8F2A9FCC5FF /* Food.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Food.swift; sourceTree = ""; }; F290F6B1207A0557A528220B /* Assembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Assembly.swift; sourceTree = ""; }; + F446D6BD4C44E16A1D608BFB /* Container+TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+TypeForwarding.swift"; sourceTree = ""; }; F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.TypeForwarding.swift; sourceTree = ""; }; FCAF491EC7DCD7477F9A0ECB /* SwinjectModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectModule.swift; sourceTree = ""; }; FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderEnvironmentSpec.swift; sourceTree = ""; }; @@ -557,9 +552,9 @@ 0A05322134E988A4593B5122 /* Unit Specs */ = { isa = PBXGroup; children = ( - CDF8F36922E8D89E008B2AF5 /* ReferenceMakerSpec.swift */, FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */, 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */, + 388605A438343F7BB80D521E /* ReferenceMakerSpec.swift */, 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */, 2902FD4C1A50263340A51FFB /* ScopeRegistryKeySpec.swift */, 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */, @@ -573,6 +568,20 @@ path = "Unit Specs"; sourceTree = ""; }; + 1F06930A1A2C8BA94D6875BA /* Legacy */ = { + isa = PBXGroup; + children = ( + 4BC5108ED11A3A3084D864CC /* Animal.swift */, + 62682D6ED38742996624B041 /* BasicAssembly.swift */, + 5EA566CD336DB8343ADFAF9B /* BehaviorFakes.swift */, + 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */, + ADA1541ABC1365DFD7E3377F /* Food.swift */, + 61EE5DDBE705B47AFC9A6986 /* LoadAwareAssembly.swift */, + 351C4221896DDB8572BD6CB5 /* Person.swift */, + ); + path = Legacy; + sourceTree = ""; + }; 2B85A6F2D9BDA29BD0BA73F8 /* Mac */ = { isa = PBXGroup; children = ( @@ -606,12 +615,12 @@ 4F46C48FA15F512EAED5F67A /* Support */ = { isa = PBXGroup; children = ( - CD4D866922E4CD990042ACDC /* 2.0 */, CC85CB215058F95C0BC190B1 /* Bridge.swift */, 5AB605ED0F735221D0EB1D5F /* Convenience.swift */, 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */, 841D83ADB41363D1E38087B4 /* NonGeneratedMocks.swift */, 722CAC1761180366DE75A4A6 /* TestModels.swift */, + 1F06930A1A2C8BA94D6875BA /* Legacy */, ); path = Support; sourceTree = ""; @@ -622,15 +631,15 @@ 59111BE319C59E4CD6CF68CD /* Assembler.swift */, F290F6B1207A0557A528220B /* Assembly.swift */, 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */, - 6C13D01A2DE6F53DF3175D22 /* Container+Registration.swift */, - BE4B1E4BA98573B6FED2D118 /* Container+Logging.swift */, 42490D1D0C395951243F5CFF /* Container.swift */, - 95C2DBC728B763B04CB25963 /* Container+TypeForwarding.swift */, + CDA78290D6D60BD0B808571F /* Container+Logging.swift */, + B59A3946B59EB4D787CCE9F2 /* Container+Registration.swift */, + F446D6BD4C44E16A1D608BFB /* Container+TypeForwarding.swift */, 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */, - CD4D866322E4C6DB0042ACDC /* ObjectScope.swift */, - C07B4728F7C73CC5530956A2 /* Resolver+LegacyApi.swift */, + 36BFF4BA99493C54260878C4 /* ObjectScope.swift */, + 4A784E2DEC7691D14DDBECD8 /* Resolver+LegacyApi.swift */, 38615FC8EEB466C5C1EAD21C /* ServiceEntry.swift */, - 03CDF95C1EAFCD54450B34B6 /* ServiceEntry+TypeForwarding.swift */, + 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */, ); path = "2.0 API"; sourceTree = ""; @@ -687,10 +696,8 @@ A4F7E56739BB9CB479DDDBF6 = { isa = PBXGroup; children = ( - CD38F90522E4EC1400A9EEFF /* .swiftlint.yml */, D026A6699A2A932511D29E14 /* Sources */, C5602A1B64E47775AF8D5700 /* Tests */, - CD4D866A22E4D4E00042ACDC /* Templates */, 80E97D8FD5574A96B6BC9EB9 /* Frameworks */, 8EB6E58A3F28FAEBBC372598 /* Products */, ); @@ -724,31 +731,6 @@ path = Carthage/Build; sourceTree = ""; }; - CD4D866922E4CD990042ACDC /* 2.0 */ = { - isa = PBXGroup; - children = ( - D1FA0377AF4799D42E9462FA /* BasicAssembly.swift */, - BBDB67E0FC7B8BEE58EECFBB /* BehaviorFakes.swift */, - 359BCD3DA6F0CC2241878C82 /* EmploymentAssembly.swift */, - EEE8FDF4B975A8F2A9FCC5FF /* Food.swift */, - 1910A1471C3CA9EA86F350BA /* LoadAwareAssembly.swift */, - 9985BEF966DCBB28B12BE17B /* Person.swift */, - 7BA261FF01C5F5510873B3EC /* Animal.swift */, - ); - path = 2.0; - sourceTree = ""; - }; - CD4D866A22E4D4E00042ACDC /* Templates */ = { - isa = PBXGroup; - children = ( - CD4D866D22E4D54D0042ACDC /* Container+Registration.swifttemplate */, - CD4D866C22E4D54D0042ACDC /* Resolver+LegacyApi.swifttemplate */, - CD4D866F22E4D54D0042ACDC /* ServiceEntry+TypeForwarding.swifttemplate */, - CD4D866B22E4D4E00042ACDC /* AutoMockable.stencil */, - ); - path = Templates; - sourceTree = ""; - }; D026A6699A2A932511D29E14 /* Sources */ = { isa = PBXGroup; children = ( @@ -782,14 +764,15 @@ FCA9C6262A4D071C8E7EEBD0 /* Core */ = { isa = PBXGroup; children = ( - CDF8F36422E8D881008B2AF5 /* Reference.swift */, 0E0B580B43E1891812C97209 /* Binding.swift */, A24B4E8F1CA18603DBB6884A /* BindingKey.swift */, 65D0BCCCD61CD9BECC29E064 /* Closable.swift */, + 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */, CADDB3E9E363310028AA5920 /* InstanceMaker.swift */, E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */, 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */, - C11D19C5F01647E4A576514A /* Resolver.swift */, + 73B4B777290FF5D38A8914CC /* Reference.swift */, + A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */, 5057BAB33984E3E33469452B /* Scope.swift */, A10187BB3A994165E7FC1528 /* ScopedBinding.swift */, 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */, @@ -799,7 +782,6 @@ A3586A4987B7C7C8122D674E /* SwinjectError.swift */, 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */, E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */, - CDF8F35522E64694008B2AF5 /* ContextTranslator.swift */, ); path = Core; sourceTree = ""; @@ -849,7 +831,8 @@ 2AB7CE6B2DF8658C3EF1D9B5 /* Sourcery */, 585AA4C5E589D1DCBB7F94E5 /* Headers */, 15C9FE5CAD693ADAC2CE7497 /* Sources */, - 66D6B3BD3D539FA0C7A9CCA0 /* Swiftlint */, + C51BF0B4EF924023AA16CA27 /* SwiftFormat */, + E0095A3C75C41331068F9F86 /* SwiftLint */, ); buildRules = ( ); @@ -867,7 +850,8 @@ F50F3DCA9EE4390D69780A5D /* Sourcery */, 54CB4C9F1A52910358025C89 /* Headers */, 604EA45A8BA53D9420351811 /* Sources */, - 0001F3C7499902D8D5EB3077 /* Swiftlint */, + A26EEBFBFC3E9F170D5B70A7 /* SwiftFormat */, + 61E3A4F4029767581060F811 /* SwiftLint */, ); buildRules = ( ); @@ -885,7 +869,8 @@ 8F89A051B21745D585F21607 /* Sourcery */, 02763B86C881518A9271575B /* Headers */, 01C827BE688B831820F3BF57 /* Sources */, - 07B6CBBA986B903471B2C38A /* Swiftlint */, + 18B06C8DC996C4FFAD446638 /* SwiftFormat */, + AB51200EA4879C47F3E0DBD4 /* SwiftLint */, ); buildRules = ( ); @@ -903,7 +888,8 @@ 8B38A2A8E5A9177159728F8A /* Sourcery */, E896EE40D53913BA1CD0CA02 /* Headers */, A40C67870E9515117AC87B4F /* Sources */, - DF58753EC2B1D8F6A5679F10 /* Swiftlint */, + 7ADF511949FFC8A278F80A19 /* SwiftFormat */, + 511D96F780EADD6A9997F575 /* SwiftLint */, ); buildRules = ( ); @@ -1057,7 +1043,7 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 0001F3C7499902D8D5EB3077 /* Swiftlint */ = { + 18B06C8DC996C4FFAD446638 /* SwiftFormat */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( @@ -1066,16 +1052,16 @@ ); inputPaths = ( ); - name = Swiftlint; + name = SwiftFormat; outputFileListPaths = ( ); outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n"; + shellScript = "if which swiftformat >/dev/null; then\n swiftformat .\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/nicklockwood/SwiftFormat\"\nfi\n"; }; - 07B6CBBA986B903471B2C38A /* Swiftlint */ = { + 2AB7CE6B2DF8658C3EF1D9B5 /* Sourcery */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( @@ -1084,16 +1070,16 @@ ); inputPaths = ( ); - name = Swiftlint; + name = Sourcery; outputFileListPaths = ( ); outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n"; + shellScript = "if which sourcery >/dev/null; then\n sourcery\nelse\n echo \"warning: Sourcery not installed, download from https://github.com/krzysztofzablocki/Sourcery\"\nfi\n"; }; - 2AB7CE6B2DF8658C3EF1D9B5 /* Sourcery */ = { + 511D96F780EADD6A9997F575 /* SwiftLint */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( @@ -1102,16 +1088,34 @@ ); inputPaths = ( ); - name = Sourcery; + name = SwiftLint; outputFileListPaths = ( ); outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "if which sourcery >/dev/null; then\n sourcery\nelse\n echo \"warning: Sourcery not installed, download from https://github.com/krzysztofzablocki/Sourcery\"\nfi\n"; + shellScript = "if which swiftlint >/dev/null; then\n swiftlint autocorrect\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n"; + }; + 61E3A4F4029767581060F811 /* SwiftLint */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + name = SwiftLint; + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "if which swiftlint >/dev/null; then\n swiftlint autocorrect\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n"; }; - 66D6B3BD3D539FA0C7A9CCA0 /* Swiftlint */ = { + 7ADF511949FFC8A278F80A19 /* SwiftFormat */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( @@ -1120,14 +1124,14 @@ ); inputPaths = ( ); - name = Swiftlint; + name = SwiftFormat; outputFileListPaths = ( ); outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n"; + shellScript = "if which swiftformat >/dev/null; then\n swiftformat .\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/nicklockwood/SwiftFormat\"\nfi\n"; }; 8B38A2A8E5A9177159728F8A /* Sourcery */ = { isa = PBXShellScriptBuildPhase; @@ -1165,7 +1169,7 @@ shellPath = /bin/sh; shellScript = "if which sourcery >/dev/null; then\n sourcery\nelse\n echo \"warning: Sourcery not installed, download from https://github.com/krzysztofzablocki/Sourcery\"\nfi\n"; }; - DF58753EC2B1D8F6A5679F10 /* Swiftlint */ = { + A26EEBFBFC3E9F170D5B70A7 /* SwiftFormat */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( @@ -1174,14 +1178,68 @@ ); inputPaths = ( ); - name = Swiftlint; + name = SwiftFormat; outputFileListPaths = ( ); outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n"; + shellScript = "if which swiftformat >/dev/null; then\n swiftformat .\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/nicklockwood/SwiftFormat\"\nfi\n"; + }; + AB51200EA4879C47F3E0DBD4 /* SwiftLint */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + name = SwiftLint; + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "if which swiftlint >/dev/null; then\n swiftlint autocorrect\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n"; + }; + C51BF0B4EF924023AA16CA27 /* SwiftFormat */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + name = SwiftFormat; + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "if which swiftformat >/dev/null; then\n swiftformat .\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/nicklockwood/SwiftFormat\"\nfi\n"; + }; + E0095A3C75C41331068F9F86 /* SwiftLint */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + name = SwiftLint; + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "if which swiftlint >/dev/null; then\n swiftlint autocorrect\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n"; }; F50F3DCA9EE4390D69780A5D /* Sourcery */ = { isa = PBXShellScriptBuildPhase; @@ -1213,32 +1271,32 @@ 0568E116A56DA02DA92BAC8E /* Behavior.swift in Sources */, 5B0ECCEBC6CB23571A9EDA38 /* BinderEnvironment.swift in Sources */, 49FB15929F16836D51779A1D /* Binding.swift in Sources */, - CDF8F35722E64694008B2AF5 /* ContextTranslator.swift in Sources */, 64A8413AD2ED65BB25BD0113 /* BindingKey.swift in Sources */, 9FEC055DC6BE1D844FE5F082 /* Closable.swift in Sources */, - 0CB9E677FDF7CF424A738F34 /* Container+Registration.swift in Sources */, - A4490FF7ACCC5CBFB2C1896C /* Container+Logging.swift in Sources */, - 7F22099B321798EAD85DBC07 /* Container+TypeForwarding.swift in Sources */, + 648CB5DEA239EA225A39A20A /* Container+Logging.swift in Sources */, + A3F070412E120E31DB0529FB /* Container+Registration.swift in Sources */, + B85ADC1EA6298966819FD6D0 /* Container+TypeForwarding.swift in Sources */, 0CED31C429BA9F9B23EB2B1F /* Container.swift in Sources */, + 5AC3FAAAAB1B899F1661B3D4 /* ContextTranslator.swift in Sources */, 3547656EF55D129316B7C5E2 /* InstanceMaker.swift in Sources */, B61FAC17826BAFD2DC1C0E5E /* InstanceRequest.swift in Sources */, 2DCEEF373F410202226D2DB5 /* InstanceWrapper.swift in Sources */, 9264E4C053A699FE01EAD232 /* Matchable.swift in Sources */, + 79772C34E5102A8E3003DBF8 /* ObjectScope.swift in Sources */, + B446D0B72AED8D4E051FF57B /* Reference.swift in Sources */, 5C4C106D138E771C872F5E80 /* Resolver+Injection.swift in Sources */, - E7E9DE84E1861D125F8D686A /* Resolver+LegacyApi.swift in Sources */, - FC120C659D0A6FB9CE757CB7 /* Resolver.swift in Sources */, + 29F709EF28B169C291135C04 /* Resolver+LegacyApi.swift in Sources */, + DAFA9AE69744F3C5DC71CF50 /* Resolver.swift in Sources */, 71C4A75D54446D844BA5FB85 /* Scope.swift in Sources */, 1AD4C43B074F736BBDADA8C9 /* ScopeRegistry.swift in Sources */, 971B97F191A9FF75A6586E0A /* ScopeRegistryKey.swift in Sources */, 3F8EA877F153EE374FF8E31A /* ScopedBinding.swift in Sources */, - 38FACA739BA59278725FAE67 /* ServiceEntry+TypeForwarding.swift in Sources */, + FCBDE573A9BBFC0245D25895 /* ServiceEntry+TypeForwarding.swift in Sources */, EF25C3A81E568411233E6867 /* ServiceEntry.swift in Sources */, 8D71D83DB3F5D3655FB6C71D /* SimpleBinding.swift in Sources */, 15FA8361AB335F4CC372A52C /* Swinject+Builder.swift in Sources */, - CD4D866622E4C8A70042ACDC /* ObjectScope.swift in Sources */, 828C5B0915A8D08CF98F5F4C /* Swinject.swift in Sources */, EAC4EA9BAC87B34AD5BA2110 /* SwinjectError.swift in Sources */, - CDF8F36622E8D881008B2AF5 /* Reference.swift in Sources */, 94615DB1AD57F1547933D8A5 /* SwinjectModule.swift in Sources */, 8F48909C95AA648D056A392B /* SwinjectTree.swift in Sources */, 3B61931D1E9C0F7D1AAEDDF7 /* TypeBinder.swift in Sources */, @@ -1250,10 +1308,10 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 2BE5AF2623B96992C74970F9 /* Animal.swift in Sources */, + AD89FFF56D87A23AD74BC7F1 /* Animal.swift in Sources */, D7D5560E4F790F41126F61CF /* AssemblerSpec.swift in Sources */, - 4503217DA585B602EDE65742 /* BasicAssembly.swift in Sources */, - F50BA96120EDA5D470F4265C /* BehaviorFakes.swift in Sources */, + BAFE51FEADADF31B0DB513A6 /* BasicAssembly.swift in Sources */, + EC6830FA962E84DD737D8885 /* BehaviorFakes.swift in Sources */, 87056684D7F91917F6B0AC7A /* BinderEnvironmentSpec.swift in Sources */, 7845113EAF8FFAFD5EC10540 /* BindingKeySpec.swift in Sources */, 876F90C64EA036596E797CB3 /* Bridge.swift in Sources */, @@ -1263,17 +1321,17 @@ 86E1845B6272AF95F1806CB4 /* ContainerSpec.Circularity.swift in Sources */, 93DCA2A58C4067D5E60F7ED1 /* ContainerSpec.CustomStringConvertible.swift in Sources */, F8DB4EDA0367BCC6832E4AA6 /* ContainerSpec.TypeForwarding.swift in Sources */, - CDF8F36A22E8D89E008B2AF5 /* ReferenceMakerSpec.swift in Sources */, 4C6D7AE29CB7E16431AACFA2 /* ContainerSpec.swift in Sources */, A014793C56F8966AD2D7CC50 /* Convenience.swift in Sources */, - DC5C3A946BDA224C388D2438 /* EmploymentAssembly.swift in Sources */, - 60AF45155775AA5E97AAB5C1 /* Food.swift in Sources */, + 5FCE3C447CE0CD2211A5EB3D /* EmploymentAssembly.swift in Sources */, + D7313C07419E511B66E5A56C /* Food.swift in Sources */, 9D1AD9CBA32CEE29EF6C68C2 /* GeneratedMocks.swift in Sources */, 9C08C2D57E0B0B46D5748B6C /* LazySpec.swift in Sources */, - 013A1E1096BD1305A3A14493 /* LoadAwareAssembly.swift in Sources */, + 9925498BDD0C9CA36116292F /* LoadAwareAssembly.swift in Sources */, 01197582F81B8D30D7D4A8AF /* NonGeneratedMocks.swift in Sources */, - DA6CB0A98FE5968CAAFDE9BF /* Person.swift in Sources */, + AB8A04BA95434DF26D637B47 /* Person.swift in Sources */, 788AE378F10DA216265FFF52 /* ProviderSpec.swift in Sources */, + A9C0FE53F80BF341EA1F0B04 /* ReferenceMakerSpec.swift in Sources */, 16FE1BC18A9DD0D21CAF2806 /* ScopeRegistryKeySpec.swift in Sources */, D2391A103E7356AD7E08F5BA /* ScopedBindingSpec.swift in Sources */, 91FED72828F68263D599B6C0 /* SimpleBindingSpec.swift in Sources */, @@ -1293,10 +1351,10 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - EC4EE4B0AECDBA8EC0B8F73D /* Animal.swift in Sources */, + 87C665DAF0CC607F0D022B50 /* Animal.swift in Sources */, 30BD96CC0333463C71377C4B /* AssemblerSpec.swift in Sources */, - 5329D4D400755935B22C0881 /* BasicAssembly.swift in Sources */, - 5E983707B893B9A8EF94B33E /* BehaviorFakes.swift in Sources */, + D9A92063A905E6EDBEA6B7CF /* BasicAssembly.swift in Sources */, + AF1BA0CE40742BA6C19320B5 /* BehaviorFakes.swift in Sources */, FD1678ED0C9813A653D9C68B /* BinderEnvironmentSpec.swift in Sources */, 166CBBCA1E1441AD87A60EFF /* BindingKeySpec.swift in Sources */, 4B35CE8BAA88DCAE7D36BC4B /* Bridge.swift in Sources */, @@ -1306,17 +1364,17 @@ 37FE9A9C76DB50ABB28AF9BE /* ContainerSpec.Circularity.swift in Sources */, E423395FC7006DD82513F347 /* ContainerSpec.CustomStringConvertible.swift in Sources */, FAF8F8B75F63D43995A004E8 /* ContainerSpec.TypeForwarding.swift in Sources */, - CDF8F36D22E8D89E008B2AF5 /* ReferenceMakerSpec.swift in Sources */, C797CCF413DF181935DAB58C /* ContainerSpec.swift in Sources */, DE0A534B660AA93F73A2CB41 /* Convenience.swift in Sources */, - 833635A5D695AA696559C250 /* EmploymentAssembly.swift in Sources */, - F4D2218805AEBF797A2945AB /* Food.swift in Sources */, + 393EC075C105E906430F15DF /* EmploymentAssembly.swift in Sources */, + C295515C38C93A82B7F54915 /* Food.swift in Sources */, 64BC606D6414CB4BE8834B08 /* GeneratedMocks.swift in Sources */, D42D98955F4F78E3FC91803E /* LazySpec.swift in Sources */, - 9B04477B2B117122CB99989A /* LoadAwareAssembly.swift in Sources */, + B9B7AF8C0E13B9D80635F1EF /* LoadAwareAssembly.swift in Sources */, 3A149A223FA316F68C0A486A /* NonGeneratedMocks.swift in Sources */, - 2B386345150685F670BF04B1 /* Person.swift in Sources */, + 0862B3AD1CE95CA4A9854E8F /* Person.swift in Sources */, 03E7834C4448A5D939948CCF /* ProviderSpec.swift in Sources */, + EC19876AC6526691345DA389 /* ReferenceMakerSpec.swift in Sources */, 86CD1F46C15A352BCF7CE396 /* ScopeRegistryKeySpec.swift in Sources */, 9B83FF80C5BE658ED0F7B709 /* ScopedBindingSpec.swift in Sources */, 8AEB5894656086C3E2F022FD /* SimpleBindingSpec.swift in Sources */, @@ -1341,32 +1399,32 @@ 588A600231D894122A4D9C47 /* Behavior.swift in Sources */, 196AA219BB35334B07B34F37 /* BinderEnvironment.swift in Sources */, 4735419DE3D63E556D07C663 /* Binding.swift in Sources */, - CDF8F35822E64694008B2AF5 /* ContextTranslator.swift in Sources */, FDB7873663CEFBF7BE76ECFF /* BindingKey.swift in Sources */, 2B67E8B80A930E8598FAD10C /* Closable.swift in Sources */, - 7E0539C5CD130F0AC4B02096 /* Container+Registration.swift in Sources */, - E9F5DF3C8AA3A9651D504AF7 /* Container+Logging.swift in Sources */, - 5381C2CDA084C5BEF82D7521 /* Container+TypeForwarding.swift in Sources */, + FDF173EB90F7764887841A6B /* Container+Logging.swift in Sources */, + 61BBC25BC709F5A57CC592BA /* Container+Registration.swift in Sources */, + E02056E5E8F896E3C330B531 /* Container+TypeForwarding.swift in Sources */, AAB6386F88442B22E9F7FF0E /* Container.swift in Sources */, + 406147FA5D2FBBD2BA9C8FEB /* ContextTranslator.swift in Sources */, 58CFFB8C98C465B9101AA9A8 /* InstanceMaker.swift in Sources */, 9AFDF0122A11B2E996B16C3D /* InstanceRequest.swift in Sources */, 3B2E8B8CF4825DB05B0233F8 /* InstanceWrapper.swift in Sources */, C50BFD826112288F1D693A30 /* Matchable.swift in Sources */, + 401A790CF8450924114D89ED /* ObjectScope.swift in Sources */, + 78D311E69E44F242CCB66287 /* Reference.swift in Sources */, 741344C30785507B22DF703B /* Resolver+Injection.swift in Sources */, - FDCF96E2A442CDC6815B8127 /* Resolver+LegacyApi.swift in Sources */, - 2488CDD8D67CAC5C97BDF8B1 /* Resolver.swift in Sources */, + 0874FBEE3E260F862C4AC54A /* Resolver+LegacyApi.swift in Sources */, + E62C6509D0B52001CC309068 /* Resolver.swift in Sources */, 1718A1577AB543174FD8E644 /* Scope.swift in Sources */, 1F4FBB9D795CE9D45E5A8BEE /* ScopeRegistry.swift in Sources */, 54A1FEE340AC3A2413876AD2 /* ScopeRegistryKey.swift in Sources */, 73214A0BF7D4AE8B78DEB4FD /* ScopedBinding.swift in Sources */, - 982E4682C79B74226C03E0C9 /* ServiceEntry+TypeForwarding.swift in Sources */, + C032FA4CB2D35904C513D27A /* ServiceEntry+TypeForwarding.swift in Sources */, 908AE547955AE4432C1D161A /* ServiceEntry.swift in Sources */, DB14CA46130A816F6FAADE92 /* SimpleBinding.swift in Sources */, FCBA6B66A6BBA29B3EC6CDDD /* Swinject+Builder.swift in Sources */, - CD4D866822E4C8A80042ACDC /* ObjectScope.swift in Sources */, B5048A00D49FD5C1C098EE01 /* Swinject.swift in Sources */, 439254FAE8DF567DE9659ADA /* SwinjectError.swift in Sources */, - CDF8F36722E8D881008B2AF5 /* Reference.swift in Sources */, AA6651CFD4090465E7CB7871 /* SwinjectModule.swift in Sources */, 4DA000959B4D60B509859810 /* SwinjectTree.swift in Sources */, 5D2C492FD5088FCB2BA5CDB8 /* TypeBinder.swift in Sources */, @@ -1378,10 +1436,10 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - EFCA30870DA55BC3572AF634 /* Animal.swift in Sources */, + E81B712F36E326A7905272F3 /* Animal.swift in Sources */, A44D1B2E48E1C0FEF146933A /* AssemblerSpec.swift in Sources */, - 124369E08D4848D05E3EA6B1 /* BasicAssembly.swift in Sources */, - 2C6047BB84D52FC94F63B7C8 /* BehaviorFakes.swift in Sources */, + 4229FBE59AF2769A0BF2ED65 /* BasicAssembly.swift in Sources */, + FC07362CFB0C849BD5A7B4BC /* BehaviorFakes.swift in Sources */, 7480A500FEC04BB9CB048AE1 /* BinderEnvironmentSpec.swift in Sources */, 13379D1C70FC17FE2F949341 /* BindingKeySpec.swift in Sources */, E584841CFD26155FB056C85A /* Bridge.swift in Sources */, @@ -1391,17 +1449,17 @@ EAD0757CE0163D3549CB5405 /* ContainerSpec.Circularity.swift in Sources */, 377EE35B80E8F91543B52F0C /* ContainerSpec.CustomStringConvertible.swift in Sources */, 5D241BBB39F54B8FA2BFF595 /* ContainerSpec.TypeForwarding.swift in Sources */, - CDF8F36B22E8D89E008B2AF5 /* ReferenceMakerSpec.swift in Sources */, 37E07236E0E63570242CE23F /* ContainerSpec.swift in Sources */, 564B886D2A35AF26FC411922 /* Convenience.swift in Sources */, - 58C9D537D453BC7C7DC5C0C1 /* EmploymentAssembly.swift in Sources */, - 0539332D989C37CA34A5FB4F /* Food.swift in Sources */, + D0BA6CF98B7F0ECE9FA95055 /* EmploymentAssembly.swift in Sources */, + 42813F8FA6786279AF2C9DC7 /* Food.swift in Sources */, F1D5D6A0A7679A14317617E1 /* GeneratedMocks.swift in Sources */, 661B5A18940BA6E67D9BA65E /* LazySpec.swift in Sources */, - 9CEF62C5A3EC3CB8034F08BB /* LoadAwareAssembly.swift in Sources */, + A24F290A74A85DD34BE05141 /* LoadAwareAssembly.swift in Sources */, 963D32297EE5CA9C18A0C246 /* NonGeneratedMocks.swift in Sources */, - 71674FB84CBE1E97B72123BF /* Person.swift in Sources */, + 7C4EDB197C821D1A7FE1FAB3 /* Person.swift in Sources */, 261D54C316CB625359F7EE97 /* ProviderSpec.swift in Sources */, + 4374382E77C73DB48164592F /* ReferenceMakerSpec.swift in Sources */, 9623C7F8B9FED0541D959708 /* ScopeRegistryKeySpec.swift in Sources */, 1CFCB38BC4EE2D3AAD40154E /* ScopedBindingSpec.swift in Sources */, 35847FDC65085C6741D2A132 /* SimpleBindingSpec.swift in Sources */, @@ -1421,10 +1479,10 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 5CADD5B13173034498BF4A5F /* Animal.swift in Sources */, + EC6D316B79FE51336B771139 /* Animal.swift in Sources */, D5BD321738E03967CA8E27C6 /* AssemblerSpec.swift in Sources */, - 60CEB9FCA08EFF202DD38096 /* BasicAssembly.swift in Sources */, - 9A551D43739EDE556FF3F9ED /* BehaviorFakes.swift in Sources */, + 2565CB32BBAD60BD198150C7 /* BasicAssembly.swift in Sources */, + B40F2E0BF341A31ADA195CB0 /* BehaviorFakes.swift in Sources */, 2CA05A2362E0390075908A32 /* BinderEnvironmentSpec.swift in Sources */, 9DD1C1273B38FCF4FFE9BCC2 /* BindingKeySpec.swift in Sources */, D7DFD1B77BFB5FABAE165A11 /* Bridge.swift in Sources */, @@ -1434,17 +1492,17 @@ 9B9AA902B80620568D732D7B /* ContainerSpec.Circularity.swift in Sources */, E8D70420E8A3C91D01BC3B5B /* ContainerSpec.CustomStringConvertible.swift in Sources */, 9F1C7A652660EA87BF599126 /* ContainerSpec.TypeForwarding.swift in Sources */, - CDF8F36C22E8D89E008B2AF5 /* ReferenceMakerSpec.swift in Sources */, E80558941BC2149C25A17495 /* ContainerSpec.swift in Sources */, A1B275A2EFA22C45AC46B31E /* Convenience.swift in Sources */, - 187BD516162B3FBB1158E015 /* EmploymentAssembly.swift in Sources */, - D98CA679A3AAC176D291CA8E /* Food.swift in Sources */, + E2594F32273350049629A349 /* EmploymentAssembly.swift in Sources */, + A4432BDF84F354954D3C4597 /* Food.swift in Sources */, 3F04B9C7812B5E21DCE4D36C /* GeneratedMocks.swift in Sources */, 648FDC2A1E3DC75CB47D31E1 /* LazySpec.swift in Sources */, - D10FFA4B80F4BE6024B1DCEE /* LoadAwareAssembly.swift in Sources */, + 394199DBE804A34B14D9D48C /* LoadAwareAssembly.swift in Sources */, BAFD66351A9ED8E7BFB19CD3 /* NonGeneratedMocks.swift in Sources */, - 9102F98F672DD39F304AFC3B /* Person.swift in Sources */, + 37B6C0608A8879226D25585F /* Person.swift in Sources */, E484C3994AD91E91C454B11D /* ProviderSpec.swift in Sources */, + 2E962A972989EAEB03ECDDB4 /* ReferenceMakerSpec.swift in Sources */, F4D7CC563B9C212A418C4EBC /* ScopeRegistryKeySpec.swift in Sources */, 0E8E5B08478EB883D9B52947 /* ScopedBindingSpec.swift in Sources */, 1ACC90951353E5F69899A833 /* SimpleBindingSpec.swift in Sources */, @@ -1469,32 +1527,32 @@ C3AD37D47C38E5EB20FAF917 /* Behavior.swift in Sources */, 01D985B5F99817DEE0E0DAD1 /* BinderEnvironment.swift in Sources */, 705F51FD21F7E1536BFC0C41 /* Binding.swift in Sources */, - CDF8F35622E64694008B2AF5 /* ContextTranslator.swift in Sources */, A4866802E1E597EEFEFDEB66 /* BindingKey.swift in Sources */, 816F47E9D87CAE910091B484 /* Closable.swift in Sources */, - 7472B748AEA9F4D1E5EF9A70 /* Container+Registration.swift in Sources */, - 31266C4BA7CE6C3FBAFBACDD /* Container+Logging.swift in Sources */, - 0DFB6FB4DF6A713EA545930F /* Container+TypeForwarding.swift in Sources */, + 846CA938C957BA8623D2069C /* Container+Logging.swift in Sources */, + 886D2A54B2857FF52AB5CA56 /* Container+Registration.swift in Sources */, + D815847229F70F0AE7D0D2F9 /* Container+TypeForwarding.swift in Sources */, C8F1F075F5792C9936B0577D /* Container.swift in Sources */, + 791591AEE261B40F4A04BA07 /* ContextTranslator.swift in Sources */, 48714C7B99D346C83E1E8293 /* InstanceMaker.swift in Sources */, 04C24C140F2D0BBFE48C682C /* InstanceRequest.swift in Sources */, 53DC7093FD7C2FEE16154DED /* InstanceWrapper.swift in Sources */, DEB3F135FFAEBF825881E886 /* Matchable.swift in Sources */, + D688F61360D46A16B0678BA4 /* ObjectScope.swift in Sources */, + A6E0CFB53B2EEAE0E89084E2 /* Reference.swift in Sources */, 1C2F5A09F986586F85FAC3E8 /* Resolver+Injection.swift in Sources */, - 8108969F33C37040624E0D02 /* Resolver+LegacyApi.swift in Sources */, - EE5763938068B3FA56D1BA59 /* Resolver.swift in Sources */, + AEEF98CB6977B472C384BC82 /* Resolver+LegacyApi.swift in Sources */, + 1B29712FD3C5FB3B372EE35F /* Resolver.swift in Sources */, D557A108A21751DF75542692 /* Scope.swift in Sources */, D7DE20CC15F3A6BD09E43A75 /* ScopeRegistry.swift in Sources */, 9437AF5CAAD1A2D033AE3599 /* ScopeRegistryKey.swift in Sources */, D6AA597218691F1FE87724E7 /* ScopedBinding.swift in Sources */, - 78ACD9EBF8625ECD24103A17 /* ServiceEntry+TypeForwarding.swift in Sources */, + F96FD82F093567BA0CB891F1 /* ServiceEntry+TypeForwarding.swift in Sources */, EABC31077D2369311E6C14C3 /* ServiceEntry.swift in Sources */, 35175F8F168EDB5EB83BD8E9 /* SimpleBinding.swift in Sources */, D18275ADB0E56D3087894518 /* Swinject+Builder.swift in Sources */, - CD4D866522E4C8A50042ACDC /* ObjectScope.swift in Sources */, 9E084F679592ADFA28D3AD6D /* Swinject.swift in Sources */, AAC84D757FE8F601FF053923 /* SwinjectError.swift in Sources */, - CDF8F36522E8D881008B2AF5 /* Reference.swift in Sources */, 5570E14A839D4065FFBA7EF4 /* SwinjectModule.swift in Sources */, E8A89383E1D1106DEABB778B /* SwinjectTree.swift in Sources */, 050982D62AE0244372456440 /* TypeBinder.swift in Sources */, @@ -1511,32 +1569,32 @@ AF5F860DBFE2607EF4157CF7 /* Behavior.swift in Sources */, 4D0ABCA733720469F2240C31 /* BinderEnvironment.swift in Sources */, EEC04BEF02E6776003CC2003 /* Binding.swift in Sources */, - CDF8F35922E64694008B2AF5 /* ContextTranslator.swift in Sources */, E0D7B3285AA1FE51E14A52A1 /* BindingKey.swift in Sources */, 418F111C8E128766AC8E33CC /* Closable.swift in Sources */, - 7DD047C203659BCA7F04E48D /* Container+Registration.swift in Sources */, - F151A5040BB76E8E909D9D6B /* Container+Logging.swift in Sources */, - 782801544D9F468F536E045E /* Container+TypeForwarding.swift in Sources */, + D1DB8BA2F9F0B832865688E6 /* Container+Logging.swift in Sources */, + C6D9ADDCEBD26C3DF6DAD4D9 /* Container+Registration.swift in Sources */, + C9B440CFC0B944D25F7EE57E /* Container+TypeForwarding.swift in Sources */, 91DAE32F86CEA897AD52AEDB /* Container.swift in Sources */, + 8E92150DFA758FD3E32CC0A7 /* ContextTranslator.swift in Sources */, 41EEA4724CD401F38F9622E3 /* InstanceMaker.swift in Sources */, 5E74770DDD69EAFE5D187F90 /* InstanceRequest.swift in Sources */, 39F9BBD670C944E1331FAB13 /* InstanceWrapper.swift in Sources */, D3828F01A014F3A06B1141D7 /* Matchable.swift in Sources */, + 3AC304A612ECAED02C58BBF5 /* ObjectScope.swift in Sources */, + EC3E297BC24CB5D39A731136 /* Reference.swift in Sources */, 90B4143005C86717AC76B6EE /* Resolver+Injection.swift in Sources */, - 66033468A5FC65C19B60086A /* Resolver+LegacyApi.swift in Sources */, - A3815641CEB5A06759D288E0 /* Resolver.swift in Sources */, + 250B276C7FF6E5FCB194C6BE /* Resolver+LegacyApi.swift in Sources */, + 8A212C0486A514CF17B5F140 /* Resolver.swift in Sources */, B2FCC51BB61148422256A14A /* Scope.swift in Sources */, 46A14FAA5AA73BE8A0397707 /* ScopeRegistry.swift in Sources */, 18A07EB6FB61F3CDCC766AF4 /* ScopeRegistryKey.swift in Sources */, 6F5323F408E5708076C02768 /* ScopedBinding.swift in Sources */, - 51F2CD3C07148069167AB6E9 /* ServiceEntry+TypeForwarding.swift in Sources */, + EA5AC0A3555E0D65D178ED82 /* ServiceEntry+TypeForwarding.swift in Sources */, 4939B8B795061A74ADFC02D8 /* ServiceEntry.swift in Sources */, 87F8C64D9E8B4317C0C036E0 /* SimpleBinding.swift in Sources */, D267BD55BBEDE3ECEC449472 /* Swinject+Builder.swift in Sources */, - CD4D866722E4C8A80042ACDC /* ObjectScope.swift in Sources */, 26C8D37F26408DC308A0CDA3 /* Swinject.swift in Sources */, 14AECF24B26ECEC8E9086FBB /* SwinjectError.swift in Sources */, - CDF8F36822E8D881008B2AF5 /* Reference.swift in Sources */, 699DB780BD90A5AAAD5B4646 /* SwinjectModule.swift in Sources */, 192278AA7165EC3C2C12A4C2 /* SwinjectTree.swift in Sources */, D88D7841C5C84A2E34CE15FD /* TypeBinder.swift in Sources */, @@ -1638,11 +1696,7 @@ ); INFOPLIST_FILE = Tests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SwinjectTests; SDKROOT = watchos; @@ -1666,10 +1720,7 @@ INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = Swinject; SDKROOT = macosx; @@ -1692,10 +1743,7 @@ INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = Swinject; SDKROOT = iphoneos; @@ -1742,10 +1790,7 @@ INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = Swinject; SDKROOT = appletvos; @@ -1767,11 +1812,7 @@ ); INFOPLIST_FILE = Tests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SwinjectTests; SDKROOT = appletvos; @@ -1841,11 +1882,7 @@ ); INFOPLIST_FILE = Tests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SwinjectTests; SDKROOT = iphoneos; @@ -1867,10 +1904,7 @@ INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = Swinject; SDKROOT = appletvos; @@ -1918,10 +1952,7 @@ INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = Swinject; SDKROOT = macosx; @@ -1944,10 +1975,7 @@ INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = Swinject; SDKROOT = iphoneos; @@ -1970,11 +1998,7 @@ ); INFOPLIST_FILE = Tests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - "@loader_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SwinjectTests; SDKROOT = macosx; @@ -1993,11 +2017,7 @@ ); INFOPLIST_FILE = Tests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SwinjectTests; SDKROOT = appletvos; @@ -2018,11 +2038,7 @@ ); INFOPLIST_FILE = Tests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - "@loader_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SwinjectTests; SDKROOT = macosx; @@ -2041,11 +2057,7 @@ ); INFOPLIST_FILE = Tests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SwinjectTests; SDKROOT = watchos; @@ -2066,11 +2078,7 @@ ); INFOPLIST_FILE = Tests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SwinjectTests; SDKROOT = iphoneos; diff --git a/Templates/Container+Registration.swifttemplate b/Templates/Container+Registration.swifttemplate index b46ebe14..22feb834 100644 --- a/Templates/Container+Registration.swifttemplate +++ b/Templates/Container+Registration.swifttemplate @@ -15,7 +15,7 @@ extension Container { /// /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult - public func register(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver) -> Service) -> ServiceEntry { + public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver) -> Service) -> ServiceEntry { let entry = ServiceEntry(container: self, name: name, scope: defaultScope) { (r, _, _: Void) in factory(r) } addEntry(entry, with: name) return entry @@ -40,7 +40,7 @@ extension Container { /// /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult - public func register>(_ serviceType: Service.Type, name: String? = nil, factory: @escaping (Resolver, <%= arg_types %>) -> Service) -> ServiceEntry { + public func register>(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, <%= arg_types %>) -> Service) -> ServiceEntry { let entry = ServiceEntry(container: self, name: name, scope: defaultScope) { (r, _, a: <%= arg_closure_type %>) in factory(r, <%= arg_vars %>) } addEntry(entry, with: name) return entry diff --git a/Templates/ServiceEntry+TypeForwarding.swifttemplate b/Templates/ServiceEntry+TypeForwarding.swifttemplate index 48121e06..e63e8da8 100644 --- a/Templates/ServiceEntry+TypeForwarding.swifttemplate +++ b/Templates/ServiceEntry+TypeForwarding.swifttemplate @@ -24,9 +24,9 @@ extension ServiceEntry { /// - types: List of <%= i %> types resolution of which should be forwarded @discardableResult public func implements<<%= types %>>(<%= params %>) -> ServiceEntry { - return self<% (1...i).forEach { %>.implements(type<%= $0 %>)<% } %> + return <%= (1...i).map { "implements(type\($0))" }.joined(separator: ".") %> } - -<% } %> + +<%_ } -%> } // sourcery:end diff --git a/Tests/2.0 API/ContainerSpec.CustomStringConvertible.swift b/Tests/2.0 API/ContainerSpec.CustomStringConvertible.swift index 76871cf0..12d9653d 100644 --- a/Tests/2.0 API/ContainerSpec.CustomStringConvertible.swift +++ b/Tests/2.0 API/ContainerSpec.CustomStringConvertible.swift @@ -7,7 +7,7 @@ import Quick @testable import Swinject // TODO: Implement debug description -//class ContainerSpec_CustomStringConvertible: QuickSpec { +// class ContainerSpec_CustomStringConvertible: QuickSpec { // override func spec() { // var container: Container! // beforeEach { @@ -71,4 +71,4 @@ import Quick // + "]" // } // } -//} +// } diff --git a/Tests/2.0 API/LazySpec.swift b/Tests/2.0 API/LazySpec.swift index 59635155..5f4c96ee 100644 --- a/Tests/2.0 API/LazySpec.swift +++ b/Tests/2.0 API/LazySpec.swift @@ -7,7 +7,7 @@ import Quick import Swinject // TODO: Enable Lazy injection -//class LazySpec: QuickSpec { +// class LazySpec: QuickSpec { // override func spec() { // var container: Container! // beforeEach { @@ -106,4 +106,4 @@ import Swinject // } // } // } -//} +// } diff --git a/Tests/2.0 API/ProviderSpec.swift b/Tests/2.0 API/ProviderSpec.swift index da0dd193..c3fb58ee 100644 --- a/Tests/2.0 API/ProviderSpec.swift +++ b/Tests/2.0 API/ProviderSpec.swift @@ -7,7 +7,7 @@ import Quick import Swinject // TODO: Enable Provider injection -//class ProviderSpec: QuickSpec { +// class ProviderSpec: QuickSpec { // override func spec() { // var container: Container! // beforeEach { @@ -111,4 +111,4 @@ import Swinject // } // } // } -//} +// } diff --git a/Tests/Support/2.0/Animal.swift b/Tests/Support/Legacy/Animal.swift similarity index 100% rename from Tests/Support/2.0/Animal.swift rename to Tests/Support/Legacy/Animal.swift diff --git a/Tests/Support/2.0/BasicAssembly.swift b/Tests/Support/Legacy/BasicAssembly.swift similarity index 100% rename from Tests/Support/2.0/BasicAssembly.swift rename to Tests/Support/Legacy/BasicAssembly.swift diff --git a/Tests/Support/2.0/BehaviorFakes.swift b/Tests/Support/Legacy/BehaviorFakes.swift similarity index 100% rename from Tests/Support/2.0/BehaviorFakes.swift rename to Tests/Support/Legacy/BehaviorFakes.swift diff --git a/Tests/Support/2.0/EmploymentAssembly.swift b/Tests/Support/Legacy/EmploymentAssembly.swift similarity index 100% rename from Tests/Support/2.0/EmploymentAssembly.swift rename to Tests/Support/Legacy/EmploymentAssembly.swift diff --git a/Tests/Support/2.0/Food.swift b/Tests/Support/Legacy/Food.swift similarity index 100% rename from Tests/Support/2.0/Food.swift rename to Tests/Support/Legacy/Food.swift diff --git a/Tests/Support/2.0/LoadAwareAssembly.swift b/Tests/Support/Legacy/LoadAwareAssembly.swift similarity index 100% rename from Tests/Support/2.0/LoadAwareAssembly.swift rename to Tests/Support/Legacy/LoadAwareAssembly.swift diff --git a/Tests/Support/2.0/Person.swift b/Tests/Support/Legacy/Person.swift similarity index 100% rename from Tests/Support/2.0/Person.swift rename to Tests/Support/Legacy/Person.swift diff --git a/project.yml b/project.yml index 798c8e71..d2c1517f 100644 --- a/project.yml +++ b/project.yml @@ -27,13 +27,21 @@ targets: fi name: Sourcery postCompileScripts: + - script: > + if which swiftformat >/dev/null; then + swiftformat . + else + echo "warning: SwiftLint not installed, download from https://github.com/nicklockwood/SwiftFormat" + fi + name: SwiftFormat - script: > if which swiftlint >/dev/null; then + swiftlint autocorrect swiftlint else echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint" fi - name: Swiftlint + name: SwiftLint SwinjectTests: type: bundle.unit-test platform: [macOS, iOS, tvOS, watchOS] From 275d07d05d751ac253761c2f0701d49eee2cecc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Wed, 24 Jul 2019 20:56:43 +0200 Subject: [PATCH 118/239] Implement weak reference maker --- Sources/Core/Reference.swift | 19 +++++++++++++++++++ Tests/Unit Specs/ReferenceMakerSpec.swift | 22 ++++++++++++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/Sources/Core/Reference.swift b/Sources/Core/Reference.swift index 58f816ac..b33c0d40 100644 --- a/Sources/Core/Reference.swift +++ b/Sources/Core/Reference.swift @@ -22,4 +22,23 @@ struct StrongReference: Reference { } } +struct WeakReference: Reference { + private weak var object: AnyObject? + var value: Any? { + guard let object = object else { return nil } + return object + } + + struct Maker: ReferenceMaker { + func makeReference(for value: Any) -> Reference { + #if os(Linux) + return WeakReference(object: value as? AnyObject) + #else + return WeakReference(object: value as AnyObject) + #endif + } + } +} + public let strongRef: ReferenceMaker = StrongReference.Maker() +public let weakRef: ReferenceMaker = WeakReference.Maker() diff --git a/Tests/Unit Specs/ReferenceMakerSpec.swift b/Tests/Unit Specs/ReferenceMakerSpec.swift index a4a6efb7..f1b11033 100644 --- a/Tests/Unit Specs/ReferenceMakerSpec.swift +++ b/Tests/Unit Specs/ReferenceMakerSpec.swift @@ -7,15 +7,33 @@ import Quick @testable import Swinject class ReferenceMakerSpec: QuickSpec { override func spec() { + var maker: ReferenceMaker! describe("strongRef") { + beforeEach { + maker = strongRef + } it("returns given value") { let human = Human() - let reference = strongRef.makeReference(for: human) + let reference = maker.makeReference(for: human) expect(reference.value) === human } it("persists given value") { - let reference = strongRef.makeReference(for: Human()) + let reference = maker.makeReference(for: Human()) expect(reference.value).notTo(beNil()) } } + describe("weakRef") { + beforeEach { + maker = weakRef + } + it("returns given value") { + let human = Human() + let reference = maker.makeReference(for: human) + expect(reference.value) === human + } + it("does not keep strong reference on value") { + let reference = maker.makeReference(for: Human()) + expect(reference.value).to(beNil()) + } + } } } From 0fc10de084a906836f6751c349375a97cc288a64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Wed, 24 Jul 2019 21:21:22 +0200 Subject: [PATCH 119/239] Refactor reference type --- Sources/Core/Reference.swift | 42 +++++++---------------- Tests/Support/GeneratedMocks.swift | 25 -------------- Tests/Unit Specs/ReferenceMakerSpec.swift | 16 +++++---- 3 files changed, 23 insertions(+), 60 deletions(-) diff --git a/Sources/Core/Reference.swift b/Sources/Core/Reference.swift index b33c0d40..37d5eaef 100644 --- a/Sources/Core/Reference.swift +++ b/Sources/Core/Reference.swift @@ -2,43 +2,27 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -// sourcery: AutoMockable -public protocol Reference { - var value: Any? { get } +public struct Reference { + let currentValue: T + let nextValue: () -> T? } -// sourcery: AutoMockable public protocol ReferenceMaker { - func makeReference(for value: Any) -> Reference + func makeReference(for value: T) -> Reference } -struct StrongReference: Reference { - let value: Any? - - struct Maker: ReferenceMaker { - func makeReference(for value: Any) -> Reference { - StrongReference(value: value) - } +struct StrongReferenceMaker: ReferenceMaker { + func makeReference(for value: T) -> Reference { + Reference(currentValue: value, nextValue: { value }) } } -struct WeakReference: Reference { - private weak var object: AnyObject? - var value: Any? { - guard let object = object else { return nil } - return object - } - - struct Maker: ReferenceMaker { - func makeReference(for value: Any) -> Reference { - #if os(Linux) - return WeakReference(object: value as? AnyObject) - #else - return WeakReference(object: value as AnyObject) - #endif - } +struct WeakReferenceMaker: ReferenceMaker { + func makeReference(for value: T) -> Reference { + weak var weakValue: AnyObject? = value as AnyObject? + return Reference(currentValue: value, nextValue: { weakValue as? T }) } } -public let strongRef: ReferenceMaker = StrongReference.Maker() -public let weakRef: ReferenceMaker = WeakReference.Maker() +public let strongRef: ReferenceMaker = StrongReferenceMaker() +public let weakRef: ReferenceMaker = WeakReferenceMaker() diff --git a/Tests/Support/GeneratedMocks.swift b/Tests/Support/GeneratedMocks.swift index aeacf1f6..25bd6e9f 100644 --- a/Tests/Support/GeneratedMocks.swift +++ b/Tests/Support/GeneratedMocks.swift @@ -301,31 +301,6 @@ class MatchableMock: Matchable { } class ModuleIncludeEntryMock: ModuleIncludeEntry { -} -class ReferenceMock: Reference { - var value: Any? - -} -class ReferenceMakerMock: ReferenceMaker { - - //MARK: - makeReference - - var makeReferenceForCallsCount = 0 - var makeReferenceForCalled: Bool { - return makeReferenceForCallsCount > 0 - } - var makeReferenceForReceivedValue: Any? - var makeReferenceForReceivedInvocations: [Any] = [] - var makeReferenceForReturnValue: Reference! - var makeReferenceForClosure: ((Any) -> Reference)? - - func makeReference(for value: Any) -> Reference { - makeReferenceForCallsCount += 1 - makeReferenceForReceivedValue = value - makeReferenceForReceivedInvocations.append(value) - return makeReferenceForClosure.map({ $0(value) }) ?? makeReferenceForReturnValue - } - } class StaticScopeRegistryMock: StaticScopeRegistry { diff --git a/Tests/Unit Specs/ReferenceMakerSpec.swift b/Tests/Unit Specs/ReferenceMakerSpec.swift index f1b11033..72043c90 100644 --- a/Tests/Unit Specs/ReferenceMakerSpec.swift +++ b/Tests/Unit Specs/ReferenceMakerSpec.swift @@ -15,11 +15,13 @@ class ReferenceMakerSpec: QuickSpec { override func spec() { it("returns given value") { let human = Human() let reference = maker.makeReference(for: human) - expect(reference.value) === human + expect(reference.currentValue) === human } it("persists given value") { - let reference = maker.makeReference(for: Human()) - expect(reference.value).notTo(beNil()) + var reference: Reference? = maker.makeReference(for: Human()) + let nextValue = reference!.nextValue + reference = nil + expect(nextValue()).notTo(beNil()) } } describe("weakRef") { @@ -29,11 +31,13 @@ class ReferenceMakerSpec: QuickSpec { override func spec() { it("returns given value") { let human = Human() let reference = maker.makeReference(for: human) - expect(reference.value) === human + expect(reference.currentValue) === human } it("does not keep strong reference on value") { - let reference = maker.makeReference(for: Human()) - expect(reference.value).to(beNil()) + var reference: Reference? = maker.makeReference(for: Human()) + let nextValue = reference!.nextValue + reference = nil + expect(nextValue()).to(beNil()) } } } } From 011b9e92494c4dec7f232d120698eb7a54cecdd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Wed, 24 Jul 2019 21:37:48 +0200 Subject: [PATCH 120/239] Use reference in scope registry interface --- Sources/2.0 API/ServiceEntry.swift | 2 +- Sources/Core/Reference.swift | 23 ++++---- Sources/Core/ScopeRegistry.swift | 12 +++-- Sources/Core/ScopedBinding.swift | 2 +- Tests/Support/NonGeneratedMocks.swift | 10 ++-- Tests/Unit Specs/ReferenceMakerSpec.swift | 15 ++---- .../StandardScopeRegistrySpec.swift | 54 +++++++++---------- 7 files changed, 57 insertions(+), 61 deletions(-) diff --git a/Sources/2.0 API/ServiceEntry.swift b/Sources/2.0 API/ServiceEntry.swift index 3b9c7ab2..35384c8c 100644 --- a/Sources/2.0 API/ServiceEntry.swift +++ b/Sources/2.0 API/ServiceEntry.swift @@ -76,7 +76,7 @@ extension ServiceEntry: Binding { if let scope = scope { return scope.registry(for: context).instance( for: ScopeRegistryKey(descriptor: key.descriptor, argument: arg), - builder: { builder(resolver, context, arg) }, + builder: { strongRef(builder(resolver, context, arg)) }, finalizer: { instance in finalizers.forEach { $0(resolver, instance as! Service) } } ) } else { diff --git a/Sources/Core/Reference.swift b/Sources/Core/Reference.swift index 37d5eaef..74d3cb44 100644 --- a/Sources/Core/Reference.swift +++ b/Sources/Core/Reference.swift @@ -7,22 +7,17 @@ public struct Reference { let nextValue: () -> T? } -public protocol ReferenceMaker { - func makeReference(for value: T) -> Reference -} +typealias ReferenceMaker = (T) -> Reference -struct StrongReferenceMaker: ReferenceMaker { - func makeReference(for value: T) -> Reference { - Reference(currentValue: value, nextValue: { value }) - } +public func strongRef(_ value: T) -> Reference { + Reference(currentValue: value, nextValue: { value }) } -struct WeakReferenceMaker: ReferenceMaker { - func makeReference(for value: T) -> Reference { - weak var weakValue: AnyObject? = value as AnyObject? - return Reference(currentValue: value, nextValue: { weakValue as? T }) - } +public func weakRef(_ value: T) -> Reference { + weak var weakValue: AnyObject? = value as AnyObject? + return Reference(currentValue: value, nextValue: { weakValue as? T }) } -public let strongRef: ReferenceMaker = StrongReferenceMaker() -public let weakRef: ReferenceMaker = WeakReferenceMaker() +func noRef(_ value: T) -> Reference { + Reference(currentValue: value, nextValue: { nil }) +} diff --git a/Sources/Core/ScopeRegistry.swift b/Sources/Core/ScopeRegistry.swift index 7b0fded4..ededc567 100644 --- a/Sources/Core/ScopeRegistry.swift +++ b/Sources/Core/ScopeRegistry.swift @@ -5,12 +5,16 @@ import Foundation public protocol ScopeRegistry { - func instance(for key: ScopeRegistryKey, builder: () throws -> Any, finalizer: (Any) throws -> Void) rethrows -> Any + func instance( + for key: ScopeRegistryKey, + builder: () throws -> Reference, + finalizer: (Any) throws -> Void + ) rethrows -> Any func clear() } extension ScopeRegistry { - func instance(for key: ScopeRegistryKey, builder: () throws -> Any) rethrows -> Any { + func instance(for key: ScopeRegistryKey, builder: () throws -> Reference) rethrows -> Any { try instance(for: key, builder: builder, finalizer: { _ in }) } } @@ -23,12 +27,12 @@ public class StandardScopeRegistry: ScopeRegistry, Closable { public func instance( for key: ScopeRegistryKey, - builder: () throws -> Any, + builder: () throws -> Reference, finalizer: (Any) throws -> Void ) rethrows -> Any { try lock.sync { if let instance = instances[key] { return instance } - let newInstance = try builder() + let newInstance = try builder().currentValue if let instance = instances[key] { return instance } instances[key] = newInstance try finalizer(newInstance) diff --git a/Sources/Core/ScopedBinding.swift b/Sources/Core/ScopedBinding.swift index 648b0ca7..e64cbc07 100644 --- a/Sources/Core/ScopedBinding.swift +++ b/Sources/Core/ScopedBinding.swift @@ -17,7 +17,7 @@ extension ScopedBinding: Binding { try scope .registry(for: context) .instance(for: ScopeRegistryKey(descriptor: key.descriptor, argument: arg)) { - try maker.makeInstance(arg: arg, context: context, resolver: resolver) + noRef(try maker.makeInstance(arg: arg, context: context, resolver: resolver)) } } } diff --git a/Tests/Support/NonGeneratedMocks.swift b/Tests/Support/NonGeneratedMocks.swift index 27976eb0..ac34bb28 100644 --- a/Tests/Support/NonGeneratedMocks.swift +++ b/Tests/Support/NonGeneratedMocks.swift @@ -69,7 +69,7 @@ protocol StaticScopeRegistry { extension StaticScopeRegistryMock: ScopeRegistry { func instance( for key: ScopeRegistryKey, - builder _: () throws -> Any, + builder _: () throws -> Reference, finalizer: (Any) throws -> Void ) rethrows -> Any { instance(key: key) @@ -77,8 +77,12 @@ extension StaticScopeRegistryMock: ScopeRegistry { } struct BuilderScopeRegistry: ScopeRegistry { - func instance(for _: ScopeRegistryKey, builder: () throws -> Any, finalizer: (Any) throws -> Void) rethrows -> Any { - try builder() + func instance( + for _: ScopeRegistryKey, + builder: () throws -> Reference, + finalizer: (Any) throws -> Void + ) rethrows -> Any { + try builder().currentValue } func clear() {} diff --git a/Tests/Unit Specs/ReferenceMakerSpec.swift b/Tests/Unit Specs/ReferenceMakerSpec.swift index 72043c90..a74e5d8e 100644 --- a/Tests/Unit Specs/ReferenceMakerSpec.swift +++ b/Tests/Unit Specs/ReferenceMakerSpec.swift @@ -7,34 +7,27 @@ import Quick @testable import Swinject class ReferenceMakerSpec: QuickSpec { override func spec() { - var maker: ReferenceMaker! describe("strongRef") { - beforeEach { - maker = strongRef - } it("returns given value") { let human = Human() - let reference = maker.makeReference(for: human) + let reference = strongRef(human) expect(reference.currentValue) === human } it("persists given value") { - var reference: Reference? = maker.makeReference(for: Human()) + var reference: Reference? = strongRef(Human()) let nextValue = reference!.nextValue reference = nil expect(nextValue()).notTo(beNil()) } } describe("weakRef") { - beforeEach { - maker = weakRef - } it("returns given value") { let human = Human() - let reference = maker.makeReference(for: human) + let reference = weakRef(human) expect(reference.currentValue) === human } it("does not keep strong reference on value") { - var reference: Reference? = maker.makeReference(for: Human()) + var reference: Reference? = weakRef(Human()) let nextValue = reference!.nextValue reference = nil expect(nextValue()).to(beNil()) diff --git a/Tests/Unit Specs/StandardScopeRegistrySpec.swift b/Tests/Unit Specs/StandardScopeRegistrySpec.swift index 97dd95c5..fefdac58 100644 --- a/Tests/Unit Specs/StandardScopeRegistrySpec.swift +++ b/Tests/Unit Specs/StandardScopeRegistrySpec.swift @@ -17,7 +17,7 @@ class StandardScopeRegistrySpec: QuickSpec { override func spec() { describe("instance") { var builderCallCount = 0 var finalizerCallCount = 0 - let countingBuilder: () -> Any = { builderCallCount += 1; return 0 } + let countingBuilder: () -> Reference = { builderCallCount += 1; return strongRef(0) } let countingFinalizer: (Any) -> Void = { _ in finalizerCallCount += 1 } beforeEach { builderCallCount = 0 @@ -40,41 +40,41 @@ class StandardScopeRegistrySpec: QuickSpec { override func spec() { }.to(throwError(errorType: TestError.self)) } it("returns result of builder for first invocation") { - expect(registry.instance(for: key[0]) { 42 } as? Int) == 42 + expect(registry.instance(for: key[0]) { strongRef(42) } as? Int) == 42 } it("returns result of builder on second invocation") { - _ = registry.instance(for: key[0]) { 42 } - _ = registry.instance(for: key[1]) { 25 } - expect(registry.instance(for: key[0]) { 0 } as? Int) == 42 - expect(registry.instance(for: key[1]) { 0 } as? Int) == 25 + _ = registry.instance(for: key[0]) { strongRef(42) } + _ = registry.instance(for: key[1]) { strongRef(25) } + expect(registry.instance(for: key[0]) { strongRef(0) } as? Int) == 42 + expect(registry.instance(for: key[1]) { strongRef(0) } as? Int) == 25 } it("calls finalizer on first invocation for key") { - _ = registry.instance(for: key[0], builder: { 0 }, finalizer: countingFinalizer) + _ = registry.instance(for: key[0], builder: { strongRef(0) }, finalizer: countingFinalizer) expect(finalizerCallCount) == 1 } it("rethrows error from finalizer") { expect { - try registry.instance(for: key[0], builder: { 0 }, finalizer: { _ in throw TestError() }) + try registry.instance(for: key[0], builder: { strongRef(0) }, finalizer: { _ in throw TestError() }) }.to(throwError(errorType: TestError.self)) } it("calls finalizer with instance from builder") { var instance: Any? - _ = registry.instance(for: key[0], builder: { 42 }, finalizer: { instance = $0 }) + _ = registry.instance(for: key[0], builder: { strongRef(42) }, finalizer: { instance = $0 }) expect(instance as? Int) == 42 } it("only calls finalizer on first invocation for each key") { - _ = registry.instance(for: key[0], builder: { 0 }, finalizer: countingFinalizer) - _ = registry.instance(for: key[1], builder: { 0 }, finalizer: countingFinalizer) - _ = registry.instance(for: key[0], builder: { 0 }, finalizer: countingFinalizer) - _ = registry.instance(for: key[1], builder: { 0 }, finalizer: countingFinalizer) + _ = registry.instance(for: key[0], builder: { strongRef(0) }, finalizer: countingFinalizer) + _ = registry.instance(for: key[1], builder: { strongRef(0) }, finalizer: countingFinalizer) + _ = registry.instance(for: key[0], builder: { strongRef(0) }, finalizer: countingFinalizer) + _ = registry.instance(for: key[1], builder: { strongRef(0) }, finalizer: countingFinalizer) expect(finalizerCallCount) == 2 } it("returns the last instance if the same key was used from builder") { let instance = registry.instance( for: key[0], builder: { - _ = registry.instance(for: key[0], builder: { 42 }) - return 0 + _ = registry.instance(for: key[0], builder: { strongRef(42) }) + return strongRef(0) }, finalizer: { _ in } ) @@ -89,8 +89,8 @@ class StandardScopeRegistrySpec: QuickSpec { override func spec() { } describe("clear") { it("closes instances when cleared") { - _ = registry.instance(for: key[0]) { closable[0] } - _ = registry.instance(for: key[1]) { closable[1] } + _ = registry.instance(for: key[0]) { strongRef(closable[0]) } + _ = registry.instance(for: key[1]) { strongRef(closable[1]) } registry.clear() expect(closable[0].closeCallsCount) == 1 expect(closable[1].closeCallsCount) == 1 @@ -98,7 +98,7 @@ class StandardScopeRegistrySpec: QuickSpec { override func spec() { it("releases instance references when cleared") { var human: Human? = Human() weak var weakRef = human - _ = registry.instance(for: key[0]) { human! } + _ = registry.instance(for: key[0]) { strongRef(human!) } registry.clear() human = nil expect(weakRef).to(beNil()) @@ -106,12 +106,12 @@ class StandardScopeRegistrySpec: QuickSpec { override func spec() { } describe("closable") { it("does not close instance by default") { - _ = registry.instance(for: key[0]) { closable[0] } + _ = registry.instance(for: key[0]) { strongRef(closable[0]) } expect(closable[0].closeCallsCount) == 0 } it("closes instances when closed") { - _ = registry.instance(for: key[0]) { closable[0] } - _ = registry.instance(for: key[1]) { closable[1] } + _ = registry.instance(for: key[0]) { strongRef(closable[0]) } + _ = registry.instance(for: key[1]) { strongRef(closable[1]) } registry.close() expect(closable[0].closeCallsCount) == 1 expect(closable[1].closeCallsCount) == 1 @@ -119,7 +119,7 @@ class StandardScopeRegistrySpec: QuickSpec { override func spec() { it("releases instance references when closed") { var human: Human? = Human() weak var weakRef = human - _ = registry.instance(for: key[0]) { human! } + _ = registry.instance(for: key[0]) { strongRef(human!) } registry.close() human = nil expect(weakRef).to(beNil()) @@ -127,8 +127,8 @@ class StandardScopeRegistrySpec: QuickSpec { override func spec() { } describe("deinit") { it("closes instances on deinit") { - _ = registry.instance(for: key[0]) { closable[0] } - _ = registry.instance(for: key[1]) { closable[1] } + _ = registry.instance(for: key[0]) { strongRef(closable[0]) } + _ = registry.instance(for: key[1]) { strongRef(closable[1]) } registry = nil expect(closable[0].closeCallsCount) == 1 expect(closable[1].closeCallsCount) == 1 @@ -141,7 +141,7 @@ class StandardScopeRegistrySpec: QuickSpec { override func spec() { _ = registry.instance(for: key[0]) { Thread.sleep(forTimeInterval: 0.1) builderCallCount += 1 - return 0 + return strongRef(0) } } expect(builderCallCount) == 1 @@ -149,7 +149,7 @@ class StandardScopeRegistrySpec: QuickSpec { override func spec() { it("closes instance only once when closed concurrently multiple times") { let closable = ClosableMock() closable.closeClosure = { Thread.sleep(forTimeInterval: 0.1) } - _ = registry.instance(for: key[0]) { closable } + _ = registry.instance(for: key[0]) { strongRef(closable) } concurrentPerform(iterations: 5, action: registry.close) expect(closable.closeCallsCount) == 1 } @@ -157,7 +157,7 @@ class StandardScopeRegistrySpec: QuickSpec { override func spec() { waitUntil { done in DispatchQueue.global(qos: .background).async { _ = registry.instance(for: key[0]) { - registry.instance(for: key[1]) { 42 } + strongRef(registry.instance(for: key[1]) { strongRef(42) }) } done() } From 9c36e4e9b3e307b0e4185a1369271f7c74418c26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Wed, 24 Jul 2019 22:00:43 +0200 Subject: [PATCH 121/239] Update standard registry to properly handle references --- Sources/Core/ScopeRegistry.swift | 16 ++++----- .../StandardScopeRegistrySpec.swift | 33 ++++++++++++++++--- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/Sources/Core/ScopeRegistry.swift b/Sources/Core/ScopeRegistry.swift index ededc567..5b6c6af9 100644 --- a/Sources/Core/ScopeRegistry.swift +++ b/Sources/Core/ScopeRegistry.swift @@ -21,7 +21,7 @@ extension ScopeRegistry { public class StandardScopeRegistry: ScopeRegistry, Closable { private let lock = NSRecursiveLock() - private var instances = [ScopeRegistryKey: Any]() + private var instances = [ScopeRegistryKey: () -> Any?]() public init() {} @@ -31,18 +31,18 @@ public class StandardScopeRegistry: ScopeRegistry, Closable { finalizer: (Any) throws -> Void ) rethrows -> Any { try lock.sync { - if let instance = instances[key] { return instance } - let newInstance = try builder().currentValue - if let instance = instances[key] { return instance } - instances[key] = newInstance - try finalizer(newInstance) - return newInstance + if let instance = instances[key]?() { return instance } + let ref = try builder() + if let instance = instances[key]?() { return instance } + instances[key] = ref.nextValue + try finalizer(ref.currentValue) + return ref.currentValue } } public func close() { lock.sync { - instances.values.forEach { ($0 as? Closable)?.close() } + instances.values.forEach { ($0() as? Closable)?.close() } instances.removeAll() } } diff --git a/Tests/Unit Specs/StandardScopeRegistrySpec.swift b/Tests/Unit Specs/StandardScopeRegistrySpec.swift index fefdac58..d451e07a 100644 --- a/Tests/Unit Specs/StandardScopeRegistrySpec.swift +++ b/Tests/Unit Specs/StandardScopeRegistrySpec.swift @@ -34,17 +34,40 @@ class StandardScopeRegistrySpec: QuickSpec { override func spec() { _ = registry.instance(for: key[1], builder: countingBuilder) expect(builderCallCount) == 2 } + it("calls builder every time if reference returns nil for next value") { + let noRefBuilder: () -> Reference = { builderCallCount += 1; return noRef(0) } + _ = registry.instance(for: key[0], builder: noRefBuilder) + _ = registry.instance(for: key[1], builder: noRefBuilder) + _ = registry.instance(for: key[0], builder: noRefBuilder) + _ = registry.instance(for: key[1], builder: noRefBuilder) + expect(builderCallCount) == 4 + } + it("does not call builder's nextValue before second invocation") { + var nextValueCalled = false + _ = registry.instance(for: key[0]) { + Reference(currentValue: 42) { nextValueCalled = true; return 0 } + } + expect(nextValueCalled) == false + } + it("does not keep reference on builder's currentValue") { + var human = Human() as Human? + weak var weakRef = human + _ = registry.instance(for: key[0]) { Reference(currentValue: human!, nextValue: { nil }) } + human = nil + expect(weakRef).to(beNil()) + } it("rethtrows error from builder") { expect { try registry.instance(for: key[0]) { throw TestError() } }.to(throwError(errorType: TestError.self)) } - it("returns result of builder for first invocation") { - expect(registry.instance(for: key[0]) { strongRef(42) } as? Int) == 42 + it("returns result of builder's currentValue for first invocation") { + let builder: () -> Reference = { Reference(currentValue: 42, nextValue: { 0 }) } + expect(registry.instance(for: key[0], builder: builder) as? Int) == 42 } - it("returns result of builder on second invocation") { - _ = registry.instance(for: key[0]) { strongRef(42) } - _ = registry.instance(for: key[1]) { strongRef(25) } + it("returns result of builder's next value on second invocation") { + _ = registry.instance(for: key[0]) { Reference(currentValue: 0, nextValue: { 42 }) } + _ = registry.instance(for: key[1]) { Reference(currentValue: 0, nextValue: { 25 }) } expect(registry.instance(for: key[0]) { strongRef(0) } as? Int) == 42 expect(registry.instance(for: key[1]) { strongRef(0) } as? Int) == 25 } From 1a3a730401853fe8f7944417a627ee13cf4beff2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Wed, 24 Jul 2019 22:28:38 +0200 Subject: [PATCH 122/239] Add reference maker to scoped binding --- Sources/3.0 API/BinderEnvironment.swift | 30 +++++++++++----------- Sources/Core/ScopedBinding.swift | 14 ++++++++--- Tests/Unit Specs/ScopedBindingSpec.swift | 32 ++++++++++++++++++------ 3 files changed, 51 insertions(+), 25 deletions(-) diff --git a/Sources/3.0 API/BinderEnvironment.swift b/Sources/3.0 API/BinderEnvironment.swift index 9418634a..50fe07e4 100644 --- a/Sources/3.0 API/BinderEnvironment.swift +++ b/Sources/3.0 API/BinderEnvironment.swift @@ -47,37 +47,37 @@ public extension BinderEnvironment where AScope == Void { public extension BinderEnvironment where AScope: Scope, Context == AScope.Context { func singleton(_ builder: @escaping () throws -> Type) -> ScopedBinding.Builder { - .init(scope) { _, _, _ in try builder() } + .init(scope, strongRef) { _, _, _ in try builder() } } func singleton(_ builder: @escaping (Resolver) throws -> Type) -> ScopedBinding.Builder { - .init(scope) { r, _, _ in try builder(r) } + .init(scope, strongRef) { r, _, _ in try builder(r) } } func singleton(_ builder: @escaping (Resolver, Context) throws -> Type) -> ScopedBinding.Builder { - .init(scope) { r, c, _ in try builder(r, c) } + .init(scope, strongRef) { r, c, _ in try builder(r, c) } } } public extension BinderEnvironment where AScope: Scope, Context == AScope.Context { func multiton(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> ScopedBinding.Builder { - .init(scope, builder) + .init(scope, strongRef, builder) } func multiton(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> ScopedBinding.Builder { - .init(scope) { try builder($0, $1, $2.0, $2.1) } + .init(scope, strongRef) { try builder($0, $1, $2.0, $2.1) } } func multiton(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> ScopedBinding.Builder { - .init(scope) { try builder($0, $1, $2.0, $2.1, $2.2) } + .init(scope, strongRef) { try builder($0, $1, $2.0, $2.1, $2.2) } } func multiton(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> ScopedBinding.Builder { - .init(scope) { try builder($0, $1, $2.0, $2.1, $2.2, $2.3) } + .init(scope, strongRef) { try builder($0, $1, $2.0, $2.1, $2.2, $2.3) } } func multiton(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> ScopedBinding.Builder { - .init(scope) { try builder($0, $1, $2.0, $2.1, $2.2, $2.3, $2.4) } + .init(scope, strongRef) { try builder($0, $1, $2.0, $2.1, $2.2, $2.3, $2.4) } } } @@ -114,29 +114,29 @@ public func factory(_ builder: @escaping (Re } public func singleton(_ builder: @escaping () throws -> Type) -> ScopedBinding.Builder { - .init(.root) { _, _, _ in try builder() } + .init(.root, strongRef) { _, _, _ in try builder() } } public func singleton(_ builder: @escaping (Resolver) throws -> Type) -> ScopedBinding.Builder { - .init(.root) { r, _, _ in try builder(r) } + .init(.root, strongRef) { r, _, _ in try builder(r) } } public func multiton(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> ScopedBinding.Builder { - .init(.root) { try builder($0, $2) } + .init(.root, strongRef) { try builder($0, $2) } } public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> ScopedBinding.Builder { - .init(.root) { try builder($0, $2.0, $2.1) } + .init(.root, strongRef) { try builder($0, $2.0, $2.1) } } public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> ScopedBinding.Builder { - .init(.root) { try builder($0, $2.0, $2.1, $2.2) } + .init(.root, strongRef) { try builder($0, $2.0, $2.1, $2.2) } } public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> ScopedBinding.Builder { - .init(.root) { try builder($0, $2.0, $2.1, $2.2, $2.3) } + .init(.root, strongRef) { try builder($0, $2.0, $2.1, $2.2, $2.3) } } public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> ScopedBinding.Builder { - .init(.root) { try builder($0, $2.0, $2.1, $2.2, $2.3, $2.4) } + .init(.root, strongRef) { try builder($0, $2.0, $2.1, $2.2, $2.3, $2.4) } } diff --git a/Sources/Core/ScopedBinding.swift b/Sources/Core/ScopedBinding.swift index e64cbc07..30abd7d6 100644 --- a/Sources/Core/ScopedBinding.swift +++ b/Sources/Core/ScopedBinding.swift @@ -6,6 +6,7 @@ public struct ScopedBinding { let key: AnyBindingKey let maker: AnyInstanceMaker let scope: AnyScope + let makeRef: ReferenceMaker } extension ScopedBinding: Binding { @@ -17,7 +18,7 @@ extension ScopedBinding: Binding { try scope .registry(for: context) .instance(for: ScopeRegistryKey(descriptor: key.descriptor, argument: arg)) { - noRef(try maker.makeInstance(arg: arg, context: context, resolver: resolver)) + makeRef(try maker.makeInstance(arg: arg, context: context, resolver: resolver)) } } } @@ -25,9 +26,15 @@ extension ScopedBinding: Binding { extension ScopedBinding { public struct Builder where AScope: Scope { let scope: AScope + let makeRef: ReferenceMaker private let builder: (Resolver, Context, Argument) throws -> Type - init(_ scope: AScope, _ builder: @escaping (Resolver, Context, Argument) throws -> Type) { + init( + _ scope: AScope, + _ makeRef: @escaping ReferenceMaker, + _ builder: @escaping (Resolver, Context, Argument) throws -> Type + ) { + self.makeRef = makeRef self.scope = scope self.builder = builder } @@ -50,7 +57,8 @@ extension ScopedBinding.Builder: BindingMaker { ScopedBinding( key: BindingKey(descriptor: descriptor, contextType: Context.self, argumentType: Argument.self), maker: self, - scope: scope + scope: scope, + makeRef: makeRef ) } } diff --git a/Tests/Unit Specs/ScopedBindingSpec.swift b/Tests/Unit Specs/ScopedBindingSpec.swift index 1e324db3..2eabf495 100644 --- a/Tests/Unit Specs/ScopedBindingSpec.swift +++ b/Tests/Unit Specs/ScopedBindingSpec.swift @@ -10,7 +10,8 @@ class ScopedBindingSpec: QuickSpec { override func spec() { describe("binding builder") { let descriptor = AnyTypeDescriptorMock() let scope = DummyScope() - let builder = ScopedBinding.Builder, Int>(scope) { _, _, _ in } + let makeRef: ReferenceMaker = { _ in noRef(42) } + let builder = ScopedBinding.Builder, Int>(scope, makeRef) { _, _, _ in } it("makes binding with self as maker") { let binding = builder.makeBinding(for: descriptor) as? ScopedBinding expect(binding?.maker is ScopedBinding.Builder, Int>).to(beTrue()) @@ -25,6 +26,10 @@ class ScopedBindingSpec: QuickSpec { override func spec() { let binding = builder.makeBinding(for: descriptor) as? ScopedBinding expect(binding?.scope) === scope } + it("makes binding with correct reference maker") { + let binding = builder.makeBinding(for: descriptor) as? ScopedBinding + expect(binding?.makeRef(0).currentValue as? Int) == 42 + } } describe("matching") { var key = AnyBindingKeyMock() @@ -34,7 +39,9 @@ class ScopedBindingSpec: QuickSpec { override func spec() { key = AnyBindingKeyMock() bindingKey = AnyBindingKeyMock() bindingKey.matchesReturnValue = false - binding = ScopedBinding(key: bindingKey, maker: AnyInstanceMakerMock(), scope: AnyScopeMock()) + binding = ScopedBinding( + key: bindingKey, maker: AnyInstanceMakerMock(), scope: AnyScopeMock(), makeRef: noRef + ) } it("passes the input key to the binding key") { _ = binding.matches(key) @@ -62,7 +69,7 @@ class ScopedBindingSpec: QuickSpec { override func spec() { maker = AnyInstanceMakerMock() key = AnyBindingKeyMock() key.descriptor = AnyTypeDescriptorMock() - binding = ScopedBinding(key: key, maker: maker, scope: scope) + binding = ScopedBinding(key: key, maker: maker, scope: scope, makeRef: noRef) } it("retrieves registry using passed context") { _ = try? binding.instance(arg: (), context: "context", resolver: DummyResolver()) @@ -79,18 +86,29 @@ class ScopedBindingSpec: QuickSpec { override func spec() { beforeEach { scope.registryForReturnValue = BuilderScopeRegistry() } - it("returns instance produced by maker") { - maker.makeInstanceArgContextResolverReturnValue = 42 + it("returns instance produced by reference maker") { + binding = ScopedBinding(key: key, maker: maker, scope: scope) { _ in + Reference(currentValue: 42, nextValue: { 42 }) + } let instance = try? binding.instance(arg: (), context: (), resolver: DummyResolver()) as? Int expect(instance) == 42 } - it("rethrows error from maker") { + it("invokes reference maker with the instance from the instance maker") { + var makeRefInput: Any? + maker.makeInstanceArgContextResolverReturnValue = 42 + binding = ScopedBinding(key: key, maker: maker, scope: scope) { + makeRefInput = $0; return noRef($0) + } + _ = try? binding.instance(arg: 0, context: (), resolver: DummyResolver()) + expect(makeRefInput as? Int) == 42 + } + it("rethrows error from instance maker") { maker.makeInstanceArgContextResolverThrowableError = TestError() expect { try binding.instance(arg: (), context: (), resolver: DummyResolver()) }.to(throwError(errorType: TestError.self)) } - it("invokes maker with correct parameters") { + it("invokes instance maker with correct parameters") { let resolver = DummyResolver() _ = try? binding.instance(arg: 42, context: "context", resolver: resolver) expect(maker.makeInstanceArgContextResolverReceivedArguments?.arg as? Int) == 42 From ed9fd070e76c51ab2d446bbd75d6545fd001f98b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Wed, 24 Jul 2019 22:39:49 +0200 Subject: [PATCH 123/239] Allow reference maker definition during scoped binder declaration --- Sources/3.0 API/BinderEnvironment.swift | 28 ++++++++++---------- Sources/Core/Reference.swift | 2 +- Sources/Core/ScopedBinding.swift | 7 +++-- Tests/Unit Specs/BinderEnvironmentSpec.swift | 12 ++++++++- Tests/Unit Specs/ScopedBindingSpec.swift | 6 ++--- 5 files changed, 34 insertions(+), 21 deletions(-) diff --git a/Sources/3.0 API/BinderEnvironment.swift b/Sources/3.0 API/BinderEnvironment.swift index 50fe07e4..f25ee592 100644 --- a/Sources/3.0 API/BinderEnvironment.swift +++ b/Sources/3.0 API/BinderEnvironment.swift @@ -113,30 +113,30 @@ public func factory(_ builder: @escaping (Re SimpleBinding.Builder { try builder($0, $2.0, $2.1, $2.2, $2.3, $2.4) } } -public func singleton(_ builder: @escaping () throws -> Type) -> ScopedBinding.Builder { - .init(.root, strongRef) { _, _, _ in try builder() } +public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping () throws -> Type) -> ScopedBinding.Builder { + .init(.root, ref) { _, _, _ in try builder() } } -public func singleton(_ builder: @escaping (Resolver) throws -> Type) -> ScopedBinding.Builder { - .init(.root, strongRef) { r, _, _ in try builder(r) } +public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver) throws -> Type) -> ScopedBinding.Builder { + .init(.root, ref) { r, _, _ in try builder(r) } } -public func multiton(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> ScopedBinding.Builder { - .init(.root, strongRef) { try builder($0, $2) } +public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1) throws -> Type) -> ScopedBinding.Builder { + .init(.root, ref) { try builder($0, $2) } } -public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> ScopedBinding.Builder { - .init(.root, strongRef) { try builder($0, $2.0, $2.1) } +public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> ScopedBinding.Builder { + .init(.root, ref) { try builder($0, $2.0, $2.1) } } -public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> ScopedBinding.Builder { - .init(.root, strongRef) { try builder($0, $2.0, $2.1, $2.2) } +public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> ScopedBinding.Builder { + .init(.root, ref) { try builder($0, $2.0, $2.1, $2.2) } } -public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> ScopedBinding.Builder { - .init(.root, strongRef) { try builder($0, $2.0, $2.1, $2.2, $2.3) } +public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> ScopedBinding.Builder { + .init(.root, ref) { try builder($0, $2.0, $2.1, $2.2, $2.3) } } -public func multiton(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> ScopedBinding.Builder { - .init(.root, strongRef) { try builder($0, $2.0, $2.1, $2.2, $2.3, $2.4) } +public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> ScopedBinding.Builder { + .init(.root, ref) { try builder($0, $2.0, $2.1, $2.2, $2.3, $2.4) } } diff --git a/Sources/Core/Reference.swift b/Sources/Core/Reference.swift index 74d3cb44..86f85453 100644 --- a/Sources/Core/Reference.swift +++ b/Sources/Core/Reference.swift @@ -7,7 +7,7 @@ public struct Reference { let nextValue: () -> T? } -typealias ReferenceMaker = (T) -> Reference +public typealias ReferenceMaker = (T) -> Reference public func strongRef(_ value: T) -> Reference { Reference(currentValue: value, nextValue: { value }) diff --git a/Sources/Core/ScopedBinding.swift b/Sources/Core/ScopedBinding.swift index 30abd7d6..cdc0e70f 100644 --- a/Sources/Core/ScopedBinding.swift +++ b/Sources/Core/ScopedBinding.swift @@ -31,10 +31,13 @@ extension ScopedBinding { init( _ scope: AScope, - _ makeRef: @escaping ReferenceMaker, + _ makeRef: @escaping ReferenceMaker, _ builder: @escaping (Resolver, Context, Argument) throws -> Type ) { - self.makeRef = makeRef + self.makeRef = { + let ref = makeRef($0 as! Type) + return Reference(currentValue: ref.currentValue, nextValue: { ref.nextValue() }) + } self.scope = scope self.builder = builder } diff --git a/Tests/Unit Specs/BinderEnvironmentSpec.swift b/Tests/Unit Specs/BinderEnvironmentSpec.swift index 09da8a37..7af35d52 100644 --- a/Tests/Unit Specs/BinderEnvironmentSpec.swift +++ b/Tests/Unit Specs/BinderEnvironmentSpec.swift @@ -113,9 +113,14 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { } describe("singleton") { it("has correct scope") { - let maker = singleton { 42 } + let maker = singleton { 0 } expect(maker.scope) === UnboundScope.root } + it("has correct reference maker") { + let makeRef: ReferenceMaker = { _ in noRef(42) } + let maker = singleton(ref: makeRef) { 0 } + expect(maker.makeRef(0).currentValue as? Int) == 42 + } it("returns instance made by builder") { let maker = singleton { 42 } expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 @@ -148,6 +153,11 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { let maker = multiton { (_, _: Void) in 42 } expect(maker.scope) === UnboundScope.root } + it("has correct reference maker") { + let makeRef: ReferenceMaker = { _ in noRef(42) } + let maker = singleton(ref: makeRef) { 0 } + expect(maker.makeRef(0).currentValue as? Int) == 42 + } it("returns instance made by builder method") { let maker = multiton { (_, _: Void) in 42 } expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 diff --git a/Tests/Unit Specs/ScopedBindingSpec.swift b/Tests/Unit Specs/ScopedBindingSpec.swift index 2eabf495..2b957b3e 100644 --- a/Tests/Unit Specs/ScopedBindingSpec.swift +++ b/Tests/Unit Specs/ScopedBindingSpec.swift @@ -10,11 +10,11 @@ class ScopedBindingSpec: QuickSpec { override func spec() { describe("binding builder") { let descriptor = AnyTypeDescriptorMock() let scope = DummyScope() - let makeRef: ReferenceMaker = { _ in noRef(42) } - let builder = ScopedBinding.Builder, Int>(scope, makeRef) { _, _, _ in } + let makeRef: ReferenceMaker = { _ in noRef(42) } + let builder = ScopedBinding.Builder, Int>(scope, makeRef) { _, _, _ in 0 } it("makes binding with self as maker") { let binding = builder.makeBinding(for: descriptor) as? ScopedBinding - expect(binding?.maker is ScopedBinding.Builder, Int>).to(beTrue()) + expect(binding?.maker is ScopedBinding.Builder, Int>).to(beTrue()) } it("makes binding with correct key") { let binding = builder.makeBinding(for: descriptor) as? ScopedBinding From 7abecd7ae4d7b8a1d45bfbba1ba7e52023af9aba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Wed, 24 Jul 2019 23:37:09 +0200 Subject: [PATCH 124/239] Add reference maker to service entry --- Sources/2.0 API/Assembler.swift | 9 ++++- Sources/2.0 API/Container+Registration.swift | 20 +++++----- Sources/2.0 API/Container.swift | 4 ++ Sources/2.0 API/ObjectScope.swift | 12 +++++- Sources/2.0 API/ServiceEntry.swift | 10 +++-- Sources/Core/Reference.swift | 4 +- .../Container+Registration.swifttemplate | 4 +- Tests/2.0 API/AssemblerSpec.swift | 2 +- Tests/2.0 API/ContainerSpec.Circularity.swift | 27 +++++++------ Tests/2.0 API/ContainerSpec.swift | 39 +++++++++---------- 10 files changed, 78 insertions(+), 53 deletions(-) diff --git a/Sources/2.0 API/Assembler.swift b/Sources/2.0 API/Assembler.swift index 721edd30..496bc6de 100644 --- a/Sources/2.0 API/Assembler.swift +++ b/Sources/2.0 API/Assembler.swift @@ -46,6 +46,7 @@ public final class Assembler { assemblies, parent: parent, defaultScope: defaultObjectScope.scope, + defaultMakeRef: defaultObjectScope.makeRef, behaviors: behaviors ) } @@ -60,9 +61,15 @@ public final class Assembler { _ assemblies: [Assembly] = [], parent: Assembler? = nil, defaultScope: AnyScope?, + defaultMakeRef: @escaping ReferenceMaker, behaviors: [Behavior] = [] ) { - container = Container(parent: parent?.container, defaultScope: defaultScope, behaviors: behaviors) + container = Container( + parent: parent?.container, + defaultScope: defaultScope, + defaultMakeRef: defaultMakeRef, + behaviors: behaviors + ) run(assemblies: assemblies) } diff --git a/Sources/2.0 API/Container+Registration.swift b/Sources/2.0 API/Container+Registration.swift index 7c759bc0..7721be7d 100644 --- a/Sources/2.0 API/Container+Registration.swift +++ b/Sources/2.0 API/Container+Registration.swift @@ -19,7 +19,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultScope) { (r, _, _: Void) in factory(r) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, _: Void) in factory(r) } addEntry(entry, with: name) return entry } @@ -38,7 +38,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultScope) { (r, _, a: Arg1) in factory(r, a) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, a: Arg1) in factory(r, a) } addEntry(entry, with: name) return entry } @@ -57,7 +57,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2)) in factory(r, a.0, a.1) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, a: (Arg1, Arg2)) in factory(r, a.0, a.1) } addEntry(entry, with: name) return entry } @@ -76,7 +76,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3)) in factory(r, a.0, a.1, a.2) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, a: (Arg1, Arg2, Arg3)) in factory(r, a.0, a.1, a.2) } addEntry(entry, with: name) return entry } @@ -95,7 +95,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3, Arg4)) in factory(r, a.0, a.1, a.2, a.3) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, a: (Arg1, Arg2, Arg3, Arg4)) in factory(r, a.0, a.1, a.2, a.3) } addEntry(entry, with: name) return entry } @@ -114,7 +114,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5)) in factory(r, a.0, a.1, a.2, a.3, a.4) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5)) in factory(r, a.0, a.1, a.2, a.3, a.4) } addEntry(entry, with: name) return entry } @@ -133,7 +133,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5) } addEntry(entry, with: name) return entry } @@ -152,7 +152,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6) } addEntry(entry, with: name) return entry } @@ -171,7 +171,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6, a.7) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6, a.7) } addEntry(entry, with: name) return entry } @@ -190,7 +190,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultScope) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6, a.7, a.8) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6, a.7, a.8) } addEntry(entry, with: name) return entry } diff --git a/Sources/2.0 API/Container.swift b/Sources/2.0 API/Container.swift index 1ffc3e0b..7fe9fa33 100644 --- a/Sources/2.0 API/Container.swift +++ b/Sources/2.0 API/Container.swift @@ -23,6 +23,7 @@ public final class Container { let registry: ScopeRegistry let parent: Container? let defaultScope: AnyScope? + let defaultMakeRef: ReferenceMaker var bindings = [Binding]() var behaviors = [Behavior]() var swinject: Swinject { Swinject(tree: SwinjectTree( @@ -47,11 +48,13 @@ public final class Container { public init( parent: Container? = nil, defaultScope: AnyScope?, + defaultMakeRef: @escaping ReferenceMaker, behaviors: [Behavior] = [], registeringClosure: (Container) -> Void = { _ in } ) { self.parent = parent self.defaultScope = defaultScope + self.defaultMakeRef = defaultMakeRef self.behaviors = behaviors registry = parent?.registry ?? StandardScopeRegistry() registeringClosure(self) @@ -76,6 +79,7 @@ public final class Container { self.init( parent: parent, defaultScope: defaultObjectScope.scope, + defaultMakeRef: defaultObjectScope.makeRef, behaviors: behaviors, registeringClosure: registeringClosure ) diff --git a/Sources/2.0 API/ObjectScope.swift b/Sources/2.0 API/ObjectScope.swift index 47bd0328..340f89d9 100644 --- a/Sources/2.0 API/ObjectScope.swift +++ b/Sources/2.0 API/ObjectScope.swift @@ -27,7 +27,17 @@ extension ObjectScope { switch self { case .graph: return GraphScope.shared case .container: return ContainerScope.shared - default: return nil + case .weak: return ContainerScope.shared + case .transient: return nil + } + } + + var makeRef: ReferenceMaker { + switch self { + case .graph: return strongRef + case .container: return strongRef + case .weak: return weakRef + case .transient: return noRef } } } diff --git a/Sources/2.0 API/ServiceEntry.swift b/Sources/2.0 API/ServiceEntry.swift index 35384c8c..add98141 100644 --- a/Sources/2.0 API/ServiceEntry.swift +++ b/Sources/2.0 API/ServiceEntry.swift @@ -10,6 +10,7 @@ public class ServiceEntry { let argumentType: Any.Type let name: String? var scope: AnyScope? + var makeRef: ReferenceMaker var finalizers = [(Resolver, Service) -> Void]() var forwardedDescriptors = [AnyTypeDescriptor]() @@ -17,13 +18,15 @@ public class ServiceEntry { container: Container, name: String?, scope: AnyScope?, + makeRef: @escaping ReferenceMaker, builder: @escaping (Resolver, Any, Argument) -> Service ) { self.container = container - self.builder = { builder($0, $1, $2 as! Argument) } - argumentType = Argument.self self.name = name self.scope = scope + self.makeRef = makeRef + self.builder = { builder($0, $1, $2 as! Argument) } + argumentType = Argument.self } /// Specifies the object scope to resolve the service. @@ -47,6 +50,7 @@ public class ServiceEntry { @discardableResult public func inObjectScope(_ objectScope: ObjectScope) -> Self { scope = objectScope.scope + makeRef = objectScope.makeRef return self } @@ -76,7 +80,7 @@ extension ServiceEntry: Binding { if let scope = scope { return scope.registry(for: context).instance( for: ScopeRegistryKey(descriptor: key.descriptor, argument: arg), - builder: { strongRef(builder(resolver, context, arg)) }, + builder: { makeRef(builder(resolver, context, arg)) }, finalizer: { instance in finalizers.forEach { $0(resolver, instance as! Service) } } ) } else { diff --git a/Sources/Core/Reference.swift b/Sources/Core/Reference.swift index 86f85453..1370f4e6 100644 --- a/Sources/Core/Reference.swift +++ b/Sources/Core/Reference.swift @@ -15,7 +15,9 @@ public func strongRef(_ value: T) -> Reference { public func weakRef(_ value: T) -> Reference { weak var weakValue: AnyObject? = value as AnyObject? - return Reference(currentValue: value, nextValue: { weakValue as? T }) + return Reference(currentValue: value) { + if let value = weakValue as? T { return value } else { return nil } + } } func noRef(_ value: T) -> Reference { diff --git a/Templates/Container+Registration.swifttemplate b/Templates/Container+Registration.swifttemplate index 22feb834..6889b089 100644 --- a/Templates/Container+Registration.swifttemplate +++ b/Templates/Container+Registration.swifttemplate @@ -16,7 +16,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultScope) { (r, _, _: Void) in factory(r) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, _: Void) in factory(r) } addEntry(entry, with: name) return entry } @@ -41,7 +41,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register>(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, <%= arg_types %>) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultScope) { (r, _, a: <%= arg_closure_type %>) in factory(r, <%= arg_vars %>) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, a: <%= arg_closure_type %>) in factory(r, <%= arg_vars %>) } addEntry(entry, with: name) return entry } diff --git a/Tests/2.0 API/AssemblerSpec.swift b/Tests/2.0 API/AssemblerSpec.swift index 64866d1c..78c32458 100644 --- a/Tests/2.0 API/AssemblerSpec.swift +++ b/Tests/2.0 API/AssemblerSpec.swift @@ -53,7 +53,7 @@ class AssemblerSpec: QuickSpec { it("uses injected default custom scope") { let scope = UnboundScope() - let assembler = Assembler(parent: nil, defaultScope: scope) + let assembler = Assembler(parent: nil, defaultScope: scope, defaultMakeRef: strongRef) assembler.apply(assembly: ContainerSpyAssembly()) let container = assembler.resolver.resolve(Container.self) diff --git a/Tests/2.0 API/ContainerSpec.Circularity.swift b/Tests/2.0 API/ContainerSpec.Circularity.swift index ca0941b1..6855ac4a 100644 --- a/Tests/2.0 API/ContainerSpec.Circularity.swift +++ b/Tests/2.0 API/ContainerSpec.Circularity.swift @@ -116,19 +116,18 @@ class ContainerSpec_Circularity: QuickSpec { expect(d.c as? CDependingOnAD === c).to(beTrue()) // Workaround for crash in Nimble } } - // TODO: Implement weak scope -// describe("Graph root is in weak object scope") { -// it("does not deallocate during graph resolution") { -// container.register(B.self) { r in BDependingOnC(c: r.resolve(C.self)!) } -// .inObjectScope(.weak) -// container.register(C.self) { _ in CDependingOnWeakB() } -// .initCompleted { r, c in (c as! CDependingOnWeakB).b = r.resolve(B.self) } -// -// let b = container.resolve(B.self) as? BDependingOnC -// let c = b?.c as? CDependingOnWeakB -// -// expect(c?.b).notTo(beNil()) -// } -// } + describe("Graph root is in weak object scope") { + it("does not deallocate during graph resolution") { + container.register(B.self) { r in BDependingOnC(c: r.resolve(C.self)!) } + .inObjectScope(.weak) + container.register(C.self) { _ in CDependingOnWeakB() } + .initCompleted { r, c in (c as! CDependingOnWeakB).b = r.resolve(B.self) } + + let b = container.resolve(B.self) as? BDependingOnC + let c = b?.c as? CDependingOnWeakB + + expect(c?.b).notTo(beNil()) + } + } } } diff --git a/Tests/2.0 API/ContainerSpec.swift b/Tests/2.0 API/ContainerSpec.swift index 6cd2cadf..96827b64 100644 --- a/Tests/2.0 API/ContainerSpec.swift +++ b/Tests/2.0 API/ContainerSpec.swift @@ -187,25 +187,24 @@ class ContainerSpec: QuickSpec { expect(ownersSushi === catsSushi).to(beTrue()) // Workaround for crash in Nimble. } } - // TODO: implement weak scope -// context("in weak scope") { -// it("shares the object in the container") { -// container.register(Animal.self) { _ in Cat() } -// .inObjectScope(.weak) -// -// let cat1 = container.resolve(Animal.self) as? Cat -// let cat2 = container.resolve(Animal.self) as? Cat -// expect(cat1).notTo(beNil()) -// expect(cat1 === cat2).to(beTrue()) // Workaround for crash in Nimble. -// } -// it("does not maintain a strong reference to the object") { -// container.register(Animal.self) { _ in Cat() } -// .inObjectScope(.weak) -// -// weak var cat = container.resolve(Animal.self) as? Cat -// expect(cat).to(beNil()) -// } -// } + context("in weak scope") { + it("shares the object in the container") { + container.register(Animal.self) { _ in Cat() } + .inObjectScope(.weak) + + let cat1 = container.resolve(Animal.self) as? Cat + let cat2 = container.resolve(Animal.self) as? Cat + expect(cat1).notTo(beNil()) + expect(cat1 === cat2).to(beTrue()) // Workaround for crash in Nimble. + } + it("does not maintain a strong reference to the object") { + container.register(Animal.self) { _ in Cat() } + .inObjectScope(.weak) + + weak var cat = container.resolve(Animal.self) as? Cat + expect(cat).to(beNil()) + } + } } describe("Init completed event") { it("raises the event when a new instance is created.") { @@ -374,7 +373,7 @@ class ContainerSpec: QuickSpec { } it("registers services with given custom scope") { let scope = UnboundScope() - let container = Container(parent: nil, defaultScope: scope) + let container = Container(parent: nil, defaultScope: scope, defaultMakeRef: strongRef) let serviceEntry = container.register(Animal.self) { _ in Siamese(name: "Siam") } expect(serviceEntry.scope) === scope From e19fa1d1123b0c135713e22410b7ff4010167e45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Wed, 24 Jul 2019 23:46:01 +0200 Subject: [PATCH 125/239] Make weak reference work with type erasure --- Sources/Core/Reference.swift | 2 +- Tests/Support/TestModels.swift | 4 +++- Tests/Unit Specs/ReferenceMakerSpec.swift | 5 +++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Sources/Core/Reference.swift b/Sources/Core/Reference.swift index 1370f4e6..9ad55217 100644 --- a/Sources/Core/Reference.swift +++ b/Sources/Core/Reference.swift @@ -16,7 +16,7 @@ public func strongRef(_ value: T) -> Reference { public func weakRef(_ value: T) -> Reference { weak var weakValue: AnyObject? = value as AnyObject? return Reference(currentValue: value) { - if let value = weakValue as? T { return value } else { return nil } + if let value = weakValue { return value as? T } else { return nil } } } diff --git a/Tests/Support/TestModels.swift b/Tests/Support/TestModels.swift index a11cc969..eb808844 100644 --- a/Tests/Support/TestModels.swift +++ b/Tests/Support/TestModels.swift @@ -2,7 +2,9 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -class Human { +protocol Mammal {} + +class Human: Mammal { var age = 0 var height = 0.0 var name = "" diff --git a/Tests/Unit Specs/ReferenceMakerSpec.swift b/Tests/Unit Specs/ReferenceMakerSpec.swift index a74e5d8e..0342966e 100644 --- a/Tests/Unit Specs/ReferenceMakerSpec.swift +++ b/Tests/Unit Specs/ReferenceMakerSpec.swift @@ -32,5 +32,10 @@ class ReferenceMakerSpec: QuickSpec { override func spec() { reference = nil expect(nextValue()).to(beNil()) } + it("works with type erasure") { + let human: Mammal = Human() + let nextValue = { weakRef(human).nextValue() as Any? } + expect(nextValue() is Mammal) == true + } } } } From 39b07eafe4601d3744fc3bbd45fcc8532f70d114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Thu, 25 Jul 2019 06:08:11 +0200 Subject: [PATCH 126/239] Update container specs --- Sources/2.0 API/Container.swift | 8 +- Tests/2.0 API/ContainerSpec.Circularity.swift | 27 +++---- Tests/2.0 API/ContainerSpec.swift | 73 +++++++++++++------ 3 files changed, 66 insertions(+), 42 deletions(-) diff --git a/Sources/2.0 API/Container.swift b/Sources/2.0 API/Container.swift index 7fe9fa33..0a4daa0d 100644 --- a/Sources/2.0 API/Container.swift +++ b/Sources/2.0 API/Container.swift @@ -20,7 +20,7 @@ import Foundation /// where `A` and `X` are protocols, `B` is a type conforming `A`, and `Y` is a type conforming `X` /// and depending on `A`. public final class Container { - let registry: ScopeRegistry + let registry = StandardScopeRegistry() let parent: Container? let defaultScope: AnyScope? let defaultMakeRef: ReferenceMaker @@ -56,7 +56,6 @@ public final class Container { self.defaultScope = defaultScope self.defaultMakeRef = defaultMakeRef self.behaviors = behaviors - registry = parent?.registry ?? StandardScopeRegistry() registeringClosure(self) } @@ -88,6 +87,7 @@ public final class Container { /// Removes all registrations in the container. public func removeAll() { bindings = [] + registry.clear() } /// Discards instances for services registered in the given `ObjectsScopeProtocol`. @@ -97,9 +97,7 @@ public final class Container { /// /// - Parameters: /// - objectScope: All instances registered in given `ObjectsScopeProtocol` will be discarded. - public func resetObjectScope(_ objectScope: ObjectScope) { - (objectScope.scope as? Closable)?.close() - } + public func resetObjectScope(_: ObjectScope) {} /// Returns a synchronized view of the container for thread safety. /// The returned container is `Resolver` type. Call this method after you finish all service registrations diff --git a/Tests/2.0 API/ContainerSpec.Circularity.swift b/Tests/2.0 API/ContainerSpec.Circularity.swift index 6855ac4a..9fe7e882 100644 --- a/Tests/2.0 API/ContainerSpec.Circularity.swift +++ b/Tests/2.0 API/ContainerSpec.Circularity.swift @@ -116,18 +116,19 @@ class ContainerSpec_Circularity: QuickSpec { expect(d.c as? CDependingOnAD === c).to(beTrue()) // Workaround for crash in Nimble } } - describe("Graph root is in weak object scope") { - it("does not deallocate during graph resolution") { - container.register(B.self) { r in BDependingOnC(c: r.resolve(C.self)!) } - .inObjectScope(.weak) - container.register(C.self) { _ in CDependingOnWeakB() } - .initCompleted { r, c in (c as! CDependingOnWeakB).b = r.resolve(B.self) } - - let b = container.resolve(B.self) as? BDependingOnC - let c = b?.c as? CDependingOnWeakB - - expect(c?.b).notTo(beNil()) - } - } + // Implement subscopes +// describe("Graph root is in weak object scope") { +// it("does not deallocate during graph resolution") { +// container.register(B.self) { r in BDependingOnC(c: r.resolve(C.self)!) } +// .inObjectScope(.weak) +// container.register(C.self) { _ in CDependingOnWeakB() } +// .initCompleted { r, c in (c as! CDependingOnWeakB).b = r.resolve(B.self) } +// +// let b = container.resolve(B.self) as? BDependingOnC +// let c = b?.c as? CDependingOnWeakB +// +// expect(c?.b).notTo(beNil()) +// } +// } } } diff --git a/Tests/2.0 API/ContainerSpec.swift b/Tests/2.0 API/ContainerSpec.swift index 96827b64..4971c1d8 100644 --- a/Tests/2.0 API/ContainerSpec.swift +++ b/Tests/2.0 API/ContainerSpec.swift @@ -156,36 +156,61 @@ class ContainerSpec: QuickSpec { let cat2 = container.resolve(Animal.self) as? Cat expect(cat1 === cat2).to(beTrue()) // Workaround for crash in Nimble. } - it("shares an object from a parent container to its child.") { - let parent = Container() - parent.register(Animal.self) { _ in Cat() } - .inObjectScope(.container) - parent.register(Animal.self, name: "dog") { _ in Dog() } + it("releases instnace after removing registrations") { + container.register(Animal.self) { _ in Cat() } .inObjectScope(.container) - let child = Container(parent: parent) + let cat1 = container.resolve(Animal.self) as? Cat - // Case resolving on the parent first. - let cat1 = parent.resolve(Animal.self) as? Cat - let cat2 = child.resolve(Animal.self) as? Cat - expect(cat1 === cat2).to(beTrue()) // Workaround for crash in Nimble. + container.removeAll() - // Case resolving on the child first. - let dog1 = child.resolve(Animal.self, name: "dog") as? Dog - let dog2 = parent.resolve(Animal.self, name: "dog") as? Dog - expect(dog1 === dog2).to(beTrue()) // Workaround for crash in Nimble. - } - it("resolves a service in the parent container to the same object in a graph") { - let parent = Container() - parent.register(Food.self) { _ in Sushi() } + container.register(Animal.self) { _ in Cat() } .inObjectScope(.container) - let child = Container(parent: parent) - registerCatAndPetOwnerDependingOnFood(child) + let cat2 = container.resolve(Animal.self) as? Cat - let owner = child.resolve(Person.self) as? PetOwner - let ownersSushi = owner?.favoriteFood as? Sushi - let catsSushi = (owner?.pet as? Cat)?.favoriteFood as? Sushi - expect(ownersSushi === catsSushi).to(beTrue()) // Workaround for crash in Nimble. + expect(cat1) !== cat2 } + // TODO: Implement resetting object scope +// it("releases instance after reseting scope") { +// container.register(Animal.self) { _ in Cat() } +// .inObjectScope(.container) +// +// let cat1 = container.resolve(Animal.self) as? Cat +// container.resetObjectScope(.container) +// let cat2 = container.resolve(Animal.self) as? Cat +// +// expect(cat1) !== cat2 +// } + // TODO: Implement subscopes +// it("shares an object from a parent container to its child.") { +// let parent = Container() +// parent.register(Animal.self) { _ in Cat() } +// .inObjectScope(.container) +// parent.register(Animal.self, name: "dog") { _ in Dog() } +// .inObjectScope(.container) +// let child = Container(parent: parent) +// +// // Case resolving on the parent first. +// let cat1 = parent.resolve(Animal.self) as? Cat +// let cat2 = child.resolve(Animal.self) as? Cat +// expect(cat1 === cat2).to(beTrue()) // Workaround for crash in Nimble. +// +// // Case resolving on the child first. +// let dog1 = child.resolve(Animal.self, name: "dog") as? Dog +// let dog2 = parent.resolve(Animal.self, name: "dog") as? Dog +// expect(dog1 === dog2).to(beTrue()) // Workaround for crash in Nimble. +// } +// it("resolves a service in the parent container to the same object in a graph") { +// let parent = Container() +// parent.register(Food.self) { _ in Sushi() } +// .inObjectScope(.container) +// let child = Container(parent: parent) +// registerCatAndPetOwnerDependingOnFood(child) +// +// let owner = child.resolve(Person.self) as? PetOwner +// let ownersSushi = owner?.favoriteFood as? Sushi +// let catsSushi = (owner?.pet as? Cat)?.favoriteFood as? Sushi +// expect(ownersSushi === catsSushi).to(beTrue()) // Workaround for crash in Nimble. +// } } context("in weak scope") { it("shares the object in the container") { From cd9a1404c691dada08f144fb67ff5cf448e4a8f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Thu, 25 Jul 2019 23:26:44 +0200 Subject: [PATCH 127/239] Generate provider & instance injection api --- Sources/3.0 API/Resolver+Injection.swift | 100 +++++++++++++++++---- Swinject.xcodeproj/project.pbxproj | 98 ++++++++++++++++---- Templates/Resolver+Injection.swifttemplate | 50 +++++++++++ Tests/Support/GeneratedMocks.swift | 2 + 4 files changed, 219 insertions(+), 31 deletions(-) create mode 100644 Templates/Resolver+Injection.swifttemplate diff --git a/Sources/3.0 API/Resolver+Injection.swift b/Sources/3.0 API/Resolver+Injection.swift index 261c9572..cde23c1d 100644 --- a/Sources/3.0 API/Resolver+Injection.swift +++ b/Sources/3.0 API/Resolver+Injection.swift @@ -2,45 +2,113 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -// TODO: Overloads for multiple arguments & tag / notag combinations // swiftlint:disable line_length - +// swiftlint:disable function_parameter_count +// sourcery:inline:ResolverInjectionApi public extension Resolver { func instance(of _: Type.Type = Type.self) throws -> Type { - try instance(tagged: NoTag(), arg: ()) - } - - func instance(of _: Type.Type = Type.self, arg: Argument) throws -> Type { - try instance(tagged: NoTag(), arg: arg) + try resolve(request(tag: NoTag(), arg: ())) } func instance(of _: Type.Type = Type.self, tagged tag: Tag) throws -> Type { try resolve(request(tag: tag, arg: ())) } - func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg: Argument) throws -> Type { - try resolve(request(tag: tag, arg: arg)) + func instance(of _: Type.Type = Type.self, arg arg1: Arg1) throws -> Type { + try resolve(request(tag: NoTag(), arg: arg1)) + } + + func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) throws -> Type { + try resolve(request(tag: tag, arg: arg1)) + } + + func instance(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2) throws -> Type { + try resolve(request(tag: NoTag(), arg: (arg1, arg2))) + } + + func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2) throws -> Type { + try resolve(request(tag: tag, arg: (arg1, arg2))) + } + + func instance(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) throws -> Type { + try resolve(request(tag: NoTag(), arg: (arg1, arg2, arg3))) + } + + func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) throws -> Type { + try resolve(request(tag: tag, arg: (arg1, arg2, arg3))) + } + + func instance(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) throws -> Type { + try resolve(request(tag: NoTag(), arg: (arg1, arg2, arg3, arg4))) + } + + func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) throws -> Type { + try resolve(request(tag: tag, arg: (arg1, arg2, arg3, arg4))) + } + + func instance(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) throws -> Type { + try resolve(request(tag: NoTag(), arg: (arg1, arg2, arg3, arg4, arg5))) + } + + func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) throws -> Type { + try resolve(request(tag: tag, arg: (arg1, arg2, arg3, arg4, arg5))) } } public extension Resolver { func provider(of _: Type.Type = Type.self) -> () throws -> Type { - provider(tagged: NoTag(), arg: ()) + return { try self.resolve(request(tag: NoTag(), arg: ())) } } - func provider(of _: Type.Type = Type.self, arg: Argument) -> () throws -> Type { - provider(tagged: NoTag(), arg: arg) + func provider(of _: Type.Type = Type.self, tagged tag: Tag) -> () throws -> Type { + return { try self.resolve(request(tag: tag, arg: ())) } } - func provider(of _: Type.Type = Type.self, tagged tag: Tag) -> () throws -> Type { - provider(tagged: tag, arg: ()) + func provider(of _: Type.Type = Type.self, arg arg1: Arg1) -> () throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: arg1)) } + } + + func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) -> () throws -> Type { + return { try self.resolve(request(tag: tag, arg: arg1)) } + } + + func provider(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2) -> () throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: (arg1, arg2))) } + } + + func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2) -> () throws -> Type { + return { try self.resolve(request(tag: tag, arg: (arg1, arg2))) } + } + + func provider(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> () throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: (arg1, arg2, arg3))) } } - func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg: Argument) -> () throws -> Type { - return { try self.resolve(request(tag: tag, arg: arg)) } + func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> () throws -> Type { + return { try self.resolve(request(tag: tag, arg: (arg1, arg2, arg3))) } + } + + func provider(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> () throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: (arg1, arg2, arg3, arg4))) } + } + + func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> () throws -> Type { + return { try self.resolve(request(tag: tag, arg: (arg1, arg2, arg3, arg4))) } + } + + func provider(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> () throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: (arg1, arg2, arg3, arg4, arg5))) } + } + + func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> () throws -> Type { + return { try self.resolve(request(tag: tag, arg: (arg1, arg2, arg3, arg4, arg5))) } } } +// sourcery:end + + +// TODO: Generate public extension Resolver { func factory(of _: Type.Type = Type.self) -> (Argument) throws -> Type { factory(tagged: NoTag()) diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index fa991b0c..6da93b1a 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -416,7 +416,7 @@ 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopedBindingSpec.swift; sourceTree = ""; }; 0E0B580B43E1891812C97209 /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; 10480F2154EAA0414D4C1F55 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */ = {isa = PBXFileReference; path = .swiftlint.yml; sourceTree = ""; }; + 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .swiftlint.yml; sourceTree = ""; }; 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SynchronizedResolverSpec.swift; sourceTree = ""; }; 13513FA012659ADE699A3608 /* LazySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LazySpec.swift; sourceTree = ""; }; 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleBindingSpec.swift; sourceTree = ""; }; @@ -492,6 +492,11 @@ C765B92B00C0AC8625BB4AC9 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; CADDB3E9E363310028AA5920 /* InstanceMaker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceMaker.swift; sourceTree = ""; }; CC85CB215058F95C0BC190B1 /* Bridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bridge.swift; sourceTree = ""; }; + CD13E07E22EA4E8D0078C4C4 /* AutoMockable.stencil */ = {isa = PBXFileReference; lastKnownFileType = text; path = AutoMockable.stencil; sourceTree = ""; }; + CD13E07F22EA4E8D0078C4C4 /* Resolver+LegacyApi.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+LegacyApi.swifttemplate"; sourceTree = ""; }; + CD13E08022EA4E8D0078C4C4 /* ServiceEntry+TypeForwarding.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "ServiceEntry+TypeForwarding.swifttemplate"; sourceTree = ""; }; + CD13E08122EA4E8D0078C4C4 /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; + CD13E08222EA4EF10078C4C4 /* Resolver+Injection.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+Injection.swifttemplate"; sourceTree = ""; }; CDA78290D6D60BD0B808571F /* Container+Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Logging.swift"; sourceTree = ""; }; E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRequest.swift; sourceTree = ""; }; E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; @@ -700,6 +705,7 @@ C5602A1B64E47775AF8D5700 /* Tests */, 80E97D8FD5574A96B6BC9EB9 /* Frameworks */, 8EB6E58A3F28FAEBBC372598 /* Products */, + CD13E07D22EA4E8D0078C4C4 /* Templates */, ); indentWidth = 4; sourceTree = ""; @@ -731,6 +737,18 @@ path = Carthage/Build; sourceTree = ""; }; + CD13E07D22EA4E8D0078C4C4 /* Templates */ = { + isa = PBXGroup; + children = ( + CD13E07E22EA4E8D0078C4C4 /* AutoMockable.stencil */, + CD13E07F22EA4E8D0078C4C4 /* Resolver+LegacyApi.swifttemplate */, + CD13E08022EA4E8D0078C4C4 /* ServiceEntry+TypeForwarding.swifttemplate */, + CD13E08122EA4E8D0078C4C4 /* Container+Registration.swifttemplate */, + CD13E08222EA4EF10078C4C4 /* Resolver+Injection.swifttemplate */, + ); + path = Templates; + sourceTree = ""; + }; D026A6699A2A932511D29E14 /* Sources */ = { isa = PBXGroup; children = ( @@ -1696,7 +1714,11 @@ ); INFOPLIST_FILE = Tests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SwinjectTests; SDKROOT = watchos; @@ -1720,7 +1742,10 @@ INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = Swinject; SDKROOT = macosx; @@ -1743,7 +1768,10 @@ INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = Swinject; SDKROOT = iphoneos; @@ -1790,7 +1818,10 @@ INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = Swinject; SDKROOT = appletvos; @@ -1812,7 +1843,11 @@ ); INFOPLIST_FILE = Tests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SwinjectTests; SDKROOT = appletvos; @@ -1882,7 +1917,11 @@ ); INFOPLIST_FILE = Tests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SwinjectTests; SDKROOT = iphoneos; @@ -1904,7 +1943,10 @@ INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = Swinject; SDKROOT = appletvos; @@ -1952,7 +1994,10 @@ INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = Swinject; SDKROOT = macosx; @@ -1975,7 +2020,10 @@ INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = Swinject; SDKROOT = iphoneos; @@ -1998,7 +2046,11 @@ ); INFOPLIST_FILE = Tests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SwinjectTests; SDKROOT = macosx; @@ -2017,7 +2069,11 @@ ); INFOPLIST_FILE = Tests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SwinjectTests; SDKROOT = appletvos; @@ -2038,7 +2094,11 @@ ); INFOPLIST_FILE = Tests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SwinjectTests; SDKROOT = macosx; @@ -2057,7 +2117,11 @@ ); INFOPLIST_FILE = Tests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SwinjectTests; SDKROOT = watchos; @@ -2078,7 +2142,11 @@ ); INFOPLIST_FILE = Tests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SwinjectTests; SDKROOT = iphoneos; diff --git a/Templates/Resolver+Injection.swifttemplate b/Templates/Resolver+Injection.swifttemplate new file mode 100644 index 00000000..066bf149 --- /dev/null +++ b/Templates/Resolver+Injection.swifttemplate @@ -0,0 +1,50 @@ +<% let arg_count = 5 %> +// sourcery:inline:ResolverInjectionApi +public extension Resolver { + func instance(of _: Type.Type = Type.self) throws -> Type { + try resolve(request(tag: NoTag(), arg: ())) + } + + func instance(of _: Type.Type = Type.self, tagged tag: Tag) throws -> Type { + try resolve(request(tag: tag, arg: ())) + } +<%_ (1...arg_count).forEach { i in + let arg_types = (1...i).map { "Arg\($0)" }.joined(separator: ", ") + let arg_vars = (1...i).map { "arg\($0)" }.joined(separator: ", ") + let arg_params = (1...i).map { "arg\($0): Arg\($0)" }.joined(separator: ", _ ") +-%> + + func instance>(of _: Type.Type = Type.self, arg <%= arg_params %>) throws -> Type { + try resolve(request(tag: NoTag(), arg: (<%= arg_vars %>))) + } + + func instance>(of _: Type.Type = Type.self, tagged tag: Tag, arg <%= arg_params %>) throws -> Type { + try resolve(request(tag: tag, arg: (<%= arg_vars %>))) + } +<%_ } -%> +} + +public extension Resolver { + func provider(of _: Type.Type = Type.self) -> () throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: ())) } + } + + func provider(of _: Type.Type = Type.self, tagged tag: Tag) -> () throws -> Type { + return { try self.resolve(request(tag: tag, arg: ())) } + } +<%_ (1...arg_count).forEach { i in + let arg_types = (1...i).map { "Arg\($0)" }.joined(separator: ", ") + let arg_vars = (1...i).map { "arg\($0)" }.joined(separator: ", ") + let arg_params = (1...i).map { "arg\($0): Arg\($0)" }.joined(separator: ", _ ") +-%> + + func provider>(of _: Type.Type = Type.self, arg <%= arg_params %>) -> () throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: (<%= arg_vars %>))) } + } + + func provider>(of _: Type.Type = Type.self, tagged tag: Tag, arg <%= arg_params %>) -> () throws -> Type { + return { try self.resolve(request(tag: tag, arg: (<%= arg_vars %>))) } + } +<%_ } -%> +} +// sourcery:end diff --git a/Tests/Support/GeneratedMocks.swift b/Tests/Support/GeneratedMocks.swift index 25bd6e9f..56c0f9b0 100644 --- a/Tests/Support/GeneratedMocks.swift +++ b/Tests/Support/GeneratedMocks.swift @@ -342,3 +342,5 @@ class StaticScopeRegistryMock: StaticScopeRegistry { + + From 4eae5b06bd68ec4c1e30655c4924d151fc5c9438 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Fri, 26 Jul 2019 16:41:21 +0200 Subject: [PATCH 128/239] Describe weakly referenced singleton API --- Sources/3.0 API/BinderEnvironment.swift | 32 ++++++++++++------------ Sources/3.0 API/Resolver+Injection.swift | 1 - Sources/Core/ScopedBinding.swift | 3 ++- Tests/3.0 API/SwinjectApiSpec.swift | 17 ++++++++++++- Tests/Unit Specs/ScopedBindingSpec.swift | 12 +++++++++ 5 files changed, 46 insertions(+), 19 deletions(-) diff --git a/Sources/3.0 API/BinderEnvironment.swift b/Sources/3.0 API/BinderEnvironment.swift index f25ee592..c2a61440 100644 --- a/Sources/3.0 API/BinderEnvironment.swift +++ b/Sources/3.0 API/BinderEnvironment.swift @@ -46,38 +46,38 @@ public extension BinderEnvironment where AScope == Void { } public extension BinderEnvironment where AScope: Scope, Context == AScope.Context { - func singleton(_ builder: @escaping () throws -> Type) -> ScopedBinding.Builder { - .init(scope, strongRef) { _, _, _ in try builder() } + func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping () throws -> Type) -> ScopedBinding.Builder { + .init(scope, ref) { _, _, _ in try builder() } } - func singleton(_ builder: @escaping (Resolver) throws -> Type) -> ScopedBinding.Builder { - .init(scope, strongRef) { r, _, _ in try builder(r) } + func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver) throws -> Type) -> ScopedBinding.Builder { + .init(scope, ref) { r, _, _ in try builder(r) } } - func singleton(_ builder: @escaping (Resolver, Context) throws -> Type) -> ScopedBinding.Builder { - .init(scope, strongRef) { r, c, _ in try builder(r, c) } + func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context) throws -> Type) -> ScopedBinding.Builder { + .init(scope, ref) { r, c, _ in try builder(r, c) } } } public extension BinderEnvironment where AScope: Scope, Context == AScope.Context { - func multiton(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> ScopedBinding.Builder { - .init(scope, strongRef, builder) + func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> ScopedBinding.Builder { + .init(scope, ref, builder) } - func multiton(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> ScopedBinding.Builder { - .init(scope, strongRef) { try builder($0, $1, $2.0, $2.1) } + func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> ScopedBinding.Builder { + .init(scope, ref) { try builder($0, $1, $2.0, $2.1) } } - func multiton(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> ScopedBinding.Builder { - .init(scope, strongRef) { try builder($0, $1, $2.0, $2.1, $2.2) } + func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> ScopedBinding.Builder { + .init(scope, ref) { try builder($0, $1, $2.0, $2.1, $2.2) } } - func multiton(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> ScopedBinding.Builder { - .init(scope, strongRef) { try builder($0, $1, $2.0, $2.1, $2.2, $2.3) } + func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> ScopedBinding.Builder { + .init(scope, ref) { try builder($0, $1, $2.0, $2.1, $2.2, $2.3) } } - func multiton(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> ScopedBinding.Builder { - .init(scope, strongRef) { try builder($0, $1, $2.0, $2.1, $2.2, $2.3, $2.4) } + func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> ScopedBinding.Builder { + .init(scope, ref) { try builder($0, $1, $2.0, $2.1, $2.2, $2.3, $2.4) } } } diff --git a/Sources/3.0 API/Resolver+Injection.swift b/Sources/3.0 API/Resolver+Injection.swift index cde23c1d..a77e1b75 100644 --- a/Sources/3.0 API/Resolver+Injection.swift +++ b/Sources/3.0 API/Resolver+Injection.swift @@ -107,7 +107,6 @@ public extension Resolver { // sourcery:end - // TODO: Generate public extension Resolver { func factory(of _: Type.Type = Type.self) -> (Argument) throws -> Type { diff --git a/Sources/Core/ScopedBinding.swift b/Sources/Core/ScopedBinding.swift index cdc0e70f..a1ebb1df 100644 --- a/Sources/Core/ScopedBinding.swift +++ b/Sources/Core/ScopedBinding.swift @@ -36,7 +36,8 @@ extension ScopedBinding { ) { self.makeRef = { let ref = makeRef($0 as! Type) - return Reference(currentValue: ref.currentValue, nextValue: { ref.nextValue() }) + let nextValue = ref.nextValue + return Reference(currentValue: ref.currentValue, nextValue: { nextValue() }) } self.scope = scope self.builder = builder diff --git a/Tests/3.0 API/SwinjectApiSpec.swift b/Tests/3.0 API/SwinjectApiSpec.swift index 4adc878a..1cda4bc0 100644 --- a/Tests/3.0 API/SwinjectApiSpec.swift +++ b/Tests/3.0 API/SwinjectApiSpec.swift @@ -59,6 +59,13 @@ class SwinjectApiSpec: QuickSpec { override func spec() { expect { try swinject.instance(of: String.self) } == "Plain" expect { try swinject.instance(of: String.self, tagged: "Tag") } == "Tagged" } + // FIXME: Binding Protocol to Implementation does not work +// it("can bind protocol to implementation") { +// let swinject = Swinject { +// bbind(Mammal.self).with(provider { Human() }) +// } +// expect(try? swinject.instance(of: Mammal.self) is Human) == true +// } it("can inject optionals") { let swinject = Swinject { bbind(Int.self) & 42 @@ -169,5 +176,13 @@ class SwinjectApiSpec: QuickSpec { override func spec() { scope.close() expect(closable?.closeCalled) == true } - // FIXME: Binding Protocol to Implementation does not work + it("can bind weakly referenced singleton") { + let scope = UnboundScope() + let swinject = Swinject { + bbind(Human.self) & scoped(scope).singleton(ref: weakRef) { Human() } + } + weak var first = try? swinject.instance() as Human + expect(first).to(beNil()) + } + } } diff --git a/Tests/Unit Specs/ScopedBindingSpec.swift b/Tests/Unit Specs/ScopedBindingSpec.swift index 2b957b3e..c4eb2f2f 100644 --- a/Tests/Unit Specs/ScopedBindingSpec.swift +++ b/Tests/Unit Specs/ScopedBindingSpec.swift @@ -8,10 +8,14 @@ import Quick class ScopedBindingSpec: QuickSpec { override func spec() { describe("binding builder") { + var bag = [Any]() let descriptor = AnyTypeDescriptorMock() let scope = DummyScope() let makeRef: ReferenceMaker = { _ in noRef(42) } let builder = ScopedBinding.Builder, Int>(scope, makeRef) { _, _, _ in 0 } + beforeEach { + bag.removeAll() + } it("makes binding with self as maker") { let binding = builder.makeBinding(for: descriptor) as? ScopedBinding expect(binding?.maker is ScopedBinding.Builder, Int>).to(beTrue()) @@ -30,6 +34,14 @@ class ScopedBindingSpec: QuickSpec { override func spec() { let binding = builder.makeBinding(for: descriptor) as? ScopedBinding expect(binding?.makeRef(0).currentValue as? Int) == 42 } + it("does not hold on to made reference") { + var human = Human() as Human? + weak var weakHuman = human + let builder = ScopedBinding.Builder, Int>(scope, noRef) { _, _, _ in Human() } + bag.append(builder.makeRef(human!).nextValue) + human = nil + expect(weakHuman).to(beNil()) + } } describe("matching") { var key = AnyBindingKeyMock() From e8c44363408271991ce06c1e3afab392ba766cc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Fri, 26 Jul 2019 18:18:15 +0200 Subject: [PATCH 129/239] Fix type inference when binding protocol to implementation --- Sources/3.0 API/TypeBinder.swift | 9 ++++++--- Tests/3.0 API/SwinjectApiSpec.swift | 13 ++++++------- Tests/Support/Bridge.swift | 4 ++-- Tests/Unit Specs/TypeBinderSpec.swift | 14 +++++++------- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/Sources/3.0 API/TypeBinder.swift b/Sources/3.0 API/TypeBinder.swift index 01f4b69c..afa41219 100644 --- a/Sources/3.0 API/TypeBinder.swift +++ b/Sources/3.0 API/TypeBinder.swift @@ -7,14 +7,17 @@ public struct TypeBinder where Descriptor: TypeDescriptor { } public func bind(_: Type.Type) -> TypeBinder> { - bind(plain(Type.self)) + TypeBinder(descriptor: plain(Type.self)) } public func bind(_: Type.Type, tagged tag: Tag) -> TypeBinder> where Tag: Equatable { - bind(tagged(Type.self, with: tag)) + TypeBinder(descriptor: tagged(Type.self, with: tag)) } -public func bind(_ descriptor: Descriptor) -> TypeBinder where Descriptor: TypeDescriptor { +// TODO: Compiler Bug? +// omitting `decriptor` param name here causes compiler to incorrectly infer types when using bind(), e.g.: +// bind(CustomStringConvertible.self).with(provider { 42 }) +public func bind(descriptor: Descriptor) -> TypeBinder where Descriptor: TypeDescriptor { TypeBinder(descriptor: descriptor) } diff --git a/Tests/3.0 API/SwinjectApiSpec.swift b/Tests/3.0 API/SwinjectApiSpec.swift index 1cda4bc0..a1864c0f 100644 --- a/Tests/3.0 API/SwinjectApiSpec.swift +++ b/Tests/3.0 API/SwinjectApiSpec.swift @@ -59,13 +59,12 @@ class SwinjectApiSpec: QuickSpec { override func spec() { expect { try swinject.instance(of: String.self) } == "Plain" expect { try swinject.instance(of: String.self, tagged: "Tag") } == "Tagged" } - // FIXME: Binding Protocol to Implementation does not work -// it("can bind protocol to implementation") { -// let swinject = Swinject { -// bbind(Mammal.self).with(provider { Human() }) -// } -// expect(try? swinject.instance(of: Mammal.self) is Human) == true -// } + it("can bind protocol to implementation") { + let swinject = Swinject { + bbind(Mammal.self).with(provider { Human() }) + } + expect(try? swinject.instance(of: Mammal.self) is Human) == true + } it("can inject optionals") { let swinject = Swinject { bbind(Int.self) & 42 diff --git a/Tests/Support/Bridge.swift b/Tests/Support/Bridge.swift index 0a199f65..f52fe0a0 100644 --- a/Tests/Support/Bridge.swift +++ b/Tests/Support/Bridge.swift @@ -17,6 +17,6 @@ func bbind(_: Type.Type, tagged tag: Tag) -> TypeBinder(_ descriptor: Descriptor) -> TypeBinder where Descriptor: TypeDescriptor { - bind(descriptor) +func bbind(descriptor: Descriptor) -> TypeBinder where Descriptor: TypeDescriptor { + bind(descriptor: descriptor) } diff --git a/Tests/Unit Specs/TypeBinderSpec.swift b/Tests/Unit Specs/TypeBinderSpec.swift index dc5dc819..a93577cf 100644 --- a/Tests/Unit Specs/TypeBinderSpec.swift +++ b/Tests/Unit Specs/TypeBinderSpec.swift @@ -20,37 +20,37 @@ class TypeBinderSpec: QuickSpec { override func spec() { expect(descriptor.tag) == "Foo" } it("descriptor is used if given as parameter") { - let request = bbind(descriptor) + let request = bbind(descriptor: descriptor) expect(request.descriptor) === descriptor } } describe("`with` method") { it("passes descriptor to maker") { - _ = bbind(descriptor).with(maker) + _ = bbind(descriptor: descriptor).with(maker) expect(maker.makeBindingForReceivedDescriptor) === descriptor } it("returns binding from maker") { let binding = BindingMock() maker.makeBindingForReturnValue = binding - expect(bbind(descriptor).with(maker)) === binding + expect(bbind(descriptor: descriptor).with(maker)) === binding } it("works with passing instance directly") { - let binding = bbind(descriptor).with(42) + let binding = bbind(descriptor: descriptor).with(42) expect { try binding.instance(arg: (), context: (), resolver: DummyResolver()) as? Int } == 42 } } describe("`&` method") { it("passes descriptor to maker") { - _ = bbind(descriptor) & maker + _ = bbind(descriptor: descriptor) & maker expect(maker.makeBindingForReceivedDescriptor) === descriptor } it("returns binding from maker") { let binding = BindingMock() maker.makeBindingForReturnValue = binding - expect(bbind(descriptor) & maker) === binding + expect(bbind(descriptor: descriptor) & maker) === binding } it("works with passing instance directly") { - let binding = bbind(descriptor) & 42 + let binding = bbind(descriptor: descriptor) & 42 expect { try binding.instance(arg: (), context: (), resolver: DummyResolver()) as? Int } == 42 } } From 201b02fb2e2996c20eddce67a1c0e58cc1a9b72f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Fri, 26 Jul 2019 18:36:35 +0200 Subject: [PATCH 130/239] Bump xcode version in travis.yml --- .travis.yml | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index f80d0846..c5dadfcd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,11 +3,9 @@ env: global: - LC_CTYPE=en_US.UTF-8 - PROJECT=Swinject.xcodeproj -git: - submodules: false matrix: include: - - env: JOB="LINUX_SPM" SWIFT_VERSION="5.0" + - env: JOB="LINUX_SPM" SWIFT_VERSION="5.1" os: linux language: generic sudo: required @@ -19,18 +17,18 @@ matrix: - swift build - swift test - env: JOB="POD_LINT" - osx_image: xcode10.2 + osx_image: xcode11 before_install: script: - pod lib lint - env: JOB="XCODE" DEST="OS=10.0,name=iPhone 6" SCHEME="Swinject-iOS" SDK="iphonesimulator" ACTION="test" PLATFORM="iOS" - osx_image: xcode10.2 + osx_image: xcode11 - env: JOB="XCODE" DEST="arch=x86_64" SCHEME="Swinject-macOS" SDK="macosx" ACTION="test" PLATFORM="OSX" - osx_image: xcode10.2 + osx_image: xcode11 - env: JOB="XCODE" DEST="OS=10.0,name=Apple TV 1080p" SCHEME="Swinject-tvOS" SDK="appletvsimulator" ACTION="test" PLATFORM="tvOS" - osx_image: xcode10.2 + osx_image: xcode11 - env: JOB="XCODE" DEST="OS=2.2,name=Apple Watch - 42mm" SCHEME="Swinject-watchOS" SDK="watchsimulator" ACTION="build" PLATFORM="watchOS" - osx_image: xcode10.2 + osx_image: xcode11 before_install: - curl -L -O https://github.com/Carthage/Carthage/releases/download/0.33.0/Carthage.pkg From f22165ae6b75d7c4e0998fb0cdd64da0bc1d7f9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Fri, 26 Jul 2019 18:55:19 +0200 Subject: [PATCH 131/239] Use hash(into) instead of legacy hashValue in Matchable protocol --- Sources/Core/Matchable.swift | 2 +- Sources/Core/ScopeRegistryKey.swift | 4 +- Sources/Core/TypeDescriptor.swift | 5 ++- Templates/AutoMockable.stencil | 2 +- Tests/Support/Convenience.swift | 8 ++++ Tests/Support/GeneratedMocks.swift | 44 ++++++++++++++++----- Tests/Unit Specs/ScopeRegistryKeySpec.swift | 20 ++++------ 7 files changed, 57 insertions(+), 28 deletions(-) diff --git a/Sources/Core/Matchable.swift b/Sources/Core/Matchable.swift index 708435d2..287c2545 100644 --- a/Sources/Core/Matchable.swift +++ b/Sources/Core/Matchable.swift @@ -5,7 +5,7 @@ // sourcery: AutoMockable public protocol Matchable { func matches(_ other: Any) -> Bool - var hashValue: Int { get } + func hash(into hasher: inout Hasher) } // TODO: Box / Unbox internally all the arguments diff --git a/Sources/Core/ScopeRegistryKey.swift b/Sources/Core/ScopeRegistryKey.swift index d4e097f9..c85c9624 100644 --- a/Sources/Core/ScopeRegistryKey.swift +++ b/Sources/Core/ScopeRegistryKey.swift @@ -28,7 +28,7 @@ extension ScopeRegistryKey: Hashable { } public func hash(into hasher: inout Hasher) { - descriptor.hashValue.hash(into: &hasher) - (argument as? Matchable)?.hashValue.hash(into: &hasher) + descriptor.hash(into: &hasher) + (argument as? Matchable)?.hash(into: &hasher) } } diff --git a/Sources/Core/TypeDescriptor.swift b/Sources/Core/TypeDescriptor.swift index ff73d8d1..3c5f1345 100644 --- a/Sources/Core/TypeDescriptor.swift +++ b/Sources/Core/TypeDescriptor.swift @@ -27,8 +27,9 @@ public struct Tagged: TypeDescriptor where Tag: Hashable { return false } - public var hashValue: Int { - String(describing: hashedType).hashValue ^ tag.hashValue + public func hash(into hasher: inout Hasher) { + hasher.combine(String(describing: hashedType)) + hasher.combine(tag) } private var hashedType: Any.Type { diff --git a/Templates/AutoMockable.stencil b/Templates/AutoMockable.stencil index 37510cd6..a30733eb 100644 --- a/Templates/AutoMockable.stencil +++ b/Templates/AutoMockable.stencil @@ -35,7 +35,7 @@ var {% call methodClosureName method %}: (({% for param in method.parameters %}{{ param.typeName }}{% if not forloop.last %}, {% endif %}{% endfor %}) {% if method.throws %}throws {% endif %}-> {% if method.isInitializer %}Void{% else %}{% call closureReturnTypeName method %}{% endif %})? {% endmacro %} -{% macro methodClosureCallParameters method %}{% for param in method.parameters %}{{ param.name }}{% if not forloop.last %}, {% endif %}{% endfor %}{% endmacro %} +{% macro methodClosureCallParameters method %}{% for param in method.parameters %}{% if param.inout %}&{% endif %}{{ param.name }}{% if not forloop.last %}, {% endif %}{% endfor %}{% endmacro %} {% macro mockMethod method %} //MARK: - {{ method.shortName }} diff --git a/Tests/Support/Convenience.swift b/Tests/Support/Convenience.swift index 783b0887..11de8323 100644 --- a/Tests/Support/Convenience.swift +++ b/Tests/Support/Convenience.swift @@ -33,3 +33,11 @@ func concurrentPerform(iterations: Int, action: () -> Void) { if finished == iterations { done() } } } + +extension Matchable { + var hashValue: Int { // swiftlint:disable:this legacy_hashing + var hasher = Hasher() + hash(into: &hasher) + return hasher.finalize() + } +} diff --git a/Tests/Support/GeneratedMocks.swift b/Tests/Support/GeneratedMocks.swift index 56c0f9b0..576b18e3 100644 --- a/Tests/Support/GeneratedMocks.swift +++ b/Tests/Support/GeneratedMocks.swift @@ -189,11 +189,6 @@ class AnyScopeMock: AnyScope { } class AnyTypeDescriptorMock: AnyTypeDescriptor { - var hashValue: Int { - get { return underlyingHashValue } - set(value) { underlyingHashValue = value } - } - var underlyingHashValue: Int! //MARK: - matches @@ -213,6 +208,23 @@ class AnyTypeDescriptorMock: AnyTypeDescriptor { return matchesClosure.map({ $0(other) }) ?? matchesReturnValue } + //MARK: - hash + + var hashIntoCallsCount = 0 + var hashIntoCalled: Bool { + return hashIntoCallsCount > 0 + } + var hashIntoReceivedHasher: Hasher? + var hashIntoReceivedInvocations: [Hasher] = [] + var hashIntoClosure: ((inout Hasher) -> Void)? + + func hash(into hasher: inout Hasher) { + hashIntoCallsCount += 1 + hashIntoReceivedHasher = hasher + hashIntoReceivedInvocations.append(hasher) + hashIntoClosure?(&hasher) + } + } class BindingMock: Binding { @@ -274,11 +286,6 @@ class ClosableMock: Closable { } class MatchableMock: Matchable { - var hashValue: Int { - get { return underlyingHashValue } - set(value) { underlyingHashValue = value } - } - var underlyingHashValue: Int! //MARK: - matches @@ -298,6 +305,23 @@ class MatchableMock: Matchable { return matchesClosure.map({ $0(other) }) ?? matchesReturnValue } + //MARK: - hash + + var hashIntoCallsCount = 0 + var hashIntoCalled: Bool { + return hashIntoCallsCount > 0 + } + var hashIntoReceivedHasher: Hasher? + var hashIntoReceivedInvocations: [Hasher] = [] + var hashIntoClosure: ((inout Hasher) -> Void)? + + func hash(into hasher: inout Hasher) { + hashIntoCallsCount += 1 + hashIntoReceivedHasher = hasher + hashIntoReceivedInvocations.append(hasher) + hashIntoClosure?(&hasher) + } + } class ModuleIncludeEntryMock: ModuleIncludeEntry { diff --git a/Tests/Unit Specs/ScopeRegistryKeySpec.swift b/Tests/Unit Specs/ScopeRegistryKeySpec.swift index 4ffbbebb..e6598f94 100644 --- a/Tests/Unit Specs/ScopeRegistryKeySpec.swift +++ b/Tests/Unit Specs/ScopeRegistryKeySpec.swift @@ -16,16 +16,12 @@ class ScopeRegistryKeySpec: QuickSpec { override func spec() { beforeEach { descriptor1 = AnyTypeDescriptorMock() descriptor1.matchesReturnValue = true - descriptor1.hashValue = 0 argument1 = MatchableMock() argument1.matchesReturnValue = true - argument1.hashValue = 0 descriptor2 = AnyTypeDescriptorMock() descriptor2.matchesReturnValue = true - descriptor2.hashValue = 0 argument2 = MatchableMock() argument2.matchesReturnValue = true - argument2.hashValue = 0 key1 = ScopeRegistryKey(descriptor: descriptor1, argument: argument1) key2 = ScopeRegistryKey(descriptor: descriptor2, argument: argument2) } @@ -79,25 +75,25 @@ class ScopeRegistryKeySpec: QuickSpec { override func spec() { describe("hash") { describe("hashes descriptor") { it("does not equal if descriptor hashes are different") { - descriptor1.hashValue = 1 - descriptor2.hashValue = 2 + descriptor1.hashIntoClosure = { $0.combine(1) } + descriptor2.hashIntoClosure = { $0.combine(2) } expect(key1.hashValue) != key2.hashValue } it("equals if descriptor hashes are the same") { - descriptor1.hashValue = 1 - descriptor2.hashValue = 1 + descriptor1.hashIntoClosure = { $0.combine(1) } + descriptor2.hashIntoClosure = { $0.combine(1) } expect(key1.hashValue) == key2.hashValue } } describe("hashes matchable argument") { it("does not equal if argument hashes are different") { - argument1.hashValue = 1 - argument2.hashValue = 2 + argument1.hashIntoClosure = { $0.combine(1) } + argument2.hashIntoClosure = { $0.combine(2) } expect(key1.hashValue) != key2.hashValue } it("equals if argument hashes are the same") { - argument1.hashValue = 1 - argument2.hashValue = 1 + argument1.hashIntoClosure = { $0.combine(1) } + argument2.hashIntoClosure = { $0.combine(1) } expect(key1.hashValue) == key2.hashValue } } From 605ffa7c02771f19dd72fa4227cad4da07240001 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Fri, 26 Jul 2019 18:58:27 +0200 Subject: [PATCH 132/239] Fix warnings in generated mocks --- Templates/AutoMockable.stencil | 2 +- Tests/Support/GeneratedMocks.swift | 22 +++++++++++----------- Tests/Unit Specs/ScopedBindingSpec.swift | 2 ++ Tests/Unit Specs/SwinjectSpec.swift | 6 +++++- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/Templates/AutoMockable.stencil b/Templates/AutoMockable.stencil index a30733eb..8321249a 100644 --- a/Templates/AutoMockable.stencil +++ b/Templates/AutoMockable.stencil @@ -76,7 +76,7 @@ {% if method.returnTypeName.isVoid %} {% if method.throws %}try {% endif %}{% call methodClosureName method %}?({% call methodClosureCallParameters method %}) {% else %} - return {{ 'try ' if method.throws }}{% call methodClosureName method %}.map({ {{ 'try ' if method.throws }}$0({% call methodClosureCallParameters method %}) }) ?? {% call swiftifyMethodName method.selectorName %}ReturnValue + return {{ 'try ' if method.throws }}{% call methodClosureName method %}.map({ {{ 'try ' if method.throws }}$0({% call methodClosureCallParameters method %}) }) ?? {% call swiftifyMethodName method.selectorName %}ReturnValue! {% endif %} } diff --git a/Tests/Support/GeneratedMocks.swift b/Tests/Support/GeneratedMocks.swift index 576b18e3..eb709a2e 100644 --- a/Tests/Support/GeneratedMocks.swift +++ b/Tests/Support/GeneratedMocks.swift @@ -52,7 +52,7 @@ class AnyBindingKeyMock: AnyBindingKey { matchesCallsCount += 1 matchesReceivedOther = other matchesReceivedInvocations.append(other) - return matchesClosure.map({ $0(other) }) ?? matchesReturnValue + return matchesClosure.map({ $0(other) }) ?? matchesReturnValue! } } @@ -73,7 +73,7 @@ class AnyBindningMakerMock: AnyBindningMaker { makeBindingForCallsCount += 1 makeBindingForReceivedDescriptor = descriptor makeBindingForReceivedInvocations.append(descriptor) - return makeBindingForClosure.map({ $0(descriptor) }) ?? makeBindingForReturnValue + return makeBindingForClosure.map({ $0(descriptor) }) ?? makeBindingForReturnValue! } } @@ -108,7 +108,7 @@ class AnyContextTranslatorMock: AnyContextTranslator { translateCallsCount += 1 translateReceivedContext = context translateReceivedInvocations.append(context) - return try translateClosure.map({ try $0(context) }) ?? translateReturnValue + return try translateClosure.map({ try $0(context) }) ?? translateReturnValue! } } @@ -133,7 +133,7 @@ class AnyInstanceMakerMock: AnyInstanceMaker { makeInstanceArgContextResolverCallsCount += 1 makeInstanceArgContextResolverReceivedArguments = (arg: arg, context: context, resolver: resolver) makeInstanceArgContextResolverReceivedInvocations.append((arg: arg, context: context, resolver: resolver)) - return try makeInstanceArgContextResolverClosure.map({ try $0(arg, context, resolver) }) ?? makeInstanceArgContextResolverReturnValue + return try makeInstanceArgContextResolverClosure.map({ try $0(arg, context, resolver) }) ?? makeInstanceArgContextResolverReturnValue! } } @@ -158,7 +158,7 @@ class AnyResolverMock: AnyResolver { resolveCallsCount += 1 resolveReceivedRequest = request resolveReceivedInvocations.append(request) - return try resolveClosure.map({ try $0(request) }) ?? resolveReturnValue + return try resolveClosure.map({ try $0(request) }) ?? resolveReturnValue! } } @@ -184,7 +184,7 @@ class AnyScopeMock: AnyScope { registryForCallsCount += 1 registryForReceivedContext = context registryForReceivedInvocations.append(context) - return registryForClosure.map({ $0(context) }) ?? registryForReturnValue + return registryForClosure.map({ $0(context) }) ?? registryForReturnValue! } } @@ -205,7 +205,7 @@ class AnyTypeDescriptorMock: AnyTypeDescriptor { matchesCallsCount += 1 matchesReceivedOther = other matchesReceivedInvocations.append(other) - return matchesClosure.map({ $0(other) }) ?? matchesReturnValue + return matchesClosure.map({ $0(other) }) ?? matchesReturnValue! } //MARK: - hash @@ -243,7 +243,7 @@ class BindingMock: Binding { matchesCallsCount += 1 matchesReceivedKey = key matchesReceivedInvocations.append(key) - return matchesClosure.map({ $0(key) }) ?? matchesReturnValue + return matchesClosure.map({ $0(key) }) ?? matchesReturnValue! } //MARK: - instance @@ -265,7 +265,7 @@ class BindingMock: Binding { instanceArgContextResolverCallsCount += 1 instanceArgContextResolverReceivedArguments = (arg: arg, context: context, resolver: resolver) instanceArgContextResolverReceivedInvocations.append((arg: arg, context: context, resolver: resolver)) - return try instanceArgContextResolverClosure.map({ try $0(arg, context, resolver) }) ?? instanceArgContextResolverReturnValue + return try instanceArgContextResolverClosure.map({ try $0(arg, context, resolver) }) ?? instanceArgContextResolverReturnValue! } } @@ -302,7 +302,7 @@ class MatchableMock: Matchable { matchesCallsCount += 1 matchesReceivedOther = other matchesReceivedInvocations.append(other) - return matchesClosure.map({ $0(other) }) ?? matchesReturnValue + return matchesClosure.map({ $0(other) }) ?? matchesReturnValue! } //MARK: - hash @@ -343,7 +343,7 @@ class StaticScopeRegistryMock: StaticScopeRegistry { instanceKeyCallsCount += 1 instanceKeyReceivedKey = key instanceKeyReceivedInvocations.append(key) - return instanceKeyClosure.map({ $0(key) }) ?? instanceKeyReturnValue + return instanceKeyClosure.map({ $0(key) }) ?? instanceKeyReturnValue! } //MARK: - clear diff --git a/Tests/Unit Specs/ScopedBindingSpec.swift b/Tests/Unit Specs/ScopedBindingSpec.swift index c4eb2f2f..feb8cd54 100644 --- a/Tests/Unit Specs/ScopedBindingSpec.swift +++ b/Tests/Unit Specs/ScopedBindingSpec.swift @@ -76,9 +76,11 @@ class ScopedBindingSpec: QuickSpec { override func spec() { var binding: ScopedBinding! beforeEach { registry = StaticScopeRegistryMock() + registry.instanceKeyReturnValue = 0 scope = AnyScopeMock() scope.registryForReturnValue = registry maker = AnyInstanceMakerMock() + maker.makeInstanceArgContextResolverReturnValue = 0 key = AnyBindingKeyMock() key.descriptor = AnyTypeDescriptorMock() binding = ScopedBinding(key: key, maker: maker, scope: scope, makeRef: noRef) diff --git a/Tests/Unit Specs/SwinjectSpec.swift b/Tests/Unit Specs/SwinjectSpec.swift index 8ad27d22..bd6864d1 100644 --- a/Tests/Unit Specs/SwinjectSpec.swift +++ b/Tests/Unit Specs/SwinjectSpec.swift @@ -11,6 +11,7 @@ class SwinjectSpec: QuickSpec { override func spec() { var binding = BindingMock() beforeEach { binding = BindingMock() + binding.instanceArgContextResolverReturnValue = 0 swinject = Swinject { binding } } describe("instance injection") { @@ -85,7 +86,10 @@ class SwinjectSpec: QuickSpec { override func spec() { var bindings = [BindingMock]() beforeEach { bindings = Array(0 ..< 3).map { _ in BindingMock() } - bindings.forEach { $0.matchesReturnValue = false } + bindings.forEach { + $0.matchesReturnValue = false + $0.instanceArgContextResolverReturnValue = 0 + } swinject = Swinject { bindings[0] bindings[1] From b421d337086348cbc676a48bbab22885cdf261a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Fri, 26 Jul 2019 19:03:55 +0200 Subject: [PATCH 133/239] Enable code coverage gathering --- .../xcshareddata/xcschemes/Swinject-iOS.xcscheme | 1 + .../xcshareddata/xcschemes/Swinject-macOS.xcscheme | 1 + .../xcshareddata/xcschemes/Swinject-tvOS.xcscheme | 1 + .../xcshareddata/xcschemes/Swinject-watchOS.xcscheme | 1 + Tests/Unit Specs/SwinjectTreeBuilderSpec.swift | 12 ++++++------ project.yml | 1 + 6 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Swinject.xcodeproj/xcshareddata/xcschemes/Swinject-iOS.xcscheme b/Swinject.xcodeproj/xcshareddata/xcschemes/Swinject-iOS.xcscheme index 7020ad39..80c9709d 100644 --- a/Swinject.xcodeproj/xcshareddata/xcschemes/Swinject-iOS.xcscheme +++ b/Swinject.xcodeproj/xcshareddata/xcschemes/Swinject-iOS.xcscheme @@ -26,6 +26,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + codeCoverageEnabled = "YES" shouldUseLaunchSchemeArgsEnv = "YES"> Date: Fri, 26 Jul 2019 19:13:40 +0200 Subject: [PATCH 134/239] Reset root scope before each api test --- Tests/3.0 API/SwinjectApiSpec.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Tests/3.0 API/SwinjectApiSpec.swift b/Tests/3.0 API/SwinjectApiSpec.swift index a1864c0f..fd403c82 100644 --- a/Tests/3.0 API/SwinjectApiSpec.swift +++ b/Tests/3.0 API/SwinjectApiSpec.swift @@ -5,10 +5,12 @@ import Nimble import Quick import Swinject +@testable import class Swinject.UnboundScope class SwinjectApiSpec: QuickSpec { override func spec() { var human = Human() beforeEach { + UnboundScope.root.close() human = Human() } it("returns instance if is bound") { @@ -176,9 +178,8 @@ class SwinjectApiSpec: QuickSpec { override func spec() { expect(closable?.closeCalled) == true } it("can bind weakly referenced singleton") { - let scope = UnboundScope() let swinject = Swinject { - bbind(Human.self) & scoped(scope).singleton(ref: weakRef) { Human() } + bbind(Human.self) & singleton(ref: weakRef) { Human() } } weak var first = try? swinject.instance() as Human expect(first).to(beNil()) From 17030ba2ef66621015f0f7284993a10140ba6f47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Fri, 26 Jul 2019 19:58:32 +0200 Subject: [PATCH 135/239] Tie lifetime of the service-entry instances to the container --- Sources/2.0 API/Assembler.swift | 28 +---- Sources/2.0 API/Container+Registration.swift | 20 ++-- Sources/2.0 API/Container.swift | 52 +++----- Sources/2.0 API/ObjectScope.swift | 12 +- Sources/2.0 API/ServiceEntry.swift | 2 +- Swinject.xcodeproj/project.pbxproj | 98 ++++++++++++--- .../Container+Registration.swifttemplate | 4 +- Tests/2.0 API/AssemblerSpec.swift | 11 -- Tests/2.0 API/ContainerSpec.swift | 112 ++++++++++-------- 9 files changed, 188 insertions(+), 151 deletions(-) diff --git a/Sources/2.0 API/Assembler.swift b/Sources/2.0 API/Assembler.swift index 496bc6de..9352f6f8 100644 --- a/Sources/2.0 API/Assembler.swift +++ b/Sources/2.0 API/Assembler.swift @@ -36,38 +36,16 @@ public final class Assembler { /// - parameter parent: the baseline assembler /// - parameter defaultObjectScope: default object scope for container /// - parameter behaviors: list of behaviors to be added to the container - public convenience init( - _ assemblies: [Assembly] = [], - parent: Assembler? = nil, - defaultObjectScope: ObjectScope = .graph, - behaviors: [Behavior] = [] - ) { - self.init( - assemblies, - parent: parent, - defaultScope: defaultObjectScope.scope, - defaultMakeRef: defaultObjectScope.makeRef, - behaviors: behaviors - ) - } - - /// Will create a new `Assembler` with the given `Assembly` instances to build a `Container` - /// - /// - parameter assemblies: the list of assemblies to build the container from - /// - parameter parent: the baseline assembler - /// - parameter defaultScope: default object scope for container - /// - parameter behaviors: list of behaviors to be added to the container public init( _ assemblies: [Assembly] = [], parent: Assembler? = nil, - defaultScope: AnyScope?, - defaultMakeRef: @escaping ReferenceMaker, + // TODO: Enable arbitrary default scope + defaultObjectScope: ObjectScope = .graph, behaviors: [Behavior] = [] ) { container = Container( parent: parent?.container, - defaultScope: defaultScope, - defaultMakeRef: defaultMakeRef, + defaultObjectScope: defaultObjectScope, behaviors: behaviors ) run(assemblies: assemblies) diff --git a/Sources/2.0 API/Container+Registration.swift b/Sources/2.0 API/Container+Registration.swift index 7721be7d..37194232 100644 --- a/Sources/2.0 API/Container+Registration.swift +++ b/Sources/2.0 API/Container+Registration.swift @@ -19,7 +19,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, _: Void) in factory(r) } + let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef(in: self)) { (r, _, _: Void) in factory(r) } addEntry(entry, with: name) return entry } @@ -38,7 +38,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, a: Arg1) in factory(r, a) } + let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef(in: self)) { (r, _, a: Arg1) in factory(r, a) } addEntry(entry, with: name) return entry } @@ -57,7 +57,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, a: (Arg1, Arg2)) in factory(r, a.0, a.1) } + let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef(in: self)) { (r, _, a: (Arg1, Arg2)) in factory(r, a.0, a.1) } addEntry(entry, with: name) return entry } @@ -76,7 +76,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, a: (Arg1, Arg2, Arg3)) in factory(r, a.0, a.1, a.2) } + let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef(in: self)) { (r, _, a: (Arg1, Arg2, Arg3)) in factory(r, a.0, a.1, a.2) } addEntry(entry, with: name) return entry } @@ -95,7 +95,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, a: (Arg1, Arg2, Arg3, Arg4)) in factory(r, a.0, a.1, a.2, a.3) } + let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef(in: self)) { (r, _, a: (Arg1, Arg2, Arg3, Arg4)) in factory(r, a.0, a.1, a.2, a.3) } addEntry(entry, with: name) return entry } @@ -114,7 +114,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5)) in factory(r, a.0, a.1, a.2, a.3, a.4) } + let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef(in: self)) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5)) in factory(r, a.0, a.1, a.2, a.3, a.4) } addEntry(entry, with: name) return entry } @@ -133,7 +133,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5) } + let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef(in: self)) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5) } addEntry(entry, with: name) return entry } @@ -152,7 +152,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6) } + let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef(in: self)) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6) } addEntry(entry, with: name) return entry } @@ -171,7 +171,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6, a.7) } + let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef(in: self)) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6, a.7) } addEntry(entry, with: name) return entry } @@ -190,7 +190,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6, a.7, a.8) } + let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef(in: self)) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6, a.7, a.8) } addEntry(entry, with: name) return entry } diff --git a/Sources/2.0 API/Container.swift b/Sources/2.0 API/Container.swift index 0a4daa0d..bca7f075 100644 --- a/Sources/2.0 API/Container.swift +++ b/Sources/2.0 API/Container.swift @@ -20,10 +20,13 @@ import Foundation /// where `A` and `X` are protocols, `B` is a type conforming `A`, and `Y` is a type conforming `X` /// and depending on `A`. public final class Container { - let registry = StandardScopeRegistry() + private class Handle {} + var referenceHandle: AnyObject = Handle() + + let registry: StandardScopeRegistry let parent: Container? - let defaultScope: AnyScope? - let defaultMakeRef: ReferenceMaker + // TODO: Enable arbitrary scope as default + let defaultObjectScope: ObjectScope var bindings = [Binding]() var behaviors = [Behavior]() var swinject: Swinject { Swinject(tree: SwinjectTree( @@ -39,7 +42,7 @@ public final class Container { /// /// - Parameters /// - parent: The optional parent `Container`. - /// - defaultScope: Default scope + /// - defaultObjectScope: Default object scope (graph if no scope is injected) /// - behaviors: List of behaviors to be added to the container /// - registeringClosure: The closure registering services to the new container instance. /// @@ -47,47 +50,21 @@ public final class Container { /// Use `init()` or `init(parent:)` instead. public init( parent: Container? = nil, - defaultScope: AnyScope?, - defaultMakeRef: @escaping ReferenceMaker, + defaultObjectScope: ObjectScope = .graph, behaviors: [Behavior] = [], registeringClosure: (Container) -> Void = { _ in } ) { self.parent = parent - self.defaultScope = defaultScope - self.defaultMakeRef = defaultMakeRef + self.defaultObjectScope = defaultObjectScope self.behaviors = behaviors + registry = parent?.registry ?? StandardScopeRegistry() registeringClosure(self) } - /// Instantiates a `Container` - /// - /// - Parameters - /// - parent: The optional parent `Container`. - /// - defaultObjectScope: Default object scope (graph if no scope is injected) - /// - behaviors: List of behaviors to be added to the container - /// - registeringClosure: The closure registering services to the new container instance. - /// - /// - Remark: Compile time may be long if you pass a long closure to this initializer. - /// Use `init()` or `init(parent:)` instead. - public convenience init( - parent: Container? = nil, - defaultObjectScope: ObjectScope = .graph, - behaviors: [Behavior] = [], - registeringClosure: (Container) -> Void = { _ in } - ) { - self.init( - parent: parent, - defaultScope: defaultObjectScope.scope, - defaultMakeRef: defaultObjectScope.makeRef, - behaviors: behaviors, - registeringClosure: registeringClosure - ) - } - /// Removes all registrations in the container. public func removeAll() { bindings = [] - registry.clear() + referenceHandle = Handle() } /// Discards instances for services registered in the given `ObjectsScopeProtocol`. @@ -97,7 +74,12 @@ public final class Container { /// /// - Parameters: /// - objectScope: All instances registered in given `ObjectsScopeProtocol` will be discarded. - public func resetObjectScope(_: ObjectScope) {} + public func resetObjectScope(_ scope: ObjectScope) { + switch scope { + case .container, .weak: referenceHandle = Handle() + case .graph, .transient: break + } + } /// Returns a synchronized view of the container for thread safety. /// The returned container is `Resolver` type. Call this method after you finish all service registrations diff --git a/Sources/2.0 API/ObjectScope.swift b/Sources/2.0 API/ObjectScope.swift index 340f89d9..890dffc3 100644 --- a/Sources/2.0 API/ObjectScope.swift +++ b/Sources/2.0 API/ObjectScope.swift @@ -32,10 +32,16 @@ extension ObjectScope { } } - var makeRef: ReferenceMaker { + func makeRef(in container: Container?) -> ReferenceMaker { + weak var container = container + func containerRef(_ value: Any) -> Reference { + Reference(currentValue: value) { [weak handle = container?.referenceHandle] in + handle == nil ? nil : value + } + } switch self { - case .graph: return strongRef - case .container: return strongRef + case .graph: return containerRef + case .container: return containerRef case .weak: return weakRef case .transient: return noRef } diff --git a/Sources/2.0 API/ServiceEntry.swift b/Sources/2.0 API/ServiceEntry.swift index add98141..95a47db8 100644 --- a/Sources/2.0 API/ServiceEntry.swift +++ b/Sources/2.0 API/ServiceEntry.swift @@ -50,7 +50,7 @@ public class ServiceEntry { @discardableResult public func inObjectScope(_ objectScope: ObjectScope) -> Self { scope = objectScope.scope - makeRef = objectScope.makeRef + makeRef = container.map(objectScope.makeRef) ?? noRef return self } diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 101d14bb..6d654cf7 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -419,7 +419,7 @@ 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopedBindingSpec.swift; sourceTree = ""; }; 0E0B580B43E1891812C97209 /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; 10480F2154EAA0414D4C1F55 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */ = {isa = PBXFileReference; path = .swiftlint.yml; sourceTree = ""; }; + 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .swiftlint.yml; sourceTree = ""; }; 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SynchronizedResolverSpec.swift; sourceTree = ""; }; 13513FA012659ADE699A3608 /* LazySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LazySpec.swift; sourceTree = ""; }; 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleBindingSpec.swift; sourceTree = ""; }; @@ -494,6 +494,11 @@ C765B92B00C0AC8625BB4AC9 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; CADDB3E9E363310028AA5920 /* InstanceMaker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceMaker.swift; sourceTree = ""; }; CC85CB215058F95C0BC190B1 /* Bridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bridge.swift; sourceTree = ""; }; + CD13E09D22EB70BA0078C4C4 /* AutoMockable.stencil */ = {isa = PBXFileReference; lastKnownFileType = text; path = AutoMockable.stencil; sourceTree = ""; }; + CD13E09E22EB70BA0078C4C4 /* Resolver+LegacyApi.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+LegacyApi.swifttemplate"; sourceTree = ""; }; + CD13E09F22EB70BA0078C4C4 /* ServiceEntry+TypeForwarding.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "ServiceEntry+TypeForwarding.swifttemplate"; sourceTree = ""; }; + CD13E0A022EB70BA0078C4C4 /* Resolver+Injection.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+Injection.swifttemplate"; sourceTree = ""; }; + CD13E0A122EB70BA0078C4C4 /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; CDA78290D6D60BD0B808571F /* Container+Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Logging.swift"; sourceTree = ""; }; E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRequest.swift; sourceTree = ""; }; E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; @@ -700,6 +705,7 @@ C5602A1B64E47775AF8D5700 /* Tests */, 80E97D8FD5574A96B6BC9EB9 /* Frameworks */, 8EB6E58A3F28FAEBBC372598 /* Products */, + CD13E09C22EB70BA0078C4C4 /* Templates */, ); indentWidth = 4; sourceTree = ""; @@ -731,6 +737,18 @@ path = Carthage/Build; sourceTree = ""; }; + CD13E09C22EB70BA0078C4C4 /* Templates */ = { + isa = PBXGroup; + children = ( + CD13E09D22EB70BA0078C4C4 /* AutoMockable.stencil */, + CD13E09E22EB70BA0078C4C4 /* Resolver+LegacyApi.swifttemplate */, + CD13E09F22EB70BA0078C4C4 /* ServiceEntry+TypeForwarding.swifttemplate */, + CD13E0A022EB70BA0078C4C4 /* Resolver+Injection.swifttemplate */, + CD13E0A122EB70BA0078C4C4 /* Container+Registration.swifttemplate */, + ); + path = Templates; + sourceTree = ""; + }; D026A6699A2A932511D29E14 /* Sources */ = { isa = PBXGroup; children = ( @@ -1699,7 +1717,11 @@ "$(PROJECT_DIR)/Carthage/Build/iOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -1737,7 +1759,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = macosx; SKIP_INSTALL = YES; @@ -1754,7 +1779,11 @@ "$(PROJECT_DIR)/Carthage/Build/tvOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = appletvos; TARGETED_DEVICE_FAMILY = 3; @@ -1772,7 +1801,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = appletvos; SKIP_INSTALL = YES; @@ -1790,7 +1822,11 @@ "$(PROJECT_DIR)/Carthage/Build/iOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -1807,7 +1843,11 @@ "$(PROJECT_DIR)/Carthage/Build/Mac", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = macosx; }; @@ -1897,7 +1937,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = appletvos; SKIP_INSTALL = YES; @@ -1915,7 +1958,11 @@ "$(PROJECT_DIR)/Carthage/Build/watchOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = watchos; SKIP_INSTALL = YES; @@ -1934,7 +1981,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = iphoneos; SKIP_INSTALL = YES; @@ -1952,7 +2002,11 @@ "$(PROJECT_DIR)/Carthage/Build/watchOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = watchos; SKIP_INSTALL = YES; @@ -1970,7 +2024,11 @@ "$(PROJECT_DIR)/Carthage/Build/Mac", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = macosx; }; @@ -1985,7 +2043,11 @@ "$(PROJECT_DIR)/Carthage/Build/tvOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = appletvos; TARGETED_DEVICE_FAMILY = 3; @@ -2004,7 +2066,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = macosx; SKIP_INSTALL = YES; @@ -2023,7 +2088,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = iphoneos; SKIP_INSTALL = YES; diff --git a/Templates/Container+Registration.swifttemplate b/Templates/Container+Registration.swifttemplate index 6889b089..3d1f28c1 100644 --- a/Templates/Container+Registration.swifttemplate +++ b/Templates/Container+Registration.swifttemplate @@ -16,7 +16,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, _: Void) in factory(r) } + let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef(in: self)) { (r, _, _: Void) in factory(r) } addEntry(entry, with: name) return entry } @@ -41,7 +41,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register>(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, <%= arg_types %>) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, a: <%= arg_closure_type %>) in factory(r, <%= arg_vars %>) } + let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef(in: self)) { (r, _, a: <%= arg_closure_type %>) in factory(r, <%= arg_vars %>) } addEntry(entry, with: name) return entry } diff --git a/Tests/2.0 API/AssemblerSpec.swift b/Tests/2.0 API/AssemblerSpec.swift index 78c32458..a33b7c0d 100644 --- a/Tests/2.0 API/AssemblerSpec.swift +++ b/Tests/2.0 API/AssemblerSpec.swift @@ -51,17 +51,6 @@ class AssemblerSpec: QuickSpec { expect(serviceEntry?.scope) === ObjectScope.container.scope } - it("uses injected default custom scope") { - let scope = UnboundScope() - let assembler = Assembler(parent: nil, defaultScope: scope, defaultMakeRef: strongRef) - - assembler.apply(assembly: ContainerSpyAssembly()) - let container = assembler.resolver.resolve(Container.self) - let serviceEntry = container?.register(Animal.self) { _ in Siamese(name: "Siam") } - - expect(serviceEntry?.scope) === scope - } - it("uses graph scope if no default object scope is injected") { let assembler = Assembler([], parent: nil) diff --git a/Tests/2.0 API/ContainerSpec.swift b/Tests/2.0 API/ContainerSpec.swift index 4971c1d8..44ccee83 100644 --- a/Tests/2.0 API/ContainerSpec.swift +++ b/Tests/2.0 API/ContainerSpec.swift @@ -169,48 +169,69 @@ class ContainerSpec: QuickSpec { expect(cat1) !== cat2 } - // TODO: Implement resetting object scope -// it("releases instance after reseting scope") { -// container.register(Animal.self) { _ in Cat() } -// .inObjectScope(.container) -// -// let cat1 = container.resolve(Animal.self) as? Cat -// container.resetObjectScope(.container) -// let cat2 = container.resolve(Animal.self) as? Cat -// -// expect(cat1) !== cat2 -// } - // TODO: Implement subscopes -// it("shares an object from a parent container to its child.") { -// let parent = Container() -// parent.register(Animal.self) { _ in Cat() } -// .inObjectScope(.container) -// parent.register(Animal.self, name: "dog") { _ in Dog() } -// .inObjectScope(.container) -// let child = Container(parent: parent) -// -// // Case resolving on the parent first. -// let cat1 = parent.resolve(Animal.self) as? Cat -// let cat2 = child.resolve(Animal.self) as? Cat -// expect(cat1 === cat2).to(beTrue()) // Workaround for crash in Nimble. -// -// // Case resolving on the child first. -// let dog1 = child.resolve(Animal.self, name: "dog") as? Dog -// let dog2 = parent.resolve(Animal.self, name: "dog") as? Dog -// expect(dog1 === dog2).to(beTrue()) // Workaround for crash in Nimble. -// } -// it("resolves a service in the parent container to the same object in a graph") { -// let parent = Container() -// parent.register(Food.self) { _ in Sushi() } -// .inObjectScope(.container) -// let child = Container(parent: parent) -// registerCatAndPetOwnerDependingOnFood(child) -// -// let owner = child.resolve(Person.self) as? PetOwner -// let ownersSushi = owner?.favoriteFood as? Sushi -// let catsSushi = (owner?.pet as? Cat)?.favoriteFood as? Sushi -// expect(ownersSushi === catsSushi).to(beTrue()) // Workaround for crash in Nimble. -// } + it("releases instance after reseting scope") { + container.register(Animal.self) { _ in Cat() } + .inObjectScope(.container) + + let cat1 = container.resolve(Animal.self) as? Cat + container.resetObjectScope(.container) + let cat2 = container.resolve(Animal.self) as? Cat + + expect(cat1) !== cat2 + } + it("shares an object from a parent container to its child.") { + let parent = Container() + parent.register(Animal.self) { _ in Cat() } + .inObjectScope(.container) + parent.register(Animal.self, name: "dog") { _ in Dog() } + .inObjectScope(.container) + let child = Container(parent: parent) + + // Case resolving on the parent first. + let cat1 = parent.resolve(Animal.self) as? Cat + let cat2 = child.resolve(Animal.self) as? Cat + expect(cat1 === cat2).to(beTrue()) // Workaround for crash in Nimble. + + // Case resolving on the child first. + let dog1 = child.resolve(Animal.self, name: "dog") as? Dog + let dog2 = parent.resolve(Animal.self, name: "dog") as? Dog + expect(dog1 === dog2).to(beTrue()) // Workaround for crash in Nimble. + } + it("resolves a service in the parent container to the same object in a graph") { + let parent = Container() + parent.register(Food.self) { _ in Sushi() } + .inObjectScope(.container) + let child = Container(parent: parent) + registerCatAndPetOwnerDependingOnFood(child) + + let owner = child.resolve(Person.self) as? PetOwner + let ownersSushi = owner?.favoriteFood as? Sushi + let catsSushi = (owner?.pet as? Cat)?.favoriteFood as? Sushi + expect(ownersSushi === catsSushi).to(beTrue()) // Workaround for crash in Nimble. + } + it("after resetting child it resolves child type to the different instance") { + let parent = Container() + let child = Container(parent: parent) + child.register(Animal.self, factory: { _ in Cat() }).inObjectScope(.container) + let first = child.resolve(Animal.self) + + child.removeAll() + child.register(Animal.self, factory: { _ in Cat() }).inObjectScope(.container) + let second = child.resolve(Animal.self) + + expect(first) !== second + } + it("after resetting child it resolves parent type to the same instance") { + let parent = Container() + let child = Container(parent: parent) + parent.register(Animal.self, factory: { _ in Cat() }).inObjectScope(.container) + + let first = child.resolve(Animal.self) + child.removeAll() + let second = child.resolve(Animal.self) + + expect(first) === second + } } context("in weak scope") { it("shares the object in the container") { @@ -396,13 +417,6 @@ class ContainerSpec: QuickSpec { let serviceEntry = container.register(Animal.self) { _ in Siamese(name: "Siam") } expect(serviceEntry.scope) === ObjectScope.container.scope } - it("registers services with given custom scope") { - let scope = UnboundScope() - let container = Container(parent: nil, defaultScope: scope, defaultMakeRef: strongRef) - - let serviceEntry = container.register(Animal.self) { _ in Siamese(name: "Siam") } - expect(serviceEntry.scope) === scope - } } } } From 00a37ea8d2094699cb341b3250da70ae8313ac05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Fri, 19 Jul 2019 01:42:57 +0200 Subject: [PATCH 136/239] Describe multiton binding --- Tests/3.0 API/SwinjectApiSpec.swift | 11 ++++++++++- Tests/Support/TestModels.swift | 8 ++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Tests/3.0 API/SwinjectApiSpec.swift b/Tests/3.0 API/SwinjectApiSpec.swift index fd403c82..baae64f8 100644 --- a/Tests/3.0 API/SwinjectApiSpec.swift +++ b/Tests/3.0 API/SwinjectApiSpec.swift @@ -184,5 +184,14 @@ class SwinjectApiSpec: QuickSpec { override func spec() { weak var first = try? swinject.instance() as Human expect(first).to(beNil()) } - + it("can bind multitons") { + let swinject = Swinject { + bbind(Building.self) & multiton { Building(floors: $1) } + } + let house1 = try? swinject.instance(arg: 1) as Building + let house2 = try? swinject.instance(arg: 1) as Building + let skyscrapper = try? swinject.instance(arg: 100) as Building + expect(house1) === house2 + expect(skyscrapper) !== house1 + } } } diff --git a/Tests/Support/TestModels.swift b/Tests/Support/TestModels.swift index eb808844..980cbe80 100644 --- a/Tests/Support/TestModels.swift +++ b/Tests/Support/TestModels.swift @@ -14,4 +14,12 @@ struct Pet { let owner: Human } +class Building { + let floors: Int + + init(floors: Int) { + self.floors = floors + } +} + struct TestError: Error, Equatable {} From 7272fab034527ab4930c9e9ee4e4638bc6a73524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Fri, 26 Jul 2019 21:41:48 +0200 Subject: [PATCH 137/239] Add templates to project.yml --- Swinject.xcodeproj/project.pbxproj | 116 ++++++++--------------------- project.yml | 2 + 2 files changed, 35 insertions(+), 83 deletions(-) diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 6d654cf7..e146a9d3 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -412,6 +412,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 01DEC4D20CE554C9DFBD0A8D /* Resolver+Injection.swifttemplate */ = {isa = PBXFileReference; path = "Resolver+Injection.swifttemplate"; sourceTree = ""; }; 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.swift; sourceTree = ""; }; 09FC792715B1658721F76885 /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 0CA449690AE00F6300DE8ACA /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -419,7 +420,7 @@ 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopedBindingSpec.swift; sourceTree = ""; }; 0E0B580B43E1891812C97209 /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; 10480F2154EAA0414D4C1F55 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .swiftlint.yml; sourceTree = ""; }; + 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */ = {isa = PBXFileReference; path = .swiftlint.yml; sourceTree = ""; }; 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SynchronizedResolverSpec.swift; sourceTree = ""; }; 13513FA012659ADE699A3608 /* LazySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LazySpec.swift; sourceTree = ""; }; 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleBindingSpec.swift; sourceTree = ""; }; @@ -441,6 +442,7 @@ 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaggedTypeSpec.swift; sourceTree = ""; }; 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingKeySpec.swift; sourceTree = ""; }; 42490D1D0C395951243F5CFF /* Container.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.swift; sourceTree = ""; }; + 4286F98133270A36F19E5CD0 /* AutoMockable.stencil */ = {isa = PBXFileReference; path = AutoMockable.stencil; sourceTree = ""; }; 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmploymentAssembly.swift; sourceTree = ""; }; 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTree.swift; sourceTree = ""; }; 494AA2AA587975747596C157 /* ProviderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProviderSpec.swift; sourceTree = ""; }; @@ -489,17 +491,14 @@ B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderEnvironment.swift; sourceTree = ""; }; B92B8E618A08408404FB2A7A /* TypeBinder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinder.swift; sourceTree = ""; }; BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StandardScopeRegistrySpec.swift; sourceTree = ""; }; + BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */ = {isa = PBXFileReference; path = "ServiceEntry+TypeForwarding.swifttemplate"; sourceTree = ""; }; BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Behavior.swift; sourceTree = ""; }; C074BAC560F277E806146C60 /* SimpleBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleBinding.swift; sourceTree = ""; }; C765B92B00C0AC8625BB4AC9 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; CADDB3E9E363310028AA5920 /* InstanceMaker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceMaker.swift; sourceTree = ""; }; CC85CB215058F95C0BC190B1 /* Bridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bridge.swift; sourceTree = ""; }; - CD13E09D22EB70BA0078C4C4 /* AutoMockable.stencil */ = {isa = PBXFileReference; lastKnownFileType = text; path = AutoMockable.stencil; sourceTree = ""; }; - CD13E09E22EB70BA0078C4C4 /* Resolver+LegacyApi.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+LegacyApi.swifttemplate"; sourceTree = ""; }; - CD13E09F22EB70BA0078C4C4 /* ServiceEntry+TypeForwarding.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "ServiceEntry+TypeForwarding.swifttemplate"; sourceTree = ""; }; - CD13E0A022EB70BA0078C4C4 /* Resolver+Injection.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+Injection.swifttemplate"; sourceTree = ""; }; - CD13E0A122EB70BA0078C4C4 /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; CDA78290D6D60BD0B808571F /* Container+Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Logging.swift"; sourceTree = ""; }; + CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRequest.swift; sourceTree = ""; }; E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; EDA62EEBC79ED2639C93A76B /* TypeBinderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinderSpec.swift; sourceTree = ""; }; @@ -508,6 +507,7 @@ F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.TypeForwarding.swift; sourceTree = ""; }; FCAF491EC7DCD7477F9A0ECB /* SwinjectModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectModule.swift; sourceTree = ""; }; FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderEnvironmentSpec.swift; sourceTree = ""; }; + FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */ = {isa = PBXFileReference; path = "Resolver+LegacyApi.swifttemplate"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -554,6 +554,18 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 07354387D49F6D7BBBA4F3AC /* Templates */ = { + isa = PBXGroup; + children = ( + 4286F98133270A36F19E5CD0 /* AutoMockable.stencil */, + CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */, + 01DEC4D20CE554C9DFBD0A8D /* Resolver+Injection.swifttemplate */, + FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */, + BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */, + ); + path = Templates; + sourceTree = ""; + }; 0A05322134E988A4593B5122 /* Unit Specs */ = { isa = PBXGroup; children = ( @@ -702,10 +714,10 @@ isa = PBXGroup; children = ( D026A6699A2A932511D29E14 /* Sources */, + 07354387D49F6D7BBBA4F3AC /* Templates */, C5602A1B64E47775AF8D5700 /* Tests */, 80E97D8FD5574A96B6BC9EB9 /* Frameworks */, 8EB6E58A3F28FAEBBC372598 /* Products */, - CD13E09C22EB70BA0078C4C4 /* Templates */, ); indentWidth = 4; sourceTree = ""; @@ -737,18 +749,6 @@ path = Carthage/Build; sourceTree = ""; }; - CD13E09C22EB70BA0078C4C4 /* Templates */ = { - isa = PBXGroup; - children = ( - CD13E09D22EB70BA0078C4C4 /* AutoMockable.stencil */, - CD13E09E22EB70BA0078C4C4 /* Resolver+LegacyApi.swifttemplate */, - CD13E09F22EB70BA0078C4C4 /* ServiceEntry+TypeForwarding.swifttemplate */, - CD13E0A022EB70BA0078C4C4 /* Resolver+Injection.swifttemplate */, - CD13E0A122EB70BA0078C4C4 /* Container+Registration.swifttemplate */, - ); - path = Templates; - sourceTree = ""; - }; D026A6699A2A932511D29E14 /* Sources */ = { isa = PBXGroup; children = ( @@ -1717,11 +1717,7 @@ "$(PROJECT_DIR)/Carthage/Build/iOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -1759,10 +1755,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; PRODUCT_NAME = Swinject; SDKROOT = macosx; SKIP_INSTALL = YES; @@ -1779,11 +1772,7 @@ "$(PROJECT_DIR)/Carthage/Build/tvOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = appletvos; TARGETED_DEVICE_FAMILY = 3; @@ -1801,10 +1790,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = Swinject; SDKROOT = appletvos; SKIP_INSTALL = YES; @@ -1822,11 +1808,7 @@ "$(PROJECT_DIR)/Carthage/Build/iOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -1843,11 +1825,7 @@ "$(PROJECT_DIR)/Carthage/Build/Mac", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - "@loader_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = macosx; }; @@ -1937,10 +1915,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = Swinject; SDKROOT = appletvos; SKIP_INSTALL = YES; @@ -1958,11 +1933,7 @@ "$(PROJECT_DIR)/Carthage/Build/watchOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = watchos; SKIP_INSTALL = YES; @@ -1981,10 +1952,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = Swinject; SDKROOT = iphoneos; SKIP_INSTALL = YES; @@ -2002,11 +1970,7 @@ "$(PROJECT_DIR)/Carthage/Build/watchOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = watchos; SKIP_INSTALL = YES; @@ -2024,11 +1988,7 @@ "$(PROJECT_DIR)/Carthage/Build/Mac", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - "@loader_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = macosx; }; @@ -2043,11 +2003,7 @@ "$(PROJECT_DIR)/Carthage/Build/tvOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = appletvos; TARGETED_DEVICE_FAMILY = 3; @@ -2066,10 +2022,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; PRODUCT_NAME = Swinject; SDKROOT = macosx; SKIP_INSTALL = YES; @@ -2088,10 +2041,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = Swinject; SDKROOT = iphoneos; SKIP_INSTALL = YES; diff --git a/project.yml b/project.yml index a1d6eed6..45bc2926 100644 --- a/project.yml +++ b/project.yml @@ -20,6 +20,8 @@ targets: sources: - path: Sources excludes: ["**/*.erb"] + - path: Templates + buildPhase: none preBuildScripts: - script: > if which sourcery >/dev/null; then From 5f2ab4b4b76add1a73165f5a4189ddd9505f812f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Fri, 26 Jul 2019 22:07:46 +0200 Subject: [PATCH 138/239] Define argument box --- Sources/Core/Matchable.swift | 57 +++++++----- Swinject.xcodeproj/project.pbxproj | 92 +++++++++++++++---- Templates/ArgumentBox.swifttemplate | 12 +++ Tests/Support/GeneratedMocks.swift | 2 + .../StandardScopeRegistrySpec.swift | 2 +- 5 files changed, 121 insertions(+), 44 deletions(-) create mode 100644 Templates/ArgumentBox.swifttemplate diff --git a/Sources/Core/Matchable.swift b/Sources/Core/Matchable.swift index 287c2545..1afcda17 100644 --- a/Sources/Core/Matchable.swift +++ b/Sources/Core/Matchable.swift @@ -8,31 +8,42 @@ public protocol Matchable { func hash(into hasher: inout Hasher) } -// TODO: Box / Unbox internally all the arguments -struct AnyMatchable: Matchable, Hashable { - let value: Any - private let matchesValue: (Any) -> Bool - private let hashValueInto: (inout Hasher) -> Void - - init(_ value: T) { - self.value = value - matchesValue = { $0 as? T == value } - hashValueInto = { value.hash(into: &$0) } - } - +public extension Matchable where Self: Equatable { func matches(_ other: Any) -> Bool { - if let other = other as? AnyMatchable { - return matchesValue(other.value) - } else { - return false - } + self == (other as? Self) } +} - func hash(into hasher: inout Hasher) { - hashValueInto(&hasher) - } +// swiftlint:disable line_length +// sourcery:inline:ArgumentBox +struct ArgumentBox1: Hashable, Matchable where Arg1: Hashable { + let arg1: Arg1 +} - static func == (lhs: AnyMatchable, rhs: AnyMatchable) -> Bool { - lhs.matches(rhs.value) - } +struct ArgumentBox2: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable { + let arg1: Arg1 + let arg2: Arg2 } + +struct ArgumentBox3: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + let arg1: Arg1 + let arg2: Arg2 + let arg3: Arg3 +} + +struct ArgumentBox4: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + let arg1: Arg1 + let arg2: Arg2 + let arg3: Arg3 + let arg4: Arg4 +} + +struct ArgumentBox5: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + let arg1: Arg1 + let arg2: Arg2 + let arg3: Arg3 + let arg4: Arg4 + let arg5: Arg5 +} + +// sourcery:end diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index e146a9d3..e3568461 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -412,7 +412,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 01DEC4D20CE554C9DFBD0A8D /* Resolver+Injection.swifttemplate */ = {isa = PBXFileReference; path = "Resolver+Injection.swifttemplate"; sourceTree = ""; }; + 01DEC4D20CE554C9DFBD0A8D /* Resolver+Injection.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+Injection.swifttemplate"; sourceTree = ""; }; 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.swift; sourceTree = ""; }; 09FC792715B1658721F76885 /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 0CA449690AE00F6300DE8ACA /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -420,7 +420,7 @@ 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopedBindingSpec.swift; sourceTree = ""; }; 0E0B580B43E1891812C97209 /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; 10480F2154EAA0414D4C1F55 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */ = {isa = PBXFileReference; path = .swiftlint.yml; sourceTree = ""; }; + 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .swiftlint.yml; sourceTree = ""; }; 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SynchronizedResolverSpec.swift; sourceTree = ""; }; 13513FA012659ADE699A3608 /* LazySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LazySpec.swift; sourceTree = ""; }; 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleBindingSpec.swift; sourceTree = ""; }; @@ -442,7 +442,7 @@ 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaggedTypeSpec.swift; sourceTree = ""; }; 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingKeySpec.swift; sourceTree = ""; }; 42490D1D0C395951243F5CFF /* Container.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.swift; sourceTree = ""; }; - 4286F98133270A36F19E5CD0 /* AutoMockable.stencil */ = {isa = PBXFileReference; path = AutoMockable.stencil; sourceTree = ""; }; + 4286F98133270A36F19E5CD0 /* AutoMockable.stencil */ = {isa = PBXFileReference; lastKnownFileType = text; path = AutoMockable.stencil; sourceTree = ""; }; 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmploymentAssembly.swift; sourceTree = ""; }; 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTree.swift; sourceTree = ""; }; 494AA2AA587975747596C157 /* ProviderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProviderSpec.swift; sourceTree = ""; }; @@ -491,14 +491,15 @@ B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderEnvironment.swift; sourceTree = ""; }; B92B8E618A08408404FB2A7A /* TypeBinder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinder.swift; sourceTree = ""; }; BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StandardScopeRegistrySpec.swift; sourceTree = ""; }; - BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */ = {isa = PBXFileReference; path = "ServiceEntry+TypeForwarding.swifttemplate"; sourceTree = ""; }; + BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "ServiceEntry+TypeForwarding.swifttemplate"; sourceTree = ""; }; BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Behavior.swift; sourceTree = ""; }; C074BAC560F277E806146C60 /* SimpleBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleBinding.swift; sourceTree = ""; }; C765B92B00C0AC8625BB4AC9 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; CADDB3E9E363310028AA5920 /* InstanceMaker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceMaker.swift; sourceTree = ""; }; CC85CB215058F95C0BC190B1 /* Bridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bridge.swift; sourceTree = ""; }; CDA78290D6D60BD0B808571F /* Container+Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Logging.swift"; sourceTree = ""; }; - CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; + CDCF3FCB22EB8F960025E2BD /* ArgumentBox.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = ArgumentBox.swifttemplate; sourceTree = ""; }; + CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRequest.swift; sourceTree = ""; }; E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; EDA62EEBC79ED2639C93A76B /* TypeBinderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinderSpec.swift; sourceTree = ""; }; @@ -507,7 +508,7 @@ F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.TypeForwarding.swift; sourceTree = ""; }; FCAF491EC7DCD7477F9A0ECB /* SwinjectModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectModule.swift; sourceTree = ""; }; FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderEnvironmentSpec.swift; sourceTree = ""; }; - FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */ = {isa = PBXFileReference; path = "Resolver+LegacyApi.swifttemplate"; sourceTree = ""; }; + FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+LegacyApi.swifttemplate"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -558,6 +559,7 @@ isa = PBXGroup; children = ( 4286F98133270A36F19E5CD0 /* AutoMockable.stencil */, + CDCF3FCB22EB8F960025E2BD /* ArgumentBox.swifttemplate */, CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */, 01DEC4D20CE554C9DFBD0A8D /* Resolver+Injection.swifttemplate */, FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */, @@ -1717,7 +1719,11 @@ "$(PROJECT_DIR)/Carthage/Build/iOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -1755,7 +1761,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = macosx; SKIP_INSTALL = YES; @@ -1772,7 +1781,11 @@ "$(PROJECT_DIR)/Carthage/Build/tvOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = appletvos; TARGETED_DEVICE_FAMILY = 3; @@ -1790,7 +1803,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = appletvos; SKIP_INSTALL = YES; @@ -1808,7 +1824,11 @@ "$(PROJECT_DIR)/Carthage/Build/iOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -1825,7 +1845,11 @@ "$(PROJECT_DIR)/Carthage/Build/Mac", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = macosx; }; @@ -1915,7 +1939,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = appletvos; SKIP_INSTALL = YES; @@ -1933,7 +1960,11 @@ "$(PROJECT_DIR)/Carthage/Build/watchOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = watchos; SKIP_INSTALL = YES; @@ -1952,7 +1983,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = iphoneos; SKIP_INSTALL = YES; @@ -1970,7 +2004,11 @@ "$(PROJECT_DIR)/Carthage/Build/watchOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = watchos; SKIP_INSTALL = YES; @@ -1988,7 +2026,11 @@ "$(PROJECT_DIR)/Carthage/Build/Mac", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = macosx; }; @@ -2003,7 +2045,11 @@ "$(PROJECT_DIR)/Carthage/Build/tvOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = appletvos; TARGETED_DEVICE_FAMILY = 3; @@ -2022,7 +2068,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = macosx; SKIP_INSTALL = YES; @@ -2041,7 +2090,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = iphoneos; SKIP_INSTALL = YES; diff --git a/Templates/ArgumentBox.swifttemplate b/Templates/ArgumentBox.swifttemplate new file mode 100644 index 00000000..ca62a7b9 --- /dev/null +++ b/Templates/ArgumentBox.swifttemplate @@ -0,0 +1,12 @@ +<% let arg_count = 5 %> +// sourcery:inline:ArgumentBox +<%_ (1...arg_count).forEach { i in + let arg_types = (1...i).map { "Arg\($0)" }.joined(separator: ", ") + let arg_hashables = (1...i).map { "Arg\($0): Hashable" }.joined(separator: ", ") +-%> +struct ArgumentBox<%= i %><<%= arg_types %>>: Hashable, Matchable where <%= arg_hashables %>{ + <%= (1...i).map { "let arg\($0): Arg\($0)" }.joined(separator: "\n ") %> +} + +<%_ } -%> +// sourcery:end diff --git a/Tests/Support/GeneratedMocks.swift b/Tests/Support/GeneratedMocks.swift index eb709a2e..fd5a1b56 100644 --- a/Tests/Support/GeneratedMocks.swift +++ b/Tests/Support/GeneratedMocks.swift @@ -2,6 +2,8 @@ // DO NOT EDIT + + // swiftlint:disable line_length // swiftlint:disable variable_name diff --git a/Tests/Unit Specs/StandardScopeRegistrySpec.swift b/Tests/Unit Specs/StandardScopeRegistrySpec.swift index d451e07a..b3fdca53 100644 --- a/Tests/Unit Specs/StandardScopeRegistrySpec.swift +++ b/Tests/Unit Specs/StandardScopeRegistrySpec.swift @@ -8,7 +8,7 @@ import Quick class StandardScopeRegistrySpec: QuickSpec { override func spec() { var registry: StandardScopeRegistry! - let key = (1 ... 5).map { ScopeRegistryKey(descriptor: plain(Int.self), argument: AnyMatchable($0)) } + let key = (1 ... 5).map { ScopeRegistryKey(descriptor: tagged(Int.self, with: $0), argument: ()) } var closable = [ClosableMock]() beforeEach { closable = (1 ... 3).map { _ in ClosableMock() } From 61ab565f9d06fb475702e8b6277fe3d09d2a86bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Fri, 26 Jul 2019 22:41:19 +0200 Subject: [PATCH 139/239] Make multitons work for single argument --- Sources/3.0 API/BinderEnvironment.swift | 12 ++++++-- Sources/3.0 API/Resolver+Injection.swift | 14 +++++++++ Sources/Core/Matchable.swift | 30 ++++++++++++++++---- Templates/ArgumentBox.swifttemplate | 13 ++++++++- Tests/Unit Specs/BinderEnvironmentSpec.swift | 4 +-- Tests/Unit Specs/SwinjectSpec.swift | 2 +- 6 files changed, 64 insertions(+), 11 deletions(-) diff --git a/Sources/3.0 API/BinderEnvironment.swift b/Sources/3.0 API/BinderEnvironment.swift index c2a61440..fef348fe 100644 --- a/Sources/3.0 API/BinderEnvironment.swift +++ b/Sources/3.0 API/BinderEnvironment.swift @@ -21,13 +21,13 @@ public extension BinderEnvironment where AScope == Void { func provider(_ builder: @escaping (Resolver, Context) throws -> Type) -> SimpleBinding.Builder { .init { r, c, _ in try builder(r, c) } } +} +public extension BinderEnvironment where AScope == Void { func factory(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SimpleBinding.Builder { .init(builder) } -} -public extension BinderEnvironment where AScope == Void { func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SimpleBinding.Builder { .init { try builder($0, $1, $2.0, $2.1) } } @@ -97,6 +97,10 @@ public func factory(_ builder: @escaping (Resolver, Arg1) throws -> .init { try builder($0, $2) } } +public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> SimpleBinding.Builder> { + .init { try builder($0, $2.arg1) } +} + public func factory(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SimpleBinding.Builder { .init { try builder($0, $2.0, $2.1) } } @@ -125,6 +129,10 @@ public func multiton(ref: @escaping ReferenceMaker = strongRef .init(.root, ref) { try builder($0, $2) } } +public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1) throws -> Type) -> ScopedBinding.Builder> { + .init(.root, ref) { try builder($0, $2.arg1) } +} + public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> ScopedBinding.Builder { .init(.root, ref) { try builder($0, $2.0, $2.1) } } diff --git a/Sources/3.0 API/Resolver+Injection.swift b/Sources/3.0 API/Resolver+Injection.swift index a77e1b75..5ee5325c 100644 --- a/Sources/3.0 API/Resolver+Injection.swift +++ b/Sources/3.0 API/Resolver+Injection.swift @@ -2,6 +2,20 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // +public extension Resolver { + func instance(of _: Type.Type = Type.self, arg arg1: Arg1) throws -> Type { + try resolve(request(tag: NoTag(), arg: box(arg1))) + } + + func provider(of _: Type.Type = Type.self, arg arg1: Arg1) -> () throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: box(arg1))) } + } + + func factory(of _: Type.Type = Type.self) -> (Arg1) throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: box($0))) } + } +} + // swiftlint:disable line_length // swiftlint:disable function_parameter_count // sourcery:inline:ResolverInjectionApi diff --git a/Sources/Core/Matchable.swift b/Sources/Core/Matchable.swift index 1afcda17..601487e3 100644 --- a/Sources/Core/Matchable.swift +++ b/Sources/Core/Matchable.swift @@ -16,29 +16,29 @@ public extension Matchable where Self: Equatable { // swiftlint:disable line_length // sourcery:inline:ArgumentBox -struct ArgumentBox1: Hashable, Matchable where Arg1: Hashable { +public struct ArgumentBox1: Hashable, Matchable where Arg1: Hashable { let arg1: Arg1 } -struct ArgumentBox2: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable { +public struct ArgumentBox2: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable { let arg1: Arg1 let arg2: Arg2 } -struct ArgumentBox3: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { +public struct ArgumentBox3: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { let arg1: Arg1 let arg2: Arg2 let arg3: Arg3 } -struct ArgumentBox4: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { +public struct ArgumentBox4: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { let arg1: Arg1 let arg2: Arg2 let arg3: Arg3 let arg4: Arg4 } -struct ArgumentBox5: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { +public struct ArgumentBox5: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { let arg1: Arg1 let arg2: Arg2 let arg3: Arg3 @@ -46,4 +46,24 @@ struct ArgumentBox5: Hashable, Matchable where Arg let arg5: Arg5 } +func box(_ arg1: Arg1) -> ArgumentBox1 where Arg1: Hashable { + ArgumentBox1(arg1: arg1) +} + +func box(_ arg1: Arg1, _ arg2: Arg2) -> ArgumentBox2 where Arg1: Hashable, Arg2: Hashable { + ArgumentBox2(arg1: arg1, arg2: arg2) +} + +func box(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> ArgumentBox3 where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + ArgumentBox3(arg1: arg1, arg2: arg2, arg3: arg3) +} + +func box(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> ArgumentBox4 where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + ArgumentBox4(arg1: arg1, arg2: arg2, arg3: arg3, arg4: arg4) +} + +func box(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> ArgumentBox5 where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + ArgumentBox5(arg1: arg1, arg2: arg2, arg3: arg3, arg4: arg4, arg5: arg5) +} + // sourcery:end diff --git a/Templates/ArgumentBox.swifttemplate b/Templates/ArgumentBox.swifttemplate index ca62a7b9..40a85402 100644 --- a/Templates/ArgumentBox.swifttemplate +++ b/Templates/ArgumentBox.swifttemplate @@ -4,9 +4,20 @@ let arg_types = (1...i).map { "Arg\($0)" }.joined(separator: ", ") let arg_hashables = (1...i).map { "Arg\($0): Hashable" }.joined(separator: ", ") -%> -struct ArgumentBox<%= i %><<%= arg_types %>>: Hashable, Matchable where <%= arg_hashables %>{ +public struct ArgumentBox<%= i %><<%= arg_types %>>: Hashable, Matchable where <%= arg_hashables %>{ <%= (1...i).map { "let arg\($0): Arg\($0)" }.joined(separator: "\n ") %> } +<%_ } -%> +<%_ (1...arg_count).forEach { i in + let arg_types = (1...i).map { "Arg\($0)" }.joined(separator: ", ") + let arg_hashables = (1...i).map { "Arg\($0): Hashable" }.joined(separator: ", ") + let arg_params = (1...i).map { "_ arg\($0): Arg\($0)" }.joined(separator: ", ") + let arg_call_params = (1...i).map { "arg\($0): arg\($0)" }.joined(separator: ", ") +-%> +func box<<%= arg_types %>>(<%= arg_params %>) -> ArgumentBox<%= i %><<%= arg_types %>> where <%= arg_hashables %> { + ArgumentBox<%= i %>(<%= arg_call_params %>) +} + <%_ } -%> // sourcery:end diff --git a/Tests/Unit Specs/BinderEnvironmentSpec.swift b/Tests/Unit Specs/BinderEnvironmentSpec.swift index 7af35d52..55bf1629 100644 --- a/Tests/Unit Specs/BinderEnvironmentSpec.swift +++ b/Tests/Unit Specs/BinderEnvironmentSpec.swift @@ -75,7 +75,7 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { it("calls builder with given argument") { var passedArgument: Int? let maker = factory { (_, arg: Int) in passedArgument = arg } - _ = try? maker.makeInstance(arg: 42, resolver: DummyResolver()) + _ = try? maker.makeInstance(arg: box(42), resolver: DummyResolver()) expect(passedArgument) == 42 } it("rethrows error from builder") { @@ -177,7 +177,7 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { it("calls builder with given argument") { var passedArgument: Int? let maker = multiton { (_, arg: Int) in passedArgument = arg } - _ = try? maker.makeInstance(arg: 42, resolver: DummyResolver()) + _ = try? maker.makeInstance(arg: box(42), resolver: DummyResolver()) expect(passedArgument) == 42 } it("rethrows error from builder") { diff --git a/Tests/Unit Specs/SwinjectSpec.swift b/Tests/Unit Specs/SwinjectSpec.swift index bd6864d1..ac7af64f 100644 --- a/Tests/Unit Specs/SwinjectSpec.swift +++ b/Tests/Unit Specs/SwinjectSpec.swift @@ -208,7 +208,7 @@ class SwinjectSpec: QuickSpec { override func spec() { binding.matchesReturnValue = true binding.instanceArgContextResolverReturnValue = 42 _ = try? swinject.factory(of: Int.self)("arg") - expect(binding.instanceArgContextResolverReceivedArguments?.arg as? String) == "arg" + expect(binding.instanceArgContextResolverReceivedArguments?.arg as? ArgumentBox1) == box("arg") } it("matches binding with correct key") { binding.matchesReturnValue = false From dfe9756848adc07f3d1e31bceb9e3dac8d047747 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sat, 27 Jul 2019 00:58:56 +0200 Subject: [PATCH 140/239] Implement argument boxing for injection methods --- Sources/3.0 API/Resolver+Injection.swift | 307 ++++++++++++++----- Sources/Core/Matchable.swift | 103 ++++++- Templates/ArgumentBox.swifttemplate | 19 +- Templates/Resolver+Injection.swifttemplate | 104 +++++-- Tests/3.0 API/SwinjectApiSpec.swift | 2 +- Tests/Unit Specs/BinderEnvironmentSpec.swift | 4 +- Tests/Unit Specs/SwinjectSpec.swift | 41 +-- 7 files changed, 427 insertions(+), 153 deletions(-) diff --git a/Sources/3.0 API/Resolver+Injection.swift b/Sources/3.0 API/Resolver+Injection.swift index 5ee5325c..bd7ca7a4 100644 --- a/Sources/3.0 API/Resolver+Injection.swift +++ b/Sources/3.0 API/Resolver+Injection.swift @@ -2,152 +2,301 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -public extension Resolver { - func instance(of _: Type.Type = Type.self, arg arg1: Arg1) throws -> Type { - try resolve(request(tag: NoTag(), arg: box(arg1))) +// swiftlint:disable line_length +// swiftlint:disable large_tuple +// sourcery:inline:ResolverInjectionApi +extension Resolver { + func instance(of _: Type.Type = Type.self) throws -> Type { + try resolve(request(tag: NoTag(), arg: ())) + } + + func instance(of _: Type.Type = Type.self, arg: Arg1) throws -> Type { + try resolve(request(tag: NoTag(), arg: pack(arg))) + } + + func instance(of _: Type.Type = Type.self, arg: Arg1) throws -> Type where Arg1: Hashable { + try resolve(request(tag: NoTag(), arg: pack(arg))) + } + + func instance(of _: Type.Type = Type.self, tagged tag: Tag) throws -> Type where Tag: Hashable { + try resolve(request(tag: tag, arg: ())) } - func provider(of _: Type.Type = Type.self, arg arg1: Arg1) -> () throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: box(arg1))) } + func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg: Arg1) throws -> Type where Tag: Hashable { + try resolve(request(tag: tag, arg: pack(arg))) } - func factory(of _: Type.Type = Type.self) -> (Arg1) throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: box($0))) } + func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg: Arg1) throws -> Type where Tag: Hashable, Arg1: Hashable { + try resolve(request(tag: tag, arg: pack(arg))) } } -// swiftlint:disable line_length -// swiftlint:disable function_parameter_count -// sourcery:inline:ResolverInjectionApi -public extension Resolver { - func instance(of _: Type.Type = Type.self) throws -> Type { - try resolve(request(tag: NoTag(), arg: ())) +extension Resolver { + func provider(of _: Type.Type = Type.self) -> () throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: ())) } } - func instance(of _: Type.Type = Type.self, tagged tag: Tag) throws -> Type { - try resolve(request(tag: tag, arg: ())) + func provider(of _: Type.Type = Type.self, arg: Arg1) -> () throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: pack(arg))) } } - func instance(of _: Type.Type = Type.self, arg arg1: Arg1) throws -> Type { - try resolve(request(tag: NoTag(), arg: arg1)) + func provider(of _: Type.Type = Type.self, arg: Arg1) -> () throws -> Type where Arg1: Hashable { + return { try self.resolve(request(tag: NoTag(), arg: pack(arg))) } } - func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) throws -> Type { - try resolve(request(tag: tag, arg: arg1)) + func provider(of _: Type.Type = Type.self, tagged tag: Tag) -> () throws -> Type where Tag: Hashable { + return { try self.resolve(request(tag: tag, arg: ())) } } - func instance(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2) throws -> Type { - try resolve(request(tag: NoTag(), arg: (arg1, arg2))) + func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg: Arg1) -> () throws -> Type where Tag: Hashable { + return { try self.resolve(request(tag: tag, arg: pack(arg))) } } - func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2) throws -> Type { - try resolve(request(tag: tag, arg: (arg1, arg2))) + func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg: Arg1) -> () throws -> Type where Tag: Hashable, Arg1: Hashable { + return { try self.resolve(request(tag: tag, arg: pack(arg))) } } +} - func instance(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) throws -> Type { - try resolve(request(tag: NoTag(), arg: (arg1, arg2, arg3))) +extension Resolver { + func factory(of _: Type.Type = Type.self) -> (Arg1) throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: pack($0))) } } - func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) throws -> Type { - try resolve(request(tag: tag, arg: (arg1, arg2, arg3))) + func factory(of _: Type.Type = Type.self) -> (Arg1) throws -> Type where Arg1: Hashable { + return { try self.resolve(request(tag: NoTag(), arg: pack($0))) } } - func instance(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) throws -> Type { - try resolve(request(tag: NoTag(), arg: (arg1, arg2, arg3, arg4))) + func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2) throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: pack($0, $1))) } } - func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) throws -> Type { - try resolve(request(tag: tag, arg: (arg1, arg2, arg3, arg4))) + func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2) throws -> Type where Arg1: Hashable, Arg2: Hashable { + return { try self.resolve(request(tag: NoTag(), arg: pack($0, $1))) } } - func instance(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) throws -> Type { - try resolve(request(tag: NoTag(), arg: (arg1, arg2, arg3, arg4, arg5))) + func factory(of _: Type.Type = Type.self, arg: Arg1) -> (Arg2) throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: pack(arg, $0))) } } - func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) throws -> Type { - try resolve(request(tag: tag, arg: (arg1, arg2, arg3, arg4, arg5))) + func factory(of _: Type.Type = Type.self, arg: Arg1) -> (Arg2) throws -> Type where Arg1: Hashable, Arg2: Hashable { + return { try self.resolve(request(tag: NoTag(), arg: pack(arg, $0))) } } -} -public extension Resolver { - func provider(of _: Type.Type = Type.self) -> () throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: ())) } + func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2, Arg3) throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: pack($0, $1, $2))) } } - func provider(of _: Type.Type = Type.self, tagged tag: Tag) -> () throws -> Type { - return { try self.resolve(request(tag: tag, arg: ())) } + func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2, Arg3) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + return { try self.resolve(request(tag: NoTag(), arg: pack($0, $1, $2))) } } - func provider(of _: Type.Type = Type.self, arg arg1: Arg1) -> () throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: arg1)) } + func factory(of _: Type.Type = Type.self, arg: Arg1) -> (Arg2, Arg3) throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: pack(arg, $0, $1))) } } - func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) -> () throws -> Type { - return { try self.resolve(request(tag: tag, arg: arg1)) } + func factory(of _: Type.Type = Type.self, arg: Arg1) -> (Arg2, Arg3) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + return { try self.resolve(request(tag: NoTag(), arg: pack(arg, $0, $1))) } } - func provider(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2) -> () throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: (arg1, arg2))) } + func factory(of _: Type.Type = Type.self, arg: (Arg1, Arg2)) -> (Arg3) throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: pack(arg.0, arg.1, $0))) } } - func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2) -> () throws -> Type { - return { try self.resolve(request(tag: tag, arg: (arg1, arg2))) } + func factory(of _: Type.Type = Type.self, arg: ArgumentBox2) -> (Arg3) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + return { try self.resolve(request(tag: NoTag(), arg: pack(arg.arg1, arg.arg2, $0))) } } - func provider(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> () throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: (arg1, arg2, arg3))) } + func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2, Arg3, Arg4) throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: pack($0, $1, $2, $3))) } } - func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> () throws -> Type { - return { try self.resolve(request(tag: tag, arg: (arg1, arg2, arg3))) } + func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2, Arg3, Arg4) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + return { try self.resolve(request(tag: NoTag(), arg: pack($0, $1, $2, $3))) } } - func provider(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> () throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: (arg1, arg2, arg3, arg4))) } + func factory(of _: Type.Type = Type.self, arg: Arg1) -> (Arg2, Arg3, Arg4) throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: pack(arg, $0, $1, $2))) } } - func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> () throws -> Type { - return { try self.resolve(request(tag: tag, arg: (arg1, arg2, arg3, arg4))) } + func factory(of _: Type.Type = Type.self, arg: Arg1) -> (Arg2, Arg3, Arg4) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + return { try self.resolve(request(tag: NoTag(), arg: pack(arg, $0, $1, $2))) } } - func provider(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> () throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: (arg1, arg2, arg3, arg4, arg5))) } + func factory(of _: Type.Type = Type.self, arg: (Arg1, Arg2)) -> (Arg3, Arg4) throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: pack(arg.0, arg.1, $0, $1))) } } - func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> () throws -> Type { - return { try self.resolve(request(tag: tag, arg: (arg1, arg2, arg3, arg4, arg5))) } + func factory(of _: Type.Type = Type.self, arg: ArgumentBox2) -> (Arg3, Arg4) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + return { try self.resolve(request(tag: NoTag(), arg: pack(arg.arg1, arg.arg2, $0, $1))) } } -} -// sourcery:end + func factory(of _: Type.Type = Type.self, arg: (Arg1, Arg2, Arg3)) -> (Arg4) throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: pack(arg.0, arg.1, arg.2, $0))) } + } -// TODO: Generate -public extension Resolver { - func factory(of _: Type.Type = Type.self) -> (Argument) throws -> Type { - factory(tagged: NoTag()) + func factory(of _: Type.Type = Type.self, arg: ArgumentBox3) -> (Arg4) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + return { try self.resolve(request(tag: NoTag(), arg: pack(arg.arg1, arg.arg2, arg.arg3, $0))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Argument) throws -> Type { - return { try self.resolve(request(tag: tag, arg: $0)) } + func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: pack($0, $1, $2, $3, $4))) } } - func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2) throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: ($0, $1))) } + func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + return { try self.resolve(request(tag: NoTag(), arg: pack($0, $1, $2, $3, $4))) } } - func factory(of _: Type.Type = Type.self, arg: Arg1) -> (Arg2) throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: (arg, $0))) } + func factory(of _: Type.Type = Type.self, arg: Arg1) -> (Arg2, Arg3, Arg4, Arg5) throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: pack(arg, $0, $1, $2, $3))) } } - func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2, Arg3) throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: ($0, $1, $2))) } + func factory(of _: Type.Type = Type.self, arg: Arg1) -> (Arg2, Arg3, Arg4, Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + return { try self.resolve(request(tag: NoTag(), arg: pack(arg, $0, $1, $2, $3))) } } - func factory(of _: Type.Type = Type.self, arg: Arg1) -> (Arg2, Arg3) throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: (arg, $0, $1))) } + func factory(of _: Type.Type = Type.self, arg: (Arg1, Arg2)) -> (Arg3, Arg4, Arg5) throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: pack(arg.0, arg.1, $0, $1, $2))) } + } + + func factory(of _: Type.Type = Type.self, arg: ArgumentBox2) -> (Arg3, Arg4, Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + return { try self.resolve(request(tag: NoTag(), arg: pack(arg.arg1, arg.arg2, $0, $1, $2))) } + } + + func factory(of _: Type.Type = Type.self, arg: (Arg1, Arg2, Arg3)) -> (Arg4, Arg5) throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: pack(arg.0, arg.1, arg.2, $0, $1))) } + } + + func factory(of _: Type.Type = Type.self, arg: ArgumentBox3) -> (Arg4, Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + return { try self.resolve(request(tag: NoTag(), arg: pack(arg.arg1, arg.arg2, arg.arg3, $0, $1))) } + } + + func factory(of _: Type.Type = Type.self, arg: (Arg1, Arg2, Arg3, Arg4)) -> (Arg5) throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: pack(arg.0, arg.1, arg.2, arg.3, $0))) } + } + + func factory(of _: Type.Type = Type.self, arg: ArgumentBox4) -> (Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + return { try self.resolve(request(tag: NoTag(), arg: pack(arg.arg1, arg.arg2, arg.arg3, arg.arg4, $0))) } + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1) throws -> Type where Tag: Hashable { + return { try self.resolve(request(tag: tag, arg: pack($0))) } + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1) throws -> Type where Tag: Hashable, Arg1: Hashable { + return { try self.resolve(request(tag: tag, arg: pack($0))) } + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1, Arg2) throws -> Type where Tag: Hashable { + return { try self.resolve(request(tag: tag, arg: pack($0, $1))) } + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1, Arg2) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable { + return { try self.resolve(request(tag: tag, arg: pack($0, $1))) } } - func factory(of _: Type.Type = Type.self, args arg1: Arg1, _ arg2: Arg2) -> (Arg3) throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: (arg1, arg2, $0))) } + func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg: Arg1) -> (Arg2) throws -> Type where Tag: Hashable { + return { try self.resolve(request(tag: tag, arg: pack(arg, $0))) } + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg: Arg1) -> (Arg2) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable { + return { try self.resolve(request(tag: tag, arg: pack(arg, $0))) } + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1, Arg2, Arg3) throws -> Type where Tag: Hashable { + return { try self.resolve(request(tag: tag, arg: pack($0, $1, $2))) } + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1, Arg2, Arg3) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + return { try self.resolve(request(tag: tag, arg: pack($0, $1, $2))) } + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg: Arg1) -> (Arg2, Arg3) throws -> Type where Tag: Hashable { + return { try self.resolve(request(tag: tag, arg: pack(arg, $0, $1))) } + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg: Arg1) -> (Arg2, Arg3) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + return { try self.resolve(request(tag: tag, arg: pack(arg, $0, $1))) } + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg: (Arg1, Arg2)) -> (Arg3) throws -> Type where Tag: Hashable { + return { try self.resolve(request(tag: tag, arg: pack(arg.0, arg.1, $0))) } + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg: ArgumentBox2) -> (Arg3) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + return { try self.resolve(request(tag: tag, arg: pack(arg.arg1, arg.arg2, $0))) } + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1, Arg2, Arg3, Arg4) throws -> Type where Tag: Hashable { + return { try self.resolve(request(tag: tag, arg: pack($0, $1, $2, $3))) } + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1, Arg2, Arg3, Arg4) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + return { try self.resolve(request(tag: tag, arg: pack($0, $1, $2, $3))) } + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg: Arg1) -> (Arg2, Arg3, Arg4) throws -> Type where Tag: Hashable { + return { try self.resolve(request(tag: tag, arg: pack(arg, $0, $1, $2))) } + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg: Arg1) -> (Arg2, Arg3, Arg4) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + return { try self.resolve(request(tag: tag, arg: pack(arg, $0, $1, $2))) } + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg: (Arg1, Arg2)) -> (Arg3, Arg4) throws -> Type where Tag: Hashable { + return { try self.resolve(request(tag: tag, arg: pack(arg.0, arg.1, $0, $1))) } + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg: ArgumentBox2) -> (Arg3, Arg4) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + return { try self.resolve(request(tag: tag, arg: pack(arg.arg1, arg.arg2, $0, $1))) } + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg: (Arg1, Arg2, Arg3)) -> (Arg4) throws -> Type where Tag: Hashable { + return { try self.resolve(request(tag: tag, arg: pack(arg.0, arg.1, arg.2, $0))) } + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg: ArgumentBox3) -> (Arg4) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + return { try self.resolve(request(tag: tag, arg: pack(arg.arg1, arg.arg2, arg.arg3, $0))) } + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type where Tag: Hashable { + return { try self.resolve(request(tag: tag, arg: pack($0, $1, $2, $3, $4))) } + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + return { try self.resolve(request(tag: tag, arg: pack($0, $1, $2, $3, $4))) } + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg: Arg1) -> (Arg2, Arg3, Arg4, Arg5) throws -> Type where Tag: Hashable { + return { try self.resolve(request(tag: tag, arg: pack(arg, $0, $1, $2, $3))) } + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg: Arg1) -> (Arg2, Arg3, Arg4, Arg5) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + return { try self.resolve(request(tag: tag, arg: pack(arg, $0, $1, $2, $3))) } + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg: (Arg1, Arg2)) -> (Arg3, Arg4, Arg5) throws -> Type where Tag: Hashable { + return { try self.resolve(request(tag: tag, arg: pack(arg.0, arg.1, $0, $1, $2))) } + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg: ArgumentBox2) -> (Arg3, Arg4, Arg5) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + return { try self.resolve(request(tag: tag, arg: pack(arg.arg1, arg.arg2, $0, $1, $2))) } + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg: (Arg1, Arg2, Arg3)) -> (Arg4, Arg5) throws -> Type where Tag: Hashable { + return { try self.resolve(request(tag: tag, arg: pack(arg.0, arg.1, arg.2, $0, $1))) } + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg: ArgumentBox3) -> (Arg4, Arg5) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + return { try self.resolve(request(tag: tag, arg: pack(arg.arg1, arg.arg2, arg.arg3, $0, $1))) } + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg: (Arg1, Arg2, Arg3, Arg4)) -> (Arg5) throws -> Type where Tag: Hashable { + return { try self.resolve(request(tag: tag, arg: pack(arg.0, arg.1, arg.2, arg.3, $0))) } + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg: ArgumentBox4) -> (Arg5) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + return { try self.resolve(request(tag: tag, arg: pack(arg.arg1, arg.arg2, arg.arg3, arg.arg4, $0))) } } } + +// sourcery:end diff --git a/Sources/Core/Matchable.swift b/Sources/Core/Matchable.swift index 601487e3..b6d07e3f 100644 --- a/Sources/Core/Matchable.swift +++ b/Sources/Core/Matchable.swift @@ -8,61 +8,132 @@ public protocol Matchable { func hash(into hasher: inout Hasher) } -public extension Matchable where Self: Equatable { - func matches(_ other: Any) -> Bool { - self == (other as? Self) - } -} - +// TODO: Can we make ArgumentBox types internal? // swiftlint:disable line_length +// swiftlint:disable large_tuple // sourcery:inline:ArgumentBox -public struct ArgumentBox1: Hashable, Matchable where Arg1: Hashable { +public struct ArgumentBox1: Matchable where Arg1: Hashable { let arg1: Arg1 + + public func matches(_ other: Any) -> Bool { + guard let other = other as? ArgumentBox1 else { return false } + return arg1 == other.arg1 + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(arg1) + } } -public struct ArgumentBox2: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable { +public struct ArgumentBox2: Matchable where Arg1: Hashable, Arg2: Hashable { let arg1: Arg1 let arg2: Arg2 + + public func matches(_ other: Any) -> Bool { + guard let other = other as? ArgumentBox2 else { return false } + return arg1 == other.arg1 && arg2 == other.arg2 + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(arg1) + hasher.combine(arg2) + } } -public struct ArgumentBox3: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { +public struct ArgumentBox3: Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { let arg1: Arg1 let arg2: Arg2 let arg3: Arg3 + + public func matches(_ other: Any) -> Bool { + guard let other = other as? ArgumentBox3 else { return false } + return arg1 == other.arg1 && arg2 == other.arg2 && arg3 == other.arg3 + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(arg1) + hasher.combine(arg2) + hasher.combine(arg3) + } } -public struct ArgumentBox4: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { +public struct ArgumentBox4: Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { let arg1: Arg1 let arg2: Arg2 let arg3: Arg3 let arg4: Arg4 + + public func matches(_ other: Any) -> Bool { + guard let other = other as? ArgumentBox4 else { return false } + return arg1 == other.arg1 && arg2 == other.arg2 && arg3 == other.arg3 && arg4 == other.arg4 + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(arg1) + hasher.combine(arg2) + hasher.combine(arg3) + hasher.combine(arg4) + } } -public struct ArgumentBox5: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { +public struct ArgumentBox5: Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { let arg1: Arg1 let arg2: Arg2 let arg3: Arg3 let arg4: Arg4 let arg5: Arg5 + + public func matches(_ other: Any) -> Bool { + guard let other = other as? ArgumentBox5 else { return false } + return arg1 == other.arg1 && arg2 == other.arg2 && arg3 == other.arg3 && arg4 == other.arg4 && arg5 == other.arg5 + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(arg1) + hasher.combine(arg2) + hasher.combine(arg3) + hasher.combine(arg4) + hasher.combine(arg5) + } +} + +func pack(_ arg1: Arg1) -> Arg1 { + arg1 } -func box(_ arg1: Arg1) -> ArgumentBox1 where Arg1: Hashable { +func pack(_ arg1: Arg1) -> ArgumentBox1 where Arg1: Hashable { ArgumentBox1(arg1: arg1) } -func box(_ arg1: Arg1, _ arg2: Arg2) -> ArgumentBox2 where Arg1: Hashable, Arg2: Hashable { +func pack(_ arg1: Arg1, _ arg2: Arg2) -> (Arg1, Arg2) { + (arg1, arg2) +} + +func pack(_ arg1: Arg1, _ arg2: Arg2) -> ArgumentBox2 where Arg1: Hashable, Arg2: Hashable { ArgumentBox2(arg1: arg1, arg2: arg2) } -func box(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> ArgumentBox3 where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { +func pack(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> (Arg1, Arg2, Arg3) { + (arg1, arg2, arg3) +} + +func pack(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> ArgumentBox3 where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { ArgumentBox3(arg1: arg1, arg2: arg2, arg3: arg3) } -func box(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> ArgumentBox4 where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { +func pack(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> (Arg1, Arg2, Arg3, Arg4) { + (arg1, arg2, arg3, arg4) +} + +func pack(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> ArgumentBox4 where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { ArgumentBox4(arg1: arg1, arg2: arg2, arg3: arg3, arg4: arg4) } -func box(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> ArgumentBox5 where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { +func pack(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> (Arg1, Arg2, Arg3, Arg4, Arg5) { + (arg1, arg2, arg3, arg4, arg5) +} + +func pack(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> ArgumentBox5 where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { ArgumentBox5(arg1: arg1, arg2: arg2, arg3: arg3, arg4: arg4, arg5: arg5) } diff --git a/Templates/ArgumentBox.swifttemplate b/Templates/ArgumentBox.swifttemplate index 40a85402..4405ddb0 100644 --- a/Templates/ArgumentBox.swifttemplate +++ b/Templates/ArgumentBox.swifttemplate @@ -3,9 +3,19 @@ <%_ (1...arg_count).forEach { i in let arg_types = (1...i).map { "Arg\($0)" }.joined(separator: ", ") let arg_hashables = (1...i).map { "Arg\($0): Hashable" }.joined(separator: ", ") + let type_name = "ArgumentBox\(i)<\(arg_types)>" -%> -public struct ArgumentBox<%= i %><<%= arg_types %>>: Hashable, Matchable where <%= arg_hashables %>{ +public struct <%= type_name %>: Matchable where <%= arg_hashables %>{ <%= (1...i).map { "let arg\($0): Arg\($0)" }.joined(separator: "\n ") %> + + public func matches(_ other: Any) -> Bool { + guard let other = other as? <%= type_name %> else { return false } + return <%= (1...i).map { "arg\($0) == other.arg\($0)" }.joined(separator: " && ") %> + } + + public func hash(into hasher: inout Hasher) { + <%= (1...i).map { "hasher.combine(arg\($0))" }.joined(separator: "\n ") %> + } } <%_ } -%> @@ -14,8 +24,13 @@ public struct ArgumentBox<%= i %><<%= arg_types %>>: Hashable, Matchable where < let arg_hashables = (1...i).map { "Arg\($0): Hashable" }.joined(separator: ", ") let arg_params = (1...i).map { "_ arg\($0): Arg\($0)" }.joined(separator: ", ") let arg_call_params = (1...i).map { "arg\($0): arg\($0)" }.joined(separator: ", ") + let tuple_params = (1...i).map { "arg\($0)" }.joined(separator: ", ") -%> -func box<<%= arg_types %>>(<%= arg_params %>) -> ArgumentBox<%= i %><<%= arg_types %>> where <%= arg_hashables %> { +func pack<<%= arg_types %>>(<%= arg_params %>) -> <%= i == 1 ? arg_types : "(\(arg_types))" %> { + <%= i == 1 ? tuple_params : "(\(tuple_params))" %> +} + +func pack<<%= arg_types %>>(<%= arg_params %>) -> ArgumentBox<%= i %><<%= arg_types %>> where <%= arg_hashables %> { ArgumentBox<%= i %>(<%= arg_call_params %>) } diff --git a/Templates/Resolver+Injection.swifttemplate b/Templates/Resolver+Injection.swifttemplate index 066bf149..73683468 100644 --- a/Templates/Resolver+Injection.swifttemplate +++ b/Templates/Resolver+Injection.swifttemplate @@ -1,50 +1,88 @@ -<% let arg_count = 5 %> -// sourcery:inline:ResolverInjectionApi -public extension Resolver { - func instance(of _: Type.Type = Type.self) throws -> Type { - try resolve(request(tag: NoTag(), arg: ())) +<%_ +let maxArgs = 5 + +struct Variation { + let isTagged: Bool + let paramArgs: Int + let factoryArgs: Int + let isMatchable: Bool + + var args: Int { return paramArgs + factoryArgs } + + static let simpleCases = [false, true] + .flatMap { b in [0, 1].map { (b, $0) } } + .flatMap { t in [false, true].map { (t.0, t.1, $0) } } + .filter { $0.1 == 1 || $0.2 } + .map { Variation(isTagged: $0.0, paramArgs: $0.1, factoryArgs: 0, isMatchable: $0.2) } + + static let factoryCases = [false, true] + .flatMap { b in (1...maxArgs).map { (b, $0) } } + .flatMap { t in (0.. 0 ? (1...args).map { "Arg\($0)" }.joined(separator: ", ") : nil + ].compactMap { $0 }.joined(separator: ", ") } + + var params: String {[ + "of _: Type.Type = Type.self", + isTagged ? "tagged tag: Tag" : nil, + paramArgs == 1 ? "arg: Arg1" : nil, + paramArgs > 1 && !isMatchable ? ("arg: (" + (1...paramArgs).map { "Arg\($0)" }.joined(separator: ", ") + ")") : nil, + paramArgs > 1 && isMatchable ? ("arg: ArgumentBox\(paramArgs)<" + (1...paramArgs).map { "Arg\($0)" }.joined(separator: ", ") + ">") : nil + ].compactMap { $0 }.joined(separator: ", ") } + + var factoryInputs: String { + (1...factoryArgs).map { "Arg\($0 + paramArgs)" }.joined(separator: ", ") } - func instance(of _: Type.Type = Type.self, tagged tag: Tag) throws -> Type { - try resolve(request(tag: tag, arg: ())) + var constraints: String {[ + isTagged ? "Tag: Hashable" : nil, + isMatchable && args > 0 ? (1...args).map { "Arg\($0): Hashable" }.joined(separator: ", ") : nil + ].compactMap { $0 }.joined(separator: ", ") } + + var whereClause: String { constraints.isEmpty ? "" : "where " + constraints } + + var requestParams: String { + let paramVars = paramArgs == 1 ? ["arg"] : (0.. - - func instance>(of _: Type.Type = Type.self, arg <%= arg_params %>) throws -> Type { - try resolve(request(tag: NoTag(), arg: (<%= arg_vars %>))) +// sourcery:inline:ResolverInjectionApi +extension Resolver { +<%_ Variation.simpleCases.forEach { v in -%> + func instance<<%= v.genericTypes %>>(<%= v.params %>) throws -> Type <%= v.whereClause %>{ + try resolve(request(<%= v.requestParams %>)) } - func instance>(of _: Type.Type = Type.self, tagged tag: Tag, arg <%= arg_params %>) throws -> Type { - try resolve(request(tag: tag, arg: (<%= arg_vars %>))) - } <%_ } -%> } -public extension Resolver { - func provider(of _: Type.Type = Type.self) -> () throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: ())) } +extension Resolver { +<%_ Variation.simpleCases.forEach { v in -%> + func provider<<%= v.genericTypes %>>(<%= v.params %>) -> () throws -> Type <%= v.whereClause %>{ + return { try self.resolve(request(<%= v.requestParams %>)) } } - func provider(of _: Type.Type = Type.self, tagged tag: Tag) -> () throws -> Type { - return { try self.resolve(request(tag: tag, arg: ())) } - } -<%_ (1...arg_count).forEach { i in - let arg_types = (1...i).map { "Arg\($0)" }.joined(separator: ", ") - let arg_vars = (1...i).map { "arg\($0)" }.joined(separator: ", ") - let arg_params = (1...i).map { "arg\($0): Arg\($0)" }.joined(separator: ", _ ") --%> +<%_ } -%> +} - func provider>(of _: Type.Type = Type.self, arg <%= arg_params %>) -> () throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: (<%= arg_vars %>))) } +extension Resolver { +<%_ Variation.factoryCases.forEach { v in -%> + func factory<<%= v.genericTypes %>>(<%= v.params %>) -> (<%= v.factoryInputs %>) throws -> Type <%= v.whereClause %>{ + return { try self.resolve(request(<%= v.requestParams %>)) } } - func provider>(of _: Type.Type = Type.self, tagged tag: Tag, arg <%= arg_params %>) -> () throws -> Type { - return { try self.resolve(request(tag: tag, arg: (<%= arg_vars %>))) } - } <%_ } -%> } // sourcery:end diff --git a/Tests/3.0 API/SwinjectApiSpec.swift b/Tests/3.0 API/SwinjectApiSpec.swift index baae64f8..c242296a 100644 --- a/Tests/3.0 API/SwinjectApiSpec.swift +++ b/Tests/3.0 API/SwinjectApiSpec.swift @@ -106,7 +106,7 @@ class SwinjectApiSpec: QuickSpec { override func spec() { } expect { try swinject.factory(of: Int.self)(11, 14.0, "17") } == 42 expect { try swinject.factory(of: Int.self, arg: 11)(14.0, "17") } == 42 - expect { try swinject.factory(of: Int.self, args: 11, 14.0)("17") } == 42 + expect { try swinject.factory(of: Int.self, arg: pack(11, 14.0))("17") } == 42 } it("can pass context to the bindings") { // FIXME: compiler segfaults if declaring these providers inside function builder diff --git a/Tests/Unit Specs/BinderEnvironmentSpec.swift b/Tests/Unit Specs/BinderEnvironmentSpec.swift index 55bf1629..40b982fe 100644 --- a/Tests/Unit Specs/BinderEnvironmentSpec.swift +++ b/Tests/Unit Specs/BinderEnvironmentSpec.swift @@ -75,7 +75,7 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { it("calls builder with given argument") { var passedArgument: Int? let maker = factory { (_, arg: Int) in passedArgument = arg } - _ = try? maker.makeInstance(arg: box(42), resolver: DummyResolver()) + _ = try? maker.makeInstance(arg: pack(42), resolver: DummyResolver()) expect(passedArgument) == 42 } it("rethrows error from builder") { @@ -177,7 +177,7 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { it("calls builder with given argument") { var passedArgument: Int? let maker = multiton { (_, arg: Int) in passedArgument = arg } - _ = try? maker.makeInstance(arg: box(42), resolver: DummyResolver()) + _ = try? maker.makeInstance(arg: pack(42), resolver: DummyResolver()) expect(passedArgument) == 42 } it("rethrows error from builder") { diff --git a/Tests/Unit Specs/SwinjectSpec.swift b/Tests/Unit Specs/SwinjectSpec.swift index ac7af64f..4fc4b6cb 100644 --- a/Tests/Unit Specs/SwinjectSpec.swift +++ b/Tests/Unit Specs/SwinjectSpec.swift @@ -208,7 +208,8 @@ class SwinjectSpec: QuickSpec { override func spec() { binding.matchesReturnValue = true binding.instanceArgContextResolverReturnValue = 42 _ = try? swinject.factory(of: Int.self)("arg") - expect(binding.instanceArgContextResolverReceivedArguments?.arg as? ArgumentBox1) == box("arg") + let argument = binding.instanceArgContextResolverReceivedArguments?.arg as? ArgumentBox1 + expect(argument?.arg1) == "arg" } it("matches binding with correct key") { binding.matchesReturnValue = false @@ -233,36 +234,36 @@ class SwinjectSpec: QuickSpec { override func spec() { } it("can curry 2-tuple as 0 / 2 argument") { _ = try? swinject.factory()("arg1", "arg2") as Int - let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? (String, String) - expect(receivedArg?.0) == "arg1" - expect(receivedArg?.1) == "arg2" + let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? ArgumentBox2 + expect(receivedArg?.arg1) == "arg1" + expect(receivedArg?.arg2) == "arg2" } it("can curry 2-tuple as 1 / 1 argument") { _ = try? swinject.factory(arg: "arg1")("arg2") as Int - let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? (String, String) - expect(receivedArg?.0) == "arg1" - expect(receivedArg?.1) == "arg2" + let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? ArgumentBox2 + expect(receivedArg?.arg1) == "arg1" + expect(receivedArg?.arg2) == "arg2" } it("can curry 3-tuple as 0 / 3 argument") { _ = try? swinject.factory()("arg1", 2, "arg3") as Int - let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? (String, Int, String) - expect(receivedArg?.0) == "arg1" - expect(receivedArg?.1) == 2 - expect(receivedArg?.2) == "arg3" + let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? ArgumentBox3 + expect(receivedArg?.arg1) == "arg1" + expect(receivedArg?.arg2) == 2 + expect(receivedArg?.arg3) == "arg3" } it("can curry 3-tuple as 1 / 2 argument") { _ = try? swinject.factory(arg: "arg1")(2, "arg3") as Int - let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? (String, Int, String) - expect(receivedArg?.0) == "arg1" - expect(receivedArg?.1) == 2 - expect(receivedArg?.2) == "arg3" + let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? ArgumentBox3 + expect(receivedArg?.arg1) == "arg1" + expect(receivedArg?.arg2) == 2 + expect(receivedArg?.arg3) == "arg3" } it("can curry 3-tuple as 2 / 1 argument") { - _ = try? swinject.factory(args: "arg1", 2)("arg3") as Int - let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? (String, Int, String) - expect(receivedArg?.0) == "arg1" - expect(receivedArg?.1) == 2 - expect(receivedArg?.2) == "arg3" + _ = try? swinject.factory(arg: pack("arg1", 2))("arg3") as Int + let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? ArgumentBox3 + expect(receivedArg?.arg1) == "arg1" + expect(receivedArg?.arg2) == 2 + expect(receivedArg?.arg3) == "arg3" } } } From 3f3161acb0f988147bfff84430fabc3e96794484 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sat, 27 Jul 2019 07:27:32 +0200 Subject: [PATCH 141/239] Refactor injection api --- Sources/3.0 API/BinderEnvironment.swift | 4 +- Sources/3.0 API/Resolver+Injection.swift | 405 ++++++++++++------ Sources/Core/Matchable.swift | 105 ++--- Swinject.xcodeproj/project.pbxproj | 6 +- ...ttemplate => MatchableBoxes.swifttemplate} | 21 +- Templates/Resolver+Injection.swifttemplate | 34 +- Tests/3.0 API/SwinjectApiSpec.swift | 2 +- Tests/Support/GeneratedMocks.swift | 4 +- Tests/Unit Specs/BinderEnvironmentSpec.swift | 4 +- Tests/Unit Specs/SwinjectSpec.swift | 14 +- 10 files changed, 335 insertions(+), 264 deletions(-) rename Templates/{ArgumentBox.swifttemplate => MatchableBoxes.swifttemplate} (54%) diff --git a/Sources/3.0 API/BinderEnvironment.swift b/Sources/3.0 API/BinderEnvironment.swift index fef348fe..98941e1c 100644 --- a/Sources/3.0 API/BinderEnvironment.swift +++ b/Sources/3.0 API/BinderEnvironment.swift @@ -97,7 +97,7 @@ public func factory(_ builder: @escaping (Resolver, Arg1) throws -> .init { try builder($0, $2) } } -public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> SimpleBinding.Builder> { +public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> SimpleBinding.Builder> { .init { try builder($0, $2.arg1) } } @@ -129,7 +129,7 @@ public func multiton(ref: @escaping ReferenceMaker = strongRef .init(.root, ref) { try builder($0, $2) } } -public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1) throws -> Type) -> ScopedBinding.Builder> { +public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1) throws -> Type) -> ScopedBinding.Builder> { .init(.root, ref) { try builder($0, $2.arg1) } } diff --git a/Sources/3.0 API/Resolver+Injection.swift b/Sources/3.0 API/Resolver+Injection.swift index bd7ca7a4..370f60d1 100644 --- a/Sources/3.0 API/Resolver+Injection.swift +++ b/Sources/3.0 API/Resolver+Injection.swift @@ -3,299 +3,428 @@ // // swiftlint:disable line_length -// swiftlint:disable large_tuple +// swiftlint:disable function_parameter_count +// swiftlint:disable file_length // sourcery:inline:ResolverInjectionApi extension Resolver { func instance(of _: Type.Type = Type.self) throws -> Type { try resolve(request(tag: NoTag(), arg: ())) } - func instance(of _: Type.Type = Type.self, arg: Arg1) throws -> Type { - try resolve(request(tag: NoTag(), arg: pack(arg))) + func instance(of _: Type.Type = Type.self, tagged tag: Tag) throws -> Type where Tag: Hashable { + try resolve(request(tag: tag, arg: ())) } - func instance(of _: Type.Type = Type.self, arg: Arg1) throws -> Type where Arg1: Hashable { - try resolve(request(tag: NoTag(), arg: pack(arg))) + func instance(of _: Type.Type = Type.self, arg arg1: Arg1) throws -> Type { + try resolve(request(tag: NoTag(), arg: box(arg1))) } - func instance(of _: Type.Type = Type.self, tagged tag: Tag) throws -> Type where Tag: Hashable { - try resolve(request(tag: tag, arg: ())) + func instance(of _: Type.Type = Type.self, arg arg1: Arg1) throws -> Type where Arg1: Hashable { + try resolve(request(tag: NoTag(), arg: box(arg1))) } - func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg: Arg1) throws -> Type where Tag: Hashable { - try resolve(request(tag: tag, arg: pack(arg))) + func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) throws -> Type where Tag: Hashable { + try resolve(request(tag: tag, arg: box(arg1))) } - func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg: Arg1) throws -> Type where Tag: Hashable, Arg1: Hashable { - try resolve(request(tag: tag, arg: pack(arg))) + func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) throws -> Type where Tag: Hashable, Arg1: Hashable { + try resolve(request(tag: tag, arg: box(arg1))) } -} -extension Resolver { - func provider(of _: Type.Type = Type.self) -> () throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: ())) } + func instance(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2) throws -> Type { + try resolve(request(tag: NoTag(), arg: box(arg1, arg2))) } - func provider(of _: Type.Type = Type.self, arg: Arg1) -> () throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: pack(arg))) } + func instance(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2) throws -> Type where Arg1: Hashable, Arg2: Hashable { + try resolve(request(tag: NoTag(), arg: box(arg1, arg2))) } - func provider(of _: Type.Type = Type.self, arg: Arg1) -> () throws -> Type where Arg1: Hashable { - return { try self.resolve(request(tag: NoTag(), arg: pack(arg))) } + func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2) throws -> Type where Tag: Hashable { + try resolve(request(tag: tag, arg: box(arg1, arg2))) } - func provider(of _: Type.Type = Type.self, tagged tag: Tag) -> () throws -> Type where Tag: Hashable { - return { try self.resolve(request(tag: tag, arg: ())) } + func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable { + try resolve(request(tag: tag, arg: box(arg1, arg2))) } - func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg: Arg1) -> () throws -> Type where Tag: Hashable { - return { try self.resolve(request(tag: tag, arg: pack(arg))) } + func instance(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) throws -> Type { + try resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3))) } - func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg: Arg1) -> () throws -> Type where Tag: Hashable, Arg1: Hashable { - return { try self.resolve(request(tag: tag, arg: pack(arg))) } + func instance(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + try resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3))) } -} -extension Resolver { - func factory(of _: Type.Type = Type.self) -> (Arg1) throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: pack($0))) } + func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) throws -> Type where Tag: Hashable { + try resolve(request(tag: tag, arg: box(arg1, arg2, arg3))) } - func factory(of _: Type.Type = Type.self) -> (Arg1) throws -> Type where Arg1: Hashable { - return { try self.resolve(request(tag: NoTag(), arg: pack($0))) } + func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + try resolve(request(tag: tag, arg: box(arg1, arg2, arg3))) } - func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2) throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: pack($0, $1))) } + func instance(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) throws -> Type { + try resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3, arg4))) } - func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2) throws -> Type where Arg1: Hashable, Arg2: Hashable { - return { try self.resolve(request(tag: NoTag(), arg: pack($0, $1))) } + func instance(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + try resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3, arg4))) } - func factory(of _: Type.Type = Type.self, arg: Arg1) -> (Arg2) throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: pack(arg, $0))) } + func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) throws -> Type where Tag: Hashable { + try resolve(request(tag: tag, arg: box(arg1, arg2, arg3, arg4))) } - func factory(of _: Type.Type = Type.self, arg: Arg1) -> (Arg2) throws -> Type where Arg1: Hashable, Arg2: Hashable { - return { try self.resolve(request(tag: NoTag(), arg: pack(arg, $0))) } + func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + try resolve(request(tag: tag, arg: box(arg1, arg2, arg3, arg4))) } - func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2, Arg3) throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: pack($0, $1, $2))) } + func instance(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) throws -> Type { + try resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3, arg4, arg5))) } - func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2, Arg3) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - return { try self.resolve(request(tag: NoTag(), arg: pack($0, $1, $2))) } + func instance(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + try resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3, arg4, arg5))) } - func factory(of _: Type.Type = Type.self, arg: Arg1) -> (Arg2, Arg3) throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: pack(arg, $0, $1))) } + func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) throws -> Type where Tag: Hashable { + try resolve(request(tag: tag, arg: box(arg1, arg2, arg3, arg4, arg5))) } - func factory(of _: Type.Type = Type.self, arg: Arg1) -> (Arg2, Arg3) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - return { try self.resolve(request(tag: NoTag(), arg: pack(arg, $0, $1))) } + func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + try resolve(request(tag: tag, arg: box(arg1, arg2, arg3, arg4, arg5))) } +} - func factory(of _: Type.Type = Type.self, arg: (Arg1, Arg2)) -> (Arg3) throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: pack(arg.0, arg.1, $0))) } +extension Resolver { + func provider(of _: Type.Type = Type.self) -> () throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: ())) } } - func factory(of _: Type.Type = Type.self, arg: ArgumentBox2) -> (Arg3) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - return { try self.resolve(request(tag: NoTag(), arg: pack(arg.arg1, arg.arg2, $0))) } + func provider(of _: Type.Type = Type.self, tagged tag: Tag) -> () throws -> Type where Tag: Hashable { + return { try self.resolve(request(tag: tag, arg: ())) } } - func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2, Arg3, Arg4) throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: pack($0, $1, $2, $3))) } + func provider(of _: Type.Type = Type.self, arg arg1: Arg1) -> () throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: box(arg1))) } } - func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2, Arg3, Arg4) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return { try self.resolve(request(tag: NoTag(), arg: pack($0, $1, $2, $3))) } + func provider(of _: Type.Type = Type.self, arg arg1: Arg1) -> () throws -> Type where Arg1: Hashable { + return { try self.resolve(request(tag: NoTag(), arg: box(arg1))) } } - func factory(of _: Type.Type = Type.self, arg: Arg1) -> (Arg2, Arg3, Arg4) throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: pack(arg, $0, $1, $2))) } + func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) -> () throws -> Type where Tag: Hashable { + return { try self.resolve(request(tag: tag, arg: box(arg1))) } } - func factory(of _: Type.Type = Type.self, arg: Arg1) -> (Arg2, Arg3, Arg4) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return { try self.resolve(request(tag: NoTag(), arg: pack(arg, $0, $1, $2))) } + func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) -> () throws -> Type where Tag: Hashable, Arg1: Hashable { + return { try self.resolve(request(tag: tag, arg: box(arg1))) } } - func factory(of _: Type.Type = Type.self, arg: (Arg1, Arg2)) -> (Arg3, Arg4) throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: pack(arg.0, arg.1, $0, $1))) } + func provider(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2) -> () throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: box(arg1, arg2))) } } - func factory(of _: Type.Type = Type.self, arg: ArgumentBox2) -> (Arg3, Arg4) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return { try self.resolve(request(tag: NoTag(), arg: pack(arg.arg1, arg.arg2, $0, $1))) } + func provider(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2) -> () throws -> Type where Arg1: Hashable, Arg2: Hashable { + return { try self.resolve(request(tag: NoTag(), arg: box(arg1, arg2))) } } - func factory(of _: Type.Type = Type.self, arg: (Arg1, Arg2, Arg3)) -> (Arg4) throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: pack(arg.0, arg.1, arg.2, $0))) } + func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2) -> () throws -> Type where Tag: Hashable { + return { try self.resolve(request(tag: tag, arg: box(arg1, arg2))) } } - func factory(of _: Type.Type = Type.self, arg: ArgumentBox3) -> (Arg4) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return { try self.resolve(request(tag: NoTag(), arg: pack(arg.arg1, arg.arg2, arg.arg3, $0))) } + func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2) -> () throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable { + return { try self.resolve(request(tag: tag, arg: box(arg1, arg2))) } } - func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: pack($0, $1, $2, $3, $4))) } + func provider(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> () throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3))) } } - func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return { try self.resolve(request(tag: NoTag(), arg: pack($0, $1, $2, $3, $4))) } + func provider(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> () throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + return { try self.resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3))) } + } + + func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> () throws -> Type where Tag: Hashable { + return { try self.resolve(request(tag: tag, arg: box(arg1, arg2, arg3))) } } - func factory(of _: Type.Type = Type.self, arg: Arg1) -> (Arg2, Arg3, Arg4, Arg5) throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: pack(arg, $0, $1, $2, $3))) } + func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> () throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + return { try self.resolve(request(tag: tag, arg: box(arg1, arg2, arg3))) } } - func factory(of _: Type.Type = Type.self, arg: Arg1) -> (Arg2, Arg3, Arg4, Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return { try self.resolve(request(tag: NoTag(), arg: pack(arg, $0, $1, $2, $3))) } + func provider(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> () throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3, arg4))) } } - func factory(of _: Type.Type = Type.self, arg: (Arg1, Arg2)) -> (Arg3, Arg4, Arg5) throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: pack(arg.0, arg.1, $0, $1, $2))) } + func provider(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> () throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + return { try self.resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3, arg4))) } } - func factory(of _: Type.Type = Type.self, arg: ArgumentBox2) -> (Arg3, Arg4, Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return { try self.resolve(request(tag: NoTag(), arg: pack(arg.arg1, arg.arg2, $0, $1, $2))) } + func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> () throws -> Type where Tag: Hashable { + return { try self.resolve(request(tag: tag, arg: box(arg1, arg2, arg3, arg4))) } } - func factory(of _: Type.Type = Type.self, arg: (Arg1, Arg2, Arg3)) -> (Arg4, Arg5) throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: pack(arg.0, arg.1, arg.2, $0, $1))) } + func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> () throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + return { try self.resolve(request(tag: tag, arg: box(arg1, arg2, arg3, arg4))) } } - func factory(of _: Type.Type = Type.self, arg: ArgumentBox3) -> (Arg4, Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return { try self.resolve(request(tag: NoTag(), arg: pack(arg.arg1, arg.arg2, arg.arg3, $0, $1))) } + func provider(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> () throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3, arg4, arg5))) } } - func factory(of _: Type.Type = Type.self, arg: (Arg1, Arg2, Arg3, Arg4)) -> (Arg5) throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: pack(arg.0, arg.1, arg.2, arg.3, $0))) } + func provider(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> () throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + return { try self.resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3, arg4, arg5))) } } - func factory(of _: Type.Type = Type.self, arg: ArgumentBox4) -> (Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return { try self.resolve(request(tag: NoTag(), arg: pack(arg.arg1, arg.arg2, arg.arg3, arg.arg4, $0))) } + func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> () throws -> Type where Tag: Hashable { + return { try self.resolve(request(tag: tag, arg: box(arg1, arg2, arg3, arg4, arg5))) } + } + + func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> () throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + return { try self.resolve(request(tag: tag, arg: box(arg1, arg2, arg3, arg4, arg5))) } + } +} + +extension Resolver { + func factory(of _: Type.Type = Type.self) -> (Arg1) throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: box($0))) } + } + + func factory(of _: Type.Type = Type.self) -> (Arg1) throws -> Type where Arg1: Hashable { + return { try self.resolve(request(tag: NoTag(), arg: box($0))) } } func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1) throws -> Type where Tag: Hashable { - return { try self.resolve(request(tag: tag, arg: pack($0))) } + return { try self.resolve(request(tag: tag, arg: box($0))) } } func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1) throws -> Type where Tag: Hashable, Arg1: Hashable { - return { try self.resolve(request(tag: tag, arg: pack($0))) } + return { try self.resolve(request(tag: tag, arg: box($0))) } + } + + func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2) throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: box($0, $1))) } + } + + func factory(of _: Type.Type = Type.self, arg arg1: Arg1) -> (Arg2) throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: box(arg1, $0))) } + } + + func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2) throws -> Type where Arg1: Hashable, Arg2: Hashable { + return { try self.resolve(request(tag: NoTag(), arg: box($0, $1))) } + } + + func factory(of _: Type.Type = Type.self, arg arg1: Arg1) -> (Arg2) throws -> Type where Arg1: Hashable, Arg2: Hashable { + return { try self.resolve(request(tag: NoTag(), arg: box(arg1, $0))) } } func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1, Arg2) throws -> Type where Tag: Hashable { - return { try self.resolve(request(tag: tag, arg: pack($0, $1))) } + return { try self.resolve(request(tag: tag, arg: box($0, $1))) } + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) -> (Arg2) throws -> Type where Tag: Hashable { + return { try self.resolve(request(tag: tag, arg: box(arg1, $0))) } } func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1, Arg2) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable { - return { try self.resolve(request(tag: tag, arg: pack($0, $1))) } + return { try self.resolve(request(tag: tag, arg: box($0, $1))) } + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) -> (Arg2) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable { + return { try self.resolve(request(tag: tag, arg: box(arg1, $0))) } + } + + func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2, Arg3) throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: box($0, $1, $2))) } + } + + func factory(of _: Type.Type = Type.self, arg arg1: Arg1) -> (Arg2, Arg3) throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: box(arg1, $0, $1))) } + } + + func factory(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3) throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: box(arg1, arg2, $0))) } + } + + func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2, Arg3) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + return { try self.resolve(request(tag: NoTag(), arg: box($0, $1, $2))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg: Arg1) -> (Arg2) throws -> Type where Tag: Hashable { - return { try self.resolve(request(tag: tag, arg: pack(arg, $0))) } + func factory(of _: Type.Type = Type.self, arg arg1: Arg1) -> (Arg2, Arg3) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + return { try self.resolve(request(tag: NoTag(), arg: box(arg1, $0, $1))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg: Arg1) -> (Arg2) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable { - return { try self.resolve(request(tag: tag, arg: pack(arg, $0))) } + func factory(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + return { try self.resolve(request(tag: NoTag(), arg: box(arg1, arg2, $0))) } } func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1, Arg2, Arg3) throws -> Type where Tag: Hashable { - return { try self.resolve(request(tag: tag, arg: pack($0, $1, $2))) } + return { try self.resolve(request(tag: tag, arg: box($0, $1, $2))) } + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) -> (Arg2, Arg3) throws -> Type where Tag: Hashable { + return { try self.resolve(request(tag: tag, arg: box(arg1, $0, $1))) } + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3) throws -> Type where Tag: Hashable { + return { try self.resolve(request(tag: tag, arg: box(arg1, arg2, $0))) } } func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1, Arg2, Arg3) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - return { try self.resolve(request(tag: tag, arg: pack($0, $1, $2))) } + return { try self.resolve(request(tag: tag, arg: box($0, $1, $2))) } + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) -> (Arg2, Arg3) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + return { try self.resolve(request(tag: tag, arg: box(arg1, $0, $1))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg: Arg1) -> (Arg2, Arg3) throws -> Type where Tag: Hashable { - return { try self.resolve(request(tag: tag, arg: pack(arg, $0, $1))) } + func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + return { try self.resolve(request(tag: tag, arg: box(arg1, arg2, $0))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg: Arg1) -> (Arg2, Arg3) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - return { try self.resolve(request(tag: tag, arg: pack(arg, $0, $1))) } + func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2, Arg3, Arg4) throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: box($0, $1, $2, $3))) } + } + + func factory(of _: Type.Type = Type.self, arg arg1: Arg1) -> (Arg2, Arg3, Arg4) throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: box(arg1, $0, $1, $2))) } + } + + func factory(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3, Arg4) throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: box(arg1, arg2, $0, $1))) } + } + + func factory(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> (Arg4) throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3, $0))) } + } + + func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2, Arg3, Arg4) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + return { try self.resolve(request(tag: NoTag(), arg: box($0, $1, $2, $3))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg: (Arg1, Arg2)) -> (Arg3) throws -> Type where Tag: Hashable { - return { try self.resolve(request(tag: tag, arg: pack(arg.0, arg.1, $0))) } + func factory(of _: Type.Type = Type.self, arg arg1: Arg1) -> (Arg2, Arg3, Arg4) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + return { try self.resolve(request(tag: NoTag(), arg: box(arg1, $0, $1, $2))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg: ArgumentBox2) -> (Arg3) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - return { try self.resolve(request(tag: tag, arg: pack(arg.arg1, arg.arg2, $0))) } + func factory(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3, Arg4) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + return { try self.resolve(request(tag: NoTag(), arg: box(arg1, arg2, $0, $1))) } + } + + func factory(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> (Arg4) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + return { try self.resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3, $0))) } } func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1, Arg2, Arg3, Arg4) throws -> Type where Tag: Hashable { - return { try self.resolve(request(tag: tag, arg: pack($0, $1, $2, $3))) } + return { try self.resolve(request(tag: tag, arg: box($0, $1, $2, $3))) } + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) -> (Arg2, Arg3, Arg4) throws -> Type where Tag: Hashable { + return { try self.resolve(request(tag: tag, arg: box(arg1, $0, $1, $2))) } + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3, Arg4) throws -> Type where Tag: Hashable { + return { try self.resolve(request(tag: tag, arg: box(arg1, arg2, $0, $1))) } + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> (Arg4) throws -> Type where Tag: Hashable { + return { try self.resolve(request(tag: tag, arg: box(arg1, arg2, arg3, $0))) } } func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1, Arg2, Arg3, Arg4) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return { try self.resolve(request(tag: tag, arg: pack($0, $1, $2, $3))) } + return { try self.resolve(request(tag: tag, arg: box($0, $1, $2, $3))) } + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) -> (Arg2, Arg3, Arg4) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + return { try self.resolve(request(tag: tag, arg: box(arg1, $0, $1, $2))) } + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3, Arg4) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + return { try self.resolve(request(tag: tag, arg: box(arg1, arg2, $0, $1))) } + } + + func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> (Arg4) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + return { try self.resolve(request(tag: tag, arg: box(arg1, arg2, arg3, $0))) } + } + + func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: box($0, $1, $2, $3, $4))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg: Arg1) -> (Arg2, Arg3, Arg4) throws -> Type where Tag: Hashable { - return { try self.resolve(request(tag: tag, arg: pack(arg, $0, $1, $2))) } + func factory(of _: Type.Type = Type.self, arg arg1: Arg1) -> (Arg2, Arg3, Arg4, Arg5) throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: box(arg1, $0, $1, $2, $3))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg: Arg1) -> (Arg2, Arg3, Arg4) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return { try self.resolve(request(tag: tag, arg: pack(arg, $0, $1, $2))) } + func factory(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3, Arg4, Arg5) throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: box(arg1, arg2, $0, $1, $2))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg: (Arg1, Arg2)) -> (Arg3, Arg4) throws -> Type where Tag: Hashable { - return { try self.resolve(request(tag: tag, arg: pack(arg.0, arg.1, $0, $1))) } + func factory(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> (Arg4, Arg5) throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3, $0, $1))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg: ArgumentBox2) -> (Arg3, Arg4) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return { try self.resolve(request(tag: tag, arg: pack(arg.arg1, arg.arg2, $0, $1))) } + func factory(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> (Arg5) throws -> Type { + return { try self.resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3, arg4, $0))) } + } + + func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + return { try self.resolve(request(tag: NoTag(), arg: box($0, $1, $2, $3, $4))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg: (Arg1, Arg2, Arg3)) -> (Arg4) throws -> Type where Tag: Hashable { - return { try self.resolve(request(tag: tag, arg: pack(arg.0, arg.1, arg.2, $0))) } + func factory(of _: Type.Type = Type.self, arg arg1: Arg1) -> (Arg2, Arg3, Arg4, Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + return { try self.resolve(request(tag: NoTag(), arg: box(arg1, $0, $1, $2, $3))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg: ArgumentBox3) -> (Arg4) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return { try self.resolve(request(tag: tag, arg: pack(arg.arg1, arg.arg2, arg.arg3, $0))) } + func factory(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3, Arg4, Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + return { try self.resolve(request(tag: NoTag(), arg: box(arg1, arg2, $0, $1, $2))) } + } + + func factory(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> (Arg4, Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + return { try self.resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3, $0, $1))) } + } + + func factory(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> (Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + return { try self.resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3, arg4, $0))) } } func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type where Tag: Hashable { - return { try self.resolve(request(tag: tag, arg: pack($0, $1, $2, $3, $4))) } + return { try self.resolve(request(tag: tag, arg: box($0, $1, $2, $3, $4))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return { try self.resolve(request(tag: tag, arg: pack($0, $1, $2, $3, $4))) } + func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) -> (Arg2, Arg3, Arg4, Arg5) throws -> Type where Tag: Hashable { + return { try self.resolve(request(tag: tag, arg: box(arg1, $0, $1, $2, $3))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg: Arg1) -> (Arg2, Arg3, Arg4, Arg5) throws -> Type where Tag: Hashable { - return { try self.resolve(request(tag: tag, arg: pack(arg, $0, $1, $2, $3))) } + func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3, Arg4, Arg5) throws -> Type where Tag: Hashable { + return { try self.resolve(request(tag: tag, arg: box(arg1, arg2, $0, $1, $2))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg: Arg1) -> (Arg2, Arg3, Arg4, Arg5) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return { try self.resolve(request(tag: tag, arg: pack(arg, $0, $1, $2, $3))) } + func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> (Arg4, Arg5) throws -> Type where Tag: Hashable { + return { try self.resolve(request(tag: tag, arg: box(arg1, arg2, arg3, $0, $1))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg: (Arg1, Arg2)) -> (Arg3, Arg4, Arg5) throws -> Type where Tag: Hashable { - return { try self.resolve(request(tag: tag, arg: pack(arg.0, arg.1, $0, $1, $2))) } + func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> (Arg5) throws -> Type where Tag: Hashable { + return { try self.resolve(request(tag: tag, arg: box(arg1, arg2, arg3, arg4, $0))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg: ArgumentBox2) -> (Arg3, Arg4, Arg5) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return { try self.resolve(request(tag: tag, arg: pack(arg.arg1, arg.arg2, $0, $1, $2))) } + func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + return { try self.resolve(request(tag: tag, arg: box($0, $1, $2, $3, $4))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg: (Arg1, Arg2, Arg3)) -> (Arg4, Arg5) throws -> Type where Tag: Hashable { - return { try self.resolve(request(tag: tag, arg: pack(arg.0, arg.1, arg.2, $0, $1))) } + func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) -> (Arg2, Arg3, Arg4, Arg5) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + return { try self.resolve(request(tag: tag, arg: box(arg1, $0, $1, $2, $3))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg: ArgumentBox3) -> (Arg4, Arg5) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return { try self.resolve(request(tag: tag, arg: pack(arg.arg1, arg.arg2, arg.arg3, $0, $1))) } + func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3, Arg4, Arg5) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + return { try self.resolve(request(tag: tag, arg: box(arg1, arg2, $0, $1, $2))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg: (Arg1, Arg2, Arg3, Arg4)) -> (Arg5) throws -> Type where Tag: Hashable { - return { try self.resolve(request(tag: tag, arg: pack(arg.0, arg.1, arg.2, arg.3, $0))) } + func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> (Arg4, Arg5) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + return { try self.resolve(request(tag: tag, arg: box(arg1, arg2, arg3, $0, $1))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg: ArgumentBox4) -> (Arg5) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return { try self.resolve(request(tag: tag, arg: pack(arg.arg1, arg.arg2, arg.arg3, arg.arg4, $0))) } + func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> (Arg5) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + return { try self.resolve(request(tag: tag, arg: box(arg1, arg2, arg3, arg4, $0))) } } } diff --git a/Sources/Core/Matchable.swift b/Sources/Core/Matchable.swift index b6d07e3f..d29f395e 100644 --- a/Sources/Core/Matchable.swift +++ b/Sources/Core/Matchable.swift @@ -8,133 +8,84 @@ public protocol Matchable { func hash(into hasher: inout Hasher) } -// TODO: Can we make ArgumentBox types internal? +public extension Matchable where Self: Equatable { + func matches(_ other: Any) -> Bool { + self == (other as? Self) + } +} + +// TODO: Can we make MatchableBox types internal? // swiftlint:disable line_length // swiftlint:disable large_tuple -// sourcery:inline:ArgumentBox -public struct ArgumentBox1: Matchable where Arg1: Hashable { +// sourcery:inline:MatchableBoxes +public struct MatchableBox1: Hashable, Matchable where Arg1: Hashable { let arg1: Arg1 - - public func matches(_ other: Any) -> Bool { - guard let other = other as? ArgumentBox1 else { return false } - return arg1 == other.arg1 - } - - public func hash(into hasher: inout Hasher) { - hasher.combine(arg1) - } } -public struct ArgumentBox2: Matchable where Arg1: Hashable, Arg2: Hashable { +public struct MatchableBox2: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable { let arg1: Arg1 let arg2: Arg2 - - public func matches(_ other: Any) -> Bool { - guard let other = other as? ArgumentBox2 else { return false } - return arg1 == other.arg1 && arg2 == other.arg2 - } - - public func hash(into hasher: inout Hasher) { - hasher.combine(arg1) - hasher.combine(arg2) - } } -public struct ArgumentBox3: Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { +public struct MatchableBox3: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { let arg1: Arg1 let arg2: Arg2 let arg3: Arg3 - - public func matches(_ other: Any) -> Bool { - guard let other = other as? ArgumentBox3 else { return false } - return arg1 == other.arg1 && arg2 == other.arg2 && arg3 == other.arg3 - } - - public func hash(into hasher: inout Hasher) { - hasher.combine(arg1) - hasher.combine(arg2) - hasher.combine(arg3) - } } -public struct ArgumentBox4: Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { +public struct MatchableBox4: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { let arg1: Arg1 let arg2: Arg2 let arg3: Arg3 let arg4: Arg4 - - public func matches(_ other: Any) -> Bool { - guard let other = other as? ArgumentBox4 else { return false } - return arg1 == other.arg1 && arg2 == other.arg2 && arg3 == other.arg3 && arg4 == other.arg4 - } - - public func hash(into hasher: inout Hasher) { - hasher.combine(arg1) - hasher.combine(arg2) - hasher.combine(arg3) - hasher.combine(arg4) - } } -public struct ArgumentBox5: Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { +public struct MatchableBox5: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { let arg1: Arg1 let arg2: Arg2 let arg3: Arg3 let arg4: Arg4 let arg5: Arg5 - - public func matches(_ other: Any) -> Bool { - guard let other = other as? ArgumentBox5 else { return false } - return arg1 == other.arg1 && arg2 == other.arg2 && arg3 == other.arg3 && arg4 == other.arg4 && arg5 == other.arg5 - } - - public func hash(into hasher: inout Hasher) { - hasher.combine(arg1) - hasher.combine(arg2) - hasher.combine(arg3) - hasher.combine(arg4) - hasher.combine(arg5) - } } -func pack(_ arg1: Arg1) -> Arg1 { +func box(_ arg1: Arg1) -> Arg1 { arg1 } -func pack(_ arg1: Arg1) -> ArgumentBox1 where Arg1: Hashable { - ArgumentBox1(arg1: arg1) +func box(_ arg1: Arg1) -> MatchableBox1 where Arg1: Hashable { + MatchableBox1(arg1: arg1) } -func pack(_ arg1: Arg1, _ arg2: Arg2) -> (Arg1, Arg2) { +func box(_ arg1: Arg1, _ arg2: Arg2) -> (Arg1, Arg2) { (arg1, arg2) } -func pack(_ arg1: Arg1, _ arg2: Arg2) -> ArgumentBox2 where Arg1: Hashable, Arg2: Hashable { - ArgumentBox2(arg1: arg1, arg2: arg2) +func box(_ arg1: Arg1, _ arg2: Arg2) -> MatchableBox2 where Arg1: Hashable, Arg2: Hashable { + MatchableBox2(arg1: arg1, arg2: arg2) } -func pack(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> (Arg1, Arg2, Arg3) { +func box(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> (Arg1, Arg2, Arg3) { (arg1, arg2, arg3) } -func pack(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> ArgumentBox3 where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - ArgumentBox3(arg1: arg1, arg2: arg2, arg3: arg3) +func box(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> MatchableBox3 where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + MatchableBox3(arg1: arg1, arg2: arg2, arg3: arg3) } -func pack(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> (Arg1, Arg2, Arg3, Arg4) { +func box(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> (Arg1, Arg2, Arg3, Arg4) { (arg1, arg2, arg3, arg4) } -func pack(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> ArgumentBox4 where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - ArgumentBox4(arg1: arg1, arg2: arg2, arg3: arg3, arg4: arg4) +func box(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> MatchableBox4 where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + MatchableBox4(arg1: arg1, arg2: arg2, arg3: arg3, arg4: arg4) } -func pack(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> (Arg1, Arg2, Arg3, Arg4, Arg5) { +func box(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> (Arg1, Arg2, Arg3, Arg4, Arg5) { (arg1, arg2, arg3, arg4, arg5) } -func pack(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> ArgumentBox5 where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - ArgumentBox5(arg1: arg1, arg2: arg2, arg3: arg3, arg4: arg4, arg5: arg5) +func box(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> MatchableBox5 where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + MatchableBox5(arg1: arg1, arg2: arg2, arg3: arg3, arg4: arg4, arg5: arg5) } // sourcery:end diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index e3568461..8ced92ce 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -498,7 +498,8 @@ CADDB3E9E363310028AA5920 /* InstanceMaker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceMaker.swift; sourceTree = ""; }; CC85CB215058F95C0BC190B1 /* Bridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bridge.swift; sourceTree = ""; }; CDA78290D6D60BD0B808571F /* Container+Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Logging.swift"; sourceTree = ""; }; - CDCF3FCB22EB8F960025E2BD /* ArgumentBox.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = ArgumentBox.swifttemplate; sourceTree = ""; }; + CDCF3FCB22EB8F960025E2BD /* MatchableBoxes.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = MatchableBoxes.swifttemplate; sourceTree = ""; }; + CDCF3FCC22EC16430025E2BD /* BinderEnvironment.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = BinderEnvironment.swifttemplate; sourceTree = ""; }; CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRequest.swift; sourceTree = ""; }; E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; @@ -559,9 +560,10 @@ isa = PBXGroup; children = ( 4286F98133270A36F19E5CD0 /* AutoMockable.stencil */, - CDCF3FCB22EB8F960025E2BD /* ArgumentBox.swifttemplate */, + CDCF3FCB22EB8F960025E2BD /* MatchableBoxes.swifttemplate */, CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */, 01DEC4D20CE554C9DFBD0A8D /* Resolver+Injection.swifttemplate */, + CDCF3FCC22EC16430025E2BD /* BinderEnvironment.swifttemplate */, FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */, BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */, ); diff --git a/Templates/ArgumentBox.swifttemplate b/Templates/MatchableBoxes.swifttemplate similarity index 54% rename from Templates/ArgumentBox.swifttemplate rename to Templates/MatchableBoxes.swifttemplate index 4405ddb0..72f93225 100644 --- a/Templates/ArgumentBox.swifttemplate +++ b/Templates/MatchableBoxes.swifttemplate @@ -1,21 +1,12 @@ <% let arg_count = 5 %> -// sourcery:inline:ArgumentBox +// sourcery:inline:MatchableBoxes <%_ (1...arg_count).forEach { i in let arg_types = (1...i).map { "Arg\($0)" }.joined(separator: ", ") let arg_hashables = (1...i).map { "Arg\($0): Hashable" }.joined(separator: ", ") - let type_name = "ArgumentBox\(i)<\(arg_types)>" + let type_name = "MatchableBox\(i)<\(arg_types)>" -%> -public struct <%= type_name %>: Matchable where <%= arg_hashables %>{ +public struct <%= type_name %>: Hashable, Matchable where <%= arg_hashables %>{ <%= (1...i).map { "let arg\($0): Arg\($0)" }.joined(separator: "\n ") %> - - public func matches(_ other: Any) -> Bool { - guard let other = other as? <%= type_name %> else { return false } - return <%= (1...i).map { "arg\($0) == other.arg\($0)" }.joined(separator: " && ") %> - } - - public func hash(into hasher: inout Hasher) { - <%= (1...i).map { "hasher.combine(arg\($0))" }.joined(separator: "\n ") %> - } } <%_ } -%> @@ -26,12 +17,12 @@ public struct <%= type_name %>: Matchable where <%= arg_hashables %>{ let arg_call_params = (1...i).map { "arg\($0): arg\($0)" }.joined(separator: ", ") let tuple_params = (1...i).map { "arg\($0)" }.joined(separator: ", ") -%> -func pack<<%= arg_types %>>(<%= arg_params %>) -> <%= i == 1 ? arg_types : "(\(arg_types))" %> { +func box<<%= arg_types %>>(<%= arg_params %>) -> <%= i == 1 ? arg_types : "(\(arg_types))" %> { <%= i == 1 ? tuple_params : "(\(tuple_params))" %> } -func pack<<%= arg_types %>>(<%= arg_params %>) -> ArgumentBox<%= i %><<%= arg_types %>> where <%= arg_hashables %> { - ArgumentBox<%= i %>(<%= arg_call_params %>) +func box<<%= arg_types %>>(<%= arg_params %>) -> MatchableBox<%= i %><<%= arg_types %>> where <%= arg_hashables %> { + MatchableBox<%= i %>(<%= arg_call_params %>) } <%_ } -%> diff --git a/Templates/Resolver+Injection.swifttemplate b/Templates/Resolver+Injection.swifttemplate index 73683468..8595c200 100644 --- a/Templates/Resolver+Injection.swifttemplate +++ b/Templates/Resolver+Injection.swifttemplate @@ -6,20 +6,7 @@ struct Variation { let paramArgs: Int let factoryArgs: Int let isMatchable: Bool - var args: Int { return paramArgs + factoryArgs } - - static let simpleCases = [false, true] - .flatMap { b in [0, 1].map { (b, $0) } } - .flatMap { t in [false, true].map { (t.0, t.1, $0) } } - .filter { $0.1 == 1 || $0.2 } - .map { Variation(isTagged: $0.0, paramArgs: $0.1, factoryArgs: 0, isMatchable: $0.2) } - - static let factoryCases = [false, true] - .flatMap { b in (1...maxArgs).map { (b, $0) } } - .flatMap { t in (0.. 1 && !isMatchable ? ("arg: (" + (1...paramArgs).map { "Arg\($0)" }.joined(separator: ", ") + ")") : nil, - paramArgs > 1 && isMatchable ? ("arg: ArgumentBox\(paramArgs)<" + (1...paramArgs).map { "Arg\($0)" }.joined(separator: ", ") + ">") : nil + paramArgs >= 1 ? "arg " + (1...paramArgs).map { "arg\($0): Arg\($0)" }.joined(separator: ", _ ") : nil ].compactMap { $0 }.joined(separator: ", ") } var factoryInputs: String { @@ -49,14 +34,27 @@ extension Variation { var whereClause: String { constraints.isEmpty ? "" : "where " + constraints } var requestParams: String { - let paramVars = paramArgs == 1 ? ["arg"] : (0.. 0 || $0.isMatchable } + + static let factoryCases = (1...maxArgs) + .flatMap { a in [false, true].map { ($0, a) } } + .flatMap { t in [false, true].map { (t.0, t.1, $0) } } + .flatMap { t in (0.. // sourcery:inline:ResolverInjectionApi extension Resolver { diff --git a/Tests/3.0 API/SwinjectApiSpec.swift b/Tests/3.0 API/SwinjectApiSpec.swift index c242296a..6a53a52e 100644 --- a/Tests/3.0 API/SwinjectApiSpec.swift +++ b/Tests/3.0 API/SwinjectApiSpec.swift @@ -106,7 +106,7 @@ class SwinjectApiSpec: QuickSpec { override func spec() { } expect { try swinject.factory(of: Int.self)(11, 14.0, "17") } == 42 expect { try swinject.factory(of: Int.self, arg: 11)(14.0, "17") } == 42 - expect { try swinject.factory(of: Int.self, arg: pack(11, 14.0))("17") } == 42 + expect { try swinject.factory(of: Int.self, arg: 11, 14.0)("17") } == 42 } it("can pass context to the bindings") { // FIXME: compiler segfaults if declaring these providers inside function builder diff --git a/Tests/Support/GeneratedMocks.swift b/Tests/Support/GeneratedMocks.swift index fd5a1b56..47a4202a 100644 --- a/Tests/Support/GeneratedMocks.swift +++ b/Tests/Support/GeneratedMocks.swift @@ -2,8 +2,6 @@ // DO NOT EDIT - - // swiftlint:disable line_length // swiftlint:disable variable_name @@ -370,3 +368,5 @@ class StaticScopeRegistryMock: StaticScopeRegistry { + + diff --git a/Tests/Unit Specs/BinderEnvironmentSpec.swift b/Tests/Unit Specs/BinderEnvironmentSpec.swift index 40b982fe..55bf1629 100644 --- a/Tests/Unit Specs/BinderEnvironmentSpec.swift +++ b/Tests/Unit Specs/BinderEnvironmentSpec.swift @@ -75,7 +75,7 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { it("calls builder with given argument") { var passedArgument: Int? let maker = factory { (_, arg: Int) in passedArgument = arg } - _ = try? maker.makeInstance(arg: pack(42), resolver: DummyResolver()) + _ = try? maker.makeInstance(arg: box(42), resolver: DummyResolver()) expect(passedArgument) == 42 } it("rethrows error from builder") { @@ -177,7 +177,7 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { it("calls builder with given argument") { var passedArgument: Int? let maker = multiton { (_, arg: Int) in passedArgument = arg } - _ = try? maker.makeInstance(arg: pack(42), resolver: DummyResolver()) + _ = try? maker.makeInstance(arg: box(42), resolver: DummyResolver()) expect(passedArgument) == 42 } it("rethrows error from builder") { diff --git a/Tests/Unit Specs/SwinjectSpec.swift b/Tests/Unit Specs/SwinjectSpec.swift index 4fc4b6cb..ff6e168f 100644 --- a/Tests/Unit Specs/SwinjectSpec.swift +++ b/Tests/Unit Specs/SwinjectSpec.swift @@ -208,7 +208,7 @@ class SwinjectSpec: QuickSpec { override func spec() { binding.matchesReturnValue = true binding.instanceArgContextResolverReturnValue = 42 _ = try? swinject.factory(of: Int.self)("arg") - let argument = binding.instanceArgContextResolverReceivedArguments?.arg as? ArgumentBox1 + let argument = binding.instanceArgContextResolverReceivedArguments?.arg as? MatchableBox1 expect(argument?.arg1) == "arg" } it("matches binding with correct key") { @@ -234,33 +234,33 @@ class SwinjectSpec: QuickSpec { override func spec() { } it("can curry 2-tuple as 0 / 2 argument") { _ = try? swinject.factory()("arg1", "arg2") as Int - let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? ArgumentBox2 + let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? MatchableBox2 expect(receivedArg?.arg1) == "arg1" expect(receivedArg?.arg2) == "arg2" } it("can curry 2-tuple as 1 / 1 argument") { _ = try? swinject.factory(arg: "arg1")("arg2") as Int - let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? ArgumentBox2 + let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? MatchableBox2 expect(receivedArg?.arg1) == "arg1" expect(receivedArg?.arg2) == "arg2" } it("can curry 3-tuple as 0 / 3 argument") { _ = try? swinject.factory()("arg1", 2, "arg3") as Int - let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? ArgumentBox3 + let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? MatchableBox3 expect(receivedArg?.arg1) == "arg1" expect(receivedArg?.arg2) == 2 expect(receivedArg?.arg3) == "arg3" } it("can curry 3-tuple as 1 / 2 argument") { _ = try? swinject.factory(arg: "arg1")(2, "arg3") as Int - let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? ArgumentBox3 + let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? MatchableBox3 expect(receivedArg?.arg1) == "arg1" expect(receivedArg?.arg2) == 2 expect(receivedArg?.arg3) == "arg3" } it("can curry 3-tuple as 2 / 1 argument") { - _ = try? swinject.factory(arg: pack("arg1", 2))("arg3") as Int - let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? ArgumentBox3 + _ = try? swinject.factory(arg: "arg1", 2)("arg3") as Int + let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? MatchableBox3 expect(receivedArg?.arg1) == "arg1" expect(receivedArg?.arg2) == 2 expect(receivedArg?.arg3) == "arg3" From e84723725b4ce9f92529eedf267f1ff3286e47de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sat, 27 Jul 2019 08:56:28 +0200 Subject: [PATCH 142/239] Create separate target for templates --- Swinject.xcodeproj/project.pbxproj | 181 +++++++++++++++++- .../xcschemes/SwinjectTests-iOS.xcscheme | 99 ---------- .../xcschemes/SwinjectTests-macOS.xcscheme | 99 ---------- .../xcschemes/SwinjectTests-tvOS.xcscheme | 99 ---------- .../xcschemes/SwinjectTests-watchOS.xcscheme | 99 ---------- Templates/InjectionVariation.swift | 58 ++++++ Templates/Resolver+Injection.swifttemplate | 65 +------ Templates/SwiftCode.swifttemplate | 60 ++++++ Tests/Support/GeneratedMocks.swift | 2 + project.yml | 21 +- 10 files changed, 321 insertions(+), 462 deletions(-) delete mode 100644 Swinject.xcodeproj/xcshareddata/xcschemes/SwinjectTests-iOS.xcscheme delete mode 100644 Swinject.xcodeproj/xcshareddata/xcschemes/SwinjectTests-macOS.xcscheme delete mode 100644 Swinject.xcodeproj/xcshareddata/xcschemes/SwinjectTests-tvOS.xcscheme delete mode 100644 Swinject.xcodeproj/xcshareddata/xcschemes/SwinjectTests-watchOS.xcscheme create mode 100644 Templates/InjectionVariation.swift create mode 100644 Templates/SwiftCode.swifttemplate diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 8ced92ce..e7d6a37b 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -38,6 +38,7 @@ 196338EA802A39E205C33B43 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; 19EBB651BD06BD0C03C1ACB5 /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59111BE319C59E4CD6CF68CD /* Assembler.swift */; }; 1A40A26942A65246D7DD268E /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = ADC44E9312C3B974AFD8F07B /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 1C82BFD00FCC384DB3AE6A89 /* MatchableBoxes.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 808C1063CA90CC593C7E0E9C /* MatchableBoxes.swifttemplate */; }; 1CA5DF3F93203B226A6FA059 /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EA566CD336DB8343ADFAF9B /* BehaviorFakes.swift */; }; 1ED6BD68D92F4FE60978EF22 /* Container+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDA78290D6D60BD0B808571F /* Container+Logging.swift */; }; 1EF3807EB529346903DFA2A1 /* BindingKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = A24B4E8F1CA18603DBB6884A /* BindingKey.swift */; }; @@ -139,6 +140,7 @@ 6FCCBA9D2E4C2A225CB1A152 /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */; }; 703F8B3AD111A6CFAFF66A49 /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; 708E1C453CBC76ED26FA2FCB /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; + 71895EBC0803EEE3BFCD7001 /* Resolver+Injection.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 01DEC4D20CE554C9DFBD0A8D /* Resolver+Injection.swifttemplate */; }; 72217E47D83C3CA6D97640B9 /* StandardScopeRegistrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */; }; 725EF35B0CC5E62791D5EA09 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 34AFFAC41BA9D02A38BDB7A3 /* Nimble.framework */; }; 7295E928A18E6055CF796840 /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C074BAC560F277E806146C60 /* SimpleBinding.swift */; }; @@ -232,6 +234,7 @@ B4B66D7251BDDE25D6D7FB3C /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BFF4BA99493C54260878C4 /* ObjectScope.swift */; }; B5FF5DFE394B6B1BB930D88D /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */; }; B703A24C1A963C6BAC95B9A5 /* GeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */; }; + B7653A6427A5E284E9A1D6D3 /* ServiceEntry+TypeForwarding.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */; }; B84167AC8C6BEB57C4D0695A /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; B9550BE2BA6FA5731BEC87FD /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; BB571B9A78FC53231A18E18C /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; @@ -244,6 +247,7 @@ BE6C13A3492E3CFC08E231B0 /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADA1541ABC1365DFD7E3377F /* Food.swift */; }; BE94EF7BCF976A703F961389 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */; }; BEEFBE87EB17D56BA8D47358 /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 351C4221896DDB8572BD6CB5 /* Person.swift */; }; + BFE22F9F2E88F177302E9D19 /* Container+Registration.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */; }; C1687ACA897DEFD3A8197CCD /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; C177D9C6969ADA38C1094F6D /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */; }; C223101DB417F1237A8421E1 /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 6D434EB4C13CF9D9FA6D80CB /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -261,6 +265,7 @@ CAF3BCDC752C821491AE8714 /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCAF491EC7DCD7477F9A0ECB /* SwinjectModule.swift */; }; CB06DC3BC4A32776BBD90DDF /* GeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */; }; CB0B308F3D3A831A28127462 /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59A3946B59EB4D787CCE9F2 /* Container+Registration.swift */; }; + CB9666A26D85B92BA1357160 /* AutoMockable.stencil in Resources */ = {isa = PBXBuildFile; fileRef = 4286F98133270A36F19E5CD0 /* AutoMockable.stencil */; }; CB9E8D16D7A0620A1F7A32A3 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; CBBE28990E0EA82AD8D5E3AF /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; CBE63031F33303F3E503CEF2 /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; @@ -302,8 +307,10 @@ EA7EB12BDE27575738D26AD4 /* SimpleBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */; }; EB3420214A9E68A0247D0F2C /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 351C4221896DDB8572BD6CB5 /* Person.swift */; }; EB79ECF5C893F63B22355167 /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; + EBC64A1515C868E410C83451 /* SwiftCode.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 90191C25A2D66E07C4E9CD73 /* SwiftCode.swifttemplate */; }; ED6CB3935B15F30A182ED6D0 /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61EE5DDBE705B47AFC9A6986 /* LoadAwareAssembly.swift */; }; EE0D3637D2524AC1CD21780D /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 74DE57FB3E8228904E6FE0D7 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; + EE2D25BFC6AFEBB13821A0E3 /* InjectionVariation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57636955DECC4A134243CE76 /* InjectionVariation.swift */; }; EE35DF2D353E2C5110DA5C42 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; EEAD7E215908DF939ECCDCC9 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; EF79F0B3D497215D4BBBC038 /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92B8E618A08408404FB2A7A /* TypeBinder.swift */; }; @@ -315,6 +322,7 @@ F37DA7FC70E254616DBD1BD7 /* ReferenceMakerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 388605A438343F7BB80D521E /* ReferenceMakerSpec.swift */; }; F39521855B858534A8D53C8F /* Closable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D0BCCCD61CD9BECC29E064 /* Closable.swift */; }; F504C2ABEFCFFCAC8B858751 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; + F568382FB877060127790413 /* Resolver+LegacyApi.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */; }; F6CF010989F531AB0A27B5A1 /* BindingKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = A24B4E8F1CA18603DBB6884A /* BindingKey.swift */; }; F7979BE4BE1B1C7101D15E61 /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; F7CD04FB09FC7F18E9E001CF /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; @@ -340,6 +348,27 @@ remoteGlobalIDString = EFE66E56E1E06404E473072E; remoteInfo = "Swinject-iOS"; }; + 65E1BD1BD263E56E3C715ACA /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 2224A31D363E48B57671956F /* Project object */; + proxyType = 1; + remoteGlobalIDString = 181553FDCFE810B94B0333A0; + remoteInfo = Templates; + }; + 909D441B79AAF49F1C06CE09 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 2224A31D363E48B57671956F /* Project object */; + proxyType = 1; + remoteGlobalIDString = 181553FDCFE810B94B0333A0; + remoteInfo = Templates; + }; + A729CE1B665AEFB575BD5010 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 2224A31D363E48B57671956F /* Project object */; + proxyType = 1; + remoteGlobalIDString = 181553FDCFE810B94B0333A0; + remoteInfo = Templates; + }; C9A1EE6892F51C7FC46F7ECC /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 2224A31D363E48B57671956F /* Project object */; @@ -347,6 +376,13 @@ remoteGlobalIDString = D89E5CC45F90DF6490FB29BE; remoteInfo = "Swinject-macOS"; }; + F0924FCD6A6A505F38C5A762 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 2224A31D363E48B57671956F /* Project object */; + proxyType = 1; + remoteGlobalIDString = 181553FDCFE810B94B0333A0; + remoteInfo = Templates; + }; FEE51FBABE119F387DF3E199 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 2224A31D363E48B57671956F /* Project object */; @@ -448,7 +484,9 @@ 494AA2AA587975747596C157 /* ProviderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProviderSpec.swift; sourceTree = ""; }; 4A784E2DEC7691D14DDBECD8 /* Resolver+LegacyApi.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Resolver+LegacyApi.swift"; sourceTree = ""; }; 4BC5108ED11A3A3084D864CC /* Animal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Animal.swift; sourceTree = ""; }; + 4D31F8718D2E847922530C20 /* Templates.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Templates.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 5057BAB33984E3E33469452B /* Scope.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Scope.swift; sourceTree = ""; }; + 57636955DECC4A134243CE76 /* InjectionVariation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InjectionVariation.swift; sourceTree = ""; }; 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Resolver+Injection.swift"; sourceTree = ""; }; 59111BE319C59E4CD6CF68CD /* Assembler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Assembler.swift; sourceTree = ""; }; 5AB605ED0F735221D0EB1D5F /* Convenience.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Convenience.swift; sourceTree = ""; }; @@ -470,11 +508,13 @@ 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ServiceEntry+TypeForwarding.swift"; sourceTree = ""; }; 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextTranslator.swift; sourceTree = ""; }; 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistry.swift; sourceTree = ""; }; + 808C1063CA90CC593C7E0E9C /* MatchableBoxes.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = MatchableBoxes.swifttemplate; sourceTree = ""; }; 823617F3B8A9192F56B13331 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; 841D83ADB41363D1E38087B4 /* NonGeneratedMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonGeneratedMocks.swift; sourceTree = ""; }; 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeneratedMocks.swift; sourceTree = ""; }; 8B9785AAE94A5447FA307242 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTreeBuilderSpec.swift; sourceTree = ""; }; + 90191C25A2D66E07C4E9CD73 /* SwiftCode.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = SwiftCode.swifttemplate; sourceTree = ""; }; 9527A4CA5BCBA7AFA3596757 /* SwinjectSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectSpec.swift; sourceTree = ""; }; 9620155728133F451B31C0AD /* Swinject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Swinject.swift; sourceTree = ""; }; 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistryKey.swift; sourceTree = ""; }; @@ -498,8 +538,6 @@ CADDB3E9E363310028AA5920 /* InstanceMaker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceMaker.swift; sourceTree = ""; }; CC85CB215058F95C0BC190B1 /* Bridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bridge.swift; sourceTree = ""; }; CDA78290D6D60BD0B808571F /* Container+Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Logging.swift"; sourceTree = ""; }; - CDCF3FCB22EB8F960025E2BD /* MatchableBoxes.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = MatchableBoxes.swifttemplate; sourceTree = ""; }; - CDCF3FCC22EC16430025E2BD /* BinderEnvironment.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = BinderEnvironment.swifttemplate; sourceTree = ""; }; CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRequest.swift; sourceTree = ""; }; E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; @@ -560,12 +598,13 @@ isa = PBXGroup; children = ( 4286F98133270A36F19E5CD0 /* AutoMockable.stencil */, - CDCF3FCB22EB8F960025E2BD /* MatchableBoxes.swifttemplate */, CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */, + 808C1063CA90CC593C7E0E9C /* MatchableBoxes.swifttemplate */, 01DEC4D20CE554C9DFBD0A8D /* Resolver+Injection.swifttemplate */, - CDCF3FCC22EC16430025E2BD /* BinderEnvironment.swifttemplate */, FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */, BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */, + 90191C25A2D66E07C4E9CD73 /* SwiftCode.swifttemplate */, + 57636955DECC4A134243CE76 /* InjectionVariation.swift */, ); path = Templates; sourceTree = ""; @@ -693,6 +732,7 @@ 09FC792715B1658721F76885 /* SwinjectTests.xctest */, 0DC67CB109091002AB433A46 /* SwinjectTests.xctest */, 0CA449690AE00F6300DE8ACA /* SwinjectTests.xctest */, + 4D31F8718D2E847922530C20 /* Templates.framework */, ); name = Products; sourceTree = ""; @@ -846,6 +886,23 @@ /* End PBXHeadersBuildPhase section */ /* Begin PBXNativeTarget section */ + 181553FDCFE810B94B0333A0 /* Templates */ = { + isa = PBXNativeTarget; + buildConfigurationList = F405397545E56D2A8DEDBE4B /* Build configuration list for PBXNativeTarget "Templates" */; + buildPhases = ( + 2439801ED42911870AF5FAFE /* Sources */, + 9689C59D3DC590586E6E8D3C /* Generate SwiftCode.swifttemplate */, + E27AA1C281CDB2770CA9C004 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = Templates; + productName = Templates; + productReference = 4D31F8718D2E847922530C20 /* Templates.framework */; + productType = "com.apple.product-type.framework"; + }; 19003555F5BD009DD25F895B /* SwinjectTests-macOS */ = { isa = PBXNativeTarget; buildConfigurationList = 7C6E4A1A8FA04805EB1944EF /* Build configuration list for PBXNativeTarget "SwinjectTests-macOS" */; @@ -878,6 +935,7 @@ buildRules = ( ); dependencies = ( + 9A31879C220104E2D6ED512C /* PBXTargetDependency */, ); name = "Swinject-watchOS"; productName = "Swinject-watchOS"; @@ -935,6 +993,7 @@ buildRules = ( ); dependencies = ( + A9BA980838BF3F651306FC24 /* PBXTargetDependency */, ); name = "Swinject-macOS"; productName = "Swinject-macOS"; @@ -973,6 +1032,7 @@ buildRules = ( ); dependencies = ( + 1640E850398FBCB80E41BCD3 /* PBXTargetDependency */, ); name = "Swinject-iOS"; productName = "Swinject-iOS"; @@ -992,6 +1052,7 @@ buildRules = ( ); dependencies = ( + F1485D8B5892F15D827E27BE /* PBXTargetDependency */, ); name = "Swinject-tvOS"; productName = "Swinject-tvOS"; @@ -1025,6 +1086,7 @@ 19003555F5BD009DD25F895B /* SwinjectTests-macOS */, A79AFABFABCB5B9F43418836 /* SwinjectTests-tvOS */, 978D2C823AE8C4BC19CF6644 /* SwinjectTests-watchOS */, + 181553FDCFE810B94B0333A0 /* Templates */, ); }; /* End PBXProject section */ @@ -1062,6 +1124,20 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + E27AA1C281CDB2770CA9C004 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + CB9666A26D85B92BA1357160 /* AutoMockable.stencil in Resources */, + BFE22F9F2E88F177302E9D19 /* Container+Registration.swifttemplate in Resources */, + 1C82BFD00FCC384DB3AE6A89 /* MatchableBoxes.swifttemplate in Resources */, + 71895EBC0803EEE3BFCD7001 /* Resolver+Injection.swifttemplate in Resources */, + F568382FB877060127790413 /* Resolver+LegacyApi.swifttemplate in Resources */, + B7653A6427A5E284E9A1D6D3 /* ServiceEntry+TypeForwarding.swifttemplate in Resources */, + EBC64A1515C868E410C83451 /* SwiftCode.swifttemplate in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ @@ -1209,6 +1285,24 @@ shellPath = /bin/sh; shellScript = "if which sourcery >/dev/null; then\n sourcery\nelse\n echo \"warning: Sourcery not installed, download from https://github.com/krzysztofzablocki/Sourcery\"\nfi\n"; }; + 9689C59D3DC590586E6E8D3C /* Generate SwiftCode.swifttemplate */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + name = "Generate SwiftCode.swifttemplate"; + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "OUTPUT=\"Templates/SwiftCode.swifttemplate\"\necho \"<%\" > $OUTPUT\nfor FILE in $(find Templates -name \"*.swift\"); do\n cat $FILE >> $OUTPUT\ndone\necho \"%>\" >> $OUTPUT\n"; + }; A83035E3ADC30E0D76E7B6C7 /* Sourcery */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; @@ -1326,6 +1420,14 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 2439801ED42911870AF5FAFE /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + EE2D25BFC6AFEBB13821A0E3 /* InjectionVariation.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 456DC259176D0BA0F4BC483F /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -1627,11 +1729,26 @@ /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ + 1640E850398FBCB80E41BCD3 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 181553FDCFE810B94B0333A0 /* Templates */; + targetProxy = A729CE1B665AEFB575BD5010 /* PBXContainerItemProxy */; + }; 5432762080D26E35E0C9F679 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = FFB12C2BA1D9FE458CAE83D0 /* Swinject-tvOS */; targetProxy = 0398E4F685979C8F56F7FB53 /* PBXContainerItemProxy */; }; + 9A31879C220104E2D6ED512C /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 181553FDCFE810B94B0333A0 /* Templates */; + targetProxy = 65E1BD1BD263E56E3C715ACA /* PBXContainerItemProxy */; + }; + A9BA980838BF3F651306FC24 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 181553FDCFE810B94B0333A0 /* Templates */; + targetProxy = 909D441B79AAF49F1C06CE09 /* PBXContainerItemProxy */; + }; CFEBFBB60A765893D05D6C9B /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = 36C7878AD0EB9515CC0F84FD /* Swinject-watchOS */; @@ -1647,6 +1764,11 @@ target = D89E5CC45F90DF6490FB29BE /* Swinject-macOS */; targetProxy = C9A1EE6892F51C7FC46F7ECC /* PBXContainerItemProxy */; }; + F1485D8B5892F15D827E27BE /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 181553FDCFE810B94B0333A0 /* Templates */; + targetProxy = F0924FCD6A6A505F38C5A762 /* PBXContainerItemProxy */; + }; /* End PBXTargetDependency section */ /* Begin XCBuildConfiguration section */ @@ -1974,6 +2096,27 @@ }; name = Debug; }; + 5DFD34F139FD3B422CBDBA0C /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_IDENTITY = ""; + COMBINE_HIDPI_IMAGES = YES; + CURRENT_PROJECT_VERSION = 1; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + SDKROOT = macosx; + SKIP_INSTALL = YES; + VERSIONING_SYSTEM = "apple-generic"; + }; + name = Release; + }; 5FFA59364179DCE442102043 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { @@ -2058,6 +2201,27 @@ }; name = Debug; }; + CBEC7AE551D042507AD35E23 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_IDENTITY = ""; + COMBINE_HIDPI_IMAGES = YES; + CURRENT_PROJECT_VERSION = 1; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + SDKROOT = macosx; + SKIP_INSTALL = YES; + VERSIONING_SYSTEM = "apple-generic"; + }; + name = Debug; + }; E650C6AB7D474A320AD57B8C /* Release */ = { isa = XCBuildConfiguration; buildSettings = { @@ -2188,6 +2352,15 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = ""; }; + F405397545E56D2A8DEDBE4B /* Build configuration list for PBXNativeTarget "Templates" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + CBEC7AE551D042507AD35E23 /* Debug */, + 5DFD34F139FD3B422CBDBA0C /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = ""; + }; /* End XCConfigurationList section */ }; rootObject = 2224A31D363E48B57671956F /* Project object */; diff --git a/Swinject.xcodeproj/xcshareddata/xcschemes/SwinjectTests-iOS.xcscheme b/Swinject.xcodeproj/xcshareddata/xcschemes/SwinjectTests-iOS.xcscheme deleted file mode 100644 index 93f569ce..00000000 --- a/Swinject.xcodeproj/xcshareddata/xcschemes/SwinjectTests-iOS.xcscheme +++ /dev/null @@ -1,99 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Swinject.xcodeproj/xcshareddata/xcschemes/SwinjectTests-macOS.xcscheme b/Swinject.xcodeproj/xcshareddata/xcschemes/SwinjectTests-macOS.xcscheme deleted file mode 100644 index 86c63825..00000000 --- a/Swinject.xcodeproj/xcshareddata/xcschemes/SwinjectTests-macOS.xcscheme +++ /dev/null @@ -1,99 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Swinject.xcodeproj/xcshareddata/xcschemes/SwinjectTests-tvOS.xcscheme b/Swinject.xcodeproj/xcshareddata/xcschemes/SwinjectTests-tvOS.xcscheme deleted file mode 100644 index 68b8f6ac..00000000 --- a/Swinject.xcodeproj/xcshareddata/xcschemes/SwinjectTests-tvOS.xcscheme +++ /dev/null @@ -1,99 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Swinject.xcodeproj/xcshareddata/xcschemes/SwinjectTests-watchOS.xcscheme b/Swinject.xcodeproj/xcshareddata/xcschemes/SwinjectTests-watchOS.xcscheme deleted file mode 100644 index b94d8c8b..00000000 --- a/Swinject.xcodeproj/xcshareddata/xcschemes/SwinjectTests-watchOS.xcscheme +++ /dev/null @@ -1,99 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Templates/InjectionVariation.swift b/Templates/InjectionVariation.swift new file mode 100644 index 00000000..90cac50c --- /dev/null +++ b/Templates/InjectionVariation.swift @@ -0,0 +1,58 @@ +// swiftformat:disable fileHeader +let maxArgs = 5 + +struct InjectionVariation { + let isTagged: Bool + let paramArgs: Int + let factoryArgs: Int + let isMatchable: Bool + var args: Int { return paramArgs + factoryArgs } +} + +extension InjectionVariation { + var genericTypes: String { [ + "Type", + isTagged ? "Tag" : nil, + args > 0 ? (1 ... args).map { "Arg\($0)" }.joined(separator: ", ") : nil, + ].compactMap { $0 }.joined(separator: ", ") } + + var params: String { [ + "of _: Type.Type = Type.self", + isTagged ? "tagged tag: Tag" : nil, + paramArgs >= 1 ? "arg " + (1 ... paramArgs).map { "arg\($0): Arg\($0)" }.joined(separator: ", _ ") : nil, + ].compactMap { $0 }.joined(separator: ", ") } + + var factoryInputs: String { + (1 ... factoryArgs).map { "Arg\($0 + paramArgs)" }.joined(separator: ", ") + } + + var constraints: String { [ + isTagged ? "Tag: Hashable" : nil, + isMatchable && args > 0 ? (1 ... args).map { "Arg\($0): Hashable" }.joined(separator: ", ") : nil, + ].compactMap { $0 }.joined(separator: ", ") } + + var whereClause: String { constraints.isEmpty ? "" : "where " + constraints } + + var requestParams: String { + let paramVars = (0 ..< paramArgs).map { "arg\($0 + 1)" } + let factoryVars = (0 ..< factoryArgs).map { "$\($0)" } + return [ + isTagged ? "tag: tag" : "tag: NoTag()", + args == 0 ? "arg: ()" : "arg: box(\((paramVars + factoryVars).joined(separator: ", ")))", + ].compactMap { $0 }.joined(separator: ", ") + } +} + +extension InjectionVariation { + static let simpleCases = (0 ... maxArgs) + .flatMap { a in [false, true].map { ($0, a) } } + .flatMap { t in [false, true].map { (t.0, t.1, 0, $0) } } + .map { InjectionVariation(isTagged: $0.0, paramArgs: $0.1, factoryArgs: $0.2, isMatchable: $0.3) } + .filter { $0.paramArgs > 0 || $0.isMatchable } + + static let factoryCases = (1 ... maxArgs) + .flatMap { a in [false, true].map { ($0, a) } } + .flatMap { t in [false, true].map { (t.0, t.1, $0) } } + .flatMap { t in (0 ..< t.1).map { (t.0, $0, t.1 - $0, t.2) } } + .map { InjectionVariation(isTagged: $0.0, paramArgs: $0.1, factoryArgs: $0.2, isMatchable: $0.3) } +} diff --git a/Templates/Resolver+Injection.swifttemplate b/Templates/Resolver+Injection.swifttemplate index 8595c200..3dcd285f 100644 --- a/Templates/Resolver+Injection.swifttemplate +++ b/Templates/Resolver+Injection.swifttemplate @@ -1,64 +1,7 @@ -<%_ -let maxArgs = 5 - -struct Variation { - let isTagged: Bool - let paramArgs: Int - let factoryArgs: Int - let isMatchable: Bool - var args: Int { return paramArgs + factoryArgs } -} - -extension Variation { - var genericTypes: String {[ - "Type", - isTagged ? "Tag" : nil, - args > 0 ? (1...args).map { "Arg\($0)" }.joined(separator: ", ") : nil - ].compactMap { $0 }.joined(separator: ", ") } - - var params: String {[ - "of _: Type.Type = Type.self", - isTagged ? "tagged tag: Tag" : nil, - paramArgs >= 1 ? "arg " + (1...paramArgs).map { "arg\($0): Arg\($0)" }.joined(separator: ", _ ") : nil - ].compactMap { $0 }.joined(separator: ", ") } - - var factoryInputs: String { - (1...factoryArgs).map { "Arg\($0 + paramArgs)" }.joined(separator: ", ") - } - - var constraints: String {[ - isTagged ? "Tag: Hashable" : nil, - isMatchable && args > 0 ? (1...args).map { "Arg\($0): Hashable" }.joined(separator: ", ") : nil - ].compactMap { $0 }.joined(separator: ", ") } - - var whereClause: String { constraints.isEmpty ? "" : "where " + constraints } - - var requestParams: String { - let paramVars = (0.. 0 || $0.isMatchable } - - static let factoryCases = (1...maxArgs) - .flatMap { a in [false, true].map { ($0, a) } } - .flatMap { t in [false, true].map { (t.0, t.1, $0) } } - .flatMap { t in (0.. +<%- include("SwiftCode") %> // sourcery:inline:ResolverInjectionApi extension Resolver { -<%_ Variation.simpleCases.forEach { v in -%> +<%_ InjectionVariation.simpleCases.forEach { v in -%> func instance<<%= v.genericTypes %>>(<%= v.params %>) throws -> Type <%= v.whereClause %>{ try resolve(request(<%= v.requestParams %>)) } @@ -67,7 +10,7 @@ extension Resolver { } extension Resolver { -<%_ Variation.simpleCases.forEach { v in -%> +<%_ InjectionVariation.simpleCases.forEach { v in -%> func provider<<%= v.genericTypes %>>(<%= v.params %>) -> () throws -> Type <%= v.whereClause %>{ return { try self.resolve(request(<%= v.requestParams %>)) } } @@ -76,7 +19,7 @@ extension Resolver { } extension Resolver { -<%_ Variation.factoryCases.forEach { v in -%> +<%_ InjectionVariation.factoryCases.forEach { v in -%> func factory<<%= v.genericTypes %>>(<%= v.params %>) -> (<%= v.factoryInputs %>) throws -> Type <%= v.whereClause %>{ return { try self.resolve(request(<%= v.requestParams %>)) } } diff --git a/Templates/SwiftCode.swifttemplate b/Templates/SwiftCode.swifttemplate new file mode 100644 index 00000000..ece514d5 --- /dev/null +++ b/Templates/SwiftCode.swifttemplate @@ -0,0 +1,60 @@ +<% +// swiftformat:disable fileHeader +let maxArgs = 5 + +struct InjectionVariation { + let isTagged: Bool + let paramArgs: Int + let factoryArgs: Int + let isMatchable: Bool + var args: Int { return paramArgs + factoryArgs } +} + +extension InjectionVariation { + var genericTypes: String { [ + "Type", + isTagged ? "Tag" : nil, + args > 0 ? (1 ... args).map { "Arg\($0)" }.joined(separator: ", ") : nil, + ].compactMap { $0 }.joined(separator: ", ") } + + var params: String { [ + "of _: Type.Type = Type.self", + isTagged ? "tagged tag: Tag" : nil, + paramArgs >= 1 ? "arg " + (1 ... paramArgs).map { "arg\($0): Arg\($0)" }.joined(separator: ", _ ") : nil, + ].compactMap { $0 }.joined(separator: ", ") } + + var factoryInputs: String { + (1 ... factoryArgs).map { "Arg\($0 + paramArgs)" }.joined(separator: ", ") + } + + var constraints: String { [ + isTagged ? "Tag: Hashable" : nil, + isMatchable && args > 0 ? (1 ... args).map { "Arg\($0): Hashable" }.joined(separator: ", ") : nil, + ].compactMap { $0 }.joined(separator: ", ") } + + var whereClause: String { constraints.isEmpty ? "" : "where " + constraints } + + var requestParams: String { + let paramVars = (0 ..< paramArgs).map { "arg\($0 + 1)" } + let factoryVars = (0 ..< factoryArgs).map { "$\($0)" } + return [ + isTagged ? "tag: tag" : "tag: NoTag()", + args == 0 ? "arg: ()" : "arg: box(\((paramVars + factoryVars).joined(separator: ", ")))", + ].compactMap { $0 }.joined(separator: ", ") + } +} + +extension InjectionVariation { + static let simpleCases = (0 ... maxArgs) + .flatMap { a in [false, true].map { ($0, a) } } + .flatMap { t in [false, true].map { (t.0, t.1, 0, $0) } } + .map { InjectionVariation(isTagged: $0.0, paramArgs: $0.1, factoryArgs: $0.2, isMatchable: $0.3) } + .filter { $0.paramArgs > 0 || $0.isMatchable } + + static let factoryCases = (1 ... maxArgs) + .flatMap { a in [false, true].map { ($0, a) } } + .flatMap { t in [false, true].map { (t.0, t.1, $0) } } + .flatMap { t in (0 ..< t.1).map { (t.0, $0, t.1 - $0, t.2) } } + .map { InjectionVariation(isTagged: $0.0, paramArgs: $0.1, factoryArgs: $0.2, isMatchable: $0.3) } +} +%> diff --git a/Tests/Support/GeneratedMocks.swift b/Tests/Support/GeneratedMocks.swift index 47a4202a..5329aa32 100644 --- a/Tests/Support/GeneratedMocks.swift +++ b/Tests/Support/GeneratedMocks.swift @@ -370,3 +370,5 @@ class StaticScopeRegistryMock: StaticScopeRegistry { + + diff --git a/project.yml b/project.yml index 45bc2926..82d95f8c 100644 --- a/project.yml +++ b/project.yml @@ -22,6 +22,9 @@ targets: excludes: ["**/*.erb"] - path: Templates buildPhase: none + dependencies: + - target: Templates + link: false preBuildScripts: - script: > if which sourcery >/dev/null; then @@ -50,7 +53,6 @@ targets: type: bundle.unit-test platform: [macOS, iOS, tvOS, watchOS] platformSuffix: -${platform} - scheme: {} sources: - path: Tests excludes: [LinuxMain.swift] @@ -58,3 +60,20 @@ targets: - target: Swinject-${platform} - carthage: Quick - carthage: Nimble + Templates: + type: framework + platform: macOS + sources: Templates + postCompileScripts: + - script: > + OUTPUT="Templates/SwiftCode.swifttemplate" + + echo "<%" > $OUTPUT + + for FILE in $(find Templates -name "*.swift"); do + cat $FILE >> $OUTPUT + done + + echo "%>" >> $OUTPUT + name: Generate SwiftCode.swifttemplate + From 87a13d1285ac3b289d9023836f38e3903db15230 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sat, 27 Jul 2019 12:27:04 +0200 Subject: [PATCH 143/239] Implement code generation for injection & binder API --- Sources/3.0 API/BinderEnvironment.swift | 174 ++++++++--- Swinject.xcodeproj/project.pbxproj | 124 +++----- Templates/BinderEnvironment.swifttemplate | 12 + Templates/BinderVariation.swift | 150 ++++++++++ .../Container+Registration.swifttemplate | 3 +- Templates/InjectionVariation.swift | 122 +++++--- Templates/MatchableBoxes.swifttemplate | 2 +- Templates/Resolver+Injection.swifttemplate | 21 +- Templates/Resolver+LegacyApi.swifttemplate | 3 +- .../ServiceEntry+TypeForwarding.swifttemplate | 3 +- Templates/SwiftCode.swifttemplate | 283 +++++++++++++++--- Templates/Utils.swift | 11 + Tests/Support/GeneratedMocks.swift | 2 + Tests/Unit Specs/BinderEnvironmentSpec.swift | 36 +-- 14 files changed, 704 insertions(+), 242 deletions(-) create mode 100644 Templates/BinderEnvironment.swifttemplate create mode 100644 Templates/BinderVariation.swift create mode 100644 Templates/Utils.swift diff --git a/Sources/3.0 API/BinderEnvironment.swift b/Sources/3.0 API/BinderEnvironment.swift index 98941e1c..0aa184e2 100644 --- a/Sources/3.0 API/BinderEnvironment.swift +++ b/Sources/3.0 API/BinderEnvironment.swift @@ -17,72 +17,118 @@ public func scoped(_ scope: AScope) -> BinderEnvironment(_ builder: @escaping (Resolver, Context) throws -> Type) -> SimpleBinding.Builder { + +public func instance(_ instance: Type) -> SimpleBinding.Builder { + .init { _, _, _ in instance } +} + +// sourcery:inline:BindingBuilders +extension BinderEnvironment where AScope == Void { + public func provider(_ builder: @escaping () throws -> Type) -> SimpleBinding.Builder { + .init { _, _, _ in try builder() } + } + + public func provider(_ builder: @escaping (Resolver) throws -> Type) -> SimpleBinding.Builder { + .init { r, _, _ in try builder(r) } + } + + public func provider(_ builder: @escaping (Resolver, Context) throws -> Type) -> SimpleBinding.Builder { .init { r, c, _ in try builder(r, c) } } -} -public extension BinderEnvironment where AScope == Void { - func factory(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SimpleBinding.Builder { - .init(builder) + public func factory(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SimpleBinding.Builder { + .init { r, c, a in try builder(r, c, a) } } - func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SimpleBinding.Builder { - .init { try builder($0, $1, $2.0, $2.1) } + public func factory(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SimpleBinding.Builder> where Arg1: Hashable { + .init { r, c, a in try builder(r, c, a.arg1) } } - func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SimpleBinding.Builder { - .init { try builder($0, $1, $2.0, $2.1, $2.2) } + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SimpleBinding.Builder { + .init { r, c, a in try builder(r, c, a.0, a.1) } } - func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SimpleBinding.Builder { - .init { try builder($0, $1, $2.0, $2.1, $2.2, $2.3) } + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SimpleBinding.Builder> where Arg1: Hashable, Arg2: Hashable { + .init { r, c, a in try builder(r, c, a.arg1, a.arg2) } } - func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SimpleBinding.Builder { - .init { try builder($0, $1, $2.0, $2.1, $2.2, $2.3, $2.4) } + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SimpleBinding.Builder { + .init { r, c, a in try builder(r, c, a.0, a.1, a.2) } + } + + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SimpleBinding.Builder> where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + .init { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3) } + } + + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SimpleBinding.Builder { + .init { r, c, a in try builder(r, c, a.0, a.1, a.2, a.3) } + } + + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SimpleBinding.Builder> where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + .init { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3, a.arg4) } + } + + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SimpleBinding.Builder { + .init { r, c, a in try builder(r, c, a.0, a.1, a.2, a.3, a.4) } + } + + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SimpleBinding.Builder> where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + .init { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) } } } -public extension BinderEnvironment where AScope: Scope, Context == AScope.Context { - func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping () throws -> Type) -> ScopedBinding.Builder { +extension BinderEnvironment where AScope: Scope, Context == AScope.Context { + public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping () throws -> Type) -> ScopedBinding.Builder { .init(scope, ref) { _, _, _ in try builder() } } - func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver) throws -> Type) -> ScopedBinding.Builder { + public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver) throws -> Type) -> ScopedBinding.Builder { .init(scope, ref) { r, _, _ in try builder(r) } } - func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context) throws -> Type) -> ScopedBinding.Builder { + public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context) throws -> Type) -> ScopedBinding.Builder { .init(scope, ref) { r, c, _ in try builder(r, c) } } -} -public extension BinderEnvironment where AScope: Scope, Context == AScope.Context { - func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> ScopedBinding.Builder { - .init(scope, ref, builder) + public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> ScopedBinding.Builder { + .init(scope, ref) { r, c, a in try builder(r, c, a) } } - func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> ScopedBinding.Builder { - .init(scope, ref) { try builder($0, $1, $2.0, $2.1) } + public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> ScopedBinding.Builder> where Arg1: Hashable { + .init(scope, ref) { r, c, a in try builder(r, c, a.arg1) } } - func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> ScopedBinding.Builder { - .init(scope, ref) { try builder($0, $1, $2.0, $2.1, $2.2) } + public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> ScopedBinding.Builder { + .init(scope, ref) { r, c, a in try builder(r, c, a.0, a.1) } } - func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> ScopedBinding.Builder { - .init(scope, ref) { try builder($0, $1, $2.0, $2.1, $2.2, $2.3) } + public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> ScopedBinding.Builder> where Arg1: Hashable, Arg2: Hashable { + .init(scope, ref) { r, c, a in try builder(r, c, a.arg1, a.arg2) } } - func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> ScopedBinding.Builder { - .init(scope, ref) { try builder($0, $1, $2.0, $2.1, $2.2, $2.3, $2.4) } + public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> ScopedBinding.Builder { + .init(scope, ref) { r, c, a in try builder(r, c, a.0, a.1, a.2) } } -} -public func instance(_ instance: Type) -> SimpleBinding.Builder { - .init { _, _, _ in instance } + public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> ScopedBinding.Builder> where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + .init(scope, ref) { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3) } + } + + public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> ScopedBinding.Builder { + .init(scope, ref) { r, c, a in try builder(r, c, a.0, a.1, a.2, a.3) } + } + + public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> ScopedBinding.Builder> where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + .init(scope, ref) { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3, a.arg4) } + } + + public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> ScopedBinding.Builder { + .init(scope, ref) { r, c, a in try builder(r, c, a.0, a.1, a.2, a.3, a.4) } + } + + public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> ScopedBinding.Builder> where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + .init(scope, ref) { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) } + } } public func provider(_ builder: @escaping () throws -> Type) -> SimpleBinding.Builder { @@ -94,27 +140,43 @@ public func provider(_ builder: @escaping (Resolver) throws -> Type) -> Si } public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> SimpleBinding.Builder { - .init { try builder($0, $2) } + .init { r, _, a in try builder(r, a) } } -public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> SimpleBinding.Builder> { - .init { try builder($0, $2.arg1) } +public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> SimpleBinding.Builder> where Arg1: Hashable { + .init { r, _, a in try builder(r, a.arg1) } } public func factory(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SimpleBinding.Builder { - .init { try builder($0, $2.0, $2.1) } + .init { r, _, a in try builder(r, a.0, a.1) } +} + +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SimpleBinding.Builder> where Arg1: Hashable, Arg2: Hashable { + .init { r, _, a in try builder(r, a.arg1, a.arg2) } } public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SimpleBinding.Builder { - .init { try builder($0, $2.0, $2.1, $2.2) } + .init { r, _, a in try builder(r, a.0, a.1, a.2) } +} + +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SimpleBinding.Builder> where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + .init { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3) } } public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SimpleBinding.Builder { - SimpleBinding.Builder { try builder($0, $2.0, $2.1, $2.2, $2.3) } + .init { r, _, a in try builder(r, a.0, a.1, a.2, a.3) } +} + +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SimpleBinding.Builder> where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + .init { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3, a.arg4) } } public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SimpleBinding.Builder { - SimpleBinding.Builder { try builder($0, $2.0, $2.1, $2.2, $2.3, $2.4) } + .init { r, _, a in try builder(r, a.0, a.1, a.2, a.3, a.4) } +} + +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SimpleBinding.Builder> where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + .init { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) } } public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping () throws -> Type) -> ScopedBinding.Builder { @@ -126,25 +188,43 @@ public func singleton(ref: @escaping ReferenceMaker = strongRef, _ b } public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1) throws -> Type) -> ScopedBinding.Builder { - .init(.root, ref) { try builder($0, $2) } + .init(.root, ref) { r, _, a in try builder(r, a) } } -public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1) throws -> Type) -> ScopedBinding.Builder> { - .init(.root, ref) { try builder($0, $2.arg1) } +public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1) throws -> Type) -> ScopedBinding.Builder> where Arg1: Hashable { + .init(.root, ref) { r, _, a in try builder(r, a.arg1) } } public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> ScopedBinding.Builder { - .init(.root, ref) { try builder($0, $2.0, $2.1) } + .init(.root, ref) { r, _, a in try builder(r, a.0, a.1) } +} + +public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> ScopedBinding.Builder> where Arg1: Hashable, Arg2: Hashable { + .init(.root, ref) { r, _, a in try builder(r, a.arg1, a.arg2) } } public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> ScopedBinding.Builder { - .init(.root, ref) { try builder($0, $2.0, $2.1, $2.2) } + .init(.root, ref) { r, _, a in try builder(r, a.0, a.1, a.2) } +} + +public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> ScopedBinding.Builder> where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + .init(.root, ref) { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3) } } public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> ScopedBinding.Builder { - .init(.root, ref) { try builder($0, $2.0, $2.1, $2.2, $2.3) } + .init(.root, ref) { r, _, a in try builder(r, a.0, a.1, a.2, a.3) } +} + +public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> ScopedBinding.Builder> where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + .init(.root, ref) { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3, a.arg4) } } public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> ScopedBinding.Builder { - .init(.root, ref) { try builder($0, $2.0, $2.1, $2.2, $2.3, $2.4) } + .init(.root, ref) { r, _, a in try builder(r, a.0, a.1, a.2, a.3, a.4) } } + +public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> ScopedBinding.Builder> where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + .init(.root, ref) { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) } +} + +// sourcery:end diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index e7d6a37b..359c716b 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -86,6 +86,7 @@ 4347EE17D0C0ED574C899D85 /* ScopeRegistryKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */; }; 43A74237D8933572BAA0F3B4 /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; 4415F3731760950C06EF2CBA /* Closable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D0BCCCD61CD9BECC29E064 /* Closable.swift */; }; + 44F458F61B21D78A91664160 /* BinderVariation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E0C3E4D518BC1FEF3EF8D33 /* BinderVariation.swift */; }; 45D57E61D4774613F2DF1CCA /* SwinjectSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9527A4CA5BCBA7AFA3596757 /* SwinjectSpec.swift */; }; 48D1568CB41BE4B6597FD535 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; 48F40377D116C6B1B786C329 /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; @@ -140,6 +141,7 @@ 6FCCBA9D2E4C2A225CB1A152 /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */; }; 703F8B3AD111A6CFAFF66A49 /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; 708E1C453CBC76ED26FA2FCB /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; + 70BAF056528B2B33B3A65E9D /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A006CC804F9AB8ACC121029 /* Utils.swift */; }; 71895EBC0803EEE3BFCD7001 /* Resolver+Injection.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 01DEC4D20CE554C9DFBD0A8D /* Resolver+Injection.swifttemplate */; }; 72217E47D83C3CA6D97640B9 /* StandardScopeRegistrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */; }; 725EF35B0CC5E62791D5EA09 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 34AFFAC41BA9D02A38BDB7A3 /* Nimble.framework */; }; @@ -157,6 +159,7 @@ 7CABC0D9C2F99BC37CC85517 /* ScopeRegistryKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2902FD4C1A50263340A51FFB /* ScopeRegistryKeySpec.swift */; }; 7D0683F36CE56228AC2CD489 /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C074BAC560F277E806146C60 /* SimpleBinding.swift */; }; 7D6F664091C70BABBFB61D53 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; + 7E3C3E6FD07F3BD76024770A /* InjectionVariation.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C516EFA0CA22D19F07B27E /* InjectionVariation.swift */; }; 8016512839FE61EC3127E489 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */; }; 811BA1018E9BF86A7DEB728F /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */; }; 820307073A53AED47AC99B8D /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3586A4987B7C7C8122D674E /* SwinjectError.swift */; }; @@ -247,6 +250,7 @@ BE6C13A3492E3CFC08E231B0 /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADA1541ABC1365DFD7E3377F /* Food.swift */; }; BE94EF7BCF976A703F961389 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */; }; BEEFBE87EB17D56BA8D47358 /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 351C4221896DDB8572BD6CB5 /* Person.swift */; }; + BEFFC7B36FE5810169C81B97 /* BinderEnvironment.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 26EEC28683E4A26B3092E8BA /* BinderEnvironment.swifttemplate */; }; BFE22F9F2E88F177302E9D19 /* Container+Registration.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */; }; C1687ACA897DEFD3A8197CCD /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; C177D9C6969ADA38C1094F6D /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */; }; @@ -310,7 +314,6 @@ EBC64A1515C868E410C83451 /* SwiftCode.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 90191C25A2D66E07C4E9CD73 /* SwiftCode.swifttemplate */; }; ED6CB3935B15F30A182ED6D0 /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61EE5DDBE705B47AFC9A6986 /* LoadAwareAssembly.swift */; }; EE0D3637D2524AC1CD21780D /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 74DE57FB3E8228904E6FE0D7 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; - EE2D25BFC6AFEBB13821A0E3 /* InjectionVariation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57636955DECC4A134243CE76 /* InjectionVariation.swift */; }; EE35DF2D353E2C5110DA5C42 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; EEAD7E215908DF939ECCDCC9 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; EF79F0B3D497215D4BBBC038 /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92B8E618A08408404FB2A7A /* TypeBinder.swift */; }; @@ -448,7 +451,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 01DEC4D20CE554C9DFBD0A8D /* Resolver+Injection.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+Injection.swifttemplate"; sourceTree = ""; }; + 01DEC4D20CE554C9DFBD0A8D /* Resolver+Injection.swifttemplate */ = {isa = PBXFileReference; path = "Resolver+Injection.swifttemplate"; sourceTree = ""; }; 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.swift; sourceTree = ""; }; 09FC792715B1658721F76885 /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 0CA449690AE00F6300DE8ACA /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -456,17 +459,20 @@ 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopedBindingSpec.swift; sourceTree = ""; }; 0E0B580B43E1891812C97209 /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; 10480F2154EAA0414D4C1F55 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .swiftlint.yml; sourceTree = ""; }; + 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */ = {isa = PBXFileReference; path = .swiftlint.yml; sourceTree = ""; }; 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SynchronizedResolverSpec.swift; sourceTree = ""; }; 13513FA012659ADE699A3608 /* LazySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LazySpec.swift; sourceTree = ""; }; 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleBindingSpec.swift; sourceTree = ""; }; + 1A006CC804F9AB8ACC121029 /* Utils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = ""; }; 1B3797A6BB56AE76CEC19F2A /* SwinjectApiSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectApiSpec.swift; sourceTree = ""; }; 1C58FC14EEA170B0DC079DE4 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Circularity.swift; sourceTree = ""; }; 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Behavior.swift; sourceTree = ""; }; 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Arguments.swift; sourceTree = ""; }; + 26EEC28683E4A26B3092E8BA /* BinderEnvironment.swifttemplate */ = {isa = PBXFileReference; path = BinderEnvironment.swifttemplate; sourceTree = ""; }; 273FB7A6277E0841E1570990 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; 2902FD4C1A50263340A51FFB /* ScopeRegistryKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistryKeySpec.swift; sourceTree = ""; }; + 2E0C3E4D518BC1FEF3EF8D33 /* BinderVariation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderVariation.swift; sourceTree = ""; }; 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; 34AFFAC41BA9D02A38BDB7A3 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; 351C4221896DDB8572BD6CB5 /* Person.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Person.swift; sourceTree = ""; }; @@ -478,7 +484,7 @@ 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaggedTypeSpec.swift; sourceTree = ""; }; 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingKeySpec.swift; sourceTree = ""; }; 42490D1D0C395951243F5CFF /* Container.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.swift; sourceTree = ""; }; - 4286F98133270A36F19E5CD0 /* AutoMockable.stencil */ = {isa = PBXFileReference; lastKnownFileType = text; path = AutoMockable.stencil; sourceTree = ""; }; + 4286F98133270A36F19E5CD0 /* AutoMockable.stencil */ = {isa = PBXFileReference; path = AutoMockable.stencil; sourceTree = ""; }; 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmploymentAssembly.swift; sourceTree = ""; }; 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTree.swift; sourceTree = ""; }; 494AA2AA587975747596C157 /* ProviderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProviderSpec.swift; sourceTree = ""; }; @@ -486,7 +492,6 @@ 4BC5108ED11A3A3084D864CC /* Animal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Animal.swift; sourceTree = ""; }; 4D31F8718D2E847922530C20 /* Templates.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Templates.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 5057BAB33984E3E33469452B /* Scope.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Scope.swift; sourceTree = ""; }; - 57636955DECC4A134243CE76 /* InjectionVariation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InjectionVariation.swift; sourceTree = ""; }; 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Resolver+Injection.swift"; sourceTree = ""; }; 59111BE319C59E4CD6CF68CD /* Assembler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Assembler.swift; sourceTree = ""; }; 5AB605ED0F735221D0EB1D5F /* Convenience.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Convenience.swift; sourceTree = ""; }; @@ -508,13 +513,13 @@ 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ServiceEntry+TypeForwarding.swift"; sourceTree = ""; }; 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextTranslator.swift; sourceTree = ""; }; 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistry.swift; sourceTree = ""; }; - 808C1063CA90CC593C7E0E9C /* MatchableBoxes.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = MatchableBoxes.swifttemplate; sourceTree = ""; }; + 808C1063CA90CC593C7E0E9C /* MatchableBoxes.swifttemplate */ = {isa = PBXFileReference; path = MatchableBoxes.swifttemplate; sourceTree = ""; }; 823617F3B8A9192F56B13331 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; 841D83ADB41363D1E38087B4 /* NonGeneratedMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonGeneratedMocks.swift; sourceTree = ""; }; 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeneratedMocks.swift; sourceTree = ""; }; 8B9785AAE94A5447FA307242 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTreeBuilderSpec.swift; sourceTree = ""; }; - 90191C25A2D66E07C4E9CD73 /* SwiftCode.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = SwiftCode.swifttemplate; sourceTree = ""; }; + 90191C25A2D66E07C4E9CD73 /* SwiftCode.swifttemplate */ = {isa = PBXFileReference; path = SwiftCode.swifttemplate; sourceTree = ""; }; 9527A4CA5BCBA7AFA3596757 /* SwinjectSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectSpec.swift; sourceTree = ""; }; 9620155728133F451B31C0AD /* Swinject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Swinject.swift; sourceTree = ""; }; 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistryKey.swift; sourceTree = ""; }; @@ -531,14 +536,15 @@ B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderEnvironment.swift; sourceTree = ""; }; B92B8E618A08408404FB2A7A /* TypeBinder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinder.swift; sourceTree = ""; }; BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StandardScopeRegistrySpec.swift; sourceTree = ""; }; - BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "ServiceEntry+TypeForwarding.swifttemplate"; sourceTree = ""; }; + BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */ = {isa = PBXFileReference; path = "ServiceEntry+TypeForwarding.swifttemplate"; sourceTree = ""; }; BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Behavior.swift; sourceTree = ""; }; C074BAC560F277E806146C60 /* SimpleBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleBinding.swift; sourceTree = ""; }; + C3C516EFA0CA22D19F07B27E /* InjectionVariation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InjectionVariation.swift; sourceTree = ""; }; C765B92B00C0AC8625BB4AC9 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; CADDB3E9E363310028AA5920 /* InstanceMaker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceMaker.swift; sourceTree = ""; }; CC85CB215058F95C0BC190B1 /* Bridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bridge.swift; sourceTree = ""; }; CDA78290D6D60BD0B808571F /* Container+Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Logging.swift"; sourceTree = ""; }; - CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; + CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRequest.swift; sourceTree = ""; }; E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; EDA62EEBC79ED2639C93A76B /* TypeBinderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinderSpec.swift; sourceTree = ""; }; @@ -547,7 +553,7 @@ F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.TypeForwarding.swift; sourceTree = ""; }; FCAF491EC7DCD7477F9A0ECB /* SwinjectModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectModule.swift; sourceTree = ""; }; FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderEnvironmentSpec.swift; sourceTree = ""; }; - FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+LegacyApi.swifttemplate"; sourceTree = ""; }; + FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */ = {isa = PBXFileReference; path = "Resolver+LegacyApi.swifttemplate"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -598,13 +604,16 @@ isa = PBXGroup; children = ( 4286F98133270A36F19E5CD0 /* AutoMockable.stencil */, + 26EEC28683E4A26B3092E8BA /* BinderEnvironment.swifttemplate */, + 2E0C3E4D518BC1FEF3EF8D33 /* BinderVariation.swift */, CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */, + C3C516EFA0CA22D19F07B27E /* InjectionVariation.swift */, 808C1063CA90CC593C7E0E9C /* MatchableBoxes.swifttemplate */, 01DEC4D20CE554C9DFBD0A8D /* Resolver+Injection.swifttemplate */, FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */, BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */, 90191C25A2D66E07C4E9CD73 /* SwiftCode.swifttemplate */, - 57636955DECC4A134243CE76 /* InjectionVariation.swift */, + 1A006CC804F9AB8ACC121029 /* Utils.swift */, ); path = Templates; sourceTree = ""; @@ -1129,6 +1138,7 @@ buildActionMask = 2147483647; files = ( CB9666A26D85B92BA1357160 /* AutoMockable.stencil in Resources */, + BEFFC7B36FE5810169C81B97 /* BinderEnvironment.swifttemplate in Resources */, BFE22F9F2E88F177302E9D19 /* Container+Registration.swifttemplate in Resources */, 1C82BFD00FCC384DB3AE6A89 /* MatchableBoxes.swifttemplate in Resources */, 71895EBC0803EEE3BFCD7001 /* Resolver+Injection.swifttemplate in Resources */, @@ -1424,7 +1434,9 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - EE2D25BFC6AFEBB13821A0E3 /* InjectionVariation.swift in Sources */, + 44F458F61B21D78A91664160 /* BinderVariation.swift in Sources */, + 7E3C3E6FD07F3BD76024770A /* InjectionVariation.swift in Sources */, + 70BAF056528B2B33B3A65E9D /* Utils.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1843,11 +1855,7 @@ "$(PROJECT_DIR)/Carthage/Build/iOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -1885,10 +1893,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; PRODUCT_NAME = Swinject; SDKROOT = macosx; SKIP_INSTALL = YES; @@ -1905,11 +1910,7 @@ "$(PROJECT_DIR)/Carthage/Build/tvOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = appletvos; TARGETED_DEVICE_FAMILY = 3; @@ -1927,10 +1928,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = Swinject; SDKROOT = appletvos; SKIP_INSTALL = YES; @@ -1948,11 +1946,7 @@ "$(PROJECT_DIR)/Carthage/Build/iOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -1969,11 +1963,7 @@ "$(PROJECT_DIR)/Carthage/Build/Mac", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - "@loader_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = macosx; }; @@ -2063,10 +2053,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = Swinject; SDKROOT = appletvos; SKIP_INSTALL = YES; @@ -2084,11 +2071,7 @@ "$(PROJECT_DIR)/Carthage/Build/watchOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = watchos; SKIP_INSTALL = YES; @@ -2107,10 +2090,7 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; SDKROOT = macosx; SKIP_INSTALL = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -2128,10 +2108,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = Swinject; SDKROOT = iphoneos; SKIP_INSTALL = YES; @@ -2149,11 +2126,7 @@ "$(PROJECT_DIR)/Carthage/Build/watchOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = watchos; SKIP_INSTALL = YES; @@ -2171,11 +2144,7 @@ "$(PROJECT_DIR)/Carthage/Build/Mac", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - "@loader_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = macosx; }; @@ -2190,11 +2159,7 @@ "$(PROJECT_DIR)/Carthage/Build/tvOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = appletvos; TARGETED_DEVICE_FAMILY = 3; @@ -2212,10 +2177,7 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; SDKROOT = macosx; SKIP_INSTALL = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -2234,10 +2196,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; PRODUCT_NAME = Swinject; SDKROOT = macosx; SKIP_INSTALL = YES; @@ -2256,10 +2215,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = Swinject; SDKROOT = iphoneos; SKIP_INSTALL = YES; diff --git a/Templates/BinderEnvironment.swifttemplate b/Templates/BinderEnvironment.swifttemplate new file mode 100644 index 00000000..69448d3f --- /dev/null +++ b/Templates/BinderEnvironment.swifttemplate @@ -0,0 +1,12 @@ +<%- include("SwiftCode") %> +// sourcery:inline:BindingBuilders +extension BinderEnvironment where AScope == Void { +<%= BinderVariation.publicCases.filter { $0.isContexted && !$0.isScoped }.map { $0.render(true) }.joined(separator: "\n\n") %> +} + +extension BinderEnvironment where AScope: Scope, Context == AScope.Context { +<%= BinderVariation.publicCases.filter { $0.isContexted && $0.isScoped }.map { $0.render(true) }.joined(separator: "\n\n") %> +} + +<%= BinderVariation.publicCases.filter { !$0.isContexted }.map { $0.render(false) }.joined(separator: "\n\n") %> +// sourcery:end diff --git a/Templates/BinderVariation.swift b/Templates/BinderVariation.swift new file mode 100644 index 00000000..284b77e2 --- /dev/null +++ b/Templates/BinderVariation.swift @@ -0,0 +1,150 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +struct BinderVariation { + let args: Int + let hasResolver: Bool + let hasContext: Bool + let isMatchable: Bool + let isScoped: Bool + let isContexted: Bool +} + +extension BinderVariation { + var argTypes: String { + join((1 ..< args + 1).map { "Arg\($0)" }) + } + + var argTypesOrNil: String? { + argTypes.isEmpty ? nil : argTypes + } + + var genericTypes: String { + join("Type", argTypesOrNil) + } + + var builderInputTypes: String { + join( + hasResolver ? "Resolver" : nil, + hasContext ? "Context" : nil, + argTypesOrNil + ) + } + + var params: String { + join( + isScoped ? "ref: @escaping ReferenceMaker = strongRef" : nil, + "_ builder: @escaping (\(builderInputTypes)) throws -> Type" + ) + } + + var scopeType: String { + isContexted ? "AScope" : "UnboundScope" + } + + var scopeVar: String { + isContexted ? "scope" : ".root" + } + + var contextType: String { + isContexted ? "Context" : "Any" + } + + var argReturnType: String { + switch args { + case 0: return "Void" + case 1: return isMatchable ? "MatchableBox1" : "Arg1" + default: return isMatchable ? "MatchableBox\(args)<\(argTypes)>" : "(\(argTypes))" + } + } + + var returnType: String { + if isScoped { + return "ScopedBinding.Builder" + } else { + return "SimpleBinding.Builder" + } + } + + var hashableArgTypes: String { + join((1 ..< args + 1).map { "Arg\($0): Hashable" }) + } + + var constraints: String { + isMatchable && args > 0 ? "where \(hashableArgTypes) " : "" + } + + var functionName: String { + switch (isScoped, args > 0) { + case (true, true): return "multiton" + case (true, false): return "singleton" + case (false, true): return "factory" + case (false, false): return "provider" + } + } + + var initVars: String { + isScoped ? "(\(join(scopeVar, "ref")))" : "" + } + + var argVarsOrNil: String? { + switch args { + case 0: return nil + case 1: return isMatchable ? "a.arg1" : "a" + default: return join((1 ... args).map { isMatchable ? "a.arg\($0)" : "a.\($0 - 1)" }) + } + } + + var builderInputs: String { + join( + hasResolver ? "r" : "_", + hasContext ? "c" : "_", + args > 0 ? "a" : "_" + ) + } + + var builderVars: String { + join( + hasResolver ? "r" : nil, + hasContext ? "c" : nil, + argVarsOrNil + ) + } +} + +extension BinderVariation { + static let maxArgs = 5 + + static let allCases = (0 ... maxArgs) + .flatMap { t in [false, true].map { (t, $0) } } + .flatMap { t in [false, true].map { (t.0, t.1, $0) } } + .flatMap { t in [false, true].map { (t.0, t.1, t.2, $0) } } + .flatMap { t in [false, true].map { (t.0, t.1, t.2, t.3, $0) } } + .flatMap { t in [false, true].map { (t.0, t.1, t.2, t.3, t.4, $0) } } + .map(BinderVariation.init) + + static let sortedCases = allCases.sorted { [ + !$0.isScoped && $1.isScoped, + $0.args < $1.args, + !$0.isMatchable && $1.isMatchable && $0.args == $1.args, + ].contains(true) } + + static let publicCases = sortedCases + .filter { !($0.hasContext && !$0.isContexted) } + .filter { !($0.hasContext && !$0.hasResolver) } + .filter { !($0.args == 0 && !$0.isMatchable) } + .filter { !($0.args > 0 && !$0.hasResolver) } + .filter { !($0.args > 0 && $0.isContexted && !$0.hasContext) } +} + +extension BinderVariation { + func render(_ indent: Bool) -> String { + let prefix = indent ? " " : "" + return """ + \(prefix)public func \(functionName)<\(genericTypes)>(\(params)) -> \(returnType) \(constraints){ + \(prefix) .init\(initVars) { \(builderInputs) in try builder(\(builderVars)) } + \(prefix)} + """ + } +} diff --git a/Templates/Container+Registration.swifttemplate b/Templates/Container+Registration.swifttemplate index 3d1f28c1..329cac86 100644 --- a/Templates/Container+Registration.swifttemplate +++ b/Templates/Container+Registration.swifttemplate @@ -44,8 +44,7 @@ extension Container { let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef(in: self)) { (r, _, a: <%= arg_closure_type %>) in factory(r, <%= arg_vars %>) } addEntry(entry, with: name) return entry - } - + }<%= i < arg_count ? "\n" : "" %> <%_ } -%> } // sourcery:end diff --git a/Templates/InjectionVariation.swift b/Templates/InjectionVariation.swift index 90cac50c..77c3e505 100644 --- a/Templates/InjectionVariation.swift +++ b/Templates/InjectionVariation.swift @@ -1,58 +1,112 @@ -// swiftformat:disable fileHeader -let maxArgs = 5 +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// struct InjectionVariation { - let isTagged: Bool let paramArgs: Int let factoryArgs: Int + let isTagged: Bool let isMatchable: Bool - var args: Int { return paramArgs + factoryArgs } + let isDelayed: Bool } extension InjectionVariation { - var genericTypes: String { [ - "Type", - isTagged ? "Tag" : nil, - args > 0 ? (1 ... args).map { "Arg\($0)" }.joined(separator: ", ") : nil, - ].compactMap { $0 }.joined(separator: ", ") } - - var params: String { [ - "of _: Type.Type = Type.self", - isTagged ? "tagged tag: Tag" : nil, - paramArgs >= 1 ? "arg " + (1 ... paramArgs).map { "arg\($0): Arg\($0)" }.joined(separator: ", _ ") : nil, - ].compactMap { $0 }.joined(separator: ", ") } + var args: Int { return paramArgs + factoryArgs } + + var genericTypes: String { + join( + "Type", + isTagged ? "Tag" : nil, + args > 0 ? join((1 ... args).map { "Arg\($0)" }) : nil + ) + } + + var params: String { + join( + "of _: Type.Type = Type.self", + isTagged ? "tagged tag: Tag" : nil, + paramArgs >= 1 ? "arg " + join(separator: ", _ ", (1 ... paramArgs).map { "arg\($0): Arg\($0)" }) : nil + ) + } var factoryInputs: String { - (1 ... factoryArgs).map { "Arg\($0 + paramArgs)" }.joined(separator: ", ") + join((1 ..< factoryArgs + 1).map { "Arg\($0 + paramArgs)" }) } - var constraints: String { [ - isTagged ? "Tag: Hashable" : nil, - isMatchable && args > 0 ? (1 ... args).map { "Arg\($0): Hashable" }.joined(separator: ", ") : nil, - ].compactMap { $0 }.joined(separator: ", ") } + var constraints: String { + join( + isTagged ? "Tag: Hashable" : nil, + isMatchable && args > 0 ? join((1 ... args).map { "Arg\($0): Hashable" }) : nil + ) + } - var whereClause: String { constraints.isEmpty ? "" : "where " + constraints } + var whereClause: String? { + constraints.isEmpty ? nil : "where " + constraints + } var requestParams: String { let paramVars = (0 ..< paramArgs).map { "arg\($0 + 1)" } let factoryVars = (0 ..< factoryArgs).map { "$\($0)" } - return [ + return join( isTagged ? "tag: tag" : "tag: NoTag()", - args == 0 ? "arg: ()" : "arg: box(\((paramVars + factoryVars).joined(separator: ", ")))", - ].compactMap { $0 }.joined(separator: ", ") + args == 0 ? "arg: ()" : "arg: box(\(join(paramVars + factoryVars)))" + ) + } + + var functionName: String { + if !isDelayed { return "instance" } + else if factoryArgs == 0 { return "provider" } + else { return "factory" } + } + + var returnType: String { + if !isDelayed { + return "throws -> Type" + } else { + return "-> (\(factoryInputs)) throws -> Type" + } + } + + var returnDescription: String { + join(separator: " ", returnType, whereClause) + } + + var returnStatement: String { + if isDelayed { + return "return { try self.resolve(request(\(requestParams))) }" + } else { + return "try resolve(request(\(requestParams)))" + } } } extension InjectionVariation { - static let simpleCases = (0 ... maxArgs) - .flatMap { a in [false, true].map { ($0, a) } } - .flatMap { t in [false, true].map { (t.0, t.1, 0, $0) } } - .map { InjectionVariation(isTagged: $0.0, paramArgs: $0.1, factoryArgs: $0.2, isMatchable: $0.3) } - .filter { $0.paramArgs > 0 || $0.isMatchable } - - static let factoryCases = (1 ... maxArgs) - .flatMap { a in [false, true].map { ($0, a) } } + static let maxArgs = 5 + + static let allCases = (0 ... maxArgs) + .flatMap { t in (t ... maxArgs).map { (t, maxArgs - $0) } } .flatMap { t in [false, true].map { (t.0, t.1, $0) } } - .flatMap { t in (0 ..< t.1).map { (t.0, $0, t.1 - $0, t.2) } } - .map { InjectionVariation(isTagged: $0.0, paramArgs: $0.1, factoryArgs: $0.2, isMatchable: $0.3) } + .flatMap { t in [false, true].map { (t.0, t.1, t.2, $0) } } + .flatMap { t in [false, true].map { (t.0, t.1, t.2, t.3, $0) } } + .map(InjectionVariation.init) + + static let sortedCases = allCases.sorted { [ + $0.args < $1.args, + !$0.isTagged && $1.isTagged && $0.args == $1.args, + !$0.isMatchable && $1.isMatchable && $0.args == $1.args && $0.isTagged == $1.isTagged, + ].contains(true) } + + static let publicCases = sortedCases + .filter { !($0.args == 0 && !$0.isMatchable) } + .filter { !($0.factoryArgs > 0 && !$0.isDelayed) } +} + +extension InjectionVariation { + func render() -> String { + """ + func \(functionName)<\(genericTypes)>(\(params)) \(returnDescription) { + \(returnStatement) + } + """ + } } diff --git a/Templates/MatchableBoxes.swifttemplate b/Templates/MatchableBoxes.swifttemplate index 72f93225..07c21033 100644 --- a/Templates/MatchableBoxes.swifttemplate +++ b/Templates/MatchableBoxes.swifttemplate @@ -5,7 +5,7 @@ let arg_hashables = (1...i).map { "Arg\($0): Hashable" }.joined(separator: ", ") let type_name = "MatchableBox\(i)<\(arg_types)>" -%> -public struct <%= type_name %>: Hashable, Matchable where <%= arg_hashables %>{ +public struct <%= type_name %>: Hashable, Matchable where <%= arg_hashables %> { <%= (1...i).map { "let arg\($0): Arg\($0)" }.joined(separator: "\n ") %> } diff --git a/Templates/Resolver+Injection.swifttemplate b/Templates/Resolver+Injection.swifttemplate index 3dcd285f..bc542e90 100644 --- a/Templates/Resolver+Injection.swifttemplate +++ b/Templates/Resolver+Injection.swifttemplate @@ -1,29 +1,14 @@ <%- include("SwiftCode") %> // sourcery:inline:ResolverInjectionApi extension Resolver { -<%_ InjectionVariation.simpleCases.forEach { v in -%> - func instance<<%= v.genericTypes %>>(<%= v.params %>) throws -> Type <%= v.whereClause %>{ - try resolve(request(<%= v.requestParams %>)) - } - -<%_ } -%> +<%= InjectionVariation.publicCases.filter { $0.functionName == "instance" }.map { $0.render() }.joined(separator: "\n\n") %> } extension Resolver { -<%_ InjectionVariation.simpleCases.forEach { v in -%> - func provider<<%= v.genericTypes %>>(<%= v.params %>) -> () throws -> Type <%= v.whereClause %>{ - return { try self.resolve(request(<%= v.requestParams %>)) } - } - -<%_ } -%> +<%= InjectionVariation.publicCases.filter { $0.functionName == "provider" }.map { $0.render() }.joined(separator: "\n\n") %> } extension Resolver { -<%_ InjectionVariation.factoryCases.forEach { v in -%> - func factory<<%= v.genericTypes %>>(<%= v.params %>) -> (<%= v.factoryInputs %>) throws -> Type <%= v.whereClause %>{ - return { try self.resolve(request(<%= v.requestParams %>)) } - } - -<%_ } -%> +<%= InjectionVariation.publicCases.filter { $0.functionName == "factory" }.map { $0.render() }.joined(separator: "\n\n") %> } // sourcery:end diff --git a/Templates/Resolver+LegacyApi.swifttemplate b/Templates/Resolver+LegacyApi.swifttemplate index 343d5af6..e86edd89 100644 --- a/Templates/Resolver+LegacyApi.swifttemplate +++ b/Templates/Resolver+LegacyApi.swifttemplate @@ -38,8 +38,7 @@ public extension Resolver { } else { return try? resolve(request(type: serviceType, tag: NoTag(), arg: <%= arg_vars %>)) } - } - + }<%= i < arg_count ? "\n" : "" %> <%_ } -%> } // sourcery:end diff --git a/Templates/ServiceEntry+TypeForwarding.swifttemplate b/Templates/ServiceEntry+TypeForwarding.swifttemplate index e63e8da8..1ce0ec04 100644 --- a/Templates/ServiceEntry+TypeForwarding.swifttemplate +++ b/Templates/ServiceEntry+TypeForwarding.swifttemplate @@ -25,8 +25,7 @@ extension ServiceEntry { @discardableResult public func implements<<%= types %>>(<%= params %>) -> ServiceEntry { return <%= (1...i).map { "implements(type\($0))" }.joined(separator: ".") %> - } - + }<%= i < type_count ? "\n" : "" %> <%_ } -%> } // sourcery:end diff --git a/Templates/SwiftCode.swifttemplate b/Templates/SwiftCode.swifttemplate index ece514d5..53e607ae 100644 --- a/Templates/SwiftCode.swifttemplate +++ b/Templates/SwiftCode.swifttemplate @@ -1,60 +1,275 @@ <% -// swiftformat:disable fileHeader -let maxArgs = 5 +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +struct BinderVariation { + let args: Int + let hasResolver: Bool + let hasContext: Bool + let isMatchable: Bool + let isScoped: Bool + let isContexted: Bool +} + +extension BinderVariation { + var argTypes: String { + join((1 ..< args + 1).map { "Arg\($0)" }) + } + + var argTypesOrNil: String? { + argTypes.isEmpty ? nil : argTypes + } + + var genericTypes: String { + join("Type", argTypesOrNil) + } + + var builderInputTypes: String { + join( + hasResolver ? "Resolver" : nil, + hasContext ? "Context" : nil, + argTypesOrNil + ) + } + + var params: String { + join( + isScoped ? "ref: @escaping ReferenceMaker = strongRef" : nil, + "_ builder: @escaping (\(builderInputTypes)) throws -> Type" + ) + } + + var scopeType: String { + isContexted ? "AScope" : "UnboundScope" + } + + var scopeVar: String { + isContexted ? "scope" : ".root" + } + + var contextType: String { + isContexted ? "Context" : "Any" + } + + var argReturnType: String { + switch args { + case 0: return "Void" + case 1: return isMatchable ? "MatchableBox1" : "Arg1" + default: return isMatchable ? "MatchableBox\(args)<\(argTypes)>" : "(\(argTypes))" + } + } + + var returnType: String { + if isScoped { + return "ScopedBinding.Builder" + } else { + return "SimpleBinding.Builder" + } + } + + var hashableArgTypes: String { + join((1 ..< args + 1).map { "Arg\($0): Hashable" }) + } + + var constraints: String { + isMatchable && args > 0 ? "where \(hashableArgTypes) " : "" + } + + var functionName: String { + switch (isScoped, args > 0) { + case (true, true): return "multiton" + case (true, false): return "singleton" + case (false, true): return "factory" + case (false, false): return "provider" + } + } + + var initVars: String { + isScoped ? "(\(join(scopeVar, "ref")))" : "" + } + + var argVarsOrNil: String? { + switch args { + case 0: return nil + case 1: return isMatchable ? "a.arg1" : "a" + default: return join((1 ... args).map { isMatchable ? "a.arg\($0)" : "a.\($0 - 1)" }) + } + } + + var builderInputs: String { + join( + hasResolver ? "r" : "_", + hasContext ? "c" : "_", + args > 0 ? "a" : "_" + ) + } + + var builderVars: String { + join( + hasResolver ? "r" : nil, + hasContext ? "c" : nil, + argVarsOrNil + ) + } +} + +extension BinderVariation { + static let maxArgs = 5 + + static let allCases = (0 ... maxArgs) + .flatMap { t in [false, true].map { (t, $0) } } + .flatMap { t in [false, true].map { (t.0, t.1, $0) } } + .flatMap { t in [false, true].map { (t.0, t.1, t.2, $0) } } + .flatMap { t in [false, true].map { (t.0, t.1, t.2, t.3, $0) } } + .flatMap { t in [false, true].map { (t.0, t.1, t.2, t.3, t.4, $0) } } + .map(BinderVariation.init) + + static let sortedCases = allCases.sorted { [ + !$0.isScoped && $1.isScoped, + $0.args < $1.args, + !$0.isMatchable && $1.isMatchable && $0.args == $1.args, + ].contains(true) } + + static let publicCases = sortedCases + .filter { !($0.hasContext && !$0.isContexted) } + .filter { !($0.hasContext && !$0.hasResolver) } + .filter { !($0.args == 0 && !$0.isMatchable) } + .filter { !($0.args > 0 && !$0.hasResolver) } + .filter { !($0.args > 0 && $0.isContexted && !$0.hasContext) } +} + +extension BinderVariation { + func render(_ indent: Bool) -> String { + let prefix = indent ? " " : "" + return """ + \(prefix)public func \(functionName)<\(genericTypes)>(\(params)) -> \(returnType) \(constraints){ + \(prefix) .init\(initVars) { \(builderInputs) in try builder(\(builderVars)) } + \(prefix)} + """ + } +} +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// struct InjectionVariation { - let isTagged: Bool let paramArgs: Int let factoryArgs: Int + let isTagged: Bool let isMatchable: Bool - var args: Int { return paramArgs + factoryArgs } + let isDelayed: Bool } extension InjectionVariation { - var genericTypes: String { [ - "Type", - isTagged ? "Tag" : nil, - args > 0 ? (1 ... args).map { "Arg\($0)" }.joined(separator: ", ") : nil, - ].compactMap { $0 }.joined(separator: ", ") } - - var params: String { [ - "of _: Type.Type = Type.self", - isTagged ? "tagged tag: Tag" : nil, - paramArgs >= 1 ? "arg " + (1 ... paramArgs).map { "arg\($0): Arg\($0)" }.joined(separator: ", _ ") : nil, - ].compactMap { $0 }.joined(separator: ", ") } + var args: Int { return paramArgs + factoryArgs } + + var genericTypes: String { + join( + "Type", + isTagged ? "Tag" : nil, + args > 0 ? join((1 ... args).map { "Arg\($0)" }) : nil + ) + } + + var params: String { + join( + "of _: Type.Type = Type.self", + isTagged ? "tagged tag: Tag" : nil, + paramArgs >= 1 ? "arg " + join(separator: ", _ ", (1 ... paramArgs).map { "arg\($0): Arg\($0)" }) : nil + ) + } var factoryInputs: String { - (1 ... factoryArgs).map { "Arg\($0 + paramArgs)" }.joined(separator: ", ") + join((1 ..< factoryArgs + 1).map { "Arg\($0 + paramArgs)" }) } - var constraints: String { [ - isTagged ? "Tag: Hashable" : nil, - isMatchable && args > 0 ? (1 ... args).map { "Arg\($0): Hashable" }.joined(separator: ", ") : nil, - ].compactMap { $0 }.joined(separator: ", ") } + var constraints: String { + join( + isTagged ? "Tag: Hashable" : nil, + isMatchable && args > 0 ? join((1 ... args).map { "Arg\($0): Hashable" }) : nil + ) + } - var whereClause: String { constraints.isEmpty ? "" : "where " + constraints } + var whereClause: String? { + constraints.isEmpty ? nil : "where " + constraints + } var requestParams: String { let paramVars = (0 ..< paramArgs).map { "arg\($0 + 1)" } let factoryVars = (0 ..< factoryArgs).map { "$\($0)" } - return [ + return join( isTagged ? "tag: tag" : "tag: NoTag()", - args == 0 ? "arg: ()" : "arg: box(\((paramVars + factoryVars).joined(separator: ", ")))", - ].compactMap { $0 }.joined(separator: ", ") + args == 0 ? "arg: ()" : "arg: box(\(join(paramVars + factoryVars)))" + ) + } + + var functionName: String { + if !isDelayed { return "instance" } + else if factoryArgs == 0 { return "provider" } + else { return "factory" } + } + + var returnType: String { + if !isDelayed { + return "throws -> Type" + } else { + return "-> (\(factoryInputs)) throws -> Type" + } + } + + var returnDescription: String { + join(separator: " ", returnType, whereClause) + } + + var returnStatement: String { + if isDelayed { + return "return { try self.resolve(request(\(requestParams))) }" + } else { + return "try resolve(request(\(requestParams)))" + } } } extension InjectionVariation { - static let simpleCases = (0 ... maxArgs) - .flatMap { a in [false, true].map { ($0, a) } } - .flatMap { t in [false, true].map { (t.0, t.1, 0, $0) } } - .map { InjectionVariation(isTagged: $0.0, paramArgs: $0.1, factoryArgs: $0.2, isMatchable: $0.3) } - .filter { $0.paramArgs > 0 || $0.isMatchable } - - static let factoryCases = (1 ... maxArgs) - .flatMap { a in [false, true].map { ($0, a) } } + static let maxArgs = 5 + + static let allCases = (0 ... maxArgs) + .flatMap { t in (t ... maxArgs).map { (t, maxArgs - $0) } } .flatMap { t in [false, true].map { (t.0, t.1, $0) } } - .flatMap { t in (0 ..< t.1).map { (t.0, $0, t.1 - $0, t.2) } } - .map { InjectionVariation(isTagged: $0.0, paramArgs: $0.1, factoryArgs: $0.2, isMatchable: $0.3) } + .flatMap { t in [false, true].map { (t.0, t.1, t.2, $0) } } + .flatMap { t in [false, true].map { (t.0, t.1, t.2, t.3, $0) } } + .map(InjectionVariation.init) + + static let sortedCases = allCases.sorted { [ + $0.args < $1.args, + !$0.isTagged && $1.isTagged && $0.args == $1.args, + !$0.isMatchable && $1.isMatchable && $0.args == $1.args && $0.isTagged == $1.isTagged, + ].contains(true) } + + static let publicCases = sortedCases + .filter { !($0.args == 0 && !$0.isMatchable) } + .filter { !($0.factoryArgs > 0 && !$0.isDelayed) } +} + +extension InjectionVariation { + func render() -> String { + """ + func \(functionName)<\(genericTypes)>(\(params)) \(returnDescription) { + \(returnStatement) + } + """ + } +} +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +func join(separator: String = ", ", _ strings: String? ...) -> String { + join(separator: separator, strings) +} + +func join(separator: String = ", ", _ strings: [String?]) -> String { + strings.compactMap { $0 }.joined(separator: separator) } %> diff --git a/Templates/Utils.swift b/Templates/Utils.swift new file mode 100644 index 00000000..bacb4570 --- /dev/null +++ b/Templates/Utils.swift @@ -0,0 +1,11 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +func join(separator: String = ", ", _ strings: String? ...) -> String { + join(separator: separator, strings) +} + +func join(separator: String = ", ", _ strings: [String?]) -> String { + strings.compactMap { $0 }.joined(separator: separator) +} diff --git a/Tests/Support/GeneratedMocks.swift b/Tests/Support/GeneratedMocks.swift index 5329aa32..d66c943a 100644 --- a/Tests/Support/GeneratedMocks.swift +++ b/Tests/Support/GeneratedMocks.swift @@ -372,3 +372,5 @@ class StaticScopeRegistryMock: StaticScopeRegistry { + + diff --git a/Tests/Unit Specs/BinderEnvironmentSpec.swift b/Tests/Unit Specs/BinderEnvironmentSpec.swift index 55bf1629..2950e529 100644 --- a/Tests/Unit Specs/BinderEnvironmentSpec.swift +++ b/Tests/Unit Specs/BinderEnvironmentSpec.swift @@ -91,22 +91,22 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { describe("multiple arguments") { it("works with 2 arguments") { let maker = factory { (_, _: Int, _: Double) in 42 } - let arguments = (1, 1.0) + let arguments = box(1, 1.0) expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 } it("works with 3 arguments") { let maker = factory { (_, _: Int, _: Double, _: String) in 42 } - let arguments = (1, 1.0, "") + let arguments = box(1, 1.0, "") expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 } it("works with 4 arguments") { let maker = factory { (_, _: Int, _: Double, _: String, _: Float) in 42 } - let arguments = (1, 1.0, "", Float(1.0)) + let arguments = box(1, 1.0, "", Float(1.0)) expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 } it("works with 5 arguments") { let maker = factory { (_, _: Int, _: Double, _: String, _: Float, _: Int) in 42 } - let arguments = (1, 1.0, "", Float(1.0), 5) + let arguments = box(1, 1.0, "", Float(1.0), 5) expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 } } @@ -193,22 +193,22 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { describe("multiple arguments") { it("works with 2 arguments") { let maker = multiton { (_, _: Int, _: Double) in 42 } - let arguments = (1, 1.0) + let arguments = box(1, 1.0) expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 } it("works with 3 arguments") { let maker = multiton { (_, _: Int, _: Double, _: String) in 42 } - let arguments = (1, 1.0, "") + let arguments = box(1, 1.0, "") expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 } it("works with 4 arguments") { let maker = multiton { (_, _: Int, _: Double, _: String, _: Float) in 42 } - let arguments = (1, 1.0, "", Float(1.0)) + let arguments = box(1, 1.0, "", Float(1.0)) expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 } it("works with 5 arguments") { let maker = multiton { (_, _: Int, _: Double, _: String, _: Float, _: Int) in 42 } - let arguments = (1, 1.0, "", Float(1.0), 5) + let arguments = box(1, 1.0, "", Float(1.0), 5) expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 } } @@ -279,7 +279,7 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { it("calls builder with given argument") { var passedArgument: Int? let maker = environment.factory { (_, _, arg: Int) in passedArgument = arg } - _ = try? maker.makeInstance(arg: 42, resolver: DummyResolver()) + _ = try? maker.makeInstance(arg: box(42), resolver: DummyResolver()) expect(passedArgument) == 42 } it("rethrows error from builder") { @@ -295,22 +295,22 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { describe("multiple arguments") { it("works with 2 arguments") { let maker = environment.factory { (_, _, _: Int, _: Double) in 42 } - let arguments = (1, 1.0) + let arguments = box(1, 1.0) expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 } it("works with 3 arguments") { let maker = environment.factory { (_, _, _: Int, _: Double, _: String) in 42 } - let arguments = (1, 1.0, "") + let arguments = box(1, 1.0, "") expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 } it("works with 4 arguments") { let maker = environment.factory { (_, _, _: Int, _: Double, _: String, _: Float) in 42 } - let arguments = (1, 1.0, "", Float(1.0)) + let arguments = box(1, 1.0, "", Float(1.0)) expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 } it("works with 5 arguments") { let maker = environment.factory { (_, _, _: Int, _: Double, _: String, _: Float, _: Int) in 42 } - let arguments = (1, 1.0, "", Float(1.0), 5) + let arguments = box(1, 1.0, "", Float(1.0), 5) expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 } } @@ -391,7 +391,7 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { it("calls builder with given argument") { var passedArgument: Int? let maker = environment.multiton { (_, _, arg: Int) in passedArgument = arg } - _ = try? maker.makeInstance(arg: 42, resolver: DummyResolver()) + _ = try? maker.makeInstance(arg: box(42), resolver: DummyResolver()) expect(passedArgument) == 42 } it("rethrows error from builder") { @@ -407,22 +407,22 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { describe("multiple arguments") { it("works with 2 arguments") { let maker = environment.multiton { (_, _, _: Int, _: Double) in 42 } - let arguments = (1, 1.0) + let arguments = box(1, 1.0) expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 } it("works with 3 arguments") { let maker = environment.multiton { (_, _, _: Int, _: Double, _: String) in 42 } - let arguments = (1, 1.0, "") + let arguments = box(1, 1.0, "") expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 } it("works with 4 arguments") { let maker = environment.multiton { (_, _, _: Int, _: Double, _: String, _: Float) in 42 } - let arguments = (1, 1.0, "", Float(1.0)) + let arguments = box(1, 1.0, "", Float(1.0)) expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 } it("works with 5 arguments") { let maker = environment.multiton { (_, _, _: Int, _: Double, _: String, _: Float, _: Int) in 42 } - let arguments = (1, 1.0, "", Float(1.0), 5) + let arguments = box(1, 1.0, "", Float(1.0), 5) expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 } } From 363cf46f3be94c8b29405ba0634ecdabc0098ca4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sat, 27 Jul 2019 12:42:57 +0200 Subject: [PATCH 144/239] Remove api for creating multitons with non-matchable arguments --- Sources/3.0 API/BinderEnvironment.swift | 40 ---------------- Templates/BinderVariation.swift | 1 + Templates/SwiftCode.swifttemplate | 1 + Tests/Support/NonGeneratedMocks.swift | 7 +++ Tests/Unit Specs/BinderEnvironmentSpec.swift | 48 ++++++++++---------- Tests/Unit Specs/SwinjectSpec.swift | 22 ++++----- 6 files changed, 44 insertions(+), 75 deletions(-) diff --git a/Sources/3.0 API/BinderEnvironment.swift b/Sources/3.0 API/BinderEnvironment.swift index 0aa184e2..ff83e180 100644 --- a/Sources/3.0 API/BinderEnvironment.swift +++ b/Sources/3.0 API/BinderEnvironment.swift @@ -90,42 +90,22 @@ extension BinderEnvironment where AScope: Scope, Context == AScope.Context { .init(scope, ref) { r, c, _ in try builder(r, c) } } - public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> ScopedBinding.Builder { - .init(scope, ref) { r, c, a in try builder(r, c, a) } - } - public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> ScopedBinding.Builder> where Arg1: Hashable { .init(scope, ref) { r, c, a in try builder(r, c, a.arg1) } } - public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> ScopedBinding.Builder { - .init(scope, ref) { r, c, a in try builder(r, c, a.0, a.1) } - } - public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> ScopedBinding.Builder> where Arg1: Hashable, Arg2: Hashable { .init(scope, ref) { r, c, a in try builder(r, c, a.arg1, a.arg2) } } - public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> ScopedBinding.Builder { - .init(scope, ref) { r, c, a in try builder(r, c, a.0, a.1, a.2) } - } - public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> ScopedBinding.Builder> where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { .init(scope, ref) { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3) } } - public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> ScopedBinding.Builder { - .init(scope, ref) { r, c, a in try builder(r, c, a.0, a.1, a.2, a.3) } - } - public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> ScopedBinding.Builder> where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { .init(scope, ref) { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3, a.arg4) } } - public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> ScopedBinding.Builder { - .init(scope, ref) { r, c, a in try builder(r, c, a.0, a.1, a.2, a.3, a.4) } - } - public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> ScopedBinding.Builder> where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { .init(scope, ref) { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) } } @@ -187,42 +167,22 @@ public func singleton(ref: @escaping ReferenceMaker = strongRef, _ b .init(.root, ref) { r, _, _ in try builder(r) } } -public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1) throws -> Type) -> ScopedBinding.Builder { - .init(.root, ref) { r, _, a in try builder(r, a) } -} - public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1) throws -> Type) -> ScopedBinding.Builder> where Arg1: Hashable { .init(.root, ref) { r, _, a in try builder(r, a.arg1) } } -public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> ScopedBinding.Builder { - .init(.root, ref) { r, _, a in try builder(r, a.0, a.1) } -} - public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> ScopedBinding.Builder> where Arg1: Hashable, Arg2: Hashable { .init(.root, ref) { r, _, a in try builder(r, a.arg1, a.arg2) } } -public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> ScopedBinding.Builder { - .init(.root, ref) { r, _, a in try builder(r, a.0, a.1, a.2) } -} - public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> ScopedBinding.Builder> where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { .init(.root, ref) { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3) } } -public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> ScopedBinding.Builder { - .init(.root, ref) { r, _, a in try builder(r, a.0, a.1, a.2, a.3) } -} - public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> ScopedBinding.Builder> where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { .init(.root, ref) { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3, a.arg4) } } -public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> ScopedBinding.Builder { - .init(.root, ref) { r, _, a in try builder(r, a.0, a.1, a.2, a.3, a.4) } -} - public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> ScopedBinding.Builder> where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { .init(.root, ref) { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) } } diff --git a/Templates/BinderVariation.swift b/Templates/BinderVariation.swift index 284b77e2..9dec49d5 100644 --- a/Templates/BinderVariation.swift +++ b/Templates/BinderVariation.swift @@ -136,6 +136,7 @@ extension BinderVariation { .filter { !($0.args == 0 && !$0.isMatchable) } .filter { !($0.args > 0 && !$0.hasResolver) } .filter { !($0.args > 0 && $0.isContexted && !$0.hasContext) } + .filter { !($0.isScoped && !$0.isMatchable) } } extension BinderVariation { diff --git a/Templates/SwiftCode.swifttemplate b/Templates/SwiftCode.swifttemplate index 53e607ae..f2c57cd1 100644 --- a/Templates/SwiftCode.swifttemplate +++ b/Templates/SwiftCode.swifttemplate @@ -137,6 +137,7 @@ extension BinderVariation { .filter { !($0.args == 0 && !$0.isMatchable) } .filter { !($0.args > 0 && !$0.hasResolver) } .filter { !($0.args > 0 && $0.isContexted && !$0.hasContext) } + .filter { !($0.isScoped && !$0.isMatchable) } } extension BinderVariation { diff --git a/Tests/Support/NonGeneratedMocks.swift b/Tests/Support/NonGeneratedMocks.swift index ac34bb28..1f4a8b2b 100644 --- a/Tests/Support/NonGeneratedMocks.swift +++ b/Tests/Support/NonGeneratedMocks.swift @@ -87,3 +87,10 @@ struct BuilderScopeRegistry: ScopeRegistry { func clear() {} } + +extension BindingMock { + // swiftlint:disable large_tuple + var instanceReceivedArguments: (arg: Any, context: Any, resolver: Resolver)? { + instanceArgContextResolverReceivedArguments + } +} diff --git a/Tests/Unit Specs/BinderEnvironmentSpec.swift b/Tests/Unit Specs/BinderEnvironmentSpec.swift index 2950e529..4d15ca4f 100644 --- a/Tests/Unit Specs/BinderEnvironmentSpec.swift +++ b/Tests/Unit Specs/BinderEnvironmentSpec.swift @@ -150,7 +150,7 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { } describe("multiton") { it("has correct scope") { - let maker = multiton { (_, _: Void) in 42 } + let maker = multiton { (_, _: String) in 42 } expect(maker.scope) === UnboundScope.root } it("has correct reference maker") { @@ -159,19 +159,19 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { expect(maker.makeRef(0).currentValue as? Int) == 42 } it("returns instance made by builder method") { - let maker = multiton { (_, _: Void) in 42 } - expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 + let maker = multiton { (_, _: String) in 42 } + expect { try maker.makeInstance(arg: box(""), resolver: DummyResolver()) } == 42 } it("does not call builder until instance is requested") { var called = false - _ = multiton { (_, _: Void) in called = true } + _ = multiton { (_, _: String) in called = true } expect(called).to(beFalse()) } it("calls builder with given resolver") { var passedResolver: Resolver? let resolver = DummyResolver() - let maker = multiton { (r, _: Void) in passedResolver = r } - _ = try? maker.makeInstance(resolver: resolver) + let maker = multiton { (r, _: String) in passedResolver = r } + _ = try? maker.makeInstance(arg: box(""), resolver: resolver) expect(passedResolver) === resolver } it("calls builder with given argument") { @@ -181,13 +181,13 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { expect(passedArgument) == 42 } it("rethrows error from builder") { - let maker = multiton { (_, _: Void) in throw SwinjectError() } - expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) + let maker = multiton { (_, _: String) in throw SwinjectError() } + expect { try maker.makeInstance(arg: box(""), resolver: DummyResolver()) }.to(throwError()) } it("does not reuse instance") { - let maker = multiton { (_, _: Void) in Human() } - let instance1 = try? maker.makeInstance(resolver: DummyResolver()) - let instance2 = try? maker.makeInstance(resolver: DummyResolver()) + let maker = multiton { (_, _: String) in Human() } + let instance1 = try? maker.makeInstance(arg: box(""), resolver: DummyResolver()) + let instance2 = try? maker.makeInstance(arg: box(""), resolver: DummyResolver()) expect(instance1) !== instance2 } describe("multiple arguments") { @@ -363,29 +363,29 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { } describe("multiton") { it("has correct scope") { - let maker = environment.multiton { (_, _, _: Void) in 42 } + let maker = environment.multiton { (_, _, _: String) in 42 } expect(maker.scope) === scope } it("returns instance made by builder method") { - let maker = environment.multiton { (_, _, _: Void) in 42 } - expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 + let maker = environment.multiton { (_, _, _: String) in 42 } + expect { try maker.makeInstance(arg: box(""), resolver: DummyResolver()) } == 42 } it("does not call builder until instance is requested") { var called = false - _ = environment.multiton { (_, _, _: Void) in called = true } + _ = environment.multiton { (_, _, _: String) in called = true } expect(called).to(beFalse()) } it("calls builder with given resolver") { var passedResolver: Resolver? let resolver = DummyResolver() - let maker = environment.multiton { (r, _, _: Void) in passedResolver = r } - _ = try? maker.makeInstance(resolver: resolver) + let maker = environment.multiton { (r, _, _: String) in passedResolver = r } + _ = try? maker.makeInstance(arg: box(""), resolver: resolver) expect(passedResolver) === resolver } it("calls builder with given context") { var passedContext: Any? - let maker = environment.multiton { (_, c, _: Void) in passedContext = c } - _ = try? maker.makeInstance(context: "context", resolver: DummyResolver()) + let maker = environment.multiton { (_, c, _: String) in passedContext = c } + _ = try? maker.makeInstance(arg: box(""), context: "context", resolver: DummyResolver()) expect(passedContext as? String) == "context" } it("calls builder with given argument") { @@ -395,13 +395,13 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { expect(passedArgument) == 42 } it("rethrows error from builder") { - let maker = environment.multiton { (_, _, _: Void) in throw SwinjectError() } - expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) + let maker = environment.multiton { (_, _, _: String) in throw SwinjectError() } + expect { try maker.makeInstance(arg: box(""), resolver: DummyResolver()) }.to(throwError()) } it("does not reuse instance") { - let maker = environment.multiton { (_, _, _: Void) in Human() } - let instance1 = try? maker.makeInstance(resolver: DummyResolver()) - let instance2 = try? maker.makeInstance(resolver: DummyResolver()) + let maker = environment.multiton { (_, _, _: String) in Human() } + let instance1 = try? maker.makeInstance(arg: box(""), resolver: DummyResolver()) + let instance2 = try? maker.makeInstance(arg: box(""), resolver: DummyResolver()) expect(instance1) !== instance2 } describe("multiple arguments") { diff --git a/Tests/Unit Specs/SwinjectSpec.swift b/Tests/Unit Specs/SwinjectSpec.swift index ff6e168f..4173f49e 100644 --- a/Tests/Unit Specs/SwinjectSpec.swift +++ b/Tests/Unit Specs/SwinjectSpec.swift @@ -59,7 +59,7 @@ class SwinjectSpec: QuickSpec { override func spec() { it("passes swinject as resolver") { binding.matchesReturnValue = true _ = try? swinject.instance(of: Any.self) - expect(binding.instanceArgContextResolverReceivedArguments?.resolver is Swinject).to(beTrue()) + expect(binding.instanceReceivedArguments?.resolver is Swinject).to(beTrue()) } it("matches binding with correct key") { binding.matchesReturnValue = false @@ -160,7 +160,7 @@ class SwinjectSpec: QuickSpec { override func spec() { it("passes given context to the binding") { binding.matchesReturnValue = true _ = try? swinject.on("context").provider()() as Int - expect(binding.instanceArgContextResolverReceivedArguments?.context as? String) == "context" + expect(binding.instanceReceivedArguments?.context as? String) == "context" } it("passes given context to dependency binding") { let binding = BindingMock() @@ -171,7 +171,7 @@ class SwinjectSpec: QuickSpec { override func spec() { binding } _ = try? swinject.on("context").instance(of: Int.self) - expect(binding.instanceArgContextResolverReceivedArguments?.context as? String) == "context" + expect(binding.instanceReceivedArguments?.context as? String) == "context" } } describe("factory injection") { @@ -208,7 +208,7 @@ class SwinjectSpec: QuickSpec { override func spec() { binding.matchesReturnValue = true binding.instanceArgContextResolverReturnValue = 42 _ = try? swinject.factory(of: Int.self)("arg") - let argument = binding.instanceArgContextResolverReceivedArguments?.arg as? MatchableBox1 + let argument = binding.instanceReceivedArguments?.arg as? MatchableBox1 expect(argument?.arg1) == "arg" } it("matches binding with correct key") { @@ -225,7 +225,7 @@ class SwinjectSpec: QuickSpec { override func spec() { it("passes given context to the bidndning") { binding.matchesReturnValue = true _ = try? swinject.on("context").factory()("arg") as Int - expect(binding.instanceArgContextResolverReceivedArguments?.context as? String) == "context" + expect(binding.instanceReceivedArguments?.context as? String) == "context" } context("currying") { beforeEach { @@ -234,33 +234,33 @@ class SwinjectSpec: QuickSpec { override func spec() { } it("can curry 2-tuple as 0 / 2 argument") { _ = try? swinject.factory()("arg1", "arg2") as Int - let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? MatchableBox2 + let receivedArg = binding.instanceReceivedArguments?.arg as? MatchableBox2 expect(receivedArg?.arg1) == "arg1" expect(receivedArg?.arg2) == "arg2" } it("can curry 2-tuple as 1 / 1 argument") { _ = try? swinject.factory(arg: "arg1")("arg2") as Int - let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? MatchableBox2 + let receivedArg = binding.instanceReceivedArguments?.arg as? MatchableBox2 expect(receivedArg?.arg1) == "arg1" expect(receivedArg?.arg2) == "arg2" } it("can curry 3-tuple as 0 / 3 argument") { _ = try? swinject.factory()("arg1", 2, "arg3") as Int - let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? MatchableBox3 + let receivedArg = binding.instanceReceivedArguments?.arg as? MatchableBox3 expect(receivedArg?.arg1) == "arg1" expect(receivedArg?.arg2) == 2 expect(receivedArg?.arg3) == "arg3" } it("can curry 3-tuple as 1 / 2 argument") { _ = try? swinject.factory(arg: "arg1")(2, "arg3") as Int - let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? MatchableBox3 + let receivedArg = binding.instanceReceivedArguments?.arg as? MatchableBox3 expect(receivedArg?.arg1) == "arg1" expect(receivedArg?.arg2) == 2 expect(receivedArg?.arg3) == "arg3" } it("can curry 3-tuple as 2 / 1 argument") { _ = try? swinject.factory(arg: "arg1", 2)("arg3") as Int - let receivedArg = binding.instanceArgContextResolverReceivedArguments?.arg as? MatchableBox3 + let receivedArg = binding.instanceReceivedArguments?.arg as? MatchableBox3 expect(receivedArg?.arg1) == "arg1" expect(receivedArg?.arg2) == 2 expect(receivedArg?.arg3) == "arg3" @@ -330,7 +330,7 @@ class SwinjectSpec: QuickSpec { override func spec() { translators[0].targetType = Int.self translators[0].translateReturnValue = 42 _ = try? swinject.on("context").instance() as Int - expect(bindings[0].instanceArgContextResolverReceivedArguments?.context as? Int) == 42 + expect(bindings[0].instanceReceivedArguments?.context as? Int) == 42 } it("passes original context to context resolver") { bindings[0].matchesClosure = { $0.contextType == Int.self } From 4188287175c08cac49155edbb59d2f6189f6631a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sat, 27 Jul 2019 13:03:34 +0200 Subject: [PATCH 145/239] Hide Tagged type descriptor --- Sources/3.0 API/TypeBinder.swift | 8 +- Sources/Core/Opaque.swift | 16 ++++ Sources/Core/TypeDescriptor.swift | 30 +++++-- Swinject.xcodeproj/project.pbxproj | 116 ++++++++++++++++++++------ Tests/Support/Bridge.swift | 7 +- Tests/Unit Specs/TypeBinderSpec.swift | 4 +- 6 files changed, 141 insertions(+), 40 deletions(-) create mode 100644 Sources/Core/Opaque.swift diff --git a/Sources/3.0 API/TypeBinder.swift b/Sources/3.0 API/TypeBinder.swift index afa41219..d9501266 100644 --- a/Sources/3.0 API/TypeBinder.swift +++ b/Sources/3.0 API/TypeBinder.swift @@ -6,12 +6,12 @@ public struct TypeBinder where Descriptor: TypeDescriptor { let descriptor: Descriptor } -public func bind(_: Type.Type) -> TypeBinder> { - TypeBinder(descriptor: plain(Type.self)) +public func bind(_: Type.Type) -> TypeBinder> { + TypeBinder(descriptor: plain(Type.self).opaque) } -public func bind(_: Type.Type, tagged tag: Tag) -> TypeBinder> where Tag: Equatable { - TypeBinder(descriptor: tagged(Type.self, with: tag)) +public func bind(_: Type.Type, tagged tag: Tag) -> TypeBinder> where Tag: Hashable { + TypeBinder(descriptor: tagged(Type.self, with: tag).opaque) } // TODO: Compiler Bug? diff --git a/Sources/Core/Opaque.swift b/Sources/Core/Opaque.swift new file mode 100644 index 00000000..f088b681 --- /dev/null +++ b/Sources/Core/Opaque.swift @@ -0,0 +1,16 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +protocol AnyOpaque { + var anyActual: Any { get } +} + +protocol Opaque: AnyOpaque { + associatedtype Actual + var actual: Actual { get } +} + +extension Opaque { + var anyActual: Any { actual } +} diff --git a/Sources/Core/TypeDescriptor.swift b/Sources/Core/TypeDescriptor.swift index 3c5f1345..0183e6e2 100644 --- a/Sources/Core/TypeDescriptor.swift +++ b/Sources/Core/TypeDescriptor.swift @@ -9,12 +9,32 @@ public protocol TypeDescriptor: AnyTypeDescriptor { associatedtype BaseType } -public struct NoTag: Hashable {} +public struct SomeTypeDescriptor: TypeDescriptor, Opaque { + let actual: AnyTypeDescriptor -public struct Tagged: TypeDescriptor where Tag: Hashable { + public func matches(_ other: Any) -> Bool { + if let other = other as? AnyOpaque { + return actual.matches(other.anyActual) + } else { + return actual.matches(other) + } + } + + public func hash(into hasher: inout Hasher) { + actual.hash(into: &hasher) + } +} + +extension TypeDescriptor { + var opaque: SomeTypeDescriptor { SomeTypeDescriptor(actual: self) } +} + +struct NoTag: Hashable {} + +struct Tagged: TypeDescriptor where Tag: Hashable { let tag: Tag - public func matches(_ other: Any) -> Bool { + func matches(_ other: Any) -> Bool { if let other = other as? Tagged { return tag == other.tag } @@ -27,12 +47,12 @@ public struct Tagged: TypeDescriptor where Tag: Hashable { return false } - public func hash(into hasher: inout Hasher) { + func hash(into hasher: inout Hasher) { hasher.combine(String(describing: hashedType)) hasher.combine(tag) } - private var hashedType: Any.Type { + var hashedType: Any.Type { if let optional = BaseType.self as? OptionalProtocol.Type { if let doubleOptional = optional.wrappedType as? OptionalProtocol.Type { return doubleOptional.wrappedType diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 359c716b..ae4f37b7 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -274,6 +274,10 @@ CBBE28990E0EA82AD8D5E3AF /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; CBE63031F33303F3E503CEF2 /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; CDBBA4023FE01CE4EFEE143A /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCAF491EC7DCD7477F9A0ECB /* SwinjectModule.swift */; }; + CDCF3FDE22EC66AF0025E2BD /* Opaque.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDCF3FDD22EC66AF0025E2BD /* Opaque.swift */; }; + CDCF3FDF22EC66AF0025E2BD /* Opaque.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDCF3FDD22EC66AF0025E2BD /* Opaque.swift */; }; + CDCF3FE022EC66AF0025E2BD /* Opaque.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDCF3FDD22EC66AF0025E2BD /* Opaque.swift */; }; + CDCF3FE122EC66AF0025E2BD /* Opaque.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDCF3FDD22EC66AF0025E2BD /* Opaque.swift */; }; CE5AFED22F04B96713ED76D7 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ADC44E9312C3B974AFD8F07B /* Nimble.framework */; }; CEA4CB2D3113EC693C590B9D /* ScopedBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */; }; CECF5BD14BCDF5248771A06A /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; @@ -451,7 +455,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 01DEC4D20CE554C9DFBD0A8D /* Resolver+Injection.swifttemplate */ = {isa = PBXFileReference; path = "Resolver+Injection.swifttemplate"; sourceTree = ""; }; + 01DEC4D20CE554C9DFBD0A8D /* Resolver+Injection.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+Injection.swifttemplate"; sourceTree = ""; }; 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.swift; sourceTree = ""; }; 09FC792715B1658721F76885 /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 0CA449690AE00F6300DE8ACA /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -459,7 +463,7 @@ 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopedBindingSpec.swift; sourceTree = ""; }; 0E0B580B43E1891812C97209 /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; 10480F2154EAA0414D4C1F55 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */ = {isa = PBXFileReference; path = .swiftlint.yml; sourceTree = ""; }; + 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .swiftlint.yml; sourceTree = ""; }; 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SynchronizedResolverSpec.swift; sourceTree = ""; }; 13513FA012659ADE699A3608 /* LazySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LazySpec.swift; sourceTree = ""; }; 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleBindingSpec.swift; sourceTree = ""; }; @@ -469,7 +473,7 @@ 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Circularity.swift; sourceTree = ""; }; 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Behavior.swift; sourceTree = ""; }; 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Arguments.swift; sourceTree = ""; }; - 26EEC28683E4A26B3092E8BA /* BinderEnvironment.swifttemplate */ = {isa = PBXFileReference; path = BinderEnvironment.swifttemplate; sourceTree = ""; }; + 26EEC28683E4A26B3092E8BA /* BinderEnvironment.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = BinderEnvironment.swifttemplate; sourceTree = ""; }; 273FB7A6277E0841E1570990 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; 2902FD4C1A50263340A51FFB /* ScopeRegistryKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistryKeySpec.swift; sourceTree = ""; }; 2E0C3E4D518BC1FEF3EF8D33 /* BinderVariation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderVariation.swift; sourceTree = ""; }; @@ -484,7 +488,7 @@ 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaggedTypeSpec.swift; sourceTree = ""; }; 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingKeySpec.swift; sourceTree = ""; }; 42490D1D0C395951243F5CFF /* Container.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.swift; sourceTree = ""; }; - 4286F98133270A36F19E5CD0 /* AutoMockable.stencil */ = {isa = PBXFileReference; path = AutoMockable.stencil; sourceTree = ""; }; + 4286F98133270A36F19E5CD0 /* AutoMockable.stencil */ = {isa = PBXFileReference; lastKnownFileType = text; path = AutoMockable.stencil; sourceTree = ""; }; 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmploymentAssembly.swift; sourceTree = ""; }; 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTree.swift; sourceTree = ""; }; 494AA2AA587975747596C157 /* ProviderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProviderSpec.swift; sourceTree = ""; }; @@ -513,13 +517,13 @@ 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ServiceEntry+TypeForwarding.swift"; sourceTree = ""; }; 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextTranslator.swift; sourceTree = ""; }; 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistry.swift; sourceTree = ""; }; - 808C1063CA90CC593C7E0E9C /* MatchableBoxes.swifttemplate */ = {isa = PBXFileReference; path = MatchableBoxes.swifttemplate; sourceTree = ""; }; + 808C1063CA90CC593C7E0E9C /* MatchableBoxes.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = MatchableBoxes.swifttemplate; sourceTree = ""; }; 823617F3B8A9192F56B13331 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; 841D83ADB41363D1E38087B4 /* NonGeneratedMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonGeneratedMocks.swift; sourceTree = ""; }; 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeneratedMocks.swift; sourceTree = ""; }; 8B9785AAE94A5447FA307242 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTreeBuilderSpec.swift; sourceTree = ""; }; - 90191C25A2D66E07C4E9CD73 /* SwiftCode.swifttemplate */ = {isa = PBXFileReference; path = SwiftCode.swifttemplate; sourceTree = ""; }; + 90191C25A2D66E07C4E9CD73 /* SwiftCode.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = SwiftCode.swifttemplate; sourceTree = ""; }; 9527A4CA5BCBA7AFA3596757 /* SwinjectSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectSpec.swift; sourceTree = ""; }; 9620155728133F451B31C0AD /* Swinject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Swinject.swift; sourceTree = ""; }; 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistryKey.swift; sourceTree = ""; }; @@ -536,7 +540,7 @@ B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderEnvironment.swift; sourceTree = ""; }; B92B8E618A08408404FB2A7A /* TypeBinder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinder.swift; sourceTree = ""; }; BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StandardScopeRegistrySpec.swift; sourceTree = ""; }; - BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */ = {isa = PBXFileReference; path = "ServiceEntry+TypeForwarding.swifttemplate"; sourceTree = ""; }; + BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "ServiceEntry+TypeForwarding.swifttemplate"; sourceTree = ""; }; BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Behavior.swift; sourceTree = ""; }; C074BAC560F277E806146C60 /* SimpleBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleBinding.swift; sourceTree = ""; }; C3C516EFA0CA22D19F07B27E /* InjectionVariation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InjectionVariation.swift; sourceTree = ""; }; @@ -544,7 +548,8 @@ CADDB3E9E363310028AA5920 /* InstanceMaker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceMaker.swift; sourceTree = ""; }; CC85CB215058F95C0BC190B1 /* Bridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bridge.swift; sourceTree = ""; }; CDA78290D6D60BD0B808571F /* Container+Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Logging.swift"; sourceTree = ""; }; - CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; + CDCF3FDD22EC66AF0025E2BD /* Opaque.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Opaque.swift; sourceTree = ""; }; + CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRequest.swift; sourceTree = ""; }; E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; EDA62EEBC79ED2639C93A76B /* TypeBinderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinderSpec.swift; sourceTree = ""; }; @@ -553,7 +558,7 @@ F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.TypeForwarding.swift; sourceTree = ""; }; FCAF491EC7DCD7477F9A0ECB /* SwinjectModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectModule.swift; sourceTree = ""; }; FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderEnvironmentSpec.swift; sourceTree = ""; }; - FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */ = {isa = PBXFileReference; path = "Resolver+LegacyApi.swifttemplate"; sourceTree = ""; }; + FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+LegacyApi.swifttemplate"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -853,6 +858,7 @@ A3586A4987B7C7C8122D674E /* SwinjectError.swift */, 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */, E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */, + CDCF3FDD22EC66AF0025E2BD /* Opaque.swift */, ); path = Core; sourceTree = ""; @@ -1426,6 +1432,7 @@ CAF3BCDC752C821491AE8714 /* SwinjectModule.swift in Sources */, 0D5C4A278A16AB3A163148AF /* SwinjectTree.swift in Sources */, AB864E029E996492ED4A3A52 /* TypeBinder.swift in Sources */, + CDCF3FDF22EC66AF0025E2BD /* Opaque.swift in Sources */, 49685AB40BEE856C62005C87 /* TypeDescriptor.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1650,6 +1657,7 @@ CDBBA4023FE01CE4EFEE143A /* SwinjectModule.swift in Sources */, 0CE1126436F680F9684837E4 /* SwinjectTree.swift in Sources */, 4B9811CF0604946CCF323ED2 /* TypeBinder.swift in Sources */, + CDCF3FE022EC66AF0025E2BD /* Opaque.swift in Sources */, 9CEE20BD42795D5E5F39BF20 /* TypeDescriptor.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1692,6 +1700,7 @@ D54DFEDF33F09035F3177248 /* SwinjectModule.swift in Sources */, 372F0061E762BF8FFF05457F /* SwinjectTree.swift in Sources */, 9425887520AC2DBDCBACB252 /* TypeBinder.swift in Sources */, + CDCF3FE122EC66AF0025E2BD /* Opaque.swift in Sources */, AC470B4322599B0A076DD3FF /* TypeDescriptor.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1734,6 +1743,7 @@ 732A8933C1310C2A6309E56B /* SwinjectModule.swift in Sources */, 6922AE734E84B515C94D9480 /* SwinjectTree.swift in Sources */, EF79F0B3D497215D4BBBC038 /* TypeBinder.swift in Sources */, + CDCF3FDE22EC66AF0025E2BD /* Opaque.swift in Sources */, E3EABE098DBFB561A20632E3 /* TypeDescriptor.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1855,7 +1865,11 @@ "$(PROJECT_DIR)/Carthage/Build/iOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -1893,7 +1907,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = macosx; SKIP_INSTALL = YES; @@ -1910,7 +1927,11 @@ "$(PROJECT_DIR)/Carthage/Build/tvOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = appletvos; TARGETED_DEVICE_FAMILY = 3; @@ -1928,7 +1949,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = appletvos; SKIP_INSTALL = YES; @@ -1946,7 +1970,11 @@ "$(PROJECT_DIR)/Carthage/Build/iOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -1963,7 +1991,11 @@ "$(PROJECT_DIR)/Carthage/Build/Mac", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = macosx; }; @@ -2053,7 +2085,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = appletvos; SKIP_INSTALL = YES; @@ -2071,7 +2106,11 @@ "$(PROJECT_DIR)/Carthage/Build/watchOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = watchos; SKIP_INSTALL = YES; @@ -2090,7 +2129,10 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); SDKROOT = macosx; SKIP_INSTALL = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -2108,7 +2150,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = iphoneos; SKIP_INSTALL = YES; @@ -2126,7 +2171,11 @@ "$(PROJECT_DIR)/Carthage/Build/watchOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = watchos; SKIP_INSTALL = YES; @@ -2144,7 +2193,11 @@ "$(PROJECT_DIR)/Carthage/Build/Mac", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = macosx; }; @@ -2159,7 +2212,11 @@ "$(PROJECT_DIR)/Carthage/Build/tvOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = appletvos; TARGETED_DEVICE_FAMILY = 3; @@ -2177,7 +2234,10 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); SDKROOT = macosx; SKIP_INSTALL = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -2196,7 +2256,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = macosx; SKIP_INSTALL = YES; @@ -2215,7 +2278,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = iphoneos; SKIP_INSTALL = YES; diff --git a/Tests/Support/Bridge.swift b/Tests/Support/Bridge.swift index f52fe0a0..4ee0c85a 100644 --- a/Tests/Support/Bridge.swift +++ b/Tests/Support/Bridge.swift @@ -3,17 +3,16 @@ // import func Swinject.bind -import struct Swinject.NoTag -import struct Swinject.Tagged +import struct Swinject.SomeTypeDescriptor import struct Swinject.TypeBinder import protocol Swinject.TypeDescriptor // Original Swinject functions conflict with QuickSpec's instance methods -func bbind(_: Type.Type) -> TypeBinder> { +func bbind(_: Type.Type) -> TypeBinder> { bind(Type.self) } -func bbind(_: Type.Type, tagged tag: Tag) -> TypeBinder> where Tag: Equatable { +func bbind(_: Type.Type, tagged tag: Tag) -> TypeBinder> where Tag: Hashable { bind(Type.self, tagged: tag) } diff --git a/Tests/Unit Specs/TypeBinderSpec.swift b/Tests/Unit Specs/TypeBinderSpec.swift index a93577cf..774d77e2 100644 --- a/Tests/Unit Specs/TypeBinderSpec.swift +++ b/Tests/Unit Specs/TypeBinderSpec.swift @@ -16,8 +16,8 @@ class TypeBinderSpec: QuickSpec { override func spec() { } describe("bind") { it("descriptor has correct tag for tagged type") { - let descriptor = bbind(Int.self, tagged: "Foo").descriptor - expect(descriptor.tag) == "Foo" + let descriptor = bbind(Int.self, tagged: "Foo").descriptor.actual as? Tagged + expect(descriptor?.tag) == "Foo" } it("descriptor is used if given as parameter") { let request = bbind(descriptor: descriptor) From 3c851e2e42e3f9eb3e8018f8d91244b3281fce3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sat, 27 Jul 2019 13:23:15 +0200 Subject: [PATCH 146/239] Loosen type restrictions on BindingMaker --- Sources/Core/Binding.swift | 3 +- Sources/Core/ScopedBinding.swift | 2 +- Sources/Core/SimpleBinding.swift | 2 +- Tests/Support/GeneratedMocks.swift | 42 +++++++++++++-------------- Tests/Support/NonGeneratedMocks.swift | 11 +------ Tests/Unit Specs/TypeBinderSpec.swift | 4 +-- 6 files changed, 28 insertions(+), 36 deletions(-) diff --git a/Sources/Core/Binding.swift b/Sources/Core/Binding.swift index 247877b1..f79cc811 100644 --- a/Sources/Core/Binding.swift +++ b/Sources/Core/Binding.swift @@ -8,7 +8,8 @@ public protocol Binding: SwinjectEntry { func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any } +// sourcery: AutoMockable public protocol BindingMaker { associatedtype BoundType - func makeBinding(for descriptor: Descriptor) -> Binding where Descriptor: TypeDescriptor + func makeBinding(for descriptor: AnyTypeDescriptor) -> Binding } diff --git a/Sources/Core/ScopedBinding.swift b/Sources/Core/ScopedBinding.swift index a1ebb1df..c2945663 100644 --- a/Sources/Core/ScopedBinding.swift +++ b/Sources/Core/ScopedBinding.swift @@ -57,7 +57,7 @@ extension ScopedBinding.Builder: InstanceMaker { extension ScopedBinding.Builder: BindingMaker { public typealias BoundType = Type - public func makeBinding(for descriptor: Descriptor) -> Binding where Descriptor: TypeDescriptor { + public func makeBinding(for descriptor: AnyTypeDescriptor) -> Binding { ScopedBinding( key: BindingKey(descriptor: descriptor, contextType: Context.self, argumentType: Argument.self), maker: self, diff --git a/Sources/Core/SimpleBinding.swift b/Sources/Core/SimpleBinding.swift index c57ff105..ded1af93 100644 --- a/Sources/Core/SimpleBinding.swift +++ b/Sources/Core/SimpleBinding.swift @@ -38,7 +38,7 @@ extension SimpleBinding.Builder: InstanceMaker { extension SimpleBinding.Builder: BindingMaker { public typealias BoundType = Type - public func makeBinding(for descriptor: Descriptor) -> Binding where Descriptor: TypeDescriptor { + public func makeBinding(for descriptor: AnyTypeDescriptor) -> Binding { SimpleBinding( key: BindingKey(descriptor: descriptor, contextType: Context.self, argumentType: Argument.self), maker: self diff --git a/Tests/Support/GeneratedMocks.swift b/Tests/Support/GeneratedMocks.swift index d66c943a..0784f9e2 100644 --- a/Tests/Support/GeneratedMocks.swift +++ b/Tests/Support/GeneratedMocks.swift @@ -55,27 +55,6 @@ class AnyBindingKeyMock: AnyBindingKey { return matchesClosure.map({ $0(other) }) ?? matchesReturnValue! } -} -class AnyBindningMakerMock: AnyBindningMaker { - - //MARK: - makeBinding - - var makeBindingForCallsCount = 0 - var makeBindingForCalled: Bool { - return makeBindingForCallsCount > 0 - } - var makeBindingForReceivedDescriptor: AnyTypeDescriptor? - var makeBindingForReceivedInvocations: [AnyTypeDescriptor] = [] - var makeBindingForReturnValue: Binding! - var makeBindingForClosure: ((AnyTypeDescriptor) -> Binding)? - - func makeBinding(for descriptor: AnyTypeDescriptor) -> Binding { - makeBindingForCallsCount += 1 - makeBindingForReceivedDescriptor = descriptor - makeBindingForReceivedInvocations.append(descriptor) - return makeBindingForClosure.map({ $0(descriptor) }) ?? makeBindingForReturnValue! - } - } class AnyContextTranslatorMock: AnyContextTranslator { var sourceType: Any.Type { @@ -268,6 +247,27 @@ class BindingMock: Binding { return try instanceArgContextResolverClosure.map({ try $0(arg, context, resolver) }) ?? instanceArgContextResolverReturnValue! } +} +class BindingMakerMock: BindingMaker { + + //MARK: - makeBinding + + var makeBindingForCallsCount = 0 + var makeBindingForCalled: Bool { + return makeBindingForCallsCount > 0 + } + var makeBindingForReceivedDescriptor: AnyTypeDescriptor? + var makeBindingForReceivedInvocations: [AnyTypeDescriptor] = [] + var makeBindingForReturnValue: Binding! + var makeBindingForClosure: ((AnyTypeDescriptor) -> Binding)? + + func makeBinding(for descriptor: AnyTypeDescriptor) -> Binding { + makeBindingForCallsCount += 1 + makeBindingForReceivedDescriptor = descriptor + makeBindingForReceivedInvocations.append(descriptor) + return makeBindingForClosure.map({ $0(descriptor) }) ?? makeBindingForReturnValue! + } + } class ClosableMock: Closable { diff --git a/Tests/Support/NonGeneratedMocks.swift b/Tests/Support/NonGeneratedMocks.swift index 1f4a8b2b..6901f52b 100644 --- a/Tests/Support/NonGeneratedMocks.swift +++ b/Tests/Support/NonGeneratedMocks.swift @@ -47,17 +47,8 @@ class DummyScope: Scope { func registry(for _: Context) -> ScopeRegistry { fatalError() } } -// sourcery: AutoMockable -protocol AnyBindningMaker { - func makeBinding(for descriptor: AnyTypeDescriptor) -> Binding -} - -extension AnyBindningMakerMock: BindingMaker { +extension BindingMakerMock { typealias BoundType = Any - - func makeBinding(for descriptor: Descriptor) -> Binding where Descriptor: TypeDescriptor { - makeBinding(for: descriptor as AnyTypeDescriptor) - } } // sourcery: AutoMockable diff --git a/Tests/Unit Specs/TypeBinderSpec.swift b/Tests/Unit Specs/TypeBinderSpec.swift index 774d77e2..c0145b6a 100644 --- a/Tests/Unit Specs/TypeBinderSpec.swift +++ b/Tests/Unit Specs/TypeBinderSpec.swift @@ -8,10 +8,10 @@ import Quick class TypeBinderSpec: QuickSpec { override func spec() { var descriptor = AnyTypeDescriptorMock() - var maker = AnyBindningMakerMock() + var maker = BindingMakerMock() beforeEach { descriptor = AnyTypeDescriptorMock() - maker = AnyBindningMakerMock() + maker = BindingMakerMock() maker.makeBindingForReturnValue = BindingMock() } describe("bind") { From 2e70d928402a001c724bd136765ae6d67ac53d20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sat, 27 Jul 2019 13:57:21 +0200 Subject: [PATCH 147/239] Remove actual bindings from the public api --- Sources/3.0 API/BinderEnvironment.swift | 164 +++++++++---------- Sources/Core/Binding.swift | 15 ++ Sources/Core/InstanceMaker.swift | 6 +- Sources/Core/Matchable.swift | 11 +- Sources/Core/ScopedBinding.swift | 18 +- Sources/Core/SimpleBinding.swift | 16 +- Sources/Core/TypeDescriptor.swift | 2 +- Templates/BinderVariation.swift | 6 +- Templates/MatchableBoxes.swifttemplate | 2 +- Templates/SwiftCode.swifttemplate | 6 +- Tests/Support/Convenience.swift | 18 -- Tests/Unit Specs/BinderEnvironmentSpec.swift | 54 ++++-- 12 files changed, 173 insertions(+), 145 deletions(-) diff --git a/Sources/3.0 API/BinderEnvironment.swift b/Sources/3.0 API/BinderEnvironment.swift index ff83e180..5c226355 100644 --- a/Sources/3.0 API/BinderEnvironment.swift +++ b/Sources/3.0 API/BinderEnvironment.swift @@ -18,173 +18,173 @@ public func scoped(_ scope: AScope) -> BinderEnvironment(_ instance: Type) -> SimpleBinding.Builder { - .init { _, _, _ in instance } +public func instance(_ instance: Type) -> SomeBindingMaker { + SimpleBinding.Builder { _, _, _ in instance }.opaque } // sourcery:inline:BindingBuilders extension BinderEnvironment where AScope == Void { - public func provider(_ builder: @escaping () throws -> Type) -> SimpleBinding.Builder { - .init { _, _, _ in try builder() } + public func provider(_ builder: @escaping () throws -> Type) -> SomeBindingMaker { + SimpleBinding.Builder { _, _, _ in try builder() }.opaque } - public func provider(_ builder: @escaping (Resolver) throws -> Type) -> SimpleBinding.Builder { - .init { r, _, _ in try builder(r) } + public func provider(_ builder: @escaping (Resolver) throws -> Type) -> SomeBindingMaker { + SimpleBinding.Builder { r, _, _ in try builder(r) }.opaque } - public func provider(_ builder: @escaping (Resolver, Context) throws -> Type) -> SimpleBinding.Builder { - .init { r, c, _ in try builder(r, c) } + public func provider(_ builder: @escaping (Resolver, Context) throws -> Type) -> SomeBindingMaker { + SimpleBinding.Builder { r, c, _ in try builder(r, c) }.opaque } - public func factory(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SimpleBinding.Builder { - .init { r, c, a in try builder(r, c, a) } + public func factory(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SomeBindingMaker { + SimpleBinding.Builder { r, c, a in try builder(r, c, a) }.opaque } - public func factory(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SimpleBinding.Builder> where Arg1: Hashable { - .init { r, c, a in try builder(r, c, a.arg1) } + public func factory(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SomeBindingMaker where Arg1: Hashable { + SimpleBinding.Builder> { r, c, a in try builder(r, c, a.arg1) }.opaque } - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SimpleBinding.Builder { - .init { r, c, a in try builder(r, c, a.0, a.1) } + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SomeBindingMaker { + SimpleBinding.Builder { r, c, a in try builder(r, c, a.0, a.1) }.opaque } - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SimpleBinding.Builder> where Arg1: Hashable, Arg2: Hashable { - .init { r, c, a in try builder(r, c, a.arg1, a.arg2) } + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable { + SimpleBinding.Builder> { r, c, a in try builder(r, c, a.arg1, a.arg2) }.opaque } - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SimpleBinding.Builder { - .init { r, c, a in try builder(r, c, a.0, a.1, a.2) } + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingMaker { + SimpleBinding.Builder { r, c, a in try builder(r, c, a.0, a.1, a.2) }.opaque } - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SimpleBinding.Builder> where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - .init { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3) } + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + SimpleBinding.Builder> { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3) }.opaque } - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SimpleBinding.Builder { - .init { r, c, a in try builder(r, c, a.0, a.1, a.2, a.3) } + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingMaker { + SimpleBinding.Builder { r, c, a in try builder(r, c, a.0, a.1, a.2, a.3) }.opaque } - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SimpleBinding.Builder> where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - .init { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3, a.arg4) } + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + SimpleBinding.Builder> { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3, a.arg4) }.opaque } - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SimpleBinding.Builder { - .init { r, c, a in try builder(r, c, a.0, a.1, a.2, a.3, a.4) } + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingMaker { + SimpleBinding.Builder { r, c, a in try builder(r, c, a.0, a.1, a.2, a.3, a.4) }.opaque } - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SimpleBinding.Builder> where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - .init { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) } + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + SimpleBinding.Builder> { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) }.opaque } } extension BinderEnvironment where AScope: Scope, Context == AScope.Context { - public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping () throws -> Type) -> ScopedBinding.Builder { - .init(scope, ref) { _, _, _ in try builder() } + public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping () throws -> Type) -> SomeBindingMaker { + ScopedBinding.Builder(scope, ref) { _, _, _ in try builder() }.opaque } - public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver) throws -> Type) -> ScopedBinding.Builder { - .init(scope, ref) { r, _, _ in try builder(r) } + public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver) throws -> Type) -> SomeBindingMaker { + ScopedBinding.Builder(scope, ref) { r, _, _ in try builder(r) }.opaque } - public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context) throws -> Type) -> ScopedBinding.Builder { - .init(scope, ref) { r, c, _ in try builder(r, c) } + public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context) throws -> Type) -> SomeBindingMaker { + ScopedBinding.Builder(scope, ref) { r, c, _ in try builder(r, c) }.opaque } - public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> ScopedBinding.Builder> where Arg1: Hashable { - .init(scope, ref) { r, c, a in try builder(r, c, a.arg1) } + public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SomeBindingMaker where Arg1: Hashable { + ScopedBinding.Builder>(scope, ref) { r, c, a in try builder(r, c, a.arg1) }.opaque } - public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> ScopedBinding.Builder> where Arg1: Hashable, Arg2: Hashable { - .init(scope, ref) { r, c, a in try builder(r, c, a.arg1, a.arg2) } + public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable { + ScopedBinding.Builder>(scope, ref) { r, c, a in try builder(r, c, a.arg1, a.arg2) }.opaque } - public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> ScopedBinding.Builder> where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - .init(scope, ref) { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3) } + public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + ScopedBinding.Builder>(scope, ref) { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3) }.opaque } - public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> ScopedBinding.Builder> where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - .init(scope, ref) { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3, a.arg4) } + public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + ScopedBinding.Builder>(scope, ref) { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3, a.arg4) }.opaque } - public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> ScopedBinding.Builder> where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - .init(scope, ref) { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) } + public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + ScopedBinding.Builder>(scope, ref) { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) }.opaque } } -public func provider(_ builder: @escaping () throws -> Type) -> SimpleBinding.Builder { - .init { _, _, _ in try builder() } +public func provider(_ builder: @escaping () throws -> Type) -> SomeBindingMaker { + SimpleBinding.Builder { _, _, _ in try builder() }.opaque } -public func provider(_ builder: @escaping (Resolver) throws -> Type) -> SimpleBinding.Builder { - .init { r, _, _ in try builder(r) } +public func provider(_ builder: @escaping (Resolver) throws -> Type) -> SomeBindingMaker { + SimpleBinding.Builder { r, _, _ in try builder(r) }.opaque } -public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> SimpleBinding.Builder { - .init { r, _, a in try builder(r, a) } +public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> SomeBindingMaker { + SimpleBinding.Builder { r, _, a in try builder(r, a) }.opaque } -public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> SimpleBinding.Builder> where Arg1: Hashable { - .init { r, _, a in try builder(r, a.arg1) } +public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> SomeBindingMaker where Arg1: Hashable { + SimpleBinding.Builder> { r, _, a in try builder(r, a.arg1) }.opaque } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SimpleBinding.Builder { - .init { r, _, a in try builder(r, a.0, a.1) } +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SomeBindingMaker { + SimpleBinding.Builder { r, _, a in try builder(r, a.0, a.1) }.opaque } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SimpleBinding.Builder> where Arg1: Hashable, Arg2: Hashable { - .init { r, _, a in try builder(r, a.arg1, a.arg2) } +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable { + SimpleBinding.Builder> { r, _, a in try builder(r, a.arg1, a.arg2) }.opaque } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SimpleBinding.Builder { - .init { r, _, a in try builder(r, a.0, a.1, a.2) } +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingMaker { + SimpleBinding.Builder { r, _, a in try builder(r, a.0, a.1, a.2) }.opaque } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SimpleBinding.Builder> where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - .init { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3) } +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + SimpleBinding.Builder> { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3) }.opaque } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SimpleBinding.Builder { - .init { r, _, a in try builder(r, a.0, a.1, a.2, a.3) } +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingMaker { + SimpleBinding.Builder { r, _, a in try builder(r, a.0, a.1, a.2, a.3) }.opaque } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SimpleBinding.Builder> where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - .init { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3, a.arg4) } +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + SimpleBinding.Builder> { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3, a.arg4) }.opaque } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SimpleBinding.Builder { - .init { r, _, a in try builder(r, a.0, a.1, a.2, a.3, a.4) } +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingMaker { + SimpleBinding.Builder { r, _, a in try builder(r, a.0, a.1, a.2, a.3, a.4) }.opaque } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SimpleBinding.Builder> where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - .init { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) } +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + SimpleBinding.Builder> { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) }.opaque } -public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping () throws -> Type) -> ScopedBinding.Builder { - .init(.root, ref) { _, _, _ in try builder() } +public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping () throws -> Type) -> SomeBindingMaker { + ScopedBinding.Builder(.root, ref) { _, _, _ in try builder() }.opaque } -public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver) throws -> Type) -> ScopedBinding.Builder { - .init(.root, ref) { r, _, _ in try builder(r) } +public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver) throws -> Type) -> SomeBindingMaker { + ScopedBinding.Builder(.root, ref) { r, _, _ in try builder(r) }.opaque } -public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1) throws -> Type) -> ScopedBinding.Builder> where Arg1: Hashable { - .init(.root, ref) { r, _, a in try builder(r, a.arg1) } +public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1) throws -> Type) -> SomeBindingMaker where Arg1: Hashable { + ScopedBinding.Builder>(.root, ref) { r, _, a in try builder(r, a.arg1) }.opaque } -public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> ScopedBinding.Builder> where Arg1: Hashable, Arg2: Hashable { - .init(.root, ref) { r, _, a in try builder(r, a.arg1, a.arg2) } +public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable { + ScopedBinding.Builder>(.root, ref) { r, _, a in try builder(r, a.arg1, a.arg2) }.opaque } -public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> ScopedBinding.Builder> where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - .init(.root, ref) { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3) } +public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + ScopedBinding.Builder>(.root, ref) { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3) }.opaque } -public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> ScopedBinding.Builder> where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - .init(.root, ref) { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3, a.arg4) } +public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + ScopedBinding.Builder>(.root, ref) { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3, a.arg4) }.opaque } -public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> ScopedBinding.Builder> where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - .init(.root, ref) { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) } +public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + ScopedBinding.Builder>(.root, ref) { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) }.opaque } // sourcery:end diff --git a/Sources/Core/Binding.swift b/Sources/Core/Binding.swift index f79cc811..876d3baf 100644 --- a/Sources/Core/Binding.swift +++ b/Sources/Core/Binding.swift @@ -13,3 +13,18 @@ public protocol BindingMaker { associatedtype BoundType func makeBinding(for descriptor: AnyTypeDescriptor) -> Binding } + +public struct SomeBindingMaker: BindingMaker, AnyOpaque { + let anyActual: Any + fileprivate let _makeBinding: (AnyTypeDescriptor) -> Binding + + public func makeBinding(for descriptor: AnyTypeDescriptor) -> Binding { + _makeBinding(descriptor) + } +} + +public extension BindingMaker { + var opaque: SomeBindingMaker { + SomeBindingMaker(anyActual: self) { self.makeBinding(for: $0) } + } +} diff --git a/Sources/Core/InstanceMaker.swift b/Sources/Core/InstanceMaker.swift index 3851716b..573403a0 100644 --- a/Sources/Core/InstanceMaker.swift +++ b/Sources/Core/InstanceMaker.swift @@ -3,20 +3,20 @@ // // sourcery: AutoMockable -public protocol AnyInstanceMaker { +protocol AnyInstanceMaker { func makeInstance(arg: Any, context: Any, resolver: Resolver) throws -> Any } // FIXME: "Maker" is not a typical concept // Could we use `InstanceFactory` / `InstanceBuilder` instead, or would it be too overloaded? -public protocol InstanceMaker: AnyInstanceMaker { +protocol InstanceMaker: AnyInstanceMaker { associatedtype MadeType associatedtype Argument associatedtype Context func makeInstance(arg: Argument, context: Context, resolver: Resolver) throws -> MadeType } -public extension InstanceMaker { +extension InstanceMaker { func makeInstance(arg: Any, context: Any, resolver: Resolver) throws -> Any { guard let arg = arg as? Argument, let context = context as? Context else { throw SwinjectError() } return try makeInstance(arg: arg, context: context, resolver: resolver) as MadeType diff --git a/Sources/Core/Matchable.swift b/Sources/Core/Matchable.swift index d29f395e..035c47b5 100644 --- a/Sources/Core/Matchable.swift +++ b/Sources/Core/Matchable.swift @@ -14,33 +14,32 @@ public extension Matchable where Self: Equatable { } } -// TODO: Can we make MatchableBox types internal? // swiftlint:disable line_length // swiftlint:disable large_tuple // sourcery:inline:MatchableBoxes -public struct MatchableBox1: Hashable, Matchable where Arg1: Hashable { +struct MatchableBox1: Hashable, Matchable where Arg1: Hashable { let arg1: Arg1 } -public struct MatchableBox2: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable { +struct MatchableBox2: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable { let arg1: Arg1 let arg2: Arg2 } -public struct MatchableBox3: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { +struct MatchableBox3: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { let arg1: Arg1 let arg2: Arg2 let arg3: Arg3 } -public struct MatchableBox4: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { +struct MatchableBox4: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { let arg1: Arg1 let arg2: Arg2 let arg3: Arg3 let arg4: Arg4 } -public struct MatchableBox5: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { +struct MatchableBox5: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { let arg1: Arg1 let arg2: Arg2 let arg3: Arg3 diff --git a/Sources/Core/ScopedBinding.swift b/Sources/Core/ScopedBinding.swift index c2945663..079dbba9 100644 --- a/Sources/Core/ScopedBinding.swift +++ b/Sources/Core/ScopedBinding.swift @@ -2,7 +2,7 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -public struct ScopedBinding { +struct ScopedBinding { let key: AnyBindingKey let maker: AnyInstanceMaker let scope: AnyScope @@ -10,11 +10,11 @@ public struct ScopedBinding { } extension ScopedBinding: Binding { - public func matches(_ key: AnyBindingKey) -> Bool { + func matches(_ key: AnyBindingKey) -> Bool { self.key.matches(key) } - public func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any { + func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any { try scope .registry(for: context) .instance(for: ScopeRegistryKey(descriptor: key.descriptor, argument: arg)) { @@ -24,7 +24,7 @@ extension ScopedBinding: Binding { } extension ScopedBinding { - public struct Builder where AScope: Scope { + struct Builder where AScope: Scope { let scope: AScope let makeRef: ReferenceMaker private let builder: (Resolver, Context, Argument) throws -> Type @@ -46,18 +46,18 @@ extension ScopedBinding { } extension ScopedBinding.Builder: InstanceMaker { - public typealias MadeType = Type - public typealias Context = AScope.Context + typealias MadeType = Type + typealias Context = AScope.Context - public func makeInstance(arg: Argument, context: Context, resolver: Resolver) throws -> Type { + func makeInstance(arg: Argument, context: Context, resolver: Resolver) throws -> Type { try builder(resolver, context, arg) } } extension ScopedBinding.Builder: BindingMaker { - public typealias BoundType = Type + typealias BoundType = Type - public func makeBinding(for descriptor: AnyTypeDescriptor) -> Binding { + func makeBinding(for descriptor: AnyTypeDescriptor) -> Binding { ScopedBinding( key: BindingKey(descriptor: descriptor, contextType: Context.self, argumentType: Argument.self), maker: self, diff --git a/Sources/Core/SimpleBinding.swift b/Sources/Core/SimpleBinding.swift index ded1af93..31ae5310 100644 --- a/Sources/Core/SimpleBinding.swift +++ b/Sources/Core/SimpleBinding.swift @@ -2,23 +2,23 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -public struct SimpleBinding { +struct SimpleBinding { let key: AnyBindingKey let maker: AnyInstanceMaker } extension SimpleBinding: Binding { - public func matches(_ key: AnyBindingKey) -> Bool { + func matches(_ key: AnyBindingKey) -> Bool { self.key.matches(key) } - public func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any { + func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any { try maker.makeInstance(arg: arg, context: context, resolver: resolver) } } extension SimpleBinding { - public struct Builder { + struct Builder { private let builder: (Resolver, Context, Argument) throws -> Type init(_ builder: @escaping (Resolver, Context, Argument) throws -> Type) { @@ -28,17 +28,17 @@ extension SimpleBinding { } extension SimpleBinding.Builder: InstanceMaker { - public typealias MadeType = Type + typealias MadeType = Type - public func makeInstance(arg: Argument, context: Context, resolver: Resolver) throws -> Type { + func makeInstance(arg: Argument, context: Context, resolver: Resolver) throws -> Type { try builder(resolver, context, arg) } } extension SimpleBinding.Builder: BindingMaker { - public typealias BoundType = Type + typealias BoundType = Type - public func makeBinding(for descriptor: AnyTypeDescriptor) -> Binding { + func makeBinding(for descriptor: AnyTypeDescriptor) -> Binding { SimpleBinding( key: BindingKey(descriptor: descriptor, contextType: Context.self, argumentType: Argument.self), maker: self diff --git a/Sources/Core/TypeDescriptor.swift b/Sources/Core/TypeDescriptor.swift index 0183e6e2..f022972b 100644 --- a/Sources/Core/TypeDescriptor.swift +++ b/Sources/Core/TypeDescriptor.swift @@ -25,7 +25,7 @@ public struct SomeTypeDescriptor: TypeDescriptor, Opaque { } } -extension TypeDescriptor { +public extension TypeDescriptor { var opaque: SomeTypeDescriptor { SomeTypeDescriptor(actual: self) } } diff --git a/Templates/BinderVariation.swift b/Templates/BinderVariation.swift index 9dec49d5..ea9caeff 100644 --- a/Templates/BinderVariation.swift +++ b/Templates/BinderVariation.swift @@ -60,6 +60,10 @@ extension BinderVariation { } var returnType: String { + return "SomeBindingMaker" + } + + var actualReturnType: String { if isScoped { return "ScopedBinding.Builder" } else { @@ -144,7 +148,7 @@ extension BinderVariation { let prefix = indent ? " " : "" return """ \(prefix)public func \(functionName)<\(genericTypes)>(\(params)) -> \(returnType) \(constraints){ - \(prefix) .init\(initVars) { \(builderInputs) in try builder(\(builderVars)) } + \(prefix) \(actualReturnType)\(initVars) { \(builderInputs) in try builder(\(builderVars)) }.opaque \(prefix)} """ } diff --git a/Templates/MatchableBoxes.swifttemplate b/Templates/MatchableBoxes.swifttemplate index 07c21033..1a49df25 100644 --- a/Templates/MatchableBoxes.swifttemplate +++ b/Templates/MatchableBoxes.swifttemplate @@ -5,7 +5,7 @@ let arg_hashables = (1...i).map { "Arg\($0): Hashable" }.joined(separator: ", ") let type_name = "MatchableBox\(i)<\(arg_types)>" -%> -public struct <%= type_name %>: Hashable, Matchable where <%= arg_hashables %> { +struct <%= type_name %>: Hashable, Matchable where <%= arg_hashables %> { <%= (1...i).map { "let arg\($0): Arg\($0)" }.joined(separator: "\n ") %> } diff --git a/Templates/SwiftCode.swifttemplate b/Templates/SwiftCode.swifttemplate index f2c57cd1..c9f6512f 100644 --- a/Templates/SwiftCode.swifttemplate +++ b/Templates/SwiftCode.swifttemplate @@ -61,6 +61,10 @@ extension BinderVariation { } var returnType: String { + return "SomeBindingMaker" + } + + var actualReturnType: String { if isScoped { return "ScopedBinding.Builder" } else { @@ -145,7 +149,7 @@ extension BinderVariation { let prefix = indent ? " " : "" return """ \(prefix)public func \(functionName)<\(genericTypes)>(\(params)) -> \(returnType) \(constraints){ - \(prefix) .init\(initVars) { \(builderInputs) in try builder(\(builderVars)) } + \(prefix) \(actualReturnType)\(initVars) { \(builderInputs) in try builder(\(builderVars)) }.opaque \(prefix)} """ } diff --git a/Tests/Support/Convenience.swift b/Tests/Support/Convenience.swift index 11de8323..c3da95e0 100644 --- a/Tests/Support/Convenience.swift +++ b/Tests/Support/Convenience.swift @@ -5,24 +5,6 @@ import Nimble @testable import Swinject -extension InstanceMaker where Argument == Void, Context == Any { - func makeInstance(resolver: Resolver) throws -> MadeType { - try makeInstance(arg: (), context: (), resolver: resolver) - } -} - -extension InstanceMaker where Argument == Void { - func makeInstance(context: Context, resolver: Resolver) throws -> MadeType { - try makeInstance(arg: (), context: context, resolver: resolver) - } -} - -extension InstanceMaker where Context == Any { - func makeInstance(arg: Argument, resolver: Resolver) throws -> MadeType { - try makeInstance(arg: arg, context: (), resolver: resolver) - } -} - func concurrentPerform(iterations: Int, action: () -> Void) { var finished = 0 DispatchQueue.concurrentPerform(iterations: iterations) { _ in diff --git a/Tests/Unit Specs/BinderEnvironmentSpec.swift b/Tests/Unit Specs/BinderEnvironmentSpec.swift index 4d15ca4f..16898572 100644 --- a/Tests/Unit Specs/BinderEnvironmentSpec.swift +++ b/Tests/Unit Specs/BinderEnvironmentSpec.swift @@ -11,8 +11,8 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { describe("implicit") { describe("instance") { it("produces maker with correct type signature") { - let maker = instance(42) as Any - expect(maker is SimpleBinding.Builder).to(beTrue()) + let maker = instance(42) + expect(maker.actual is SimpleBinding.Builder).to(beTrue()) } it("returns given instance") { let maker = instance(42) @@ -21,8 +21,8 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { } describe("provider") { it("produces maker with correct type signature") { - let maker = provider { 42 } as Any - expect(maker is SimpleBinding.Builder).to(beTrue()) + let maker = provider { 42 } + expect(maker.actual is SimpleBinding.Builder).to(beTrue()) } it("returns instance made by provider method") { let maker = provider { 42 } @@ -53,8 +53,8 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { } describe("factory") { it("produces maker with correct type signature") { - let maker = factory { (_, _: Void) in 42 } as Any - expect(maker is SimpleBinding.Builder).to(beTrue()) + let maker = factory { (_, _: Void) in 42 } + expect(maker.actual is SimpleBinding.Builder).to(beTrue()) } it("returns instance made by builder method") { let maker = factory { (_, _: Void) in 42 } @@ -113,13 +113,13 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { } describe("singleton") { it("has correct scope") { - let maker = singleton { 0 } - expect(maker.scope) === UnboundScope.root + let maker = singleton { 0 }.actual as? ScopedBinding.Builder + expect(maker?.scope) === UnboundScope.root } it("has correct reference maker") { let makeRef: ReferenceMaker = { _ in noRef(42) } - let maker = singleton(ref: makeRef) { 0 } - expect(maker.makeRef(0).currentValue as? Int) == 42 + let maker = singleton(ref: makeRef) { 0 }.actual as? ScopedBinding.Builder + expect(maker?.makeRef(0).currentValue as? Int) == 42 } it("returns instance made by builder") { let maker = singleton { 42 } @@ -151,12 +151,14 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { describe("multiton") { it("has correct scope") { let maker = multiton { (_, _: String) in 42 } - expect(maker.scope) === UnboundScope.root + let actualMaker = maker.actual as? ScopedBinding.Builder> + expect(actualMaker?.scope) === UnboundScope.root } it("has correct reference maker") { let makeRef: ReferenceMaker = { _ in noRef(42) } - let maker = singleton(ref: makeRef) { 0 } - expect(maker.makeRef(0).currentValue as? Int) == 42 + let maker = multiton(ref: makeRef) { (_, _: String) in 42 } + let actualMaker = maker.actual as? ScopedBinding.Builder> + expect(actualMaker?.makeRef(0).currentValue as? Int) == 42 } it("returns instance made by builder method") { let maker = multiton { (_, _: String) in 42 } @@ -326,7 +328,8 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { describe("singleton") { it("has correct scope") { let maker = environment.singleton { 42 } - expect(maker.scope) === scope + let actualMaker = maker.actual as? ScopedBinding.Builder + expect(actualMaker?.scope) === scope } it("returns instance made by builder") { let maker = environment.singleton { 42 } @@ -364,7 +367,8 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { describe("multiton") { it("has correct scope") { let maker = environment.multiton { (_, _, _: String) in 42 } - expect(maker.scope) === scope + let actualMaker = maker.actual as? ScopedBinding.Builder> + expect(actualMaker?.scope) === scope } it("returns instance made by builder method") { let maker = environment.multiton { (_, _, _: String) in 42 } @@ -429,3 +433,23 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { } } } } + +private extension SomeBindingMaker { + var actual: AnyInstanceMaker { anyActual as! AnyInstanceMaker } + + func makeInstance(resolver: Resolver) throws -> BoundType { + try actual.makeInstance(arg: (), context: (), resolver: resolver) as! BoundType + } + + func makeInstance(context: Any, resolver: Resolver) throws -> BoundType { + try actual.makeInstance(arg: (), context: context, resolver: resolver) as! BoundType + } + + func makeInstance(arg: Any, resolver: Resolver) throws -> BoundType { + try actual.makeInstance(arg: arg, context: (), resolver: resolver) as! BoundType + } + + func makeInstance(arg: Any, context: Any, resolver: Resolver) throws -> BoundType { + try actual.makeInstance(arg: arg, context: context, resolver: resolver) as! BoundType + } +} From 6a619cc0ae8b1a290b7eb591cb1f6a4c92d4e383 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sat, 27 Jul 2019 14:24:49 +0200 Subject: [PATCH 148/239] Fix access modifiers on injection API --- Sources/3.0 API/Resolver+Injection.swift | 6 +++--- Templates/Resolver+Injection.swifttemplate | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/3.0 API/Resolver+Injection.swift b/Sources/3.0 API/Resolver+Injection.swift index 370f60d1..c77e31a9 100644 --- a/Sources/3.0 API/Resolver+Injection.swift +++ b/Sources/3.0 API/Resolver+Injection.swift @@ -6,7 +6,7 @@ // swiftlint:disable function_parameter_count // swiftlint:disable file_length // sourcery:inline:ResolverInjectionApi -extension Resolver { +public extension Resolver { func instance(of _: Type.Type = Type.self) throws -> Type { try resolve(request(tag: NoTag(), arg: ())) } @@ -96,7 +96,7 @@ extension Resolver { } } -extension Resolver { +public extension Resolver { func provider(of _: Type.Type = Type.self) -> () throws -> Type { return { try self.resolve(request(tag: NoTag(), arg: ())) } } @@ -186,7 +186,7 @@ extension Resolver { } } -extension Resolver { +public extension Resolver { func factory(of _: Type.Type = Type.self) -> (Arg1) throws -> Type { return { try self.resolve(request(tag: NoTag(), arg: box($0))) } } diff --git a/Templates/Resolver+Injection.swifttemplate b/Templates/Resolver+Injection.swifttemplate index bc542e90..e2dc0ad5 100644 --- a/Templates/Resolver+Injection.swifttemplate +++ b/Templates/Resolver+Injection.swifttemplate @@ -1,14 +1,14 @@ <%- include("SwiftCode") %> // sourcery:inline:ResolverInjectionApi -extension Resolver { +public extension Resolver { <%= InjectionVariation.publicCases.filter { $0.functionName == "instance" }.map { $0.render() }.joined(separator: "\n\n") %> } -extension Resolver { +public extension Resolver { <%= InjectionVariation.publicCases.filter { $0.functionName == "provider" }.map { $0.render() }.joined(separator: "\n\n") %> } -extension Resolver { +public extension Resolver { <%= InjectionVariation.publicCases.filter { $0.functionName == "factory" }.map { $0.render() }.joined(separator: "\n\n") %> } // sourcery:end From f45c73c0bb22f0caae59e70cd5881cfbcdbf540c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sat, 27 Jul 2019 14:55:28 +0200 Subject: [PATCH 149/239] Improve autocompletion on scoped / contexted environments --- Sources/3.0 API/BinderEnvironment.swift | 18 ++++++++++-------- Templates/BinderEnvironment.swifttemplate | 4 ++-- Tests/Unit Specs/BinderEnvironmentSpec.swift | 4 ++-- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/Sources/3.0 API/BinderEnvironment.swift b/Sources/3.0 API/BinderEnvironment.swift index 5c226355..1d343e85 100644 --- a/Sources/3.0 API/BinderEnvironment.swift +++ b/Sources/3.0 API/BinderEnvironment.swift @@ -2,19 +2,21 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -public struct BinderEnvironment { +public struct ScopedEnvironment where AScope: Scope { + public typealias Context = AScope.Context let scope: AScope } -public func contexted(_: Context.Type = Context.self) -> BinderEnvironment { - BinderEnvironment(scope: ()) +public struct ContextedEnvironment {} + +public func contexted(_: Context.Type) -> ContextedEnvironment { + ContextedEnvironment() } -public func scoped(_ scope: AScope) -> BinderEnvironment where AScope: Scope { - BinderEnvironment(scope: scope) +public func scoped(_ scope: AScope) -> ScopedEnvironment where AScope: Scope { + ScopedEnvironment(scope: scope) } -// swiftlint:disable large_tuple // swiftlint:disable line_length // swiftlint:disable identifier_name @@ -23,7 +25,7 @@ public func instance(_ instance: Type) -> SomeBindingMaker { } // sourcery:inline:BindingBuilders -extension BinderEnvironment where AScope == Void { +extension ContextedEnvironment { public func provider(_ builder: @escaping () throws -> Type) -> SomeBindingMaker { SimpleBinding.Builder { _, _, _ in try builder() }.opaque } @@ -77,7 +79,7 @@ extension BinderEnvironment where AScope == Void { } } -extension BinderEnvironment where AScope: Scope, Context == AScope.Context { +extension ScopedEnvironment { public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping () throws -> Type) -> SomeBindingMaker { ScopedBinding.Builder(scope, ref) { _, _, _ in try builder() }.opaque } diff --git a/Templates/BinderEnvironment.swifttemplate b/Templates/BinderEnvironment.swifttemplate index 69448d3f..d8224c88 100644 --- a/Templates/BinderEnvironment.swifttemplate +++ b/Templates/BinderEnvironment.swifttemplate @@ -1,10 +1,10 @@ <%- include("SwiftCode") %> // sourcery:inline:BindingBuilders -extension BinderEnvironment where AScope == Void { +extension ContextedEnvironment { <%= BinderVariation.publicCases.filter { $0.isContexted && !$0.isScoped }.map { $0.render(true) }.joined(separator: "\n\n") %> } -extension BinderEnvironment where AScope: Scope, Context == AScope.Context { +extension ScopedEnvironment { <%= BinderVariation.publicCases.filter { $0.isContexted && $0.isScoped }.map { $0.render(true) }.joined(separator: "\n\n") %> } diff --git a/Tests/Unit Specs/BinderEnvironmentSpec.swift b/Tests/Unit Specs/BinderEnvironmentSpec.swift index 16898572..35a3053d 100644 --- a/Tests/Unit Specs/BinderEnvironmentSpec.swift +++ b/Tests/Unit Specs/BinderEnvironmentSpec.swift @@ -217,7 +217,7 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { } } describe("contexted") { - var environment: BinderEnvironment! + var environment: ContextedEnvironment! beforeEach { environment = contexted(Any.self) } @@ -320,7 +320,7 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { } describe("scoped") { var scope = AnyScopeMock() - var environment: BinderEnvironment! + var environment: ScopedEnvironment! beforeEach { scope = AnyScopeMock() environment = scoped(scope) From 3f606dbc805bca90972b06a6fd16a1bbed62771e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sat, 27 Jul 2019 17:56:43 +0200 Subject: [PATCH 150/239] Make code compatible with Swift < 5.1 --- .Package.Test.swift | 4 +- .travis.yml | 12 +- Sources/2.0 API/Container.swift | 8 +- Sources/2.0 API/ObjectScope.swift | 4 +- Sources/2.0 API/ServiceEntry.swift | 2 +- Sources/3.0 API/BinderEnvironment.swift | 86 ++++---- Sources/3.0 API/Resolver+Injection.swift | 44 ++-- Sources/3.0 API/Swinject+Builder.swift | 7 + Sources/3.0 API/TypeBinder.swift | 14 +- Sources/Core/Binding.swift | 4 +- Sources/Core/BindingKey.swift | 2 +- Sources/Core/ContextTranslator.swift | 4 +- Sources/Core/InstanceRequest.swift | 4 +- Sources/Core/Matchable.swift | 22 +- Sources/Core/Opaque.swift | 2 +- Sources/Core/Reference.swift | 4 +- Sources/Core/Scope.swift | 4 +- Sources/Core/ScopeRegistry.swift | 4 +- Sources/Core/ScopeRegistryKey.swift | 4 +- Sources/Core/ScopedBinding.swift | 8 +- Sources/Core/SimpleBinding.swift | 8 +- Sources/Core/Swinject.swift | 2 +- Sources/Core/SwinjectTree.swift | 18 +- Sources/Core/TypeDescriptor.swift | 6 +- Swinject.xcodeproj/project.pbxproj | 136 ++++-------- Templates/BinderVariation.swift | 28 +-- Templates/InjectionVariation.swift | 16 +- Templates/MatchableBoxes.swifttemplate | 4 +- Templates/SwiftCode.swifttemplate | 48 ++--- Templates/Utils.swift | 4 +- Tests/3.0 API/SwinjectApiSpec.swift | 113 +++++----- Tests/3.0 API/SwinjectApiSpecSwift5_1.swift | 198 ++++++++++++++++++ Tests/Support/Bridge.swift | 6 +- Tests/Support/Convenience.swift | 1 + Tests/Support/NonGeneratedMocks.swift | 8 +- Tests/Unit Specs/BinderEnvironmentSpec.swift | 10 +- Tests/Unit Specs/BindingKeySpec.swift | 2 +- .../StandardScopeRegistrySpec.swift | 1 + Tests/Unit Specs/SwinjectSpec.swift | 26 +-- .../Unit Specs/SwinjectTreeBuilderSpec.swift | 25 ++- 40 files changed, 539 insertions(+), 364 deletions(-) create mode 100644 Tests/3.0 API/SwinjectApiSpecSwift5_1.swift diff --git a/.Package.Test.swift b/.Package.Test.swift index 3bcda774..ac1baac7 100644 --- a/.Package.Test.swift +++ b/.Package.Test.swift @@ -26,7 +26,9 @@ let package = Package( "Quick", "Nimble", "Swinject", - ] + ], + path: "Tests", + exclude: ["LinuxMain.swift"] ), ] ) diff --git a/.travis.yml b/.travis.yml index c5dadfcd..3b424ed3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ env: - PROJECT=Swinject.xcodeproj matrix: include: - - env: JOB="LINUX_SPM" SWIFT_VERSION="5.1" + - env: JOB="LINUX_SPM" SWIFT_VERSION="5.0" os: linux language: generic sudo: required @@ -17,18 +17,20 @@ matrix: - swift build - swift test - env: JOB="POD_LINT" - osx_image: xcode11 + osx_image: xcode10.2 before_install: script: - pod lib lint - env: JOB="XCODE" DEST="OS=10.0,name=iPhone 6" SCHEME="Swinject-iOS" SDK="iphonesimulator" ACTION="test" PLATFORM="iOS" - osx_image: xcode11 + osx_image: xcode10.2 + - env: JOB="XCODE" DEST="arch=x86_64" SCHEME="Swinject-macOS" SDK="macosx" ACTION="test" PLATFORM="OSX" + osx_image: xcode10.2 - env: JOB="XCODE" DEST="arch=x86_64" SCHEME="Swinject-macOS" SDK="macosx" ACTION="test" PLATFORM="OSX" osx_image: xcode11 - env: JOB="XCODE" DEST="OS=10.0,name=Apple TV 1080p" SCHEME="Swinject-tvOS" SDK="appletvsimulator" ACTION="test" PLATFORM="tvOS" - osx_image: xcode11 + osx_image: xcode10.2 - env: JOB="XCODE" DEST="OS=2.2,name=Apple Watch - 42mm" SCHEME="Swinject-watchOS" SDK="watchsimulator" ACTION="build" PLATFORM="watchOS" - osx_image: xcode11 + osx_image: xcode10.2 before_install: - curl -L -O https://github.com/Carthage/Carthage/releases/download/0.33.0/Carthage.pkg diff --git a/Sources/2.0 API/Container.swift b/Sources/2.0 API/Container.swift index bca7f075..d173a47f 100644 --- a/Sources/2.0 API/Container.swift +++ b/Sources/2.0 API/Container.swift @@ -29,7 +29,7 @@ public final class Container { let defaultObjectScope: ObjectScope var bindings = [Binding]() var behaviors = [Behavior]() - var swinject: Swinject { Swinject(tree: SwinjectTree( + var swinject: Swinject { return Swinject(tree: SwinjectTree( bindings: allBindings, includeEntries: [], translators: [registerContextTranslator(from: Graph.self) { $0.container }] @@ -87,7 +87,7 @@ public final class Container { /// /// - Returns: A synchronized container as `Resolver`. public func synchronize() -> Resolver { - self + return self } /// Adds behavior to the container. `Behavior.container(_:didRegisterService:withName:)` will be invoked for @@ -111,7 +111,7 @@ public final class Container { extension Container: CustomStringConvertible { public var description: String { - "" + return "" } } @@ -121,6 +121,6 @@ extension Container: Resolver { public func resolve( _ request: InstanceRequest ) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { - try swinject.on(Graph(on: self)).resolve(request) + return try swinject.on(Graph(on: self)).resolve(request) } } diff --git a/Sources/2.0 API/ObjectScope.swift b/Sources/2.0 API/ObjectScope.swift index 890dffc3..49f18a76 100644 --- a/Sources/2.0 API/ObjectScope.swift +++ b/Sources/2.0 API/ObjectScope.swift @@ -35,7 +35,7 @@ extension ObjectScope { func makeRef(in container: Container?) -> ReferenceMaker { weak var container = container func containerRef(_ value: Any) -> Reference { - Reference(currentValue: value) { [weak handle = container?.referenceHandle] in + return Reference(currentValue: value) { [weak handle = container?.referenceHandle] in handle == nil ? nil : value } } @@ -69,6 +69,6 @@ final class ContainerScope: Scope { static let shared = ContainerScope() func registry(for container: Container) -> ScopeRegistry { - container.registry + return container.registry } } diff --git a/Sources/2.0 API/ServiceEntry.swift b/Sources/2.0 API/ServiceEntry.swift index 95a47db8..d09e4cd2 100644 --- a/Sources/2.0 API/ServiceEntry.swift +++ b/Sources/2.0 API/ServiceEntry.swift @@ -89,7 +89,7 @@ extension ServiceEntry: Binding { } private var key: BindingKey { - BindingKey( + return BindingKey( descriptor: { if let name = name { return tagged(Service.self, with: name) diff --git a/Sources/3.0 API/BinderEnvironment.swift b/Sources/3.0 API/BinderEnvironment.swift index 1d343e85..29d8d1c2 100644 --- a/Sources/3.0 API/BinderEnvironment.swift +++ b/Sources/3.0 API/BinderEnvironment.swift @@ -10,183 +10,183 @@ public struct ScopedEnvironment where AScope: Scope { public struct ContextedEnvironment {} public func contexted(_: Context.Type) -> ContextedEnvironment { - ContextedEnvironment() + return ContextedEnvironment() } public func scoped(_ scope: AScope) -> ScopedEnvironment where AScope: Scope { - ScopedEnvironment(scope: scope) + return ScopedEnvironment(scope: scope) } // swiftlint:disable line_length // swiftlint:disable identifier_name public func instance(_ instance: Type) -> SomeBindingMaker { - SimpleBinding.Builder { _, _, _ in instance }.opaque + return SimpleBinding.Builder { _, _, _ in instance }.opaque } // sourcery:inline:BindingBuilders extension ContextedEnvironment { public func provider(_ builder: @escaping () throws -> Type) -> SomeBindingMaker { - SimpleBinding.Builder { _, _, _ in try builder() }.opaque + return SimpleBinding.Builder { _, _, _ in try builder() }.opaque } public func provider(_ builder: @escaping (Resolver) throws -> Type) -> SomeBindingMaker { - SimpleBinding.Builder { r, _, _ in try builder(r) }.opaque + return SimpleBinding.Builder { r, _, _ in try builder(r) }.opaque } public func provider(_ builder: @escaping (Resolver, Context) throws -> Type) -> SomeBindingMaker { - SimpleBinding.Builder { r, c, _ in try builder(r, c) }.opaque + return SimpleBinding.Builder { r, c, _ in try builder(r, c) }.opaque } public func factory(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SomeBindingMaker { - SimpleBinding.Builder { r, c, a in try builder(r, c, a) }.opaque + return SimpleBinding.Builder { r, c, a in try builder(r, c, a) }.opaque } public func factory(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SomeBindingMaker where Arg1: Hashable { - SimpleBinding.Builder> { r, c, a in try builder(r, c, a.arg1) }.opaque + return SimpleBinding.Builder> { r, c, a in try builder(r, c, a.arg1) }.opaque } public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SomeBindingMaker { - SimpleBinding.Builder { r, c, a in try builder(r, c, a.0, a.1) }.opaque + return SimpleBinding.Builder { r, c, a in try builder(r, c, a.0, a.1) }.opaque } public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable { - SimpleBinding.Builder> { r, c, a in try builder(r, c, a.arg1, a.arg2) }.opaque + return SimpleBinding.Builder> { r, c, a in try builder(r, c, a.arg1, a.arg2) }.opaque } public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingMaker { - SimpleBinding.Builder { r, c, a in try builder(r, c, a.0, a.1, a.2) }.opaque + return SimpleBinding.Builder { r, c, a in try builder(r, c, a.0, a.1, a.2) }.opaque } public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - SimpleBinding.Builder> { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3) }.opaque + return SimpleBinding.Builder> { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3) }.opaque } public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingMaker { - SimpleBinding.Builder { r, c, a in try builder(r, c, a.0, a.1, a.2, a.3) }.opaque + return SimpleBinding.Builder { r, c, a in try builder(r, c, a.0, a.1, a.2, a.3) }.opaque } public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - SimpleBinding.Builder> { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3, a.arg4) }.opaque + return SimpleBinding.Builder> { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3, a.arg4) }.opaque } public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingMaker { - SimpleBinding.Builder { r, c, a in try builder(r, c, a.0, a.1, a.2, a.3, a.4) }.opaque + return SimpleBinding.Builder { r, c, a in try builder(r, c, a.0, a.1, a.2, a.3, a.4) }.opaque } public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - SimpleBinding.Builder> { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) }.opaque + return SimpleBinding.Builder> { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) }.opaque } } extension ScopedEnvironment { public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping () throws -> Type) -> SomeBindingMaker { - ScopedBinding.Builder(scope, ref) { _, _, _ in try builder() }.opaque + return ScopedBinding.Builder(scope, ref) { _, _, _ in try builder() }.opaque } public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver) throws -> Type) -> SomeBindingMaker { - ScopedBinding.Builder(scope, ref) { r, _, _ in try builder(r) }.opaque + return ScopedBinding.Builder(scope, ref) { r, _, _ in try builder(r) }.opaque } public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context) throws -> Type) -> SomeBindingMaker { - ScopedBinding.Builder(scope, ref) { r, c, _ in try builder(r, c) }.opaque + return ScopedBinding.Builder(scope, ref) { r, c, _ in try builder(r, c) }.opaque } public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SomeBindingMaker where Arg1: Hashable { - ScopedBinding.Builder>(scope, ref) { r, c, a in try builder(r, c, a.arg1) }.opaque + return ScopedBinding.Builder>(scope, ref) { r, c, a in try builder(r, c, a.arg1) }.opaque } public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable { - ScopedBinding.Builder>(scope, ref) { r, c, a in try builder(r, c, a.arg1, a.arg2) }.opaque + return ScopedBinding.Builder>(scope, ref) { r, c, a in try builder(r, c, a.arg1, a.arg2) }.opaque } public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - ScopedBinding.Builder>(scope, ref) { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3) }.opaque + return ScopedBinding.Builder>(scope, ref) { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3) }.opaque } public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - ScopedBinding.Builder>(scope, ref) { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3, a.arg4) }.opaque + return ScopedBinding.Builder>(scope, ref) { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3, a.arg4) }.opaque } public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - ScopedBinding.Builder>(scope, ref) { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) }.opaque + return ScopedBinding.Builder>(scope, ref) { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) }.opaque } } public func provider(_ builder: @escaping () throws -> Type) -> SomeBindingMaker { - SimpleBinding.Builder { _, _, _ in try builder() }.opaque + return SimpleBinding.Builder { _, _, _ in try builder() }.opaque } public func provider(_ builder: @escaping (Resolver) throws -> Type) -> SomeBindingMaker { - SimpleBinding.Builder { r, _, _ in try builder(r) }.opaque + return SimpleBinding.Builder { r, _, _ in try builder(r) }.opaque } public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> SomeBindingMaker { - SimpleBinding.Builder { r, _, a in try builder(r, a) }.opaque + return SimpleBinding.Builder { r, _, a in try builder(r, a) }.opaque } public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> SomeBindingMaker where Arg1: Hashable { - SimpleBinding.Builder> { r, _, a in try builder(r, a.arg1) }.opaque + return SimpleBinding.Builder> { r, _, a in try builder(r, a.arg1) }.opaque } public func factory(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SomeBindingMaker { - SimpleBinding.Builder { r, _, a in try builder(r, a.0, a.1) }.opaque + return SimpleBinding.Builder { r, _, a in try builder(r, a.0, a.1) }.opaque } public func factory(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable { - SimpleBinding.Builder> { r, _, a in try builder(r, a.arg1, a.arg2) }.opaque + return SimpleBinding.Builder> { r, _, a in try builder(r, a.arg1, a.arg2) }.opaque } public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingMaker { - SimpleBinding.Builder { r, _, a in try builder(r, a.0, a.1, a.2) }.opaque + return SimpleBinding.Builder { r, _, a in try builder(r, a.0, a.1, a.2) }.opaque } public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - SimpleBinding.Builder> { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3) }.opaque + return SimpleBinding.Builder> { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3) }.opaque } public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingMaker { - SimpleBinding.Builder { r, _, a in try builder(r, a.0, a.1, a.2, a.3) }.opaque + return SimpleBinding.Builder { r, _, a in try builder(r, a.0, a.1, a.2, a.3) }.opaque } public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - SimpleBinding.Builder> { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3, a.arg4) }.opaque + return SimpleBinding.Builder> { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3, a.arg4) }.opaque } public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingMaker { - SimpleBinding.Builder { r, _, a in try builder(r, a.0, a.1, a.2, a.3, a.4) }.opaque + return SimpleBinding.Builder { r, _, a in try builder(r, a.0, a.1, a.2, a.3, a.4) }.opaque } public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - SimpleBinding.Builder> { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) }.opaque + return SimpleBinding.Builder> { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) }.opaque } public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping () throws -> Type) -> SomeBindingMaker { - ScopedBinding.Builder(.root, ref) { _, _, _ in try builder() }.opaque + return ScopedBinding.Builder(.root, ref) { _, _, _ in try builder() }.opaque } public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver) throws -> Type) -> SomeBindingMaker { - ScopedBinding.Builder(.root, ref) { r, _, _ in try builder(r) }.opaque + return ScopedBinding.Builder(.root, ref) { r, _, _ in try builder(r) }.opaque } public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1) throws -> Type) -> SomeBindingMaker where Arg1: Hashable { - ScopedBinding.Builder>(.root, ref) { r, _, a in try builder(r, a.arg1) }.opaque + return ScopedBinding.Builder>(.root, ref) { r, _, a in try builder(r, a.arg1) }.opaque } public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable { - ScopedBinding.Builder>(.root, ref) { r, _, a in try builder(r, a.arg1, a.arg2) }.opaque + return ScopedBinding.Builder>(.root, ref) { r, _, a in try builder(r, a.arg1, a.arg2) }.opaque } public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - ScopedBinding.Builder>(.root, ref) { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3) }.opaque + return ScopedBinding.Builder>(.root, ref) { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3) }.opaque } public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - ScopedBinding.Builder>(.root, ref) { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3, a.arg4) }.opaque + return ScopedBinding.Builder>(.root, ref) { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3, a.arg4) }.opaque } public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - ScopedBinding.Builder>(.root, ref) { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) }.opaque + return ScopedBinding.Builder>(.root, ref) { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) }.opaque } // sourcery:end diff --git a/Sources/3.0 API/Resolver+Injection.swift b/Sources/3.0 API/Resolver+Injection.swift index c77e31a9..637fb71b 100644 --- a/Sources/3.0 API/Resolver+Injection.swift +++ b/Sources/3.0 API/Resolver+Injection.swift @@ -8,91 +8,91 @@ // sourcery:inline:ResolverInjectionApi public extension Resolver { func instance(of _: Type.Type = Type.self) throws -> Type { - try resolve(request(tag: NoTag(), arg: ())) + return try resolve(request(tag: NoTag(), arg: ())) } func instance(of _: Type.Type = Type.self, tagged tag: Tag) throws -> Type where Tag: Hashable { - try resolve(request(tag: tag, arg: ())) + return try resolve(request(tag: tag, arg: ())) } func instance(of _: Type.Type = Type.self, arg arg1: Arg1) throws -> Type { - try resolve(request(tag: NoTag(), arg: box(arg1))) + return try resolve(request(tag: NoTag(), arg: box(arg1))) } func instance(of _: Type.Type = Type.self, arg arg1: Arg1) throws -> Type where Arg1: Hashable { - try resolve(request(tag: NoTag(), arg: box(arg1))) + return try resolve(request(tag: NoTag(), arg: box(arg1))) } func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) throws -> Type where Tag: Hashable { - try resolve(request(tag: tag, arg: box(arg1))) + return try resolve(request(tag: tag, arg: box(arg1))) } func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) throws -> Type where Tag: Hashable, Arg1: Hashable { - try resolve(request(tag: tag, arg: box(arg1))) + return try resolve(request(tag: tag, arg: box(arg1))) } func instance(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2) throws -> Type { - try resolve(request(tag: NoTag(), arg: box(arg1, arg2))) + return try resolve(request(tag: NoTag(), arg: box(arg1, arg2))) } func instance(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2) throws -> Type where Arg1: Hashable, Arg2: Hashable { - try resolve(request(tag: NoTag(), arg: box(arg1, arg2))) + return try resolve(request(tag: NoTag(), arg: box(arg1, arg2))) } func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2) throws -> Type where Tag: Hashable { - try resolve(request(tag: tag, arg: box(arg1, arg2))) + return try resolve(request(tag: tag, arg: box(arg1, arg2))) } func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable { - try resolve(request(tag: tag, arg: box(arg1, arg2))) + return try resolve(request(tag: tag, arg: box(arg1, arg2))) } func instance(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) throws -> Type { - try resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3))) + return try resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3))) } func instance(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - try resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3))) + return try resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3))) } func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) throws -> Type where Tag: Hashable { - try resolve(request(tag: tag, arg: box(arg1, arg2, arg3))) + return try resolve(request(tag: tag, arg: box(arg1, arg2, arg3))) } func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - try resolve(request(tag: tag, arg: box(arg1, arg2, arg3))) + return try resolve(request(tag: tag, arg: box(arg1, arg2, arg3))) } func instance(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) throws -> Type { - try resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3, arg4))) + return try resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3, arg4))) } func instance(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - try resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3, arg4))) + return try resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3, arg4))) } func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) throws -> Type where Tag: Hashable { - try resolve(request(tag: tag, arg: box(arg1, arg2, arg3, arg4))) + return try resolve(request(tag: tag, arg: box(arg1, arg2, arg3, arg4))) } func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - try resolve(request(tag: tag, arg: box(arg1, arg2, arg3, arg4))) + return try resolve(request(tag: tag, arg: box(arg1, arg2, arg3, arg4))) } func instance(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) throws -> Type { - try resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3, arg4, arg5))) + return try resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3, arg4, arg5))) } func instance(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - try resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3, arg4, arg5))) + return try resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3, arg4, arg5))) } func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) throws -> Type where Tag: Hashable { - try resolve(request(tag: tag, arg: box(arg1, arg2, arg3, arg4, arg5))) + return try resolve(request(tag: tag, arg: box(arg1, arg2, arg3, arg4, arg5))) } func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - try resolve(request(tag: tag, arg: box(arg1, arg2, arg3, arg4, arg5))) + return try resolve(request(tag: tag, arg: box(arg1, arg2, arg3, arg4, arg5))) } } diff --git a/Sources/3.0 API/Swinject+Builder.swift b/Sources/3.0 API/Swinject+Builder.swift index cffaa9a9..7e77285c 100644 --- a/Sources/3.0 API/Swinject+Builder.swift +++ b/Sources/3.0 API/Swinject+Builder.swift @@ -3,6 +3,12 @@ // public extension Swinject { + init(_ entries: SwinjectEntry ...) { + self.init(tree: SwinjectTreeBuilder.buildFunction(entries)) + } +} + +public extension Swinject { #if swift(>=5.1) init(@SwinjectTreeBuilder builder: () -> [SwinjectEntry]) { self.init(tree: SwinjectTreeBuilder.buildFunction(builder())) } @@ -14,4 +20,5 @@ public extension Swinject { init(@SwinjectTreeBuilder _: () -> Void) { self.init(tree: SwinjectTreeBuilder.buildFunction([])) } +#endif } diff --git a/Sources/3.0 API/TypeBinder.swift b/Sources/3.0 API/TypeBinder.swift index d9501266..f52fe822 100644 --- a/Sources/3.0 API/TypeBinder.swift +++ b/Sources/3.0 API/TypeBinder.swift @@ -7,36 +7,36 @@ public struct TypeBinder where Descriptor: TypeDescriptor { } public func bind(_: Type.Type) -> TypeBinder> { - TypeBinder(descriptor: plain(Type.self).opaque) + return TypeBinder(descriptor: plain(Type.self).opaque) } public func bind(_: Type.Type, tagged tag: Tag) -> TypeBinder> where Tag: Hashable { - TypeBinder(descriptor: tagged(Type.self, with: tag).opaque) + return TypeBinder(descriptor: tagged(Type.self, with: tag).opaque) } // TODO: Compiler Bug? // omitting `decriptor` param name here causes compiler to incorrectly infer types when using bind(), e.g.: // bind(CustomStringConvertible.self).with(provider { 42 }) public func bind(descriptor: Descriptor) -> TypeBinder where Descriptor: TypeDescriptor { - TypeBinder(descriptor: descriptor) + return TypeBinder(descriptor: descriptor) } public extension TypeBinder { func with(_ maker: Maker) -> Binding where Maker: BindingMaker, Maker.BoundType == Descriptor.BaseType { - maker.makeBinding(for: descriptor) + return maker.makeBinding(for: descriptor) } func with(_ value: Descriptor.BaseType) -> Binding { - instance(value).makeBinding(for: descriptor) + return instance(value).makeBinding(for: descriptor) } } public func & ( lhs: TypeBinder, rhs: Maker ) -> Binding where Maker: BindingMaker, Maker.BoundType == Descriptor.BaseType { - lhs.with(rhs) + return lhs.with(rhs) } public func & (lhs: TypeBinder, rhs: Descriptor.BaseType) -> Binding { - lhs.with(rhs) + return lhs.with(rhs) } diff --git a/Sources/Core/Binding.swift b/Sources/Core/Binding.swift index 876d3baf..7ffdf0ab 100644 --- a/Sources/Core/Binding.swift +++ b/Sources/Core/Binding.swift @@ -19,12 +19,12 @@ public struct SomeBindingMaker: BindingMaker, AnyOpaque { fileprivate let _makeBinding: (AnyTypeDescriptor) -> Binding public func makeBinding(for descriptor: AnyTypeDescriptor) -> Binding { - _makeBinding(descriptor) + return _makeBinding(descriptor) } } public extension BindingMaker { var opaque: SomeBindingMaker { - SomeBindingMaker(anyActual: self) { self.makeBinding(for: $0) } + return SomeBindingMaker(anyActual: self) { self.makeBinding(for: $0) } } } diff --git a/Sources/Core/BindingKey.swift b/Sources/Core/BindingKey.swift index 8078c9ae..ae8d9ead 100644 --- a/Sources/Core/BindingKey.swift +++ b/Sources/Core/BindingKey.swift @@ -17,7 +17,7 @@ struct BindingKey: AnyBindingKey { let argumentType: Any.Type func matches(_ other: AnyBindingKey) -> Bool { - descriptor.matches(other.descriptor) + return descriptor.matches(other.descriptor) && (contextType == other.contextType || contextType == Any.self) && argumentType == other.argumentType } diff --git a/Sources/Core/ContextTranslator.swift b/Sources/Core/ContextTranslator.swift index 2954ebfe..3052026e 100644 --- a/Sources/Core/ContextTranslator.swift +++ b/Sources/Core/ContextTranslator.swift @@ -29,7 +29,7 @@ struct IdentityTranslator: AnyContextTranslator { targetType = contextType } - func translate(_ context: Any) throws -> Any { context } + func translate(_ context: Any) throws -> Any { return context } } public func registerContextTranslator( @@ -37,5 +37,5 @@ public func registerContextTranslator( to _: Target.Type = Target.self, using translation: @escaping (Source) -> Target ) -> ContextTranslator { - ContextTranslator(translation: translation) + return ContextTranslator(translation: translation) } diff --git a/Sources/Core/InstanceRequest.swift b/Sources/Core/InstanceRequest.swift index 533484ca..db2012ca 100644 --- a/Sources/Core/InstanceRequest.swift +++ b/Sources/Core/InstanceRequest.swift @@ -19,11 +19,11 @@ func request( tag: Tag, arg: Argument ) -> InstanceRequest, Argument> { - InstanceRequest(descriptor: tagged(type, with: tag), argument: arg) + return InstanceRequest(descriptor: tagged(type, with: tag), argument: arg) } extension AnyInstanceRequest { func key(forContextType contextType: Any.Type) -> BindingKey { - BindingKey(descriptor: descriptor, contextType: contextType, argumentType: argumentType) + return BindingKey(descriptor: descriptor, contextType: contextType, argumentType: argumentType) } } diff --git a/Sources/Core/Matchable.swift b/Sources/Core/Matchable.swift index 035c47b5..d8713a64 100644 --- a/Sources/Core/Matchable.swift +++ b/Sources/Core/Matchable.swift @@ -10,7 +10,7 @@ public protocol Matchable { public extension Matchable where Self: Equatable { func matches(_ other: Any) -> Bool { - self == (other as? Self) + return self == (other as? Self) } } @@ -48,43 +48,43 @@ struct MatchableBox5: Hashable, Matchable where Ar } func box(_ arg1: Arg1) -> Arg1 { - arg1 + return arg1 } func box(_ arg1: Arg1) -> MatchableBox1 where Arg1: Hashable { - MatchableBox1(arg1: arg1) + return MatchableBox1(arg1: arg1) } func box(_ arg1: Arg1, _ arg2: Arg2) -> (Arg1, Arg2) { - (arg1, arg2) + return (arg1, arg2) } func box(_ arg1: Arg1, _ arg2: Arg2) -> MatchableBox2 where Arg1: Hashable, Arg2: Hashable { - MatchableBox2(arg1: arg1, arg2: arg2) + return MatchableBox2(arg1: arg1, arg2: arg2) } func box(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> (Arg1, Arg2, Arg3) { - (arg1, arg2, arg3) + return (arg1, arg2, arg3) } func box(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> MatchableBox3 where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - MatchableBox3(arg1: arg1, arg2: arg2, arg3: arg3) + return MatchableBox3(arg1: arg1, arg2: arg2, arg3: arg3) } func box(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> (Arg1, Arg2, Arg3, Arg4) { - (arg1, arg2, arg3, arg4) + return (arg1, arg2, arg3, arg4) } func box(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> MatchableBox4 where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - MatchableBox4(arg1: arg1, arg2: arg2, arg3: arg3, arg4: arg4) + return MatchableBox4(arg1: arg1, arg2: arg2, arg3: arg3, arg4: arg4) } func box(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> (Arg1, Arg2, Arg3, Arg4, Arg5) { - (arg1, arg2, arg3, arg4, arg5) + return (arg1, arg2, arg3, arg4, arg5) } func box(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> MatchableBox5 where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - MatchableBox5(arg1: arg1, arg2: arg2, arg3: arg3, arg4: arg4, arg5: arg5) + return MatchableBox5(arg1: arg1, arg2: arg2, arg3: arg3, arg4: arg4, arg5: arg5) } // sourcery:end diff --git a/Sources/Core/Opaque.swift b/Sources/Core/Opaque.swift index f088b681..e29ef70c 100644 --- a/Sources/Core/Opaque.swift +++ b/Sources/Core/Opaque.swift @@ -12,5 +12,5 @@ protocol Opaque: AnyOpaque { } extension Opaque { - var anyActual: Any { actual } + var anyActual: Any { return actual } } diff --git a/Sources/Core/Reference.swift b/Sources/Core/Reference.swift index 9ad55217..243c46ca 100644 --- a/Sources/Core/Reference.swift +++ b/Sources/Core/Reference.swift @@ -10,7 +10,7 @@ public struct Reference { public typealias ReferenceMaker = (T) -> Reference public func strongRef(_ value: T) -> Reference { - Reference(currentValue: value, nextValue: { value }) + return Reference(currentValue: value, nextValue: { value }) } public func weakRef(_ value: T) -> Reference { @@ -21,5 +21,5 @@ public func weakRef(_ value: T) -> Reference { } func noRef(_ value: T) -> Reference { - Reference(currentValue: value, nextValue: { nil }) + return Reference(currentValue: value, nextValue: { nil }) } diff --git a/Sources/Core/Scope.swift b/Sources/Core/Scope.swift index 060a4b3f..0c6b1fd6 100644 --- a/Sources/Core/Scope.swift +++ b/Sources/Core/Scope.swift @@ -17,7 +17,7 @@ extension Scope { public var contextType: Any.Type { return Context.self } func registry(for context: Any) -> ScopeRegistry { - registry(for: context as! Context) + return registry(for: context as! Context) } } @@ -31,7 +31,7 @@ public class UnboundScope: Scope, Closable { } public func registry(for _: Any) -> ScopeRegistry { - _registry + return _registry } public func close() { diff --git a/Sources/Core/ScopeRegistry.swift b/Sources/Core/ScopeRegistry.swift index 5b6c6af9..2f5191e4 100644 --- a/Sources/Core/ScopeRegistry.swift +++ b/Sources/Core/ScopeRegistry.swift @@ -15,7 +15,7 @@ public protocol ScopeRegistry { extension ScopeRegistry { func instance(for key: ScopeRegistryKey, builder: () throws -> Reference) rethrows -> Any { - try instance(for: key, builder: builder, finalizer: { _ in }) + return try instance(for: key, builder: builder, finalizer: { _ in }) } } @@ -30,7 +30,7 @@ public class StandardScopeRegistry: ScopeRegistry, Closable { builder: () throws -> Reference, finalizer: (Any) throws -> Void ) rethrows -> Any { - try lock.sync { + return try lock.sync { if let instance = instances[key]?() { return instance } let ref = try builder() if let instance = instances[key]?() { return instance } diff --git a/Sources/Core/ScopeRegistryKey.swift b/Sources/Core/ScopeRegistryKey.swift index c85c9624..f83f2e2c 100644 --- a/Sources/Core/ScopeRegistryKey.swift +++ b/Sources/Core/ScopeRegistryKey.swift @@ -9,11 +9,11 @@ public struct ScopeRegistryKey { extension ScopeRegistryKey: Hashable { public static func == (lhs: ScopeRegistryKey, rhs: ScopeRegistryKey) -> Bool { - areDescriptorsEqual(lhs.descriptor, rhs.descriptor) && areArgumentsEqual(lhs.argument, rhs.argument) + return areDescriptorsEqual(lhs.descriptor, rhs.descriptor) && areArgumentsEqual(lhs.argument, rhs.argument) } private static func areDescriptorsEqual(_ lhs: AnyTypeDescriptor, _ rhs: AnyTypeDescriptor) -> Bool { - lhs.matches(rhs) && rhs.matches(lhs) + return lhs.matches(rhs) && rhs.matches(lhs) } private static func areArgumentsEqual(_ lhs: Any, _ rhs: Any) -> Bool { diff --git a/Sources/Core/ScopedBinding.swift b/Sources/Core/ScopedBinding.swift index 079dbba9..6307bf8c 100644 --- a/Sources/Core/ScopedBinding.swift +++ b/Sources/Core/ScopedBinding.swift @@ -11,11 +11,11 @@ struct ScopedBinding { extension ScopedBinding: Binding { func matches(_ key: AnyBindingKey) -> Bool { - self.key.matches(key) + return self.key.matches(key) } func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any { - try scope + return try scope .registry(for: context) .instance(for: ScopeRegistryKey(descriptor: key.descriptor, argument: arg)) { makeRef(try maker.makeInstance(arg: arg, context: context, resolver: resolver)) @@ -50,7 +50,7 @@ extension ScopedBinding.Builder: InstanceMaker { typealias Context = AScope.Context func makeInstance(arg: Argument, context: Context, resolver: Resolver) throws -> Type { - try builder(resolver, context, arg) + return try builder(resolver, context, arg) } } @@ -58,7 +58,7 @@ extension ScopedBinding.Builder: BindingMaker { typealias BoundType = Type func makeBinding(for descriptor: AnyTypeDescriptor) -> Binding { - ScopedBinding( + return ScopedBinding( key: BindingKey(descriptor: descriptor, contextType: Context.self, argumentType: Argument.self), maker: self, scope: scope, diff --git a/Sources/Core/SimpleBinding.swift b/Sources/Core/SimpleBinding.swift index 31ae5310..308ab560 100644 --- a/Sources/Core/SimpleBinding.swift +++ b/Sources/Core/SimpleBinding.swift @@ -9,11 +9,11 @@ struct SimpleBinding { extension SimpleBinding: Binding { func matches(_ key: AnyBindingKey) -> Bool { - self.key.matches(key) + return self.key.matches(key) } func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any { - try maker.makeInstance(arg: arg, context: context, resolver: resolver) + return try maker.makeInstance(arg: arg, context: context, resolver: resolver) } } @@ -31,7 +31,7 @@ extension SimpleBinding.Builder: InstanceMaker { typealias MadeType = Type func makeInstance(arg: Argument, context: Context, resolver: Resolver) throws -> Type { - try builder(resolver, context, arg) + return try builder(resolver, context, arg) } } @@ -39,7 +39,7 @@ extension SimpleBinding.Builder: BindingMaker { typealias BoundType = Type func makeBinding(for descriptor: AnyTypeDescriptor) -> Binding { - SimpleBinding( + return SimpleBinding( key: BindingKey(descriptor: descriptor, contextType: Context.self, argumentType: Argument.self), maker: self ) diff --git a/Sources/Core/Swinject.swift b/Sources/Core/Swinject.swift index 8cbd47ac..0695f1d6 100644 --- a/Sources/Core/Swinject.swift +++ b/Sources/Core/Swinject.swift @@ -63,6 +63,6 @@ extension Swinject: Resolver { private func instance( from binding: Binding, context: Context, arg: Argument ) throws -> Type { - try binding.instance(arg: arg, context: context, resolver: self) as? Type ?? { throw SwinjectError() }() + return try binding.instance(arg: arg, context: context, resolver: self) as? Type ?? { throw SwinjectError() }() } } diff --git a/Sources/Core/SwinjectTree.swift b/Sources/Core/SwinjectTree.swift index cc67a249..ca2109f1 100644 --- a/Sources/Core/SwinjectTree.swift +++ b/Sources/Core/SwinjectTree.swift @@ -10,24 +10,30 @@ public struct SwinjectTree { let translators: [AnyContextTranslator] } -@_functionBuilder -public enum SwinjectTreeBuilder { +#if swift(>=5.1) + @_functionBuilder + public enum SwinjectTreeBuilder {} +#else + public enum SwinjectTreeBuilder {} +#endif + +extension SwinjectTreeBuilder { public static func buildBlock() {} public static func buildBlock(_ input: SwinjectEntry ...) -> [SwinjectEntry] { - input.flatMap(unpack) + return input.flatMap(unpack) } public static func buildIf(_ input: [SwinjectEntry]?) -> SwinjectEntry { - Composed(parts: input ?? []) + return Composed(parts: input ?? []) } public static func buildEither(first input: [SwinjectEntry]) -> SwinjectEntry { - Composed(parts: input) + return Composed(parts: input) } public static func buildEither(second input: [SwinjectEntry]) -> SwinjectEntry { - Composed(parts: input) + return Composed(parts: input) } // This is not used by compiler implicitly yet diff --git a/Sources/Core/TypeDescriptor.swift b/Sources/Core/TypeDescriptor.swift index f022972b..c8af05fa 100644 --- a/Sources/Core/TypeDescriptor.swift +++ b/Sources/Core/TypeDescriptor.swift @@ -26,7 +26,7 @@ public struct SomeTypeDescriptor: TypeDescriptor, Opaque { } public extension TypeDescriptor { - var opaque: SomeTypeDescriptor { SomeTypeDescriptor(actual: self) } + var opaque: SomeTypeDescriptor { return SomeTypeDescriptor(actual: self) } } struct NoTag: Hashable {} @@ -66,11 +66,11 @@ struct Tagged: TypeDescriptor where Tag: Hashable { } func tagged(_: Type.Type, with tag: Tag) -> Tagged where Tag: Hashable { - Tagged(tag: tag) + return Tagged(tag: tag) } func plain(_: Type.Type) -> Tagged { - Tagged(tag: NoTag()) + return Tagged(tag: NoTag()) } protocol OptionalProtocol { diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index ae4f37b7..dc8f2b93 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -12,6 +12,7 @@ 02556F149C9AAEF5CE353AC1 /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; 03122D1B2EA65C89ADC78EC7 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62682D6ED38742996624B041 /* BasicAssembly.swift */; }; 0509EE8D41BF354EB91ACC80 /* Reference.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73B4B777290FF5D38A8914CC /* Reference.swift */; }; + 05B18A91CA201F7EE53F3ADE /* SwinjectApiSpecSwift5_1.swift in Sources */ = {isa = PBXBuildFile; fileRef = C5FB515A9B4B929026438A90 /* SwinjectApiSpecSwift5_1.swift */; }; 0622539110A7430776A307C7 /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42490D1D0C395951243F5CFF /* Container.swift */; }; 06363AE7650CA288BDF6CB73 /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 34AFFAC41BA9D02A38BDB7A3 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 06F4CAB352B4F623FF7BD885 /* ScopeRegistryKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */; }; @@ -38,8 +39,10 @@ 196338EA802A39E205C33B43 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; 19EBB651BD06BD0C03C1ACB5 /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59111BE319C59E4CD6CF68CD /* Assembler.swift */; }; 1A40A26942A65246D7DD268E /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = ADC44E9312C3B974AFD8F07B /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 1BE678F7FA5DF0E6ED2CF565 /* SwinjectApiSpecSwift5_1.swift in Sources */ = {isa = PBXBuildFile; fileRef = C5FB515A9B4B929026438A90 /* SwinjectApiSpecSwift5_1.swift */; }; 1C82BFD00FCC384DB3AE6A89 /* MatchableBoxes.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 808C1063CA90CC593C7E0E9C /* MatchableBoxes.swifttemplate */; }; 1CA5DF3F93203B226A6FA059 /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EA566CD336DB8343ADFAF9B /* BehaviorFakes.swift */; }; + 1E1CAA4156D94E3A73AEA9F6 /* Opaque.swift in Sources */ = {isa = PBXBuildFile; fileRef = C68B98C653ABDED9C3D17DB3 /* Opaque.swift */; }; 1ED6BD68D92F4FE60978EF22 /* Container+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDA78290D6D60BD0B808571F /* Container+Logging.swift */; }; 1EF3807EB529346903DFA2A1 /* BindingKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = A24B4E8F1CA18603DBB6884A /* BindingKey.swift */; }; 21285CED416F1317E993397A /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59A3946B59EB4D787CCE9F2 /* Container+Registration.swift */; }; @@ -63,6 +66,7 @@ 2DD6F290740EA69B3E73E0EA /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */; }; 3099172980F9E9143C0A1C20 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; 3129A37CDC1653C11800E24A /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EA566CD336DB8343ADFAF9B /* BehaviorFakes.swift */; }; + 31392A9EF619329716144F95 /* Opaque.swift in Sources */ = {isa = PBXBuildFile; fileRef = C68B98C653ABDED9C3D17DB3 /* Opaque.swift */; }; 328DED07602120E3EE252D57 /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 823617F3B8A9192F56B13331 /* Quick.framework */; }; 33391EBA040E82DFB0A37015 /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; 335CE53CEC2360DC86D58F07 /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61EE5DDBE705B47AFC9A6986 /* LoadAwareAssembly.swift */; }; @@ -128,6 +132,7 @@ 63528D45A548DD58D748D54C /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; 640F7A55D9A671FA112C8083 /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; 658AEDC8D802A6788E959E0C /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B580B43E1891812C97209 /* Binding.swift */; }; + 658C98B4AA17C58E8556E0AC /* Opaque.swift in Sources */ = {isa = PBXBuildFile; fileRef = C68B98C653ABDED9C3D17DB3 /* Opaque.swift */; }; 68C95FCB0D345CA3BA24D320 /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; 68D828A3C583DDD28CFE882B /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; 6922AE734E84B515C94D9480 /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; @@ -147,6 +152,7 @@ 725EF35B0CC5E62791D5EA09 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 34AFFAC41BA9D02A38BDB7A3 /* Nimble.framework */; }; 7295E928A18E6055CF796840 /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C074BAC560F277E806146C60 /* SimpleBinding.swift */; }; 732A8933C1310C2A6309E56B /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCAF491EC7DCD7477F9A0ECB /* SwinjectModule.swift */; }; + 7337BA3B0248BE5A4C8C1339 /* SwinjectApiSpecSwift5_1.swift in Sources */ = {isa = PBXBuildFile; fileRef = C5FB515A9B4B929026438A90 /* SwinjectApiSpecSwift5_1.swift */; }; 737740CDFB89189DFF5FD165 /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 74DE57FB3E8228904E6FE0D7 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; 74E1FC692A27C56510363364 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; 75D74C8C25EDACF5A7A75A5C /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; @@ -173,6 +179,7 @@ 890CCD2800597F6FB7C6FD31 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; 89E2997CB8B90368A15A91CE /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; 8B5927517B567B1DFAB5B935 /* ContextTranslator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */; }; + 8BE1DA0A9876AB47BB76E2CD /* Opaque.swift in Sources */ = {isa = PBXBuildFile; fileRef = C68B98C653ABDED9C3D17DB3 /* Opaque.swift */; }; 8CE52672848FD54520215CA1 /* SwinjectSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9527A4CA5BCBA7AFA3596757 /* SwinjectSpec.swift */; }; 8E1E051646BBD6E38F4199C2 /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EA566CD336DB8343ADFAF9B /* BehaviorFakes.swift */; }; 91E435894038C42335086FA8 /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3586A4987B7C7C8122D674E /* SwinjectError.swift */; }; @@ -274,10 +281,6 @@ CBBE28990E0EA82AD8D5E3AF /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; CBE63031F33303F3E503CEF2 /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; CDBBA4023FE01CE4EFEE143A /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCAF491EC7DCD7477F9A0ECB /* SwinjectModule.swift */; }; - CDCF3FDE22EC66AF0025E2BD /* Opaque.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDCF3FDD22EC66AF0025E2BD /* Opaque.swift */; }; - CDCF3FDF22EC66AF0025E2BD /* Opaque.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDCF3FDD22EC66AF0025E2BD /* Opaque.swift */; }; - CDCF3FE022EC66AF0025E2BD /* Opaque.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDCF3FDD22EC66AF0025E2BD /* Opaque.swift */; }; - CDCF3FE122EC66AF0025E2BD /* Opaque.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDCF3FDD22EC66AF0025E2BD /* Opaque.swift */; }; CE5AFED22F04B96713ED76D7 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ADC44E9312C3B974AFD8F07B /* Nimble.framework */; }; CEA4CB2D3113EC693C590B9D /* ScopedBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */; }; CECF5BD14BCDF5248771A06A /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; @@ -313,6 +316,7 @@ E5880DBBB91CC5F8F47FBF73 /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; E7D1045D25FAB592401DCAF0 /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; EA7EB12BDE27575738D26AD4 /* SimpleBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */; }; + EAD78B74CDD8AA95ADC26126 /* SwinjectApiSpecSwift5_1.swift in Sources */ = {isa = PBXBuildFile; fileRef = C5FB515A9B4B929026438A90 /* SwinjectApiSpecSwift5_1.swift */; }; EB3420214A9E68A0247D0F2C /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 351C4221896DDB8572BD6CB5 /* Person.swift */; }; EB79ECF5C893F63B22355167 /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; EBC64A1515C868E410C83451 /* SwiftCode.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 90191C25A2D66E07C4E9CD73 /* SwiftCode.swifttemplate */; }; @@ -455,7 +459,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 01DEC4D20CE554C9DFBD0A8D /* Resolver+Injection.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+Injection.swifttemplate"; sourceTree = ""; }; + 01DEC4D20CE554C9DFBD0A8D /* Resolver+Injection.swifttemplate */ = {isa = PBXFileReference; path = "Resolver+Injection.swifttemplate"; sourceTree = ""; }; 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.swift; sourceTree = ""; }; 09FC792715B1658721F76885 /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 0CA449690AE00F6300DE8ACA /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -463,7 +467,7 @@ 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopedBindingSpec.swift; sourceTree = ""; }; 0E0B580B43E1891812C97209 /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; 10480F2154EAA0414D4C1F55 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .swiftlint.yml; sourceTree = ""; }; + 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */ = {isa = PBXFileReference; path = .swiftlint.yml; sourceTree = ""; }; 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SynchronizedResolverSpec.swift; sourceTree = ""; }; 13513FA012659ADE699A3608 /* LazySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LazySpec.swift; sourceTree = ""; }; 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleBindingSpec.swift; sourceTree = ""; }; @@ -473,7 +477,7 @@ 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Circularity.swift; sourceTree = ""; }; 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Behavior.swift; sourceTree = ""; }; 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Arguments.swift; sourceTree = ""; }; - 26EEC28683E4A26B3092E8BA /* BinderEnvironment.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = BinderEnvironment.swifttemplate; sourceTree = ""; }; + 26EEC28683E4A26B3092E8BA /* BinderEnvironment.swifttemplate */ = {isa = PBXFileReference; path = BinderEnvironment.swifttemplate; sourceTree = ""; }; 273FB7A6277E0841E1570990 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; 2902FD4C1A50263340A51FFB /* ScopeRegistryKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistryKeySpec.swift; sourceTree = ""; }; 2E0C3E4D518BC1FEF3EF8D33 /* BinderVariation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderVariation.swift; sourceTree = ""; }; @@ -488,7 +492,7 @@ 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaggedTypeSpec.swift; sourceTree = ""; }; 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingKeySpec.swift; sourceTree = ""; }; 42490D1D0C395951243F5CFF /* Container.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.swift; sourceTree = ""; }; - 4286F98133270A36F19E5CD0 /* AutoMockable.stencil */ = {isa = PBXFileReference; lastKnownFileType = text; path = AutoMockable.stencil; sourceTree = ""; }; + 4286F98133270A36F19E5CD0 /* AutoMockable.stencil */ = {isa = PBXFileReference; path = AutoMockable.stencil; sourceTree = ""; }; 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmploymentAssembly.swift; sourceTree = ""; }; 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTree.swift; sourceTree = ""; }; 494AA2AA587975747596C157 /* ProviderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProviderSpec.swift; sourceTree = ""; }; @@ -517,13 +521,13 @@ 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ServiceEntry+TypeForwarding.swift"; sourceTree = ""; }; 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextTranslator.swift; sourceTree = ""; }; 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistry.swift; sourceTree = ""; }; - 808C1063CA90CC593C7E0E9C /* MatchableBoxes.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = MatchableBoxes.swifttemplate; sourceTree = ""; }; + 808C1063CA90CC593C7E0E9C /* MatchableBoxes.swifttemplate */ = {isa = PBXFileReference; path = MatchableBoxes.swifttemplate; sourceTree = ""; }; 823617F3B8A9192F56B13331 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; 841D83ADB41363D1E38087B4 /* NonGeneratedMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonGeneratedMocks.swift; sourceTree = ""; }; 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeneratedMocks.swift; sourceTree = ""; }; 8B9785AAE94A5447FA307242 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTreeBuilderSpec.swift; sourceTree = ""; }; - 90191C25A2D66E07C4E9CD73 /* SwiftCode.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = SwiftCode.swifttemplate; sourceTree = ""; }; + 90191C25A2D66E07C4E9CD73 /* SwiftCode.swifttemplate */ = {isa = PBXFileReference; path = SwiftCode.swifttemplate; sourceTree = ""; }; 9527A4CA5BCBA7AFA3596757 /* SwinjectSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectSpec.swift; sourceTree = ""; }; 9620155728133F451B31C0AD /* Swinject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Swinject.swift; sourceTree = ""; }; 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistryKey.swift; sourceTree = ""; }; @@ -540,16 +544,17 @@ B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderEnvironment.swift; sourceTree = ""; }; B92B8E618A08408404FB2A7A /* TypeBinder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinder.swift; sourceTree = ""; }; BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StandardScopeRegistrySpec.swift; sourceTree = ""; }; - BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "ServiceEntry+TypeForwarding.swifttemplate"; sourceTree = ""; }; + BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */ = {isa = PBXFileReference; path = "ServiceEntry+TypeForwarding.swifttemplate"; sourceTree = ""; }; BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Behavior.swift; sourceTree = ""; }; C074BAC560F277E806146C60 /* SimpleBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleBinding.swift; sourceTree = ""; }; C3C516EFA0CA22D19F07B27E /* InjectionVariation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InjectionVariation.swift; sourceTree = ""; }; + C5FB515A9B4B929026438A90 /* SwinjectApiSpecSwift5_1.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectApiSpecSwift5_1.swift; sourceTree = ""; }; + C68B98C653ABDED9C3D17DB3 /* Opaque.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Opaque.swift; sourceTree = ""; }; C765B92B00C0AC8625BB4AC9 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; CADDB3E9E363310028AA5920 /* InstanceMaker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceMaker.swift; sourceTree = ""; }; CC85CB215058F95C0BC190B1 /* Bridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bridge.swift; sourceTree = ""; }; CDA78290D6D60BD0B808571F /* Container+Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Logging.swift"; sourceTree = ""; }; - CDCF3FDD22EC66AF0025E2BD /* Opaque.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Opaque.swift; sourceTree = ""; }; - CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; + CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRequest.swift; sourceTree = ""; }; E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; EDA62EEBC79ED2639C93A76B /* TypeBinderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinderSpec.swift; sourceTree = ""; }; @@ -558,7 +563,7 @@ F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.TypeForwarding.swift; sourceTree = ""; }; FCAF491EC7DCD7477F9A0ECB /* SwinjectModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectModule.swift; sourceTree = ""; }; FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderEnvironmentSpec.swift; sourceTree = ""; }; - FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+LegacyApi.swifttemplate"; sourceTree = ""; }; + FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */ = {isa = PBXFileReference; path = "Resolver+LegacyApi.swifttemplate"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -764,6 +769,7 @@ isa = PBXGroup; children = ( 1B3797A6BB56AE76CEC19F2A /* SwinjectApiSpec.swift */, + C5FB515A9B4B929026438A90 /* SwinjectApiSpecSwift5_1.swift */, ); path = "3.0 API"; sourceTree = ""; @@ -847,6 +853,7 @@ CADDB3E9E363310028AA5920 /* InstanceMaker.swift */, E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */, 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */, + C68B98C653ABDED9C3D17DB3 /* Opaque.swift */, 73B4B777290FF5D38A8914CC /* Reference.swift */, A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */, 5057BAB33984E3E33469452B /* Scope.swift */, @@ -858,7 +865,6 @@ A3586A4987B7C7C8122D674E /* SwinjectError.swift */, 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */, E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */, - CDCF3FDD22EC66AF0025E2BD /* Opaque.swift */, ); path = Core; sourceTree = ""; @@ -1415,6 +1421,7 @@ A91EDAFBC3606EDFBD739899 /* InstanceWrapper.swift in Sources */, 98322F9371E1A8461BC614D1 /* Matchable.swift in Sources */, 3753FB83A1FB4B83891AA5C8 /* ObjectScope.swift in Sources */, + 31392A9EF619329716144F95 /* Opaque.swift in Sources */, 3BD6055555A5C30DABDC8ED2 /* Reference.swift in Sources */, D9084C826F7A798508CD66F5 /* Resolver+Injection.swift in Sources */, D4936DC1A47A8C85325FB52E /* Resolver+LegacyApi.swift in Sources */, @@ -1432,7 +1439,6 @@ CAF3BCDC752C821491AE8714 /* SwinjectModule.swift in Sources */, 0D5C4A278A16AB3A163148AF /* SwinjectTree.swift in Sources */, AB864E029E996492ED4A3A52 /* TypeBinder.swift in Sources */, - CDCF3FDF22EC66AF0025E2BD /* Opaque.swift in Sources */, 49685AB40BEE856C62005C87 /* TypeDescriptor.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1480,6 +1486,7 @@ 838E49C5683FA93A3A917346 /* SimpleBindingSpec.swift in Sources */, 72217E47D83C3CA6D97640B9 /* StandardScopeRegistrySpec.swift in Sources */, 0DC084A3650745492BB81EE9 /* SwinjectApiSpec.swift in Sources */, + 1BE678F7FA5DF0E6ED2CF565 /* SwinjectApiSpecSwift5_1.swift in Sources */, 1183FED17E9521E848F1F991 /* SwinjectSpec.swift in Sources */, 640F7A55D9A671FA112C8083 /* SwinjectTreeBuilderSpec.swift in Sources */, F7CD04FB09FC7F18E9E001CF /* SynchronizedResolverSpec.swift in Sources */, @@ -1523,6 +1530,7 @@ EA7EB12BDE27575738D26AD4 /* SimpleBindingSpec.swift in Sources */, C952D5869D87743297968E9A /* StandardScopeRegistrySpec.swift in Sources */, 273F441B941A6DF76D9BD752 /* SwinjectApiSpec.swift in Sources */, + EAD78B74CDD8AA95ADC26126 /* SwinjectApiSpecSwift5_1.swift in Sources */, 8CE52672848FD54520215CA1 /* SwinjectSpec.swift in Sources */, A308578B99D33C7E33632E85 /* SwinjectTreeBuilderSpec.swift in Sources */, 3BDB44DE92D2377334894804 /* SynchronizedResolverSpec.swift in Sources */, @@ -1566,6 +1574,7 @@ DB03A9B61E162A73506C8552 /* SimpleBindingSpec.swift in Sources */, 0720BEA814AD514378380ACB /* StandardScopeRegistrySpec.swift in Sources */, 3F0DCA7060C62712EA30CBB1 /* SwinjectApiSpec.swift in Sources */, + 05B18A91CA201F7EE53F3ADE /* SwinjectApiSpecSwift5_1.swift in Sources */, 53AC03FA6538E56A976E52FA /* SwinjectSpec.swift in Sources */, 3CEF021295AD9AF9BF26B71E /* SwinjectTreeBuilderSpec.swift in Sources */, 546FF827DB6D42490D1CA439 /* SynchronizedResolverSpec.swift in Sources */, @@ -1609,6 +1618,7 @@ 15246957A062BF0ED7134E0E /* SimpleBindingSpec.swift in Sources */, 0B61DC733616A8ED4ED77FA7 /* StandardScopeRegistrySpec.swift in Sources */, 4EFB0A66BBCAA617470CE622 /* SwinjectApiSpec.swift in Sources */, + 7337BA3B0248BE5A4C8C1339 /* SwinjectApiSpecSwift5_1.swift in Sources */, 45D57E61D4774613F2DF1CCA /* SwinjectSpec.swift in Sources */, 233F3E25FF0B51A3E6611F58 /* SwinjectTreeBuilderSpec.swift in Sources */, 890CCD2800597F6FB7C6FD31 /* SynchronizedResolverSpec.swift in Sources */, @@ -1640,6 +1650,7 @@ 57BFBA2077E70DC1C2FE796C /* InstanceWrapper.swift in Sources */, 293985649250DF270DC89135 /* Matchable.swift in Sources */, B4B66D7251BDDE25D6D7FB3C /* ObjectScope.swift in Sources */, + 1E1CAA4156D94E3A73AEA9F6 /* Opaque.swift in Sources */, B293894FEB67831DDA5F000E /* Reference.swift in Sources */, 848227742D4ABA298D340485 /* Resolver+Injection.swift in Sources */, E177D354B1F410129D921C69 /* Resolver+LegacyApi.swift in Sources */, @@ -1657,7 +1668,6 @@ CDBBA4023FE01CE4EFEE143A /* SwinjectModule.swift in Sources */, 0CE1126436F680F9684837E4 /* SwinjectTree.swift in Sources */, 4B9811CF0604946CCF323ED2 /* TypeBinder.swift in Sources */, - CDCF3FE022EC66AF0025E2BD /* Opaque.swift in Sources */, 9CEE20BD42795D5E5F39BF20 /* TypeDescriptor.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1683,6 +1693,7 @@ 389C54E04DD794DA4F648571 /* InstanceWrapper.swift in Sources */, 87FEAEF562B99522083CB87D /* Matchable.swift in Sources */, 6DA49F84E2592B32F81F268B /* ObjectScope.swift in Sources */, + 8BE1DA0A9876AB47BB76E2CD /* Opaque.swift in Sources */, 2D020C6391A4F6A2118585B8 /* Reference.swift in Sources */, C6D60E2AEC381998223145B2 /* Resolver+Injection.swift in Sources */, FD7B2663F2F931B78EB330EE /* Resolver+LegacyApi.swift in Sources */, @@ -1700,7 +1711,6 @@ D54DFEDF33F09035F3177248 /* SwinjectModule.swift in Sources */, 372F0061E762BF8FFF05457F /* SwinjectTree.swift in Sources */, 9425887520AC2DBDCBACB252 /* TypeBinder.swift in Sources */, - CDCF3FE122EC66AF0025E2BD /* Opaque.swift in Sources */, AC470B4322599B0A076DD3FF /* TypeDescriptor.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1726,6 +1736,7 @@ 98ACB1A09194572A946CA90D /* InstanceWrapper.swift in Sources */, 5ED8A7D19F21FA686215F72C /* Matchable.swift in Sources */, B42331BF00B482369B908BB8 /* ObjectScope.swift in Sources */, + 658C98B4AA17C58E8556E0AC /* Opaque.swift in Sources */, 0509EE8D41BF354EB91ACC80 /* Reference.swift in Sources */, CBE63031F33303F3E503CEF2 /* Resolver+Injection.swift in Sources */, 41C7340BFD2EB66359772733 /* Resolver+LegacyApi.swift in Sources */, @@ -1743,7 +1754,6 @@ 732A8933C1310C2A6309E56B /* SwinjectModule.swift in Sources */, 6922AE734E84B515C94D9480 /* SwinjectTree.swift in Sources */, EF79F0B3D497215D4BBBC038 /* TypeBinder.swift in Sources */, - CDCF3FDE22EC66AF0025E2BD /* Opaque.swift in Sources */, E3EABE098DBFB561A20632E3 /* TypeDescriptor.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1865,11 +1875,7 @@ "$(PROJECT_DIR)/Carthage/Build/iOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -1907,10 +1913,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; PRODUCT_NAME = Swinject; SDKROOT = macosx; SKIP_INSTALL = YES; @@ -1927,11 +1930,7 @@ "$(PROJECT_DIR)/Carthage/Build/tvOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = appletvos; TARGETED_DEVICE_FAMILY = 3; @@ -1949,10 +1948,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = Swinject; SDKROOT = appletvos; SKIP_INSTALL = YES; @@ -1970,11 +1966,7 @@ "$(PROJECT_DIR)/Carthage/Build/iOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -1991,11 +1983,7 @@ "$(PROJECT_DIR)/Carthage/Build/Mac", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - "@loader_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = macosx; }; @@ -2085,10 +2073,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = Swinject; SDKROOT = appletvos; SKIP_INSTALL = YES; @@ -2106,11 +2091,7 @@ "$(PROJECT_DIR)/Carthage/Build/watchOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = watchos; SKIP_INSTALL = YES; @@ -2129,10 +2110,7 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; SDKROOT = macosx; SKIP_INSTALL = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -2150,10 +2128,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = Swinject; SDKROOT = iphoneos; SKIP_INSTALL = YES; @@ -2171,11 +2146,7 @@ "$(PROJECT_DIR)/Carthage/Build/watchOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = watchos; SKIP_INSTALL = YES; @@ -2193,11 +2164,7 @@ "$(PROJECT_DIR)/Carthage/Build/Mac", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - "@loader_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = macosx; }; @@ -2212,11 +2179,7 @@ "$(PROJECT_DIR)/Carthage/Build/tvOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = appletvos; TARGETED_DEVICE_FAMILY = 3; @@ -2234,10 +2197,7 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; SDKROOT = macosx; SKIP_INSTALL = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -2256,10 +2216,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; PRODUCT_NAME = Swinject; SDKROOT = macosx; SKIP_INSTALL = YES; @@ -2278,10 +2235,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = Swinject; SDKROOT = iphoneos; SKIP_INSTALL = YES; diff --git a/Templates/BinderVariation.swift b/Templates/BinderVariation.swift index ea9caeff..a64ab4fe 100644 --- a/Templates/BinderVariation.swift +++ b/Templates/BinderVariation.swift @@ -13,19 +13,19 @@ struct BinderVariation { extension BinderVariation { var argTypes: String { - join((1 ..< args + 1).map { "Arg\($0)" }) + return join((1 ..< args + 1).map { "Arg\($0)" }) } var argTypesOrNil: String? { - argTypes.isEmpty ? nil : argTypes + return argTypes.isEmpty ? nil : argTypes } var genericTypes: String { - join("Type", argTypesOrNil) + return join("Type", argTypesOrNil) } var builderInputTypes: String { - join( + return join( hasResolver ? "Resolver" : nil, hasContext ? "Context" : nil, argTypesOrNil @@ -33,22 +33,22 @@ extension BinderVariation { } var params: String { - join( + return join( isScoped ? "ref: @escaping ReferenceMaker = strongRef" : nil, "_ builder: @escaping (\(builderInputTypes)) throws -> Type" ) } var scopeType: String { - isContexted ? "AScope" : "UnboundScope" + return isContexted ? "AScope" : "UnboundScope" } var scopeVar: String { - isContexted ? "scope" : ".root" + return isContexted ? "scope" : ".root" } var contextType: String { - isContexted ? "Context" : "Any" + return isContexted ? "Context" : "Any" } var argReturnType: String { @@ -72,11 +72,11 @@ extension BinderVariation { } var hashableArgTypes: String { - join((1 ..< args + 1).map { "Arg\($0): Hashable" }) + return join((1 ..< args + 1).map { "Arg\($0): Hashable" }) } var constraints: String { - isMatchable && args > 0 ? "where \(hashableArgTypes) " : "" + return isMatchable && args > 0 ? "where \(hashableArgTypes) " : "" } var functionName: String { @@ -89,7 +89,7 @@ extension BinderVariation { } var initVars: String { - isScoped ? "(\(join(scopeVar, "ref")))" : "" + return isScoped ? "(\(join(scopeVar, "ref")))" : "" } var argVarsOrNil: String? { @@ -101,7 +101,7 @@ extension BinderVariation { } var builderInputs: String { - join( + return join( hasResolver ? "r" : "_", hasContext ? "c" : "_", args > 0 ? "a" : "_" @@ -109,7 +109,7 @@ extension BinderVariation { } var builderVars: String { - join( + return join( hasResolver ? "r" : nil, hasContext ? "c" : nil, argVarsOrNil @@ -148,7 +148,7 @@ extension BinderVariation { let prefix = indent ? " " : "" return """ \(prefix)public func \(functionName)<\(genericTypes)>(\(params)) -> \(returnType) \(constraints){ - \(prefix) \(actualReturnType)\(initVars) { \(builderInputs) in try builder(\(builderVars)) }.opaque + \(prefix) return \(actualReturnType)\(initVars) { \(builderInputs) in try builder(\(builderVars)) }.opaque \(prefix)} """ } diff --git a/Templates/InjectionVariation.swift b/Templates/InjectionVariation.swift index 77c3e505..51eda4d0 100644 --- a/Templates/InjectionVariation.swift +++ b/Templates/InjectionVariation.swift @@ -14,7 +14,7 @@ extension InjectionVariation { var args: Int { return paramArgs + factoryArgs } var genericTypes: String { - join( + return join( "Type", isTagged ? "Tag" : nil, args > 0 ? join((1 ... args).map { "Arg\($0)" }) : nil @@ -22,7 +22,7 @@ extension InjectionVariation { } var params: String { - join( + return join( "of _: Type.Type = Type.self", isTagged ? "tagged tag: Tag" : nil, paramArgs >= 1 ? "arg " + join(separator: ", _ ", (1 ... paramArgs).map { "arg\($0): Arg\($0)" }) : nil @@ -30,18 +30,18 @@ extension InjectionVariation { } var factoryInputs: String { - join((1 ..< factoryArgs + 1).map { "Arg\($0 + paramArgs)" }) + return join((1 ..< factoryArgs + 1).map { "Arg\($0 + paramArgs)" }) } var constraints: String { - join( + return join( isTagged ? "Tag: Hashable" : nil, isMatchable && args > 0 ? join((1 ... args).map { "Arg\($0): Hashable" }) : nil ) } var whereClause: String? { - constraints.isEmpty ? nil : "where " + constraints + return constraints.isEmpty ? nil : "where " + constraints } var requestParams: String { @@ -68,14 +68,14 @@ extension InjectionVariation { } var returnDescription: String { - join(separator: " ", returnType, whereClause) + return join(separator: " ", returnType, whereClause) } var returnStatement: String { if isDelayed { return "return { try self.resolve(request(\(requestParams))) }" } else { - return "try resolve(request(\(requestParams)))" + return "return try resolve(request(\(requestParams)))" } } } @@ -103,7 +103,7 @@ extension InjectionVariation { extension InjectionVariation { func render() -> String { - """ + return """ func \(functionName)<\(genericTypes)>(\(params)) \(returnDescription) { \(returnStatement) } diff --git a/Templates/MatchableBoxes.swifttemplate b/Templates/MatchableBoxes.swifttemplate index 1a49df25..9156a5cf 100644 --- a/Templates/MatchableBoxes.swifttemplate +++ b/Templates/MatchableBoxes.swifttemplate @@ -18,11 +18,11 @@ struct <%= type_name %>: Hashable, Matchable where <%= arg_hashables %> { let tuple_params = (1...i).map { "arg\($0)" }.joined(separator: ", ") -%> func box<<%= arg_types %>>(<%= arg_params %>) -> <%= i == 1 ? arg_types : "(\(arg_types))" %> { - <%= i == 1 ? tuple_params : "(\(tuple_params))" %> + return <%= i == 1 ? tuple_params : "(\(tuple_params))" %> } func box<<%= arg_types %>>(<%= arg_params %>) -> MatchableBox<%= i %><<%= arg_types %>> where <%= arg_hashables %> { - MatchableBox<%= i %>(<%= arg_call_params %>) + return MatchableBox<%= i %>(<%= arg_call_params %>) } <%_ } -%> diff --git a/Templates/SwiftCode.swifttemplate b/Templates/SwiftCode.swifttemplate index c9f6512f..cce2f55f 100644 --- a/Templates/SwiftCode.swifttemplate +++ b/Templates/SwiftCode.swifttemplate @@ -14,19 +14,19 @@ struct BinderVariation { extension BinderVariation { var argTypes: String { - join((1 ..< args + 1).map { "Arg\($0)" }) + return join((1 ..< args + 1).map { "Arg\($0)" }) } var argTypesOrNil: String? { - argTypes.isEmpty ? nil : argTypes + return argTypes.isEmpty ? nil : argTypes } var genericTypes: String { - join("Type", argTypesOrNil) + return join("Type", argTypesOrNil) } var builderInputTypes: String { - join( + return join( hasResolver ? "Resolver" : nil, hasContext ? "Context" : nil, argTypesOrNil @@ -34,22 +34,22 @@ extension BinderVariation { } var params: String { - join( + return join( isScoped ? "ref: @escaping ReferenceMaker = strongRef" : nil, "_ builder: @escaping (\(builderInputTypes)) throws -> Type" ) } var scopeType: String { - isContexted ? "AScope" : "UnboundScope" + return isContexted ? "AScope" : "UnboundScope" } var scopeVar: String { - isContexted ? "scope" : ".root" + return isContexted ? "scope" : ".root" } var contextType: String { - isContexted ? "Context" : "Any" + return isContexted ? "Context" : "Any" } var argReturnType: String { @@ -73,11 +73,11 @@ extension BinderVariation { } var hashableArgTypes: String { - join((1 ..< args + 1).map { "Arg\($0): Hashable" }) + return join((1 ..< args + 1).map { "Arg\($0): Hashable" }) } var constraints: String { - isMatchable && args > 0 ? "where \(hashableArgTypes) " : "" + return isMatchable && args > 0 ? "where \(hashableArgTypes) " : "" } var functionName: String { @@ -90,7 +90,7 @@ extension BinderVariation { } var initVars: String { - isScoped ? "(\(join(scopeVar, "ref")))" : "" + return isScoped ? "(\(join(scopeVar, "ref")))" : "" } var argVarsOrNil: String? { @@ -102,7 +102,7 @@ extension BinderVariation { } var builderInputs: String { - join( + return join( hasResolver ? "r" : "_", hasContext ? "c" : "_", args > 0 ? "a" : "_" @@ -110,7 +110,7 @@ extension BinderVariation { } var builderVars: String { - join( + return join( hasResolver ? "r" : nil, hasContext ? "c" : nil, argVarsOrNil @@ -149,7 +149,7 @@ extension BinderVariation { let prefix = indent ? " " : "" return """ \(prefix)public func \(functionName)<\(genericTypes)>(\(params)) -> \(returnType) \(constraints){ - \(prefix) \(actualReturnType)\(initVars) { \(builderInputs) in try builder(\(builderVars)) }.opaque + \(prefix) return \(actualReturnType)\(initVars) { \(builderInputs) in try builder(\(builderVars)) }.opaque \(prefix)} """ } @@ -170,7 +170,7 @@ extension InjectionVariation { var args: Int { return paramArgs + factoryArgs } var genericTypes: String { - join( + return join( "Type", isTagged ? "Tag" : nil, args > 0 ? join((1 ... args).map { "Arg\($0)" }) : nil @@ -178,7 +178,7 @@ extension InjectionVariation { } var params: String { - join( + return join( "of _: Type.Type = Type.self", isTagged ? "tagged tag: Tag" : nil, paramArgs >= 1 ? "arg " + join(separator: ", _ ", (1 ... paramArgs).map { "arg\($0): Arg\($0)" }) : nil @@ -186,18 +186,18 @@ extension InjectionVariation { } var factoryInputs: String { - join((1 ..< factoryArgs + 1).map { "Arg\($0 + paramArgs)" }) + return join((1 ..< factoryArgs + 1).map { "Arg\($0 + paramArgs)" }) } var constraints: String { - join( + return join( isTagged ? "Tag: Hashable" : nil, isMatchable && args > 0 ? join((1 ... args).map { "Arg\($0): Hashable" }) : nil ) } var whereClause: String? { - constraints.isEmpty ? nil : "where " + constraints + return constraints.isEmpty ? nil : "where " + constraints } var requestParams: String { @@ -224,14 +224,14 @@ extension InjectionVariation { } var returnDescription: String { - join(separator: " ", returnType, whereClause) + return join(separator: " ", returnType, whereClause) } var returnStatement: String { if isDelayed { return "return { try self.resolve(request(\(requestParams))) }" } else { - return "try resolve(request(\(requestParams)))" + return "return try resolve(request(\(requestParams)))" } } } @@ -259,7 +259,7 @@ extension InjectionVariation { extension InjectionVariation { func render() -> String { - """ + return """ func \(functionName)<\(genericTypes)>(\(params)) \(returnDescription) { \(returnStatement) } @@ -271,10 +271,10 @@ extension InjectionVariation { // func join(separator: String = ", ", _ strings: String? ...) -> String { - join(separator: separator, strings) + return join(separator: separator, strings) } func join(separator: String = ", ", _ strings: [String?]) -> String { - strings.compactMap { $0 }.joined(separator: separator) + return strings.compactMap { $0 }.joined(separator: separator) } %> diff --git a/Templates/Utils.swift b/Templates/Utils.swift index bacb4570..a0508a9e 100644 --- a/Templates/Utils.swift +++ b/Templates/Utils.swift @@ -3,9 +3,9 @@ // func join(separator: String = ", ", _ strings: String? ...) -> String { - join(separator: separator, strings) + return join(separator: separator, strings) } func join(separator: String = ", ", _ strings: [String?]) -> String { - strings.compactMap { $0 }.joined(separator: separator) + return strings.compactMap { $0 }.joined(separator: separator) } diff --git a/Tests/3.0 API/SwinjectApiSpec.swift b/Tests/3.0 API/SwinjectApiSpec.swift index 6a53a52e..4b3c3dcb 100644 --- a/Tests/3.0 API/SwinjectApiSpec.swift +++ b/Tests/3.0 API/SwinjectApiSpec.swift @@ -14,96 +14,97 @@ class SwinjectApiSpec: QuickSpec { override func spec() { human = Human() } it("returns instance if is bound") { - let swinject = Swinject { + let swinject = Swinject( bbind(Int.self).with(42) - } + ) expect { try swinject.instance(of: Int.self) } == 42 } it("can infer the requested type") { - let swinject = Swinject { + let swinject = Swinject( bbind(Int.self) & 42 - } + ) expect { try swinject.instance() as Int } == 42 } it("throws if providing type with missing dependency") { - let swinject = Swinject { + let swinject = Swinject( bbind(Pet.self) & provider { Pet(owner: try $0.instance()) } - } + ) expect { try swinject.instance(of: Pet.self) }.to(throwError()) } it("returns instance if all dependencies are bound") { - let swinject = Swinject { - bbind(Pet.self) & provider { Pet(owner: try $0.instance()) } + let swinject = Swinject( + bbind(Pet.self) & provider { Pet(owner: try $0.instance()) }, bbind(Human.self) & instance(human) - } + ) expect { try swinject.instance(of: Pet.self).owner } === human } it("throws if has multiple bindings for the same request") { - let swinject = Swinject { - bbind(Int.self) & 42 + let swinject = Swinject( + bbind(Int.self) & 42, bbind(Int.self) & provider { 17 + 25 } - } + ) expect { try swinject.instance(of: Int.self) }.to(throwError()) } it("throws if requesting instance with wrong tag") { - let swinject = Swinject { + let swinject = Swinject( bbind(Int.self, tagged: "Tag") & 42 - } + ) expect { try swinject.instance(of: Int.self) }.to(throwError()) expect { try swinject.instance(of: Int.self, tagged: 42) }.to(throwError()) expect { try swinject.instance(of: Int.self, tagged: "OtherTag") }.to(throwError()) } it("returns instance with correct tag") { - let swinject = Swinject { - bbind(String.self) & "Plain" + let swinject = Swinject( + bbind(String.self) & "Plain", bbind(String.self, tagged: "Tag") & "Tagged" - } + ) expect { try swinject.instance(of: String.self) } == "Plain" expect { try swinject.instance(of: String.self, tagged: "Tag") } == "Tagged" } - it("can bind protocol to implementation") { - let swinject = Swinject { - bbind(Mammal.self).with(provider { Human() }) - } - expect(try? swinject.instance(of: Mammal.self) is Human) == true - } + // FIXME: +// it("can bind protocol to implementation") { +// let swinject = Swinject( +// bbind(Mammal.self).with(provider { Human() }) +// ) +// expect(try? swinject.instance(of: Mammal.self) is Human) == true +// } it("can inject optionals") { - let swinject = Swinject { + let swinject = Swinject( bbind(Int.self) & 42 - } + ) expect { try swinject.instance() as Int? } == 42 } it("can inject instance provider") { - let swinject = Swinject { + let swinject = Swinject( bbind(Int.self, tagged: "tag") & 42 - } + ) let provider = swinject.provider(of: Int.self, tagged: "tag") expect { try provider() } == 42 } it("can inject instance factory") { // FIXME: compiler segfaults if declaring this factory inside function builder let intFactory = factory { (r, arg: Int) in Int(try r.instance() as Double) + 5 * arg } - let swinject = Swinject { - bbind(Double.self) & 17.0 + let swinject = Swinject( + bbind(Double.self) & 17.0, bbind(Int.self) & intFactory - } + ) let factory = swinject.factory() as (Int) throws -> Int expect { try factory(5) } == 42 } it("can inject factory binding as provider or instance") { - let swinject = Swinject { - bbind(Double.self) & 17.0 + let swinject = Swinject( + bbind(Double.self) & 17.0, bbind(Int.self) & factory { Int(try $0.instance() as Double) + 5 * $1 } - } + ) expect { try swinject.provider(of: Int.self, arg: 5)() } == 42 expect { try swinject.instance(of: Int.self, arg: 5) } == 42 } it("can curry factory's arguments") { - let swinject = Swinject { + let swinject = Swinject( bbind(Int.self) & factory { (_, a1: Int, a2: Double, a3: String) in a1 + Int(a2) + Int(a3)! } - } + ) expect { try swinject.factory(of: Int.self)(11, 14.0, "17") } == 42 expect { try swinject.factory(of: Int.self, arg: 11)(14.0, "17") } == 42 expect { try swinject.factory(of: Int.self, arg: 11, 14.0)("17") } == 42 @@ -112,19 +113,19 @@ class SwinjectApiSpec: QuickSpec { override func spec() { // FIXME: compiler segfaults if declaring these providers inside function builder let intProvider = contexted(String.self).provider { _, string in Int(string)! } let doubleProvider = contexted(String.self).provider { _, string in Double(string)! } - let swinject = Swinject { - bbind(Int.self) & intProvider + let swinject = Swinject( + bbind(Int.self) & intProvider, bbind(Double.self) & doubleProvider - } + ) let contexted = swinject.on("42") expect { try contexted.instance(of: Int.self) } == 42 expect { try contexted.instance(of: Double.self) } == 42 expect { try swinject.instance(of: Int.self) }.to(throwError()) } it("can use binding without context in any context") { - let swinject = Swinject { + let swinject = Swinject( bbind(Int.self) & 42 - } + ) expect { try swinject.on("context").instance() as Int } == 42 expect { try swinject.on(Human()).instance() as Int } == 42 } @@ -132,37 +133,37 @@ class SwinjectApiSpec: QuickSpec { override func spec() { // FIXME: compiler segfaults if declaring these providers inside function builder let intProvider = contexted(String.self).provider { _, string in Int(string)! } let doubleProvider = contexted(Int.self).provider { _, int in Double(int) } - let swinject = Swinject { - bbind(Int.self) & intProvider - bbind(Double.self) & doubleProvider + let swinject = Swinject( + bbind(Int.self) & intProvider, + bbind(Double.self) & doubleProvider, registerContextTranslator(from: String.self) { Int($0)! } - } + ) let contexted = swinject.on("42") expect { try contexted.instance(of: Int.self) } == 42 expect { try contexted.instance(of: Double.self) } == 42 } it("can bind singleton") { - let swinject = Swinject { + let swinject = Swinject( bbind(Human.self) & singleton { Human() } - } + ) let first = try? swinject.instance() as Human let second = try? swinject.instance() as Human expect(first) === second } it("can bind scoped singleton") { let scope = UnboundScope() - let swinject = Swinject { + let swinject = Swinject( bbind(Human.self) & scoped(scope).singleton { Human() } - } + ) let first = try? swinject.instance() as Human let second = try? swinject.instance() as Human expect(first) === second } it("can close scopes") { let scope = UnboundScope() - let swinject = Swinject { + let swinject = Swinject( bbind(Human.self) & scoped(scope).singleton { Human() } - } + ) let first = try? swinject.instance() as Human scope.close() let second = try? swinject.instance() as Human @@ -170,24 +171,24 @@ class SwinjectApiSpec: QuickSpec { override func spec() { } it("notifies instances when scope is closed") { let scope = UnboundScope() - let swinject = Swinject { + let swinject = Swinject( bbind(ClosableMock.self) & scoped(scope).singleton { ClosableMock() } - } + ) let closable = try? swinject.instance() as ClosableMock scope.close() expect(closable?.closeCalled) == true } it("can bind weakly referenced singleton") { - let swinject = Swinject { + let swinject = Swinject( bbind(Human.self) & singleton(ref: weakRef) { Human() } - } + ) weak var first = try? swinject.instance() as Human expect(first).to(beNil()) } it("can bind multitons") { - let swinject = Swinject { + let swinject = Swinject( bbind(Building.self) & multiton { Building(floors: $1) } - } + ) let house1 = try? swinject.instance(arg: 1) as Building let house2 = try? swinject.instance(arg: 1) as Building let skyscrapper = try? swinject.instance(arg: 100) as Building diff --git a/Tests/3.0 API/SwinjectApiSpecSwift5_1.swift b/Tests/3.0 API/SwinjectApiSpecSwift5_1.swift new file mode 100644 index 00000000..a2ce32da --- /dev/null +++ b/Tests/3.0 API/SwinjectApiSpecSwift5_1.swift @@ -0,0 +1,198 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +import Nimble +import Quick +import Swinject +@testable import class Swinject.UnboundScope + +class SwinjectApiSpecSwift5_1: QuickSpec { override func spec() { #if swift(>=5.1) + var human = Human() + beforeEach { + UnboundScope.root.close() + human = Human() + } + it("returns instance if is bound") { + let swinject = Swinject { + bbind(Int.self).with(42) + } + expect { try swinject.instance(of: Int.self) } == 42 + } + it("can infer the requested type") { + let swinject = Swinject { + bbind(Int.self) & 42 + } + expect { try swinject.instance() as Int } == 42 + } + it("throws if providing type with missing dependency") { + let swinject = Swinject { + bbind(Pet.self) & provider { Pet(owner: try $0.instance()) } + } + expect { try swinject.instance(of: Pet.self) }.to(throwError()) + } + it("returns instance if all dependencies are bound") { + let swinject = Swinject { + bbind(Pet.self) & provider { Pet(owner: try $0.instance()) } + bbind(Human.self) & instance(human) + } + expect { try swinject.instance(of: Pet.self).owner } === human + } + it("throws if has multiple bindings for the same request") { + let swinject = Swinject { + bbind(Int.self) & 42 + bbind(Int.self) & provider { 17 + 25 } + } + expect { try swinject.instance(of: Int.self) }.to(throwError()) + } + it("throws if requesting instance with wrong tag") { + let swinject = Swinject { + bbind(Int.self, tagged: "Tag") & 42 + } + expect { try swinject.instance(of: Int.self) }.to(throwError()) + expect { try swinject.instance(of: Int.self, tagged: 42) }.to(throwError()) + expect { try swinject.instance(of: Int.self, tagged: "OtherTag") }.to(throwError()) + } + it("returns instance with correct tag") { + let swinject = Swinject { + bbind(String.self) & "Plain" + bbind(String.self, tagged: "Tag") & "Tagged" + } + expect { try swinject.instance(of: String.self) } == "Plain" + expect { try swinject.instance(of: String.self, tagged: "Tag") } == "Tagged" + } + it("can bind protocol to implementation") { + let swinject = Swinject { + bbind(Mammal.self).with(provider { Human() }) + } + expect(try? swinject.instance(of: Mammal.self) is Human) == true + } + it("can inject optionals") { + let swinject = Swinject { + bbind(Int.self) & 42 + } + expect { try swinject.instance() as Int? } == 42 + } + it("can inject instance provider") { + let swinject = Swinject { + bbind(Int.self, tagged: "tag") & 42 + } + let provider = swinject.provider(of: Int.self, tagged: "tag") + expect { try provider() } == 42 + } + it("can inject instance factory") { + // FIXME: compiler segfaults if declaring this factory inside function builder + let intFactory = factory { (r, arg: Int) in Int(try r.instance() as Double) + 5 * arg } + let swinject = Swinject { + bbind(Double.self) & 17.0 + bbind(Int.self) & intFactory + } + let factory = swinject.factory() as (Int) throws -> Int + expect { try factory(5) } == 42 + } + it("can inject factory binding as provider or instance") { + let swinject = Swinject { + bbind(Double.self) & 17.0 + bbind(Int.self) & factory { Int(try $0.instance() as Double) + 5 * $1 } + } + expect { try swinject.provider(of: Int.self, arg: 5)() } == 42 + expect { try swinject.instance(of: Int.self, arg: 5) } == 42 + } + it("can curry factory's arguments") { + let swinject = Swinject { + bbind(Int.self) & factory { (_, a1: Int, a2: Double, a3: String) in + a1 + Int(a2) + Int(a3)! + } + } + expect { try swinject.factory(of: Int.self)(11, 14.0, "17") } == 42 + expect { try swinject.factory(of: Int.self, arg: 11)(14.0, "17") } == 42 + expect { try swinject.factory(of: Int.self, arg: 11, 14.0)("17") } == 42 + } + it("can pass context to the bindings") { + // FIXME: compiler segfaults if declaring these providers inside function builder + let intProvider = contexted(String.self).provider { _, string in Int(string)! } + let doubleProvider = contexted(String.self).provider { _, string in Double(string)! } + let swinject = Swinject { + bbind(Int.self) & intProvider + bbind(Double.self) & doubleProvider + } + let contexted = swinject.on("42") + expect { try contexted.instance(of: Int.self) } == 42 + expect { try contexted.instance(of: Double.self) } == 42 + expect { try swinject.instance(of: Int.self) }.to(throwError()) + } + it("can use binding without context in any context") { + let swinject = Swinject { + bbind(Int.self) & 42 + } + expect { try swinject.on("context").instance() as Int } == 42 + expect { try swinject.on(Human()).instance() as Int } == 42 + } + it("can translate contexts") { + // FIXME: compiler segfaults if declaring these providers inside function builder + let intProvider = contexted(String.self).provider { _, string in Int(string)! } + let doubleProvider = contexted(Int.self).provider { _, int in Double(int) } + let swinject = Swinject { + bbind(Int.self) & intProvider + bbind(Double.self) & doubleProvider + registerContextTranslator(from: String.self) { Int($0)! } + } + let contexted = swinject.on("42") + expect { try contexted.instance(of: Int.self) } == 42 + expect { try contexted.instance(of: Double.self) } == 42 + } + it("can bind singleton") { + let swinject = Swinject { + bbind(Human.self) & singleton { Human() } + } + let first = try? swinject.instance() as Human + let second = try? swinject.instance() as Human + expect(first) === second + } + it("can bind scoped singleton") { + let scope = UnboundScope() + let swinject = Swinject { + bbind(Human.self) & scoped(scope).singleton { Human() } + } + let first = try? swinject.instance() as Human + let second = try? swinject.instance() as Human + expect(first) === second + } + it("can close scopes") { + let scope = UnboundScope() + let swinject = Swinject { + bbind(Human.self) & scoped(scope).singleton { Human() } + } + let first = try? swinject.instance() as Human + scope.close() + let second = try? swinject.instance() as Human + expect(first) !== second + } + it("notifies instances when scope is closed") { + let scope = UnboundScope() + let swinject = Swinject { + bbind(ClosableMock.self) & scoped(scope).singleton { ClosableMock() } + } + let closable = try? swinject.instance() as ClosableMock + scope.close() + expect(closable?.closeCalled) == true + } + it("can bind weakly referenced singleton") { + let swinject = Swinject { + bbind(Human.self) & singleton(ref: weakRef) { Human() } + } + weak var first = try? swinject.instance() as Human + expect(first).to(beNil()) + } + it("can bind multitons") { + let swinject = Swinject { + bbind(Building.self) & multiton { Building(floors: $1) } + } + let house1 = try? swinject.instance(arg: 1) as Building + let house2 = try? swinject.instance(arg: 1) as Building + let skyscrapper = try? swinject.instance(arg: 100) as Building + expect(house1) === house2 + expect(skyscrapper) !== house1 + } + #endif +} } diff --git a/Tests/Support/Bridge.swift b/Tests/Support/Bridge.swift index 4ee0c85a..421e7013 100644 --- a/Tests/Support/Bridge.swift +++ b/Tests/Support/Bridge.swift @@ -9,13 +9,13 @@ import protocol Swinject.TypeDescriptor // Original Swinject functions conflict with QuickSpec's instance methods func bbind(_: Type.Type) -> TypeBinder> { - bind(Type.self) + return bind(Type.self) } func bbind(_: Type.Type, tagged tag: Tag) -> TypeBinder> where Tag: Hashable { - bind(Type.self, tagged: tag) + return bind(Type.self, tagged: tag) } func bbind(descriptor: Descriptor) -> TypeBinder where Descriptor: TypeDescriptor { - bind(descriptor: descriptor) + return bind(descriptor: descriptor) } diff --git a/Tests/Support/Convenience.swift b/Tests/Support/Convenience.swift index c3da95e0..87ec40f7 100644 --- a/Tests/Support/Convenience.swift +++ b/Tests/Support/Convenience.swift @@ -2,6 +2,7 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // +import Foundation import Nimble @testable import Swinject diff --git a/Tests/Support/NonGeneratedMocks.swift b/Tests/Support/NonGeneratedMocks.swift index 6901f52b..0451fce3 100644 --- a/Tests/Support/NonGeneratedMocks.swift +++ b/Tests/Support/NonGeneratedMocks.swift @@ -35,7 +35,7 @@ extension AnyResolverMock: Resolver { func resolve( _ request: InstanceRequest ) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { - try resolve(request as Any) as! Descriptor.BaseType + return try resolve(request as Any) as! Descriptor.BaseType } } @@ -63,7 +63,7 @@ extension StaticScopeRegistryMock: ScopeRegistry { builder _: () throws -> Reference, finalizer: (Any) throws -> Void ) rethrows -> Any { - instance(key: key) + return instance(key: key) } } @@ -73,7 +73,7 @@ struct BuilderScopeRegistry: ScopeRegistry { builder: () throws -> Reference, finalizer: (Any) throws -> Void ) rethrows -> Any { - try builder().currentValue + return try builder().currentValue } func clear() {} @@ -82,6 +82,6 @@ struct BuilderScopeRegistry: ScopeRegistry { extension BindingMock { // swiftlint:disable large_tuple var instanceReceivedArguments: (arg: Any, context: Any, resolver: Resolver)? { - instanceArgContextResolverReceivedArguments + return instanceArgContextResolverReceivedArguments } } diff --git a/Tests/Unit Specs/BinderEnvironmentSpec.swift b/Tests/Unit Specs/BinderEnvironmentSpec.swift index 35a3053d..0a42132e 100644 --- a/Tests/Unit Specs/BinderEnvironmentSpec.swift +++ b/Tests/Unit Specs/BinderEnvironmentSpec.swift @@ -435,21 +435,21 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { } } private extension SomeBindingMaker { - var actual: AnyInstanceMaker { anyActual as! AnyInstanceMaker } + var actual: AnyInstanceMaker { return anyActual as! AnyInstanceMaker } func makeInstance(resolver: Resolver) throws -> BoundType { - try actual.makeInstance(arg: (), context: (), resolver: resolver) as! BoundType + return try actual.makeInstance(arg: (), context: (), resolver: resolver) as! BoundType } func makeInstance(context: Any, resolver: Resolver) throws -> BoundType { - try actual.makeInstance(arg: (), context: context, resolver: resolver) as! BoundType + return try actual.makeInstance(arg: (), context: context, resolver: resolver) as! BoundType } func makeInstance(arg: Any, resolver: Resolver) throws -> BoundType { - try actual.makeInstance(arg: arg, context: (), resolver: resolver) as! BoundType + return try actual.makeInstance(arg: arg, context: (), resolver: resolver) as! BoundType } func makeInstance(arg: Any, context: Any, resolver: Resolver) throws -> BoundType { - try actual.makeInstance(arg: arg, context: context, resolver: resolver) as! BoundType + return try actual.makeInstance(arg: arg, context: context, resolver: resolver) as! BoundType } } diff --git a/Tests/Unit Specs/BindingKeySpec.swift b/Tests/Unit Specs/BindingKeySpec.swift index 14f286e0..1496e56d 100644 --- a/Tests/Unit Specs/BindingKeySpec.swift +++ b/Tests/Unit Specs/BindingKeySpec.swift @@ -66,5 +66,5 @@ private func makeKey( contextType: Any.Type = Void.self, argumentType: Any.Type = Void.self ) -> BindingKey { - BindingKey(descriptor: descriptor, contextType: contextType, argumentType: argumentType) + return BindingKey(descriptor: descriptor, contextType: contextType, argumentType: argumentType) } diff --git a/Tests/Unit Specs/StandardScopeRegistrySpec.swift b/Tests/Unit Specs/StandardScopeRegistrySpec.swift index b3fdca53..4e989c23 100644 --- a/Tests/Unit Specs/StandardScopeRegistrySpec.swift +++ b/Tests/Unit Specs/StandardScopeRegistrySpec.swift @@ -2,6 +2,7 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // +import Foundation import Nimble import Quick @testable import Swinject diff --git a/Tests/Unit Specs/SwinjectSpec.swift b/Tests/Unit Specs/SwinjectSpec.swift index 4173f49e..fb8f39e8 100644 --- a/Tests/Unit Specs/SwinjectSpec.swift +++ b/Tests/Unit Specs/SwinjectSpec.swift @@ -12,12 +12,12 @@ class SwinjectSpec: QuickSpec { override func spec() { beforeEach { binding = BindingMock() binding.instanceArgContextResolverReturnValue = 0 - swinject = Swinject { binding } + swinject = Swinject(binding) } describe("instance injection") { context("no bindings") { it("throws") { - let swinject = Swinject {} + let swinject = Swinject() expect { try swinject.instance(of: Int.self) }.to(throwError()) } } @@ -90,11 +90,11 @@ class SwinjectSpec: QuickSpec { override func spec() { $0.matchesReturnValue = false $0.instanceArgContextResolverReturnValue = 0 } - swinject = Swinject { - bindings[0] - bindings[1] + swinject = Swinject( + bindings[0], + bindings[1], bindings[2] - } + ) } it("throws if multiple bindings match requested type") { bindings.forEach { $0.matchesReturnValue = true } @@ -166,10 +166,10 @@ class SwinjectSpec: QuickSpec { override func spec() { let binding = BindingMock() binding.matchesClosure = { $0.descriptor.matches(plain(Double.self)) } binding.instanceArgContextResolverReturnValue = 0.0 - let swinject = Swinject { - bbind(Int.self) & provider { Int(try $0.instance() as Double) } + let swinject = Swinject( + bbind(Int.self) & provider { Int(try $0.instance() as Double) }, binding - } + ) _ = try? swinject.on("context").instance(of: Int.self) expect(binding.instanceReceivedArguments?.context as? String) == "context" } @@ -282,10 +282,10 @@ class SwinjectSpec: QuickSpec { override func spec() { $0.matchesReturnValue = false $0.instanceArgContextResolverReturnValue = 0 } - swinject = Swinject { - bindings[0]; bindings[1]; bindings[2] - translators[0]; translators[1]; translators[2] - } + swinject = Swinject( + bindings[0], bindings[1], bindings[2], + translators[0], translators[1], translators[2] + ) } it("does not throw if one of context translators has correct context translation") { bindings[0].matchesClosure = { $0.contextType == Int.self } diff --git a/Tests/Unit Specs/SwinjectTreeBuilderSpec.swift b/Tests/Unit Specs/SwinjectTreeBuilderSpec.swift index d10fd9ea..3af93a58 100644 --- a/Tests/Unit Specs/SwinjectTreeBuilderSpec.swift +++ b/Tests/Unit Specs/SwinjectTreeBuilderSpec.swift @@ -6,7 +6,7 @@ import Nimble import Quick @testable import Swinject -class SwinjectTreeBuilderSpec: QuickSpec { override func spec() { +class SwinjectTreeBuilderSpec: QuickSpec { override func spec() { #if swift(>=5.1) describe("allowed syntax") { it("builds empty closure") { let tree = makeTree {} @@ -61,17 +61,20 @@ class SwinjectTreeBuilderSpec: QuickSpec { override func spec() { expect(tree.translators.count) == 3 } } + #endif } } -// TODO: Return SwinjectTree directly from builder once full support for @functionBuilder is available -func makeTree(@SwinjectTreeBuilder builder: () -> [SwinjectEntry]) -> SwinjectTree { - SwinjectTreeBuilder.buildFunction(builder()) -} +#if swift(>=5.1) + // TODO: Return SwinjectTree directly from builder once full support for @functionBuilder is available + func makeTree(@SwinjectTreeBuilder builder: () -> [SwinjectEntry]) -> SwinjectTree { + SwinjectTreeBuilder.buildFunction(builder()) + } -func makeTree(@SwinjectTreeBuilder builder: () -> SwinjectEntry) -> SwinjectTree { - SwinjectTreeBuilder.buildFunction([builder()]) -} + func makeTree(@SwinjectTreeBuilder builder: () -> SwinjectEntry) -> SwinjectTree { + SwinjectTreeBuilder.buildFunction([builder()]) + } -func makeTree(@SwinjectTreeBuilder _: () -> Void) -> SwinjectTree { - SwinjectTreeBuilder.buildFunction([]) -} + func makeTree(@SwinjectTreeBuilder _: () -> Void) -> SwinjectTree { + SwinjectTreeBuilder.buildFunction([]) + } +#endif From a059cf96305fdf56ba8a2b726ad78bc3a466f8ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sat, 27 Jul 2019 19:32:12 +0200 Subject: [PATCH 151/239] Fix tests on linux SPM --- .Package.Test.swift | 3 +- LinuxMain.swift | 10 ++ Swinject.xcodeproj/project.pbxproj | 116 ++++++++++++++---- ...ontainerSpec.CustomStringConvertible.swift | 6 +- Tests/2.0 API/LazySpec.swift | 6 +- Tests/2.0 API/ProviderSpec.swift | 6 +- Tests/LinuxConfig.swift | 35 ++++++ Tests/LinuxMain.swift | 20 --- 8 files changed, 146 insertions(+), 56 deletions(-) create mode 100755 LinuxMain.swift create mode 100644 Tests/LinuxConfig.swift delete mode 100755 Tests/LinuxMain.swift diff --git a/.Package.Test.swift b/.Package.Test.swift index ac1baac7..b9c6cdd2 100644 --- a/.Package.Test.swift +++ b/.Package.Test.swift @@ -27,8 +27,7 @@ let package = Package( "Nimble", "Swinject", ], - path: "Tests", - exclude: ["LinuxMain.swift"] + path: "Tests" ), ] ) diff --git a/LinuxMain.swift b/LinuxMain.swift new file mode 100755 index 00000000..595c3a91 --- /dev/null +++ b/LinuxMain.swift @@ -0,0 +1,10 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +import Quick +import XCTest + +@testable import SwinjectTests + +Quick.QCKMain(SwinjectTests.allSpecs) diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index dc8f2b93..fcd666d2 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -280,6 +280,10 @@ CB9E8D16D7A0620A1F7A32A3 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; CBBE28990E0EA82AD8D5E3AF /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; CBE63031F33303F3E503CEF2 /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; + CD92116422ECC05600211BF0 /* LinuxConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD92116322ECC05600211BF0 /* LinuxConfig.swift */; }; + CD92116522ECC05600211BF0 /* LinuxConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD92116322ECC05600211BF0 /* LinuxConfig.swift */; }; + CD92116622ECC05600211BF0 /* LinuxConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD92116322ECC05600211BF0 /* LinuxConfig.swift */; }; + CD92116722ECC05600211BF0 /* LinuxConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD92116322ECC05600211BF0 /* LinuxConfig.swift */; }; CDBBA4023FE01CE4EFEE143A /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCAF491EC7DCD7477F9A0ECB /* SwinjectModule.swift */; }; CE5AFED22F04B96713ED76D7 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ADC44E9312C3B974AFD8F07B /* Nimble.framework */; }; CEA4CB2D3113EC693C590B9D /* ScopedBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */; }; @@ -459,7 +463,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 01DEC4D20CE554C9DFBD0A8D /* Resolver+Injection.swifttemplate */ = {isa = PBXFileReference; path = "Resolver+Injection.swifttemplate"; sourceTree = ""; }; + 01DEC4D20CE554C9DFBD0A8D /* Resolver+Injection.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+Injection.swifttemplate"; sourceTree = ""; }; 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.swift; sourceTree = ""; }; 09FC792715B1658721F76885 /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 0CA449690AE00F6300DE8ACA /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -467,7 +471,7 @@ 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopedBindingSpec.swift; sourceTree = ""; }; 0E0B580B43E1891812C97209 /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; 10480F2154EAA0414D4C1F55 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */ = {isa = PBXFileReference; path = .swiftlint.yml; sourceTree = ""; }; + 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .swiftlint.yml; sourceTree = ""; }; 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SynchronizedResolverSpec.swift; sourceTree = ""; }; 13513FA012659ADE699A3608 /* LazySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LazySpec.swift; sourceTree = ""; }; 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleBindingSpec.swift; sourceTree = ""; }; @@ -477,7 +481,7 @@ 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Circularity.swift; sourceTree = ""; }; 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Behavior.swift; sourceTree = ""; }; 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Arguments.swift; sourceTree = ""; }; - 26EEC28683E4A26B3092E8BA /* BinderEnvironment.swifttemplate */ = {isa = PBXFileReference; path = BinderEnvironment.swifttemplate; sourceTree = ""; }; + 26EEC28683E4A26B3092E8BA /* BinderEnvironment.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = BinderEnvironment.swifttemplate; sourceTree = ""; }; 273FB7A6277E0841E1570990 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; 2902FD4C1A50263340A51FFB /* ScopeRegistryKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistryKeySpec.swift; sourceTree = ""; }; 2E0C3E4D518BC1FEF3EF8D33 /* BinderVariation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderVariation.swift; sourceTree = ""; }; @@ -492,7 +496,7 @@ 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaggedTypeSpec.swift; sourceTree = ""; }; 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingKeySpec.swift; sourceTree = ""; }; 42490D1D0C395951243F5CFF /* Container.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.swift; sourceTree = ""; }; - 4286F98133270A36F19E5CD0 /* AutoMockable.stencil */ = {isa = PBXFileReference; path = AutoMockable.stencil; sourceTree = ""; }; + 4286F98133270A36F19E5CD0 /* AutoMockable.stencil */ = {isa = PBXFileReference; lastKnownFileType = text; path = AutoMockable.stencil; sourceTree = ""; }; 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmploymentAssembly.swift; sourceTree = ""; }; 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTree.swift; sourceTree = ""; }; 494AA2AA587975747596C157 /* ProviderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProviderSpec.swift; sourceTree = ""; }; @@ -521,13 +525,13 @@ 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ServiceEntry+TypeForwarding.swift"; sourceTree = ""; }; 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextTranslator.swift; sourceTree = ""; }; 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistry.swift; sourceTree = ""; }; - 808C1063CA90CC593C7E0E9C /* MatchableBoxes.swifttemplate */ = {isa = PBXFileReference; path = MatchableBoxes.swifttemplate; sourceTree = ""; }; + 808C1063CA90CC593C7E0E9C /* MatchableBoxes.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = MatchableBoxes.swifttemplate; sourceTree = ""; }; 823617F3B8A9192F56B13331 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; 841D83ADB41363D1E38087B4 /* NonGeneratedMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonGeneratedMocks.swift; sourceTree = ""; }; 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeneratedMocks.swift; sourceTree = ""; }; 8B9785AAE94A5447FA307242 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTreeBuilderSpec.swift; sourceTree = ""; }; - 90191C25A2D66E07C4E9CD73 /* SwiftCode.swifttemplate */ = {isa = PBXFileReference; path = SwiftCode.swifttemplate; sourceTree = ""; }; + 90191C25A2D66E07C4E9CD73 /* SwiftCode.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = SwiftCode.swifttemplate; sourceTree = ""; }; 9527A4CA5BCBA7AFA3596757 /* SwinjectSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectSpec.swift; sourceTree = ""; }; 9620155728133F451B31C0AD /* Swinject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Swinject.swift; sourceTree = ""; }; 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistryKey.swift; sourceTree = ""; }; @@ -544,7 +548,7 @@ B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderEnvironment.swift; sourceTree = ""; }; B92B8E618A08408404FB2A7A /* TypeBinder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinder.swift; sourceTree = ""; }; BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StandardScopeRegistrySpec.swift; sourceTree = ""; }; - BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */ = {isa = PBXFileReference; path = "ServiceEntry+TypeForwarding.swifttemplate"; sourceTree = ""; }; + BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "ServiceEntry+TypeForwarding.swifttemplate"; sourceTree = ""; }; BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Behavior.swift; sourceTree = ""; }; C074BAC560F277E806146C60 /* SimpleBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleBinding.swift; sourceTree = ""; }; C3C516EFA0CA22D19F07B27E /* InjectionVariation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InjectionVariation.swift; sourceTree = ""; }; @@ -553,8 +557,9 @@ C765B92B00C0AC8625BB4AC9 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; CADDB3E9E363310028AA5920 /* InstanceMaker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceMaker.swift; sourceTree = ""; }; CC85CB215058F95C0BC190B1 /* Bridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bridge.swift; sourceTree = ""; }; + CD92116322ECC05600211BF0 /* LinuxConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinuxConfig.swift; sourceTree = ""; }; CDA78290D6D60BD0B808571F /* Container+Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Logging.swift"; sourceTree = ""; }; - CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; + CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRequest.swift; sourceTree = ""; }; E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; EDA62EEBC79ED2639C93A76B /* TypeBinderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinderSpec.swift; sourceTree = ""; }; @@ -563,7 +568,7 @@ F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.TypeForwarding.swift; sourceTree = ""; }; FCAF491EC7DCD7477F9A0ECB /* SwinjectModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectModule.swift; sourceTree = ""; }; FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderEnvironmentSpec.swift; sourceTree = ""; }; - FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */ = {isa = PBXFileReference; path = "Resolver+LegacyApi.swifttemplate"; sourceTree = ""; }; + FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+LegacyApi.swifttemplate"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -797,6 +802,7 @@ 9A6E5EB655CFE64BBCF5DED1 /* 3.0 API */, 4F46C48FA15F512EAED5F67A /* Support */, 0A05322134E988A4593B5122 /* Unit Specs */, + CD92116322ECC05600211BF0 /* LinuxConfig.swift */, ); path = Tests; sourceTree = ""; @@ -1493,6 +1499,7 @@ 9AD60A86D5A0DF4513C1EA8D /* TaggedTypeSpec.swift in Sources */, 778D9AB6470D4280254AC140 /* TestModels.swift in Sources */, A6CAAC13E97BAE1168B7933F /* TypeBinderSpec.swift in Sources */, + CD92116422ECC05600211BF0 /* LinuxConfig.swift in Sources */, 922CDD2FF5974D1756D5A126 /* UnboundScopeSpec.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1536,6 +1543,7 @@ 3BDB44DE92D2377334894804 /* SynchronizedResolverSpec.swift in Sources */, A5302886A31C90F38512B88E /* TaggedTypeSpec.swift in Sources */, 2615FC1C92B7E381116B9E57 /* TestModels.swift in Sources */, + CD92116522ECC05600211BF0 /* LinuxConfig.swift in Sources */, F050175A7FB08DE1F97DC11C /* TypeBinderSpec.swift in Sources */, 9C4FEA520C7CB1ACBAC1B57B /* UnboundScopeSpec.swift in Sources */, ); @@ -1581,6 +1589,7 @@ 09470890A74A5DDE7114891B /* TaggedTypeSpec.swift in Sources */, CB9E8D16D7A0620A1F7A32A3 /* TestModels.swift in Sources */, 57FCCFC6C6747DAB2F141A52 /* TypeBinderSpec.swift in Sources */, + CD92116722ECC05600211BF0 /* LinuxConfig.swift in Sources */, F2857EAA276179402A5E6205 /* UnboundScopeSpec.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1625,6 +1634,7 @@ 24114725AE1A834C6E3118F7 /* TaggedTypeSpec.swift in Sources */, 6034CF5459D96497AF36E4B6 /* TestModels.swift in Sources */, 36F20E1EEAD43361A98713E0 /* TypeBinderSpec.swift in Sources */, + CD92116622ECC05600211BF0 /* LinuxConfig.swift in Sources */, C3212F88E16B0592070C4F35 /* UnboundScopeSpec.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1875,7 +1885,11 @@ "$(PROJECT_DIR)/Carthage/Build/iOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -1913,7 +1927,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = macosx; SKIP_INSTALL = YES; @@ -1930,7 +1947,11 @@ "$(PROJECT_DIR)/Carthage/Build/tvOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = appletvos; TARGETED_DEVICE_FAMILY = 3; @@ -1948,7 +1969,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = appletvos; SKIP_INSTALL = YES; @@ -1966,7 +1990,11 @@ "$(PROJECT_DIR)/Carthage/Build/iOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -1983,7 +2011,11 @@ "$(PROJECT_DIR)/Carthage/Build/Mac", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = macosx; }; @@ -2073,7 +2105,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = appletvos; SKIP_INSTALL = YES; @@ -2091,7 +2126,11 @@ "$(PROJECT_DIR)/Carthage/Build/watchOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = watchos; SKIP_INSTALL = YES; @@ -2110,7 +2149,10 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); SDKROOT = macosx; SKIP_INSTALL = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -2128,7 +2170,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = iphoneos; SKIP_INSTALL = YES; @@ -2146,7 +2191,11 @@ "$(PROJECT_DIR)/Carthage/Build/watchOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = watchos; SKIP_INSTALL = YES; @@ -2164,7 +2213,11 @@ "$(PROJECT_DIR)/Carthage/Build/Mac", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = macosx; }; @@ -2179,7 +2232,11 @@ "$(PROJECT_DIR)/Carthage/Build/tvOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = appletvos; TARGETED_DEVICE_FAMILY = 3; @@ -2197,7 +2254,10 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); SDKROOT = macosx; SKIP_INSTALL = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -2216,7 +2276,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = macosx; SKIP_INSTALL = YES; @@ -2235,7 +2298,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = iphoneos; SKIP_INSTALL = YES; diff --git a/Tests/2.0 API/ContainerSpec.CustomStringConvertible.swift b/Tests/2.0 API/ContainerSpec.CustomStringConvertible.swift index 12d9653d..0d1afc56 100644 --- a/Tests/2.0 API/ContainerSpec.CustomStringConvertible.swift +++ b/Tests/2.0 API/ContainerSpec.CustomStringConvertible.swift @@ -6,8 +6,8 @@ import Nimble import Quick @testable import Swinject -// TODO: Implement debug description -// class ContainerSpec_CustomStringConvertible: QuickSpec { +class ContainerSpec_CustomStringConvertible: QuickSpec { + // TODO: Implement debug description // override func spec() { // var container: Container! // beforeEach { @@ -71,4 +71,4 @@ import Quick // + "]" // } // } -// } +} diff --git a/Tests/2.0 API/LazySpec.swift b/Tests/2.0 API/LazySpec.swift index 5f4c96ee..8b0d5791 100644 --- a/Tests/2.0 API/LazySpec.swift +++ b/Tests/2.0 API/LazySpec.swift @@ -6,8 +6,8 @@ import Nimble import Quick import Swinject -// TODO: Enable Lazy injection -// class LazySpec: QuickSpec { +class LazySpec: QuickSpec { + // TODO: Enable Lazy injection // override func spec() { // var container: Container! // beforeEach { @@ -106,4 +106,4 @@ import Swinject // } // } // } -// } +} diff --git a/Tests/2.0 API/ProviderSpec.swift b/Tests/2.0 API/ProviderSpec.swift index c3fb58ee..289b40cb 100644 --- a/Tests/2.0 API/ProviderSpec.swift +++ b/Tests/2.0 API/ProviderSpec.swift @@ -6,8 +6,8 @@ import Nimble import Quick import Swinject -// TODO: Enable Provider injection -// class ProviderSpec: QuickSpec { +class ProviderSpec: QuickSpec { + // TODO: Enable Provider injection // override func spec() { // var container: Container! // beforeEach { @@ -111,4 +111,4 @@ import Swinject // } // } // } -// } +} diff --git a/Tests/LinuxConfig.swift b/Tests/LinuxConfig.swift new file mode 100644 index 00000000..d8026e0e --- /dev/null +++ b/Tests/LinuxConfig.swift @@ -0,0 +1,35 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +import Quick + +let allSpecs: [QuickSpec.Type] = [ + // 2.0 Api + AssemblerSpec.self, + ContainerSpec_Arguments.self, + ContainerSpec_Circularity.self, + ContainerSpec_Behavior.self, + ContainerSpec_CustomStringConvertible.self, + ContainerSpec.self, + ContainerSpec_TypeForwarding.self, + LazySpec.self, + ProviderSpec.self, + SynchronizedResolverSpec.self, + // 3.0 Api + SwinjectApiSpec.self, + SwinjectApiSpecSwift5_1.self, + // Unit Specs + BinderEnvironmentSpec.self, + BindingKeySpec.self, + ReferenceMakerSpec.self, + ScopedBindingSpec.self, + ScopeRegistryKeySpec.self, + SimpleBindingSpec.self, + StandardScopeRegistrySpec.self, + SwinjectSpec.self, + SwinjectTreeBuilderSpec.self, + TaggedTypeSpec.self, + TypeBinderSpec.self, + UnboundScopeSpec.self, +] diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift deleted file mode 100755 index f88dee88..00000000 --- a/Tests/LinuxMain.swift +++ /dev/null @@ -1,20 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -import Quick -import XCTest - -@testable import SwinjectTests - -Quick.QCKMain([ - AssemblerSpec.self, - ContainerSpec.self, - ContainerSpec_Arguments.self, - ContainerSpec_Circularity.self, - ContainerSpec_DebugHelper.self, - ContainerSpec_CustomScope.self, - SynchronizedResolverSpec.self, - ServiceKeySpec.self, - ServiceEntrySpec.self, -]) From 931a59de375ffb8b67e2386c2bef93d948a1f7ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sat, 27 Jul 2019 20:19:19 +0200 Subject: [PATCH 152/239] Cleanup api spec --- Tests/3.0 API/SwinjectApiSpec.swift | 33 ++++++++++++----------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/Tests/3.0 API/SwinjectApiSpec.swift b/Tests/3.0 API/SwinjectApiSpec.swift index 4b3c3dcb..b8214206 100644 --- a/Tests/3.0 API/SwinjectApiSpec.swift +++ b/Tests/3.0 API/SwinjectApiSpec.swift @@ -61,13 +61,12 @@ class SwinjectApiSpec: QuickSpec { override func spec() { expect { try swinject.instance(of: String.self) } == "Plain" expect { try swinject.instance(of: String.self, tagged: "Tag") } == "Tagged" } - // FIXME: -// it("can bind protocol to implementation") { -// let swinject = Swinject( -// bbind(Mammal.self).with(provider { Human() }) -// ) -// expect(try? swinject.instance(of: Mammal.self) is Human) == true -// } + it("can bind protocol to implementation") { + let swinject = Swinject( + bbind(Mammal.self).with(provider { Human() }) + ) + expect(try? swinject.instance(of: Mammal.self) is Human) == true + } it("can inject optionals") { let swinject = Swinject( bbind(Int.self) & 42 @@ -82,11 +81,11 @@ class SwinjectApiSpec: QuickSpec { override func spec() { expect { try provider() } == 42 } it("can inject instance factory") { - // FIXME: compiler segfaults if declaring this factory inside function builder - let intFactory = factory { (r, arg: Int) in Int(try r.instance() as Double) + 5 * arg } let swinject = Swinject( bbind(Double.self) & 17.0, - bbind(Int.self) & intFactory + bbind(Int.self) & factory { (r, arg: Int) in + Int(try r.instance() as Double) + 5 * arg + } ) let factory = swinject.factory() as (Int) throws -> Int expect { try factory(5) } == 42 @@ -110,12 +109,9 @@ class SwinjectApiSpec: QuickSpec { override func spec() { expect { try swinject.factory(of: Int.self, arg: 11, 14.0)("17") } == 42 } it("can pass context to the bindings") { - // FIXME: compiler segfaults if declaring these providers inside function builder - let intProvider = contexted(String.self).provider { _, string in Int(string)! } - let doubleProvider = contexted(String.self).provider { _, string in Double(string)! } let swinject = Swinject( - bbind(Int.self) & intProvider, - bbind(Double.self) & doubleProvider + bbind(Int.self) & contexted(String.self).provider { _, string in Int(string)! }, + bbind(Double.self) & contexted(String.self).provider { _, string in Double(string)! } ) let contexted = swinject.on("42") expect { try contexted.instance(of: Int.self) } == 42 @@ -130,12 +126,9 @@ class SwinjectApiSpec: QuickSpec { override func spec() { expect { try swinject.on(Human()).instance() as Int } == 42 } it("can translate contexts") { - // FIXME: compiler segfaults if declaring these providers inside function builder - let intProvider = contexted(String.self).provider { _, string in Int(string)! } - let doubleProvider = contexted(Int.self).provider { _, int in Double(int) } let swinject = Swinject( - bbind(Int.self) & intProvider, - bbind(Double.self) & doubleProvider, + bbind(Int.self) & contexted(String.self).provider { _, string in Int(string)! }, + bbind(Double.self) & contexted(Int.self).provider { _, int in Double(int) }, registerContextTranslator(from: String.self) { Int($0)! } ) let contexted = swinject.on("42") From f1c2f947d99714df43a2257ca119d5a20b98ea77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sat, 27 Jul 2019 21:03:31 +0200 Subject: [PATCH 153/239] Implement debug description --- Sources/2.0 API/Container.swift | 6 +- Sources/2.0 API/ObjectScope.swift | 20 ++- Sources/2.0 API/ServiceEntry.swift | 29 ++++ ...ontainerSpec.CustomStringConvertible.swift | 127 +++++++++--------- 4 files changed, 110 insertions(+), 72 deletions(-) diff --git a/Sources/2.0 API/Container.swift b/Sources/2.0 API/Container.swift index d173a47f..19793012 100644 --- a/Sources/2.0 API/Container.swift +++ b/Sources/2.0 API/Container.swift @@ -27,7 +27,7 @@ public final class Container { let parent: Container? // TODO: Enable arbitrary scope as default let defaultObjectScope: ObjectScope - var bindings = [Binding]() + var bindings = [Binding & CustomStringConvertible]() var behaviors = [Behavior]() var swinject: Swinject { return Swinject(tree: SwinjectTree( bindings: allBindings, @@ -111,7 +111,9 @@ public final class Container { extension Container: CustomStringConvertible { public var description: String { - return "" + return "[" + + bindings.map { "\n { \($0.description) }" }.sorted().joined(separator: ",") + + "\n]" } } diff --git a/Sources/2.0 API/ObjectScope.swift b/Sources/2.0 API/ObjectScope.swift index 49f18a76..b8f5b188 100644 --- a/Sources/2.0 API/ObjectScope.swift +++ b/Sources/2.0 API/ObjectScope.swift @@ -4,7 +4,7 @@ /// A configuration how an instance provided by a `Container` is shared in the system. /// The configuration is ignored if it is applied to a value type. -public enum ObjectScope { +public enum ObjectScope: String, CaseIterable { /// A new instance is always created by the `Container` when a type is resolved. /// The instance is not shared. case transient @@ -26,8 +26,8 @@ extension ObjectScope { var scope: AnyScope? { switch self { case .graph: return GraphScope.shared - case .container: return ContainerScope.shared - case .weak: return ContainerScope.shared + case .container: return ContainerScope.container + case .weak: return ContainerScope.weak case .transient: return nil } } @@ -57,16 +57,24 @@ final class Graph { } } -final class GraphScope: Scope { +final class GraphScope: Scope, CustomStringConvertible { static let shared = GraphScope() + let description = "graph" func registry(for graph: Graph) -> ScopeRegistry { return graph.registry } } -final class ContainerScope: Scope { - static let shared = ContainerScope() +final class ContainerScope: Scope, CustomStringConvertible { + static let container = ContainerScope("container") + static let weak = ContainerScope("weak") + + let description: String + + init(_ description: String) { + self.description = description + } func registry(for container: Container) -> ScopeRegistry { return container.registry diff --git a/Sources/2.0 API/ServiceEntry.swift b/Sources/2.0 API/ServiceEntry.swift index d09e4cd2..f031179c 100644 --- a/Sources/2.0 API/ServiceEntry.swift +++ b/Sources/2.0 API/ServiceEntry.swift @@ -102,3 +102,32 @@ extension ServiceEntry: Binding { ) } } + +extension ServiceEntry: CustomStringConvertible { + public var description: String { + return [ + "Service: \(Service.self)", + name.map { "Name: \"\($0)\"" }, + "Factory: (\(factoryInputs)) -> Animal", + "ObjectScope: \(scopeDescription)", + finalizers.isEmpty ? nil : "InitCompleted: Specified \(finalizers.count) closures", + ].compactMap { $0 }.joined(separator: ", ") + } + + private var factoryInputs: String { + return ["Resolver", argumentTypes].compactMap { $0 }.joined(separator: ", ") + } + + private var argumentTypes: String? { + var result = "\(argumentType)" + if result.hasPrefix("("), result.hasSuffix(")") { + result = String(result.dropFirst().dropLast()) + } + return result.isEmpty ? nil : result + } + + private var scopeDescription: String { + guard let scope = scope else { return "transient" } + return String(describing: scope) + } +} diff --git a/Tests/2.0 API/ContainerSpec.CustomStringConvertible.swift b/Tests/2.0 API/ContainerSpec.CustomStringConvertible.swift index 0d1afc56..895b4878 100644 --- a/Tests/2.0 API/ContainerSpec.CustomStringConvertible.swift +++ b/Tests/2.0 API/ContainerSpec.CustomStringConvertible.swift @@ -7,68 +7,67 @@ import Quick @testable import Swinject class ContainerSpec_CustomStringConvertible: QuickSpec { - // TODO: Implement debug description -// override func spec() { -// var container: Container! -// beforeEach { -// container = Container() -// } -// -// it("describes empty description without service registrations.") { -// expect(container.description) == "[\n]" -// } -// it("describes a registration.") { -// container.register(Animal.self) { _ in Cat() } -// -// expect(container.description) == -// "[\n" -// + " { Service: Animal, Factory: Resolver -> Animal, ObjectScope: graph }\n" -// + "]" -// } -// it("describes a registration with name.") { -// container.register(Animal.self, name: "My Cat") { _ in Cat() } -// -// expect(container.description) == -// "[\n" -// + " { Service: Animal, Name: \"My Cat\", Factory: Resolver -> Animal, ObjectScope: graph }\n" -// + "]" -// } -// it("describes a registration with arguments.") { -// container.register(Animal.self) { _, arg1, arg2 in Cat(name: arg1, sleeping: arg2) } -// -// expect(container.description) == -// "[\n" -// + " { Service: Animal, Factory: (Resolver, String, Bool) -> Animal, ObjectScope: graph }\n" -// + "]" -// } -// it("describes a registration with a specified object scope.") { -// container.register(Animal.self) { _ in Cat() } -// .inObjectScope(.container) -// -// expect(container.description) == -// "[\n" -// + " { Service: Animal, Factory: Resolver -> Animal, ObjectScope: container }\n" -// + "]" -// } -// it("describes a registration with initCompleted.") { -// container.register(Animal.self) { _ in Cat() } -// .initCompleted { _, _ in } -// -// expect(container.description) == -// "[\n" -// + " { Service: Animal, Factory: Resolver -> Animal, ObjectScope: graph, " -// + "InitCompleted: Specified 1 closures }\n" -// + "]" -// } -// it("describes multiple registrations.") { -// container.register(Animal.self, name: "1") { _ in Cat() } -// container.register(Animal.self, name: "2") { _ in Cat() } -// -// expect(container.description) == -// "[\n" -// + " { Service: Animal, Name: \"1\", Factory: Resolver -> Animal, ObjectScope: graph },\n" -// + " { Service: Animal, Name: \"2\", Factory: Resolver -> Animal, ObjectScope: graph }\n" -// + "]" -// } -// } + override func spec() { + var container: Container! + beforeEach { + container = Container() + } + + it("describes empty description without service registrations.") { + expect(container.description) == "[\n]" + } + it("describes a registration.") { + container.register(Animal.self) { _ in Cat() } + + expect(container.description) == + "[\n" + + " { Service: Animal, Factory: (Resolver) -> Animal, ObjectScope: graph }\n" + + "]" + } + it("describes a registration with name.") { + container.register(Animal.self, name: "My Cat") { _ in Cat() } + + expect(container.description) == + "[\n" + + " { Service: Animal, Name: \"My Cat\", Factory: (Resolver) -> Animal, ObjectScope: graph }\n" + + "]" + } + it("describes a registration with arguments.") { + container.register(Animal.self) { _, arg1, arg2 in Cat(name: arg1, sleeping: arg2) } + + expect(container.description) == + "[\n" + + " { Service: Animal, Factory: (Resolver, String, Bool) -> Animal, ObjectScope: graph }\n" + + "]" + } + it("describes a registration with a specified object scope.") { + container.register(Animal.self) { _ in Cat() } + .inObjectScope(.container) + + expect(container.description) == + "[\n" + + " { Service: Animal, Factory: (Resolver) -> Animal, ObjectScope: container }\n" + + "]" + } + it("describes a registration with initCompleted.") { + container.register(Animal.self) { _ in Cat() } + .initCompleted { _, _ in } + + expect(container.description) == + "[\n" + + " { Service: Animal, Factory: (Resolver) -> Animal, ObjectScope: graph, " + + "InitCompleted: Specified 1 closures }\n" + + "]" + } + it("describes multiple registrations.") { + container.register(Animal.self, name: "1") { _ in Cat() } + container.register(Animal.self, name: "2") { _ in Cat() } + + expect(container.description) == + "[\n" + + " { Service: Animal, Name: \"1\", Factory: (Resolver) -> Animal, ObjectScope: graph },\n" + + " { Service: Animal, Name: \"2\", Factory: (Resolver) -> Animal, ObjectScope: graph }\n" + + "]" + } + } } From 71769b286bea8fcff47f6d9b0b4e0d37bc286051 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sat, 27 Jul 2019 23:18:01 +0200 Subject: [PATCH 154/239] Describe modules API --- Sources/2.0 API/Container.swift | 2 +- Sources/3.0 API/Swinject+Builder.swift | 21 ++ Sources/3.0 API/SwinjectModule.swift | 8 - Sources/Core/Swinject.swift | 7 +- Sources/Core/SwinjectModule.swift | 14 ++ Sources/Core/SwinjectTree.swift | 30 ++- Swinject.xcodeproj/project.pbxproj | 32 +-- Tests/3.0 API/SwinjectApiSpec.swift | 174 ++++++++++----- Tests/3.0 API/SwinjectApiSpecSwift5_1.swift | 198 ------------------ Tests/LinuxConfig.swift | 1 - Tests/Support/GeneratedMocks.swift | 3 - .../Unit Specs/SwinjectTreeBuilderSpec.swift | 6 +- 12 files changed, 192 insertions(+), 304 deletions(-) delete mode 100644 Sources/3.0 API/SwinjectModule.swift create mode 100644 Sources/Core/SwinjectModule.swift delete mode 100644 Tests/3.0 API/SwinjectApiSpecSwift5_1.swift diff --git a/Sources/2.0 API/Container.swift b/Sources/2.0 API/Container.swift index 19793012..19376902 100644 --- a/Sources/2.0 API/Container.swift +++ b/Sources/2.0 API/Container.swift @@ -31,7 +31,7 @@ public final class Container { var behaviors = [Behavior]() var swinject: Swinject { return Swinject(tree: SwinjectTree( bindings: allBindings, - includeEntries: [], + modules: [], translators: [registerContextTranslator(from: Graph.self) { $0.container }] )) } var allBindings: [Binding] { diff --git a/Sources/3.0 API/Swinject+Builder.swift b/Sources/3.0 API/Swinject+Builder.swift index 7e77285c..c9ec47e2 100644 --- a/Sources/3.0 API/Swinject+Builder.swift +++ b/Sources/3.0 API/Swinject+Builder.swift @@ -22,3 +22,24 @@ public extension Swinject { #if swift(>=5.1) } #endif } + +public extension Swinject.Module { + init(_ name: String, _ entries: SwinjectEntry ...) { + self.init(name: name, tree: SwinjectTreeBuilder.buildFunction(entries)) + } +} + +public extension Swinject.Module { #if swift(>=5.1) + init(_ name: String, @SwinjectTreeBuilder builder: () -> [SwinjectEntry]) { + self.init(name: name, tree: SwinjectTreeBuilder.buildFunction(builder())) + } + + init(_ name: String, @SwinjectTreeBuilder builder: () -> SwinjectEntry) { + self.init(name: name, tree: SwinjectTreeBuilder.buildFunction([builder()])) + } + + init(_ name: String, @SwinjectTreeBuilder _: () -> Void) { + self.init(name: name, tree: SwinjectTreeBuilder.buildFunction([])) + } +#endif +} diff --git a/Sources/3.0 API/SwinjectModule.swift b/Sources/3.0 API/SwinjectModule.swift deleted file mode 100644 index 2e0d4043..00000000 --- a/Sources/3.0 API/SwinjectModule.swift +++ /dev/null @@ -1,8 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -protocol SwinjectModule {} - -// sourcery: AutoMockable -protocol ModuleIncludeEntry: SwinjectEntry {} diff --git a/Sources/Core/Swinject.swift b/Sources/Core/Swinject.swift index 0695f1d6..335b6f75 100644 --- a/Sources/Core/Swinject.swift +++ b/Sources/Core/Swinject.swift @@ -25,11 +25,6 @@ extension Swinject { } extension Swinject: Resolver { - struct Resolution { - let binding: Binding - let translator: AnyContextTranslator - } - public func resolve( _ request: InstanceRequest ) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { @@ -54,7 +49,7 @@ extension Swinject: Resolver { } private func findBinding(for request: AnyInstanceRequest) throws -> Binding { - let bindings = tree.bindings.filter { (try? findTranslator(for: request, and: $0)) != nil } + let bindings = tree.allBindings.filter { (try? findTranslator(for: request, and: $0)) != nil } if bindings.isEmpty { throw NoBindingError() } if bindings.count > 1 { throw MultipleBindingsError() } return bindings[0] diff --git a/Sources/Core/SwinjectModule.swift b/Sources/Core/SwinjectModule.swift new file mode 100644 index 00000000..3bf7ff9c --- /dev/null +++ b/Sources/Core/SwinjectModule.swift @@ -0,0 +1,14 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +extension Swinject { + public struct Module: SwinjectEntry { + let name: String + let tree: SwinjectTree + } +} + +public func include(_ module: Swinject.Module) -> Swinject.Module { + return module +} diff --git a/Sources/Core/SwinjectTree.swift b/Sources/Core/SwinjectTree.swift index ca2109f1..23de44b7 100644 --- a/Sources/Core/SwinjectTree.swift +++ b/Sources/Core/SwinjectTree.swift @@ -2,14 +2,29 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -public protocol SwinjectEntry {} - public struct SwinjectTree { let bindings: [Binding] - let includeEntries: [ModuleIncludeEntry] + let modules: [Swinject.Module] let translators: [AnyContextTranslator] } +extension SwinjectTree { + var allBindings: [Binding] { + return bindings + modules.flatMap { $0.tree.allBindings } + } + + var allModules: [Swinject.Module] { + return modules + modules.flatMap { $0.tree.allModules } + } +} + +extension SwinjectTree { + func assertValid() { + let allModuleNames = allModules.map { $0.name } + assert(allModuleNames.count == Set(allModuleNames).count) + } +} + #if swift(>=5.1) @_functionBuilder public enum SwinjectTreeBuilder {} @@ -17,6 +32,8 @@ public struct SwinjectTree { public enum SwinjectTreeBuilder {} #endif +public protocol SwinjectEntry {} + extension SwinjectTreeBuilder { public static func buildBlock() {} @@ -39,12 +56,13 @@ extension SwinjectTreeBuilder { // This is not used by compiler implicitly yet public static func buildFunction(_ input: [SwinjectEntry]) -> SwinjectTree { let entries = input.flatMap(unpack) - return SwinjectTree( + let tree = SwinjectTree( bindings: entries.compactMap { $0 as? Binding }, - includeEntries: entries.compactMap { $0 as? ModuleIncludeEntry }, + modules: entries.compactMap { $0 as? Swinject.Module }, translators: entries.compactMap { $0 as? AnyContextTranslator } ) - // TODO: Validate + tree.assertValid() + return tree } } diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index fcd666d2..508bca2e 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -12,7 +12,7 @@ 02556F149C9AAEF5CE353AC1 /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; 03122D1B2EA65C89ADC78EC7 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62682D6ED38742996624B041 /* BasicAssembly.swift */; }; 0509EE8D41BF354EB91ACC80 /* Reference.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73B4B777290FF5D38A8914CC /* Reference.swift */; }; - 05B18A91CA201F7EE53F3ADE /* SwinjectApiSpecSwift5_1.swift in Sources */ = {isa = PBXBuildFile; fileRef = C5FB515A9B4B929026438A90 /* SwinjectApiSpecSwift5_1.swift */; }; + 05B18A91CA201F7EE53F3ADE /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = C5FB515A9B4B929026438A90 /* SwinjectApiSpec.swift */; }; 0622539110A7430776A307C7 /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42490D1D0C395951243F5CFF /* Container.swift */; }; 06363AE7650CA288BDF6CB73 /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 34AFFAC41BA9D02A38BDB7A3 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 06F4CAB352B4F623FF7BD885 /* ScopeRegistryKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */; }; @@ -27,7 +27,6 @@ 0CD787EACEBFD1051D358E7D /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; 0CE1126436F680F9684837E4 /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; 0D5C4A278A16AB3A163148AF /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; - 0DC084A3650745492BB81EE9 /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B3797A6BB56AE76CEC19F2A /* SwinjectApiSpec.swift */; }; 1183FED17E9521E848F1F991 /* SwinjectSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9527A4CA5BCBA7AFA3596757 /* SwinjectSpec.swift */; }; 128913D570B4A8BBF40866BE /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; 13CDEC7A6C8E43B58D5CBE3D /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; @@ -39,7 +38,7 @@ 196338EA802A39E205C33B43 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; 19EBB651BD06BD0C03C1ACB5 /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59111BE319C59E4CD6CF68CD /* Assembler.swift */; }; 1A40A26942A65246D7DD268E /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = ADC44E9312C3B974AFD8F07B /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 1BE678F7FA5DF0E6ED2CF565 /* SwinjectApiSpecSwift5_1.swift in Sources */ = {isa = PBXBuildFile; fileRef = C5FB515A9B4B929026438A90 /* SwinjectApiSpecSwift5_1.swift */; }; + 1BE678F7FA5DF0E6ED2CF565 /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = C5FB515A9B4B929026438A90 /* SwinjectApiSpec.swift */; }; 1C82BFD00FCC384DB3AE6A89 /* MatchableBoxes.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 808C1063CA90CC593C7E0E9C /* MatchableBoxes.swifttemplate */; }; 1CA5DF3F93203B226A6FA059 /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EA566CD336DB8343ADFAF9B /* BehaviorFakes.swift */; }; 1E1CAA4156D94E3A73AEA9F6 /* Opaque.swift in Sources */ = {isa = PBXBuildFile; fileRef = C68B98C653ABDED9C3D17DB3 /* Opaque.swift */; }; @@ -51,7 +50,6 @@ 24114725AE1A834C6E3118F7 /* TaggedTypeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */; }; 2615FC1C92B7E381116B9E57 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; 26C4C6118D189E8813ABD5A2 /* Quick.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = C765B92B00C0AC8625BB4AC9 /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 273F441B941A6DF76D9BD752 /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B3797A6BB56AE76CEC19F2A /* SwinjectApiSpec.swift */; }; 283C77045DA55C2134EC9C48 /* Container+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F446D6BD4C44E16A1D608BFB /* Container+TypeForwarding.swift */; }; 290C9E9420A1EE30456476CB /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59111BE319C59E4CD6CF68CD /* Assembler.swift */; }; 293985649250DF270DC89135 /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; @@ -82,7 +80,6 @@ 3C270A77DE4F1E6BC2F8E863 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; 3CEF021295AD9AF9BF26B71E /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; 3DEFB7CA42D9EFF0B4FBC0F4 /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 38BCCF3F950869BD1891F7A8 /* Swinject.framework */; }; - 3F0DCA7060C62712EA30CBB1 /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B3797A6BB56AE76CEC19F2A /* SwinjectApiSpec.swift */; }; 3F704A98C01C84BDBD0A52B3 /* BinderEnvironmentSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */; }; 3F8F5645D6D37FCEC1D89393 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B580B43E1891812C97209 /* Binding.swift */; }; 401592294E5D528379BE1AB2 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62682D6ED38742996624B041 /* BasicAssembly.swift */; }; @@ -104,7 +101,6 @@ 4E4DC8CDD1BA51FB66A332C2 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */; }; 4EC94A51037C79DE0C5C8CB1 /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; 4EE5C1207C57C85A928FA89B /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 273FB7A6277E0841E1570990 /* Nimble.framework */; }; - 4EFB0A66BBCAA617470CE622 /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B3797A6BB56AE76CEC19F2A /* SwinjectApiSpec.swift */; }; 53AC03FA6538E56A976E52FA /* SwinjectSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9527A4CA5BCBA7AFA3596757 /* SwinjectSpec.swift */; }; 53EBF7A46EF65F2A8DAADC7A /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; 546FF827DB6D42490D1CA439 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; @@ -152,7 +148,7 @@ 725EF35B0CC5E62791D5EA09 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 34AFFAC41BA9D02A38BDB7A3 /* Nimble.framework */; }; 7295E928A18E6055CF796840 /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C074BAC560F277E806146C60 /* SimpleBinding.swift */; }; 732A8933C1310C2A6309E56B /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCAF491EC7DCD7477F9A0ECB /* SwinjectModule.swift */; }; - 7337BA3B0248BE5A4C8C1339 /* SwinjectApiSpecSwift5_1.swift in Sources */ = {isa = PBXBuildFile; fileRef = C5FB515A9B4B929026438A90 /* SwinjectApiSpecSwift5_1.swift */; }; + 7337BA3B0248BE5A4C8C1339 /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = C5FB515A9B4B929026438A90 /* SwinjectApiSpec.swift */; }; 737740CDFB89189DFF5FD165 /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 74DE57FB3E8228904E6FE0D7 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; 74E1FC692A27C56510363364 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; 75D74C8C25EDACF5A7A75A5C /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; @@ -320,7 +316,7 @@ E5880DBBB91CC5F8F47FBF73 /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; E7D1045D25FAB592401DCAF0 /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; EA7EB12BDE27575738D26AD4 /* SimpleBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */; }; - EAD78B74CDD8AA95ADC26126 /* SwinjectApiSpecSwift5_1.swift in Sources */ = {isa = PBXBuildFile; fileRef = C5FB515A9B4B929026438A90 /* SwinjectApiSpecSwift5_1.swift */; }; + EAD78B74CDD8AA95ADC26126 /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = C5FB515A9B4B929026438A90 /* SwinjectApiSpec.swift */; }; EB3420214A9E68A0247D0F2C /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 351C4221896DDB8572BD6CB5 /* Person.swift */; }; EB79ECF5C893F63B22355167 /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; EBC64A1515C868E410C83451 /* SwiftCode.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 90191C25A2D66E07C4E9CD73 /* SwiftCode.swifttemplate */; }; @@ -476,7 +472,6 @@ 13513FA012659ADE699A3608 /* LazySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LazySpec.swift; sourceTree = ""; }; 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleBindingSpec.swift; sourceTree = ""; }; 1A006CC804F9AB8ACC121029 /* Utils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = ""; }; - 1B3797A6BB56AE76CEC19F2A /* SwinjectApiSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectApiSpec.swift; sourceTree = ""; }; 1C58FC14EEA170B0DC079DE4 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Circularity.swift; sourceTree = ""; }; 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Behavior.swift; sourceTree = ""; }; @@ -552,7 +547,7 @@ BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Behavior.swift; sourceTree = ""; }; C074BAC560F277E806146C60 /* SimpleBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleBinding.swift; sourceTree = ""; }; C3C516EFA0CA22D19F07B27E /* InjectionVariation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InjectionVariation.swift; sourceTree = ""; }; - C5FB515A9B4B929026438A90 /* SwinjectApiSpecSwift5_1.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectApiSpecSwift5_1.swift; sourceTree = ""; }; + C5FB515A9B4B929026438A90 /* SwinjectApiSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectApiSpec.swift; sourceTree = ""; }; C68B98C653ABDED9C3D17DB3 /* Opaque.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Opaque.swift; sourceTree = ""; }; C765B92B00C0AC8625BB4AC9 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; CADDB3E9E363310028AA5920 /* InstanceMaker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceMaker.swift; sourceTree = ""; }; @@ -681,7 +676,6 @@ B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */, 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */, 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */, - FCAF491EC7DCD7477F9A0ECB /* SwinjectModule.swift */, B92B8E618A08408404FB2A7A /* TypeBinder.swift */, ); path = "3.0 API"; @@ -773,8 +767,7 @@ 9A6E5EB655CFE64BBCF5DED1 /* 3.0 API */ = { isa = PBXGroup; children = ( - 1B3797A6BB56AE76CEC19F2A /* SwinjectApiSpec.swift */, - C5FB515A9B4B929026438A90 /* SwinjectApiSpecSwift5_1.swift */, + C5FB515A9B4B929026438A90 /* SwinjectApiSpec.swift */, ); path = "3.0 API"; sourceTree = ""; @@ -852,6 +845,7 @@ FCA9C6262A4D071C8E7EEBD0 /* Core */ = { isa = PBXGroup; children = ( + FCAF491EC7DCD7477F9A0ECB /* SwinjectModule.swift */, 0E0B580B43E1891812C97209 /* Binding.swift */, A24B4E8F1CA18603DBB6884A /* BindingKey.swift */, 65D0BCCCD61CD9BECC29E064 /* Closable.swift */, @@ -1491,8 +1485,7 @@ B3549C40707070622D261363 /* ScopedBindingSpec.swift in Sources */, 838E49C5683FA93A3A917346 /* SimpleBindingSpec.swift in Sources */, 72217E47D83C3CA6D97640B9 /* StandardScopeRegistrySpec.swift in Sources */, - 0DC084A3650745492BB81EE9 /* SwinjectApiSpec.swift in Sources */, - 1BE678F7FA5DF0E6ED2CF565 /* SwinjectApiSpecSwift5_1.swift in Sources */, + 1BE678F7FA5DF0E6ED2CF565 /* SwinjectApiSpec.swift in Sources */, 1183FED17E9521E848F1F991 /* SwinjectSpec.swift in Sources */, 640F7A55D9A671FA112C8083 /* SwinjectTreeBuilderSpec.swift in Sources */, F7CD04FB09FC7F18E9E001CF /* SynchronizedResolverSpec.swift in Sources */, @@ -1536,8 +1529,7 @@ CEA4CB2D3113EC693C590B9D /* ScopedBindingSpec.swift in Sources */, EA7EB12BDE27575738D26AD4 /* SimpleBindingSpec.swift in Sources */, C952D5869D87743297968E9A /* StandardScopeRegistrySpec.swift in Sources */, - 273F441B941A6DF76D9BD752 /* SwinjectApiSpec.swift in Sources */, - EAD78B74CDD8AA95ADC26126 /* SwinjectApiSpecSwift5_1.swift in Sources */, + EAD78B74CDD8AA95ADC26126 /* SwinjectApiSpec.swift in Sources */, 8CE52672848FD54520215CA1 /* SwinjectSpec.swift in Sources */, A308578B99D33C7E33632E85 /* SwinjectTreeBuilderSpec.swift in Sources */, 3BDB44DE92D2377334894804 /* SynchronizedResolverSpec.swift in Sources */, @@ -1581,8 +1573,7 @@ C4CB7A3BA35A1E0811842971 /* ScopedBindingSpec.swift in Sources */, DB03A9B61E162A73506C8552 /* SimpleBindingSpec.swift in Sources */, 0720BEA814AD514378380ACB /* StandardScopeRegistrySpec.swift in Sources */, - 3F0DCA7060C62712EA30CBB1 /* SwinjectApiSpec.swift in Sources */, - 05B18A91CA201F7EE53F3ADE /* SwinjectApiSpecSwift5_1.swift in Sources */, + 05B18A91CA201F7EE53F3ADE /* SwinjectApiSpec.swift in Sources */, 53AC03FA6538E56A976E52FA /* SwinjectSpec.swift in Sources */, 3CEF021295AD9AF9BF26B71E /* SwinjectTreeBuilderSpec.swift in Sources */, 546FF827DB6D42490D1CA439 /* SynchronizedResolverSpec.swift in Sources */, @@ -1626,8 +1617,7 @@ 3575DE21531F7365B713B64B /* ScopedBindingSpec.swift in Sources */, 15246957A062BF0ED7134E0E /* SimpleBindingSpec.swift in Sources */, 0B61DC733616A8ED4ED77FA7 /* StandardScopeRegistrySpec.swift in Sources */, - 4EFB0A66BBCAA617470CE622 /* SwinjectApiSpec.swift in Sources */, - 7337BA3B0248BE5A4C8C1339 /* SwinjectApiSpecSwift5_1.swift in Sources */, + 7337BA3B0248BE5A4C8C1339 /* SwinjectApiSpec.swift in Sources */, 45D57E61D4774613F2DF1CCA /* SwinjectSpec.swift in Sources */, 233F3E25FF0B51A3E6611F58 /* SwinjectTreeBuilderSpec.swift in Sources */, 890CCD2800597F6FB7C6FD31 /* SynchronizedResolverSpec.swift in Sources */, diff --git a/Tests/3.0 API/SwinjectApiSpec.swift b/Tests/3.0 API/SwinjectApiSpec.swift index b8214206..7a5aceaa 100644 --- a/Tests/3.0 API/SwinjectApiSpec.swift +++ b/Tests/3.0 API/SwinjectApiSpec.swift @@ -7,156 +7,162 @@ import Quick import Swinject @testable import class Swinject.UnboundScope -class SwinjectApiSpec: QuickSpec { override func spec() { +class SwinjectApiSpec: QuickSpec { override func spec() { #if swift(>=5.1) var human = Human() beforeEach { UnboundScope.root.close() human = Human() } it("returns instance if is bound") { - let swinject = Swinject( + let swinject = Swinject { bbind(Int.self).with(42) - ) + } expect { try swinject.instance(of: Int.self) } == 42 } it("can infer the requested type") { - let swinject = Swinject( + let swinject = Swinject { bbind(Int.self) & 42 - ) + } expect { try swinject.instance() as Int } == 42 } it("throws if providing type with missing dependency") { - let swinject = Swinject( + let swinject = Swinject { bbind(Pet.self) & provider { Pet(owner: try $0.instance()) } - ) + } expect { try swinject.instance(of: Pet.self) }.to(throwError()) } it("returns instance if all dependencies are bound") { - let swinject = Swinject( - bbind(Pet.self) & provider { Pet(owner: try $0.instance()) }, + let swinject = Swinject { + bbind(Pet.self) & provider { Pet(owner: try $0.instance()) } bbind(Human.self) & instance(human) - ) + } expect { try swinject.instance(of: Pet.self).owner } === human } it("throws if has multiple bindings for the same request") { - let swinject = Swinject( - bbind(Int.self) & 42, + let swinject = Swinject { + bbind(Int.self) & 42 bbind(Int.self) & provider { 17 + 25 } - ) + } expect { try swinject.instance(of: Int.self) }.to(throwError()) } it("throws if requesting instance with wrong tag") { - let swinject = Swinject( + let swinject = Swinject { bbind(Int.self, tagged: "Tag") & 42 - ) + } expect { try swinject.instance(of: Int.self) }.to(throwError()) expect { try swinject.instance(of: Int.self, tagged: 42) }.to(throwError()) expect { try swinject.instance(of: Int.self, tagged: "OtherTag") }.to(throwError()) } it("returns instance with correct tag") { - let swinject = Swinject( - bbind(String.self) & "Plain", + let swinject = Swinject { + bbind(String.self) & "Plain" bbind(String.self, tagged: "Tag") & "Tagged" - ) + } expect { try swinject.instance(of: String.self) } == "Plain" expect { try swinject.instance(of: String.self, tagged: "Tag") } == "Tagged" } it("can bind protocol to implementation") { - let swinject = Swinject( + let swinject = Swinject { bbind(Mammal.self).with(provider { Human() }) - ) + } expect(try? swinject.instance(of: Mammal.self) is Human) == true } it("can inject optionals") { - let swinject = Swinject( + let swinject = Swinject { bbind(Int.self) & 42 - ) + } expect { try swinject.instance() as Int? } == 42 } it("can inject instance provider") { - let swinject = Swinject( + let swinject = Swinject { bbind(Int.self, tagged: "tag") & 42 - ) + } let provider = swinject.provider(of: Int.self, tagged: "tag") expect { try provider() } == 42 } it("can inject instance factory") { - let swinject = Swinject( - bbind(Double.self) & 17.0, - bbind(Int.self) & factory { (r, arg: Int) in - Int(try r.instance() as Double) + 5 * arg - } - ) + // FIXME: compiler segfaults if declaring this factory inside function builder + let intFactory = factory { (r, arg: Int) in Int(try r.instance() as Double) + 5 * arg } + let swinject = Swinject { + bbind(Double.self) & 17.0 + bbind(Int.self) & intFactory + } let factory = swinject.factory() as (Int) throws -> Int expect { try factory(5) } == 42 } it("can inject factory binding as provider or instance") { - let swinject = Swinject( - bbind(Double.self) & 17.0, + let swinject = Swinject { + bbind(Double.self) & 17.0 bbind(Int.self) & factory { Int(try $0.instance() as Double) + 5 * $1 } - ) + } expect { try swinject.provider(of: Int.self, arg: 5)() } == 42 expect { try swinject.instance(of: Int.self, arg: 5) } == 42 } it("can curry factory's arguments") { - let swinject = Swinject( + let swinject = Swinject { bbind(Int.self) & factory { (_, a1: Int, a2: Double, a3: String) in a1 + Int(a2) + Int(a3)! } - ) + } expect { try swinject.factory(of: Int.self)(11, 14.0, "17") } == 42 expect { try swinject.factory(of: Int.self, arg: 11)(14.0, "17") } == 42 expect { try swinject.factory(of: Int.self, arg: 11, 14.0)("17") } == 42 } it("can pass context to the bindings") { - let swinject = Swinject( - bbind(Int.self) & contexted(String.self).provider { _, string in Int(string)! }, - bbind(Double.self) & contexted(String.self).provider { _, string in Double(string)! } - ) + // FIXME: compiler segfaults if declaring these providers inside function builder + let intProvider = contexted(String.self).provider { _, string in Int(string)! } + let doubleProvider = contexted(String.self).provider { _, string in Double(string)! } + let swinject = Swinject { + bbind(Int.self) & intProvider + bbind(Double.self) & doubleProvider + } let contexted = swinject.on("42") expect { try contexted.instance(of: Int.self) } == 42 expect { try contexted.instance(of: Double.self) } == 42 expect { try swinject.instance(of: Int.self) }.to(throwError()) } it("can use binding without context in any context") { - let swinject = Swinject( + let swinject = Swinject { bbind(Int.self) & 42 - ) + } expect { try swinject.on("context").instance() as Int } == 42 expect { try swinject.on(Human()).instance() as Int } == 42 } it("can translate contexts") { - let swinject = Swinject( - bbind(Int.self) & contexted(String.self).provider { _, string in Int(string)! }, - bbind(Double.self) & contexted(Int.self).provider { _, int in Double(int) }, + // FIXME: compiler segfaults if declaring these providers inside function builder + let intProvider = contexted(String.self).provider { _, string in Int(string)! } + let doubleProvider = contexted(Int.self).provider { _, int in Double(int) } + let swinject = Swinject { + bbind(Int.self) & intProvider + bbind(Double.self) & doubleProvider registerContextTranslator(from: String.self) { Int($0)! } - ) + } let contexted = swinject.on("42") expect { try contexted.instance(of: Int.self) } == 42 expect { try contexted.instance(of: Double.self) } == 42 } it("can bind singleton") { - let swinject = Swinject( + let swinject = Swinject { bbind(Human.self) & singleton { Human() } - ) + } let first = try? swinject.instance() as Human let second = try? swinject.instance() as Human expect(first) === second } it("can bind scoped singleton") { let scope = UnboundScope() - let swinject = Swinject( + let swinject = Swinject { bbind(Human.self) & scoped(scope).singleton { Human() } - ) + } let first = try? swinject.instance() as Human let second = try? swinject.instance() as Human expect(first) === second } it("can close scopes") { let scope = UnboundScope() - let swinject = Swinject( + let swinject = Swinject { bbind(Human.self) & scoped(scope).singleton { Human() } - ) + } let first = try? swinject.instance() as Human scope.close() let second = try? swinject.instance() as Human @@ -164,28 +170,82 @@ class SwinjectApiSpec: QuickSpec { override func spec() { } it("notifies instances when scope is closed") { let scope = UnboundScope() - let swinject = Swinject( + let swinject = Swinject { bbind(ClosableMock.self) & scoped(scope).singleton { ClosableMock() } - ) + } let closable = try? swinject.instance() as ClosableMock scope.close() expect(closable?.closeCalled) == true } it("can bind weakly referenced singleton") { - let swinject = Swinject( + let swinject = Swinject { bbind(Human.self) & singleton(ref: weakRef) { Human() } - ) + } weak var first = try? swinject.instance() as Human expect(first).to(beNil()) } it("can bind multitons") { - let swinject = Swinject( + let swinject = Swinject { bbind(Building.self) & multiton { Building(floors: $1) } - ) + } let house1 = try? swinject.instance(arg: 1) as Building let house2 = try? swinject.instance(arg: 1) as Building let skyscrapper = try? swinject.instance(arg: 100) as Building expect(house1) === house2 expect(skyscrapper) !== house1 } + it("can separate bindings into modules") { + let intModule = Swinject.Module("Int") { + bbind(Int.self) & 42 + } + let doubleModule = Swinject.Module("Double") { + bbind(Double.self) & provider { 25 + 17 } + } + let swinject = Swinject { + include(intModule) + include(doubleModule) + } + expect { try swinject.instance() as Int } == 42 + expect { try swinject.instance() as Double } == 42.0 + } + it("can handle module hierarchies") { + let intModule = Swinject.Module("Int") { + bbind(Int.self) & 42 + } + let numbersModule = Swinject.Module("Double") { + include(intModule) + bbind(Double.self) & provider { 25 + 17 } + } + let swinject = Swinject { + include(numbersModule) + } + expect { try swinject.instance() as Int } == 42 + expect { try swinject.instance() as Double } == 42.0 + } + it("does not allow modules with the same name") { + let firstModule = Swinject.Module("name") + let secondModule = Swinject.Module("name") + expect { + _ = Swinject { + include(firstModule) + include(secondModule) + } + }.to(throwAssertion()) + } + it("fails if module is included multiple times") { + let firstModule = Swinject.Module("first") + let secondModule = Swinject.Module("second") { + include(firstModule) + } + let thirdModule = Swinject.Module("third") { + include(firstModule) + } + expect { + _ = Swinject { + include(secondModule) + include(thirdModule) + } + }.to(throwAssertion()) + } + #endif } } diff --git a/Tests/3.0 API/SwinjectApiSpecSwift5_1.swift b/Tests/3.0 API/SwinjectApiSpecSwift5_1.swift deleted file mode 100644 index a2ce32da..00000000 --- a/Tests/3.0 API/SwinjectApiSpecSwift5_1.swift +++ /dev/null @@ -1,198 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -import Nimble -import Quick -import Swinject -@testable import class Swinject.UnboundScope - -class SwinjectApiSpecSwift5_1: QuickSpec { override func spec() { #if swift(>=5.1) - var human = Human() - beforeEach { - UnboundScope.root.close() - human = Human() - } - it("returns instance if is bound") { - let swinject = Swinject { - bbind(Int.self).with(42) - } - expect { try swinject.instance(of: Int.self) } == 42 - } - it("can infer the requested type") { - let swinject = Swinject { - bbind(Int.self) & 42 - } - expect { try swinject.instance() as Int } == 42 - } - it("throws if providing type with missing dependency") { - let swinject = Swinject { - bbind(Pet.self) & provider { Pet(owner: try $0.instance()) } - } - expect { try swinject.instance(of: Pet.self) }.to(throwError()) - } - it("returns instance if all dependencies are bound") { - let swinject = Swinject { - bbind(Pet.self) & provider { Pet(owner: try $0.instance()) } - bbind(Human.self) & instance(human) - } - expect { try swinject.instance(of: Pet.self).owner } === human - } - it("throws if has multiple bindings for the same request") { - let swinject = Swinject { - bbind(Int.self) & 42 - bbind(Int.self) & provider { 17 + 25 } - } - expect { try swinject.instance(of: Int.self) }.to(throwError()) - } - it("throws if requesting instance with wrong tag") { - let swinject = Swinject { - bbind(Int.self, tagged: "Tag") & 42 - } - expect { try swinject.instance(of: Int.self) }.to(throwError()) - expect { try swinject.instance(of: Int.self, tagged: 42) }.to(throwError()) - expect { try swinject.instance(of: Int.self, tagged: "OtherTag") }.to(throwError()) - } - it("returns instance with correct tag") { - let swinject = Swinject { - bbind(String.self) & "Plain" - bbind(String.self, tagged: "Tag") & "Tagged" - } - expect { try swinject.instance(of: String.self) } == "Plain" - expect { try swinject.instance(of: String.self, tagged: "Tag") } == "Tagged" - } - it("can bind protocol to implementation") { - let swinject = Swinject { - bbind(Mammal.self).with(provider { Human() }) - } - expect(try? swinject.instance(of: Mammal.self) is Human) == true - } - it("can inject optionals") { - let swinject = Swinject { - bbind(Int.self) & 42 - } - expect { try swinject.instance() as Int? } == 42 - } - it("can inject instance provider") { - let swinject = Swinject { - bbind(Int.self, tagged: "tag") & 42 - } - let provider = swinject.provider(of: Int.self, tagged: "tag") - expect { try provider() } == 42 - } - it("can inject instance factory") { - // FIXME: compiler segfaults if declaring this factory inside function builder - let intFactory = factory { (r, arg: Int) in Int(try r.instance() as Double) + 5 * arg } - let swinject = Swinject { - bbind(Double.self) & 17.0 - bbind(Int.self) & intFactory - } - let factory = swinject.factory() as (Int) throws -> Int - expect { try factory(5) } == 42 - } - it("can inject factory binding as provider or instance") { - let swinject = Swinject { - bbind(Double.self) & 17.0 - bbind(Int.self) & factory { Int(try $0.instance() as Double) + 5 * $1 } - } - expect { try swinject.provider(of: Int.self, arg: 5)() } == 42 - expect { try swinject.instance(of: Int.self, arg: 5) } == 42 - } - it("can curry factory's arguments") { - let swinject = Swinject { - bbind(Int.self) & factory { (_, a1: Int, a2: Double, a3: String) in - a1 + Int(a2) + Int(a3)! - } - } - expect { try swinject.factory(of: Int.self)(11, 14.0, "17") } == 42 - expect { try swinject.factory(of: Int.self, arg: 11)(14.0, "17") } == 42 - expect { try swinject.factory(of: Int.self, arg: 11, 14.0)("17") } == 42 - } - it("can pass context to the bindings") { - // FIXME: compiler segfaults if declaring these providers inside function builder - let intProvider = contexted(String.self).provider { _, string in Int(string)! } - let doubleProvider = contexted(String.self).provider { _, string in Double(string)! } - let swinject = Swinject { - bbind(Int.self) & intProvider - bbind(Double.self) & doubleProvider - } - let contexted = swinject.on("42") - expect { try contexted.instance(of: Int.self) } == 42 - expect { try contexted.instance(of: Double.self) } == 42 - expect { try swinject.instance(of: Int.self) }.to(throwError()) - } - it("can use binding without context in any context") { - let swinject = Swinject { - bbind(Int.self) & 42 - } - expect { try swinject.on("context").instance() as Int } == 42 - expect { try swinject.on(Human()).instance() as Int } == 42 - } - it("can translate contexts") { - // FIXME: compiler segfaults if declaring these providers inside function builder - let intProvider = contexted(String.self).provider { _, string in Int(string)! } - let doubleProvider = contexted(Int.self).provider { _, int in Double(int) } - let swinject = Swinject { - bbind(Int.self) & intProvider - bbind(Double.self) & doubleProvider - registerContextTranslator(from: String.self) { Int($0)! } - } - let contexted = swinject.on("42") - expect { try contexted.instance(of: Int.self) } == 42 - expect { try contexted.instance(of: Double.self) } == 42 - } - it("can bind singleton") { - let swinject = Swinject { - bbind(Human.self) & singleton { Human() } - } - let first = try? swinject.instance() as Human - let second = try? swinject.instance() as Human - expect(first) === second - } - it("can bind scoped singleton") { - let scope = UnboundScope() - let swinject = Swinject { - bbind(Human.self) & scoped(scope).singleton { Human() } - } - let first = try? swinject.instance() as Human - let second = try? swinject.instance() as Human - expect(first) === second - } - it("can close scopes") { - let scope = UnboundScope() - let swinject = Swinject { - bbind(Human.self) & scoped(scope).singleton { Human() } - } - let first = try? swinject.instance() as Human - scope.close() - let second = try? swinject.instance() as Human - expect(first) !== second - } - it("notifies instances when scope is closed") { - let scope = UnboundScope() - let swinject = Swinject { - bbind(ClosableMock.self) & scoped(scope).singleton { ClosableMock() } - } - let closable = try? swinject.instance() as ClosableMock - scope.close() - expect(closable?.closeCalled) == true - } - it("can bind weakly referenced singleton") { - let swinject = Swinject { - bbind(Human.self) & singleton(ref: weakRef) { Human() } - } - weak var first = try? swinject.instance() as Human - expect(first).to(beNil()) - } - it("can bind multitons") { - let swinject = Swinject { - bbind(Building.self) & multiton { Building(floors: $1) } - } - let house1 = try? swinject.instance(arg: 1) as Building - let house2 = try? swinject.instance(arg: 1) as Building - let skyscrapper = try? swinject.instance(arg: 100) as Building - expect(house1) === house2 - expect(skyscrapper) !== house1 - } - #endif -} } diff --git a/Tests/LinuxConfig.swift b/Tests/LinuxConfig.swift index d8026e0e..816ae692 100644 --- a/Tests/LinuxConfig.swift +++ b/Tests/LinuxConfig.swift @@ -18,7 +18,6 @@ let allSpecs: [QuickSpec.Type] = [ SynchronizedResolverSpec.self, // 3.0 Api SwinjectApiSpec.self, - SwinjectApiSpecSwift5_1.self, // Unit Specs BinderEnvironmentSpec.self, BindingKeySpec.self, diff --git a/Tests/Support/GeneratedMocks.swift b/Tests/Support/GeneratedMocks.swift index 0784f9e2..95e5dc0f 100644 --- a/Tests/Support/GeneratedMocks.swift +++ b/Tests/Support/GeneratedMocks.swift @@ -322,9 +322,6 @@ class MatchableMock: Matchable { hashIntoClosure?(&hasher) } -} -class ModuleIncludeEntryMock: ModuleIncludeEntry { - } class StaticScopeRegistryMock: StaticScopeRegistry { diff --git a/Tests/Unit Specs/SwinjectTreeBuilderSpec.swift b/Tests/Unit Specs/SwinjectTreeBuilderSpec.swift index 3af93a58..6f262b31 100644 --- a/Tests/Unit Specs/SwinjectTreeBuilderSpec.swift +++ b/Tests/Unit Specs/SwinjectTreeBuilderSpec.swift @@ -43,13 +43,13 @@ class SwinjectTreeBuilderSpec: QuickSpec { override func spec() { #if swift(>=5. // } it("builds closure with maker & include entries") { let tree = makeTree { - ModuleIncludeEntryMock() - ModuleIncludeEntryMock() + Swinject.Module("1") + Swinject.Module("2") BindingMock() BindingMock() BindingMock() } - expect(tree.includeEntries.count) == 2 + expect(tree.modules.count) == 2 expect(tree.bindings.count) == 3 } it("builds closure with translator entries") { From 1d15960a44699d9d9db9e4d29401ecf3da8fc07a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sat, 27 Jul 2019 23:34:27 +0200 Subject: [PATCH 155/239] Separate module spec --- Tests/3.0 API/ModulesSpec.swift | 64 +++++++++++++++++++++++++++++ Tests/3.0 API/SwinjectApiSpec.swift | 53 ------------------------ Tests/LinuxConfig.swift | 1 + 3 files changed, 65 insertions(+), 53 deletions(-) create mode 100644 Tests/3.0 API/ModulesSpec.swift diff --git a/Tests/3.0 API/ModulesSpec.swift b/Tests/3.0 API/ModulesSpec.swift new file mode 100644 index 00000000..e5dbceb1 --- /dev/null +++ b/Tests/3.0 API/ModulesSpec.swift @@ -0,0 +1,64 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +import Nimble +import Quick +import Swinject + +class ModulesSpec: QuickSpec { override func spec() { #if swift(>=5.1) + it("can separate bindings into modules") { + let intModule = Swinject.Module("Int") { + bbind(Int.self) & 42 + } + let doubleModule = Swinject.Module("Double") { + bbind(Double.self) & provider { 25 + 17 } + } + let swinject = Swinject { + include(intModule) + include(doubleModule) + } + expect { try swinject.instance() as Int } == 42 + expect { try swinject.instance() as Double } == 42.0 + } + it("can handle module hierarchies") { + let intModule = Swinject.Module("Int") { + bbind(Int.self) & 42 + } + let numbersModule = Swinject.Module("Double") { + include(intModule) + bbind(Double.self) & provider { 25 + 17 } + } + let swinject = Swinject { + include(numbersModule) + } + expect { try swinject.instance() as Int } == 42 + expect { try swinject.instance() as Double } == 42.0 + } + it("does not allow modules with the same name") { + let firstModule = Swinject.Module("name") + let secondModule = Swinject.Module("name") + expect { + _ = Swinject { + include(firstModule) + include(secondModule) + } + }.to(throwAssertion()) + } + it("fails if module is included multiple times") { + let firstModule = Swinject.Module("first") + let secondModule = Swinject.Module("second") { + include(firstModule) + } + let thirdModule = Swinject.Module("third") { + include(firstModule) + } + expect { + _ = Swinject { + include(secondModule) + include(thirdModule) + } + }.to(throwAssertion()) + } + #endif +} } diff --git a/Tests/3.0 API/SwinjectApiSpec.swift b/Tests/3.0 API/SwinjectApiSpec.swift index 7a5aceaa..047821e6 100644 --- a/Tests/3.0 API/SwinjectApiSpec.swift +++ b/Tests/3.0 API/SwinjectApiSpec.swift @@ -194,58 +194,5 @@ class SwinjectApiSpec: QuickSpec { override func spec() { #if swift(>=5.1) expect(house1) === house2 expect(skyscrapper) !== house1 } - it("can separate bindings into modules") { - let intModule = Swinject.Module("Int") { - bbind(Int.self) & 42 - } - let doubleModule = Swinject.Module("Double") { - bbind(Double.self) & provider { 25 + 17 } - } - let swinject = Swinject { - include(intModule) - include(doubleModule) - } - expect { try swinject.instance() as Int } == 42 - expect { try swinject.instance() as Double } == 42.0 - } - it("can handle module hierarchies") { - let intModule = Swinject.Module("Int") { - bbind(Int.self) & 42 - } - let numbersModule = Swinject.Module("Double") { - include(intModule) - bbind(Double.self) & provider { 25 + 17 } - } - let swinject = Swinject { - include(numbersModule) - } - expect { try swinject.instance() as Int } == 42 - expect { try swinject.instance() as Double } == 42.0 - } - it("does not allow modules with the same name") { - let firstModule = Swinject.Module("name") - let secondModule = Swinject.Module("name") - expect { - _ = Swinject { - include(firstModule) - include(secondModule) - } - }.to(throwAssertion()) - } - it("fails if module is included multiple times") { - let firstModule = Swinject.Module("first") - let secondModule = Swinject.Module("second") { - include(firstModule) - } - let thirdModule = Swinject.Module("third") { - include(firstModule) - } - expect { - _ = Swinject { - include(secondModule) - include(thirdModule) - } - }.to(throwAssertion()) - } #endif } } diff --git a/Tests/LinuxConfig.swift b/Tests/LinuxConfig.swift index 816ae692..3ae44e5a 100644 --- a/Tests/LinuxConfig.swift +++ b/Tests/LinuxConfig.swift @@ -18,6 +18,7 @@ let allSpecs: [QuickSpec.Type] = [ SynchronizedResolverSpec.self, // 3.0 Api SwinjectApiSpec.self, + ModulesSpec.self // Unit Specs BinderEnvironmentSpec.self, BindingKeySpec.self, From 8d3da90274b643107d724596c8fa1e1750688641 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sat, 27 Jul 2019 23:35:11 +0200 Subject: [PATCH 156/239] Separate scopes spec --- Swinject.xcodeproj/project.pbxproj | 30 ++++++++++++------ Tests/3.0 API/ScopesSpec.swift | 41 +++++++++++++++++++++++++ Tests/3.0 API/SwinjectApiSpec.swift | 28 ----------------- Tests/LinuxConfig.swift | 4 +-- Tests/Unit Specs/UnboundScopeSpec.swift | 33 -------------------- 5 files changed, 63 insertions(+), 73 deletions(-) create mode 100644 Tests/3.0 API/ScopesSpec.swift delete mode 100644 Tests/Unit Specs/UnboundScopeSpec.swift diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 508bca2e..5ef87229 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -180,7 +180,6 @@ 8E1E051646BBD6E38F4199C2 /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EA566CD336DB8343ADFAF9B /* BehaviorFakes.swift */; }; 91E435894038C42335086FA8 /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3586A4987B7C7C8122D674E /* SwinjectError.swift */; }; 920DE2CAB9895D10FAE48FBA /* ScopeRegistryKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */; }; - 922CDD2FF5974D1756D5A126 /* UnboundScopeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 671D5D89472DAFA916814506 /* UnboundScopeSpec.swift */; }; 934AFACA6BFF24AD3503F98D /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */; }; 93BCD12CEFB88BAD49BEA431 /* ServiceEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38615FC8EEB466C5C1EAD21C /* ServiceEntry.swift */; }; 9425887520AC2DBDCBACB252 /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92B8E618A08408404FB2A7A /* TypeBinder.swift */; }; @@ -198,7 +197,6 @@ 9AD60A86D5A0DF4513C1EA8D /* TaggedTypeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */; }; 9C12EB42EC058994805E93A6 /* GeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */; }; 9C15BE01C1EA41061CDB7918 /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C074BAC560F277E806146C60 /* SimpleBinding.swift */; }; - 9C4FEA520C7CB1ACBAC1B57B /* UnboundScopeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 671D5D89472DAFA916814506 /* UnboundScopeSpec.swift */; }; 9CCAB8EE342CCC8D2FB187C1 /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */; }; 9CEE20BD42795D5E5F39BF20 /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; 9DEAC620F2F00D0DDD3B5D3E /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; @@ -259,7 +257,6 @@ C177D9C6969ADA38C1094F6D /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */; }; C223101DB417F1237A8421E1 /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 6D434EB4C13CF9D9FA6D80CB /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; C243400E417F4A91E491B5EB /* ScopeRegistryKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2902FD4C1A50263340A51FFB /* ScopeRegistryKeySpec.swift */; }; - C3212F88E16B0592070C4F35 /* UnboundScopeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 671D5D89472DAFA916814506 /* UnboundScopeSpec.swift */; }; C38A2EBF4D1904E7D6989989 /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADA1541ABC1365DFD7E3377F /* Food.swift */; }; C3FDE105B08336F26CC95BAA /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = A10187BB3A994165E7FC1528 /* ScopedBinding.swift */; }; C4CB7A3BA35A1E0811842971 /* ScopedBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */; }; @@ -276,6 +273,14 @@ CB9E8D16D7A0620A1F7A32A3 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; CBBE28990E0EA82AD8D5E3AF /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; CBE63031F33303F3E503CEF2 /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; + CD77892222ECF8F100560AB7 /* ModulesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD77892122ECF8F100560AB7 /* ModulesSpec.swift */; }; + CD77892322ECF8F100560AB7 /* ModulesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD77892122ECF8F100560AB7 /* ModulesSpec.swift */; }; + CD77892422ECF8F100560AB7 /* ModulesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD77892122ECF8F100560AB7 /* ModulesSpec.swift */; }; + CD77892522ECF8F100560AB7 /* ModulesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD77892122ECF8F100560AB7 /* ModulesSpec.swift */; }; + CD77892822ECF9C700560AB7 /* ScopesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD77892722ECF9C700560AB7 /* ScopesSpec.swift */; }; + CD77892922ECF9C700560AB7 /* ScopesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD77892722ECF9C700560AB7 /* ScopesSpec.swift */; }; + CD77892A22ECF9C700560AB7 /* ScopesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD77892722ECF9C700560AB7 /* ScopesSpec.swift */; }; + CD77892B22ECF9C700560AB7 /* ScopesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD77892722ECF9C700560AB7 /* ScopesSpec.swift */; }; CD92116422ECC05600211BF0 /* LinuxConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD92116322ECC05600211BF0 /* LinuxConfig.swift */; }; CD92116522ECC05600211BF0 /* LinuxConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD92116322ECC05600211BF0 /* LinuxConfig.swift */; }; CD92116622ECC05600211BF0 /* LinuxConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD92116322ECC05600211BF0 /* LinuxConfig.swift */; }; @@ -329,7 +334,6 @@ F050175A7FB08DE1F97DC11C /* TypeBinderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDA62EEBC79ED2639C93A76B /* TypeBinderSpec.swift */; }; F06DEB671A4B85ABB0E96E51 /* ContextTranslator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */; }; F270DC6FF3901F58C76F3872 /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; - F2857EAA276179402A5E6205 /* UnboundScopeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 671D5D89472DAFA916814506 /* UnboundScopeSpec.swift */; }; F37DA7FC70E254616DBD1BD7 /* ReferenceMakerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 388605A438343F7BB80D521E /* ReferenceMakerSpec.swift */; }; F39521855B858534A8D53C8F /* Closable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D0BCCCD61CD9BECC29E064 /* Closable.swift */; }; F504C2ABEFCFFCAC8B858751 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; @@ -508,7 +512,6 @@ 61EE5DDBE705B47AFC9A6986 /* LoadAwareAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadAwareAssembly.swift; sourceTree = ""; }; 62682D6ED38742996624B041 /* BasicAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BasicAssembly.swift; sourceTree = ""; }; 65D0BCCCD61CD9BECC29E064 /* Closable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Closable.swift; sourceTree = ""; }; - 671D5D89472DAFA916814506 /* UnboundScopeSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnboundScopeSpec.swift; sourceTree = ""; }; 683A1FB7D7F4E9508D57E936 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceWrapper.swift; sourceTree = ""; }; 6D434EB4C13CF9D9FA6D80CB /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -552,6 +555,8 @@ C765B92B00C0AC8625BB4AC9 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; CADDB3E9E363310028AA5920 /* InstanceMaker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceMaker.swift; sourceTree = ""; }; CC85CB215058F95C0BC190B1 /* Bridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bridge.swift; sourceTree = ""; }; + CD77892122ECF8F100560AB7 /* ModulesSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModulesSpec.swift; sourceTree = ""; }; + CD77892722ECF9C700560AB7 /* ScopesSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopesSpec.swift; sourceTree = ""; }; CD92116322ECC05600211BF0 /* LinuxConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinuxConfig.swift; sourceTree = ""; }; CDA78290D6D60BD0B808571F /* Container+Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Logging.swift"; sourceTree = ""; }; CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; @@ -642,7 +647,6 @@ 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */, 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */, EDA62EEBC79ED2639C93A76B /* TypeBinderSpec.swift */, - 671D5D89472DAFA916814506 /* UnboundScopeSpec.swift */, ); path = "Unit Specs"; sourceTree = ""; @@ -768,6 +772,8 @@ isa = PBXGroup; children = ( C5FB515A9B4B929026438A90 /* SwinjectApiSpec.swift */, + CD77892122ECF8F100560AB7 /* ModulesSpec.swift */, + CD77892722ECF9C700560AB7 /* ScopesSpec.swift */, ); path = "3.0 API"; sourceTree = ""; @@ -1491,9 +1497,10 @@ F7CD04FB09FC7F18E9E001CF /* SynchronizedResolverSpec.swift in Sources */, 9AD60A86D5A0DF4513C1EA8D /* TaggedTypeSpec.swift in Sources */, 778D9AB6470D4280254AC140 /* TestModels.swift in Sources */, + CD77892822ECF9C700560AB7 /* ScopesSpec.swift in Sources */, + CD77892222ECF8F100560AB7 /* ModulesSpec.swift in Sources */, A6CAAC13E97BAE1168B7933F /* TypeBinderSpec.swift in Sources */, CD92116422ECC05600211BF0 /* LinuxConfig.swift in Sources */, - 922CDD2FF5974D1756D5A126 /* UnboundScopeSpec.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1535,9 +1542,10 @@ 3BDB44DE92D2377334894804 /* SynchronizedResolverSpec.swift in Sources */, A5302886A31C90F38512B88E /* TaggedTypeSpec.swift in Sources */, 2615FC1C92B7E381116B9E57 /* TestModels.swift in Sources */, + CD77892922ECF9C700560AB7 /* ScopesSpec.swift in Sources */, + CD77892322ECF8F100560AB7 /* ModulesSpec.swift in Sources */, CD92116522ECC05600211BF0 /* LinuxConfig.swift in Sources */, F050175A7FB08DE1F97DC11C /* TypeBinderSpec.swift in Sources */, - 9C4FEA520C7CB1ACBAC1B57B /* UnboundScopeSpec.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1579,9 +1587,10 @@ 546FF827DB6D42490D1CA439 /* SynchronizedResolverSpec.swift in Sources */, 09470890A74A5DDE7114891B /* TaggedTypeSpec.swift in Sources */, CB9E8D16D7A0620A1F7A32A3 /* TestModels.swift in Sources */, + CD77892B22ECF9C700560AB7 /* ScopesSpec.swift in Sources */, + CD77892522ECF8F100560AB7 /* ModulesSpec.swift in Sources */, 57FCCFC6C6747DAB2F141A52 /* TypeBinderSpec.swift in Sources */, CD92116722ECC05600211BF0 /* LinuxConfig.swift in Sources */, - F2857EAA276179402A5E6205 /* UnboundScopeSpec.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1623,9 +1632,10 @@ 890CCD2800597F6FB7C6FD31 /* SynchronizedResolverSpec.swift in Sources */, 24114725AE1A834C6E3118F7 /* TaggedTypeSpec.swift in Sources */, 6034CF5459D96497AF36E4B6 /* TestModels.swift in Sources */, + CD77892A22ECF9C700560AB7 /* ScopesSpec.swift in Sources */, + CD77892422ECF8F100560AB7 /* ModulesSpec.swift in Sources */, 36F20E1EEAD43361A98713E0 /* TypeBinderSpec.swift in Sources */, CD92116622ECC05600211BF0 /* LinuxConfig.swift in Sources */, - C3212F88E16B0592070C4F35 /* UnboundScopeSpec.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Tests/3.0 API/ScopesSpec.swift b/Tests/3.0 API/ScopesSpec.swift new file mode 100644 index 00000000..4af3e7e6 --- /dev/null +++ b/Tests/3.0 API/ScopesSpec.swift @@ -0,0 +1,41 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +import Nimble +import Quick +import Swinject +@testable import class Swinject.UnboundScope + +class ScopesSpec: QuickSpec { override func spec() { #if swift(>=5.1) + it("can bind scoped singleton") { + let scope = UnboundScope() + let swinject = Swinject { + bbind(Human.self) & scoped(scope).singleton { Human() } + } + let first = try? swinject.instance() as Human + let second = try? swinject.instance() as Human + expect(first) === second + } + it("can close scopes") { + let scope = UnboundScope() + let swinject = Swinject { + bbind(Human.self) & scoped(scope).singleton { Human() } + } + let first = try? swinject.instance() as Human + scope.close() + let second = try? swinject.instance() as Human + expect(first) !== second + } + it("notifies instances when scope is closed") { + let scope = UnboundScope() + let swinject = Swinject { + bbind(ClosableMock.self) & scoped(scope).singleton { ClosableMock() } + } + let closable = try? swinject.instance() as ClosableMock + expect(closable?.closeCalled) == false + scope.close() + expect(closable?.closeCalled) == true + } + #endif +} } diff --git a/Tests/3.0 API/SwinjectApiSpec.swift b/Tests/3.0 API/SwinjectApiSpec.swift index 047821e6..ea85661b 100644 --- a/Tests/3.0 API/SwinjectApiSpec.swift +++ b/Tests/3.0 API/SwinjectApiSpec.swift @@ -149,34 +149,6 @@ class SwinjectApiSpec: QuickSpec { override func spec() { #if swift(>=5.1) let second = try? swinject.instance() as Human expect(first) === second } - it("can bind scoped singleton") { - let scope = UnboundScope() - let swinject = Swinject { - bbind(Human.self) & scoped(scope).singleton { Human() } - } - let first = try? swinject.instance() as Human - let second = try? swinject.instance() as Human - expect(first) === second - } - it("can close scopes") { - let scope = UnboundScope() - let swinject = Swinject { - bbind(Human.self) & scoped(scope).singleton { Human() } - } - let first = try? swinject.instance() as Human - scope.close() - let second = try? swinject.instance() as Human - expect(first) !== second - } - it("notifies instances when scope is closed") { - let scope = UnboundScope() - let swinject = Swinject { - bbind(ClosableMock.self) & scoped(scope).singleton { ClosableMock() } - } - let closable = try? swinject.instance() as ClosableMock - scope.close() - expect(closable?.closeCalled) == true - } it("can bind weakly referenced singleton") { let swinject = Swinject { bbind(Human.self) & singleton(ref: weakRef) { Human() } diff --git a/Tests/LinuxConfig.swift b/Tests/LinuxConfig.swift index 3ae44e5a..f46ee5fe 100644 --- a/Tests/LinuxConfig.swift +++ b/Tests/LinuxConfig.swift @@ -18,7 +18,8 @@ let allSpecs: [QuickSpec.Type] = [ SynchronizedResolverSpec.self, // 3.0 Api SwinjectApiSpec.self, - ModulesSpec.self + ModulesSpec.self, + ScopesSpec.self, // Unit Specs BinderEnvironmentSpec.self, BindingKeySpec.self, @@ -31,5 +32,4 @@ let allSpecs: [QuickSpec.Type] = [ SwinjectTreeBuilderSpec.self, TaggedTypeSpec.self, TypeBinderSpec.self, - UnboundScopeSpec.self, ] diff --git a/Tests/Unit Specs/UnboundScopeSpec.swift b/Tests/Unit Specs/UnboundScopeSpec.swift deleted file mode 100644 index bd3a9851..00000000 --- a/Tests/Unit Specs/UnboundScopeSpec.swift +++ /dev/null @@ -1,33 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -import Nimble -import Quick -@testable import Swinject - -class UnboundScopeSpec: QuickSpec { override func spec() { - var registry = StaticScopeRegistryMock() - var scope: UnboundScope! - beforeEach { - registry = StaticScopeRegistryMock() - scope = UnboundScope(registry: registry) - } - describe("registry") { - it("returns passed registry") { - expect(scope.registry(for: 0)) === registry - } - it("uses standard registry by default") { - expect(UnboundScope().registry(for: 0) is StandardScopeRegistry) == true - } - } - describe("closable") { - it("clears passed registry when closed") { - scope.close() - expect(registry.clearCallsCount) == 1 - } - it("does not clear registry until closed") { - expect(registry.clearCallsCount) == 0 - } - } -} } From b18716aad510c4f50e3bbd31b8f327d8d7eea117 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 28 Jul 2019 00:43:17 +0200 Subject: [PATCH 157/239] Separate binding & optional tests --- Sources/3.0 API/TypeBinder.swift | 7 ---- Sources/Core/Swinject.swift | 8 ++-- Swinject.xcodeproj/project.pbxproj | 30 +++++++++----- Tests/3.0 API/BindingSpec.swift | 49 +++++++++++++++++++++++ Tests/3.0 API/OptionalsSpec.swift | 40 +++++++++++++++++++ Tests/3.0 API/SwinjectApiSpec.swift | 47 ---------------------- Tests/LinuxConfig.swift | 3 +- Tests/Support/Bridge.swift | 4 -- Tests/Unit Specs/SwinjectSpec.swift | 14 ------- Tests/Unit Specs/TaggedTypeSpec.swift | 27 ------------- Tests/Unit Specs/TypeBinderSpec.swift | 57 --------------------------- 11 files changed, 116 insertions(+), 170 deletions(-) create mode 100644 Tests/3.0 API/BindingSpec.swift create mode 100644 Tests/3.0 API/OptionalsSpec.swift delete mode 100644 Tests/Unit Specs/TypeBinderSpec.swift diff --git a/Sources/3.0 API/TypeBinder.swift b/Sources/3.0 API/TypeBinder.swift index f52fe822..d177f6a1 100644 --- a/Sources/3.0 API/TypeBinder.swift +++ b/Sources/3.0 API/TypeBinder.swift @@ -14,13 +14,6 @@ public func bind(_: Type.Type, tagged tag: Tag) -> TypeBinder(), e.g.: -// bind(CustomStringConvertible.self).with(provider { 42 }) -public func bind(descriptor: Descriptor) -> TypeBinder where Descriptor: TypeDescriptor { - return TypeBinder(descriptor: descriptor) -} - public extension TypeBinder { func with(_ maker: Maker) -> Binding where Maker: BindingMaker, Maker.BoundType == Descriptor.BaseType { return maker.makeBinding(for: descriptor) diff --git a/Sources/Core/Swinject.swift b/Sources/Core/Swinject.swift index 335b6f75..54d2a4ff 100644 --- a/Sources/Core/Swinject.swift +++ b/Sources/Core/Swinject.swift @@ -28,10 +28,10 @@ extension Swinject: Resolver { public func resolve( _ request: InstanceRequest ) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { + var binding: Binding! + // FIXME: Refactor this do { - let binding = try findBinding(for: request) - let translator = try findTranslator(for: request, and: binding) - return try instance(from: binding, context: translator.translate(context), arg: request.argument) + binding = try findBinding(for: request) } catch let error as NoBindingError { if let optional = Descriptor.BaseType.self as? OptionalProtocol.Type { return optional.init() as! Descriptor.BaseType @@ -39,6 +39,8 @@ extension Swinject: Resolver { throw error } } + let translator = try findTranslator(for: request, and: binding) + return try instance(from: binding, context: translator.translate(context), arg: request.argument) } private func findTranslator(for request: AnyInstanceRequest, and binding: Binding) throws -> AnyContextTranslator { diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 5ef87229..d5a65a0f 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -70,7 +70,6 @@ 335CE53CEC2360DC86D58F07 /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61EE5DDBE705B47AFC9A6986 /* LoadAwareAssembly.swift */; }; 3575DE21531F7365B713B64B /* ScopedBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */; }; 36A706F87ED2E88F3390C6C2 /* ServiceEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38615FC8EEB466C5C1EAD21C /* ServiceEntry.swift */; }; - 36F20E1EEAD43361A98713E0 /* TypeBinderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDA62EEBC79ED2639C93A76B /* TypeBinderSpec.swift */; }; 372F0061E762BF8FFF05457F /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; 3753FB83A1FB4B83891AA5C8 /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BFF4BA99493C54260878C4 /* ObjectScope.swift */; }; 389C54E04DD794DA4F648571 /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */; }; @@ -109,7 +108,6 @@ 56B2AD6054B63420DD025EC6 /* NonGeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841D83ADB41363D1E38087B4 /* NonGeneratedMocks.swift */; }; 56D43738C09AA7355F6D529D /* BinderEnvironmentSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */; }; 57BFBA2077E70DC1C2FE796C /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */; }; - 57FCCFC6C6747DAB2F141A52 /* TypeBinderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDA62EEBC79ED2639C93A76B /* TypeBinderSpec.swift */; }; 58ABEE0321A3061048B65EA2 /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42490D1D0C395951243F5CFF /* Container.swift */; }; 590B861A863A056A0B7FA368 /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADA1541ABC1365DFD7E3377F /* Food.swift */; }; 593B93BA2EE3FE4418A1C579 /* ScopeRegistryKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */; }; @@ -210,7 +208,6 @@ A59C6C434288333EDAF951C4 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */; }; A5A7F3C866C17F071C5D976C /* BindingKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */; }; A5E4C79F89E1A8AB3A4D8D6E /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59A3946B59EB4D787CCE9F2 /* Container+Registration.swift */; }; - A6CAAC13E97BAE1168B7933F /* TypeBinderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDA62EEBC79ED2639C93A76B /* TypeBinderSpec.swift */; }; A6EECC339FA54CA0BBFF4146 /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BC5108ED11A3A3084D864CC /* Animal.swift */; }; A70936B898139A6C5F83F616 /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; A75BAA10EC6F738EBC2C5BE8 /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */; }; @@ -281,6 +278,14 @@ CD77892922ECF9C700560AB7 /* ScopesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD77892722ECF9C700560AB7 /* ScopesSpec.swift */; }; CD77892A22ECF9C700560AB7 /* ScopesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD77892722ECF9C700560AB7 /* ScopesSpec.swift */; }; CD77892B22ECF9C700560AB7 /* ScopesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD77892722ECF9C700560AB7 /* ScopesSpec.swift */; }; + CD77892D22ED009C00560AB7 /* BindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD77892C22ED009C00560AB7 /* BindingSpec.swift */; }; + CD77892E22ED009C00560AB7 /* BindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD77892C22ED009C00560AB7 /* BindingSpec.swift */; }; + CD77892F22ED009C00560AB7 /* BindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD77892C22ED009C00560AB7 /* BindingSpec.swift */; }; + CD77893022ED009C00560AB7 /* BindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD77892C22ED009C00560AB7 /* BindingSpec.swift */; }; + CD77893222ED05C500560AB7 /* OptionalsSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD77893122ED05C500560AB7 /* OptionalsSpec.swift */; }; + CD77893322ED05C500560AB7 /* OptionalsSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD77893122ED05C500560AB7 /* OptionalsSpec.swift */; }; + CD77893422ED05C500560AB7 /* OptionalsSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD77893122ED05C500560AB7 /* OptionalsSpec.swift */; }; + CD77893522ED05C500560AB7 /* OptionalsSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD77893122ED05C500560AB7 /* OptionalsSpec.swift */; }; CD92116422ECC05600211BF0 /* LinuxConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD92116322ECC05600211BF0 /* LinuxConfig.swift */; }; CD92116522ECC05600211BF0 /* LinuxConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD92116322ECC05600211BF0 /* LinuxConfig.swift */; }; CD92116622ECC05600211BF0 /* LinuxConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD92116322ECC05600211BF0 /* LinuxConfig.swift */; }; @@ -331,7 +336,6 @@ EEAD7E215908DF939ECCDCC9 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; EF79F0B3D497215D4BBBC038 /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92B8E618A08408404FB2A7A /* TypeBinder.swift */; }; EFD2F695B86E74C77F46B7D1 /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; - F050175A7FB08DE1F97DC11C /* TypeBinderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDA62EEBC79ED2639C93A76B /* TypeBinderSpec.swift */; }; F06DEB671A4B85ABB0E96E51 /* ContextTranslator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */; }; F270DC6FF3901F58C76F3872 /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; F37DA7FC70E254616DBD1BD7 /* ReferenceMakerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 388605A438343F7BB80D521E /* ReferenceMakerSpec.swift */; }; @@ -557,12 +561,13 @@ CC85CB215058F95C0BC190B1 /* Bridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bridge.swift; sourceTree = ""; }; CD77892122ECF8F100560AB7 /* ModulesSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModulesSpec.swift; sourceTree = ""; }; CD77892722ECF9C700560AB7 /* ScopesSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopesSpec.swift; sourceTree = ""; }; + CD77892C22ED009C00560AB7 /* BindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingSpec.swift; sourceTree = ""; }; + CD77893122ED05C500560AB7 /* OptionalsSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OptionalsSpec.swift; sourceTree = ""; }; CD92116322ECC05600211BF0 /* LinuxConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinuxConfig.swift; sourceTree = ""; }; CDA78290D6D60BD0B808571F /* Container+Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Logging.swift"; sourceTree = ""; }; CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRequest.swift; sourceTree = ""; }; E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; - EDA62EEBC79ED2639C93A76B /* TypeBinderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinderSpec.swift; sourceTree = ""; }; F290F6B1207A0557A528220B /* Assembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Assembly.swift; sourceTree = ""; }; F446D6BD4C44E16A1D608BFB /* Container+TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+TypeForwarding.swift"; sourceTree = ""; }; F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.TypeForwarding.swift; sourceTree = ""; }; @@ -646,7 +651,6 @@ 9527A4CA5BCBA7AFA3596757 /* SwinjectSpec.swift */, 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */, 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */, - EDA62EEBC79ED2639C93A76B /* TypeBinderSpec.swift */, ); path = "Unit Specs"; sourceTree = ""; @@ -772,6 +776,8 @@ isa = PBXGroup; children = ( C5FB515A9B4B929026438A90 /* SwinjectApiSpec.swift */, + CD77892C22ED009C00560AB7 /* BindingSpec.swift */, + CD77893122ED05C500560AB7 /* OptionalsSpec.swift */, CD77892122ECF8F100560AB7 /* ModulesSpec.swift */, CD77892722ECF9C700560AB7 /* ScopesSpec.swift */, ); @@ -1466,6 +1472,7 @@ BD08D3E155AFD841CFECA0AD /* Animal.swift in Sources */, 02410BD4FB357F4C6B521608 /* AssemblerSpec.swift in Sources */, DD29D2E60DA979D61F32A39A /* BasicAssembly.swift in Sources */, + CD77893222ED05C500560AB7 /* OptionalsSpec.swift in Sources */, 3129A37CDC1653C11800E24A /* BehaviorFakes.swift in Sources */, 216D6360147B43F5F47C9EA2 /* BinderEnvironmentSpec.swift in Sources */, 0BCA618354F1B2867A7FB261 /* BindingKeySpec.swift in Sources */, @@ -1483,6 +1490,7 @@ 9A8164D6696C87BFEC7325C3 /* GeneratedMocks.swift in Sources */, AE6EAB8CC32ED5E1789D55B7 /* LazySpec.swift in Sources */, B0B139FADA6AE07C79847EBA /* LoadAwareAssembly.swift in Sources */, + CD77892D22ED009C00560AB7 /* BindingSpec.swift in Sources */, 2C1BD6D785E310B6F8A3CAC9 /* NonGeneratedMocks.swift in Sources */, 628EBFBA0031B1FA2E29F583 /* Person.swift in Sources */, 708E1C453CBC76ED26FA2FCB /* ProviderSpec.swift in Sources */, @@ -1499,7 +1507,6 @@ 778D9AB6470D4280254AC140 /* TestModels.swift in Sources */, CD77892822ECF9C700560AB7 /* ScopesSpec.swift in Sources */, CD77892222ECF8F100560AB7 /* ModulesSpec.swift in Sources */, - A6CAAC13E97BAE1168B7933F /* TypeBinderSpec.swift in Sources */, CD92116422ECC05600211BF0 /* LinuxConfig.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1511,6 +1518,7 @@ A6EECC339FA54CA0BBFF4146 /* Animal.swift in Sources */, CBBE28990E0EA82AD8D5E3AF /* AssemblerSpec.swift in Sources */, 401592294E5D528379BE1AB2 /* BasicAssembly.swift in Sources */, + CD77893322ED05C500560AB7 /* OptionalsSpec.swift in Sources */, A3BFFED76688F149FBAF7C53 /* BehaviorFakes.swift in Sources */, 56D43738C09AA7355F6D529D /* BinderEnvironmentSpec.swift in Sources */, 6203E6494C12ECE21323F512 /* BindingKeySpec.swift in Sources */, @@ -1528,6 +1536,7 @@ 9C12EB42EC058994805E93A6 /* GeneratedMocks.swift in Sources */, 979518E078B187549E11DF48 /* LazySpec.swift in Sources */, 335CE53CEC2360DC86D58F07 /* LoadAwareAssembly.swift in Sources */, + CD77892E22ED009C00560AB7 /* BindingSpec.swift in Sources */, 56B2AD6054B63420DD025EC6 /* NonGeneratedMocks.swift in Sources */, EB3420214A9E68A0247D0F2C /* Person.swift in Sources */, CF9535A0DCAFF23F4D62F871 /* ProviderSpec.swift in Sources */, @@ -1545,7 +1554,6 @@ CD77892922ECF9C700560AB7 /* ScopesSpec.swift in Sources */, CD77892322ECF8F100560AB7 /* ModulesSpec.swift in Sources */, CD92116522ECC05600211BF0 /* LinuxConfig.swift in Sources */, - F050175A7FB08DE1F97DC11C /* TypeBinderSpec.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1556,6 +1564,7 @@ A53B5A8E2188F8C4A3F29C2E /* Animal.swift in Sources */, CF4516872D3DA7118DB2B90B /* AssemblerSpec.swift in Sources */, 03122D1B2EA65C89ADC78EC7 /* BasicAssembly.swift in Sources */, + CD77893522ED05C500560AB7 /* OptionalsSpec.swift in Sources */, 1CA5DF3F93203B226A6FA059 /* BehaviorFakes.swift in Sources */, 3F704A98C01C84BDBD0A52B3 /* BinderEnvironmentSpec.swift in Sources */, 1927B730A0F0E141BFC1773E /* BindingKeySpec.swift in Sources */, @@ -1573,6 +1582,7 @@ CB06DC3BC4A32776BBD90DDF /* GeneratedMocks.swift in Sources */, 6A0FD11468B3852E48B682BE /* LazySpec.swift in Sources */, ED6CB3935B15F30A182ED6D0 /* LoadAwareAssembly.swift in Sources */, + CD77893022ED009C00560AB7 /* BindingSpec.swift in Sources */, 7AE3FF1C0B4860942D90B68B /* NonGeneratedMocks.swift in Sources */, C76374CAFE7C2BCCE52F1BB1 /* Person.swift in Sources */, 4954CBB07E38E98752AC3347 /* ProviderSpec.swift in Sources */, @@ -1589,7 +1599,6 @@ CB9E8D16D7A0620A1F7A32A3 /* TestModels.swift in Sources */, CD77892B22ECF9C700560AB7 /* ScopesSpec.swift in Sources */, CD77892522ECF8F100560AB7 /* ModulesSpec.swift in Sources */, - 57FCCFC6C6747DAB2F141A52 /* TypeBinderSpec.swift in Sources */, CD92116722ECC05600211BF0 /* LinuxConfig.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1601,6 +1610,7 @@ D13208E63523A97A0B840283 /* Animal.swift in Sources */, 2AA60B7E6EBA9EC6BE92D7CB /* AssemblerSpec.swift in Sources */, 599C7F009F954CDA522244B3 /* BasicAssembly.swift in Sources */, + CD77893422ED05C500560AB7 /* OptionalsSpec.swift in Sources */, 8E1E051646BBD6E38F4199C2 /* BehaviorFakes.swift in Sources */, 4A977D2B639B8098AA508389 /* BinderEnvironmentSpec.swift in Sources */, A5A7F3C866C17F071C5D976C /* BindingKeySpec.swift in Sources */, @@ -1618,6 +1628,7 @@ B703A24C1A963C6BAC95B9A5 /* GeneratedMocks.swift in Sources */, 0CD787EACEBFD1051D358E7D /* LazySpec.swift in Sources */, A2D3B18BE38948A427B60BC5 /* LoadAwareAssembly.swift in Sources */, + CD77892F22ED009C00560AB7 /* BindingSpec.swift in Sources */, C4E9DC50A2FDAE4D36A925D9 /* NonGeneratedMocks.swift in Sources */, BEEFBE87EB17D56BA8D47358 /* Person.swift in Sources */, 48F40377D116C6B1B786C329 /* ProviderSpec.swift in Sources */, @@ -1634,7 +1645,6 @@ 6034CF5459D96497AF36E4B6 /* TestModels.swift in Sources */, CD77892A22ECF9C700560AB7 /* ScopesSpec.swift in Sources */, CD77892422ECF8F100560AB7 /* ModulesSpec.swift in Sources */, - 36F20E1EEAD43361A98713E0 /* TypeBinderSpec.swift in Sources */, CD92116622ECC05600211BF0 /* LinuxConfig.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Tests/3.0 API/BindingSpec.swift b/Tests/3.0 API/BindingSpec.swift new file mode 100644 index 00000000..10d15d89 --- /dev/null +++ b/Tests/3.0 API/BindingSpec.swift @@ -0,0 +1,49 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +import Nimble +import Quick +import Swinject + +class BindingSpec: QuickSpec { override func spec() { #if swift(>=5.1) + it("can define a binding for a type") { + let swinject = Swinject { + bbind(Int.self).with(42) + bbind(Double.self) & 42.0 + } + expect { try swinject.instance() as Int } == 42 + expect { try swinject.instance() as Double } == 42 + } + it("does not allow multiple bindings for the same type") { + let swinject = Swinject { + bbind(Int.self).with(42) + bbind(Int.self) & 27 + } + expect { try swinject.instance() as Int }.to(throwError()) + } + it("can bind the same type with different tags") { + let swinject = Swinject { + bbind(String.self) & "Plain" + bbind(String.self, tagged: "Tag") & "Tagged" + bbind(String.self, tagged: 42) & "42" + } + expect { try swinject.instance(of: String.self) } == "Plain" + expect { try swinject.instance(of: String.self, tagged: "Tag") } == "Tagged" + expect { try swinject.instance(of: String.self, tagged: 42) } == "42" + } + it("throws if has no binding with given tag") { + let swinject = Swinject { + bbind(String.self) & "Plain" + bbind(String.self, tagged: "Tag") & "Tagged" + } + expect { try swinject.instance(of: String.self, tagged: "WrongTag") }.to(throwError()) + } + it("can bind a protocol to it's implementation") { + let swinject = Swinject { + bbind(Mammal.self).with(provider { Human() }) + } + expect(try? swinject.instance(of: Mammal.self) is Human) == true + } + #endif +} } diff --git a/Tests/3.0 API/OptionalsSpec.swift b/Tests/3.0 API/OptionalsSpec.swift new file mode 100644 index 00000000..f829f517 --- /dev/null +++ b/Tests/3.0 API/OptionalsSpec.swift @@ -0,0 +1,40 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +import Nimble +import Quick +import Swinject + +class OptionalsSpec: QuickSpec { override func spec() { #if swift(>=5.1) + it("can use a binding for bound type's optional") { + let swinject = Swinject { + bbind(Int.self) & 42 + } + expect { try swinject.instance() as Int? } == 42 + } + it("can use a binding for bound type's double optional") { + let swinject = Swinject { + bbind(Int.self) & 42 + } + expect { try swinject.instance() as Int?? } == 42 + } + it("does not throw if injecting optional for an unbound type") { + let swinject = Swinject {} + expect { try swinject.instance() as Int? }.notTo(throwError()) + } + it("throws if has an incomplete binding for the optional") { + let swinject = Swinject { + bbind(Int.self) & provider { Int(try $0.instance() as Double) } + } + expect { try swinject.instance() as Int? }.to(throwError()) + } + it("throws if has multiple bindings for optional") { + let swinject = Swinject { + bbind(Int.self) & 42 + bbind(Int.self) & 25 + } + expect { try swinject.instance() as Int? }.to(throwError()) + } + #endif +} } diff --git a/Tests/3.0 API/SwinjectApiSpec.swift b/Tests/3.0 API/SwinjectApiSpec.swift index ea85661b..0898e0a2 100644 --- a/Tests/3.0 API/SwinjectApiSpec.swift +++ b/Tests/3.0 API/SwinjectApiSpec.swift @@ -13,18 +13,6 @@ class SwinjectApiSpec: QuickSpec { override func spec() { #if swift(>=5.1) UnboundScope.root.close() human = Human() } - it("returns instance if is bound") { - let swinject = Swinject { - bbind(Int.self).with(42) - } - expect { try swinject.instance(of: Int.self) } == 42 - } - it("can infer the requested type") { - let swinject = Swinject { - bbind(Int.self) & 42 - } - expect { try swinject.instance() as Int } == 42 - } it("throws if providing type with missing dependency") { let swinject = Swinject { bbind(Pet.self) & provider { Pet(owner: try $0.instance()) } @@ -38,41 +26,6 @@ class SwinjectApiSpec: QuickSpec { override func spec() { #if swift(>=5.1) } expect { try swinject.instance(of: Pet.self).owner } === human } - it("throws if has multiple bindings for the same request") { - let swinject = Swinject { - bbind(Int.self) & 42 - bbind(Int.self) & provider { 17 + 25 } - } - expect { try swinject.instance(of: Int.self) }.to(throwError()) - } - it("throws if requesting instance with wrong tag") { - let swinject = Swinject { - bbind(Int.self, tagged: "Tag") & 42 - } - expect { try swinject.instance(of: Int.self) }.to(throwError()) - expect { try swinject.instance(of: Int.self, tagged: 42) }.to(throwError()) - expect { try swinject.instance(of: Int.self, tagged: "OtherTag") }.to(throwError()) - } - it("returns instance with correct tag") { - let swinject = Swinject { - bbind(String.self) & "Plain" - bbind(String.self, tagged: "Tag") & "Tagged" - } - expect { try swinject.instance(of: String.self) } == "Plain" - expect { try swinject.instance(of: String.self, tagged: "Tag") } == "Tagged" - } - it("can bind protocol to implementation") { - let swinject = Swinject { - bbind(Mammal.self).with(provider { Human() }) - } - expect(try? swinject.instance(of: Mammal.self) is Human) == true - } - it("can inject optionals") { - let swinject = Swinject { - bbind(Int.self) & 42 - } - expect { try swinject.instance() as Int? } == 42 - } it("can inject instance provider") { let swinject = Swinject { bbind(Int.self, tagged: "tag") & 42 diff --git a/Tests/LinuxConfig.swift b/Tests/LinuxConfig.swift index f46ee5fe..59f74572 100644 --- a/Tests/LinuxConfig.swift +++ b/Tests/LinuxConfig.swift @@ -18,8 +18,10 @@ let allSpecs: [QuickSpec.Type] = [ SynchronizedResolverSpec.self, // 3.0 Api SwinjectApiSpec.self, + BindingSpec.self, ModulesSpec.self, ScopesSpec.self, + OptionalsSpec.self, // Unit Specs BinderEnvironmentSpec.self, BindingKeySpec.self, @@ -31,5 +33,4 @@ let allSpecs: [QuickSpec.Type] = [ SwinjectSpec.self, SwinjectTreeBuilderSpec.self, TaggedTypeSpec.self, - TypeBinderSpec.self, ] diff --git a/Tests/Support/Bridge.swift b/Tests/Support/Bridge.swift index 421e7013..964a0669 100644 --- a/Tests/Support/Bridge.swift +++ b/Tests/Support/Bridge.swift @@ -15,7 +15,3 @@ func bbind(_: Type.Type) -> TypeBinder> { func bbind(_: Type.Type, tagged tag: Tag) -> TypeBinder> where Tag: Hashable { return bind(Type.self, tagged: tag) } - -func bbind(descriptor: Descriptor) -> TypeBinder where Descriptor: TypeDescriptor { - return bind(descriptor: descriptor) -} diff --git a/Tests/Unit Specs/SwinjectSpec.swift b/Tests/Unit Specs/SwinjectSpec.swift index fb8f39e8..028da653 100644 --- a/Tests/Unit Specs/SwinjectSpec.swift +++ b/Tests/Unit Specs/SwinjectSpec.swift @@ -72,15 +72,6 @@ class SwinjectSpec: QuickSpec { override func spec() { _ = try? swinject.on("context").instance() as Int expect(binding.matchesReceivedKey?.contextType is String.Type).to(beTrue()) } - it("does not throw if has no binding for optional") { - binding.matchesReturnValue = false - expect { try swinject.instance() as Int? }.notTo(throwError()) - } - it("throws if has throwing binding for optional") { - binding.matchesReturnValue = true - binding.instanceArgContextResolverThrowableError = TestError() - expect { try swinject.instance() as Int? }.to(throwError()) - } } context("multiple bindings") { var bindings = [BindingMock]() @@ -109,11 +100,6 @@ class SwinjectSpec: QuickSpec { override func spec() { bindings[1].instanceArgContextResolverReturnValue = 42 expect { try swinject.instance(of: Int.self) } == 42 } - it("throws if has multiple bindings for optional") { - bindings[0].matchesReturnValue = true - bindings[1].matchesReturnValue = true - expect { try swinject.instance() as Int? }.to(throwError()) - } } } describe("provider injection") { diff --git a/Tests/Unit Specs/TaggedTypeSpec.swift b/Tests/Unit Specs/TaggedTypeSpec.swift index 0cbfafca..680e4b91 100644 --- a/Tests/Unit Specs/TaggedTypeSpec.swift +++ b/Tests/Unit Specs/TaggedTypeSpec.swift @@ -34,31 +34,4 @@ class TaggedTypeSpec: QuickSpec { override func spec() { expect(first.hashValue) == second.hashValue } } - describe("matches") { - it("doesn't match if base type is different") { - let first = plain(Int.self) - let second = plain(String.self) - expect(first.matches(second)) == false - } - it("doesn't match if tag is different") { - let first = tagged(Int.self, with: "tag1") - let second = tagged(Int.self, with: "tag2") - expect(first.matches(second)) == false - } - it("matches if the same descriptor") { - let first = tagged(Int.self, with: "tag1") - let second = tagged(Int.self, with: "tag1") - expect(first.matches(second)) == true - } - it("matches if second type is optional of first type") { - let first = plain(Int.self) - let second = plain(Int?.self) - expect(first.matches(second)) == true - } - it("matches if second type is double optional of first type") { - let first = plain(Int.self) - let second = plain(Int??.self) - expect(first.matches(second)) == true - } - } } } diff --git a/Tests/Unit Specs/TypeBinderSpec.swift b/Tests/Unit Specs/TypeBinderSpec.swift deleted file mode 100644 index c0145b6a..00000000 --- a/Tests/Unit Specs/TypeBinderSpec.swift +++ /dev/null @@ -1,57 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -import Nimble -import Quick -@testable import Swinject - -class TypeBinderSpec: QuickSpec { override func spec() { - var descriptor = AnyTypeDescriptorMock() - var maker = BindingMakerMock() - beforeEach { - descriptor = AnyTypeDescriptorMock() - maker = BindingMakerMock() - maker.makeBindingForReturnValue = BindingMock() - } - describe("bind") { - it("descriptor has correct tag for tagged type") { - let descriptor = bbind(Int.self, tagged: "Foo").descriptor.actual as? Tagged - expect(descriptor?.tag) == "Foo" - } - it("descriptor is used if given as parameter") { - let request = bbind(descriptor: descriptor) - expect(request.descriptor) === descriptor - } - } - describe("`with` method") { - it("passes descriptor to maker") { - _ = bbind(descriptor: descriptor).with(maker) - expect(maker.makeBindingForReceivedDescriptor) === descriptor - } - it("returns binding from maker") { - let binding = BindingMock() - maker.makeBindingForReturnValue = binding - expect(bbind(descriptor: descriptor).with(maker)) === binding - } - it("works with passing instance directly") { - let binding = bbind(descriptor: descriptor).with(42) - expect { try binding.instance(arg: (), context: (), resolver: DummyResolver()) as? Int } == 42 - } - } - describe("`&` method") { - it("passes descriptor to maker") { - _ = bbind(descriptor: descriptor) & maker - expect(maker.makeBindingForReceivedDescriptor) === descriptor - } - it("returns binding from maker") { - let binding = BindingMock() - maker.makeBindingForReturnValue = binding - expect(bbind(descriptor: descriptor) & maker) === binding - } - it("works with passing instance directly") { - let binding = bbind(descriptor: descriptor) & 42 - expect { try binding.instance(arg: (), context: (), resolver: DummyResolver()) as? Int } == 42 - } - } -} } From 353ad19ab7b8df046d5083752e891e57f11b197f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 28 Jul 2019 09:17:36 +0200 Subject: [PATCH 158/239] Fix assertion tests --- .travis.yml | 12 ++++++------ Tests/3.0 API/ModulesSpec.swift | 4 ++-- Tests/Support/Convenience.swift | 10 ++++++++++ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3b424ed3..d78e1797 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,15 +21,15 @@ matrix: before_install: script: - pod lib lint - - env: JOB="XCODE" DEST="OS=10.0,name=iPhone 6" SCHEME="Swinject-iOS" SDK="iphonesimulator" ACTION="test" PLATFORM="iOS" + - env: JOB="XCODE" DEST="OS=10.0,name=iPhone 6" SCHEME="Swinject-iOS" SDK="iphonesimulator" ACTION="test" PLATFORM="iOS" CONFIG="Release" osx_image: xcode10.2 - - env: JOB="XCODE" DEST="arch=x86_64" SCHEME="Swinject-macOS" SDK="macosx" ACTION="test" PLATFORM="OSX" + - env: JOB="XCODE" DEST="arch=x86_64" SCHEME="Swinject-macOS" SDK="macosx" ACTION="test" PLATFORM="OSX" CONFIG="Release" osx_image: xcode10.2 - - env: JOB="XCODE" DEST="arch=x86_64" SCHEME="Swinject-macOS" SDK="macosx" ACTION="test" PLATFORM="OSX" + - env: JOB="XCODE" DEST="arch=x86_64" SCHEME="Swinject-macOS" SDK="macosx" ACTION="test" PLATFORM="OSX" CONFIG="Release" osx_image: xcode11 - - env: JOB="XCODE" DEST="OS=10.0,name=Apple TV 1080p" SCHEME="Swinject-tvOS" SDK="appletvsimulator" ACTION="test" PLATFORM="tvOS" + - env: JOB="XCODE" DEST="OS=10.0,name=Apple TV 1080p" SCHEME="Swinject-tvOS" SDK="appletvsimulator" ACTION="test" PLATFORM="tvOS" CONFIG="Debug" osx_image: xcode10.2 - - env: JOB="XCODE" DEST="OS=2.2,name=Apple Watch - 42mm" SCHEME="Swinject-watchOS" SDK="watchsimulator" ACTION="build" PLATFORM="watchOS" + - env: JOB="XCODE" DEST="OS=2.2,name=Apple Watch - 42mm" SCHEME="Swinject-watchOS" SDK="watchsimulator" ACTION="build" PLATFORM="watchOS" CONFIG="Release" osx_image: xcode10.2 before_install: @@ -39,7 +39,7 @@ before_install: - carthage bootstrap --verbose --platform $PLATFORM script: - set -o pipefail - - xcodebuild "$ACTION" -project "$PROJECT" -scheme "$SCHEME" -sdk "$SDK" -destination "$DEST" -configuration Release ENABLE_TESTABILITY=YES | xcpretty + - xcodebuild "$ACTION" -project "$PROJECT" -scheme "$SCHEME" -sdk "$SDK" -destination "$DEST" -configuration "$CONFIG" ENABLE_TESTABILITY=YES | xcpretty notifications: email: on_success: never diff --git a/Tests/3.0 API/ModulesSpec.swift b/Tests/3.0 API/ModulesSpec.swift index e5dbceb1..e2c7d9c5 100644 --- a/Tests/3.0 API/ModulesSpec.swift +++ b/Tests/3.0 API/ModulesSpec.swift @@ -43,7 +43,7 @@ class ModulesSpec: QuickSpec { override func spec() { #if swift(>=5.1) include(firstModule) include(secondModule) } - }.to(throwAssertion()) + }.ifDebugTo(throwAssertion()) } it("fails if module is included multiple times") { let firstModule = Swinject.Module("first") @@ -58,7 +58,7 @@ class ModulesSpec: QuickSpec { override func spec() { #if swift(>=5.1) include(secondModule) include(thirdModule) } - }.to(throwAssertion()) + }.ifDebugTo(throwAssertion()) } #endif } } diff --git a/Tests/Support/Convenience.swift b/Tests/Support/Convenience.swift index 87ec40f7..a20645ee 100644 --- a/Tests/Support/Convenience.swift +++ b/Tests/Support/Convenience.swift @@ -24,3 +24,13 @@ extension Matchable { return hasher.finalize() } } + +extension Expectation { + public func ifDebugTo(_ predicate: Predicate, description: String? = nil) { + #if DEBUG + to(predicate, description: description) + #else + toNot(predicate, description: description) + #endif + } +} From 733b30014d3c2464b6c8362037e85af0a48fd658 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 28 Jul 2019 10:46:15 +0200 Subject: [PATCH 159/239] Replace injection unit tests with api spec --- Swinject.xcodeproj/project.pbxproj | 10 ++ Tests/3.0 API/InjectionSpec.swift | 109 ++++++++++++++++ Tests/3.0 API/SwinjectApiSpec.swift | 50 -------- Tests/LinuxConfig.swift | 1 + Tests/Support/TestModels.swift | 6 + Tests/Unit Specs/BindingKeySpec.swift | 27 +--- Tests/Unit Specs/SwinjectSpec.swift | 174 -------------------------- 7 files changed, 127 insertions(+), 250 deletions(-) create mode 100644 Tests/3.0 API/InjectionSpec.swift diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index d5a65a0f..08ef0958 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -270,6 +270,10 @@ CB9E8D16D7A0620A1F7A32A3 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; CBBE28990E0EA82AD8D5E3AF /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; CBE63031F33303F3E503CEF2 /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; + CD1BEB4F22ED8BDD009168AE /* InjectionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD1BEB4E22ED8BDD009168AE /* InjectionSpec.swift */; }; + CD1BEB5022ED8BDD009168AE /* InjectionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD1BEB4E22ED8BDD009168AE /* InjectionSpec.swift */; }; + CD1BEB5122ED8BDD009168AE /* InjectionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD1BEB4E22ED8BDD009168AE /* InjectionSpec.swift */; }; + CD1BEB5222ED8BDD009168AE /* InjectionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD1BEB4E22ED8BDD009168AE /* InjectionSpec.swift */; }; CD77892222ECF8F100560AB7 /* ModulesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD77892122ECF8F100560AB7 /* ModulesSpec.swift */; }; CD77892322ECF8F100560AB7 /* ModulesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD77892122ECF8F100560AB7 /* ModulesSpec.swift */; }; CD77892422ECF8F100560AB7 /* ModulesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD77892122ECF8F100560AB7 /* ModulesSpec.swift */; }; @@ -559,6 +563,7 @@ C765B92B00C0AC8625BB4AC9 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; CADDB3E9E363310028AA5920 /* InstanceMaker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceMaker.swift; sourceTree = ""; }; CC85CB215058F95C0BC190B1 /* Bridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bridge.swift; sourceTree = ""; }; + CD1BEB4E22ED8BDD009168AE /* InjectionSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InjectionSpec.swift; sourceTree = ""; }; CD77892122ECF8F100560AB7 /* ModulesSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModulesSpec.swift; sourceTree = ""; }; CD77892722ECF9C700560AB7 /* ScopesSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopesSpec.swift; sourceTree = ""; }; CD77892C22ED009C00560AB7 /* BindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingSpec.swift; sourceTree = ""; }; @@ -777,6 +782,7 @@ children = ( C5FB515A9B4B929026438A90 /* SwinjectApiSpec.swift */, CD77892C22ED009C00560AB7 /* BindingSpec.swift */, + CD1BEB4E22ED8BDD009168AE /* InjectionSpec.swift */, CD77893122ED05C500560AB7 /* OptionalsSpec.swift */, CD77892122ECF8F100560AB7 /* ModulesSpec.swift */, CD77892722ECF9C700560AB7 /* ScopesSpec.swift */, @@ -1489,6 +1495,7 @@ 180DB4397B4C05E26F819C85 /* Food.swift in Sources */, 9A8164D6696C87BFEC7325C3 /* GeneratedMocks.swift in Sources */, AE6EAB8CC32ED5E1789D55B7 /* LazySpec.swift in Sources */, + CD1BEB4F22ED8BDD009168AE /* InjectionSpec.swift in Sources */, B0B139FADA6AE07C79847EBA /* LoadAwareAssembly.swift in Sources */, CD77892D22ED009C00560AB7 /* BindingSpec.swift in Sources */, 2C1BD6D785E310B6F8A3CAC9 /* NonGeneratedMocks.swift in Sources */, @@ -1535,6 +1542,7 @@ 590B861A863A056A0B7FA368 /* Food.swift in Sources */, 9C12EB42EC058994805E93A6 /* GeneratedMocks.swift in Sources */, 979518E078B187549E11DF48 /* LazySpec.swift in Sources */, + CD1BEB5022ED8BDD009168AE /* InjectionSpec.swift in Sources */, 335CE53CEC2360DC86D58F07 /* LoadAwareAssembly.swift in Sources */, CD77892E22ED009C00560AB7 /* BindingSpec.swift in Sources */, 56B2AD6054B63420DD025EC6 /* NonGeneratedMocks.swift in Sources */, @@ -1581,6 +1589,7 @@ BE6C13A3492E3CFC08E231B0 /* Food.swift in Sources */, CB06DC3BC4A32776BBD90DDF /* GeneratedMocks.swift in Sources */, 6A0FD11468B3852E48B682BE /* LazySpec.swift in Sources */, + CD1BEB5222ED8BDD009168AE /* InjectionSpec.swift in Sources */, ED6CB3935B15F30A182ED6D0 /* LoadAwareAssembly.swift in Sources */, CD77893022ED009C00560AB7 /* BindingSpec.swift in Sources */, 7AE3FF1C0B4860942D90B68B /* NonGeneratedMocks.swift in Sources */, @@ -1627,6 +1636,7 @@ C38A2EBF4D1904E7D6989989 /* Food.swift in Sources */, B703A24C1A963C6BAC95B9A5 /* GeneratedMocks.swift in Sources */, 0CD787EACEBFD1051D358E7D /* LazySpec.swift in Sources */, + CD1BEB5122ED8BDD009168AE /* InjectionSpec.swift in Sources */, A2D3B18BE38948A427B60BC5 /* LoadAwareAssembly.swift in Sources */, CD77892F22ED009C00560AB7 /* BindingSpec.swift in Sources */, C4E9DC50A2FDAE4D36A925D9 /* NonGeneratedMocks.swift in Sources */, diff --git a/Tests/3.0 API/InjectionSpec.swift b/Tests/3.0 API/InjectionSpec.swift new file mode 100644 index 00000000..2d171d40 --- /dev/null +++ b/Tests/3.0 API/InjectionSpec.swift @@ -0,0 +1,109 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +import Nimble +import Quick +import Swinject + +class InjectionSpec: QuickSpec { override func spec() { #if swift(>=5.1) + describe("instance") { + it("throws if bound type has missing dependency") { + let swinject = Swinject { + bbind(Pet.self) & provider { Pet(owner: try $0.instance()) } + } + expect { try swinject.instance(of: Pet.self) }.to(throwError()) + } + it("injects instance if all dependencies are bound") { + let john = Human() + let swinject = Swinject { + bbind(Pet.self) & provider { Pet(owner: try $0.instance()) } + bbind(Human.self) & instance(john) + } + expect { try swinject.instance(of: Pet.self).owner } === john + } + it("throws if type's binding requires different arguments") { + let swinject = Swinject { + bbind(Int.self) & factory { (_, string: String) in Int(string)! } + } + expect { try swinject.instance() as Int }.to(throwError()) + expect { try swinject.instance(arg: 42.0) as Int }.to(throwError()) + } + } + describe("provider") { + it("can inject instance provider") { + let swinject = Swinject { + bbind(Int.self) & 42 + } + let intProvider = swinject.provider(of: Int.self) + expect { try intProvider() } == 42 + } + it("throws if provided type is not bound") { + let swinject = Swinject {} + let intProvider = swinject.provider(of: Int.self) + expect { try intProvider() }.to(throwError()) + } + it("throws if provided type has missing dependency") { + let swinject = Swinject { + bbind(Pet.self) & provider { Pet(owner: try $0.instance()) } + } + let petProvider = swinject.provider(of: Pet.self) + expect { try petProvider() }.to(throwError()) + } + it("throws if provided type's binding requires different arguments") { + let swinject = Swinject { + bbind(Int.self) & factory { (_, string: String) in Int(string)! } + } + expect { try swinject.provider(of: Int.self)() }.to(throwError()) + expect { try swinject.provider(of: Int.self, arg: 42.0)() }.to(throwError()) + } + } + describe("factory") { + it("can inject instance factory") { + let john = Human() + let swinject = Swinject { + bbind(Pet.self) & factory { try Pet(name: $1, owner: $0.instance()) } + bbind(Human.self) & john + } + + let petFactory = swinject.factory() as (String) throws -> Pet + let pet = try? petFactory("mimi") + + expect(pet?.owner) === john + expect(pet?.name) == "mimi" + } + it("throws if created type is not bound") { + let swinject = Swinject {} + let petFactory = swinject.factory() as (String) throws -> Pet + expect { try petFactory("mimi") }.to(throwError()) + } + it("throws if created type has missing dependency") { + let swinject = Swinject { + bbind(Pet.self) & factory { try Pet(name: $1, owner: $0.instance()) } + } + let petFactory = swinject.factory() as (String) throws -> Pet + expect { try petFactory("mimi") }.to(throwError()) + } + it("throws if created type's binding requires different arguments") { + let swinject = Swinject { + bbind(Pet.self) & factory { try Pet(name: $1, owner: $0.instance()) } + bbind(Human.self) & provider { Human() } + } + let petFactory = swinject.factory() as (Int) throws -> Pet + expect { try petFactory(42) }.to(throwError()) + } + it("can curry factory arguments") { + let swinject = Swinject { + bbind(Int.self) & factory { + Int($1 as Int) + Int($2 as Double) + Int($3 as String)! + } + } + expect { try swinject.factory()(11, 14.0, "17") as Int } == 42 + expect { try swinject.factory(arg: 11)(14.0, "17") as Int } == 42 + expect { try swinject.factory(arg: 11, 14.0)("17") as Int } == 42 + expect { try swinject.provider(arg: 11, 14.0, "17")() as Int } == 42 + expect { try swinject.instance(arg: 11, 14.0, "17") as Int } == 42 + } + } + #endif +} } diff --git a/Tests/3.0 API/SwinjectApiSpec.swift b/Tests/3.0 API/SwinjectApiSpec.swift index 0898e0a2..d5856820 100644 --- a/Tests/3.0 API/SwinjectApiSpec.swift +++ b/Tests/3.0 API/SwinjectApiSpec.swift @@ -8,58 +8,8 @@ import Swinject @testable import class Swinject.UnboundScope class SwinjectApiSpec: QuickSpec { override func spec() { #if swift(>=5.1) - var human = Human() beforeEach { UnboundScope.root.close() - human = Human() - } - it("throws if providing type with missing dependency") { - let swinject = Swinject { - bbind(Pet.self) & provider { Pet(owner: try $0.instance()) } - } - expect { try swinject.instance(of: Pet.self) }.to(throwError()) - } - it("returns instance if all dependencies are bound") { - let swinject = Swinject { - bbind(Pet.self) & provider { Pet(owner: try $0.instance()) } - bbind(Human.self) & instance(human) - } - expect { try swinject.instance(of: Pet.self).owner } === human - } - it("can inject instance provider") { - let swinject = Swinject { - bbind(Int.self, tagged: "tag") & 42 - } - let provider = swinject.provider(of: Int.self, tagged: "tag") - expect { try provider() } == 42 - } - it("can inject instance factory") { - // FIXME: compiler segfaults if declaring this factory inside function builder - let intFactory = factory { (r, arg: Int) in Int(try r.instance() as Double) + 5 * arg } - let swinject = Swinject { - bbind(Double.self) & 17.0 - bbind(Int.self) & intFactory - } - let factory = swinject.factory() as (Int) throws -> Int - expect { try factory(5) } == 42 - } - it("can inject factory binding as provider or instance") { - let swinject = Swinject { - bbind(Double.self) & 17.0 - bbind(Int.self) & factory { Int(try $0.instance() as Double) + 5 * $1 } - } - expect { try swinject.provider(of: Int.self, arg: 5)() } == 42 - expect { try swinject.instance(of: Int.self, arg: 5) } == 42 - } - it("can curry factory's arguments") { - let swinject = Swinject { - bbind(Int.self) & factory { (_, a1: Int, a2: Double, a3: String) in - a1 + Int(a2) + Int(a3)! - } - } - expect { try swinject.factory(of: Int.self)(11, 14.0, "17") } == 42 - expect { try swinject.factory(of: Int.self, arg: 11)(14.0, "17") } == 42 - expect { try swinject.factory(of: Int.self, arg: 11, 14.0)("17") } == 42 } it("can pass context to the bindings") { // FIXME: compiler segfaults if declaring these providers inside function builder diff --git a/Tests/LinuxConfig.swift b/Tests/LinuxConfig.swift index 59f74572..6b64e84e 100644 --- a/Tests/LinuxConfig.swift +++ b/Tests/LinuxConfig.swift @@ -19,6 +19,7 @@ let allSpecs: [QuickSpec.Type] = [ // 3.0 Api SwinjectApiSpec.self, BindingSpec.self, + InjectionSpec.self, ModulesSpec.self, ScopesSpec.self, OptionalsSpec.self, diff --git a/Tests/Support/TestModels.swift b/Tests/Support/TestModels.swift index 980cbe80..8b3c8051 100644 --- a/Tests/Support/TestModels.swift +++ b/Tests/Support/TestModels.swift @@ -11,7 +11,13 @@ class Human: Mammal { } struct Pet { + let name: String let owner: Human + + init(name: String = "", owner: Human) { + self.name = name + self.owner = owner + } } class Building { diff --git a/Tests/Unit Specs/BindingKeySpec.swift b/Tests/Unit Specs/BindingKeySpec.swift index 1496e56d..59a48106 100644 --- a/Tests/Unit Specs/BindingKeySpec.swift +++ b/Tests/Unit Specs/BindingKeySpec.swift @@ -8,47 +8,22 @@ import Quick class BindingKeySpec: QuickSpec { override func spec() { describe("matching") { - var key: BindingKey! var descriptor = AnyTypeDescriptorMock() var otherKey = AnyBindingKeyMock() beforeEach { descriptor = AnyTypeDescriptorMock() descriptor.matchesReturnValue = true - key = makeKey(descriptor: descriptor) otherKey = AnyBindingKeyMock() otherKey.descriptor = AnyTypeDescriptorMock() otherKey.argumentType = Void.self otherKey.contextType = Void.self } - it("does not match if descriptors don't match") { - descriptor.matchesReturnValue = false - expect { key.matches(otherKey) }.to(beFalse()) - } - it("it checks if descriptors match") { - let otherDescriptor = AnyTypeDescriptorMock() - _ = key.matches(makeKey(descriptor: otherDescriptor)) - expect(descriptor.matchesReceivedOther) === otherDescriptor - } - it("matches if descriptors match") { - descriptor.matchesReturnValue = true - expect { key.matches(otherKey) }.to(beTrue()) - } - it("does not match if argument types are different") { - let key = makeKey(descriptor: descriptor, argumentType: Int.self) - otherKey.argumentType = Double.self - expect(key.matches(otherKey)).to(beFalse()) - } - it("matches if argument types are the same") { - let key = makeKey(descriptor: descriptor, argumentType: Int.self) - otherKey.argumentType = Int.self - expect(key.matches(otherKey)).to(beTrue()) - } it("does not match if context types are different") { let key = makeKey(descriptor: descriptor, contextType: Int.self) otherKey.contextType = Double.self expect(key.matches(otherKey)).to(beFalse()) } - it("matches if argument context are the same") { + it("matches if contexts are the same") { let key = makeKey(descriptor: descriptor, contextType: Int.self) otherKey.contextType = Int.self expect(key.matches(otherKey)).to(beTrue()) diff --git a/Tests/Unit Specs/SwinjectSpec.swift b/Tests/Unit Specs/SwinjectSpec.swift index 028da653..f9a057e0 100644 --- a/Tests/Unit Specs/SwinjectSpec.swift +++ b/Tests/Unit Specs/SwinjectSpec.swift @@ -15,18 +15,7 @@ class SwinjectSpec: QuickSpec { override func spec() { swinject = Swinject(binding) } describe("instance injection") { - context("no bindings") { - it("throws") { - let swinject = Swinject() - expect { try swinject.instance(of: Int.self) }.to(throwError()) - } - } context("single binding") { - it("request instance from matching binding") { - binding.matchesReturnValue = true - _ = try? swinject.instance(of: Any.self) - expect(binding.instanceArgContextResolverCallsCount) == 1 - } it("does not request instance from matching binding until instance is required") { binding.matchesReturnValue = true expect(binding.instanceArgContextResolverCallsCount) == 0 @@ -36,108 +25,20 @@ class SwinjectSpec: QuickSpec { override func spec() { _ = try? swinject.instance(of: Any.self) expect(binding.instanceArgContextResolverCallsCount) == 0 } - it("returns instance produced by binding") { - binding.matchesReturnValue = true - binding.instanceArgContextResolverReturnValue = 42 - expect { try swinject.instance(of: Any.self) as? Int } == 42 - } - it("rethrows error from binding") { - binding.matchesReturnValue = true - binding.instanceArgContextResolverThrowableError = TestError() - expect { try swinject.instance(of: Any.self) }.to(throwError(errorType: TestError.self)) - } - it("crashes if bound type does not match requested type") { - binding.matchesReturnValue = true - binding.instanceArgContextResolverReturnValue = "" - expect { _ = try swinject.instance(of: Double.self) }.to(throwError()) - } - it("does not crash if bound type conforms to the requested type") { - binding.matchesReturnValue = true - binding.instanceArgContextResolverReturnValue = 42 - expect { _ = try swinject.instance(of: CustomStringConvertible?.self) }.notTo(throwError()) - } - it("passes swinject as resolver") { - binding.matchesReturnValue = true - _ = try? swinject.instance(of: Any.self) - expect(binding.instanceReceivedArguments?.resolver is Swinject).to(beTrue()) - } - it("matches binding with correct key") { - binding.matchesReturnValue = false - _ = try? swinject.instance(tagged: "tag") as Int - let descriptor = binding.matchesReceivedKey?.descriptor as? Tagged - expect(descriptor?.tag) == "tag" - } it("matches binding with correct context") { binding.matchesReturnValue = false _ = try? swinject.on("context").instance() as Int expect(binding.matchesReceivedKey?.contextType is String.Type).to(beTrue()) } } - context("multiple bindings") { - var bindings = [BindingMock]() - beforeEach { - bindings = Array(0 ..< 3).map { _ in BindingMock() } - bindings.forEach { - $0.matchesReturnValue = false - $0.instanceArgContextResolverReturnValue = 0 - } - swinject = Swinject( - bindings[0], - bindings[1], - bindings[2] - ) - } - it("throws if multiple bindings match requested type") { - bindings.forEach { $0.matchesReturnValue = true } - expect { try swinject.instance(of: Any.self) }.to(throwError()) - } - it("does not throw if single binding matches requested type") { - bindings[1].matchesReturnValue = true - expect { try swinject.instance(of: Any.self) }.notTo(throwError()) - } - it("returns instance from matching binding") { - bindings[1].matchesReturnValue = true - bindings[1].instanceArgContextResolverReturnValue = 42 - expect { try swinject.instance(of: Int.self) } == 42 - } - } } describe("provider injection") { - it("does not throw if binding matches provided type") { - binding.matchesReturnValue = true - binding.instanceArgContextResolverReturnValue = 42 - let provider = swinject.provider() as () throws -> Int - expect { try provider() }.notTo(throwError()) - } - it("throws if missing binding for provided type") { - binding.matchesReturnValue = false - let provider = swinject.provider() as () throws -> Int - expect { try provider() }.to(throwError()) - } it("does not request provided type until provider is called") { binding.matchesReturnValue = true binding.instanceArgContextResolverReturnValue = 42 _ = swinject.provider(of: Int.self) expect(binding.instanceArgContextResolverCallsCount) == 0 } - it("returns instance from binding") { - binding.matchesReturnValue = true - binding.instanceArgContextResolverReturnValue = 42 - let provider = swinject.provider(of: Int.self) - expect { try provider() } == 42 - } - it("rethrows binding error from provider") { - binding.matchesReturnValue = true - binding.instanceArgContextResolverThrowableError = TestError() - let provider = swinject.provider(of: Int.self) - expect { try provider() }.to(throwError(errorType: TestError.self)) - } - it("matches binding with correct key") { - binding.matchesReturnValue = true - _ = try? swinject.provider(of: Any.self, tagged: "tag")() - let descriptor = binding.matchesReceivedKey?.descriptor as? Tagged - expect(descriptor?.tag) == "tag" - } it("matches binding with correct context") { binding.matchesReturnValue = false _ = try? swinject.on("context").provider()() as Int @@ -161,48 +62,12 @@ class SwinjectSpec: QuickSpec { override func spec() { } } describe("factory injection") { - it("throws if missing binding for created type") { - binding.matchesReturnValue = false - let factory = swinject.factory() as (String) throws -> Int - expect { try factory("arg") }.to(throwError()) - } - it("does not throw if binding matches created type") { - binding.matchesReturnValue = true - binding.instanceArgContextResolverReturnValue = 42 - let factory = swinject.factory() as (String) throws -> Int - expect { try factory("arg") }.notTo(throwError()) - } it("does not request created type until factory is called") { binding.matchesReturnValue = true binding.instanceArgContextResolverReturnValue = 42 _ = swinject.factory() as (String) throws -> Int expect(binding.instanceArgContextResolverCallsCount) == 0 } - it("rethrows binding error from factory") { - binding.matchesReturnValue = true - binding.instanceArgContextResolverThrowableError = TestError() - let factory = swinject.factory() as (String) throws -> Int - expect { try factory("arg") }.to(throwError(errorType: TestError.self)) - } - it("returns instance from binding") { - binding.matchesReturnValue = true - binding.instanceArgContextResolverReturnValue = 42 - let factory = swinject.factory() as (String) throws -> Int - expect { try factory("arg") } == 42 - } - it("passes given factory argument to binding") { - binding.matchesReturnValue = true - binding.instanceArgContextResolverReturnValue = 42 - _ = try? swinject.factory(of: Int.self)("arg") - let argument = binding.instanceReceivedArguments?.arg as? MatchableBox1 - expect(argument?.arg1) == "arg" - } - it("matches binding with correct key") { - binding.matchesReturnValue = false - _ = try? swinject.factory(tagged: "tag")("arg") as Int - let descriptor = binding.matchesReceivedKey?.descriptor as? Tagged - expect(descriptor?.tag) == "tag" - } it("matches binding with correct context") { binding.matchesReturnValue = false _ = try? swinject.on("context").factory()("arg") as Int @@ -213,45 +78,6 @@ class SwinjectSpec: QuickSpec { override func spec() { _ = try? swinject.on("context").factory()("arg") as Int expect(binding.instanceReceivedArguments?.context as? String) == "context" } - context("currying") { - beforeEach { - binding.matchesReturnValue = true - binding.instanceArgContextResolverReturnValue = 42 - } - it("can curry 2-tuple as 0 / 2 argument") { - _ = try? swinject.factory()("arg1", "arg2") as Int - let receivedArg = binding.instanceReceivedArguments?.arg as? MatchableBox2 - expect(receivedArg?.arg1) == "arg1" - expect(receivedArg?.arg2) == "arg2" - } - it("can curry 2-tuple as 1 / 1 argument") { - _ = try? swinject.factory(arg: "arg1")("arg2") as Int - let receivedArg = binding.instanceReceivedArguments?.arg as? MatchableBox2 - expect(receivedArg?.arg1) == "arg1" - expect(receivedArg?.arg2) == "arg2" - } - it("can curry 3-tuple as 0 / 3 argument") { - _ = try? swinject.factory()("arg1", 2, "arg3") as Int - let receivedArg = binding.instanceReceivedArguments?.arg as? MatchableBox3 - expect(receivedArg?.arg1) == "arg1" - expect(receivedArg?.arg2) == 2 - expect(receivedArg?.arg3) == "arg3" - } - it("can curry 3-tuple as 1 / 2 argument") { - _ = try? swinject.factory(arg: "arg1")(2, "arg3") as Int - let receivedArg = binding.instanceReceivedArguments?.arg as? MatchableBox3 - expect(receivedArg?.arg1) == "arg1" - expect(receivedArg?.arg2) == 2 - expect(receivedArg?.arg3) == "arg3" - } - it("can curry 3-tuple as 2 / 1 argument") { - _ = try? swinject.factory(arg: "arg1", 2)("arg3") as Int - let receivedArg = binding.instanceReceivedArguments?.arg as? MatchableBox3 - expect(receivedArg?.arg1) == "arg1" - expect(receivedArg?.arg2) == 2 - expect(receivedArg?.arg3) == "arg3" - } - } } describe("context translators") { var translators = [AnyContextTranslatorMock]() From b52d9f1bcfc527a9450a7176f303040f2d832bf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 28 Jul 2019 11:14:50 +0200 Subject: [PATCH 160/239] Extend binding spec --- Tests/3.0 API/BindingSpec.swift | 31 +++++++++++++++++++++++++++++ Tests/Unit Specs/SwinjectSpec.swift | 21 ------------------- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/Tests/3.0 API/BindingSpec.swift b/Tests/3.0 API/BindingSpec.swift index 10d15d89..d20cc532 100644 --- a/Tests/3.0 API/BindingSpec.swift +++ b/Tests/3.0 API/BindingSpec.swift @@ -45,5 +45,36 @@ class BindingSpec: QuickSpec { override func spec() { #if swift(>=5.1) } expect(try? swinject.instance(of: Mammal.self) is Human) == true } + it("can use up to 5 arguments in factory binding") { + let swinject = Swinject { + bbind(Int.self) & factory { (_, a1: Int) in a1 } + bbind(Int.self) & factory { (_, a1: Int, a2: Int) in a1 + a2 } + bbind(Int.self) & factory { (_, a1: Int, a2: Int, a3: Int) in a1 + a2 + a3 } + bbind(Int.self) & factory { (_, a1: Int, a2: Int, a3: Int, a4: Int) in a1 + a2 + a3 + a4 } + bbind(Int.self) & factory { (_, a1: Int, a2: Int, a3: Int, a4: Int, a5: Int) in a1 + a2 + a3 + a4 + a5 } + } + expect { try swinject.instance(of: Int.self, arg: 1) } == 1 + expect { try swinject.instance(of: Int.self, arg: 1, 2) } == 3 + expect { try swinject.instance(of: Int.self, arg: 1, 2, 3) } == 6 + expect { try swinject.instance(of: Int.self, arg: 1, 2, 3, 4) } == 10 + expect { try swinject.instance(of: Int.self, arg: 1, 2, 3, 4, 5) } == 15 + } + it("does not invoke binding until instance is required") { + var invoked = false + let swinject = Swinject { + bbind(Int.self) & provider { invoked = true; return 42 } + } + _ = swinject.provider(of: Int.self) + expect(invoked) == false + } + it("does not invoke unnecessary bindings") { + var invoked = false + let swinject = Swinject { + bbind(Int.self) & provider { invoked = true; return 42 } + bbind(Int.self, tagged: "tag") & 42 + } + _ = try? swinject.instance(of: Int.self, tagged: "tag") + expect(invoked) == false + } #endif } } diff --git a/Tests/Unit Specs/SwinjectSpec.swift b/Tests/Unit Specs/SwinjectSpec.swift index f9a057e0..ab38523f 100644 --- a/Tests/Unit Specs/SwinjectSpec.swift +++ b/Tests/Unit Specs/SwinjectSpec.swift @@ -16,15 +16,6 @@ class SwinjectSpec: QuickSpec { override func spec() { } describe("instance injection") { context("single binding") { - it("does not request instance from matching binding until instance is required") { - binding.matchesReturnValue = true - expect(binding.instanceArgContextResolverCallsCount) == 0 - } - it("only requests instance from matching binding") { - binding.matchesReturnValue = false - _ = try? swinject.instance(of: Any.self) - expect(binding.instanceArgContextResolverCallsCount) == 0 - } it("matches binding with correct context") { binding.matchesReturnValue = false _ = try? swinject.on("context").instance() as Int @@ -33,12 +24,6 @@ class SwinjectSpec: QuickSpec { override func spec() { } } describe("provider injection") { - it("does not request provided type until provider is called") { - binding.matchesReturnValue = true - binding.instanceArgContextResolverReturnValue = 42 - _ = swinject.provider(of: Int.self) - expect(binding.instanceArgContextResolverCallsCount) == 0 - } it("matches binding with correct context") { binding.matchesReturnValue = false _ = try? swinject.on("context").provider()() as Int @@ -62,12 +47,6 @@ class SwinjectSpec: QuickSpec { override func spec() { } } describe("factory injection") { - it("does not request created type until factory is called") { - binding.matchesReturnValue = true - binding.instanceArgContextResolverReturnValue = 42 - _ = swinject.factory() as (String) throws -> Int - expect(binding.instanceArgContextResolverCallsCount) == 0 - } it("matches binding with correct context") { binding.matchesReturnValue = false _ = try? swinject.on("context").factory()("arg") as Int From e49dfe6ddfceae0174b714ae4bca954c5b6a28fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 28 Jul 2019 12:05:23 +0200 Subject: [PATCH 161/239] Move context test to separate spec --- Swinject.xcodeproj/project.pbxproj | 200 ++++++++---------- Tests/3.0 API/ContextSpec.swift | 102 ++++++++++ Tests/3.0 API/SwinjectApiSpec.swift | 33 --- Tests/LinuxConfig.swift | 2 +- Tests/Unit Specs/BinderEnvironmentSpec.swift | 204 ------------------- Tests/Unit Specs/BindingKeySpec.swift | 45 ---- Tests/Unit Specs/SimpleBindingSpec.swift | 24 --- Tests/Unit Specs/SwinjectSpec.swift | 143 ------------- 8 files changed, 193 insertions(+), 560 deletions(-) create mode 100644 Tests/3.0 API/ContextSpec.swift delete mode 100644 Tests/Unit Specs/BindingKeySpec.swift delete mode 100644 Tests/Unit Specs/SimpleBindingSpec.swift delete mode 100644 Tests/Unit Specs/SwinjectSpec.swift diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 08ef0958..2cc5e9d1 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -7,12 +7,14 @@ objects = { /* Begin PBXBuildFile section */ + 004B06007E4FDD8F44B7EC89 /* ModulesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75BE3AE3E30DFE42A919D825 /* ModulesSpec.swift */; }; + 0068DAA4AA322F00AF53731F /* ScopesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D3C59E84B5FD0C13F487838 /* ScopesSpec.swift */; }; + 0207493E1CEE8456E91E3DAE /* BindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E59A67F3548663368788B17 /* BindingSpec.swift */; }; 020DA1718FCC68D889FB5A5F /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3586A4987B7C7C8122D674E /* SwinjectError.swift */; }; 02410BD4FB357F4C6B521608 /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; 02556F149C9AAEF5CE353AC1 /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; 03122D1B2EA65C89ADC78EC7 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62682D6ED38742996624B041 /* BasicAssembly.swift */; }; 0509EE8D41BF354EB91ACC80 /* Reference.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73B4B777290FF5D38A8914CC /* Reference.swift */; }; - 05B18A91CA201F7EE53F3ADE /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = C5FB515A9B4B929026438A90 /* SwinjectApiSpec.swift */; }; 0622539110A7430776A307C7 /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42490D1D0C395951243F5CFF /* Container.swift */; }; 06363AE7650CA288BDF6CB73 /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 34AFFAC41BA9D02A38BDB7A3 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 06F4CAB352B4F623FF7BD885 /* ScopeRegistryKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */; }; @@ -23,22 +25,19 @@ 0A7E1E5E74113A0C523A4973 /* BindingKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = A24B4E8F1CA18603DBB6884A /* BindingKey.swift */; }; 0B61DC733616A8ED4ED77FA7 /* StandardScopeRegistrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */; }; 0BA8216CFBC61A93F4948ABE /* InstanceMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CADDB3E9E363310028AA5920 /* InstanceMaker.swift */; }; - 0BCA618354F1B2867A7FB261 /* BindingKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */; }; 0CD787EACEBFD1051D358E7D /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; 0CE1126436F680F9684837E4 /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; 0D5C4A278A16AB3A163148AF /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; - 1183FED17E9521E848F1F991 /* SwinjectSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9527A4CA5BCBA7AFA3596757 /* SwinjectSpec.swift */; }; + 0DC084A3650745492BB81EE9 /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B3797A6BB56AE76CEC19F2A /* SwinjectApiSpec.swift */; }; 128913D570B4A8BBF40866BE /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; 13CDEC7A6C8E43B58D5CBE3D /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; - 15246957A062BF0ED7134E0E /* SimpleBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */; }; 180DB4397B4C05E26F819C85 /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADA1541ABC1365DFD7E3377F /* Food.swift */; }; 181204958559CE25462AA6EF /* ScopeRegistryKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2902FD4C1A50263340A51FFB /* ScopeRegistryKeySpec.swift */; }; - 1927B730A0F0E141BFC1773E /* BindingKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */; }; 19416C867F15E88394A0ABD1 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */; }; 196338EA802A39E205C33B43 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; 19EBB651BD06BD0C03C1ACB5 /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59111BE319C59E4CD6CF68CD /* Assembler.swift */; }; 1A40A26942A65246D7DD268E /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = ADC44E9312C3B974AFD8F07B /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 1BE678F7FA5DF0E6ED2CF565 /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = C5FB515A9B4B929026438A90 /* SwinjectApiSpec.swift */; }; + 1C62135FAE3D64DC7BFBF861 /* ContextSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */; }; 1C82BFD00FCC384DB3AE6A89 /* MatchableBoxes.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 808C1063CA90CC593C7E0E9C /* MatchableBoxes.swifttemplate */; }; 1CA5DF3F93203B226A6FA059 /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EA566CD336DB8343ADFAF9B /* BehaviorFakes.swift */; }; 1E1CAA4156D94E3A73AEA9F6 /* Opaque.swift in Sources */ = {isa = PBXBuildFile; fileRef = C68B98C653ABDED9C3D17DB3 /* Opaque.swift */; }; @@ -50,6 +49,7 @@ 24114725AE1A834C6E3118F7 /* TaggedTypeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */; }; 2615FC1C92B7E381116B9E57 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; 26C4C6118D189E8813ABD5A2 /* Quick.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = C765B92B00C0AC8625BB4AC9 /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 273F441B941A6DF76D9BD752 /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B3797A6BB56AE76CEC19F2A /* SwinjectApiSpec.swift */; }; 283C77045DA55C2134EC9C48 /* Container+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F446D6BD4C44E16A1D608BFB /* Container+TypeForwarding.swift */; }; 290C9E9420A1EE30456476CB /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59111BE319C59E4CD6CF68CD /* Assembler.swift */; }; 293985649250DF270DC89135 /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; @@ -65,9 +65,11 @@ 3099172980F9E9143C0A1C20 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; 3129A37CDC1653C11800E24A /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EA566CD336DB8343ADFAF9B /* BehaviorFakes.swift */; }; 31392A9EF619329716144F95 /* Opaque.swift in Sources */ = {isa = PBXBuildFile; fileRef = C68B98C653ABDED9C3D17DB3 /* Opaque.swift */; }; + 31729A1E5F50EF30FDD427AD /* ScopesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D3C59E84B5FD0C13F487838 /* ScopesSpec.swift */; }; 328DED07602120E3EE252D57 /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 823617F3B8A9192F56B13331 /* Quick.framework */; }; 33391EBA040E82DFB0A37015 /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; 335CE53CEC2360DC86D58F07 /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61EE5DDBE705B47AFC9A6986 /* LoadAwareAssembly.swift */; }; + 33B86F2D33219879731CDDF0 /* ScopesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D3C59E84B5FD0C13F487838 /* ScopesSpec.swift */; }; 3575DE21531F7365B713B64B /* ScopedBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */; }; 36A706F87ED2E88F3390C6C2 /* ServiceEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38615FC8EEB466C5C1EAD21C /* ServiceEntry.swift */; }; 372F0061E762BF8FFF05457F /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; @@ -79,19 +81,21 @@ 3C270A77DE4F1E6BC2F8E863 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; 3CEF021295AD9AF9BF26B71E /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; 3DEFB7CA42D9EFF0B4FBC0F4 /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 38BCCF3F950869BD1891F7A8 /* Swinject.framework */; }; + 3F0DCA7060C62712EA30CBB1 /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B3797A6BB56AE76CEC19F2A /* SwinjectApiSpec.swift */; }; 3F704A98C01C84BDBD0A52B3 /* BinderEnvironmentSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */; }; 3F8F5645D6D37FCEC1D89393 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B580B43E1891812C97209 /* Binding.swift */; }; 401592294E5D528379BE1AB2 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62682D6ED38742996624B041 /* BasicAssembly.swift */; }; 41C7340BFD2EB66359772733 /* Resolver+LegacyApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A784E2DEC7691D14DDBECD8 /* Resolver+LegacyApi.swift */; }; + 42FE916C1593A9289E1A28BC /* InjectionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 670DB253ECD5CE1468A7F2E3 /* InjectionSpec.swift */; }; 4347EE17D0C0ED574C899D85 /* ScopeRegistryKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */; }; 43A74237D8933572BAA0F3B4 /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; 4415F3731760950C06EF2CBA /* Closable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D0BCCCD61CD9BECC29E064 /* Closable.swift */; }; 44F458F61B21D78A91664160 /* BinderVariation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E0C3E4D518BC1FEF3EF8D33 /* BinderVariation.swift */; }; - 45D57E61D4774613F2DF1CCA /* SwinjectSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9527A4CA5BCBA7AFA3596757 /* SwinjectSpec.swift */; }; 48D1568CB41BE4B6597FD535 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; 48F40377D116C6B1B786C329 /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; 4954CBB07E38E98752AC3347 /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; 49685AB40BEE856C62005C87 /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; + 49D71F6CC12C12FE7B6A097A /* ContextSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */; }; 4A977D2B639B8098AA508389 /* BinderEnvironmentSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */; }; 4B9811CF0604946CCF323ED2 /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92B8E618A08408404FB2A7A /* TypeBinder.swift */; }; 4B9BAB1D38AB0C08F8CA25F5 /* ScopeRegistryKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2902FD4C1A50263340A51FFB /* ScopeRegistryKeySpec.swift */; }; @@ -100,11 +104,12 @@ 4E4DC8CDD1BA51FB66A332C2 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */; }; 4EC94A51037C79DE0C5C8CB1 /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; 4EE5C1207C57C85A928FA89B /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 273FB7A6277E0841E1570990 /* Nimble.framework */; }; - 53AC03FA6538E56A976E52FA /* SwinjectSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9527A4CA5BCBA7AFA3596757 /* SwinjectSpec.swift */; }; + 4EFB0A66BBCAA617470CE622 /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B3797A6BB56AE76CEC19F2A /* SwinjectApiSpec.swift */; }; 53EBF7A46EF65F2A8DAADC7A /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; 546FF827DB6D42490D1CA439 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; 54956014A1774DF8357B69E6 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; 55CA3AA3F28B7CC221ABEC83 /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6D54F152C11C966ECFC55ECB /* Swinject.framework */; }; + 55F2E72EA8C3564130F66946 /* ModulesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75BE3AE3E30DFE42A919D825 /* ModulesSpec.swift */; }; 56B2AD6054B63420DD025EC6 /* NonGeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841D83ADB41363D1E38087B4 /* NonGeneratedMocks.swift */; }; 56D43738C09AA7355F6D529D /* BinderEnvironmentSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */; }; 57BFBA2077E70DC1C2FE796C /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */; }; @@ -120,7 +125,6 @@ 5ED8A7D19F21FA686215F72C /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; 5FCE2A2AE5DD0DBECA4A9953 /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */; }; 6034CF5459D96497AF36E4B6 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; - 6203E6494C12ECE21323F512 /* BindingKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */; }; 62307C8E22EC65E5E85AA08A /* InstanceMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CADDB3E9E363310028AA5920 /* InstanceMaker.swift */; }; 628EBFBA0031B1FA2E29F583 /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 351C4221896DDB8572BD6CB5 /* Person.swift */; }; 63528D45A548DD58D748D54C /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; @@ -138,6 +142,7 @@ 6DA49F84E2592B32F81F268B /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BFF4BA99493C54260878C4 /* ObjectScope.swift */; }; 6F6FAD0EEF84580DD53BB755 /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1C58FC14EEA170B0DC079DE4 /* Quick.framework */; }; 6FCCBA9D2E4C2A225CB1A152 /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */; }; + 70368EC369287B4EE767E929 /* LinuxConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 938425B216B78A06EC10504A /* LinuxConfig.swift */; }; 703F8B3AD111A6CFAFF66A49 /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; 708E1C453CBC76ED26FA2FCB /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; 70BAF056528B2B33B3A65E9D /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A006CC804F9AB8ACC121029 /* Utils.swift */; }; @@ -145,8 +150,7 @@ 72217E47D83C3CA6D97640B9 /* StandardScopeRegistrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */; }; 725EF35B0CC5E62791D5EA09 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 34AFFAC41BA9D02A38BDB7A3 /* Nimble.framework */; }; 7295E928A18E6055CF796840 /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C074BAC560F277E806146C60 /* SimpleBinding.swift */; }; - 732A8933C1310C2A6309E56B /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCAF491EC7DCD7477F9A0ECB /* SwinjectModule.swift */; }; - 7337BA3B0248BE5A4C8C1339 /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = C5FB515A9B4B929026438A90 /* SwinjectApiSpec.swift */; }; + 72F09FC92FFB0F7C32D8E2A5 /* OptionalsSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50D6F2639990DD5BAD9578B0 /* OptionalsSpec.swift */; }; 737740CDFB89189DFF5FD165 /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 74DE57FB3E8228904E6FE0D7 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; 74E1FC692A27C56510363364 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; 75D74C8C25EDACF5A7A75A5C /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; @@ -162,25 +166,29 @@ 7E3C3E6FD07F3BD76024770A /* InjectionVariation.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C516EFA0CA22D19F07B27E /* InjectionVariation.swift */; }; 8016512839FE61EC3127E489 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */; }; 811BA1018E9BF86A7DEB728F /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */; }; + 818DF17D671EA1022CE59A2A /* InjectionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 670DB253ECD5CE1468A7F2E3 /* InjectionSpec.swift */; }; 820307073A53AED47AC99B8D /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3586A4987B7C7C8122D674E /* SwinjectError.swift */; }; 8228FEB1DF3C41DEDCE0FB1D /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = A10187BB3A994165E7FC1528 /* ScopedBinding.swift */; }; + 82299769BC637A14E7827DB0 /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1E726A651C3AFE92C19608B /* SwinjectModule.swift */; }; 829853126CDB7464599AFC85 /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; + 832C9ABB8DCF5340D796F5F8 /* ContextSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */; }; 83464EDC08380F5CE2190F30 /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; - 838E49C5683FA93A3A917346 /* SimpleBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */; }; 8436D091ED844817C8CE3AF2 /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; 848227742D4ABA298D340485 /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; + 86CBC40FDC90E2A2051386C5 /* ContextSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */; }; 87FEAEF562B99522083CB87D /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; 890CCD2800597F6FB7C6FD31 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; 89E2997CB8B90368A15A91CE /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; 8B5927517B567B1DFAB5B935 /* ContextTranslator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */; }; 8BE1DA0A9876AB47BB76E2CD /* Opaque.swift in Sources */ = {isa = PBXBuildFile; fileRef = C68B98C653ABDED9C3D17DB3 /* Opaque.swift */; }; - 8CE52672848FD54520215CA1 /* SwinjectSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9527A4CA5BCBA7AFA3596757 /* SwinjectSpec.swift */; }; 8E1E051646BBD6E38F4199C2 /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EA566CD336DB8343ADFAF9B /* BehaviorFakes.swift */; }; + 8E77B56EE7F90BF723600DDF /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1E726A651C3AFE92C19608B /* SwinjectModule.swift */; }; 91E435894038C42335086FA8 /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3586A4987B7C7C8122D674E /* SwinjectError.swift */; }; 920DE2CAB9895D10FAE48FBA /* ScopeRegistryKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */; }; 934AFACA6BFF24AD3503F98D /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */; }; 93BCD12CEFB88BAD49BEA431 /* ServiceEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38615FC8EEB466C5C1EAD21C /* ServiceEntry.swift */; }; 9425887520AC2DBDCBACB252 /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92B8E618A08408404FB2A7A /* TypeBinder.swift */; }; + 95A6654089875BCC863FB53B /* InjectionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 670DB253ECD5CE1468A7F2E3 /* InjectionSpec.swift */; }; 96EA0A5DF33F025EBE0B67D2 /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; 979518E078B187549E11DF48 /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; 97C2EA47D7623AFD723AFE93 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */; }; @@ -191,6 +199,7 @@ 999AF7221D3F2E1F83C3ACB1 /* Container+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDA78290D6D60BD0B808571F /* Container+Logging.swift */; }; 99C5D861B16FAFAD3F9E28C5 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */; }; 9A21ECA8F283E1E144CEC763 /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; + 9A2A6978519F2BBA97DA6EA6 /* BindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E59A67F3548663368788B17 /* BindingSpec.swift */; }; 9A8164D6696C87BFEC7325C3 /* GeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */; }; 9AD60A86D5A0DF4513C1EA8D /* TaggedTypeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */; }; 9C12EB42EC058994805E93A6 /* GeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */; }; @@ -203,27 +212,30 @@ A2D3B18BE38948A427B60BC5 /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61EE5DDBE705B47AFC9A6986 /* LoadAwareAssembly.swift */; }; A308578B99D33C7E33632E85 /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; A3BFFED76688F149FBAF7C53 /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EA566CD336DB8343ADFAF9B /* BehaviorFakes.swift */; }; + A453A5A7E0EC0FE161AA34D5 /* OptionalsSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50D6F2639990DD5BAD9578B0 /* OptionalsSpec.swift */; }; A5302886A31C90F38512B88E /* TaggedTypeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */; }; A53B5A8E2188F8C4A3F29C2E /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BC5108ED11A3A3084D864CC /* Animal.swift */; }; A59C6C434288333EDAF951C4 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */; }; - A5A7F3C866C17F071C5D976C /* BindingKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */; }; A5E4C79F89E1A8AB3A4D8D6E /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59A3946B59EB4D787CCE9F2 /* Container+Registration.swift */; }; A6EECC339FA54CA0BBFF4146 /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BC5108ED11A3A3084D864CC /* Animal.swift */; }; A70936B898139A6C5F83F616 /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; A75BAA10EC6F738EBC2C5BE8 /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */; }; A78FF99AA81139C27FA57F4F /* BindingKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = A24B4E8F1CA18603DBB6884A /* BindingKey.swift */; }; A7DD08A60F12EC078BBE086F /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; + A834D948AB86794CA3304B98 /* LinuxConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 938425B216B78A06EC10504A /* LinuxConfig.swift */; }; A882705E4199EF759E80B311 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; A91EDAFBC3606EDFBD739899 /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */; }; A9A242086D1EDE408DC556D0 /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; AAD8D0551B8A26A9B22AECEC /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59A3946B59EB4D787CCE9F2 /* Container+Registration.swift */; }; AB864E029E996492ED4A3A52 /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92B8E618A08408404FB2A7A /* TypeBinder.swift */; }; AC470B4322599B0A076DD3FF /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; + AD214F3DBAB4F16C88322CAC /* InjectionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 670DB253ECD5CE1468A7F2E3 /* InjectionSpec.swift */; }; AD3E7135985F1046E35C39DE /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */; }; ADCF273AF041E74DBEC2C13A /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */; }; ADF0B21969FE77CEFBB2AAAC /* Quick.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 823617F3B8A9192F56B13331 /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; AE6EAB8CC32ED5E1789D55B7 /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; AE93BDC3AA7962AFD574B32B /* Quick.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 1C58FC14EEA170B0DC079DE4 /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + B00627BABCF9181C7B58609E /* LinuxConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 938425B216B78A06EC10504A /* LinuxConfig.swift */; }; B06306286CC5EA66C88F24D1 /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 38BCCF3F950869BD1891F7A8 /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; B0B139FADA6AE07C79847EBA /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61EE5DDBE705B47AFC9A6986 /* LoadAwareAssembly.swift */; }; B293894FEB67831DDA5F000E /* Reference.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73B4B777290FF5D38A8914CC /* Reference.swift */; }; @@ -238,7 +250,9 @@ B7653A6427A5E284E9A1D6D3 /* ServiceEntry+TypeForwarding.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */; }; B84167AC8C6BEB57C4D0695A /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; B9550BE2BA6FA5731BEC87FD /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; + B96A6370D549AAC383360ABC /* LinuxConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 938425B216B78A06EC10504A /* LinuxConfig.swift */; }; BB571B9A78FC53231A18E18C /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; + BB77A5D81C58392964D07233 /* BindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E59A67F3548663368788B17 /* BindingSpec.swift */; }; BB8FDF4F2A0AF8C1DA615854 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; BCD130E9F1D33C66AA6A12F7 /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 74DE57FB3E8228904E6FE0D7 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; BD01D1F86970237D6D5C8D38 /* ReferenceMakerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 388605A438343F7BB80D521E /* ReferenceMakerSpec.swift */; }; @@ -258,48 +272,25 @@ C3FDE105B08336F26CC95BAA /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = A10187BB3A994165E7FC1528 /* ScopedBinding.swift */; }; C4CB7A3BA35A1E0811842971 /* ScopedBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */; }; C4E9DC50A2FDAE4D36A925D9 /* NonGeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841D83ADB41363D1E38087B4 /* NonGeneratedMocks.swift */; }; + C637E97E193BB1DADDDC6C21 /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1E726A651C3AFE92C19608B /* SwinjectModule.swift */; }; C6D60E2AEC381998223145B2 /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; C76374CAFE7C2BCCE52F1BB1 /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 351C4221896DDB8572BD6CB5 /* Person.swift */; }; C950785B81C6DB22F41FA3CE /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; C952D5869D87743297968E9A /* StandardScopeRegistrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */; }; CA5523B60E51EB98719CF1F8 /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; - CAF3BCDC752C821491AE8714 /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCAF491EC7DCD7477F9A0ECB /* SwinjectModule.swift */; }; + CAA5241DAA201FBB5818C803 /* BindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E59A67F3548663368788B17 /* BindingSpec.swift */; }; CB06DC3BC4A32776BBD90DDF /* GeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */; }; CB0B308F3D3A831A28127462 /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59A3946B59EB4D787CCE9F2 /* Container+Registration.swift */; }; CB9666A26D85B92BA1357160 /* AutoMockable.stencil in Resources */ = {isa = PBXBuildFile; fileRef = 4286F98133270A36F19E5CD0 /* AutoMockable.stencil */; }; CB9E8D16D7A0620A1F7A32A3 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; CBBE28990E0EA82AD8D5E3AF /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; CBE63031F33303F3E503CEF2 /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; - CD1BEB4F22ED8BDD009168AE /* InjectionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD1BEB4E22ED8BDD009168AE /* InjectionSpec.swift */; }; - CD1BEB5022ED8BDD009168AE /* InjectionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD1BEB4E22ED8BDD009168AE /* InjectionSpec.swift */; }; - CD1BEB5122ED8BDD009168AE /* InjectionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD1BEB4E22ED8BDD009168AE /* InjectionSpec.swift */; }; - CD1BEB5222ED8BDD009168AE /* InjectionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD1BEB4E22ED8BDD009168AE /* InjectionSpec.swift */; }; - CD77892222ECF8F100560AB7 /* ModulesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD77892122ECF8F100560AB7 /* ModulesSpec.swift */; }; - CD77892322ECF8F100560AB7 /* ModulesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD77892122ECF8F100560AB7 /* ModulesSpec.swift */; }; - CD77892422ECF8F100560AB7 /* ModulesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD77892122ECF8F100560AB7 /* ModulesSpec.swift */; }; - CD77892522ECF8F100560AB7 /* ModulesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD77892122ECF8F100560AB7 /* ModulesSpec.swift */; }; - CD77892822ECF9C700560AB7 /* ScopesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD77892722ECF9C700560AB7 /* ScopesSpec.swift */; }; - CD77892922ECF9C700560AB7 /* ScopesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD77892722ECF9C700560AB7 /* ScopesSpec.swift */; }; - CD77892A22ECF9C700560AB7 /* ScopesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD77892722ECF9C700560AB7 /* ScopesSpec.swift */; }; - CD77892B22ECF9C700560AB7 /* ScopesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD77892722ECF9C700560AB7 /* ScopesSpec.swift */; }; - CD77892D22ED009C00560AB7 /* BindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD77892C22ED009C00560AB7 /* BindingSpec.swift */; }; - CD77892E22ED009C00560AB7 /* BindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD77892C22ED009C00560AB7 /* BindingSpec.swift */; }; - CD77892F22ED009C00560AB7 /* BindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD77892C22ED009C00560AB7 /* BindingSpec.swift */; }; - CD77893022ED009C00560AB7 /* BindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD77892C22ED009C00560AB7 /* BindingSpec.swift */; }; - CD77893222ED05C500560AB7 /* OptionalsSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD77893122ED05C500560AB7 /* OptionalsSpec.swift */; }; - CD77893322ED05C500560AB7 /* OptionalsSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD77893122ED05C500560AB7 /* OptionalsSpec.swift */; }; - CD77893422ED05C500560AB7 /* OptionalsSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD77893122ED05C500560AB7 /* OptionalsSpec.swift */; }; - CD77893522ED05C500560AB7 /* OptionalsSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD77893122ED05C500560AB7 /* OptionalsSpec.swift */; }; - CD92116422ECC05600211BF0 /* LinuxConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD92116322ECC05600211BF0 /* LinuxConfig.swift */; }; - CD92116522ECC05600211BF0 /* LinuxConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD92116322ECC05600211BF0 /* LinuxConfig.swift */; }; - CD92116622ECC05600211BF0 /* LinuxConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD92116322ECC05600211BF0 /* LinuxConfig.swift */; }; - CD92116722ECC05600211BF0 /* LinuxConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD92116322ECC05600211BF0 /* LinuxConfig.swift */; }; - CDBBA4023FE01CE4EFEE143A /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCAF491EC7DCD7477F9A0ECB /* SwinjectModule.swift */; }; CE5AFED22F04B96713ED76D7 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ADC44E9312C3B974AFD8F07B /* Nimble.framework */; }; CEA4CB2D3113EC693C590B9D /* ScopedBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */; }; CECF5BD14BCDF5248771A06A /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; CEE763218A90832454A6E2DE /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */; }; CF4516872D3DA7118DB2B90B /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; + CF4EBB60C21F8C503BCD7A29 /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1E726A651C3AFE92C19608B /* SwinjectModule.swift */; }; CF9535A0DCAFF23F4D62F871 /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; D0D71F9C22A0EE82B6E4F61A /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 74DE57FB3E8228904E6FE0D7 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; D13208E63523A97A0B840283 /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BC5108ED11A3A3084D864CC /* Animal.swift */; }; @@ -307,14 +298,14 @@ D2BAE1CB997A4D052CB8EFC8 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B580B43E1891812C97209 /* Binding.swift */; }; D3FB9F7B3F791A83FF86205C /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 273FB7A6277E0841E1570990 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; D4936DC1A47A8C85325FB52E /* Resolver+LegacyApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A784E2DEC7691D14DDBECD8 /* Resolver+LegacyApi.swift */; }; - D54DFEDF33F09035F3177248 /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCAF491EC7DCD7477F9A0ECB /* SwinjectModule.swift */; }; D600D0EFA0FE12A719EF095F /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 683A1FB7D7F4E9508D57E936 /* Quick.framework */; }; D69ED6990417ED1E921ACFCA /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; D861595482464ED95CF81922 /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; D9084C826F7A798508CD66F5 /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; + D941D81F59900A52805D6B4A /* OptionalsSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50D6F2639990DD5BAD9578B0 /* OptionalsSpec.swift */; }; D98BB7F59E98FC197D1C97A2 /* ServiceEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38615FC8EEB466C5C1EAD21C /* ServiceEntry.swift */; }; D9C5E21A1B6F43FA4C9DAD3C /* Quick.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 683A1FB7D7F4E9508D57E936 /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - DB03A9B61E162A73506C8552 /* SimpleBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */; }; + D9F132E4A6F6BC2BDD5DFCAA /* ModulesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75BE3AE3E30DFE42A919D825 /* ModulesSpec.swift */; }; DB74F17CDFF4886B9C38AD14 /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42490D1D0C395951243F5CFF /* Container.swift */; }; DC5B169FD525CC1C01518312 /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59111BE319C59E4CD6CF68CD /* Assembler.swift */; }; DCA3CCF94219A24E82DAF9ED /* Closable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D0BCCCD61CD9BECC29E064 /* Closable.swift */; }; @@ -329,8 +320,7 @@ E4CE31B7B9616EFC93C69341 /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; E5880DBBB91CC5F8F47FBF73 /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; E7D1045D25FAB592401DCAF0 /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; - EA7EB12BDE27575738D26AD4 /* SimpleBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */; }; - EAD78B74CDD8AA95ADC26126 /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = C5FB515A9B4B929026438A90 /* SwinjectApiSpec.swift */; }; + EA0D19F7DF0355C774B0F40B /* ScopesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D3C59E84B5FD0C13F487838 /* ScopesSpec.swift */; }; EB3420214A9E68A0247D0F2C /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 351C4221896DDB8572BD6CB5 /* Person.swift */; }; EB79ECF5C893F63B22355167 /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; EBC64A1515C868E410C83451 /* SwiftCode.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 90191C25A2D66E07C4E9CD73 /* SwiftCode.swifttemplate */; }; @@ -341,12 +331,14 @@ EF79F0B3D497215D4BBBC038 /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92B8E618A08408404FB2A7A /* TypeBinder.swift */; }; EFD2F695B86E74C77F46B7D1 /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; F06DEB671A4B85ABB0E96E51 /* ContextTranslator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */; }; + F1F3BA81462E2362374BD4C4 /* ModulesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75BE3AE3E30DFE42A919D825 /* ModulesSpec.swift */; }; F270DC6FF3901F58C76F3872 /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; F37DA7FC70E254616DBD1BD7 /* ReferenceMakerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 388605A438343F7BB80D521E /* ReferenceMakerSpec.swift */; }; F39521855B858534A8D53C8F /* Closable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D0BCCCD61CD9BECC29E064 /* Closable.swift */; }; F504C2ABEFCFFCAC8B858751 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; F568382FB877060127790413 /* Resolver+LegacyApi.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */; }; F6CF010989F531AB0A27B5A1 /* BindingKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = A24B4E8F1CA18603DBB6884A /* BindingKey.swift */; }; + F6EEF5F7B57DC0E44EF569A4 /* OptionalsSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50D6F2639990DD5BAD9578B0 /* OptionalsSpec.swift */; }; F7979BE4BE1B1C7101D15E61 /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; F7CD04FB09FC7F18E9E001CF /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; F8EB47A631D482A0D7B621DE /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; @@ -482,9 +474,10 @@ 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .swiftlint.yml; sourceTree = ""; }; 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SynchronizedResolverSpec.swift; sourceTree = ""; }; 13513FA012659ADE699A3608 /* LazySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LazySpec.swift; sourceTree = ""; }; - 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleBindingSpec.swift; sourceTree = ""; }; 1A006CC804F9AB8ACC121029 /* Utils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = ""; }; + 1B3797A6BB56AE76CEC19F2A /* SwinjectApiSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectApiSpec.swift; sourceTree = ""; }; 1C58FC14EEA170B0DC079DE4 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; + 1D3C59E84B5FD0C13F487838 /* ScopesSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopesSpec.swift; sourceTree = ""; }; 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Circularity.swift; sourceTree = ""; }; 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Behavior.swift; sourceTree = ""; }; 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Arguments.swift; sourceTree = ""; }; @@ -501,7 +494,6 @@ 388605A438343F7BB80D521E /* ReferenceMakerSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReferenceMakerSpec.swift; sourceTree = ""; }; 38BCCF3F950869BD1891F7A8 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaggedTypeSpec.swift; sourceTree = ""; }; - 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingKeySpec.swift; sourceTree = ""; }; 42490D1D0C395951243F5CFF /* Container.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.swift; sourceTree = ""; }; 4286F98133270A36F19E5CD0 /* AutoMockable.stencil */ = {isa = PBXFileReference; lastKnownFileType = text; path = AutoMockable.stencil; sourceTree = ""; }; 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmploymentAssembly.swift; sourceTree = ""; }; @@ -511,6 +503,7 @@ 4BC5108ED11A3A3084D864CC /* Animal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Animal.swift; sourceTree = ""; }; 4D31F8718D2E847922530C20 /* Templates.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Templates.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 5057BAB33984E3E33469452B /* Scope.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Scope.swift; sourceTree = ""; }; + 50D6F2639990DD5BAD9578B0 /* OptionalsSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OptionalsSpec.swift; sourceTree = ""; }; 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Resolver+Injection.swift"; sourceTree = ""; }; 59111BE319C59E4CD6CF68CD /* Assembler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Assembler.swift; sourceTree = ""; }; 5AB605ED0F735221D0EB1D5F /* Convenience.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Convenience.swift; sourceTree = ""; }; @@ -520,14 +513,17 @@ 61EE5DDBE705B47AFC9A6986 /* LoadAwareAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadAwareAssembly.swift; sourceTree = ""; }; 62682D6ED38742996624B041 /* BasicAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BasicAssembly.swift; sourceTree = ""; }; 65D0BCCCD61CD9BECC29E064 /* Closable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Closable.swift; sourceTree = ""; }; + 670DB253ECD5CE1468A7F2E3 /* InjectionSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InjectionSpec.swift; sourceTree = ""; }; 683A1FB7D7F4E9508D57E936 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceWrapper.swift; sourceTree = ""; }; 6D434EB4C13CF9D9FA6D80CB /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 6D54F152C11C966ECFC55ECB /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 6E59A67F3548663368788B17 /* BindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingSpec.swift; sourceTree = ""; }; 722CAC1761180366DE75A4A6 /* TestModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestModels.swift; sourceTree = ""; }; 73B4B777290FF5D38A8914CC /* Reference.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Reference.swift; sourceTree = ""; }; 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.CustomStringConvertible.swift; sourceTree = ""; }; 74DE57FB3E8228904E6FE0D7 /* Swinject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Swinject.h; sourceTree = ""; }; + 75BE3AE3E30DFE42A919D825 /* ModulesSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModulesSpec.swift; sourceTree = ""; }; 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ServiceEntry+TypeForwarding.swift"; sourceTree = ""; }; 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextTranslator.swift; sourceTree = ""; }; 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistry.swift; sourceTree = ""; }; @@ -538,7 +534,7 @@ 8B9785AAE94A5447FA307242 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTreeBuilderSpec.swift; sourceTree = ""; }; 90191C25A2D66E07C4E9CD73 /* SwiftCode.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = SwiftCode.swifttemplate; sourceTree = ""; }; - 9527A4CA5BCBA7AFA3596757 /* SwinjectSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectSpec.swift; sourceTree = ""; }; + 938425B216B78A06EC10504A /* LinuxConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinuxConfig.swift; sourceTree = ""; }; 9620155728133F451B31C0AD /* Swinject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Swinject.swift; sourceTree = ""; }; 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistryKey.swift; sourceTree = ""; }; A10187BB3A994165E7FC1528 /* ScopedBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopedBinding.swift; sourceTree = ""; }; @@ -557,26 +553,20 @@ BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "ServiceEntry+TypeForwarding.swifttemplate"; sourceTree = ""; }; BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Behavior.swift; sourceTree = ""; }; C074BAC560F277E806146C60 /* SimpleBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleBinding.swift; sourceTree = ""; }; + C1E726A651C3AFE92C19608B /* SwinjectModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectModule.swift; sourceTree = ""; }; C3C516EFA0CA22D19F07B27E /* InjectionVariation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InjectionVariation.swift; sourceTree = ""; }; - C5FB515A9B4B929026438A90 /* SwinjectApiSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectApiSpec.swift; sourceTree = ""; }; C68B98C653ABDED9C3D17DB3 /* Opaque.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Opaque.swift; sourceTree = ""; }; C765B92B00C0AC8625BB4AC9 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; CADDB3E9E363310028AA5920 /* InstanceMaker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceMaker.swift; sourceTree = ""; }; CC85CB215058F95C0BC190B1 /* Bridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bridge.swift; sourceTree = ""; }; - CD1BEB4E22ED8BDD009168AE /* InjectionSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InjectionSpec.swift; sourceTree = ""; }; - CD77892122ECF8F100560AB7 /* ModulesSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModulesSpec.swift; sourceTree = ""; }; - CD77892722ECF9C700560AB7 /* ScopesSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopesSpec.swift; sourceTree = ""; }; - CD77892C22ED009C00560AB7 /* BindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingSpec.swift; sourceTree = ""; }; - CD77893122ED05C500560AB7 /* OptionalsSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OptionalsSpec.swift; sourceTree = ""; }; - CD92116322ECC05600211BF0 /* LinuxConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinuxConfig.swift; sourceTree = ""; }; CDA78290D6D60BD0B808571F /* Container+Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Logging.swift"; sourceTree = ""; }; CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; + DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextSpec.swift; sourceTree = ""; }; E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRequest.swift; sourceTree = ""; }; E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; F290F6B1207A0557A528220B /* Assembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Assembly.swift; sourceTree = ""; }; F446D6BD4C44E16A1D608BFB /* Container+TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+TypeForwarding.swift"; sourceTree = ""; }; F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.TypeForwarding.swift; sourceTree = ""; }; - FCAF491EC7DCD7477F9A0ECB /* SwinjectModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectModule.swift; sourceTree = ""; }; FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderEnvironmentSpec.swift; sourceTree = ""; }; FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+LegacyApi.swifttemplate"; sourceTree = ""; }; /* End PBXFileReference section */ @@ -647,13 +637,10 @@ isa = PBXGroup; children = ( FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */, - 40E8C8D605989E2D208BEB5D /* BindingKeySpec.swift */, 388605A438343F7BB80D521E /* ReferenceMakerSpec.swift */, 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */, 2902FD4C1A50263340A51FFB /* ScopeRegistryKeySpec.swift */, - 1855CAD6965A000DDC9FF264 /* SimpleBindingSpec.swift */, BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */, - 9527A4CA5BCBA7AFA3596757 /* SwinjectSpec.swift */, 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */, 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */, ); @@ -780,12 +767,13 @@ 9A6E5EB655CFE64BBCF5DED1 /* 3.0 API */ = { isa = PBXGroup; children = ( - C5FB515A9B4B929026438A90 /* SwinjectApiSpec.swift */, - CD77892C22ED009C00560AB7 /* BindingSpec.swift */, - CD1BEB4E22ED8BDD009168AE /* InjectionSpec.swift */, - CD77893122ED05C500560AB7 /* OptionalsSpec.swift */, - CD77892122ECF8F100560AB7 /* ModulesSpec.swift */, - CD77892722ECF9C700560AB7 /* ScopesSpec.swift */, + 6E59A67F3548663368788B17 /* BindingSpec.swift */, + DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */, + 670DB253ECD5CE1468A7F2E3 /* InjectionSpec.swift */, + 75BE3AE3E30DFE42A919D825 /* ModulesSpec.swift */, + 50D6F2639990DD5BAD9578B0 /* OptionalsSpec.swift */, + 1D3C59E84B5FD0C13F487838 /* ScopesSpec.swift */, + 1B3797A6BB56AE76CEC19F2A /* SwinjectApiSpec.swift */, ); path = "3.0 API"; sourceTree = ""; @@ -809,11 +797,11 @@ children = ( 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */, 10480F2154EAA0414D4C1F55 /* Info.plist */, + 938425B216B78A06EC10504A /* LinuxConfig.swift */, F64B4AFEC15ABABB3014A636 /* 2.0 API */, 9A6E5EB655CFE64BBCF5DED1 /* 3.0 API */, 4F46C48FA15F512EAED5F67A /* Support */, 0A05322134E988A4593B5122 /* Unit Specs */, - CD92116322ECC05600211BF0 /* LinuxConfig.swift */, ); path = Tests; sourceTree = ""; @@ -863,7 +851,6 @@ FCA9C6262A4D071C8E7EEBD0 /* Core */ = { isa = PBXGroup; children = ( - FCAF491EC7DCD7477F9A0ECB /* SwinjectModule.swift */, 0E0B580B43E1891812C97209 /* Binding.swift */, A24B4E8F1CA18603DBB6884A /* BindingKey.swift */, 65D0BCCCD61CD9BECC29E064 /* Closable.swift */, @@ -881,6 +868,7 @@ C074BAC560F277E806146C60 /* SimpleBinding.swift */, 9620155728133F451B31C0AD /* Swinject.swift */, A3586A4987B7C7C8122D674E /* SwinjectError.swift */, + C1E726A651C3AFE92C19608B /* SwinjectModule.swift */, 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */, E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */, ); @@ -1454,7 +1442,7 @@ B9550BE2BA6FA5731BEC87FD /* Swinject+Builder.swift in Sources */, 33391EBA040E82DFB0A37015 /* Swinject.swift in Sources */, 020DA1718FCC68D889FB5A5F /* SwinjectError.swift in Sources */, - CAF3BCDC752C821491AE8714 /* SwinjectModule.swift in Sources */, + CF4EBB60C21F8C503BCD7A29 /* SwinjectModule.swift in Sources */, 0D5C4A278A16AB3A163148AF /* SwinjectTree.swift in Sources */, AB864E029E996492ED4A3A52 /* TypeBinder.swift in Sources */, 49685AB40BEE856C62005C87 /* TypeDescriptor.swift in Sources */, @@ -1478,10 +1466,9 @@ BD08D3E155AFD841CFECA0AD /* Animal.swift in Sources */, 02410BD4FB357F4C6B521608 /* AssemblerSpec.swift in Sources */, DD29D2E60DA979D61F32A39A /* BasicAssembly.swift in Sources */, - CD77893222ED05C500560AB7 /* OptionalsSpec.swift in Sources */, 3129A37CDC1653C11800E24A /* BehaviorFakes.swift in Sources */, 216D6360147B43F5F47C9EA2 /* BinderEnvironmentSpec.swift in Sources */, - 0BCA618354F1B2867A7FB261 /* BindingKeySpec.swift in Sources */, + 9A2A6978519F2BBA97DA6EA6 /* BindingSpec.swift in Sources */, 89E2997CB8B90368A15A91CE /* Bridge.swift in Sources */, 0946D0D940D38828FD0DFBAD /* Circularity.swift in Sources */, 68D828A3C583DDD28CFE882B /* ContainerSpec.Arguments.swift in Sources */, @@ -1490,31 +1477,30 @@ B3062AB22373AD23052B61DF /* ContainerSpec.CustomStringConvertible.swift in Sources */, A1A2D0FA98038EACAC04E64C /* ContainerSpec.TypeForwarding.swift in Sources */, C1687ACA897DEFD3A8197CCD /* ContainerSpec.swift in Sources */, + 832C9ABB8DCF5340D796F5F8 /* ContextSpec.swift in Sources */, EE35DF2D353E2C5110DA5C42 /* Convenience.swift in Sources */, 934AFACA6BFF24AD3503F98D /* EmploymentAssembly.swift in Sources */, 180DB4397B4C05E26F819C85 /* Food.swift in Sources */, 9A8164D6696C87BFEC7325C3 /* GeneratedMocks.swift in Sources */, + 818DF17D671EA1022CE59A2A /* InjectionSpec.swift in Sources */, AE6EAB8CC32ED5E1789D55B7 /* LazySpec.swift in Sources */, - CD1BEB4F22ED8BDD009168AE /* InjectionSpec.swift in Sources */, + A834D948AB86794CA3304B98 /* LinuxConfig.swift in Sources */, B0B139FADA6AE07C79847EBA /* LoadAwareAssembly.swift in Sources */, - CD77892D22ED009C00560AB7 /* BindingSpec.swift in Sources */, + F1F3BA81462E2362374BD4C4 /* ModulesSpec.swift in Sources */, 2C1BD6D785E310B6F8A3CAC9 /* NonGeneratedMocks.swift in Sources */, + 72F09FC92FFB0F7C32D8E2A5 /* OptionalsSpec.swift in Sources */, 628EBFBA0031B1FA2E29F583 /* Person.swift in Sources */, 708E1C453CBC76ED26FA2FCB /* ProviderSpec.swift in Sources */, 7BBB627731769BD052696A7E /* ReferenceMakerSpec.swift in Sources */, 7CABC0D9C2F99BC37CC85517 /* ScopeRegistryKeySpec.swift in Sources */, B3549C40707070622D261363 /* ScopedBindingSpec.swift in Sources */, - 838E49C5683FA93A3A917346 /* SimpleBindingSpec.swift in Sources */, + 33B86F2D33219879731CDDF0 /* ScopesSpec.swift in Sources */, 72217E47D83C3CA6D97640B9 /* StandardScopeRegistrySpec.swift in Sources */, - 1BE678F7FA5DF0E6ED2CF565 /* SwinjectApiSpec.swift in Sources */, - 1183FED17E9521E848F1F991 /* SwinjectSpec.swift in Sources */, + 0DC084A3650745492BB81EE9 /* SwinjectApiSpec.swift in Sources */, 640F7A55D9A671FA112C8083 /* SwinjectTreeBuilderSpec.swift in Sources */, F7CD04FB09FC7F18E9E001CF /* SynchronizedResolverSpec.swift in Sources */, 9AD60A86D5A0DF4513C1EA8D /* TaggedTypeSpec.swift in Sources */, 778D9AB6470D4280254AC140 /* TestModels.swift in Sources */, - CD77892822ECF9C700560AB7 /* ScopesSpec.swift in Sources */, - CD77892222ECF8F100560AB7 /* ModulesSpec.swift in Sources */, - CD92116422ECC05600211BF0 /* LinuxConfig.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1525,10 +1511,9 @@ A6EECC339FA54CA0BBFF4146 /* Animal.swift in Sources */, CBBE28990E0EA82AD8D5E3AF /* AssemblerSpec.swift in Sources */, 401592294E5D528379BE1AB2 /* BasicAssembly.swift in Sources */, - CD77893322ED05C500560AB7 /* OptionalsSpec.swift in Sources */, A3BFFED76688F149FBAF7C53 /* BehaviorFakes.swift in Sources */, 56D43738C09AA7355F6D529D /* BinderEnvironmentSpec.swift in Sources */, - 6203E6494C12ECE21323F512 /* BindingKeySpec.swift in Sources */, + BB77A5D81C58392964D07233 /* BindingSpec.swift in Sources */, 13CDEC7A6C8E43B58D5CBE3D /* Bridge.swift in Sources */, 2B88BFD81C226C858E0AE2B6 /* Circularity.swift in Sources */, 83464EDC08380F5CE2190F30 /* ContainerSpec.Arguments.swift in Sources */, @@ -1537,31 +1522,30 @@ 2B506344F37CE5F5C5C02C05 /* ContainerSpec.CustomStringConvertible.swift in Sources */, E01D0D443FBA4DB82A6EC298 /* ContainerSpec.TypeForwarding.swift in Sources */, A9A242086D1EDE408DC556D0 /* ContainerSpec.swift in Sources */, + 1C62135FAE3D64DC7BFBF861 /* ContextSpec.swift in Sources */, A882705E4199EF759E80B311 /* Convenience.swift in Sources */, 19416C867F15E88394A0ABD1 /* EmploymentAssembly.swift in Sources */, 590B861A863A056A0B7FA368 /* Food.swift in Sources */, 9C12EB42EC058994805E93A6 /* GeneratedMocks.swift in Sources */, + 95A6654089875BCC863FB53B /* InjectionSpec.swift in Sources */, 979518E078B187549E11DF48 /* LazySpec.swift in Sources */, - CD1BEB5022ED8BDD009168AE /* InjectionSpec.swift in Sources */, + B96A6370D549AAC383360ABC /* LinuxConfig.swift in Sources */, 335CE53CEC2360DC86D58F07 /* LoadAwareAssembly.swift in Sources */, - CD77892E22ED009C00560AB7 /* BindingSpec.swift in Sources */, + 004B06007E4FDD8F44B7EC89 /* ModulesSpec.swift in Sources */, 56B2AD6054B63420DD025EC6 /* NonGeneratedMocks.swift in Sources */, + D941D81F59900A52805D6B4A /* OptionalsSpec.swift in Sources */, EB3420214A9E68A0247D0F2C /* Person.swift in Sources */, CF9535A0DCAFF23F4D62F871 /* ProviderSpec.swift in Sources */, FB446EB8754FDAAE011C4362 /* ReferenceMakerSpec.swift in Sources */, C243400E417F4A91E491B5EB /* ScopeRegistryKeySpec.swift in Sources */, CEA4CB2D3113EC693C590B9D /* ScopedBindingSpec.swift in Sources */, - EA7EB12BDE27575738D26AD4 /* SimpleBindingSpec.swift in Sources */, + 0068DAA4AA322F00AF53731F /* ScopesSpec.swift in Sources */, C952D5869D87743297968E9A /* StandardScopeRegistrySpec.swift in Sources */, - EAD78B74CDD8AA95ADC26126 /* SwinjectApiSpec.swift in Sources */, - 8CE52672848FD54520215CA1 /* SwinjectSpec.swift in Sources */, + 273F441B941A6DF76D9BD752 /* SwinjectApiSpec.swift in Sources */, A308578B99D33C7E33632E85 /* SwinjectTreeBuilderSpec.swift in Sources */, 3BDB44DE92D2377334894804 /* SynchronizedResolverSpec.swift in Sources */, A5302886A31C90F38512B88E /* TaggedTypeSpec.swift in Sources */, 2615FC1C92B7E381116B9E57 /* TestModels.swift in Sources */, - CD77892922ECF9C700560AB7 /* ScopesSpec.swift in Sources */, - CD77892322ECF8F100560AB7 /* ModulesSpec.swift in Sources */, - CD92116522ECC05600211BF0 /* LinuxConfig.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1572,10 +1556,9 @@ A53B5A8E2188F8C4A3F29C2E /* Animal.swift in Sources */, CF4516872D3DA7118DB2B90B /* AssemblerSpec.swift in Sources */, 03122D1B2EA65C89ADC78EC7 /* BasicAssembly.swift in Sources */, - CD77893522ED05C500560AB7 /* OptionalsSpec.swift in Sources */, 1CA5DF3F93203B226A6FA059 /* BehaviorFakes.swift in Sources */, 3F704A98C01C84BDBD0A52B3 /* BinderEnvironmentSpec.swift in Sources */, - 1927B730A0F0E141BFC1773E /* BindingKeySpec.swift in Sources */, + CAA5241DAA201FBB5818C803 /* BindingSpec.swift in Sources */, E4CE31B7B9616EFC93C69341 /* Bridge.swift in Sources */, 4DC8A58B6607898BAF6504A3 /* Circularity.swift in Sources */, 8436D091ED844817C8CE3AF2 /* ContainerSpec.Arguments.swift in Sources */, @@ -1584,31 +1567,30 @@ 7D6F664091C70BABBFB61D53 /* ContainerSpec.CustomStringConvertible.swift in Sources */, 196338EA802A39E205C33B43 /* ContainerSpec.TypeForwarding.swift in Sources */, F270DC6FF3901F58C76F3872 /* ContainerSpec.swift in Sources */, + 49D71F6CC12C12FE7B6A097A /* ContextSpec.swift in Sources */, EEAD7E215908DF939ECCDCC9 /* Convenience.swift in Sources */, 4E4DC8CDD1BA51FB66A332C2 /* EmploymentAssembly.swift in Sources */, BE6C13A3492E3CFC08E231B0 /* Food.swift in Sources */, CB06DC3BC4A32776BBD90DDF /* GeneratedMocks.swift in Sources */, + 42FE916C1593A9289E1A28BC /* InjectionSpec.swift in Sources */, 6A0FD11468B3852E48B682BE /* LazySpec.swift in Sources */, - CD1BEB5222ED8BDD009168AE /* InjectionSpec.swift in Sources */, + B00627BABCF9181C7B58609E /* LinuxConfig.swift in Sources */, ED6CB3935B15F30A182ED6D0 /* LoadAwareAssembly.swift in Sources */, - CD77893022ED009C00560AB7 /* BindingSpec.swift in Sources */, + D9F132E4A6F6BC2BDD5DFCAA /* ModulesSpec.swift in Sources */, 7AE3FF1C0B4860942D90B68B /* NonGeneratedMocks.swift in Sources */, + A453A5A7E0EC0FE161AA34D5 /* OptionalsSpec.swift in Sources */, C76374CAFE7C2BCCE52F1BB1 /* Person.swift in Sources */, 4954CBB07E38E98752AC3347 /* ProviderSpec.swift in Sources */, F37DA7FC70E254616DBD1BD7 /* ReferenceMakerSpec.swift in Sources */, 4B9BAB1D38AB0C08F8CA25F5 /* ScopeRegistryKeySpec.swift in Sources */, C4CB7A3BA35A1E0811842971 /* ScopedBindingSpec.swift in Sources */, - DB03A9B61E162A73506C8552 /* SimpleBindingSpec.swift in Sources */, + 31729A1E5F50EF30FDD427AD /* ScopesSpec.swift in Sources */, 0720BEA814AD514378380ACB /* StandardScopeRegistrySpec.swift in Sources */, - 05B18A91CA201F7EE53F3ADE /* SwinjectApiSpec.swift in Sources */, - 53AC03FA6538E56A976E52FA /* SwinjectSpec.swift in Sources */, + 3F0DCA7060C62712EA30CBB1 /* SwinjectApiSpec.swift in Sources */, 3CEF021295AD9AF9BF26B71E /* SwinjectTreeBuilderSpec.swift in Sources */, 546FF827DB6D42490D1CA439 /* SynchronizedResolverSpec.swift in Sources */, 09470890A74A5DDE7114891B /* TaggedTypeSpec.swift in Sources */, CB9E8D16D7A0620A1F7A32A3 /* TestModels.swift in Sources */, - CD77892B22ECF9C700560AB7 /* ScopesSpec.swift in Sources */, - CD77892522ECF8F100560AB7 /* ModulesSpec.swift in Sources */, - CD92116722ECC05600211BF0 /* LinuxConfig.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1619,10 +1601,9 @@ D13208E63523A97A0B840283 /* Animal.swift in Sources */, 2AA60B7E6EBA9EC6BE92D7CB /* AssemblerSpec.swift in Sources */, 599C7F009F954CDA522244B3 /* BasicAssembly.swift in Sources */, - CD77893422ED05C500560AB7 /* OptionalsSpec.swift in Sources */, 8E1E051646BBD6E38F4199C2 /* BehaviorFakes.swift in Sources */, 4A977D2B639B8098AA508389 /* BinderEnvironmentSpec.swift in Sources */, - A5A7F3C866C17F071C5D976C /* BindingKeySpec.swift in Sources */, + 0207493E1CEE8456E91E3DAE /* BindingSpec.swift in Sources */, 43A74237D8933572BAA0F3B4 /* Bridge.swift in Sources */, C177D9C6969ADA38C1094F6D /* Circularity.swift in Sources */, A70936B898139A6C5F83F616 /* ContainerSpec.Arguments.swift in Sources */, @@ -1631,31 +1612,30 @@ 54956014A1774DF8357B69E6 /* ContainerSpec.CustomStringConvertible.swift in Sources */, 3C270A77DE4F1E6BC2F8E863 /* ContainerSpec.TypeForwarding.swift in Sources */, CA5523B60E51EB98719CF1F8 /* ContainerSpec.swift in Sources */, + 86CBC40FDC90E2A2051386C5 /* ContextSpec.swift in Sources */, 48D1568CB41BE4B6597FD535 /* Convenience.swift in Sources */, A59C6C434288333EDAF951C4 /* EmploymentAssembly.swift in Sources */, C38A2EBF4D1904E7D6989989 /* Food.swift in Sources */, B703A24C1A963C6BAC95B9A5 /* GeneratedMocks.swift in Sources */, + AD214F3DBAB4F16C88322CAC /* InjectionSpec.swift in Sources */, 0CD787EACEBFD1051D358E7D /* LazySpec.swift in Sources */, - CD1BEB5122ED8BDD009168AE /* InjectionSpec.swift in Sources */, + 70368EC369287B4EE767E929 /* LinuxConfig.swift in Sources */, A2D3B18BE38948A427B60BC5 /* LoadAwareAssembly.swift in Sources */, - CD77892F22ED009C00560AB7 /* BindingSpec.swift in Sources */, + 55F2E72EA8C3564130F66946 /* ModulesSpec.swift in Sources */, C4E9DC50A2FDAE4D36A925D9 /* NonGeneratedMocks.swift in Sources */, + F6EEF5F7B57DC0E44EF569A4 /* OptionalsSpec.swift in Sources */, BEEFBE87EB17D56BA8D47358 /* Person.swift in Sources */, 48F40377D116C6B1B786C329 /* ProviderSpec.swift in Sources */, BD01D1F86970237D6D5C8D38 /* ReferenceMakerSpec.swift in Sources */, 181204958559CE25462AA6EF /* ScopeRegistryKeySpec.swift in Sources */, 3575DE21531F7365B713B64B /* ScopedBindingSpec.swift in Sources */, - 15246957A062BF0ED7134E0E /* SimpleBindingSpec.swift in Sources */, + EA0D19F7DF0355C774B0F40B /* ScopesSpec.swift in Sources */, 0B61DC733616A8ED4ED77FA7 /* StandardScopeRegistrySpec.swift in Sources */, - 7337BA3B0248BE5A4C8C1339 /* SwinjectApiSpec.swift in Sources */, - 45D57E61D4774613F2DF1CCA /* SwinjectSpec.swift in Sources */, + 4EFB0A66BBCAA617470CE622 /* SwinjectApiSpec.swift in Sources */, 233F3E25FF0B51A3E6611F58 /* SwinjectTreeBuilderSpec.swift in Sources */, 890CCD2800597F6FB7C6FD31 /* SynchronizedResolverSpec.swift in Sources */, 24114725AE1A834C6E3118F7 /* TaggedTypeSpec.swift in Sources */, 6034CF5459D96497AF36E4B6 /* TestModels.swift in Sources */, - CD77892A22ECF9C700560AB7 /* ScopesSpec.swift in Sources */, - CD77892422ECF8F100560AB7 /* ModulesSpec.swift in Sources */, - CD92116622ECC05600211BF0 /* LinuxConfig.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1695,7 +1675,7 @@ EFD2F695B86E74C77F46B7D1 /* Swinject+Builder.swift in Sources */, 63528D45A548DD58D748D54C /* Swinject.swift in Sources */, 91E435894038C42335086FA8 /* SwinjectError.swift in Sources */, - CDBBA4023FE01CE4EFEE143A /* SwinjectModule.swift in Sources */, + C637E97E193BB1DADDDC6C21 /* SwinjectModule.swift in Sources */, 0CE1126436F680F9684837E4 /* SwinjectTree.swift in Sources */, 4B9811CF0604946CCF323ED2 /* TypeBinder.swift in Sources */, 9CEE20BD42795D5E5F39BF20 /* TypeDescriptor.swift in Sources */, @@ -1738,7 +1718,7 @@ DCB7C4BF24782862BE9DB135 /* Swinject+Builder.swift in Sources */, 75D74C8C25EDACF5A7A75A5C /* Swinject.swift in Sources */, 4DF3DC1CDD3C4948F9BDD3DF /* SwinjectError.swift in Sources */, - D54DFEDF33F09035F3177248 /* SwinjectModule.swift in Sources */, + 82299769BC637A14E7827DB0 /* SwinjectModule.swift in Sources */, 372F0061E762BF8FFF05457F /* SwinjectTree.swift in Sources */, 9425887520AC2DBDCBACB252 /* TypeBinder.swift in Sources */, AC470B4322599B0A076DD3FF /* TypeDescriptor.swift in Sources */, @@ -1781,7 +1761,7 @@ 6C01E868DE44BD396D94858B /* Swinject+Builder.swift in Sources */, 4EC94A51037C79DE0C5C8CB1 /* Swinject.swift in Sources */, 820307073A53AED47AC99B8D /* SwinjectError.swift in Sources */, - 732A8933C1310C2A6309E56B /* SwinjectModule.swift in Sources */, + 8E77B56EE7F90BF723600DDF /* SwinjectModule.swift in Sources */, 6922AE734E84B515C94D9480 /* SwinjectTree.swift in Sources */, EF79F0B3D497215D4BBBC038 /* TypeBinder.swift in Sources */, E3EABE098DBFB561A20632E3 /* TypeDescriptor.swift in Sources */, diff --git a/Tests/3.0 API/ContextSpec.swift b/Tests/3.0 API/ContextSpec.swift new file mode 100644 index 00000000..cd3e7c40 --- /dev/null +++ b/Tests/3.0 API/ContextSpec.swift @@ -0,0 +1,102 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +import Nimble +import Quick +import Swinject +@testable import class Swinject.UnboundScope + +class ContextSpec: QuickSpec { override func spec() { #if swift(>=5.1) + it("can pass context to the bindings") { + let swinject = Swinject { + bbind(Int.self) & contexted(String.self).provider { (_, c: String) in Int(c)! } + bbind(Double.self) & contexted(String.self).factory { (_, c: String, a: Int) in Double(c)! + Double(a) } + } + expect { try swinject.on("42").instance(of: Int.self) } == 42 + expect { try swinject.on("25").instance(of: Double.self, arg: 17) } == 42 + } + it("throws if injecting on the wrong context") { + let swinject = Swinject { + bbind(Int.self) & contexted(Double.self).provider { (_, c: Double) in Int(c) } + } + expect { try swinject.on("context").instance(of: Int.self) }.to(throwError()) + } + it("does not invoke bindings on other contexts") { + var invoked = false + let swinject = Swinject { + bbind(Int.self) & contexted(String.self).provider { (_, _: String) in 42 } + bbind(Int.self) & contexted(Double.self).provider { (_, _: Double) in + invoked = true + return 42 + } + } + _ = try? swinject.on("context").instance(of: Int.self) + expect(invoked) == false + } + it("can use binding without context in any context") { + let swinject = Swinject { + bbind(Int.self) & 42 + } + expect { try swinject.on("context").instance() as Int } == 42 + expect { try swinject.on(Human()).instance() as Int } == 42 + } + it("passes context to the dependencies") { + let john = Human() + let swinject = Swinject { + bbind(Human.self) & contexted(String.self).provider { (_, c: String) in + c == "john" ? john : Human() + } + bbind(Pet.self) & provider { Pet(owner: try $0.instance()) } + } + let pet = try? swinject.on("john").instance(of: Pet.self) + expect(pet?.owner) === john + } + describe("translators") { + it("can translate contexts") { + let john = Human() + // FIXME: compiler segfaults if declaring this provider in functionBuilder + let petProvider = contexted(Human.self).provider { Pet(owner: $1) } + let swinject = Swinject { + bbind(Pet.self) & petProvider + registerContextTranslator(from: String.self) { $0 == "john" ? john : Human() } + } + let pet = try? swinject.on("john").instance(of: Pet.self) + expect(pet?.owner) === john + } + it("throws if translator has incorrect types") { + let swinject = Swinject { + bbind(Int.self) & contexted(String.self).provider { (_, c: String) in Int(c)! } + registerContextTranslator(from: Float.self) { String($0) } + registerContextTranslator(from: Double.self) { Int($0) } + } + expect { try swinject.on(42.0).instance(of: Int.self) }.to(throwError()) + } + it("throws if multiple bindings could be used with translated contexts") { + let swinject = Swinject { + bbind(Int.self) & contexted(Float.self).provider { (_, c: Float) in Int(c) } + bbind(Int.self) & contexted(Double.self).provider { (_, c: Double) in Int(c) } + registerContextTranslator(from: String.self) { Float($0)! } + registerContextTranslator(from: String.self) { Double($0)! } + } + expect { try swinject.on("42").instance(of: Int.self) }.to(throwError()) + } + it("throws if has binding on given context and translator leading to other binding") { + let swinject = Swinject { + bbind(Int.self) & contexted(String.self).provider { (_, c: String) in Int(c)! } + bbind(Int.self) & contexted(Double.self).provider { (_, c: Double) in Int(c) } + registerContextTranslator(from: String.self) { Double($0)! } + } + expect { try swinject.on("42").instance(of: Int.self) }.to(throwError()) + } + it("does not throw if multiple translators lead to the same binding") { + let swinject = Swinject { + bbind(Int.self) & contexted(Any.self).provider { _, _ in 42 } + registerContextTranslator(from: Double.self) { "\($0)" } + registerContextTranslator(from: Double.self) { Float($0) } + } + expect { try swinject.on(42.0).instance(of: Int.self) }.notTo(throwError()) + } + } + #endif +} } diff --git a/Tests/3.0 API/SwinjectApiSpec.swift b/Tests/3.0 API/SwinjectApiSpec.swift index d5856820..dad90978 100644 --- a/Tests/3.0 API/SwinjectApiSpec.swift +++ b/Tests/3.0 API/SwinjectApiSpec.swift @@ -11,39 +11,6 @@ class SwinjectApiSpec: QuickSpec { override func spec() { #if swift(>=5.1) beforeEach { UnboundScope.root.close() } - it("can pass context to the bindings") { - // FIXME: compiler segfaults if declaring these providers inside function builder - let intProvider = contexted(String.self).provider { _, string in Int(string)! } - let doubleProvider = contexted(String.self).provider { _, string in Double(string)! } - let swinject = Swinject { - bbind(Int.self) & intProvider - bbind(Double.self) & doubleProvider - } - let contexted = swinject.on("42") - expect { try contexted.instance(of: Int.self) } == 42 - expect { try contexted.instance(of: Double.self) } == 42 - expect { try swinject.instance(of: Int.self) }.to(throwError()) - } - it("can use binding without context in any context") { - let swinject = Swinject { - bbind(Int.self) & 42 - } - expect { try swinject.on("context").instance() as Int } == 42 - expect { try swinject.on(Human()).instance() as Int } == 42 - } - it("can translate contexts") { - // FIXME: compiler segfaults if declaring these providers inside function builder - let intProvider = contexted(String.self).provider { _, string in Int(string)! } - let doubleProvider = contexted(Int.self).provider { _, int in Double(int) } - let swinject = Swinject { - bbind(Int.self) & intProvider - bbind(Double.self) & doubleProvider - registerContextTranslator(from: String.self) { Int($0)! } - } - let contexted = swinject.on("42") - expect { try contexted.instance(of: Int.self) } == 42 - expect { try contexted.instance(of: Double.self) } == 42 - } it("can bind singleton") { let swinject = Swinject { bbind(Human.self) & singleton { Human() } diff --git a/Tests/LinuxConfig.swift b/Tests/LinuxConfig.swift index 6b64e84e..d7d5ad91 100644 --- a/Tests/LinuxConfig.swift +++ b/Tests/LinuxConfig.swift @@ -21,6 +21,7 @@ let allSpecs: [QuickSpec.Type] = [ BindingSpec.self, InjectionSpec.self, ModulesSpec.self, + ContextSpec.self, ScopesSpec.self, OptionalsSpec.self, // Unit Specs @@ -31,7 +32,6 @@ let allSpecs: [QuickSpec.Type] = [ ScopeRegistryKeySpec.self, SimpleBindingSpec.self, StandardScopeRegistrySpec.self, - SwinjectSpec.self, SwinjectTreeBuilderSpec.self, TaggedTypeSpec.self, ] diff --git a/Tests/Unit Specs/BinderEnvironmentSpec.swift b/Tests/Unit Specs/BinderEnvironmentSpec.swift index 0a42132e..4ba1ffe6 100644 --- a/Tests/Unit Specs/BinderEnvironmentSpec.swift +++ b/Tests/Unit Specs/BinderEnvironmentSpec.swift @@ -9,108 +9,6 @@ import Quick // TODO: Reuse code class BinderEnvironmentSpec: QuickSpec { override func spec() { describe("implicit") { - describe("instance") { - it("produces maker with correct type signature") { - let maker = instance(42) - expect(maker.actual is SimpleBinding.Builder).to(beTrue()) - } - it("returns given instance") { - let maker = instance(42) - expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 - } - } - describe("provider") { - it("produces maker with correct type signature") { - let maker = provider { 42 } - expect(maker.actual is SimpleBinding.Builder).to(beTrue()) - } - it("returns instance made by provider method") { - let maker = provider { 42 } - expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 - } - it("does not call builder until instance is requested") { - var called = false - _ = provider { called = true } - expect(called).to(beFalse()) - } - it("calls builder with given resolver") { - var passedResolver: Resolver? - let resolver = DummyResolver() - let maker = provider { passedResolver = $0 } - _ = try? maker.makeInstance(resolver: resolver) - expect(passedResolver) === resolver - } - it("rethrows error from builder") { - let maker = provider { throw SwinjectError() } - expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) - } - it("does not reuse instance") { - let maker = provider { Human() } - let instance1 = try? maker.makeInstance(resolver: DummyResolver()) - let instance2 = try? maker.makeInstance(resolver: DummyResolver()) - expect(instance1) !== instance2 - } - } - describe("factory") { - it("produces maker with correct type signature") { - let maker = factory { (_, _: Void) in 42 } - expect(maker.actual is SimpleBinding.Builder).to(beTrue()) - } - it("returns instance made by builder method") { - let maker = factory { (_, _: Void) in 42 } - expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 - } - it("does not call builder until instance is requested") { - var called = false - _ = factory { (_, _: Void) in called = true } - expect(called).to(beFalse()) - } - it("calls builder with given resolver") { - var passedResolver: Resolver? - let resolver = DummyResolver() - let maker = factory { (r, _: Void) in passedResolver = r } - _ = try? maker.makeInstance(resolver: resolver) - expect(passedResolver) === resolver - } - it("calls builder with given argument") { - var passedArgument: Int? - let maker = factory { (_, arg: Int) in passedArgument = arg } - _ = try? maker.makeInstance(arg: box(42), resolver: DummyResolver()) - expect(passedArgument) == 42 - } - it("rethrows error from builder") { - let maker = factory { (_, _: Void) in throw SwinjectError() } - expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) - } - it("does not reuse instance") { - let maker = factory { (_, _: Void) in Human() } - let instance1 = try? maker.makeInstance(resolver: DummyResolver()) - let instance2 = try? maker.makeInstance(resolver: DummyResolver()) - expect(instance1) !== instance2 - } - describe("multiple arguments") { - it("works with 2 arguments") { - let maker = factory { (_, _: Int, _: Double) in 42 } - let arguments = box(1, 1.0) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 - } - it("works with 3 arguments") { - let maker = factory { (_, _: Int, _: Double, _: String) in 42 } - let arguments = box(1, 1.0, "") - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 - } - it("works with 4 arguments") { - let maker = factory { (_, _: Int, _: Double, _: String, _: Float) in 42 } - let arguments = box(1, 1.0, "", Float(1.0)) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 - } - it("works with 5 arguments") { - let maker = factory { (_, _: Int, _: Double, _: String, _: Float, _: Int) in 42 } - let arguments = box(1, 1.0, "", Float(1.0), 5) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 - } - } - } describe("singleton") { it("has correct scope") { let maker = singleton { 0 }.actual as? ScopedBinding.Builder @@ -216,108 +114,6 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { } } } - describe("contexted") { - var environment: ContextedEnvironment! - beforeEach { - environment = contexted(Any.self) - } - describe("provider") { - it("returns instance made by provider method") { - let maker = environment.provider { _, _ in 42 } - expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 - } - it("does not call builder until instance is requested") { - var called = false - _ = provider { called = true } - expect(called).to(beFalse()) - } - it("calls builder with given resolver") { - var passedResolver: Resolver? - let resolver = DummyResolver() - let maker = environment.provider { r, _ in passedResolver = r } - _ = try? maker.makeInstance(resolver: resolver) - expect(passedResolver) === resolver - } - it("calls builder with given context") { - var passedContext: Any? - let maker = environment.provider { _, c in passedContext = c } - _ = try? maker.makeInstance(context: 42, resolver: DummyResolver()) - expect(passedContext as? Int) == 42 - } - it("rethrows error from builder") { - let maker = environment.provider { _, _ in throw SwinjectError() } - expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) - } - it("does not reuse instance") { - let maker = environment.provider { _, _ in Human() } - let instance1 = try? maker.makeInstance(resolver: DummyResolver()) - let instance2 = try? maker.makeInstance(resolver: DummyResolver()) - expect(instance1) !== instance2 - } - } - describe("factory") { - it("returns instance made by builder method") { - let maker = environment.factory { (_, _, _: Void) in 42 } - expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 - } - it("does not call builder until instance is requested") { - var called = false - _ = environment.factory { (_, _, _: Void) in called = true } - expect(called).to(beFalse()) - } - it("calls builder with given resolver") { - var passedResolver: Resolver? - let resolver = DummyResolver() - let maker = environment.factory { (r, _, _: Void) in passedResolver = r } - _ = try? maker.makeInstance(resolver: resolver) - expect(passedResolver) === resolver - } - it("calls builder with given context") { - var passedContext: Any? - let maker = environment.factory { (_, c, _: Void) in passedContext = c } - _ = try? maker.makeInstance(context: 42, resolver: DummyResolver()) - expect(passedContext as? Int) == 42 - } - it("calls builder with given argument") { - var passedArgument: Int? - let maker = environment.factory { (_, _, arg: Int) in passedArgument = arg } - _ = try? maker.makeInstance(arg: box(42), resolver: DummyResolver()) - expect(passedArgument) == 42 - } - it("rethrows error from builder") { - let maker = environment.factory { (_, _, _: Void) in throw SwinjectError() } - expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) - } - it("does not reuse instance") { - let maker = environment.factory { (_, _, _: Void) in Human() } - let instance1 = try? maker.makeInstance(resolver: DummyResolver()) - let instance2 = try? maker.makeInstance(resolver: DummyResolver()) - expect(instance1) !== instance2 - } - describe("multiple arguments") { - it("works with 2 arguments") { - let maker = environment.factory { (_, _, _: Int, _: Double) in 42 } - let arguments = box(1, 1.0) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 - } - it("works with 3 arguments") { - let maker = environment.factory { (_, _, _: Int, _: Double, _: String) in 42 } - let arguments = box(1, 1.0, "") - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 - } - it("works with 4 arguments") { - let maker = environment.factory { (_, _, _: Int, _: Double, _: String, _: Float) in 42 } - let arguments = box(1, 1.0, "", Float(1.0)) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 - } - it("works with 5 arguments") { - let maker = environment.factory { (_, _, _: Int, _: Double, _: String, _: Float, _: Int) in 42 } - let arguments = box(1, 1.0, "", Float(1.0), 5) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 - } - } - } - } describe("scoped") { var scope = AnyScopeMock() var environment: ScopedEnvironment! diff --git a/Tests/Unit Specs/BindingKeySpec.swift b/Tests/Unit Specs/BindingKeySpec.swift deleted file mode 100644 index 59a48106..00000000 --- a/Tests/Unit Specs/BindingKeySpec.swift +++ /dev/null @@ -1,45 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -import Nimble -import Quick -@testable import Swinject - -class BindingKeySpec: QuickSpec { override func spec() { - describe("matching") { - var descriptor = AnyTypeDescriptorMock() - var otherKey = AnyBindingKeyMock() - beforeEach { - descriptor = AnyTypeDescriptorMock() - descriptor.matchesReturnValue = true - otherKey = AnyBindingKeyMock() - otherKey.descriptor = AnyTypeDescriptorMock() - otherKey.argumentType = Void.self - otherKey.contextType = Void.self - } - it("does not match if context types are different") { - let key = makeKey(descriptor: descriptor, contextType: Int.self) - otherKey.contextType = Double.self - expect(key.matches(otherKey)).to(beFalse()) - } - it("matches if contexts are the same") { - let key = makeKey(descriptor: descriptor, contextType: Int.self) - otherKey.contextType = Int.self - expect(key.matches(otherKey)).to(beTrue()) - } - it("matches if context is Any") { - let key = makeKey(descriptor: descriptor, contextType: Any.self) - otherKey.contextType = Int.self - expect(key.matches(otherKey)).to(beTrue()) - } - } -} } - -private func makeKey( - descriptor: AnyTypeDescriptor, - contextType: Any.Type = Void.self, - argumentType: Any.Type = Void.self -) -> BindingKey { - return BindingKey(descriptor: descriptor, contextType: contextType, argumentType: argumentType) -} diff --git a/Tests/Unit Specs/SimpleBindingSpec.swift b/Tests/Unit Specs/SimpleBindingSpec.swift deleted file mode 100644 index b359e043..00000000 --- a/Tests/Unit Specs/SimpleBindingSpec.swift +++ /dev/null @@ -1,24 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -import Nimble -import Quick -@testable import Swinject - -class SimpleBindingSpec: QuickSpec { override func spec() { - describe("binding builder") { - let builder = SimpleBinding.Builder { _, _, _ in } - it("makes binding with self as maker") { - let binding = builder.makeBinding(for: AnyTypeDescriptorMock()) as? SimpleBinding - expect(binding?.maker is SimpleBinding.Builder).to(beTrue()) - } - it("makes binding with correct key") { - let descriptor = AnyTypeDescriptorMock() - let binding = builder.makeBinding(for: descriptor) as? SimpleBinding - expect(binding?.key.descriptor) === descriptor - expect(binding?.key.contextType is String.Type).to(beTrue()) - expect(binding?.key.argumentType is Int.Type).to(beTrue()) - } - } -} } diff --git a/Tests/Unit Specs/SwinjectSpec.swift b/Tests/Unit Specs/SwinjectSpec.swift deleted file mode 100644 index ab38523f..00000000 --- a/Tests/Unit Specs/SwinjectSpec.swift +++ /dev/null @@ -1,143 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -import Nimble -import Quick -@testable import Swinject - -class SwinjectSpec: QuickSpec { override func spec() { - var swinject: Swinject! - var binding = BindingMock() - beforeEach { - binding = BindingMock() - binding.instanceArgContextResolverReturnValue = 0 - swinject = Swinject(binding) - } - describe("instance injection") { - context("single binding") { - it("matches binding with correct context") { - binding.matchesReturnValue = false - _ = try? swinject.on("context").instance() as Int - expect(binding.matchesReceivedKey?.contextType is String.Type).to(beTrue()) - } - } - } - describe("provider injection") { - it("matches binding with correct context") { - binding.matchesReturnValue = false - _ = try? swinject.on("context").provider()() as Int - expect(binding.matchesReceivedKey?.contextType is String.Type).to(beTrue()) - } - it("passes given context to the binding") { - binding.matchesReturnValue = true - _ = try? swinject.on("context").provider()() as Int - expect(binding.instanceReceivedArguments?.context as? String) == "context" - } - it("passes given context to dependency binding") { - let binding = BindingMock() - binding.matchesClosure = { $0.descriptor.matches(plain(Double.self)) } - binding.instanceArgContextResolverReturnValue = 0.0 - let swinject = Swinject( - bbind(Int.self) & provider { Int(try $0.instance() as Double) }, - binding - ) - _ = try? swinject.on("context").instance(of: Int.self) - expect(binding.instanceReceivedArguments?.context as? String) == "context" - } - } - describe("factory injection") { - it("matches binding with correct context") { - binding.matchesReturnValue = false - _ = try? swinject.on("context").factory()("arg") as Int - expect(binding.matchesReceivedKey?.contextType is String.Type).to(beTrue()) - } - it("passes given context to the bidndning") { - binding.matchesReturnValue = true - _ = try? swinject.on("context").factory()("arg") as Int - expect(binding.instanceReceivedArguments?.context as? String) == "context" - } - } - describe("context translators") { - var translators = [AnyContextTranslatorMock]() - var bindings = [BindingMock]() - beforeEach { - translators = (1 ... 3).map { _ in AnyContextTranslatorMock() } - translators.forEach { - $0.sourceType = Void.self - $0.targetType = Void.self - $0.translateReturnValue = 0 - } - bindings = Array(0 ..< 3).map { _ in BindingMock() } - bindings.forEach { - $0.matchesReturnValue = false - $0.instanceArgContextResolverReturnValue = 0 - } - swinject = Swinject( - bindings[0], bindings[1], bindings[2], - translators[0], translators[1], translators[2] - ) - } - it("does not throw if one of context translators has correct context translation") { - bindings[0].matchesClosure = { $0.contextType == Int.self } - translators[1].sourceType = String.self - translators[1].targetType = Int.self - expect { try swinject.on("context").instance() as Int }.notTo(throwError()) - } - it("throws if translator has incorrect source type") { - bindings[0].matchesClosure = { $0.contextType == Int.self } - translators[1].sourceType = Double.self - translators[1].targetType = Int.self - expect { try swinject.on("context").instance() as Int }.to(throwError()) - } - it("throws if multiple translators have correct translation") { - bindings[0].matchesClosure = { $0.contextType == Int.self } - bindings[1].matchesClosure = { $0.contextType == Float.self } - translators[0].sourceType = String.self - translators[0].targetType = Int.self - translators[1].sourceType = String.self - translators[1].targetType = Float.self - expect { try swinject.on("context").instance() as Int }.to(throwError()) - } - it("does not throw if multiple translators have correct target type but not source type") { - bindings[0].matchesClosure = { $0.contextType == Int.self } - bindings[1].matchesClosure = { $0.contextType == Float.self } - translators[0].sourceType = String.self - translators[0].targetType = Int.self - translators[1].sourceType = Double.self - translators[1].targetType = Float.self - expect { try swinject.on("context").instance() }.notTo(throwError()) - } - it("throws if has binding for given context and translator with correct context translation") { - bindings[0].matchesClosure = { $0.contextType == Int.self } - bindings[1].matchesClosure = { $0.contextType == String.self } - translators[0].sourceType = String.self - translators[0].targetType = Int.self - expect { try swinject.on("context").instance() as Int }.to(throwError()) - } - it("passes translated context to binding") { - bindings[0].matchesClosure = { $0.contextType == Int.self } - translators[0].sourceType = String.self - translators[0].targetType = Int.self - translators[0].translateReturnValue = 42 - _ = try? swinject.on("context").instance() as Int - expect(bindings[0].instanceReceivedArguments?.context as? Int) == 42 - } - it("passes original context to context resolver") { - bindings[0].matchesClosure = { $0.contextType == Int.self } - translators[0].sourceType = String.self - translators[0].targetType = Int.self - _ = try? swinject.on("context").instance() as Int - expect(translators[0].translateReceivedContext as? String) == "context" - } - it("does not throw if single binding can be used with multiple translated contexts") { - bindings[0].matchesReturnValue = true - translators[1 ... 2].forEach { - $0.sourceType = String.self - $0.targetType = Int.self - $0.translateReturnValue = 0 - } - expect { try swinject.on("context").instance() }.notTo(throwError()) - } - } -} } From 31cb40a51e627577ee5fd260d38c459e0a0c2738 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 28 Jul 2019 12:49:56 +0200 Subject: [PATCH 162/239] Describe singleton & multiton bindings --- Swinject.xcodeproj/project.pbxproj | 50 ++----- Tests/3.0 API/OptionalsSpec.swift | 8 ++ Tests/3.0 API/ScopesSpec.swift | 1 - Tests/3.0 API/SingletonSpec.swift | 97 ++++++++++++++ Tests/3.0 API/SwinjectApiSpec.swift | 40 ------ Tests/LinuxConfig.swift | 7 +- Tests/Support/TestModels.swift | 10 +- Tests/Unit Specs/BinderEnvironmentSpec.swift | 64 --------- Tests/Unit Specs/ReferenceMakerSpec.swift | 41 ------ Tests/Unit Specs/ScopeRegistryKeySpec.swift | 101 -------------- Tests/Unit Specs/ScopedBindingSpec.swift | 134 ------------------- 11 files changed, 117 insertions(+), 436 deletions(-) create mode 100644 Tests/3.0 API/SingletonSpec.swift delete mode 100644 Tests/3.0 API/SwinjectApiSpec.swift delete mode 100644 Tests/Unit Specs/ReferenceMakerSpec.swift delete mode 100644 Tests/Unit Specs/ScopeRegistryKeySpec.swift delete mode 100644 Tests/Unit Specs/ScopedBindingSpec.swift diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 2cc5e9d1..2c96b06b 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -28,11 +28,9 @@ 0CD787EACEBFD1051D358E7D /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; 0CE1126436F680F9684837E4 /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; 0D5C4A278A16AB3A163148AF /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; - 0DC084A3650745492BB81EE9 /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B3797A6BB56AE76CEC19F2A /* SwinjectApiSpec.swift */; }; 128913D570B4A8BBF40866BE /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; 13CDEC7A6C8E43B58D5CBE3D /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; 180DB4397B4C05E26F819C85 /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADA1541ABC1365DFD7E3377F /* Food.swift */; }; - 181204958559CE25462AA6EF /* ScopeRegistryKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2902FD4C1A50263340A51FFB /* ScopeRegistryKeySpec.swift */; }; 19416C867F15E88394A0ABD1 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */; }; 196338EA802A39E205C33B43 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; 19EBB651BD06BD0C03C1ACB5 /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59111BE319C59E4CD6CF68CD /* Assembler.swift */; }; @@ -49,7 +47,6 @@ 24114725AE1A834C6E3118F7 /* TaggedTypeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */; }; 2615FC1C92B7E381116B9E57 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; 26C4C6118D189E8813ABD5A2 /* Quick.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = C765B92B00C0AC8625BB4AC9 /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 273F441B941A6DF76D9BD752 /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B3797A6BB56AE76CEC19F2A /* SwinjectApiSpec.swift */; }; 283C77045DA55C2134EC9C48 /* Container+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F446D6BD4C44E16A1D608BFB /* Container+TypeForwarding.swift */; }; 290C9E9420A1EE30456476CB /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59111BE319C59E4CD6CF68CD /* Assembler.swift */; }; 293985649250DF270DC89135 /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; @@ -70,7 +67,6 @@ 33391EBA040E82DFB0A37015 /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; 335CE53CEC2360DC86D58F07 /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61EE5DDBE705B47AFC9A6986 /* LoadAwareAssembly.swift */; }; 33B86F2D33219879731CDDF0 /* ScopesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D3C59E84B5FD0C13F487838 /* ScopesSpec.swift */; }; - 3575DE21531F7365B713B64B /* ScopedBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */; }; 36A706F87ED2E88F3390C6C2 /* ServiceEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38615FC8EEB466C5C1EAD21C /* ServiceEntry.swift */; }; 372F0061E762BF8FFF05457F /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; 3753FB83A1FB4B83891AA5C8 /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BFF4BA99493C54260878C4 /* ObjectScope.swift */; }; @@ -81,7 +77,6 @@ 3C270A77DE4F1E6BC2F8E863 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; 3CEF021295AD9AF9BF26B71E /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; 3DEFB7CA42D9EFF0B4FBC0F4 /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 38BCCF3F950869BD1891F7A8 /* Swinject.framework */; }; - 3F0DCA7060C62712EA30CBB1 /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B3797A6BB56AE76CEC19F2A /* SwinjectApiSpec.swift */; }; 3F704A98C01C84BDBD0A52B3 /* BinderEnvironmentSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */; }; 3F8F5645D6D37FCEC1D89393 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B580B43E1891812C97209 /* Binding.swift */; }; 401592294E5D528379BE1AB2 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62682D6ED38742996624B041 /* BasicAssembly.swift */; }; @@ -98,13 +93,11 @@ 49D71F6CC12C12FE7B6A097A /* ContextSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */; }; 4A977D2B639B8098AA508389 /* BinderEnvironmentSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */; }; 4B9811CF0604946CCF323ED2 /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92B8E618A08408404FB2A7A /* TypeBinder.swift */; }; - 4B9BAB1D38AB0C08F8CA25F5 /* ScopeRegistryKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2902FD4C1A50263340A51FFB /* ScopeRegistryKeySpec.swift */; }; 4DC8A58B6607898BAF6504A3 /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */; }; 4DF3DC1CDD3C4948F9BDD3DF /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3586A4987B7C7C8122D674E /* SwinjectError.swift */; }; 4E4DC8CDD1BA51FB66A332C2 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */; }; 4EC94A51037C79DE0C5C8CB1 /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; 4EE5C1207C57C85A928FA89B /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 273FB7A6277E0841E1570990 /* Nimble.framework */; }; - 4EFB0A66BBCAA617470CE622 /* SwinjectApiSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B3797A6BB56AE76CEC19F2A /* SwinjectApiSpec.swift */; }; 53EBF7A46EF65F2A8DAADC7A /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; 546FF827DB6D42490D1CA439 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; 54956014A1774DF8357B69E6 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; @@ -159,8 +152,6 @@ 789BF74652A2424EB8F7EF47 /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 7A7032384E07DAD308D4F70A /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 8B9785AAE94A5447FA307242 /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 7AE3FF1C0B4860942D90B68B /* NonGeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841D83ADB41363D1E38087B4 /* NonGeneratedMocks.swift */; }; - 7BBB627731769BD052696A7E /* ReferenceMakerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 388605A438343F7BB80D521E /* ReferenceMakerSpec.swift */; }; - 7CABC0D9C2F99BC37CC85517 /* ScopeRegistryKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2902FD4C1A50263340A51FFB /* ScopeRegistryKeySpec.swift */; }; 7D0683F36CE56228AC2CD489 /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C074BAC560F277E806146C60 /* SimpleBinding.swift */; }; 7D6F664091C70BABBFB61D53 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; 7E3C3E6FD07F3BD76024770A /* InjectionVariation.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C516EFA0CA22D19F07B27E /* InjectionVariation.swift */; }; @@ -242,7 +233,6 @@ B2E998C200979E513C70D7E3 /* InstanceMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CADDB3E9E363310028AA5920 /* InstanceMaker.swift */; }; B2FAD41F7726502822AF913B /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42490D1D0C395951243F5CFF /* Container.swift */; }; B3062AB22373AD23052B61DF /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; - B3549C40707070622D261363 /* ScopedBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */; }; B42331BF00B482369B908BB8 /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BFF4BA99493C54260878C4 /* ObjectScope.swift */; }; B4B66D7251BDDE25D6D7FB3C /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BFF4BA99493C54260878C4 /* ObjectScope.swift */; }; B5FF5DFE394B6B1BB930D88D /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */; }; @@ -255,7 +245,6 @@ BB77A5D81C58392964D07233 /* BindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E59A67F3548663368788B17 /* BindingSpec.swift */; }; BB8FDF4F2A0AF8C1DA615854 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; BCD130E9F1D33C66AA6A12F7 /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 74DE57FB3E8228904E6FE0D7 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; - BD01D1F86970237D6D5C8D38 /* ReferenceMakerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 388605A438343F7BB80D521E /* ReferenceMakerSpec.swift */; }; BD08D3E155AFD841CFECA0AD /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BC5108ED11A3A3084D864CC /* Animal.swift */; }; BD9B57E26722C80B7EF990DB /* Container+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F446D6BD4C44E16A1D608BFB /* Container+TypeForwarding.swift */; }; BE3A8FAC5AC745EDCCD5A5FB /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 6D54F152C11C966ECFC55ECB /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -267,10 +256,8 @@ C1687ACA897DEFD3A8197CCD /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; C177D9C6969ADA38C1094F6D /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */; }; C223101DB417F1237A8421E1 /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 6D434EB4C13CF9D9FA6D80CB /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - C243400E417F4A91E491B5EB /* ScopeRegistryKeySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2902FD4C1A50263340A51FFB /* ScopeRegistryKeySpec.swift */; }; C38A2EBF4D1904E7D6989989 /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADA1541ABC1365DFD7E3377F /* Food.swift */; }; C3FDE105B08336F26CC95BAA /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = A10187BB3A994165E7FC1528 /* ScopedBinding.swift */; }; - C4CB7A3BA35A1E0811842971 /* ScopedBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */; }; C4E9DC50A2FDAE4D36A925D9 /* NonGeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841D83ADB41363D1E38087B4 /* NonGeneratedMocks.swift */; }; C637E97E193BB1DADDDC6C21 /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1E726A651C3AFE92C19608B /* SwinjectModule.swift */; }; C6D60E2AEC381998223145B2 /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; @@ -285,8 +272,11 @@ CB9E8D16D7A0620A1F7A32A3 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; CBBE28990E0EA82AD8D5E3AF /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; CBE63031F33303F3E503CEF2 /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; + CD9954F222EDB05B00032165 /* SingletonSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD9954F022EDAF9A00032165 /* SingletonSpec.swift */; }; + CD9954F322EDB05C00032165 /* SingletonSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD9954F022EDAF9A00032165 /* SingletonSpec.swift */; }; + CD9954F422EDB05C00032165 /* SingletonSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD9954F022EDAF9A00032165 /* SingletonSpec.swift */; }; + CD9954F522EDB05D00032165 /* SingletonSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD9954F022EDAF9A00032165 /* SingletonSpec.swift */; }; CE5AFED22F04B96713ED76D7 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ADC44E9312C3B974AFD8F07B /* Nimble.framework */; }; - CEA4CB2D3113EC693C590B9D /* ScopedBindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */; }; CECF5BD14BCDF5248771A06A /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; CEE763218A90832454A6E2DE /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */; }; CF4516872D3DA7118DB2B90B /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; @@ -333,7 +323,6 @@ F06DEB671A4B85ABB0E96E51 /* ContextTranslator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */; }; F1F3BA81462E2362374BD4C4 /* ModulesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75BE3AE3E30DFE42A919D825 /* ModulesSpec.swift */; }; F270DC6FF3901F58C76F3872 /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; - F37DA7FC70E254616DBD1BD7 /* ReferenceMakerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 388605A438343F7BB80D521E /* ReferenceMakerSpec.swift */; }; F39521855B858534A8D53C8F /* Closable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D0BCCCD61CD9BECC29E064 /* Closable.swift */; }; F504C2ABEFCFFCAC8B858751 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; F568382FB877060127790413 /* Resolver+LegacyApi.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */; }; @@ -344,7 +333,6 @@ F8EB47A631D482A0D7B621DE /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; F9A4BF18B0085B7DCD3440EC /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B580B43E1891812C97209 /* Binding.swift */; }; FA805A162E989A22990B99AA /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; - FB446EB8754FDAAE011C4362 /* ReferenceMakerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 388605A438343F7BB80D521E /* ReferenceMakerSpec.swift */; }; FD7B2663F2F931B78EB330EE /* Resolver+LegacyApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A784E2DEC7691D14DDBECD8 /* Resolver+LegacyApi.swift */; }; /* End PBXBuildFile section */ @@ -468,14 +456,12 @@ 09FC792715B1658721F76885 /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 0CA449690AE00F6300DE8ACA /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 0DC67CB109091002AB433A46 /* SwinjectTests.xctest */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.cfbundle; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopedBindingSpec.swift; sourceTree = ""; }; 0E0B580B43E1891812C97209 /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; 10480F2154EAA0414D4C1F55 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .swiftlint.yml; sourceTree = ""; }; 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SynchronizedResolverSpec.swift; sourceTree = ""; }; 13513FA012659ADE699A3608 /* LazySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LazySpec.swift; sourceTree = ""; }; 1A006CC804F9AB8ACC121029 /* Utils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = ""; }; - 1B3797A6BB56AE76CEC19F2A /* SwinjectApiSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectApiSpec.swift; sourceTree = ""; }; 1C58FC14EEA170B0DC079DE4 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; 1D3C59E84B5FD0C13F487838 /* ScopesSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopesSpec.swift; sourceTree = ""; }; 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Circularity.swift; sourceTree = ""; }; @@ -483,7 +469,6 @@ 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Arguments.swift; sourceTree = ""; }; 26EEC28683E4A26B3092E8BA /* BinderEnvironment.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = BinderEnvironment.swifttemplate; sourceTree = ""; }; 273FB7A6277E0841E1570990 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; - 2902FD4C1A50263340A51FFB /* ScopeRegistryKeySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistryKeySpec.swift; sourceTree = ""; }; 2E0C3E4D518BC1FEF3EF8D33 /* BinderVariation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderVariation.swift; sourceTree = ""; }; 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; 34AFFAC41BA9D02A38BDB7A3 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; @@ -491,7 +476,6 @@ 36BFF4BA99493C54260878C4 /* ObjectScope.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObjectScope.swift; sourceTree = ""; }; 38615FC8EEB466C5C1EAD21C /* ServiceEntry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServiceEntry.swift; sourceTree = ""; }; 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Swinject+Builder.swift"; sourceTree = ""; }; - 388605A438343F7BB80D521E /* ReferenceMakerSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReferenceMakerSpec.swift; sourceTree = ""; }; 38BCCF3F950869BD1891F7A8 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaggedTypeSpec.swift; sourceTree = ""; }; 42490D1D0C395951243F5CFF /* Container.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.swift; sourceTree = ""; }; @@ -559,6 +543,7 @@ C765B92B00C0AC8625BB4AC9 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; CADDB3E9E363310028AA5920 /* InstanceMaker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceMaker.swift; sourceTree = ""; }; CC85CB215058F95C0BC190B1 /* Bridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bridge.swift; sourceTree = ""; }; + CD9954F022EDAF9A00032165 /* SingletonSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingletonSpec.swift; sourceTree = ""; }; CDA78290D6D60BD0B808571F /* Container+Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Logging.swift"; sourceTree = ""; }; CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextSpec.swift; sourceTree = ""; }; @@ -637,9 +622,6 @@ isa = PBXGroup; children = ( FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */, - 388605A438343F7BB80D521E /* ReferenceMakerSpec.swift */, - 0DEE0E5A14336481369A3434 /* ScopedBindingSpec.swift */, - 2902FD4C1A50263340A51FFB /* ScopeRegistryKeySpec.swift */, BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */, 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */, 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */, @@ -770,10 +752,10 @@ 6E59A67F3548663368788B17 /* BindingSpec.swift */, DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */, 670DB253ECD5CE1468A7F2E3 /* InjectionSpec.swift */, + CD9954F022EDAF9A00032165 /* SingletonSpec.swift */, 75BE3AE3E30DFE42A919D825 /* ModulesSpec.swift */, 50D6F2639990DD5BAD9578B0 /* OptionalsSpec.swift */, 1D3C59E84B5FD0C13F487838 /* ScopesSpec.swift */, - 1B3797A6BB56AE76CEC19F2A /* SwinjectApiSpec.swift */, ); path = "3.0 API"; sourceTree = ""; @@ -1481,6 +1463,7 @@ EE35DF2D353E2C5110DA5C42 /* Convenience.swift in Sources */, 934AFACA6BFF24AD3503F98D /* EmploymentAssembly.swift in Sources */, 180DB4397B4C05E26F819C85 /* Food.swift in Sources */, + CD9954F222EDB05B00032165 /* SingletonSpec.swift in Sources */, 9A8164D6696C87BFEC7325C3 /* GeneratedMocks.swift in Sources */, 818DF17D671EA1022CE59A2A /* InjectionSpec.swift in Sources */, AE6EAB8CC32ED5E1789D55B7 /* LazySpec.swift in Sources */, @@ -1491,12 +1474,8 @@ 72F09FC92FFB0F7C32D8E2A5 /* OptionalsSpec.swift in Sources */, 628EBFBA0031B1FA2E29F583 /* Person.swift in Sources */, 708E1C453CBC76ED26FA2FCB /* ProviderSpec.swift in Sources */, - 7BBB627731769BD052696A7E /* ReferenceMakerSpec.swift in Sources */, - 7CABC0D9C2F99BC37CC85517 /* ScopeRegistryKeySpec.swift in Sources */, - B3549C40707070622D261363 /* ScopedBindingSpec.swift in Sources */, 33B86F2D33219879731CDDF0 /* ScopesSpec.swift in Sources */, 72217E47D83C3CA6D97640B9 /* StandardScopeRegistrySpec.swift in Sources */, - 0DC084A3650745492BB81EE9 /* SwinjectApiSpec.swift in Sources */, 640F7A55D9A671FA112C8083 /* SwinjectTreeBuilderSpec.swift in Sources */, F7CD04FB09FC7F18E9E001CF /* SynchronizedResolverSpec.swift in Sources */, 9AD60A86D5A0DF4513C1EA8D /* TaggedTypeSpec.swift in Sources */, @@ -1526,6 +1505,7 @@ A882705E4199EF759E80B311 /* Convenience.swift in Sources */, 19416C867F15E88394A0ABD1 /* EmploymentAssembly.swift in Sources */, 590B861A863A056A0B7FA368 /* Food.swift in Sources */, + CD9954F322EDB05C00032165 /* SingletonSpec.swift in Sources */, 9C12EB42EC058994805E93A6 /* GeneratedMocks.swift in Sources */, 95A6654089875BCC863FB53B /* InjectionSpec.swift in Sources */, 979518E078B187549E11DF48 /* LazySpec.swift in Sources */, @@ -1536,12 +1516,8 @@ D941D81F59900A52805D6B4A /* OptionalsSpec.swift in Sources */, EB3420214A9E68A0247D0F2C /* Person.swift in Sources */, CF9535A0DCAFF23F4D62F871 /* ProviderSpec.swift in Sources */, - FB446EB8754FDAAE011C4362 /* ReferenceMakerSpec.swift in Sources */, - C243400E417F4A91E491B5EB /* ScopeRegistryKeySpec.swift in Sources */, - CEA4CB2D3113EC693C590B9D /* ScopedBindingSpec.swift in Sources */, 0068DAA4AA322F00AF53731F /* ScopesSpec.swift in Sources */, C952D5869D87743297968E9A /* StandardScopeRegistrySpec.swift in Sources */, - 273F441B941A6DF76D9BD752 /* SwinjectApiSpec.swift in Sources */, A308578B99D33C7E33632E85 /* SwinjectTreeBuilderSpec.swift in Sources */, 3BDB44DE92D2377334894804 /* SynchronizedResolverSpec.swift in Sources */, A5302886A31C90F38512B88E /* TaggedTypeSpec.swift in Sources */, @@ -1571,6 +1547,7 @@ EEAD7E215908DF939ECCDCC9 /* Convenience.swift in Sources */, 4E4DC8CDD1BA51FB66A332C2 /* EmploymentAssembly.swift in Sources */, BE6C13A3492E3CFC08E231B0 /* Food.swift in Sources */, + CD9954F522EDB05D00032165 /* SingletonSpec.swift in Sources */, CB06DC3BC4A32776BBD90DDF /* GeneratedMocks.swift in Sources */, 42FE916C1593A9289E1A28BC /* InjectionSpec.swift in Sources */, 6A0FD11468B3852E48B682BE /* LazySpec.swift in Sources */, @@ -1581,12 +1558,8 @@ A453A5A7E0EC0FE161AA34D5 /* OptionalsSpec.swift in Sources */, C76374CAFE7C2BCCE52F1BB1 /* Person.swift in Sources */, 4954CBB07E38E98752AC3347 /* ProviderSpec.swift in Sources */, - F37DA7FC70E254616DBD1BD7 /* ReferenceMakerSpec.swift in Sources */, - 4B9BAB1D38AB0C08F8CA25F5 /* ScopeRegistryKeySpec.swift in Sources */, - C4CB7A3BA35A1E0811842971 /* ScopedBindingSpec.swift in Sources */, 31729A1E5F50EF30FDD427AD /* ScopesSpec.swift in Sources */, 0720BEA814AD514378380ACB /* StandardScopeRegistrySpec.swift in Sources */, - 3F0DCA7060C62712EA30CBB1 /* SwinjectApiSpec.swift in Sources */, 3CEF021295AD9AF9BF26B71E /* SwinjectTreeBuilderSpec.swift in Sources */, 546FF827DB6D42490D1CA439 /* SynchronizedResolverSpec.swift in Sources */, 09470890A74A5DDE7114891B /* TaggedTypeSpec.swift in Sources */, @@ -1616,6 +1589,7 @@ 48D1568CB41BE4B6597FD535 /* Convenience.swift in Sources */, A59C6C434288333EDAF951C4 /* EmploymentAssembly.swift in Sources */, C38A2EBF4D1904E7D6989989 /* Food.swift in Sources */, + CD9954F422EDB05C00032165 /* SingletonSpec.swift in Sources */, B703A24C1A963C6BAC95B9A5 /* GeneratedMocks.swift in Sources */, AD214F3DBAB4F16C88322CAC /* InjectionSpec.swift in Sources */, 0CD787EACEBFD1051D358E7D /* LazySpec.swift in Sources */, @@ -1626,12 +1600,8 @@ F6EEF5F7B57DC0E44EF569A4 /* OptionalsSpec.swift in Sources */, BEEFBE87EB17D56BA8D47358 /* Person.swift in Sources */, 48F40377D116C6B1B786C329 /* ProviderSpec.swift in Sources */, - BD01D1F86970237D6D5C8D38 /* ReferenceMakerSpec.swift in Sources */, - 181204958559CE25462AA6EF /* ScopeRegistryKeySpec.swift in Sources */, - 3575DE21531F7365B713B64B /* ScopedBindingSpec.swift in Sources */, EA0D19F7DF0355C774B0F40B /* ScopesSpec.swift in Sources */, 0B61DC733616A8ED4ED77FA7 /* StandardScopeRegistrySpec.swift in Sources */, - 4EFB0A66BBCAA617470CE622 /* SwinjectApiSpec.swift in Sources */, 233F3E25FF0B51A3E6611F58 /* SwinjectTreeBuilderSpec.swift in Sources */, 890CCD2800597F6FB7C6FD31 /* SynchronizedResolverSpec.swift in Sources */, 24114725AE1A834C6E3118F7 /* TaggedTypeSpec.swift in Sources */, diff --git a/Tests/3.0 API/OptionalsSpec.swift b/Tests/3.0 API/OptionalsSpec.swift index f829f517..f813586e 100644 --- a/Tests/3.0 API/OptionalsSpec.swift +++ b/Tests/3.0 API/OptionalsSpec.swift @@ -36,5 +36,13 @@ class OptionalsSpec: QuickSpec { override func spec() { #if swift(>=5.1) } expect { try swinject.instance() as Int? }.to(throwError()) } + it("injects same singleton instance for type and it's optional") { + let swinject = Swinject { + bbind(Human.self) & singleton { Human() } + } + let direct = try? swinject.instance(of: Human.self) + let optional = try? swinject.instance(of: Human?.self) + expect(direct) === optional + } #endif } } diff --git a/Tests/3.0 API/ScopesSpec.swift b/Tests/3.0 API/ScopesSpec.swift index 4af3e7e6..24f8e2c3 100644 --- a/Tests/3.0 API/ScopesSpec.swift +++ b/Tests/3.0 API/ScopesSpec.swift @@ -5,7 +5,6 @@ import Nimble import Quick import Swinject -@testable import class Swinject.UnboundScope class ScopesSpec: QuickSpec { override func spec() { #if swift(>=5.1) it("can bind scoped singleton") { diff --git a/Tests/3.0 API/SingletonSpec.swift b/Tests/3.0 API/SingletonSpec.swift new file mode 100644 index 00000000..62fa1437 --- /dev/null +++ b/Tests/3.0 API/SingletonSpec.swift @@ -0,0 +1,97 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +import Nimble +import Quick +import Swinject +@testable import class Swinject.UnboundScope + +class SingletonSpec: QuickSpec { override func spec() { #if swift(>=5.1) + beforeEach { + UnboundScope.root.close() + } + it("never reuses instances from a provider binding") { + let swinject = Swinject { + bbind(Human.self) & provider { Human() } + } + let first = try? swinject.instance(of: Human.self) + let second = try? swinject.instance(of: Human.self) + expect(first) !== second + } + it("never reuses instances from a factory binding") { + let swinject = Swinject { + bbind(Human.self) & factory { (_, _: Int) in Human() } + } + let first = try? swinject.instance(of: Human.self, arg: 0) + let second = try? swinject.instance(of: Human.self, arg: 0) + expect(first) !== second + } + it("injects the same instance from a singleton binding") { + let swinject = Swinject { + bbind(Human.self) & singleton { Human() } + } + let first = try? swinject.instance(of: Human.self) + let second = try? swinject.instance(of: Human.self) + expect(first) === second + } + it("does not reuse singleton instances for different tags") { + let swinject = Swinject { + bbind(Human.self, tagged: "john") & singleton { Human() } + bbind(Human.self, tagged: "rick") & singleton { Human() } + } + let john = try? swinject.instance(of: Human.self, tagged: "john") + let rick = try? swinject.instance(of: Human.self, tagged: "rick") + expect(john) !== rick + } + it("injects the same instance from multiton binding when using the same argument") { + let swinject = Swinject { + bbind(Human.self) & provider { Human() } + bbind(Pet.self) & multiton { Pet(name: $1, owner: try $0.instance()) } + } + let first = try? swinject.instance(of: Pet.self, arg: "mimi") + let second = try? swinject.instance(of: Pet.self, arg: "mimi") + expect(first) === second + } + it("injects a different instance from multiton binding when using a different argument") { + let swinject = Swinject { + bbind(Human.self) & provider { Human() } + bbind(Pet.self) & multiton { Pet(name: $1, owner: try $0.instance()) } + } + let mimi = try? swinject.instance(of: Pet.self, arg: "mimi") + let riff = try? swinject.instance(of: Pet.self, arg: "riff") + expect(mimi) !== riff + } + it("can use up to 5 arguments in multiton binding") { + let swinject = Swinject { + bbind(Int.self) & multiton { (_, a1: Int) in a1 } + bbind(Int.self) & multiton { (_, a1: Int, a2: Int) in a1 + a2 } + bbind(Int.self) & multiton { (_, a1: Int, a2: Int, a3: Int) in a1 + a2 + a3 } + bbind(Int.self) & multiton { (_, a1: Int, a2: Int, a3: Int, a4: Int) in a1 + a2 + a3 + a4 } + bbind(Int.self) & multiton { (_, a1: Int, a2: Int, a3: Int, a4: Int, a5: Int) in a1 + a2 + a3 + a4 + a5 } + } + expect { try swinject.instance(of: Int.self, arg: 1) } == 1 + expect { try swinject.instance(of: Int.self, arg: 1, 2) } == 3 + expect { try swinject.instance(of: Int.self, arg: 1, 2, 3) } == 6 + expect { try swinject.instance(of: Int.self, arg: 1, 2, 3, 4) } == 10 + expect { try swinject.instance(of: Int.self, arg: 1, 2, 3, 4, 5) } == 15 + } + describe("weak reference") { + it("it releases instance if it is not used") { + let swinject = Swinject { + bbind(Human.self) & singleton(ref: weakRef) { Human() } + } + weak var first = try? swinject.instance() as Human + expect(first).to(beNil()) + } + it("injects the same instance while it is used") { + let swinject = Swinject { + bbind(Human.self) & singleton(ref: weakRef) { Human() } + } + let first = try? swinject.instance(of: Human.self) + let second = try? swinject.instance(of: Human.self) + expect(first) === second + } + } + #endif +} } diff --git a/Tests/3.0 API/SwinjectApiSpec.swift b/Tests/3.0 API/SwinjectApiSpec.swift deleted file mode 100644 index dad90978..00000000 --- a/Tests/3.0 API/SwinjectApiSpec.swift +++ /dev/null @@ -1,40 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -import Nimble -import Quick -import Swinject -@testable import class Swinject.UnboundScope - -class SwinjectApiSpec: QuickSpec { override func spec() { #if swift(>=5.1) - beforeEach { - UnboundScope.root.close() - } - it("can bind singleton") { - let swinject = Swinject { - bbind(Human.self) & singleton { Human() } - } - let first = try? swinject.instance() as Human - let second = try? swinject.instance() as Human - expect(first) === second - } - it("can bind weakly referenced singleton") { - let swinject = Swinject { - bbind(Human.self) & singleton(ref: weakRef) { Human() } - } - weak var first = try? swinject.instance() as Human - expect(first).to(beNil()) - } - it("can bind multitons") { - let swinject = Swinject { - bbind(Building.self) & multiton { Building(floors: $1) } - } - let house1 = try? swinject.instance(arg: 1) as Building - let house2 = try? swinject.instance(arg: 1) as Building - let skyscrapper = try? swinject.instance(arg: 100) as Building - expect(house1) === house2 - expect(skyscrapper) !== house1 - } - #endif -} } diff --git a/Tests/LinuxConfig.swift b/Tests/LinuxConfig.swift index d7d5ad91..db28b5e9 100644 --- a/Tests/LinuxConfig.swift +++ b/Tests/LinuxConfig.swift @@ -17,20 +17,15 @@ let allSpecs: [QuickSpec.Type] = [ ProviderSpec.self, SynchronizedResolverSpec.self, // 3.0 Api - SwinjectApiSpec.self, BindingSpec.self, InjectionSpec.self, + SingletonSpec.self, ModulesSpec.self, ContextSpec.self, ScopesSpec.self, OptionalsSpec.self, // Unit Specs BinderEnvironmentSpec.self, - BindingKeySpec.self, - ReferenceMakerSpec.self, - ScopedBindingSpec.self, - ScopeRegistryKeySpec.self, - SimpleBindingSpec.self, StandardScopeRegistrySpec.self, SwinjectTreeBuilderSpec.self, TaggedTypeSpec.self, diff --git a/Tests/Support/TestModels.swift b/Tests/Support/TestModels.swift index 8b3c8051..dcaadd6c 100644 --- a/Tests/Support/TestModels.swift +++ b/Tests/Support/TestModels.swift @@ -10,7 +10,7 @@ class Human: Mammal { var name = "" } -struct Pet { +class Pet { let name: String let owner: Human @@ -20,12 +20,4 @@ struct Pet { } } -class Building { - let floors: Int - - init(floors: Int) { - self.floors = floors - } -} - struct TestError: Error, Equatable {} diff --git a/Tests/Unit Specs/BinderEnvironmentSpec.swift b/Tests/Unit Specs/BinderEnvironmentSpec.swift index 4ba1ffe6..788d5c79 100644 --- a/Tests/Unit Specs/BinderEnvironmentSpec.swift +++ b/Tests/Unit Specs/BinderEnvironmentSpec.swift @@ -14,15 +14,6 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { let maker = singleton { 0 }.actual as? ScopedBinding.Builder expect(maker?.scope) === UnboundScope.root } - it("has correct reference maker") { - let makeRef: ReferenceMaker = { _ in noRef(42) } - let maker = singleton(ref: makeRef) { 0 }.actual as? ScopedBinding.Builder - expect(maker?.makeRef(0).currentValue as? Int) == 42 - } - it("returns instance made by builder") { - let maker = singleton { 42 } - expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 - } it("does not call builder until instance is requested") { var called = false _ = singleton { called = true } @@ -39,12 +30,6 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { let maker = singleton { throw SwinjectError() } expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) } - it("does not reuse instance") { - let maker = singleton { Human() } - let instance1 = try? maker.makeInstance(resolver: DummyResolver()) - let instance2 = try? maker.makeInstance(resolver: DummyResolver()) - expect(instance1) !== instance2 - } } describe("multiton") { it("has correct scope") { @@ -52,21 +37,6 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { let actualMaker = maker.actual as? ScopedBinding.Builder> expect(actualMaker?.scope) === UnboundScope.root } - it("has correct reference maker") { - let makeRef: ReferenceMaker = { _ in noRef(42) } - let maker = multiton(ref: makeRef) { (_, _: String) in 42 } - let actualMaker = maker.actual as? ScopedBinding.Builder> - expect(actualMaker?.makeRef(0).currentValue as? Int) == 42 - } - it("returns instance made by builder method") { - let maker = multiton { (_, _: String) in 42 } - expect { try maker.makeInstance(arg: box(""), resolver: DummyResolver()) } == 42 - } - it("does not call builder until instance is requested") { - var called = false - _ = multiton { (_, _: String) in called = true } - expect(called).to(beFalse()) - } it("calls builder with given resolver") { var passedResolver: Resolver? let resolver = DummyResolver() @@ -74,44 +44,10 @@ class BinderEnvironmentSpec: QuickSpec { override func spec() { _ = try? maker.makeInstance(arg: box(""), resolver: resolver) expect(passedResolver) === resolver } - it("calls builder with given argument") { - var passedArgument: Int? - let maker = multiton { (_, arg: Int) in passedArgument = arg } - _ = try? maker.makeInstance(arg: box(42), resolver: DummyResolver()) - expect(passedArgument) == 42 - } it("rethrows error from builder") { let maker = multiton { (_, _: String) in throw SwinjectError() } expect { try maker.makeInstance(arg: box(""), resolver: DummyResolver()) }.to(throwError()) } - it("does not reuse instance") { - let maker = multiton { (_, _: String) in Human() } - let instance1 = try? maker.makeInstance(arg: box(""), resolver: DummyResolver()) - let instance2 = try? maker.makeInstance(arg: box(""), resolver: DummyResolver()) - expect(instance1) !== instance2 - } - describe("multiple arguments") { - it("works with 2 arguments") { - let maker = multiton { (_, _: Int, _: Double) in 42 } - let arguments = box(1, 1.0) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 - } - it("works with 3 arguments") { - let maker = multiton { (_, _: Int, _: Double, _: String) in 42 } - let arguments = box(1, 1.0, "") - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 - } - it("works with 4 arguments") { - let maker = multiton { (_, _: Int, _: Double, _: String, _: Float) in 42 } - let arguments = box(1, 1.0, "", Float(1.0)) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 - } - it("works with 5 arguments") { - let maker = multiton { (_, _: Int, _: Double, _: String, _: Float, _: Int) in 42 } - let arguments = box(1, 1.0, "", Float(1.0), 5) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 - } - } } } describe("scoped") { diff --git a/Tests/Unit Specs/ReferenceMakerSpec.swift b/Tests/Unit Specs/ReferenceMakerSpec.swift deleted file mode 100644 index 0342966e..00000000 --- a/Tests/Unit Specs/ReferenceMakerSpec.swift +++ /dev/null @@ -1,41 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -import Nimble -import Quick -@testable import Swinject - -class ReferenceMakerSpec: QuickSpec { override func spec() { - describe("strongRef") { - it("returns given value") { - let human = Human() - let reference = strongRef(human) - expect(reference.currentValue) === human - } - it("persists given value") { - var reference: Reference? = strongRef(Human()) - let nextValue = reference!.nextValue - reference = nil - expect(nextValue()).notTo(beNil()) - } - } - describe("weakRef") { - it("returns given value") { - let human = Human() - let reference = weakRef(human) - expect(reference.currentValue) === human - } - it("does not keep strong reference on value") { - var reference: Reference? = weakRef(Human()) - let nextValue = reference!.nextValue - reference = nil - expect(nextValue()).to(beNil()) - } - it("works with type erasure") { - let human: Mammal = Human() - let nextValue = { weakRef(human).nextValue() as Any? } - expect(nextValue() is Mammal) == true - } - } -} } diff --git a/Tests/Unit Specs/ScopeRegistryKeySpec.swift b/Tests/Unit Specs/ScopeRegistryKeySpec.swift deleted file mode 100644 index e6598f94..00000000 --- a/Tests/Unit Specs/ScopeRegistryKeySpec.swift +++ /dev/null @@ -1,101 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -import Nimble -import Quick -@testable import Swinject - -class ScopeRegistryKeySpec: QuickSpec { override func spec() { - var descriptor1 = AnyTypeDescriptorMock() - var descriptor2 = AnyTypeDescriptorMock() - var argument1 = MatchableMock() - var argument2 = MatchableMock() - var key1: ScopeRegistryKey! - var key2: ScopeRegistryKey! - beforeEach { - descriptor1 = AnyTypeDescriptorMock() - descriptor1.matchesReturnValue = true - argument1 = MatchableMock() - argument1.matchesReturnValue = true - descriptor2 = AnyTypeDescriptorMock() - descriptor2.matchesReturnValue = true - argument2 = MatchableMock() - argument2.matchesReturnValue = true - key1 = ScopeRegistryKey(descriptor: descriptor1, argument: argument1) - key2 = ScopeRegistryKey(descriptor: descriptor2, argument: argument2) - } - describe("equality") { - describe("descriptor matching") { - it("does not equal if first descriptor doesnt match") { - descriptor1.matchesReturnValue = false - descriptor2.matchesReturnValue = true - expect(key1) != key2 - } - it("does not equal if second descriptor doesnt match") { - descriptor1.matchesReturnValue = true - descriptor2.matchesReturnValue = false - expect(key1) != key2 - } - it("equals if both descriptor match") { - descriptor1.matchesReturnValue = true - descriptor2.matchesReturnValue = true - expect(key1) == key2 - } - } - describe("argument matching") { - it("does not equal if first argument is not matchable") { - key1 = ScopeRegistryKey(descriptor: descriptor1, argument: ()) - expect(key1) != key2 - } - it("does not equal if first argument doesnt match") { - argument1.matchesReturnValue = false - expect(key1) != key2 - } - it("does not equal if second argument is not matchable") { - key2 = ScopeRegistryKey(descriptor: descriptor2, argument: ()) - expect(key1) != key2 - } - it("does not equal if second argument doesnt match") { - argument2.matchesReturnValue = false - expect(key1) != key2 - } - it("equals if both arguments match") { - argument1.matchesReturnValue = true - argument2.matchesReturnValue = true - expect(key1) == key2 - } - it("equals if both arguments are Void") { - key1 = ScopeRegistryKey(descriptor: descriptor1, argument: ()) - key2 = ScopeRegistryKey(descriptor: descriptor2, argument: ()) - expect(key1) == key2 - } - } - } - describe("hash") { - describe("hashes descriptor") { - it("does not equal if descriptor hashes are different") { - descriptor1.hashIntoClosure = { $0.combine(1) } - descriptor2.hashIntoClosure = { $0.combine(2) } - expect(key1.hashValue) != key2.hashValue - } - it("equals if descriptor hashes are the same") { - descriptor1.hashIntoClosure = { $0.combine(1) } - descriptor2.hashIntoClosure = { $0.combine(1) } - expect(key1.hashValue) == key2.hashValue - } - } - describe("hashes matchable argument") { - it("does not equal if argument hashes are different") { - argument1.hashIntoClosure = { $0.combine(1) } - argument2.hashIntoClosure = { $0.combine(2) } - expect(key1.hashValue) != key2.hashValue - } - it("equals if argument hashes are the same") { - argument1.hashIntoClosure = { $0.combine(1) } - argument2.hashIntoClosure = { $0.combine(1) } - expect(key1.hashValue) == key2.hashValue - } - } - } -} } diff --git a/Tests/Unit Specs/ScopedBindingSpec.swift b/Tests/Unit Specs/ScopedBindingSpec.swift deleted file mode 100644 index feb8cd54..00000000 --- a/Tests/Unit Specs/ScopedBindingSpec.swift +++ /dev/null @@ -1,134 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -import Nimble -import Quick -@testable import Swinject - -class ScopedBindingSpec: QuickSpec { override func spec() { - describe("binding builder") { - var bag = [Any]() - let descriptor = AnyTypeDescriptorMock() - let scope = DummyScope() - let makeRef: ReferenceMaker = { _ in noRef(42) } - let builder = ScopedBinding.Builder, Int>(scope, makeRef) { _, _, _ in 0 } - beforeEach { - bag.removeAll() - } - it("makes binding with self as maker") { - let binding = builder.makeBinding(for: descriptor) as? ScopedBinding - expect(binding?.maker is ScopedBinding.Builder, Int>).to(beTrue()) - } - it("makes binding with correct key") { - let binding = builder.makeBinding(for: descriptor) as? ScopedBinding - expect(binding?.key.descriptor) === descriptor - expect(binding?.key.contextType is String.Type).to(beTrue()) - expect(binding?.key.argumentType is Int.Type).to(beTrue()) - } - it("makes binding with correct scope") { - let binding = builder.makeBinding(for: descriptor) as? ScopedBinding - expect(binding?.scope) === scope - } - it("makes binding with correct reference maker") { - let binding = builder.makeBinding(for: descriptor) as? ScopedBinding - expect(binding?.makeRef(0).currentValue as? Int) == 42 - } - it("does not hold on to made reference") { - var human = Human() as Human? - weak var weakHuman = human - let builder = ScopedBinding.Builder, Int>(scope, noRef) { _, _, _ in Human() } - bag.append(builder.makeRef(human!).nextValue) - human = nil - expect(weakHuman).to(beNil()) - } - } - describe("matching") { - var key = AnyBindingKeyMock() - var bindingKey = AnyBindingKeyMock() - var binding: ScopedBinding! - beforeEach { - key = AnyBindingKeyMock() - bindingKey = AnyBindingKeyMock() - bindingKey.matchesReturnValue = false - binding = ScopedBinding( - key: bindingKey, maker: AnyInstanceMakerMock(), scope: AnyScopeMock(), makeRef: noRef - ) - } - it("passes the input key to the binding key") { - _ = binding.matches(key) - expect(bindingKey.matchesReceivedOther) === key - } - it("returns true if binding key matches") { - bindingKey.matchesReturnValue = true - expect(binding.matches(key)).to(beTrue()) - } - it("returns false if binding key matches") { - bindingKey.matchesReturnValue = false - expect(binding.matches(key)).to(beFalse()) - } - } - describe("instance") { - var key = AnyBindingKeyMock() - var registry = StaticScopeRegistryMock() - var scope = AnyScopeMock() - var maker = AnyInstanceMakerMock() - var binding: ScopedBinding! - beforeEach { - registry = StaticScopeRegistryMock() - registry.instanceKeyReturnValue = 0 - scope = AnyScopeMock() - scope.registryForReturnValue = registry - maker = AnyInstanceMakerMock() - maker.makeInstanceArgContextResolverReturnValue = 0 - key = AnyBindingKeyMock() - key.descriptor = AnyTypeDescriptorMock() - binding = ScopedBinding(key: key, maker: maker, scope: scope, makeRef: noRef) - } - it("retrieves registry using passed context") { - _ = try? binding.instance(arg: (), context: "context", resolver: DummyResolver()) - expect(scope.registryForReceivedContext as? String) == "context" - } - it("retrieves instance from registry using a correct key") { - let descriptor = AnyTypeDescriptorMock() - key.descriptor = descriptor - _ = try? binding.instance(arg: 42, context: (), resolver: DummyResolver()) - expect(registry.instanceKeyReceivedKey?.argument as? Int) == 42 - expect(registry.instanceKeyReceivedKey?.descriptor) === descriptor - } - context("instance builder") { - beforeEach { - scope.registryForReturnValue = BuilderScopeRegistry() - } - it("returns instance produced by reference maker") { - binding = ScopedBinding(key: key, maker: maker, scope: scope) { _ in - Reference(currentValue: 42, nextValue: { 42 }) - } - let instance = try? binding.instance(arg: (), context: (), resolver: DummyResolver()) as? Int - expect(instance) == 42 - } - it("invokes reference maker with the instance from the instance maker") { - var makeRefInput: Any? - maker.makeInstanceArgContextResolverReturnValue = 42 - binding = ScopedBinding(key: key, maker: maker, scope: scope) { - makeRefInput = $0; return noRef($0) - } - _ = try? binding.instance(arg: 0, context: (), resolver: DummyResolver()) - expect(makeRefInput as? Int) == 42 - } - it("rethrows error from instance maker") { - maker.makeInstanceArgContextResolverThrowableError = TestError() - expect { - try binding.instance(arg: (), context: (), resolver: DummyResolver()) - }.to(throwError(errorType: TestError.self)) - } - it("invokes instance maker with correct parameters") { - let resolver = DummyResolver() - _ = try? binding.instance(arg: 42, context: "context", resolver: resolver) - expect(maker.makeInstanceArgContextResolverReceivedArguments?.arg as? Int) == 42 - expect(maker.makeInstanceArgContextResolverReceivedArguments?.context as? String) == "context" - expect(maker.makeInstanceArgContextResolverReceivedArguments?.resolver) === resolver - } - } - } -} } From 94a47d0f9c6a8e1ad1c66a405669d9b67507445e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 28 Jul 2019 13:40:56 +0200 Subject: [PATCH 163/239] Extend scope spec --- Sources/Core/Scope.swift | 4 +- Swinject.xcodeproj/project.pbxproj | 10 - Tests/3.0 API/OptionalsSpec.swift | 7 + Tests/3.0 API/ScopesSpec.swift | 97 ++++++++-- Tests/Unit Specs/BinderEnvironmentSpec.swift | 187 ------------------- 5 files changed, 90 insertions(+), 215 deletions(-) delete mode 100644 Tests/Unit Specs/BinderEnvironmentSpec.swift diff --git a/Sources/Core/Scope.swift b/Sources/Core/Scope.swift index 0c6b1fd6..193c6044 100644 --- a/Sources/Core/Scope.swift +++ b/Sources/Core/Scope.swift @@ -13,8 +13,8 @@ public protocol Scope: AnyScope { func registry(for context: Context) -> ScopeRegistry } -extension Scope { - public var contextType: Any.Type { return Context.self } +public extension Scope { + var contextType: Any.Type { return Context.self } func registry(for context: Any) -> ScopeRegistry { return registry(for: context as! Context) diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 2c96b06b..052ede0c 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -42,7 +42,6 @@ 1ED6BD68D92F4FE60978EF22 /* Container+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDA78290D6D60BD0B808571F /* Container+Logging.swift */; }; 1EF3807EB529346903DFA2A1 /* BindingKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = A24B4E8F1CA18603DBB6884A /* BindingKey.swift */; }; 21285CED416F1317E993397A /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59A3946B59EB4D787CCE9F2 /* Container+Registration.swift */; }; - 216D6360147B43F5F47C9EA2 /* BinderEnvironmentSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */; }; 233F3E25FF0B51A3E6611F58 /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; 24114725AE1A834C6E3118F7 /* TaggedTypeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */; }; 2615FC1C92B7E381116B9E57 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; @@ -77,7 +76,6 @@ 3C270A77DE4F1E6BC2F8E863 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; 3CEF021295AD9AF9BF26B71E /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; 3DEFB7CA42D9EFF0B4FBC0F4 /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 38BCCF3F950869BD1891F7A8 /* Swinject.framework */; }; - 3F704A98C01C84BDBD0A52B3 /* BinderEnvironmentSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */; }; 3F8F5645D6D37FCEC1D89393 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B580B43E1891812C97209 /* Binding.swift */; }; 401592294E5D528379BE1AB2 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62682D6ED38742996624B041 /* BasicAssembly.swift */; }; 41C7340BFD2EB66359772733 /* Resolver+LegacyApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A784E2DEC7691D14DDBECD8 /* Resolver+LegacyApi.swift */; }; @@ -91,7 +89,6 @@ 4954CBB07E38E98752AC3347 /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; 49685AB40BEE856C62005C87 /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; 49D71F6CC12C12FE7B6A097A /* ContextSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */; }; - 4A977D2B639B8098AA508389 /* BinderEnvironmentSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */; }; 4B9811CF0604946CCF323ED2 /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92B8E618A08408404FB2A7A /* TypeBinder.swift */; }; 4DC8A58B6607898BAF6504A3 /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */; }; 4DF3DC1CDD3C4948F9BDD3DF /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3586A4987B7C7C8122D674E /* SwinjectError.swift */; }; @@ -104,7 +101,6 @@ 55CA3AA3F28B7CC221ABEC83 /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6D54F152C11C966ECFC55ECB /* Swinject.framework */; }; 55F2E72EA8C3564130F66946 /* ModulesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75BE3AE3E30DFE42A919D825 /* ModulesSpec.swift */; }; 56B2AD6054B63420DD025EC6 /* NonGeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841D83ADB41363D1E38087B4 /* NonGeneratedMocks.swift */; }; - 56D43738C09AA7355F6D529D /* BinderEnvironmentSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */; }; 57BFBA2077E70DC1C2FE796C /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */; }; 58ABEE0321A3061048B65EA2 /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42490D1D0C395951243F5CFF /* Container.swift */; }; 590B861A863A056A0B7FA368 /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADA1541ABC1365DFD7E3377F /* Food.swift */; }; @@ -552,7 +548,6 @@ F290F6B1207A0557A528220B /* Assembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Assembly.swift; sourceTree = ""; }; F446D6BD4C44E16A1D608BFB /* Container+TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+TypeForwarding.swift"; sourceTree = ""; }; F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.TypeForwarding.swift; sourceTree = ""; }; - FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderEnvironmentSpec.swift; sourceTree = ""; }; FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+LegacyApi.swifttemplate"; sourceTree = ""; }; /* End PBXFileReference section */ @@ -621,7 +616,6 @@ 0A05322134E988A4593B5122 /* Unit Specs */ = { isa = PBXGroup; children = ( - FD372C51962DAACD1FAF2269 /* BinderEnvironmentSpec.swift */, BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */, 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */, 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */, @@ -1449,7 +1443,6 @@ 02410BD4FB357F4C6B521608 /* AssemblerSpec.swift in Sources */, DD29D2E60DA979D61F32A39A /* BasicAssembly.swift in Sources */, 3129A37CDC1653C11800E24A /* BehaviorFakes.swift in Sources */, - 216D6360147B43F5F47C9EA2 /* BinderEnvironmentSpec.swift in Sources */, 9A2A6978519F2BBA97DA6EA6 /* BindingSpec.swift in Sources */, 89E2997CB8B90368A15A91CE /* Bridge.swift in Sources */, 0946D0D940D38828FD0DFBAD /* Circularity.swift in Sources */, @@ -1491,7 +1484,6 @@ CBBE28990E0EA82AD8D5E3AF /* AssemblerSpec.swift in Sources */, 401592294E5D528379BE1AB2 /* BasicAssembly.swift in Sources */, A3BFFED76688F149FBAF7C53 /* BehaviorFakes.swift in Sources */, - 56D43738C09AA7355F6D529D /* BinderEnvironmentSpec.swift in Sources */, BB77A5D81C58392964D07233 /* BindingSpec.swift in Sources */, 13CDEC7A6C8E43B58D5CBE3D /* Bridge.swift in Sources */, 2B88BFD81C226C858E0AE2B6 /* Circularity.swift in Sources */, @@ -1533,7 +1525,6 @@ CF4516872D3DA7118DB2B90B /* AssemblerSpec.swift in Sources */, 03122D1B2EA65C89ADC78EC7 /* BasicAssembly.swift in Sources */, 1CA5DF3F93203B226A6FA059 /* BehaviorFakes.swift in Sources */, - 3F704A98C01C84BDBD0A52B3 /* BinderEnvironmentSpec.swift in Sources */, CAA5241DAA201FBB5818C803 /* BindingSpec.swift in Sources */, E4CE31B7B9616EFC93C69341 /* Bridge.swift in Sources */, 4DC8A58B6607898BAF6504A3 /* Circularity.swift in Sources */, @@ -1575,7 +1566,6 @@ 2AA60B7E6EBA9EC6BE92D7CB /* AssemblerSpec.swift in Sources */, 599C7F009F954CDA522244B3 /* BasicAssembly.swift in Sources */, 8E1E051646BBD6E38F4199C2 /* BehaviorFakes.swift in Sources */, - 4A977D2B639B8098AA508389 /* BinderEnvironmentSpec.swift in Sources */, 0207493E1CEE8456E91E3DAE /* BindingSpec.swift in Sources */, 43A74237D8933572BAA0F3B4 /* Bridge.swift in Sources */, C177D9C6969ADA38C1094F6D /* Circularity.swift in Sources */, diff --git a/Tests/3.0 API/OptionalsSpec.swift b/Tests/3.0 API/OptionalsSpec.swift index f813586e..57343470 100644 --- a/Tests/3.0 API/OptionalsSpec.swift +++ b/Tests/3.0 API/OptionalsSpec.swift @@ -44,5 +44,12 @@ class OptionalsSpec: QuickSpec { override func spec() { #if swift(>=5.1) let optional = try? swinject.instance(of: Human?.self) expect(direct) === optional } + // TODO: Optional contexts +// it("injects instance on the optional of a binding's context") { +// let swinject = Swinject { +// bbind(Int.self) & contexted(String.self).provider { (_, c: String) in Int(c)! } +// } +// expect { try swinject.on("42" as String?).instance(of: Int.self) } == 42 +// } #endif } } diff --git a/Tests/3.0 API/ScopesSpec.swift b/Tests/3.0 API/ScopesSpec.swift index 24f8e2c3..921dbc9f 100644 --- a/Tests/3.0 API/ScopesSpec.swift +++ b/Tests/3.0 API/ScopesSpec.swift @@ -7,34 +7,99 @@ import Quick import Swinject class ScopesSpec: QuickSpec { override func spec() { #if swift(>=5.1) - it("can bind scoped singleton") { + it("can bind singleton on a scope without context") { let scope = UnboundScope() let swinject = Swinject { bbind(Human.self) & scoped(scope).singleton { Human() } } - let first = try? swinject.instance() as Human - let second = try? swinject.instance() as Human + let first = try? swinject.instance(of: Human.self) + let second = try? swinject.instance(of: Human.self) expect(first) === second } - it("can close scopes") { - let scope = UnboundScope() + it("can bind singleton on a scope with context") { + let scope = SessionScope() + let session = Session() let swinject = Swinject { bbind(Human.self) & scoped(scope).singleton { Human() } } - let first = try? swinject.instance() as Human - scope.close() - let second = try? swinject.instance() as Human - expect(first) !== second + let first = try? swinject.on(session).instance(of: Human.self) + let second = try? swinject.on(session).instance(of: Human.self) + expect(first) === second } - it("notifies instances when scope is closed") { - let scope = UnboundScope() + it("throws if injecting scoped singleton without context") { + let scope = SessionScope() let swinject = Swinject { - bbind(ClosableMock.self) & scoped(scope).singleton { ClosableMock() } + bbind(Human.self) & scoped(scope).singleton { Human() } + } + expect { try swinject.instance(of: Human.self) }.to(throwError()) + } + it("injects different intances on different contexts") { + let scope = SessionScope() + let swinject = Swinject { + bbind(Human.self) & scoped(scope).singleton { Human() } + } + let first = try? swinject.on(Session()).instance(of: Human.self) + let second = try? swinject.on(Session()).instance(of: Human.self) + expect(first) !== second + } + describe("closable") { + it("can close (some) scopes") { + let scope = UnboundScope() + let swinject = Swinject { + bbind(Human.self) & scoped(scope).singleton { Human() } + } + + let first = try? swinject.instance(of: Human.self) + scope.close() + let second = try? swinject.instance(of: Human.self) + + expect(first) !== second + } + it("notifies instances when scope is closed") { + let scope = UnboundScope() + let swinject = Swinject { + bbind(ClosableMock.self) & scoped(scope).singleton { ClosableMock() } + } + let closable = try? swinject.instance() as ClosableMock + + scope.close() + + expect(closable?.closeCalled) == true + } + it("closes scoped instances when context expires") { + let scope = SessionScope() + var session = Session() as Session? + let swinject = Swinject { + bbind(ClosableMock.self) & scoped(scope).singleton { ClosableMock() } + } + let closable = try? swinject.on(session!).instance(of: ClosableMock.self) + + session = nil + + expect(closable?.closeCalled) == true + } + it("releases scoped instances when context expires") { + let scope = SessionScope() + var session = Session() as Session? + let swinject = Swinject { + bbind(Human.self) & scoped(scope).singleton { Human() } + } + weak var instance = try? swinject.on(session!).instance(of: Human.self) + + session = nil + + expect(instance).to(beNil()) } - let closable = try? swinject.instance() as ClosableMock - expect(closable?.closeCalled) == false - scope.close() - expect(closable?.closeCalled) == true } #endif } } + +class Session { + let registry = StandardScopeRegistry() +} + +struct SessionScope: Scope { + func registry(for session: Session) -> ScopeRegistry { + return session.registry + } +} diff --git a/Tests/Unit Specs/BinderEnvironmentSpec.swift b/Tests/Unit Specs/BinderEnvironmentSpec.swift deleted file mode 100644 index 788d5c79..00000000 --- a/Tests/Unit Specs/BinderEnvironmentSpec.swift +++ /dev/null @@ -1,187 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -import Nimble -import Quick -@testable import Swinject - -// TODO: Reuse code -class BinderEnvironmentSpec: QuickSpec { override func spec() { - describe("implicit") { - describe("singleton") { - it("has correct scope") { - let maker = singleton { 0 }.actual as? ScopedBinding.Builder - expect(maker?.scope) === UnboundScope.root - } - it("does not call builder until instance is requested") { - var called = false - _ = singleton { called = true } - expect(called).to(beFalse()) - } - it("calls builder with given resolver") { - var passedResolver: Resolver? - let resolver = DummyResolver() - let maker = singleton { passedResolver = $0 } - _ = try? maker.makeInstance(resolver: resolver) - expect(passedResolver) === resolver - } - it("rethrows error from builder") { - let maker = singleton { throw SwinjectError() } - expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) - } - } - describe("multiton") { - it("has correct scope") { - let maker = multiton { (_, _: String) in 42 } - let actualMaker = maker.actual as? ScopedBinding.Builder> - expect(actualMaker?.scope) === UnboundScope.root - } - it("calls builder with given resolver") { - var passedResolver: Resolver? - let resolver = DummyResolver() - let maker = multiton { (r, _: String) in passedResolver = r } - _ = try? maker.makeInstance(arg: box(""), resolver: resolver) - expect(passedResolver) === resolver - } - it("rethrows error from builder") { - let maker = multiton { (_, _: String) in throw SwinjectError() } - expect { try maker.makeInstance(arg: box(""), resolver: DummyResolver()) }.to(throwError()) - } - } - } - describe("scoped") { - var scope = AnyScopeMock() - var environment: ScopedEnvironment! - beforeEach { - scope = AnyScopeMock() - environment = scoped(scope) - } - describe("singleton") { - it("has correct scope") { - let maker = environment.singleton { 42 } - let actualMaker = maker.actual as? ScopedBinding.Builder - expect(actualMaker?.scope) === scope - } - it("returns instance made by builder") { - let maker = environment.singleton { 42 } - expect { try maker.makeInstance(resolver: DummyResolver()) } == 42 - } - it("does not call builder until instance is requested") { - var called = false - _ = environment.singleton { called = true } - expect(called).to(beFalse()) - } - it("calls builder with given resolver") { - var passedResolver: Resolver? - let resolver = DummyResolver() - let maker = environment.singleton { passedResolver = $0 } - _ = try? maker.makeInstance(resolver: resolver) - expect(passedResolver) === resolver - } - it("calls builder with given context") { - var passedContext: Any? - let maker = environment.singleton { _, c in passedContext = c } - _ = try? maker.makeInstance(context: "context", resolver: DummyResolver()) - expect(passedContext as? String) == "context" - } - it("rethrows error from builder") { - let maker = environment.singleton { throw SwinjectError() } - expect { try maker.makeInstance(resolver: DummyResolver()) }.to(throwError()) - } - it("does not reuse instance") { - let maker = environment.singleton { _, _ in Human() } - let instance1 = try? maker.makeInstance(resolver: DummyResolver()) - let instance2 = try? maker.makeInstance(resolver: DummyResolver()) - expect(instance1) !== instance2 - } - } - describe("multiton") { - it("has correct scope") { - let maker = environment.multiton { (_, _, _: String) in 42 } - let actualMaker = maker.actual as? ScopedBinding.Builder> - expect(actualMaker?.scope) === scope - } - it("returns instance made by builder method") { - let maker = environment.multiton { (_, _, _: String) in 42 } - expect { try maker.makeInstance(arg: box(""), resolver: DummyResolver()) } == 42 - } - it("does not call builder until instance is requested") { - var called = false - _ = environment.multiton { (_, _, _: String) in called = true } - expect(called).to(beFalse()) - } - it("calls builder with given resolver") { - var passedResolver: Resolver? - let resolver = DummyResolver() - let maker = environment.multiton { (r, _, _: String) in passedResolver = r } - _ = try? maker.makeInstance(arg: box(""), resolver: resolver) - expect(passedResolver) === resolver - } - it("calls builder with given context") { - var passedContext: Any? - let maker = environment.multiton { (_, c, _: String) in passedContext = c } - _ = try? maker.makeInstance(arg: box(""), context: "context", resolver: DummyResolver()) - expect(passedContext as? String) == "context" - } - it("calls builder with given argument") { - var passedArgument: Int? - let maker = environment.multiton { (_, _, arg: Int) in passedArgument = arg } - _ = try? maker.makeInstance(arg: box(42), resolver: DummyResolver()) - expect(passedArgument) == 42 - } - it("rethrows error from builder") { - let maker = environment.multiton { (_, _, _: String) in throw SwinjectError() } - expect { try maker.makeInstance(arg: box(""), resolver: DummyResolver()) }.to(throwError()) - } - it("does not reuse instance") { - let maker = environment.multiton { (_, _, _: String) in Human() } - let instance1 = try? maker.makeInstance(arg: box(""), resolver: DummyResolver()) - let instance2 = try? maker.makeInstance(arg: box(""), resolver: DummyResolver()) - expect(instance1) !== instance2 - } - describe("multiple arguments") { - it("works with 2 arguments") { - let maker = environment.multiton { (_, _, _: Int, _: Double) in 42 } - let arguments = box(1, 1.0) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 - } - it("works with 3 arguments") { - let maker = environment.multiton { (_, _, _: Int, _: Double, _: String) in 42 } - let arguments = box(1, 1.0, "") - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 - } - it("works with 4 arguments") { - let maker = environment.multiton { (_, _, _: Int, _: Double, _: String, _: Float) in 42 } - let arguments = box(1, 1.0, "", Float(1.0)) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 - } - it("works with 5 arguments") { - let maker = environment.multiton { (_, _, _: Int, _: Double, _: String, _: Float, _: Int) in 42 } - let arguments = box(1, 1.0, "", Float(1.0), 5) - expect { try maker.makeInstance(arg: arguments, resolver: DummyResolver()) } == 42 - } - } - } - } -} } - -private extension SomeBindingMaker { - var actual: AnyInstanceMaker { return anyActual as! AnyInstanceMaker } - - func makeInstance(resolver: Resolver) throws -> BoundType { - return try actual.makeInstance(arg: (), context: (), resolver: resolver) as! BoundType - } - - func makeInstance(context: Any, resolver: Resolver) throws -> BoundType { - return try actual.makeInstance(arg: (), context: context, resolver: resolver) as! BoundType - } - - func makeInstance(arg: Any, resolver: Resolver) throws -> BoundType { - return try actual.makeInstance(arg: arg, context: (), resolver: resolver) as! BoundType - } - - func makeInstance(arg: Any, context: Any, resolver: Resolver) throws -> BoundType { - return try actual.makeInstance(arg: arg, context: context, resolver: resolver) as! BoundType - } -} From b30fe1a1a40ac0a8512522ec15562a3a5029e3ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 28 Jul 2019 14:02:23 +0200 Subject: [PATCH 164/239] Remove mocks --- .gitignore | 3 + .sourcery.yml | 3 +- Sources/Core/Binding.swift | 2 - Sources/Core/BindingKey.swift | 1 - Sources/Core/Closable.swift | 1 - Sources/Core/ContextTranslator.swift | 1 - Sources/Core/InstanceMaker.swift | 1 - Sources/Core/Matchable.swift | 1 - Sources/Core/Scope.swift | 1 - Sources/Core/TypeDescriptor.swift | 1 - Swinject.xcodeproj/project.pbxproj | 148 ++----- .../xcschemes/Swinject-iOS.xcscheme | 1 - .../xcschemes/Swinject-macOS.xcscheme | 1 - .../xcschemes/Swinject-tvOS.xcscheme | 1 - .../xcschemes/Swinject-watchOS.xcscheme | 1 - Templates/AutoMockable.stencil | 115 ------ Tests/3.0 API/ScopesSpec.swift | 12 +- Tests/LinuxConfig.swift | 1 - Tests/Support/GeneratedMocks.swift | 373 ------------------ Tests/Support/NonGeneratedMocks.swift | 87 ---- Tests/Support/TestModels.swift | 13 + .../StandardScopeRegistrySpec.swift | 40 +- .../Unit Specs/SwinjectTreeBuilderSpec.swift | 63 +-- project.yml | 1 - 24 files changed, 113 insertions(+), 759 deletions(-) delete mode 100644 Templates/AutoMockable.stencil delete mode 100644 Tests/Support/GeneratedMocks.swift delete mode 100644 Tests/Support/NonGeneratedMocks.swift diff --git a/.gitignore b/.gitignore index f4118b3f..048d1eff 100644 --- a/.gitignore +++ b/.gitignore @@ -65,5 +65,8 @@ fastlane/screenshots ## Mac .DS_Store +## Sourcery +.sourcery.dump + ## Swinject Swinject.framework.zip diff --git a/.sourcery.yml b/.sourcery.yml index 4b38cc34..360f7ea1 100644 --- a/.sourcery.yml +++ b/.sourcery.yml @@ -1,7 +1,6 @@ sources: - Sources - - Tests/Support/NonGeneratedMocks.swift templates: - Templates output: - Tests/Support/GeneratedMocks.swift + .sourcery.dump diff --git a/Sources/Core/Binding.swift b/Sources/Core/Binding.swift index 7ffdf0ab..e0da60b7 100644 --- a/Sources/Core/Binding.swift +++ b/Sources/Core/Binding.swift @@ -2,13 +2,11 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -// sourcery: AutoMockable public protocol Binding: SwinjectEntry { func matches(_ key: AnyBindingKey) -> Bool func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any } -// sourcery: AutoMockable public protocol BindingMaker { associatedtype BoundType func makeBinding(for descriptor: AnyTypeDescriptor) -> Binding diff --git a/Sources/Core/BindingKey.swift b/Sources/Core/BindingKey.swift index ae8d9ead..5bf33602 100644 --- a/Sources/Core/BindingKey.swift +++ b/Sources/Core/BindingKey.swift @@ -2,7 +2,6 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -// sourcery: AutoMockable public protocol AnyBindingKey { var contextType: Any.Type { get } var argumentType: Any.Type { get } diff --git a/Sources/Core/Closable.swift b/Sources/Core/Closable.swift index 6837eabd..1d58d804 100644 --- a/Sources/Core/Closable.swift +++ b/Sources/Core/Closable.swift @@ -2,7 +2,6 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -// sourcery: AutoMockable public protocol Closable { func close() } diff --git a/Sources/Core/ContextTranslator.swift b/Sources/Core/ContextTranslator.swift index 3052026e..db9cb4eb 100644 --- a/Sources/Core/ContextTranslator.swift +++ b/Sources/Core/ContextTranslator.swift @@ -2,7 +2,6 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -// sourcery: AutoMockable protocol AnyContextTranslator: SwinjectEntry { var sourceType: Any.Type { get } var targetType: Any.Type { get } diff --git a/Sources/Core/InstanceMaker.swift b/Sources/Core/InstanceMaker.swift index 573403a0..df25ecff 100644 --- a/Sources/Core/InstanceMaker.swift +++ b/Sources/Core/InstanceMaker.swift @@ -2,7 +2,6 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -// sourcery: AutoMockable protocol AnyInstanceMaker { func makeInstance(arg: Any, context: Any, resolver: Resolver) throws -> Any } diff --git a/Sources/Core/Matchable.swift b/Sources/Core/Matchable.swift index d8713a64..335762c5 100644 --- a/Sources/Core/Matchable.swift +++ b/Sources/Core/Matchable.swift @@ -2,7 +2,6 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -// sourcery: AutoMockable public protocol Matchable { func matches(_ other: Any) -> Bool func hash(into hasher: inout Hasher) diff --git a/Sources/Core/Scope.swift b/Sources/Core/Scope.swift index 193c6044..abee896e 100644 --- a/Sources/Core/Scope.swift +++ b/Sources/Core/Scope.swift @@ -2,7 +2,6 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -// sourcery: AutoMockable public protocol AnyScope { var contextType: Any.Type { get } func registry(for context: Any) -> ScopeRegistry diff --git a/Sources/Core/TypeDescriptor.swift b/Sources/Core/TypeDescriptor.swift index c8af05fa..ea3de5ec 100644 --- a/Sources/Core/TypeDescriptor.swift +++ b/Sources/Core/TypeDescriptor.swift @@ -2,7 +2,6 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -// sourcery: AutoMockable public protocol AnyTypeDescriptor: Matchable {} public protocol TypeDescriptor: AnyTypeDescriptor { diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 052ede0c..b53e2dd3 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -27,6 +27,7 @@ 0BA8216CFBC61A93F4948ABE /* InstanceMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CADDB3E9E363310028AA5920 /* InstanceMaker.swift */; }; 0CD787EACEBFD1051D358E7D /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; 0CE1126436F680F9684837E4 /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; + 0CE158916595980A7C8272D3 /* SingletonSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46F05CC591903E2B04B6D8ED /* SingletonSpec.swift */; }; 0D5C4A278A16AB3A163148AF /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; 128913D570B4A8BBF40866BE /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; 13CDEC7A6C8E43B58D5CBE3D /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; @@ -52,13 +53,13 @@ 2AA60B7E6EBA9EC6BE92D7CB /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; 2B506344F37CE5F5C5C02C05 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; 2B88BFD81C226C858E0AE2B6 /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */; }; - 2C1BD6D785E310B6F8A3CAC9 /* NonGeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841D83ADB41363D1E38087B4 /* NonGeneratedMocks.swift */; }; 2C352AAD1AC7D82A4A059046 /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; 2C3EB507FFA03D18B2909405 /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8B9785AAE94A5447FA307242 /* Swinject.framework */; }; 2CB057F2A16DA462E0517AAB /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; 2D020C6391A4F6A2118585B8 /* Reference.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73B4B777290FF5D38A8914CC /* Reference.swift */; }; 2DD6F290740EA69B3E73E0EA /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */; }; 3099172980F9E9143C0A1C20 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; + 30D247E8083858C233B92908 /* SingletonSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46F05CC591903E2B04B6D8ED /* SingletonSpec.swift */; }; 3129A37CDC1653C11800E24A /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EA566CD336DB8343ADFAF9B /* BehaviorFakes.swift */; }; 31392A9EF619329716144F95 /* Opaque.swift in Sources */ = {isa = PBXBuildFile; fileRef = C68B98C653ABDED9C3D17DB3 /* Opaque.swift */; }; 31729A1E5F50EF30FDD427AD /* ScopesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D3C59E84B5FD0C13F487838 /* ScopesSpec.swift */; }; @@ -100,7 +101,6 @@ 54956014A1774DF8357B69E6 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; 55CA3AA3F28B7CC221ABEC83 /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6D54F152C11C966ECFC55ECB /* Swinject.framework */; }; 55F2E72EA8C3564130F66946 /* ModulesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75BE3AE3E30DFE42A919D825 /* ModulesSpec.swift */; }; - 56B2AD6054B63420DD025EC6 /* NonGeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841D83ADB41363D1E38087B4 /* NonGeneratedMocks.swift */; }; 57BFBA2077E70DC1C2FE796C /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */; }; 58ABEE0321A3061048B65EA2 /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42490D1D0C395951243F5CFF /* Container.swift */; }; 590B861A863A056A0B7FA368 /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADA1541ABC1365DFD7E3377F /* Food.swift */; }; @@ -147,7 +147,6 @@ 77BF219EAB4FC8475943CECC /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6D434EB4C13CF9D9FA6D80CB /* Swinject.framework */; }; 789BF74652A2424EB8F7EF47 /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 7A7032384E07DAD308D4F70A /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 8B9785AAE94A5447FA307242 /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 7AE3FF1C0B4860942D90B68B /* NonGeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841D83ADB41363D1E38087B4 /* NonGeneratedMocks.swift */; }; 7D0683F36CE56228AC2CD489 /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C074BAC560F277E806146C60 /* SimpleBinding.swift */; }; 7D6F664091C70BABBFB61D53 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; 7E3C3E6FD07F3BD76024770A /* InjectionVariation.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C516EFA0CA22D19F07B27E /* InjectionVariation.swift */; }; @@ -179,6 +178,7 @@ 96EA0A5DF33F025EBE0B67D2 /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; 979518E078B187549E11DF48 /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; 97C2EA47D7623AFD723AFE93 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */; }; + 980FED1DBC62B65597E2828B /* SingletonSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46F05CC591903E2B04B6D8ED /* SingletonSpec.swift */; }; 98322F9371E1A8461BC614D1 /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; 9885175B6062254D54CFE4D4 /* InstanceMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CADDB3E9E363310028AA5920 /* InstanceMaker.swift */; }; 98ACB1A09194572A946CA90D /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */; }; @@ -187,9 +187,7 @@ 99C5D861B16FAFAD3F9E28C5 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */; }; 9A21ECA8F283E1E144CEC763 /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; 9A2A6978519F2BBA97DA6EA6 /* BindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E59A67F3548663368788B17 /* BindingSpec.swift */; }; - 9A8164D6696C87BFEC7325C3 /* GeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */; }; 9AD60A86D5A0DF4513C1EA8D /* TaggedTypeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */; }; - 9C12EB42EC058994805E93A6 /* GeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */; }; 9C15BE01C1EA41061CDB7918 /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C074BAC560F277E806146C60 /* SimpleBinding.swift */; }; 9CCAB8EE342CCC8D2FB187C1 /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */; }; 9CEE20BD42795D5E5F39BF20 /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; @@ -232,7 +230,7 @@ B42331BF00B482369B908BB8 /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BFF4BA99493C54260878C4 /* ObjectScope.swift */; }; B4B66D7251BDDE25D6D7FB3C /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BFF4BA99493C54260878C4 /* ObjectScope.swift */; }; B5FF5DFE394B6B1BB930D88D /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */; }; - B703A24C1A963C6BAC95B9A5 /* GeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */; }; + B65DE0B0562540CC8CEC48F3 /* SingletonSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46F05CC591903E2B04B6D8ED /* SingletonSpec.swift */; }; B7653A6427A5E284E9A1D6D3 /* ServiceEntry+TypeForwarding.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */; }; B84167AC8C6BEB57C4D0695A /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; B9550BE2BA6FA5731BEC87FD /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; @@ -254,7 +252,6 @@ C223101DB417F1237A8421E1 /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 6D434EB4C13CF9D9FA6D80CB /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; C38A2EBF4D1904E7D6989989 /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADA1541ABC1365DFD7E3377F /* Food.swift */; }; C3FDE105B08336F26CC95BAA /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = A10187BB3A994165E7FC1528 /* ScopedBinding.swift */; }; - C4E9DC50A2FDAE4D36A925D9 /* NonGeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841D83ADB41363D1E38087B4 /* NonGeneratedMocks.swift */; }; C637E97E193BB1DADDDC6C21 /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1E726A651C3AFE92C19608B /* SwinjectModule.swift */; }; C6D60E2AEC381998223145B2 /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; C76374CAFE7C2BCCE52F1BB1 /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 351C4221896DDB8572BD6CB5 /* Person.swift */; }; @@ -262,16 +259,10 @@ C952D5869D87743297968E9A /* StandardScopeRegistrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */; }; CA5523B60E51EB98719CF1F8 /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; CAA5241DAA201FBB5818C803 /* BindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E59A67F3548663368788B17 /* BindingSpec.swift */; }; - CB06DC3BC4A32776BBD90DDF /* GeneratedMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */; }; CB0B308F3D3A831A28127462 /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59A3946B59EB4D787CCE9F2 /* Container+Registration.swift */; }; - CB9666A26D85B92BA1357160 /* AutoMockable.stencil in Resources */ = {isa = PBXBuildFile; fileRef = 4286F98133270A36F19E5CD0 /* AutoMockable.stencil */; }; CB9E8D16D7A0620A1F7A32A3 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; CBBE28990E0EA82AD8D5E3AF /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; CBE63031F33303F3E503CEF2 /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; - CD9954F222EDB05B00032165 /* SingletonSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD9954F022EDAF9A00032165 /* SingletonSpec.swift */; }; - CD9954F322EDB05C00032165 /* SingletonSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD9954F022EDAF9A00032165 /* SingletonSpec.swift */; }; - CD9954F422EDB05C00032165 /* SingletonSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD9954F022EDAF9A00032165 /* SingletonSpec.swift */; }; - CD9954F522EDB05D00032165 /* SingletonSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD9954F022EDAF9A00032165 /* SingletonSpec.swift */; }; CE5AFED22F04B96713ED76D7 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ADC44E9312C3B974AFD8F07B /* Nimble.framework */; }; CECF5BD14BCDF5248771A06A /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; CEE763218A90832454A6E2DE /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */; }; @@ -447,14 +438,14 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 01DEC4D20CE554C9DFBD0A8D /* Resolver+Injection.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+Injection.swifttemplate"; sourceTree = ""; }; + 01DEC4D20CE554C9DFBD0A8D /* Resolver+Injection.swifttemplate */ = {isa = PBXFileReference; path = "Resolver+Injection.swifttemplate"; sourceTree = ""; }; 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.swift; sourceTree = ""; }; 09FC792715B1658721F76885 /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 0CA449690AE00F6300DE8ACA /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 0DC67CB109091002AB433A46 /* SwinjectTests.xctest */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.cfbundle; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 0E0B580B43E1891812C97209 /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; 10480F2154EAA0414D4C1F55 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .swiftlint.yml; sourceTree = ""; }; + 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */ = {isa = PBXFileReference; path = .swiftlint.yml; sourceTree = ""; }; 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SynchronizedResolverSpec.swift; sourceTree = ""; }; 13513FA012659ADE699A3608 /* LazySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LazySpec.swift; sourceTree = ""; }; 1A006CC804F9AB8ACC121029 /* Utils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = ""; }; @@ -463,7 +454,7 @@ 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Circularity.swift; sourceTree = ""; }; 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Behavior.swift; sourceTree = ""; }; 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Arguments.swift; sourceTree = ""; }; - 26EEC28683E4A26B3092E8BA /* BinderEnvironment.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = BinderEnvironment.swifttemplate; sourceTree = ""; }; + 26EEC28683E4A26B3092E8BA /* BinderEnvironment.swifttemplate */ = {isa = PBXFileReference; path = BinderEnvironment.swifttemplate; sourceTree = ""; }; 273FB7A6277E0841E1570990 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; 2E0C3E4D518BC1FEF3EF8D33 /* BinderVariation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderVariation.swift; sourceTree = ""; }; 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; @@ -475,8 +466,8 @@ 38BCCF3F950869BD1891F7A8 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaggedTypeSpec.swift; sourceTree = ""; }; 42490D1D0C395951243F5CFF /* Container.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.swift; sourceTree = ""; }; - 4286F98133270A36F19E5CD0 /* AutoMockable.stencil */ = {isa = PBXFileReference; lastKnownFileType = text; path = AutoMockable.stencil; sourceTree = ""; }; 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmploymentAssembly.swift; sourceTree = ""; }; + 46F05CC591903E2B04B6D8ED /* SingletonSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingletonSpec.swift; sourceTree = ""; }; 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTree.swift; sourceTree = ""; }; 494AA2AA587975747596C157 /* ProviderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProviderSpec.swift; sourceTree = ""; }; 4A784E2DEC7691D14DDBECD8 /* Resolver+LegacyApi.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Resolver+LegacyApi.swift"; sourceTree = ""; }; @@ -507,13 +498,11 @@ 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ServiceEntry+TypeForwarding.swift"; sourceTree = ""; }; 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextTranslator.swift; sourceTree = ""; }; 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistry.swift; sourceTree = ""; }; - 808C1063CA90CC593C7E0E9C /* MatchableBoxes.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = MatchableBoxes.swifttemplate; sourceTree = ""; }; + 808C1063CA90CC593C7E0E9C /* MatchableBoxes.swifttemplate */ = {isa = PBXFileReference; path = MatchableBoxes.swifttemplate; sourceTree = ""; }; 823617F3B8A9192F56B13331 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; - 841D83ADB41363D1E38087B4 /* NonGeneratedMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonGeneratedMocks.swift; sourceTree = ""; }; - 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeneratedMocks.swift; sourceTree = ""; }; 8B9785AAE94A5447FA307242 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTreeBuilderSpec.swift; sourceTree = ""; }; - 90191C25A2D66E07C4E9CD73 /* SwiftCode.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = SwiftCode.swifttemplate; sourceTree = ""; }; + 90191C25A2D66E07C4E9CD73 /* SwiftCode.swifttemplate */ = {isa = PBXFileReference; path = SwiftCode.swifttemplate; sourceTree = ""; }; 938425B216B78A06EC10504A /* LinuxConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinuxConfig.swift; sourceTree = ""; }; 9620155728133F451B31C0AD /* Swinject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Swinject.swift; sourceTree = ""; }; 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistryKey.swift; sourceTree = ""; }; @@ -530,7 +519,7 @@ B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderEnvironment.swift; sourceTree = ""; }; B92B8E618A08408404FB2A7A /* TypeBinder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinder.swift; sourceTree = ""; }; BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StandardScopeRegistrySpec.swift; sourceTree = ""; }; - BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "ServiceEntry+TypeForwarding.swifttemplate"; sourceTree = ""; }; + BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */ = {isa = PBXFileReference; path = "ServiceEntry+TypeForwarding.swifttemplate"; sourceTree = ""; }; BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Behavior.swift; sourceTree = ""; }; C074BAC560F277E806146C60 /* SimpleBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleBinding.swift; sourceTree = ""; }; C1E726A651C3AFE92C19608B /* SwinjectModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectModule.swift; sourceTree = ""; }; @@ -539,16 +528,15 @@ C765B92B00C0AC8625BB4AC9 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; CADDB3E9E363310028AA5920 /* InstanceMaker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceMaker.swift; sourceTree = ""; }; CC85CB215058F95C0BC190B1 /* Bridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bridge.swift; sourceTree = ""; }; - CD9954F022EDAF9A00032165 /* SingletonSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingletonSpec.swift; sourceTree = ""; }; CDA78290D6D60BD0B808571F /* Container+Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Logging.swift"; sourceTree = ""; }; - CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; + CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextSpec.swift; sourceTree = ""; }; E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRequest.swift; sourceTree = ""; }; E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; F290F6B1207A0557A528220B /* Assembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Assembly.swift; sourceTree = ""; }; F446D6BD4C44E16A1D608BFB /* Container+TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+TypeForwarding.swift"; sourceTree = ""; }; F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.TypeForwarding.swift; sourceTree = ""; }; - FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+LegacyApi.swifttemplate"; sourceTree = ""; }; + FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */ = {isa = PBXFileReference; path = "Resolver+LegacyApi.swifttemplate"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -598,7 +586,6 @@ 07354387D49F6D7BBBA4F3AC /* Templates */ = { isa = PBXGroup; children = ( - 4286F98133270A36F19E5CD0 /* AutoMockable.stencil */, 26EEC28683E4A26B3092E8BA /* BinderEnvironment.swifttemplate */, 2E0C3E4D518BC1FEF3EF8D33 /* BinderVariation.swift */, CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */, @@ -671,8 +658,6 @@ children = ( CC85CB215058F95C0BC190B1 /* Bridge.swift */, 5AB605ED0F735221D0EB1D5F /* Convenience.swift */, - 898BCE370D2257FEAED9E7EA /* GeneratedMocks.swift */, - 841D83ADB41363D1E38087B4 /* NonGeneratedMocks.swift */, 722CAC1761180366DE75A4A6 /* TestModels.swift */, 1F06930A1A2C8BA94D6875BA /* Legacy */, ); @@ -746,10 +731,10 @@ 6E59A67F3548663368788B17 /* BindingSpec.swift */, DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */, 670DB253ECD5CE1468A7F2E3 /* InjectionSpec.swift */, - CD9954F022EDAF9A00032165 /* SingletonSpec.swift */, 75BE3AE3E30DFE42A919D825 /* ModulesSpec.swift */, 50D6F2639990DD5BAD9578B0 /* OptionalsSpec.swift */, 1D3C59E84B5FD0C13F487838 /* ScopesSpec.swift */, + 46F05CC591903E2B04B6D8ED /* SingletonSpec.swift */, ); path = "3.0 API"; sourceTree = ""; @@ -1131,7 +1116,6 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - CB9666A26D85B92BA1357160 /* AutoMockable.stencil in Resources */, BEFFC7B36FE5810169C81B97 /* BinderEnvironment.swifttemplate in Resources */, BFE22F9F2E88F177302E9D19 /* Container+Registration.swifttemplate in Resources */, 1C82BFD00FCC384DB3AE6A89 /* MatchableBoxes.swifttemplate in Resources */, @@ -1456,18 +1440,16 @@ EE35DF2D353E2C5110DA5C42 /* Convenience.swift in Sources */, 934AFACA6BFF24AD3503F98D /* EmploymentAssembly.swift in Sources */, 180DB4397B4C05E26F819C85 /* Food.swift in Sources */, - CD9954F222EDB05B00032165 /* SingletonSpec.swift in Sources */, - 9A8164D6696C87BFEC7325C3 /* GeneratedMocks.swift in Sources */, 818DF17D671EA1022CE59A2A /* InjectionSpec.swift in Sources */, AE6EAB8CC32ED5E1789D55B7 /* LazySpec.swift in Sources */, A834D948AB86794CA3304B98 /* LinuxConfig.swift in Sources */, B0B139FADA6AE07C79847EBA /* LoadAwareAssembly.swift in Sources */, F1F3BA81462E2362374BD4C4 /* ModulesSpec.swift in Sources */, - 2C1BD6D785E310B6F8A3CAC9 /* NonGeneratedMocks.swift in Sources */, 72F09FC92FFB0F7C32D8E2A5 /* OptionalsSpec.swift in Sources */, 628EBFBA0031B1FA2E29F583 /* Person.swift in Sources */, 708E1C453CBC76ED26FA2FCB /* ProviderSpec.swift in Sources */, 33B86F2D33219879731CDDF0 /* ScopesSpec.swift in Sources */, + 30D247E8083858C233B92908 /* SingletonSpec.swift in Sources */, 72217E47D83C3CA6D97640B9 /* StandardScopeRegistrySpec.swift in Sources */, 640F7A55D9A671FA112C8083 /* SwinjectTreeBuilderSpec.swift in Sources */, F7CD04FB09FC7F18E9E001CF /* SynchronizedResolverSpec.swift in Sources */, @@ -1497,18 +1479,16 @@ A882705E4199EF759E80B311 /* Convenience.swift in Sources */, 19416C867F15E88394A0ABD1 /* EmploymentAssembly.swift in Sources */, 590B861A863A056A0B7FA368 /* Food.swift in Sources */, - CD9954F322EDB05C00032165 /* SingletonSpec.swift in Sources */, - 9C12EB42EC058994805E93A6 /* GeneratedMocks.swift in Sources */, 95A6654089875BCC863FB53B /* InjectionSpec.swift in Sources */, 979518E078B187549E11DF48 /* LazySpec.swift in Sources */, B96A6370D549AAC383360ABC /* LinuxConfig.swift in Sources */, 335CE53CEC2360DC86D58F07 /* LoadAwareAssembly.swift in Sources */, 004B06007E4FDD8F44B7EC89 /* ModulesSpec.swift in Sources */, - 56B2AD6054B63420DD025EC6 /* NonGeneratedMocks.swift in Sources */, D941D81F59900A52805D6B4A /* OptionalsSpec.swift in Sources */, EB3420214A9E68A0247D0F2C /* Person.swift in Sources */, CF9535A0DCAFF23F4D62F871 /* ProviderSpec.swift in Sources */, 0068DAA4AA322F00AF53731F /* ScopesSpec.swift in Sources */, + B65DE0B0562540CC8CEC48F3 /* SingletonSpec.swift in Sources */, C952D5869D87743297968E9A /* StandardScopeRegistrySpec.swift in Sources */, A308578B99D33C7E33632E85 /* SwinjectTreeBuilderSpec.swift in Sources */, 3BDB44DE92D2377334894804 /* SynchronizedResolverSpec.swift in Sources */, @@ -1538,18 +1518,16 @@ EEAD7E215908DF939ECCDCC9 /* Convenience.swift in Sources */, 4E4DC8CDD1BA51FB66A332C2 /* EmploymentAssembly.swift in Sources */, BE6C13A3492E3CFC08E231B0 /* Food.swift in Sources */, - CD9954F522EDB05D00032165 /* SingletonSpec.swift in Sources */, - CB06DC3BC4A32776BBD90DDF /* GeneratedMocks.swift in Sources */, 42FE916C1593A9289E1A28BC /* InjectionSpec.swift in Sources */, 6A0FD11468B3852E48B682BE /* LazySpec.swift in Sources */, B00627BABCF9181C7B58609E /* LinuxConfig.swift in Sources */, ED6CB3935B15F30A182ED6D0 /* LoadAwareAssembly.swift in Sources */, D9F132E4A6F6BC2BDD5DFCAA /* ModulesSpec.swift in Sources */, - 7AE3FF1C0B4860942D90B68B /* NonGeneratedMocks.swift in Sources */, A453A5A7E0EC0FE161AA34D5 /* OptionalsSpec.swift in Sources */, C76374CAFE7C2BCCE52F1BB1 /* Person.swift in Sources */, 4954CBB07E38E98752AC3347 /* ProviderSpec.swift in Sources */, 31729A1E5F50EF30FDD427AD /* ScopesSpec.swift in Sources */, + 0CE158916595980A7C8272D3 /* SingletonSpec.swift in Sources */, 0720BEA814AD514378380ACB /* StandardScopeRegistrySpec.swift in Sources */, 3CEF021295AD9AF9BF26B71E /* SwinjectTreeBuilderSpec.swift in Sources */, 546FF827DB6D42490D1CA439 /* SynchronizedResolverSpec.swift in Sources */, @@ -1579,18 +1557,16 @@ 48D1568CB41BE4B6597FD535 /* Convenience.swift in Sources */, A59C6C434288333EDAF951C4 /* EmploymentAssembly.swift in Sources */, C38A2EBF4D1904E7D6989989 /* Food.swift in Sources */, - CD9954F422EDB05C00032165 /* SingletonSpec.swift in Sources */, - B703A24C1A963C6BAC95B9A5 /* GeneratedMocks.swift in Sources */, AD214F3DBAB4F16C88322CAC /* InjectionSpec.swift in Sources */, 0CD787EACEBFD1051D358E7D /* LazySpec.swift in Sources */, 70368EC369287B4EE767E929 /* LinuxConfig.swift in Sources */, A2D3B18BE38948A427B60BC5 /* LoadAwareAssembly.swift in Sources */, 55F2E72EA8C3564130F66946 /* ModulesSpec.swift in Sources */, - C4E9DC50A2FDAE4D36A925D9 /* NonGeneratedMocks.swift in Sources */, F6EEF5F7B57DC0E44EF569A4 /* OptionalsSpec.swift in Sources */, BEEFBE87EB17D56BA8D47358 /* Person.swift in Sources */, 48F40377D116C6B1B786C329 /* ProviderSpec.swift in Sources */, EA0D19F7DF0355C774B0F40B /* ScopesSpec.swift in Sources */, + 980FED1DBC62B65597E2828B /* SingletonSpec.swift in Sources */, 0B61DC733616A8ED4ED77FA7 /* StandardScopeRegistrySpec.swift in Sources */, 233F3E25FF0B51A3E6611F58 /* SwinjectTreeBuilderSpec.swift in Sources */, 890CCD2800597F6FB7C6FD31 /* SynchronizedResolverSpec.swift in Sources */, @@ -1845,11 +1821,7 @@ "$(PROJECT_DIR)/Carthage/Build/iOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -1887,10 +1859,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; PRODUCT_NAME = Swinject; SDKROOT = macosx; SKIP_INSTALL = YES; @@ -1907,11 +1876,7 @@ "$(PROJECT_DIR)/Carthage/Build/tvOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = appletvos; TARGETED_DEVICE_FAMILY = 3; @@ -1929,10 +1894,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = Swinject; SDKROOT = appletvos; SKIP_INSTALL = YES; @@ -1950,11 +1912,7 @@ "$(PROJECT_DIR)/Carthage/Build/iOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -1971,11 +1929,7 @@ "$(PROJECT_DIR)/Carthage/Build/Mac", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - "@loader_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = macosx; }; @@ -2065,10 +2019,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = Swinject; SDKROOT = appletvos; SKIP_INSTALL = YES; @@ -2086,11 +2037,7 @@ "$(PROJECT_DIR)/Carthage/Build/watchOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = watchos; SKIP_INSTALL = YES; @@ -2109,10 +2056,7 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; SDKROOT = macosx; SKIP_INSTALL = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -2130,10 +2074,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = Swinject; SDKROOT = iphoneos; SKIP_INSTALL = YES; @@ -2151,11 +2092,7 @@ "$(PROJECT_DIR)/Carthage/Build/watchOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = watchos; SKIP_INSTALL = YES; @@ -2173,11 +2110,7 @@ "$(PROJECT_DIR)/Carthage/Build/Mac", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - "@loader_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = macosx; }; @@ -2192,11 +2125,7 @@ "$(PROJECT_DIR)/Carthage/Build/tvOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = appletvos; TARGETED_DEVICE_FAMILY = 3; @@ -2214,10 +2143,7 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; SDKROOT = macosx; SKIP_INSTALL = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -2236,10 +2162,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; PRODUCT_NAME = Swinject; SDKROOT = macosx; SKIP_INSTALL = YES; @@ -2258,10 +2181,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = Swinject; SDKROOT = iphoneos; SKIP_INSTALL = YES; diff --git a/Swinject.xcodeproj/xcshareddata/xcschemes/Swinject-iOS.xcscheme b/Swinject.xcodeproj/xcshareddata/xcschemes/Swinject-iOS.xcscheme index 80c9709d..7020ad39 100644 --- a/Swinject.xcodeproj/xcshareddata/xcschemes/Swinject-iOS.xcscheme +++ b/Swinject.xcodeproj/xcshareddata/xcschemes/Swinject-iOS.xcscheme @@ -26,7 +26,6 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - codeCoverageEnabled = "YES" shouldUseLaunchSchemeArgsEnv = "YES"> {% if method.isInitializer %}Void{% else %}{% call closureReturnTypeName method %}{% endif %})? -{% endmacro %} - -{% macro methodClosureCallParameters method %}{% for param in method.parameters %}{% if param.inout %}&{% endif %}{{ param.name }}{% if not forloop.last %}, {% endif %}{% endfor %}{% endmacro %} - -{% macro mockMethod method %} - //MARK: - {{ method.shortName }} - - {% if method.throws %} - {% call methodThrowableErrorDeclaration method %} - {% endif %} - {% if not method.isInitializer %} - var {% call swiftifyMethodName method.selectorName %}CallsCount = 0 - var {% call swiftifyMethodName method.selectorName %}Called: Bool { - return {% call swiftifyMethodName method.selectorName %}CallsCount > 0 - } - {% endif %} - {% if method.parameters.count == 1 %} - var {% call swiftifyMethodName method.selectorName %}Received{% for param in method.parameters %}{{ param.name|upperFirstLetter }}: {{ '(' if param.isClosure }}{{ param.typeName.unwrappedTypeName }}{{ ')' if param.isClosure }}?{% endfor %} - var {% call swiftifyMethodName method.selectorName %}ReceivedInvocations{% for param in method.parameters %}: [{{ '(' if param.isClosure }}{{ param.typeName.unwrappedTypeName }}{{ ')' if param.isClosure }}{%if param.typeName.isOptional%}?{%endif%}]{% endfor %} = [] - {% elif not method.parameters.count == 0 %} - var {% call swiftifyMethodName method.selectorName %}ReceivedArguments: ({% for param in method.parameters %}{{ param.name }}: {{ param.unwrappedTypeName if param.typeAttributes.escaping else param.typeName }}{{ ', ' if not forloop.last }}{% endfor %})? - var {% call swiftifyMethodName method.selectorName %}ReceivedInvocations: [({% for param in method.parameters %}{{ param.name }}: {{ param.unwrappedTypeName if param.typeAttributes.escaping else param.typeName }}{{ ', ' if not forloop.last }}{% endfor %})] = [] - {% endif %} - {% if not method.returnTypeName.isVoid and not method.isInitializer %} - var {% call swiftifyMethodName method.selectorName %}ReturnValue: {{ method.returnTypeName }}{{ '!' if not method.isOptionalReturnType }} - {% endif %} - {% call methodClosureDeclaration method %} - -{% if method.isInitializer %} - required {{ method.name }} { - {% call methodReceivedParameters method %} - {% call methodClosureName method %}?({% call methodClosureCallParameters method %}) - } -{% else %} - func {{ method.name }}{{ ' throws' if method.throws }}{% if not method.returnTypeName.isVoid %} -> {{ method.returnTypeName }}{% endif %} { - {% if method.throws %} - {% call methodThrowableErrorUsage method %} - {% endif %} - {% call swiftifyMethodName method.selectorName %}CallsCount += 1 - {% call methodReceivedParameters method %} - {% if method.returnTypeName.isVoid %} - {% if method.throws %}try {% endif %}{% call methodClosureName method %}?({% call methodClosureCallParameters method %}) - {% else %} - return {{ 'try ' if method.throws }}{% call methodClosureName method %}.map({ {{ 'try ' if method.throws }}$0({% call methodClosureCallParameters method %}) }) ?? {% call swiftifyMethodName method.selectorName %}ReturnValue! - {% endif %} - } - -{% endif %} -{% endmacro %} - -{% macro mockOptionalVariable variable %} - var {% call mockedVariableName variable %}: {{ variable.typeName }} -{% endmacro %} - -{% macro mockNonOptionalArrayOrDictionaryVariable variable %} - var {% call mockedVariableName variable %}: {{ variable.typeName }} = {% if variable.isArray %}[]{% elif variable.isDictionary %}[:]{% endif %} -{% endmacro %} - -{% macro mockNonOptionalVariable variable %} - var {% call mockedVariableName variable %}: {{ variable.typeName }} { - get { return {% call underlyingMockedVariableName variable %} } - set(value) { {% call underlyingMockedVariableName variable %} = value } - } - var {% call underlyingMockedVariableName variable %}: {{ variable.typeName }}! -{% endmacro %} - -{% macro underlyingMockedVariableName variable %}underlying{{ variable.name|upperFirstLetter }}{% endmacro %} -{% macro mockedVariableName variable %}{{ variable.name }}{% endmacro %} - -{% for type in types.protocols where type.based.AutoMockable or type|annotated:"AutoMockable" %}{% if type.name != "AutoMockable" %} -class {{ type.name }}Mock: {{ type.name }} { -{% for variable in type.allVariables|!definedInExtension %} - {% if variable.isOptional %}{% call mockOptionalVariable variable %}{% elif variable.isArray or variable.isDictionary %}{% call mockNonOptionalArrayOrDictionaryVariable variable %}{% else %}{% call mockNonOptionalVariable variable %}{% endif %} -{% endfor %} - -{% for method in type.allMethods|!definedInExtension %} - {% call mockMethod method %} -{% endfor %} -} -{% endif %}{% endfor %} diff --git a/Tests/3.0 API/ScopesSpec.swift b/Tests/3.0 API/ScopesSpec.swift index 921dbc9f..7f4d687d 100644 --- a/Tests/3.0 API/ScopesSpec.swift +++ b/Tests/3.0 API/ScopesSpec.swift @@ -58,25 +58,25 @@ class ScopesSpec: QuickSpec { override func spec() { #if swift(>=5.1) it("notifies instances when scope is closed") { let scope = UnboundScope() let swinject = Swinject { - bbind(ClosableMock.self) & scoped(scope).singleton { ClosableMock() } + bbind(Door.self) & scoped(scope).singleton { Door() } } - let closable = try? swinject.instance() as ClosableMock + let door = try? swinject.instance() as Door scope.close() - expect(closable?.closeCalled) == true + expect(door?.isClosed) == true } it("closes scoped instances when context expires") { let scope = SessionScope() var session = Session() as Session? let swinject = Swinject { - bbind(ClosableMock.self) & scoped(scope).singleton { ClosableMock() } + bbind(Door.self) & scoped(scope).singleton { Door() } } - let closable = try? swinject.on(session!).instance(of: ClosableMock.self) + let door = try? swinject.on(session!).instance(of: Door.self) session = nil - expect(closable?.closeCalled) == true + expect(door?.isClosed) == true } it("releases scoped instances when context expires") { let scope = SessionScope() diff --git a/Tests/LinuxConfig.swift b/Tests/LinuxConfig.swift index db28b5e9..80e50d2d 100644 --- a/Tests/LinuxConfig.swift +++ b/Tests/LinuxConfig.swift @@ -25,7 +25,6 @@ let allSpecs: [QuickSpec.Type] = [ ScopesSpec.self, OptionalsSpec.self, // Unit Specs - BinderEnvironmentSpec.self, StandardScopeRegistrySpec.self, SwinjectTreeBuilderSpec.self, TaggedTypeSpec.self, diff --git a/Tests/Support/GeneratedMocks.swift b/Tests/Support/GeneratedMocks.swift deleted file mode 100644 index 95e5dc0f..00000000 --- a/Tests/Support/GeneratedMocks.swift +++ /dev/null @@ -1,373 +0,0 @@ -// Generated using Sourcery 0.16.1 — https://github.com/krzysztofzablocki/Sourcery -// DO NOT EDIT - - -// swiftlint:disable line_length -// swiftlint:disable variable_name - -@testable import Swinject - - - - - - - - - - - - - - -class AnyBindingKeyMock: AnyBindingKey { - var contextType: Any.Type { - get { return underlyingContextType } - set(value) { underlyingContextType = value } - } - var underlyingContextType: Any.Type! - var argumentType: Any.Type { - get { return underlyingArgumentType } - set(value) { underlyingArgumentType = value } - } - var underlyingArgumentType: Any.Type! - var descriptor: AnyTypeDescriptor { - get { return underlyingDescriptor } - set(value) { underlyingDescriptor = value } - } - var underlyingDescriptor: AnyTypeDescriptor! - - //MARK: - matches - - var matchesCallsCount = 0 - var matchesCalled: Bool { - return matchesCallsCount > 0 - } - var matchesReceivedOther: AnyBindingKey? - var matchesReceivedInvocations: [AnyBindingKey] = [] - var matchesReturnValue: Bool! - var matchesClosure: ((AnyBindingKey) -> Bool)? - - func matches(_ other: AnyBindingKey) -> Bool { - matchesCallsCount += 1 - matchesReceivedOther = other - matchesReceivedInvocations.append(other) - return matchesClosure.map({ $0(other) }) ?? matchesReturnValue! - } - -} -class AnyContextTranslatorMock: AnyContextTranslator { - var sourceType: Any.Type { - get { return underlyingSourceType } - set(value) { underlyingSourceType = value } - } - var underlyingSourceType: Any.Type! - var targetType: Any.Type { - get { return underlyingTargetType } - set(value) { underlyingTargetType = value } - } - var underlyingTargetType: Any.Type! - - //MARK: - translate - - var translateThrowableError: Error? - var translateCallsCount = 0 - var translateCalled: Bool { - return translateCallsCount > 0 - } - var translateReceivedContext: Any? - var translateReceivedInvocations: [Any] = [] - var translateReturnValue: Any! - var translateClosure: ((Any) throws -> Any)? - - func translate(_ context: Any) throws -> Any { - if let error = translateThrowableError { - throw error - } - translateCallsCount += 1 - translateReceivedContext = context - translateReceivedInvocations.append(context) - return try translateClosure.map({ try $0(context) }) ?? translateReturnValue! - } - -} -class AnyInstanceMakerMock: AnyInstanceMaker { - - //MARK: - makeInstance - - var makeInstanceArgContextResolverThrowableError: Error? - var makeInstanceArgContextResolverCallsCount = 0 - var makeInstanceArgContextResolverCalled: Bool { - return makeInstanceArgContextResolverCallsCount > 0 - } - var makeInstanceArgContextResolverReceivedArguments: (arg: Any, context: Any, resolver: Resolver)? - var makeInstanceArgContextResolverReceivedInvocations: [(arg: Any, context: Any, resolver: Resolver)] = [] - var makeInstanceArgContextResolverReturnValue: Any! - var makeInstanceArgContextResolverClosure: ((Any, Any, Resolver) throws -> Any)? - - func makeInstance(arg: Any, context: Any, resolver: Resolver) throws -> Any { - if let error = makeInstanceArgContextResolverThrowableError { - throw error - } - makeInstanceArgContextResolverCallsCount += 1 - makeInstanceArgContextResolverReceivedArguments = (arg: arg, context: context, resolver: resolver) - makeInstanceArgContextResolverReceivedInvocations.append((arg: arg, context: context, resolver: resolver)) - return try makeInstanceArgContextResolverClosure.map({ try $0(arg, context, resolver) }) ?? makeInstanceArgContextResolverReturnValue! - } - -} -class AnyResolverMock: AnyResolver { - - //MARK: - resolve - - var resolveThrowableError: Error? - var resolveCallsCount = 0 - var resolveCalled: Bool { - return resolveCallsCount > 0 - } - var resolveReceivedRequest: Any? - var resolveReceivedInvocations: [Any] = [] - var resolveReturnValue: Any! - var resolveClosure: ((Any) throws -> Any)? - - func resolve(_ request: Any) throws -> Any { - if let error = resolveThrowableError { - throw error - } - resolveCallsCount += 1 - resolveReceivedRequest = request - resolveReceivedInvocations.append(request) - return try resolveClosure.map({ try $0(request) }) ?? resolveReturnValue! - } - -} -class AnyScopeMock: AnyScope { - var contextType: Any.Type { - get { return underlyingContextType } - set(value) { underlyingContextType = value } - } - var underlyingContextType: Any.Type! - - //MARK: - registry - - var registryForCallsCount = 0 - var registryForCalled: Bool { - return registryForCallsCount > 0 - } - var registryForReceivedContext: Any? - var registryForReceivedInvocations: [Any] = [] - var registryForReturnValue: ScopeRegistry! - var registryForClosure: ((Any) -> ScopeRegistry)? - - func registry(for context: Any) -> ScopeRegistry { - registryForCallsCount += 1 - registryForReceivedContext = context - registryForReceivedInvocations.append(context) - return registryForClosure.map({ $0(context) }) ?? registryForReturnValue! - } - -} -class AnyTypeDescriptorMock: AnyTypeDescriptor { - - //MARK: - matches - - var matchesCallsCount = 0 - var matchesCalled: Bool { - return matchesCallsCount > 0 - } - var matchesReceivedOther: Any? - var matchesReceivedInvocations: [Any] = [] - var matchesReturnValue: Bool! - var matchesClosure: ((Any) -> Bool)? - - func matches(_ other: Any) -> Bool { - matchesCallsCount += 1 - matchesReceivedOther = other - matchesReceivedInvocations.append(other) - return matchesClosure.map({ $0(other) }) ?? matchesReturnValue! - } - - //MARK: - hash - - var hashIntoCallsCount = 0 - var hashIntoCalled: Bool { - return hashIntoCallsCount > 0 - } - var hashIntoReceivedHasher: Hasher? - var hashIntoReceivedInvocations: [Hasher] = [] - var hashIntoClosure: ((inout Hasher) -> Void)? - - func hash(into hasher: inout Hasher) { - hashIntoCallsCount += 1 - hashIntoReceivedHasher = hasher - hashIntoReceivedInvocations.append(hasher) - hashIntoClosure?(&hasher) - } - -} -class BindingMock: Binding { - - //MARK: - matches - - var matchesCallsCount = 0 - var matchesCalled: Bool { - return matchesCallsCount > 0 - } - var matchesReceivedKey: AnyBindingKey? - var matchesReceivedInvocations: [AnyBindingKey] = [] - var matchesReturnValue: Bool! - var matchesClosure: ((AnyBindingKey) -> Bool)? - - func matches(_ key: AnyBindingKey) -> Bool { - matchesCallsCount += 1 - matchesReceivedKey = key - matchesReceivedInvocations.append(key) - return matchesClosure.map({ $0(key) }) ?? matchesReturnValue! - } - - //MARK: - instance - - var instanceArgContextResolverThrowableError: Error? - var instanceArgContextResolverCallsCount = 0 - var instanceArgContextResolverCalled: Bool { - return instanceArgContextResolverCallsCount > 0 - } - var instanceArgContextResolverReceivedArguments: (arg: Any, context: Any, resolver: Resolver)? - var instanceArgContextResolverReceivedInvocations: [(arg: Any, context: Any, resolver: Resolver)] = [] - var instanceArgContextResolverReturnValue: Any! - var instanceArgContextResolverClosure: ((Any, Any, Resolver) throws -> Any)? - - func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any { - if let error = instanceArgContextResolverThrowableError { - throw error - } - instanceArgContextResolverCallsCount += 1 - instanceArgContextResolverReceivedArguments = (arg: arg, context: context, resolver: resolver) - instanceArgContextResolverReceivedInvocations.append((arg: arg, context: context, resolver: resolver)) - return try instanceArgContextResolverClosure.map({ try $0(arg, context, resolver) }) ?? instanceArgContextResolverReturnValue! - } - -} -class BindingMakerMock: BindingMaker { - - //MARK: - makeBinding - - var makeBindingForCallsCount = 0 - var makeBindingForCalled: Bool { - return makeBindingForCallsCount > 0 - } - var makeBindingForReceivedDescriptor: AnyTypeDescriptor? - var makeBindingForReceivedInvocations: [AnyTypeDescriptor] = [] - var makeBindingForReturnValue: Binding! - var makeBindingForClosure: ((AnyTypeDescriptor) -> Binding)? - - func makeBinding(for descriptor: AnyTypeDescriptor) -> Binding { - makeBindingForCallsCount += 1 - makeBindingForReceivedDescriptor = descriptor - makeBindingForReceivedInvocations.append(descriptor) - return makeBindingForClosure.map({ $0(descriptor) }) ?? makeBindingForReturnValue! - } - -} -class ClosableMock: Closable { - - //MARK: - close - - var closeCallsCount = 0 - var closeCalled: Bool { - return closeCallsCount > 0 - } - var closeClosure: (() -> Void)? - - func close() { - closeCallsCount += 1 - closeClosure?() - } - -} -class MatchableMock: Matchable { - - //MARK: - matches - - var matchesCallsCount = 0 - var matchesCalled: Bool { - return matchesCallsCount > 0 - } - var matchesReceivedOther: Any? - var matchesReceivedInvocations: [Any] = [] - var matchesReturnValue: Bool! - var matchesClosure: ((Any) -> Bool)? - - func matches(_ other: Any) -> Bool { - matchesCallsCount += 1 - matchesReceivedOther = other - matchesReceivedInvocations.append(other) - return matchesClosure.map({ $0(other) }) ?? matchesReturnValue! - } - - //MARK: - hash - - var hashIntoCallsCount = 0 - var hashIntoCalled: Bool { - return hashIntoCallsCount > 0 - } - var hashIntoReceivedHasher: Hasher? - var hashIntoReceivedInvocations: [Hasher] = [] - var hashIntoClosure: ((inout Hasher) -> Void)? - - func hash(into hasher: inout Hasher) { - hashIntoCallsCount += 1 - hashIntoReceivedHasher = hasher - hashIntoReceivedInvocations.append(hasher) - hashIntoClosure?(&hasher) - } - -} -class StaticScopeRegistryMock: StaticScopeRegistry { - - //MARK: - instance - - var instanceKeyCallsCount = 0 - var instanceKeyCalled: Bool { - return instanceKeyCallsCount > 0 - } - var instanceKeyReceivedKey: ScopeRegistryKey? - var instanceKeyReceivedInvocations: [ScopeRegistryKey] = [] - var instanceKeyReturnValue: Any! - var instanceKeyClosure: ((ScopeRegistryKey) -> Any)? - - func instance(key: ScopeRegistryKey) -> Any { - instanceKeyCallsCount += 1 - instanceKeyReceivedKey = key - instanceKeyReceivedInvocations.append(key) - return instanceKeyClosure.map({ $0(key) }) ?? instanceKeyReturnValue! - } - - //MARK: - clear - - var clearCallsCount = 0 - var clearCalled: Bool { - return clearCallsCount > 0 - } - var clearClosure: (() -> Void)? - - func clear() { - clearCallsCount += 1 - clearClosure?() - } - -} - - - - - - - - - - - - - - diff --git a/Tests/Support/NonGeneratedMocks.swift b/Tests/Support/NonGeneratedMocks.swift deleted file mode 100644 index 0451fce3..00000000 --- a/Tests/Support/NonGeneratedMocks.swift +++ /dev/null @@ -1,87 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -@testable import Swinject - -class DummyResolver: Resolver { - func resolve( - _: InstanceRequest - ) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { - fatalError() - } -} - -extension AnyTypeDescriptorMock: TypeDescriptor { - typealias BaseType = Any -} - -extension AnyInstanceMakerMock: InstanceMaker { - typealias Argument = Any -} - -class DummyMaker: InstanceMaker { - func makeInstance(arg _: Argument, context: Context, resolver _: Resolver) throws -> Any { - fatalError() - } -} - -// sourcery: AutoMockable -protocol AnyResolver { - func resolve(_ request: Any) throws -> Any -} - -extension AnyResolverMock: Resolver { - func resolve( - _ request: InstanceRequest - ) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { - return try resolve(request as Any) as! Descriptor.BaseType - } -} - -extension AnyScopeMock: Scope { - typealias Context = Any -} - -class DummyScope: Scope { - func registry(for _: Context) -> ScopeRegistry { fatalError() } -} - -extension BindingMakerMock { - typealias BoundType = Any -} - -// sourcery: AutoMockable -protocol StaticScopeRegistry { - func instance(key: ScopeRegistryKey) -> Any - func clear() -} - -extension StaticScopeRegistryMock: ScopeRegistry { - func instance( - for key: ScopeRegistryKey, - builder _: () throws -> Reference, - finalizer: (Any) throws -> Void - ) rethrows -> Any { - return instance(key: key) - } -} - -struct BuilderScopeRegistry: ScopeRegistry { - func instance( - for _: ScopeRegistryKey, - builder: () throws -> Reference, - finalizer: (Any) throws -> Void - ) rethrows -> Any { - return try builder().currentValue - } - - func clear() {} -} - -extension BindingMock { - // swiftlint:disable large_tuple - var instanceReceivedArguments: (arg: Any, context: Any, resolver: Resolver)? { - return instanceArgContextResolverReceivedArguments - } -} diff --git a/Tests/Support/TestModels.swift b/Tests/Support/TestModels.swift index dcaadd6c..6c1ffbf0 100644 --- a/Tests/Support/TestModels.swift +++ b/Tests/Support/TestModels.swift @@ -2,6 +2,8 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // +import Swinject + protocol Mammal {} class Human: Mammal { @@ -21,3 +23,14 @@ class Pet { } struct TestError: Error, Equatable {} + +class Door: Closable { + var closeCount = 0 + var isClosed: Bool { return closeCount > 0 } + var whenClosed: () -> Void = {} + + func close() { + closeCount += 1 + whenClosed() + } +} diff --git a/Tests/Unit Specs/StandardScopeRegistrySpec.swift b/Tests/Unit Specs/StandardScopeRegistrySpec.swift index 4e989c23..57ad63f9 100644 --- a/Tests/Unit Specs/StandardScopeRegistrySpec.swift +++ b/Tests/Unit Specs/StandardScopeRegistrySpec.swift @@ -10,9 +10,9 @@ import Quick class StandardScopeRegistrySpec: QuickSpec { override func spec() { var registry: StandardScopeRegistry! let key = (1 ... 5).map { ScopeRegistryKey(descriptor: tagged(Int.self, with: $0), argument: ()) } - var closable = [ClosableMock]() + var doors = [Door]() beforeEach { - closable = (1 ... 3).map { _ in ClosableMock() } + doors = (1 ... 3).map { _ in Door() } registry = StandardScopeRegistry() } describe("instance") { @@ -113,11 +113,11 @@ class StandardScopeRegistrySpec: QuickSpec { override func spec() { } describe("clear") { it("closes instances when cleared") { - _ = registry.instance(for: key[0]) { strongRef(closable[0]) } - _ = registry.instance(for: key[1]) { strongRef(closable[1]) } + _ = registry.instance(for: key[0]) { strongRef(doors[0]) } + _ = registry.instance(for: key[1]) { strongRef(doors[1]) } registry.clear() - expect(closable[0].closeCallsCount) == 1 - expect(closable[1].closeCallsCount) == 1 + expect(doors[0].closeCount) == 1 + expect(doors[1].closeCount) == 1 } it("releases instance references when cleared") { var human: Human? = Human() @@ -130,15 +130,15 @@ class StandardScopeRegistrySpec: QuickSpec { override func spec() { } describe("closable") { it("does not close instance by default") { - _ = registry.instance(for: key[0]) { strongRef(closable[0]) } - expect(closable[0].closeCallsCount) == 0 + _ = registry.instance(for: key[0]) { strongRef(doors[0]) } + expect(doors[0].isClosed) == false } it("closes instances when closed") { - _ = registry.instance(for: key[0]) { strongRef(closable[0]) } - _ = registry.instance(for: key[1]) { strongRef(closable[1]) } + _ = registry.instance(for: key[0]) { strongRef(doors[0]) } + _ = registry.instance(for: key[1]) { strongRef(doors[1]) } registry.close() - expect(closable[0].closeCallsCount) == 1 - expect(closable[1].closeCallsCount) == 1 + expect(doors[0].closeCount) == 1 + expect(doors[1].closeCount) == 1 } it("releases instance references when closed") { var human: Human? = Human() @@ -151,11 +151,11 @@ class StandardScopeRegistrySpec: QuickSpec { override func spec() { } describe("deinit") { it("closes instances on deinit") { - _ = registry.instance(for: key[0]) { strongRef(closable[0]) } - _ = registry.instance(for: key[1]) { strongRef(closable[1]) } + _ = registry.instance(for: key[0]) { strongRef(doors[0]) } + _ = registry.instance(for: key[1]) { strongRef(doors[1]) } registry = nil - expect(closable[0].closeCallsCount) == 1 - expect(closable[1].closeCallsCount) == 1 + expect(doors[0].closeCount) == 1 + expect(doors[1].closeCount) == 1 } } describe("concurrency") { @@ -171,11 +171,11 @@ class StandardScopeRegistrySpec: QuickSpec { override func spec() { expect(builderCallCount) == 1 } it("closes instance only once when closed concurrently multiple times") { - let closable = ClosableMock() - closable.closeClosure = { Thread.sleep(forTimeInterval: 0.1) } - _ = registry.instance(for: key[0]) { strongRef(closable) } + let door = Door() + door.whenClosed = { Thread.sleep(forTimeInterval: 0.1) } + _ = registry.instance(for: key[0]) { strongRef(door) } concurrentPerform(iterations: 5, action: registry.close) - expect(closable.closeCallsCount) == 1 + expect(door.closeCount) == 1 } it("does not deadlock if invoked inside builder") { waitUntil { done in diff --git a/Tests/Unit Specs/SwinjectTreeBuilderSpec.swift b/Tests/Unit Specs/SwinjectTreeBuilderSpec.swift index 6f262b31..bc858d69 100644 --- a/Tests/Unit Specs/SwinjectTreeBuilderSpec.swift +++ b/Tests/Unit Specs/SwinjectTreeBuilderSpec.swift @@ -13,50 +13,59 @@ class SwinjectTreeBuilderSpec: QuickSpec { override func spec() { #if swift(>=5. expect(tree.bindings).to(beEmpty()) } it("builds closure with single entry") { - let tree = makeTree { BindingMock() } + let tree = makeTree { bbind(Int.self).with(42) } expect(tree.bindings.count) == 1 } it("builds closure with multiple entries") { let tree = makeTree { - BindingMock(); BindingMock(); BindingMock(); BindingMock(); BindingMock() + bbind(Int.self).with(42) + bbind(UInt.self).with(42) + bbind(Float.self).with(42) + bbind(Double.self).with(42) + bbind(Int32.self).with(42) } expect(tree.bindings.count) == 5 } - // FIXME: Test coverage enabled build segfaults on this -// it("builds closure with if statement") { -// let tree = makeTree { -// if true { BindingMock() } -// } -// expect(tree.bindings.count) == 1 -// } -// it("builds closure with nested if statement") { -// let tree = makeTree { -// if true { BindingMock(); if true { BindingMock() } } -// } -// expect(tree.bindings.count) == 2 -// } -// it("builds closure with if else statement") { -// let tree = makeTree { -// if false {} else { BindingMock(); BindingMock() } -// } -// expect(tree.bindings.count) == 2 -// } + it("builds closure with if statement") { + let tree = makeTree { + if true { bbind(Int.self).with(42) } + } + expect(tree.bindings.count) == 1 + } + it("builds closure with nested if statement") { + let tree = makeTree { + if true { + bbind(Int.self).with(42) + if true { bbind(UInt.self).with(42) } + } + } + expect(tree.bindings.count) == 2 + } + it("builds closure with if else statement") { + let tree = makeTree { + if false {} else { + bbind(Int.self).with(42) + bbind(UInt.self).with(42) + } + } + expect(tree.bindings.count) == 2 + } it("builds closure with maker & include entries") { let tree = makeTree { Swinject.Module("1") Swinject.Module("2") - BindingMock() - BindingMock() - BindingMock() + bbind(Int.self).with(42) + bbind(UInt.self).with(42) + bbind(Float.self).with(42) } expect(tree.modules.count) == 2 expect(tree.bindings.count) == 3 } it("builds closure with translator entries") { let tree = makeTree { - AnyContextTranslatorMock() - AnyContextTranslatorMock() - AnyContextTranslatorMock() + registerContextTranslator(from: Int.self) { Double($0) } + registerContextTranslator(from: Float.self) { Double($0) } + registerContextTranslator(from: UInt.self) { Double($0) } } expect(tree.translators.count) == 3 } diff --git a/project.yml b/project.yml index 82d95f8c..24024778 100644 --- a/project.yml +++ b/project.yml @@ -14,7 +14,6 @@ targets: platform: [macOS, iOS, tvOS, watchOS] platformSuffix: -${platform} scheme: - gatherCoverageData: true testTargets: - SwinjectTests-${platform} sources: From 4427580e9f92aadf59bd33210edaa5370e576712 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 28 Jul 2019 14:12:34 +0200 Subject: [PATCH 165/239] Rename Maker to Builder --- Sources/3.0 API/BinderEnvironment.swift | 82 ++++++------ Sources/3.0 API/TypeBinder.swift | 10 +- Sources/Core/Binding.swift | 10 +- ...tanceMaker.swift => InstanceBuilder.swift} | 8 +- Sources/Core/ScopedBinding.swift | 10 +- Sources/Core/SimpleBinding.swift | 10 +- Swinject.xcodeproj/project.pbxproj | 124 +++++++++++++----- Templates/BinderVariation.swift | 2 +- Templates/SwiftCode.swifttemplate | 2 +- 9 files changed, 156 insertions(+), 102 deletions(-) rename Sources/Core/{InstanceMaker.swift => InstanceBuilder.swift} (72%) diff --git a/Sources/3.0 API/BinderEnvironment.swift b/Sources/3.0 API/BinderEnvironment.swift index 29d8d1c2..340c4873 100644 --- a/Sources/3.0 API/BinderEnvironment.swift +++ b/Sources/3.0 API/BinderEnvironment.swift @@ -20,172 +20,172 @@ public func scoped(_ scope: AScope) -> ScopedEnvironment where A // swiftlint:disable line_length // swiftlint:disable identifier_name -public func instance(_ instance: Type) -> SomeBindingMaker { +public func instance(_ instance: Type) -> SomeBindingBuilder { return SimpleBinding.Builder { _, _, _ in instance }.opaque } // sourcery:inline:BindingBuilders extension ContextedEnvironment { - public func provider(_ builder: @escaping () throws -> Type) -> SomeBindingMaker { + public func provider(_ builder: @escaping () throws -> Type) -> SomeBindingBuilder { return SimpleBinding.Builder { _, _, _ in try builder() }.opaque } - public func provider(_ builder: @escaping (Resolver) throws -> Type) -> SomeBindingMaker { + public func provider(_ builder: @escaping (Resolver) throws -> Type) -> SomeBindingBuilder { return SimpleBinding.Builder { r, _, _ in try builder(r) }.opaque } - public func provider(_ builder: @escaping (Resolver, Context) throws -> Type) -> SomeBindingMaker { + public func provider(_ builder: @escaping (Resolver, Context) throws -> Type) -> SomeBindingBuilder { return SimpleBinding.Builder { r, c, _ in try builder(r, c) }.opaque } - public func factory(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SomeBindingMaker { + public func factory(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SomeBindingBuilder { return SimpleBinding.Builder { r, c, a in try builder(r, c, a) }.opaque } - public func factory(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SomeBindingMaker where Arg1: Hashable { + public func factory(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable { return SimpleBinding.Builder> { r, c, a in try builder(r, c, a.arg1) }.opaque } - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SomeBindingMaker { + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SomeBindingBuilder { return SimpleBinding.Builder { r, c, a in try builder(r, c, a.0, a.1) }.opaque } - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable { + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable { return SimpleBinding.Builder> { r, c, a in try builder(r, c, a.arg1, a.arg2) }.opaque } - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingMaker { + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingBuilder { return SimpleBinding.Builder { r, c, a in try builder(r, c, a.0, a.1, a.2) }.opaque } - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { return SimpleBinding.Builder> { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3) }.opaque } - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingMaker { + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingBuilder { return SimpleBinding.Builder { r, c, a in try builder(r, c, a.0, a.1, a.2, a.3) }.opaque } - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { return SimpleBinding.Builder> { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3, a.arg4) }.opaque } - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingMaker { + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingBuilder { return SimpleBinding.Builder { r, c, a in try builder(r, c, a.0, a.1, a.2, a.3, a.4) }.opaque } - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { return SimpleBinding.Builder> { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) }.opaque } } extension ScopedEnvironment { - public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping () throws -> Type) -> SomeBindingMaker { + public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping () throws -> Type) -> SomeBindingBuilder { return ScopedBinding.Builder(scope, ref) { _, _, _ in try builder() }.opaque } - public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver) throws -> Type) -> SomeBindingMaker { + public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver) throws -> Type) -> SomeBindingBuilder { return ScopedBinding.Builder(scope, ref) { r, _, _ in try builder(r) }.opaque } - public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context) throws -> Type) -> SomeBindingMaker { + public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context) throws -> Type) -> SomeBindingBuilder { return ScopedBinding.Builder(scope, ref) { r, c, _ in try builder(r, c) }.opaque } - public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SomeBindingMaker where Arg1: Hashable { + public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable { return ScopedBinding.Builder>(scope, ref) { r, c, a in try builder(r, c, a.arg1) }.opaque } - public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable { + public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable { return ScopedBinding.Builder>(scope, ref) { r, c, a in try builder(r, c, a.arg1, a.arg2) }.opaque } - public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { return ScopedBinding.Builder>(scope, ref) { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3) }.opaque } - public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { return ScopedBinding.Builder>(scope, ref) { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3, a.arg4) }.opaque } - public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { return ScopedBinding.Builder>(scope, ref) { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) }.opaque } } -public func provider(_ builder: @escaping () throws -> Type) -> SomeBindingMaker { +public func provider(_ builder: @escaping () throws -> Type) -> SomeBindingBuilder { return SimpleBinding.Builder { _, _, _ in try builder() }.opaque } -public func provider(_ builder: @escaping (Resolver) throws -> Type) -> SomeBindingMaker { +public func provider(_ builder: @escaping (Resolver) throws -> Type) -> SomeBindingBuilder { return SimpleBinding.Builder { r, _, _ in try builder(r) }.opaque } -public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> SomeBindingMaker { +public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> SomeBindingBuilder { return SimpleBinding.Builder { r, _, a in try builder(r, a) }.opaque } -public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> SomeBindingMaker where Arg1: Hashable { +public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable { return SimpleBinding.Builder> { r, _, a in try builder(r, a.arg1) }.opaque } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SomeBindingMaker { +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SomeBindingBuilder { return SimpleBinding.Builder { r, _, a in try builder(r, a.0, a.1) }.opaque } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable { +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable { return SimpleBinding.Builder> { r, _, a in try builder(r, a.arg1, a.arg2) }.opaque } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingMaker { +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingBuilder { return SimpleBinding.Builder { r, _, a in try builder(r, a.0, a.1, a.2) }.opaque } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { return SimpleBinding.Builder> { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3) }.opaque } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingMaker { +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingBuilder { return SimpleBinding.Builder { r, _, a in try builder(r, a.0, a.1, a.2, a.3) }.opaque } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { return SimpleBinding.Builder> { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3, a.arg4) }.opaque } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingMaker { +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingBuilder { return SimpleBinding.Builder { r, _, a in try builder(r, a.0, a.1, a.2, a.3, a.4) }.opaque } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { return SimpleBinding.Builder> { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) }.opaque } -public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping () throws -> Type) -> SomeBindingMaker { +public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping () throws -> Type) -> SomeBindingBuilder { return ScopedBinding.Builder(.root, ref) { _, _, _ in try builder() }.opaque } -public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver) throws -> Type) -> SomeBindingMaker { +public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver) throws -> Type) -> SomeBindingBuilder { return ScopedBinding.Builder(.root, ref) { r, _, _ in try builder(r) }.opaque } -public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1) throws -> Type) -> SomeBindingMaker where Arg1: Hashable { +public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable { return ScopedBinding.Builder>(.root, ref) { r, _, a in try builder(r, a.arg1) }.opaque } -public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable { +public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable { return ScopedBinding.Builder>(.root, ref) { r, _, a in try builder(r, a.arg1, a.arg2) }.opaque } -public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { +public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { return ScopedBinding.Builder>(.root, ref) { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3) }.opaque } -public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { +public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { return ScopedBinding.Builder>(.root, ref) { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3, a.arg4) }.opaque } -public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingMaker where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { +public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { return ScopedBinding.Builder>(.root, ref) { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) }.opaque } diff --git a/Sources/3.0 API/TypeBinder.swift b/Sources/3.0 API/TypeBinder.swift index d177f6a1..1d0af77d 100644 --- a/Sources/3.0 API/TypeBinder.swift +++ b/Sources/3.0 API/TypeBinder.swift @@ -15,8 +15,8 @@ public func bind(_: Type.Type, tagged tag: Tag) -> TypeBinder(_ maker: Maker) -> Binding where Maker: BindingMaker, Maker.BoundType == Descriptor.BaseType { - return maker.makeBinding(for: descriptor) + func with(_ builder: Builder) -> Binding where Builder: BindingBuilder, Builder.BoundType == Descriptor.BaseType { + return builder.makeBinding(for: descriptor) } func with(_ value: Descriptor.BaseType) -> Binding { @@ -24,9 +24,9 @@ public extension TypeBinder { } } -public func & ( - lhs: TypeBinder, rhs: Maker -) -> Binding where Maker: BindingMaker, Maker.BoundType == Descriptor.BaseType { +public func & ( + lhs: TypeBinder, rhs: Builder +) -> Binding where Builder: BindingBuilder, Builder.BoundType == Descriptor.BaseType { return lhs.with(rhs) } diff --git a/Sources/Core/Binding.swift b/Sources/Core/Binding.swift index e0da60b7..eae05574 100644 --- a/Sources/Core/Binding.swift +++ b/Sources/Core/Binding.swift @@ -7,12 +7,12 @@ public protocol Binding: SwinjectEntry { func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any } -public protocol BindingMaker { +public protocol BindingBuilder { associatedtype BoundType func makeBinding(for descriptor: AnyTypeDescriptor) -> Binding } -public struct SomeBindingMaker: BindingMaker, AnyOpaque { +public struct SomeBindingBuilder: BindingBuilder, AnyOpaque { let anyActual: Any fileprivate let _makeBinding: (AnyTypeDescriptor) -> Binding @@ -21,8 +21,8 @@ public struct SomeBindingMaker: BindingMaker, AnyOpaque { } } -public extension BindingMaker { - var opaque: SomeBindingMaker { - return SomeBindingMaker(anyActual: self) { self.makeBinding(for: $0) } +public extension BindingBuilder { + var opaque: SomeBindingBuilder { + return SomeBindingBuilder(anyActual: self) { self.makeBinding(for: $0) } } } diff --git a/Sources/Core/InstanceMaker.swift b/Sources/Core/InstanceBuilder.swift similarity index 72% rename from Sources/Core/InstanceMaker.swift rename to Sources/Core/InstanceBuilder.swift index df25ecff..45d45dce 100644 --- a/Sources/Core/InstanceMaker.swift +++ b/Sources/Core/InstanceBuilder.swift @@ -2,20 +2,18 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -protocol AnyInstanceMaker { +protocol AnyInstanceBuilder { func makeInstance(arg: Any, context: Any, resolver: Resolver) throws -> Any } -// FIXME: "Maker" is not a typical concept -// Could we use `InstanceFactory` / `InstanceBuilder` instead, or would it be too overloaded? -protocol InstanceMaker: AnyInstanceMaker { +protocol InstanceBuilder: AnyInstanceBuilder { associatedtype MadeType associatedtype Argument associatedtype Context func makeInstance(arg: Argument, context: Context, resolver: Resolver) throws -> MadeType } -extension InstanceMaker { +extension InstanceBuilder { func makeInstance(arg: Any, context: Any, resolver: Resolver) throws -> Any { guard let arg = arg as? Argument, let context = context as? Context else { throw SwinjectError() } return try makeInstance(arg: arg, context: context, resolver: resolver) as MadeType diff --git a/Sources/Core/ScopedBinding.swift b/Sources/Core/ScopedBinding.swift index 6307bf8c..29c71915 100644 --- a/Sources/Core/ScopedBinding.swift +++ b/Sources/Core/ScopedBinding.swift @@ -4,7 +4,7 @@ struct ScopedBinding { let key: AnyBindingKey - let maker: AnyInstanceMaker + let builder: AnyInstanceBuilder let scope: AnyScope let makeRef: ReferenceMaker } @@ -18,7 +18,7 @@ extension ScopedBinding: Binding { return try scope .registry(for: context) .instance(for: ScopeRegistryKey(descriptor: key.descriptor, argument: arg)) { - makeRef(try maker.makeInstance(arg: arg, context: context, resolver: resolver)) + makeRef(try builder.makeInstance(arg: arg, context: context, resolver: resolver)) } } } @@ -45,7 +45,7 @@ extension ScopedBinding { } } -extension ScopedBinding.Builder: InstanceMaker { +extension ScopedBinding.Builder: InstanceBuilder { typealias MadeType = Type typealias Context = AScope.Context @@ -54,13 +54,13 @@ extension ScopedBinding.Builder: InstanceMaker { } } -extension ScopedBinding.Builder: BindingMaker { +extension ScopedBinding.Builder: BindingBuilder { typealias BoundType = Type func makeBinding(for descriptor: AnyTypeDescriptor) -> Binding { return ScopedBinding( key: BindingKey(descriptor: descriptor, contextType: Context.self, argumentType: Argument.self), - maker: self, + builder: self, scope: scope, makeRef: makeRef ) diff --git a/Sources/Core/SimpleBinding.swift b/Sources/Core/SimpleBinding.swift index 308ab560..b10bb594 100644 --- a/Sources/Core/SimpleBinding.swift +++ b/Sources/Core/SimpleBinding.swift @@ -4,7 +4,7 @@ struct SimpleBinding { let key: AnyBindingKey - let maker: AnyInstanceMaker + let builder: AnyInstanceBuilder } extension SimpleBinding: Binding { @@ -13,7 +13,7 @@ extension SimpleBinding: Binding { } func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any { - return try maker.makeInstance(arg: arg, context: context, resolver: resolver) + return try builder.makeInstance(arg: arg, context: context, resolver: resolver) } } @@ -27,7 +27,7 @@ extension SimpleBinding { } } -extension SimpleBinding.Builder: InstanceMaker { +extension SimpleBinding.Builder: InstanceBuilder { typealias MadeType = Type func makeInstance(arg: Argument, context: Context, resolver: Resolver) throws -> Type { @@ -35,13 +35,13 @@ extension SimpleBinding.Builder: InstanceMaker { } } -extension SimpleBinding.Builder: BindingMaker { +extension SimpleBinding.Builder: BindingBuilder { typealias BoundType = Type func makeBinding(for descriptor: AnyTypeDescriptor) -> Binding { return SimpleBinding( key: BindingKey(descriptor: descriptor, contextType: Context.self, argumentType: Argument.self), - maker: self + builder: self ) } } diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index b53e2dd3..6768c74e 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -24,7 +24,7 @@ 09470890A74A5DDE7114891B /* TaggedTypeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */; }; 0A7E1E5E74113A0C523A4973 /* BindingKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = A24B4E8F1CA18603DBB6884A /* BindingKey.swift */; }; 0B61DC733616A8ED4ED77FA7 /* StandardScopeRegistrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */; }; - 0BA8216CFBC61A93F4948ABE /* InstanceMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CADDB3E9E363310028AA5920 /* InstanceMaker.swift */; }; + 0BA8216CFBC61A93F4948ABE /* InstanceBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = CADDB3E9E363310028AA5920 /* InstanceBuilder.swift */; }; 0CD787EACEBFD1051D358E7D /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; 0CE1126436F680F9684837E4 /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; 0CE158916595980A7C8272D3 /* SingletonSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46F05CC591903E2B04B6D8ED /* SingletonSpec.swift */; }; @@ -114,7 +114,7 @@ 5ED8A7D19F21FA686215F72C /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; 5FCE2A2AE5DD0DBECA4A9953 /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */; }; 6034CF5459D96497AF36E4B6 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; - 62307C8E22EC65E5E85AA08A /* InstanceMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CADDB3E9E363310028AA5920 /* InstanceMaker.swift */; }; + 62307C8E22EC65E5E85AA08A /* InstanceBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = CADDB3E9E363310028AA5920 /* InstanceBuilder.swift */; }; 628EBFBA0031B1FA2E29F583 /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 351C4221896DDB8572BD6CB5 /* Person.swift */; }; 63528D45A548DD58D748D54C /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; 640F7A55D9A671FA112C8083 /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; @@ -180,7 +180,7 @@ 97C2EA47D7623AFD723AFE93 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */; }; 980FED1DBC62B65597E2828B /* SingletonSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46F05CC591903E2B04B6D8ED /* SingletonSpec.swift */; }; 98322F9371E1A8461BC614D1 /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; - 9885175B6062254D54CFE4D4 /* InstanceMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CADDB3E9E363310028AA5920 /* InstanceMaker.swift */; }; + 9885175B6062254D54CFE4D4 /* InstanceBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = CADDB3E9E363310028AA5920 /* InstanceBuilder.swift */; }; 98ACB1A09194572A946CA90D /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */; }; 996CCFE825834C7D3236E742 /* Container+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F446D6BD4C44E16A1D608BFB /* Container+TypeForwarding.swift */; }; 999AF7221D3F2E1F83C3ACB1 /* Container+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDA78290D6D60BD0B808571F /* Container+Logging.swift */; }; @@ -224,7 +224,7 @@ B06306286CC5EA66C88F24D1 /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 38BCCF3F950869BD1891F7A8 /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; B0B139FADA6AE07C79847EBA /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61EE5DDBE705B47AFC9A6986 /* LoadAwareAssembly.swift */; }; B293894FEB67831DDA5F000E /* Reference.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73B4B777290FF5D38A8914CC /* Reference.swift */; }; - B2E998C200979E513C70D7E3 /* InstanceMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CADDB3E9E363310028AA5920 /* InstanceMaker.swift */; }; + B2E998C200979E513C70D7E3 /* InstanceBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = CADDB3E9E363310028AA5920 /* InstanceBuilder.swift */; }; B2FAD41F7726502822AF913B /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42490D1D0C395951243F5CFF /* Container.swift */; }; B3062AB22373AD23052B61DF /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; B42331BF00B482369B908BB8 /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BFF4BA99493C54260878C4 /* ObjectScope.swift */; }; @@ -438,14 +438,14 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 01DEC4D20CE554C9DFBD0A8D /* Resolver+Injection.swifttemplate */ = {isa = PBXFileReference; path = "Resolver+Injection.swifttemplate"; sourceTree = ""; }; + 01DEC4D20CE554C9DFBD0A8D /* Resolver+Injection.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+Injection.swifttemplate"; sourceTree = ""; }; 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.swift; sourceTree = ""; }; 09FC792715B1658721F76885 /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 0CA449690AE00F6300DE8ACA /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 0DC67CB109091002AB433A46 /* SwinjectTests.xctest */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.cfbundle; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 0E0B580B43E1891812C97209 /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; 10480F2154EAA0414D4C1F55 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */ = {isa = PBXFileReference; path = .swiftlint.yml; sourceTree = ""; }; + 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .swiftlint.yml; sourceTree = ""; }; 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SynchronizedResolverSpec.swift; sourceTree = ""; }; 13513FA012659ADE699A3608 /* LazySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LazySpec.swift; sourceTree = ""; }; 1A006CC804F9AB8ACC121029 /* Utils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = ""; }; @@ -454,7 +454,7 @@ 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Circularity.swift; sourceTree = ""; }; 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Behavior.swift; sourceTree = ""; }; 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Arguments.swift; sourceTree = ""; }; - 26EEC28683E4A26B3092E8BA /* BinderEnvironment.swifttemplate */ = {isa = PBXFileReference; path = BinderEnvironment.swifttemplate; sourceTree = ""; }; + 26EEC28683E4A26B3092E8BA /* BinderEnvironment.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = BinderEnvironment.swifttemplate; sourceTree = ""; }; 273FB7A6277E0841E1570990 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; 2E0C3E4D518BC1FEF3EF8D33 /* BinderVariation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderVariation.swift; sourceTree = ""; }; 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; @@ -498,11 +498,11 @@ 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ServiceEntry+TypeForwarding.swift"; sourceTree = ""; }; 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextTranslator.swift; sourceTree = ""; }; 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistry.swift; sourceTree = ""; }; - 808C1063CA90CC593C7E0E9C /* MatchableBoxes.swifttemplate */ = {isa = PBXFileReference; path = MatchableBoxes.swifttemplate; sourceTree = ""; }; + 808C1063CA90CC593C7E0E9C /* MatchableBoxes.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = MatchableBoxes.swifttemplate; sourceTree = ""; }; 823617F3B8A9192F56B13331 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; 8B9785AAE94A5447FA307242 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTreeBuilderSpec.swift; sourceTree = ""; }; - 90191C25A2D66E07C4E9CD73 /* SwiftCode.swifttemplate */ = {isa = PBXFileReference; path = SwiftCode.swifttemplate; sourceTree = ""; }; + 90191C25A2D66E07C4E9CD73 /* SwiftCode.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = SwiftCode.swifttemplate; sourceTree = ""; }; 938425B216B78A06EC10504A /* LinuxConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinuxConfig.swift; sourceTree = ""; }; 9620155728133F451B31C0AD /* Swinject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Swinject.swift; sourceTree = ""; }; 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistryKey.swift; sourceTree = ""; }; @@ -519,24 +519,24 @@ B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderEnvironment.swift; sourceTree = ""; }; B92B8E618A08408404FB2A7A /* TypeBinder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinder.swift; sourceTree = ""; }; BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StandardScopeRegistrySpec.swift; sourceTree = ""; }; - BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */ = {isa = PBXFileReference; path = "ServiceEntry+TypeForwarding.swifttemplate"; sourceTree = ""; }; + BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "ServiceEntry+TypeForwarding.swifttemplate"; sourceTree = ""; }; BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Behavior.swift; sourceTree = ""; }; C074BAC560F277E806146C60 /* SimpleBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleBinding.swift; sourceTree = ""; }; C1E726A651C3AFE92C19608B /* SwinjectModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectModule.swift; sourceTree = ""; }; C3C516EFA0CA22D19F07B27E /* InjectionVariation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InjectionVariation.swift; sourceTree = ""; }; C68B98C653ABDED9C3D17DB3 /* Opaque.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Opaque.swift; sourceTree = ""; }; C765B92B00C0AC8625BB4AC9 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; - CADDB3E9E363310028AA5920 /* InstanceMaker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceMaker.swift; sourceTree = ""; }; + CADDB3E9E363310028AA5920 /* InstanceBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceBuilder.swift; sourceTree = ""; }; CC85CB215058F95C0BC190B1 /* Bridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bridge.swift; sourceTree = ""; }; CDA78290D6D60BD0B808571F /* Container+Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Logging.swift"; sourceTree = ""; }; - CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; + CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextSpec.swift; sourceTree = ""; }; E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRequest.swift; sourceTree = ""; }; E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; F290F6B1207A0557A528220B /* Assembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Assembly.swift; sourceTree = ""; }; F446D6BD4C44E16A1D608BFB /* Container+TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+TypeForwarding.swift"; sourceTree = ""; }; F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.TypeForwarding.swift; sourceTree = ""; }; - FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */ = {isa = PBXFileReference; path = "Resolver+LegacyApi.swifttemplate"; sourceTree = ""; }; + FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+LegacyApi.swifttemplate"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -816,7 +816,7 @@ A24B4E8F1CA18603DBB6884A /* BindingKey.swift */, 65D0BCCCD61CD9BECC29E064 /* Closable.swift */, 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */, - CADDB3E9E363310028AA5920 /* InstanceMaker.swift */, + CADDB3E9E363310028AA5920 /* InstanceBuilder.swift */, E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */, 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */, C68B98C653ABDED9C3D17DB3 /* Opaque.swift */, @@ -1382,7 +1382,7 @@ 996CCFE825834C7D3236E742 /* Container+TypeForwarding.swift in Sources */, B2FAD41F7726502822AF913B /* Container.swift in Sources */, 8B5927517B567B1DFAB5B935 /* ContextTranslator.swift in Sources */, - 62307C8E22EC65E5E85AA08A /* InstanceMaker.swift in Sources */, + 62307C8E22EC65E5E85AA08A /* InstanceBuilder.swift in Sources */, 53EBF7A46EF65F2A8DAADC7A /* InstanceRequest.swift in Sources */, A91EDAFBC3606EDFBD739899 /* InstanceWrapper.swift in Sources */, 98322F9371E1A8461BC614D1 /* Matchable.swift in Sources */, @@ -1591,7 +1591,7 @@ BD9B57E26722C80B7EF990DB /* Container+TypeForwarding.swift in Sources */, DB74F17CDFF4886B9C38AD14 /* Container.swift in Sources */, DD5E3AF2B5FCE5E81EBDF606 /* ContextTranslator.swift in Sources */, - B2E998C200979E513C70D7E3 /* InstanceMaker.swift in Sources */, + B2E998C200979E513C70D7E3 /* InstanceBuilder.swift in Sources */, 9DEAC620F2F00D0DDD3B5D3E /* InstanceRequest.swift in Sources */, 57BFBA2077E70DC1C2FE796C /* InstanceWrapper.swift in Sources */, 293985649250DF270DC89135 /* Matchable.swift in Sources */, @@ -1634,7 +1634,7 @@ 283C77045DA55C2134EC9C48 /* Container+TypeForwarding.swift in Sources */, 58ABEE0321A3061048B65EA2 /* Container.swift in Sources */, F06DEB671A4B85ABB0E96E51 /* ContextTranslator.swift in Sources */, - 0BA8216CFBC61A93F4948ABE /* InstanceMaker.swift in Sources */, + 0BA8216CFBC61A93F4948ABE /* InstanceBuilder.swift in Sources */, CECF5BD14BCDF5248771A06A /* InstanceRequest.swift in Sources */, 389C54E04DD794DA4F648571 /* InstanceWrapper.swift in Sources */, 87FEAEF562B99522083CB87D /* Matchable.swift in Sources */, @@ -1677,7 +1677,7 @@ 3A0B409E840B44B281DB3C54 /* Container+TypeForwarding.swift in Sources */, 0622539110A7430776A307C7 /* Container.swift in Sources */, D1DF4740A9D86362B63104B8 /* ContextTranslator.swift in Sources */, - 9885175B6062254D54CFE4D4 /* InstanceMaker.swift in Sources */, + 9885175B6062254D54CFE4D4 /* InstanceBuilder.swift in Sources */, 128913D570B4A8BBF40866BE /* InstanceRequest.swift in Sources */, 98ACB1A09194572A946CA90D /* InstanceWrapper.swift in Sources */, 5ED8A7D19F21FA686215F72C /* Matchable.swift in Sources */, @@ -1821,7 +1821,11 @@ "$(PROJECT_DIR)/Carthage/Build/iOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -1859,7 +1863,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = macosx; SKIP_INSTALL = YES; @@ -1876,7 +1883,11 @@ "$(PROJECT_DIR)/Carthage/Build/tvOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = appletvos; TARGETED_DEVICE_FAMILY = 3; @@ -1894,7 +1905,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = appletvos; SKIP_INSTALL = YES; @@ -1912,7 +1926,11 @@ "$(PROJECT_DIR)/Carthage/Build/iOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -1929,7 +1947,11 @@ "$(PROJECT_DIR)/Carthage/Build/Mac", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = macosx; }; @@ -2019,7 +2041,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = appletvos; SKIP_INSTALL = YES; @@ -2037,7 +2062,11 @@ "$(PROJECT_DIR)/Carthage/Build/watchOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = watchos; SKIP_INSTALL = YES; @@ -2056,7 +2085,10 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); SDKROOT = macosx; SKIP_INSTALL = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -2074,7 +2106,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = iphoneos; SKIP_INSTALL = YES; @@ -2092,7 +2127,11 @@ "$(PROJECT_DIR)/Carthage/Build/watchOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = watchos; SKIP_INSTALL = YES; @@ -2110,7 +2149,11 @@ "$(PROJECT_DIR)/Carthage/Build/Mac", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = macosx; }; @@ -2125,7 +2168,11 @@ "$(PROJECT_DIR)/Carthage/Build/tvOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = appletvos; TARGETED_DEVICE_FAMILY = 3; @@ -2143,7 +2190,10 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); SDKROOT = macosx; SKIP_INSTALL = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -2162,7 +2212,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = macosx; SKIP_INSTALL = YES; @@ -2181,7 +2234,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = iphoneos; SKIP_INSTALL = YES; diff --git a/Templates/BinderVariation.swift b/Templates/BinderVariation.swift index a64ab4fe..295be62f 100644 --- a/Templates/BinderVariation.swift +++ b/Templates/BinderVariation.swift @@ -60,7 +60,7 @@ extension BinderVariation { } var returnType: String { - return "SomeBindingMaker" + return "SomeBindingBuilder" } var actualReturnType: String { diff --git a/Templates/SwiftCode.swifttemplate b/Templates/SwiftCode.swifttemplate index cce2f55f..f782f0f0 100644 --- a/Templates/SwiftCode.swifttemplate +++ b/Templates/SwiftCode.swifttemplate @@ -61,7 +61,7 @@ extension BinderVariation { } var returnType: String { - return "SomeBindingMaker" + return "SomeBindingBuilder" } var actualReturnType: String { From 66f2ce943795d21ff8daf9fdbbb1d9705ba54de7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 28 Jul 2019 14:16:46 +0200 Subject: [PATCH 166/239] Remove AnyBindingKey --- Sources/2.0 API/ServiceEntry.swift | 2 +- Sources/Core/Binding.swift | 14 +++++++++++++- Sources/Core/BindingKey.swift | 23 ----------------------- Sources/Core/Closable.swift | 7 ------- Sources/Core/Scope.swift | 4 ++++ Sources/Core/ScopedBinding.swift | 4 ++-- Sources/Core/SimpleBinding.swift | 4 ++-- Swinject.xcodeproj/project.pbxproj | 20 -------------------- 8 files changed, 22 insertions(+), 56 deletions(-) delete mode 100644 Sources/Core/BindingKey.swift delete mode 100644 Sources/Core/Closable.swift diff --git a/Sources/2.0 API/ServiceEntry.swift b/Sources/2.0 API/ServiceEntry.swift index f031179c..7997c17b 100644 --- a/Sources/2.0 API/ServiceEntry.swift +++ b/Sources/2.0 API/ServiceEntry.swift @@ -69,7 +69,7 @@ public class ServiceEntry { } extension ServiceEntry: Binding { - public func matches(_ key: AnyBindingKey) -> Bool { + public func matches(_ key: BindingKey) -> Bool { let forwardedKeys = forwardedDescriptors.map { BindingKey(descriptor: $0, contextType: scope?.contextType ?? Any.self, argumentType: argumentType) } diff --git a/Sources/Core/Binding.swift b/Sources/Core/Binding.swift index eae05574..89de9d89 100644 --- a/Sources/Core/Binding.swift +++ b/Sources/Core/Binding.swift @@ -2,8 +2,20 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // +public struct BindingKey { + let descriptor: AnyTypeDescriptor + let contextType: Any.Type + let argumentType: Any.Type + + func matches(_ other: BindingKey) -> Bool { + return descriptor.matches(other.descriptor) + && (contextType == other.contextType || contextType == Any.self) + && argumentType == other.argumentType + } +} + public protocol Binding: SwinjectEntry { - func matches(_ key: AnyBindingKey) -> Bool + func matches(_ key: BindingKey) -> Bool func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any } diff --git a/Sources/Core/BindingKey.swift b/Sources/Core/BindingKey.swift deleted file mode 100644 index 5bf33602..00000000 --- a/Sources/Core/BindingKey.swift +++ /dev/null @@ -1,23 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -public protocol AnyBindingKey { - var contextType: Any.Type { get } - var argumentType: Any.Type { get } - var descriptor: AnyTypeDescriptor { get } - - func matches(_ other: AnyBindingKey) -> Bool -} - -struct BindingKey: AnyBindingKey { - let descriptor: AnyTypeDescriptor - let contextType: Any.Type - let argumentType: Any.Type - - func matches(_ other: AnyBindingKey) -> Bool { - return descriptor.matches(other.descriptor) - && (contextType == other.contextType || contextType == Any.self) - && argumentType == other.argumentType - } -} diff --git a/Sources/Core/Closable.swift b/Sources/Core/Closable.swift deleted file mode 100644 index 1d58d804..00000000 --- a/Sources/Core/Closable.swift +++ /dev/null @@ -1,7 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -public protocol Closable { - func close() -} diff --git a/Sources/Core/Scope.swift b/Sources/Core/Scope.swift index abee896e..eb236e56 100644 --- a/Sources/Core/Scope.swift +++ b/Sources/Core/Scope.swift @@ -20,6 +20,10 @@ public extension Scope { } } +public protocol Closable { + func close() +} + public class UnboundScope: Scope, Closable { public typealias Context = Any diff --git a/Sources/Core/ScopedBinding.swift b/Sources/Core/ScopedBinding.swift index 29c71915..b601e86d 100644 --- a/Sources/Core/ScopedBinding.swift +++ b/Sources/Core/ScopedBinding.swift @@ -3,14 +3,14 @@ // struct ScopedBinding { - let key: AnyBindingKey + let key: BindingKey let builder: AnyInstanceBuilder let scope: AnyScope let makeRef: ReferenceMaker } extension ScopedBinding: Binding { - func matches(_ key: AnyBindingKey) -> Bool { + func matches(_ key: BindingKey) -> Bool { return self.key.matches(key) } diff --git a/Sources/Core/SimpleBinding.swift b/Sources/Core/SimpleBinding.swift index b10bb594..009a6952 100644 --- a/Sources/Core/SimpleBinding.swift +++ b/Sources/Core/SimpleBinding.swift @@ -3,12 +3,12 @@ // struct SimpleBinding { - let key: AnyBindingKey + let key: BindingKey let builder: AnyInstanceBuilder } extension SimpleBinding: Binding { - func matches(_ key: AnyBindingKey) -> Bool { + func matches(_ key: BindingKey) -> Bool { return self.key.matches(key) } diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 6768c74e..e6ba2db3 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -22,7 +22,6 @@ 0781579818FC4A2CA1CD3CAE /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */; }; 0946D0D940D38828FD0DFBAD /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */; }; 09470890A74A5DDE7114891B /* TaggedTypeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */; }; - 0A7E1E5E74113A0C523A4973 /* BindingKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = A24B4E8F1CA18603DBB6884A /* BindingKey.swift */; }; 0B61DC733616A8ED4ED77FA7 /* StandardScopeRegistrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */; }; 0BA8216CFBC61A93F4948ABE /* InstanceBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = CADDB3E9E363310028AA5920 /* InstanceBuilder.swift */; }; 0CD787EACEBFD1051D358E7D /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; @@ -41,7 +40,6 @@ 1CA5DF3F93203B226A6FA059 /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EA566CD336DB8343ADFAF9B /* BehaviorFakes.swift */; }; 1E1CAA4156D94E3A73AEA9F6 /* Opaque.swift in Sources */ = {isa = PBXBuildFile; fileRef = C68B98C653ABDED9C3D17DB3 /* Opaque.swift */; }; 1ED6BD68D92F4FE60978EF22 /* Container+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDA78290D6D60BD0B808571F /* Container+Logging.swift */; }; - 1EF3807EB529346903DFA2A1 /* BindingKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = A24B4E8F1CA18603DBB6884A /* BindingKey.swift */; }; 21285CED416F1317E993397A /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59A3946B59EB4D787CCE9F2 /* Container+Registration.swift */; }; 233F3E25FF0B51A3E6611F58 /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; 24114725AE1A834C6E3118F7 /* TaggedTypeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */; }; @@ -83,7 +81,6 @@ 42FE916C1593A9289E1A28BC /* InjectionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 670DB253ECD5CE1468A7F2E3 /* InjectionSpec.swift */; }; 4347EE17D0C0ED574C899D85 /* ScopeRegistryKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */; }; 43A74237D8933572BAA0F3B4 /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; - 4415F3731760950C06EF2CBA /* Closable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D0BCCCD61CD9BECC29E064 /* Closable.swift */; }; 44F458F61B21D78A91664160 /* BinderVariation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E0C3E4D518BC1FEF3EF8D33 /* BinderVariation.swift */; }; 48D1568CB41BE4B6597FD535 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; 48F40377D116C6B1B786C329 /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; @@ -205,7 +202,6 @@ A6EECC339FA54CA0BBFF4146 /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BC5108ED11A3A3084D864CC /* Animal.swift */; }; A70936B898139A6C5F83F616 /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; A75BAA10EC6F738EBC2C5BE8 /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */; }; - A78FF99AA81139C27FA57F4F /* BindingKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = A24B4E8F1CA18603DBB6884A /* BindingKey.swift */; }; A7DD08A60F12EC078BBE086F /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; A834D948AB86794CA3304B98 /* LinuxConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 938425B216B78A06EC10504A /* LinuxConfig.swift */; }; A882705E4199EF759E80B311 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; @@ -285,14 +281,12 @@ D9F132E4A6F6BC2BDD5DFCAA /* ModulesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75BE3AE3E30DFE42A919D825 /* ModulesSpec.swift */; }; DB74F17CDFF4886B9C38AD14 /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42490D1D0C395951243F5CFF /* Container.swift */; }; DC5B169FD525CC1C01518312 /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59111BE319C59E4CD6CF68CD /* Assembler.swift */; }; - DCA3CCF94219A24E82DAF9ED /* Closable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D0BCCCD61CD9BECC29E064 /* Closable.swift */; }; DCB7C4BF24782862BE9DB135 /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; DD29D2E60DA979D61F32A39A /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62682D6ED38742996624B041 /* BasicAssembly.swift */; }; DD5E3AF2B5FCE5E81EBDF606 /* ContextTranslator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */; }; E01D0D443FBA4DB82A6EC298 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; E177D354B1F410129D921C69 /* Resolver+LegacyApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A784E2DEC7691D14DDBECD8 /* Resolver+LegacyApi.swift */; }; E1B95D3EEA5BB989CCFFE70D /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = A10187BB3A994165E7FC1528 /* ScopedBinding.swift */; }; - E2FE364C858AA7CE86B42D6F /* Closable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D0BCCCD61CD9BECC29E064 /* Closable.swift */; }; E3EABE098DBFB561A20632E3 /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; E4CE31B7B9616EFC93C69341 /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; E5880DBBB91CC5F8F47FBF73 /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; @@ -310,10 +304,8 @@ F06DEB671A4B85ABB0E96E51 /* ContextTranslator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */; }; F1F3BA81462E2362374BD4C4 /* ModulesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75BE3AE3E30DFE42A919D825 /* ModulesSpec.swift */; }; F270DC6FF3901F58C76F3872 /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; - F39521855B858534A8D53C8F /* Closable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D0BCCCD61CD9BECC29E064 /* Closable.swift */; }; F504C2ABEFCFFCAC8B858751 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; F568382FB877060127790413 /* Resolver+LegacyApi.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */; }; - F6CF010989F531AB0A27B5A1 /* BindingKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = A24B4E8F1CA18603DBB6884A /* BindingKey.swift */; }; F6EEF5F7B57DC0E44EF569A4 /* OptionalsSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50D6F2639990DD5BAD9578B0 /* OptionalsSpec.swift */; }; F7979BE4BE1B1C7101D15E61 /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; F7CD04FB09FC7F18E9E001CF /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; @@ -483,7 +475,6 @@ 5F7BC1C4169BB4382C6D3E1F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 61EE5DDBE705B47AFC9A6986 /* LoadAwareAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadAwareAssembly.swift; sourceTree = ""; }; 62682D6ED38742996624B041 /* BasicAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BasicAssembly.swift; sourceTree = ""; }; - 65D0BCCCD61CD9BECC29E064 /* Closable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Closable.swift; sourceTree = ""; }; 670DB253ECD5CE1468A7F2E3 /* InjectionSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InjectionSpec.swift; sourceTree = ""; }; 683A1FB7D7F4E9508D57E936 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceWrapper.swift; sourceTree = ""; }; @@ -508,7 +499,6 @@ 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistryKey.swift; sourceTree = ""; }; A10187BB3A994165E7FC1528 /* ScopedBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopedBinding.swift; sourceTree = ""; }; A20C1319AF31EC7F8E6945FE /* SwinjectTests.xctest */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.cfbundle; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - A24B4E8F1CA18603DBB6884A /* BindingKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingKey.swift; sourceTree = ""; }; A3586A4987B7C7C8122D674E /* SwinjectError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectError.swift; sourceTree = ""; }; A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Resolver.swift; sourceTree = ""; }; ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Circularity.swift; sourceTree = ""; }; @@ -813,8 +803,6 @@ isa = PBXGroup; children = ( 0E0B580B43E1891812C97209 /* Binding.swift */, - A24B4E8F1CA18603DBB6884A /* BindingKey.swift */, - 65D0BCCCD61CD9BECC29E064 /* Closable.swift */, 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */, CADDB3E9E363310028AA5920 /* InstanceBuilder.swift */, E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */, @@ -1375,8 +1363,6 @@ 703F8B3AD111A6CFAFF66A49 /* Behavior.swift in Sources */, ADCF273AF041E74DBEC2C13A /* BinderEnvironment.swift in Sources */, 658AEDC8D802A6788E959E0C /* Binding.swift in Sources */, - 0A7E1E5E74113A0C523A4973 /* BindingKey.swift in Sources */, - E2FE364C858AA7CE86B42D6F /* Closable.swift in Sources */, 694C2C891D581371B2B051D7 /* Container+Logging.swift in Sources */, AAD8D0551B8A26A9B22AECEC /* Container+Registration.swift in Sources */, 996CCFE825834C7D3236E742 /* Container+TypeForwarding.swift in Sources */, @@ -1584,8 +1570,6 @@ FA805A162E989A22990B99AA /* Behavior.swift in Sources */, 6FCCBA9D2E4C2A225CB1A152 /* BinderEnvironment.swift in Sources */, F9A4BF18B0085B7DCD3440EC /* Binding.swift in Sources */, - 1EF3807EB529346903DFA2A1 /* BindingKey.swift in Sources */, - DCA3CCF94219A24E82DAF9ED /* Closable.swift in Sources */, 6A03ABEED82EF31E8E6E297E /* Container+Logging.swift in Sources */, A5E4C79F89E1A8AB3A4D8D6E /* Container+Registration.swift in Sources */, BD9B57E26722C80B7EF990DB /* Container+TypeForwarding.swift in Sources */, @@ -1627,8 +1611,6 @@ 2CB057F2A16DA462E0517AAB /* Behavior.swift in Sources */, 2DD6F290740EA69B3E73E0EA /* BinderEnvironment.swift in Sources */, D2BAE1CB997A4D052CB8EFC8 /* Binding.swift in Sources */, - A78FF99AA81139C27FA57F4F /* BindingKey.swift in Sources */, - 4415F3731760950C06EF2CBA /* Closable.swift in Sources */, 1ED6BD68D92F4FE60978EF22 /* Container+Logging.swift in Sources */, CB0B308F3D3A831A28127462 /* Container+Registration.swift in Sources */, 283C77045DA55C2134EC9C48 /* Container+TypeForwarding.swift in Sources */, @@ -1670,8 +1652,6 @@ F7979BE4BE1B1C7101D15E61 /* Behavior.swift in Sources */, B5FF5DFE394B6B1BB930D88D /* BinderEnvironment.swift in Sources */, 3F8F5645D6D37FCEC1D89393 /* Binding.swift in Sources */, - F6CF010989F531AB0A27B5A1 /* BindingKey.swift in Sources */, - F39521855B858534A8D53C8F /* Closable.swift in Sources */, 999AF7221D3F2E1F83C3ACB1 /* Container+Logging.swift in Sources */, 21285CED416F1317E993397A /* Container+Registration.swift in Sources */, 3A0B409E840B44B281DB3C54 /* Container+TypeForwarding.swift in Sources */, From 22e1029dd87f5b475c02fa69b1e14add590b3aa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 28 Jul 2019 09:41:53 +0200 Subject: [PATCH 167/239] Define instance retrieval API --- Sources/3.0 API/TypeBinder.swift | 4 +- Sources/Core/Resolver.swift | 12 +++ Swinject.xcodeproj/project.pbxproj | 134 ++++++++++------------------- Tests/3.0 API/RetrievalSpec.swift | 24 ++++++ Tests/LinuxConfig.swift | 1 + 5 files changed, 84 insertions(+), 91 deletions(-) create mode 100644 Tests/3.0 API/RetrievalSpec.swift diff --git a/Sources/3.0 API/TypeBinder.swift b/Sources/3.0 API/TypeBinder.swift index 1d0af77d..a7817ac0 100644 --- a/Sources/3.0 API/TypeBinder.swift +++ b/Sources/3.0 API/TypeBinder.swift @@ -15,7 +15,9 @@ public func bind(_: Type.Type, tagged tag: Tag) -> TypeBinder(_ builder: Builder) -> Binding where Builder: BindingBuilder, Builder.BoundType == Descriptor.BaseType { + func with( + _ builder: Builder + ) -> Binding where Builder: BindingBuilder, Builder.BoundType == Descriptor.BaseType { return builder.makeBinding(for: descriptor) } diff --git a/Sources/Core/Resolver.swift b/Sources/Core/Resolver.swift index 8b9b85ae..c99a6a77 100644 --- a/Sources/Core/Resolver.swift +++ b/Sources/Core/Resolver.swift @@ -7,3 +7,15 @@ public protocol Resolver { _ request: InstanceRequest ) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor } + +public protocol SwinjectAware: Resolver { + var swinject: Resolver { get } +} + +extension SwinjectAware { + public func resolve( + _ request: InstanceRequest + ) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { + return try swinject.resolve(request) + } +} diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index e6ba2db3..f33d4eca 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -17,13 +17,13 @@ 0509EE8D41BF354EB91ACC80 /* Reference.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73B4B777290FF5D38A8914CC /* Reference.swift */; }; 0622539110A7430776A307C7 /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42490D1D0C395951243F5CFF /* Container.swift */; }; 06363AE7650CA288BDF6CB73 /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 34AFFAC41BA9D02A38BDB7A3 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 06CD85528AABB15BDFBF3166 /* RetrievalSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D8B3342E2AC3236F12072F5 /* RetrievalSpec.swift */; }; 06F4CAB352B4F623FF7BD885 /* ScopeRegistryKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */; }; 0720BEA814AD514378380ACB /* StandardScopeRegistrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */; }; 0781579818FC4A2CA1CD3CAE /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */; }; 0946D0D940D38828FD0DFBAD /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */; }; 09470890A74A5DDE7114891B /* TaggedTypeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */; }; 0B61DC733616A8ED4ED77FA7 /* StandardScopeRegistrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */; }; - 0BA8216CFBC61A93F4948ABE /* InstanceBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = CADDB3E9E363310028AA5920 /* InstanceBuilder.swift */; }; 0CD787EACEBFD1051D358E7D /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; 0CE1126436F680F9684837E4 /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; 0CE158916595980A7C8272D3 /* SingletonSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46F05CC591903E2B04B6D8ED /* SingletonSpec.swift */; }; @@ -35,6 +35,7 @@ 196338EA802A39E205C33B43 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; 19EBB651BD06BD0C03C1ACB5 /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59111BE319C59E4CD6CF68CD /* Assembler.swift */; }; 1A40A26942A65246D7DD268E /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = ADC44E9312C3B974AFD8F07B /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 1A68A8D05D9974002BF34CF8 /* RetrievalSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D8B3342E2AC3236F12072F5 /* RetrievalSpec.swift */; }; 1C62135FAE3D64DC7BFBF861 /* ContextSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */; }; 1C82BFD00FCC384DB3AE6A89 /* MatchableBoxes.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 808C1063CA90CC593C7E0E9C /* MatchableBoxes.swifttemplate */; }; 1CA5DF3F93203B226A6FA059 /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EA566CD336DB8343ADFAF9B /* BehaviorFakes.swift */; }; @@ -56,6 +57,7 @@ 2CB057F2A16DA462E0517AAB /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; 2D020C6391A4F6A2118585B8 /* Reference.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73B4B777290FF5D38A8914CC /* Reference.swift */; }; 2DD6F290740EA69B3E73E0EA /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */; }; + 2F664F8534CA1D92ED2F81E2 /* RetrievalSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D8B3342E2AC3236F12072F5 /* RetrievalSpec.swift */; }; 3099172980F9E9143C0A1C20 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; 30D247E8083858C233B92908 /* SingletonSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46F05CC591903E2B04B6D8ED /* SingletonSpec.swift */; }; 3129A37CDC1653C11800E24A /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EA566CD336DB8343ADFAF9B /* BehaviorFakes.swift */; }; @@ -111,7 +113,6 @@ 5ED8A7D19F21FA686215F72C /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; 5FCE2A2AE5DD0DBECA4A9953 /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */; }; 6034CF5459D96497AF36E4B6 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; - 62307C8E22EC65E5E85AA08A /* InstanceBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = CADDB3E9E363310028AA5920 /* InstanceBuilder.swift */; }; 628EBFBA0031B1FA2E29F583 /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 351C4221896DDB8572BD6CB5 /* Person.swift */; }; 63528D45A548DD58D748D54C /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; 640F7A55D9A671FA112C8083 /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; @@ -125,6 +126,7 @@ 6A0FD11468B3852E48B682BE /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; 6BB1E24C1CE55C9F6EA6CC28 /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C765B92B00C0AC8625BB4AC9 /* Quick.framework */; }; 6C01E868DE44BD396D94858B /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; + 6C4D29A3FB54416D5E4D4C89 /* InstanceBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED41A352529A5B2950F39D8F /* InstanceBuilder.swift */; }; 6DA49F84E2592B32F81F268B /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BFF4BA99493C54260878C4 /* ObjectScope.swift */; }; 6F6FAD0EEF84580DD53BB755 /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1C58FC14EEA170B0DC079DE4 /* Quick.framework */; }; 6FCCBA9D2E4C2A225CB1A152 /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */; }; @@ -147,6 +149,7 @@ 7D0683F36CE56228AC2CD489 /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C074BAC560F277E806146C60 /* SimpleBinding.swift */; }; 7D6F664091C70BABBFB61D53 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; 7E3C3E6FD07F3BD76024770A /* InjectionVariation.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C516EFA0CA22D19F07B27E /* InjectionVariation.swift */; }; + 7F9686F3669BF35E5AC970B3 /* InstanceBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED41A352529A5B2950F39D8F /* InstanceBuilder.swift */; }; 8016512839FE61EC3127E489 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */; }; 811BA1018E9BF86A7DEB728F /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */; }; 818DF17D671EA1022CE59A2A /* InjectionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 670DB253ECD5CE1468A7F2E3 /* InjectionSpec.swift */; }; @@ -177,7 +180,6 @@ 97C2EA47D7623AFD723AFE93 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */; }; 980FED1DBC62B65597E2828B /* SingletonSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46F05CC591903E2B04B6D8ED /* SingletonSpec.swift */; }; 98322F9371E1A8461BC614D1 /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; - 9885175B6062254D54CFE4D4 /* InstanceBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = CADDB3E9E363310028AA5920 /* InstanceBuilder.swift */; }; 98ACB1A09194572A946CA90D /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */; }; 996CCFE825834C7D3236E742 /* Container+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F446D6BD4C44E16A1D608BFB /* Container+TypeForwarding.swift */; }; 999AF7221D3F2E1F83C3ACB1 /* Container+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDA78290D6D60BD0B808571F /* Container+Logging.swift */; }; @@ -220,7 +222,6 @@ B06306286CC5EA66C88F24D1 /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 38BCCF3F950869BD1891F7A8 /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; B0B139FADA6AE07C79847EBA /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61EE5DDBE705B47AFC9A6986 /* LoadAwareAssembly.swift */; }; B293894FEB67831DDA5F000E /* Reference.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73B4B777290FF5D38A8914CC /* Reference.swift */; }; - B2E998C200979E513C70D7E3 /* InstanceBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = CADDB3E9E363310028AA5920 /* InstanceBuilder.swift */; }; B2FAD41F7726502822AF913B /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42490D1D0C395951243F5CFF /* Container.swift */; }; B3062AB22373AD23052B61DF /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; B42331BF00B482369B908BB8 /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BFF4BA99493C54260878C4 /* ObjectScope.swift */; }; @@ -229,6 +230,7 @@ B65DE0B0562540CC8CEC48F3 /* SingletonSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46F05CC591903E2B04B6D8ED /* SingletonSpec.swift */; }; B7653A6427A5E284E9A1D6D3 /* ServiceEntry+TypeForwarding.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */; }; B84167AC8C6BEB57C4D0695A /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; + B90EA5A6764CEFA2BCB6C4D9 /* InstanceBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED41A352529A5B2950F39D8F /* InstanceBuilder.swift */; }; B9550BE2BA6FA5731BEC87FD /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; B96A6370D549AAC383360ABC /* LinuxConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 938425B216B78A06EC10504A /* LinuxConfig.swift */; }; BB571B9A78FC53231A18E18C /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; @@ -280,6 +282,7 @@ D9C5E21A1B6F43FA4C9DAD3C /* Quick.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 683A1FB7D7F4E9508D57E936 /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; D9F132E4A6F6BC2BDD5DFCAA /* ModulesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75BE3AE3E30DFE42A919D825 /* ModulesSpec.swift */; }; DB74F17CDFF4886B9C38AD14 /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42490D1D0C395951243F5CFF /* Container.swift */; }; + DBEFC5C6A51FCEBF9E4F70EE /* InstanceBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED41A352529A5B2950F39D8F /* InstanceBuilder.swift */; }; DC5B169FD525CC1C01518312 /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59111BE319C59E4CD6CF68CD /* Assembler.swift */; }; DCB7C4BF24782862BE9DB135 /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; DD29D2E60DA979D61F32A39A /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62682D6ED38742996624B041 /* BasicAssembly.swift */; }; @@ -287,6 +290,7 @@ E01D0D443FBA4DB82A6EC298 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; E177D354B1F410129D921C69 /* Resolver+LegacyApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A784E2DEC7691D14DDBECD8 /* Resolver+LegacyApi.swift */; }; E1B95D3EEA5BB989CCFFE70D /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = A10187BB3A994165E7FC1528 /* ScopedBinding.swift */; }; + E227D08034E08AA0909BC043 /* RetrievalSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D8B3342E2AC3236F12072F5 /* RetrievalSpec.swift */; }; E3EABE098DBFB561A20632E3 /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; E4CE31B7B9616EFC93C69341 /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; E5880DBBB91CC5F8F47FBF73 /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; @@ -430,14 +434,15 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 01DEC4D20CE554C9DFBD0A8D /* Resolver+Injection.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+Injection.swifttemplate"; sourceTree = ""; }; + 01DEC4D20CE554C9DFBD0A8D /* Resolver+Injection.swifttemplate */ = {isa = PBXFileReference; path = "Resolver+Injection.swifttemplate"; sourceTree = ""; }; 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.swift; sourceTree = ""; }; 09FC792715B1658721F76885 /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 0CA449690AE00F6300DE8ACA /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 0D8B3342E2AC3236F12072F5 /* RetrievalSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RetrievalSpec.swift; sourceTree = ""; }; 0DC67CB109091002AB433A46 /* SwinjectTests.xctest */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.cfbundle; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 0E0B580B43E1891812C97209 /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; 10480F2154EAA0414D4C1F55 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .swiftlint.yml; sourceTree = ""; }; + 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */ = {isa = PBXFileReference; path = .swiftlint.yml; sourceTree = ""; }; 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SynchronizedResolverSpec.swift; sourceTree = ""; }; 13513FA012659ADE699A3608 /* LazySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LazySpec.swift; sourceTree = ""; }; 1A006CC804F9AB8ACC121029 /* Utils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = ""; }; @@ -446,7 +451,7 @@ 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Circularity.swift; sourceTree = ""; }; 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Behavior.swift; sourceTree = ""; }; 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Arguments.swift; sourceTree = ""; }; - 26EEC28683E4A26B3092E8BA /* BinderEnvironment.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = BinderEnvironment.swifttemplate; sourceTree = ""; }; + 26EEC28683E4A26B3092E8BA /* BinderEnvironment.swifttemplate */ = {isa = PBXFileReference; path = BinderEnvironment.swifttemplate; sourceTree = ""; }; 273FB7A6277E0841E1570990 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; 2E0C3E4D518BC1FEF3EF8D33 /* BinderVariation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderVariation.swift; sourceTree = ""; }; 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; @@ -489,11 +494,11 @@ 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ServiceEntry+TypeForwarding.swift"; sourceTree = ""; }; 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextTranslator.swift; sourceTree = ""; }; 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistry.swift; sourceTree = ""; }; - 808C1063CA90CC593C7E0E9C /* MatchableBoxes.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = MatchableBoxes.swifttemplate; sourceTree = ""; }; + 808C1063CA90CC593C7E0E9C /* MatchableBoxes.swifttemplate */ = {isa = PBXFileReference; path = MatchableBoxes.swifttemplate; sourceTree = ""; }; 823617F3B8A9192F56B13331 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; 8B9785AAE94A5447FA307242 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTreeBuilderSpec.swift; sourceTree = ""; }; - 90191C25A2D66E07C4E9CD73 /* SwiftCode.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = SwiftCode.swifttemplate; sourceTree = ""; }; + 90191C25A2D66E07C4E9CD73 /* SwiftCode.swifttemplate */ = {isa = PBXFileReference; path = SwiftCode.swifttemplate; sourceTree = ""; }; 938425B216B78A06EC10504A /* LinuxConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinuxConfig.swift; sourceTree = ""; }; 9620155728133F451B31C0AD /* Swinject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Swinject.swift; sourceTree = ""; }; 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistryKey.swift; sourceTree = ""; }; @@ -509,24 +514,24 @@ B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderEnvironment.swift; sourceTree = ""; }; B92B8E618A08408404FB2A7A /* TypeBinder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinder.swift; sourceTree = ""; }; BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StandardScopeRegistrySpec.swift; sourceTree = ""; }; - BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "ServiceEntry+TypeForwarding.swifttemplate"; sourceTree = ""; }; + BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */ = {isa = PBXFileReference; path = "ServiceEntry+TypeForwarding.swifttemplate"; sourceTree = ""; }; BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Behavior.swift; sourceTree = ""; }; C074BAC560F277E806146C60 /* SimpleBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleBinding.swift; sourceTree = ""; }; C1E726A651C3AFE92C19608B /* SwinjectModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectModule.swift; sourceTree = ""; }; C3C516EFA0CA22D19F07B27E /* InjectionVariation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InjectionVariation.swift; sourceTree = ""; }; C68B98C653ABDED9C3D17DB3 /* Opaque.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Opaque.swift; sourceTree = ""; }; C765B92B00C0AC8625BB4AC9 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; - CADDB3E9E363310028AA5920 /* InstanceBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceBuilder.swift; sourceTree = ""; }; CC85CB215058F95C0BC190B1 /* Bridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bridge.swift; sourceTree = ""; }; CDA78290D6D60BD0B808571F /* Container+Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Logging.swift"; sourceTree = ""; }; - CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; + CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextSpec.swift; sourceTree = ""; }; E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRequest.swift; sourceTree = ""; }; E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; + ED41A352529A5B2950F39D8F /* InstanceBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceBuilder.swift; sourceTree = ""; }; F290F6B1207A0557A528220B /* Assembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Assembly.swift; sourceTree = ""; }; F446D6BD4C44E16A1D608BFB /* Container+TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+TypeForwarding.swift"; sourceTree = ""; }; F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.TypeForwarding.swift; sourceTree = ""; }; - FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+LegacyApi.swifttemplate"; sourceTree = ""; }; + FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */ = {isa = PBXFileReference; path = "Resolver+LegacyApi.swifttemplate"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -723,6 +728,7 @@ 670DB253ECD5CE1468A7F2E3 /* InjectionSpec.swift */, 75BE3AE3E30DFE42A919D825 /* ModulesSpec.swift */, 50D6F2639990DD5BAD9578B0 /* OptionalsSpec.swift */, + 0D8B3342E2AC3236F12072F5 /* RetrievalSpec.swift */, 1D3C59E84B5FD0C13F487838 /* ScopesSpec.swift */, 46F05CC591903E2B04B6D8ED /* SingletonSpec.swift */, ); @@ -804,7 +810,7 @@ children = ( 0E0B580B43E1891812C97209 /* Binding.swift */, 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */, - CADDB3E9E363310028AA5920 /* InstanceBuilder.swift */, + ED41A352529A5B2950F39D8F /* InstanceBuilder.swift */, E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */, 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */, C68B98C653ABDED9C3D17DB3 /* Opaque.swift */, @@ -1368,7 +1374,7 @@ 996CCFE825834C7D3236E742 /* Container+TypeForwarding.swift in Sources */, B2FAD41F7726502822AF913B /* Container.swift in Sources */, 8B5927517B567B1DFAB5B935 /* ContextTranslator.swift in Sources */, - 62307C8E22EC65E5E85AA08A /* InstanceBuilder.swift in Sources */, + 6C4D29A3FB54416D5E4D4C89 /* InstanceBuilder.swift in Sources */, 53EBF7A46EF65F2A8DAADC7A /* InstanceRequest.swift in Sources */, A91EDAFBC3606EDFBD739899 /* InstanceWrapper.swift in Sources */, 98322F9371E1A8461BC614D1 /* Matchable.swift in Sources */, @@ -1434,6 +1440,7 @@ 72F09FC92FFB0F7C32D8E2A5 /* OptionalsSpec.swift in Sources */, 628EBFBA0031B1FA2E29F583 /* Person.swift in Sources */, 708E1C453CBC76ED26FA2FCB /* ProviderSpec.swift in Sources */, + E227D08034E08AA0909BC043 /* RetrievalSpec.swift in Sources */, 33B86F2D33219879731CDDF0 /* ScopesSpec.swift in Sources */, 30D247E8083858C233B92908 /* SingletonSpec.swift in Sources */, 72217E47D83C3CA6D97640B9 /* StandardScopeRegistrySpec.swift in Sources */, @@ -1473,6 +1480,7 @@ D941D81F59900A52805D6B4A /* OptionalsSpec.swift in Sources */, EB3420214A9E68A0247D0F2C /* Person.swift in Sources */, CF9535A0DCAFF23F4D62F871 /* ProviderSpec.swift in Sources */, + 1A68A8D05D9974002BF34CF8 /* RetrievalSpec.swift in Sources */, 0068DAA4AA322F00AF53731F /* ScopesSpec.swift in Sources */, B65DE0B0562540CC8CEC48F3 /* SingletonSpec.swift in Sources */, C952D5869D87743297968E9A /* StandardScopeRegistrySpec.swift in Sources */, @@ -1512,6 +1520,7 @@ A453A5A7E0EC0FE161AA34D5 /* OptionalsSpec.swift in Sources */, C76374CAFE7C2BCCE52F1BB1 /* Person.swift in Sources */, 4954CBB07E38E98752AC3347 /* ProviderSpec.swift in Sources */, + 2F664F8534CA1D92ED2F81E2 /* RetrievalSpec.swift in Sources */, 31729A1E5F50EF30FDD427AD /* ScopesSpec.swift in Sources */, 0CE158916595980A7C8272D3 /* SingletonSpec.swift in Sources */, 0720BEA814AD514378380ACB /* StandardScopeRegistrySpec.swift in Sources */, @@ -1551,6 +1560,7 @@ F6EEF5F7B57DC0E44EF569A4 /* OptionalsSpec.swift in Sources */, BEEFBE87EB17D56BA8D47358 /* Person.swift in Sources */, 48F40377D116C6B1B786C329 /* ProviderSpec.swift in Sources */, + 06CD85528AABB15BDFBF3166 /* RetrievalSpec.swift in Sources */, EA0D19F7DF0355C774B0F40B /* ScopesSpec.swift in Sources */, 980FED1DBC62B65597E2828B /* SingletonSpec.swift in Sources */, 0B61DC733616A8ED4ED77FA7 /* StandardScopeRegistrySpec.swift in Sources */, @@ -1575,7 +1585,7 @@ BD9B57E26722C80B7EF990DB /* Container+TypeForwarding.swift in Sources */, DB74F17CDFF4886B9C38AD14 /* Container.swift in Sources */, DD5E3AF2B5FCE5E81EBDF606 /* ContextTranslator.swift in Sources */, - B2E998C200979E513C70D7E3 /* InstanceBuilder.swift in Sources */, + 7F9686F3669BF35E5AC970B3 /* InstanceBuilder.swift in Sources */, 9DEAC620F2F00D0DDD3B5D3E /* InstanceRequest.swift in Sources */, 57BFBA2077E70DC1C2FE796C /* InstanceWrapper.swift in Sources */, 293985649250DF270DC89135 /* Matchable.swift in Sources */, @@ -1616,7 +1626,7 @@ 283C77045DA55C2134EC9C48 /* Container+TypeForwarding.swift in Sources */, 58ABEE0321A3061048B65EA2 /* Container.swift in Sources */, F06DEB671A4B85ABB0E96E51 /* ContextTranslator.swift in Sources */, - 0BA8216CFBC61A93F4948ABE /* InstanceBuilder.swift in Sources */, + DBEFC5C6A51FCEBF9E4F70EE /* InstanceBuilder.swift in Sources */, CECF5BD14BCDF5248771A06A /* InstanceRequest.swift in Sources */, 389C54E04DD794DA4F648571 /* InstanceWrapper.swift in Sources */, 87FEAEF562B99522083CB87D /* Matchable.swift in Sources */, @@ -1657,7 +1667,7 @@ 3A0B409E840B44B281DB3C54 /* Container+TypeForwarding.swift in Sources */, 0622539110A7430776A307C7 /* Container.swift in Sources */, D1DF4740A9D86362B63104B8 /* ContextTranslator.swift in Sources */, - 9885175B6062254D54CFE4D4 /* InstanceBuilder.swift in Sources */, + B90EA5A6764CEFA2BCB6C4D9 /* InstanceBuilder.swift in Sources */, 128913D570B4A8BBF40866BE /* InstanceRequest.swift in Sources */, 98ACB1A09194572A946CA90D /* InstanceWrapper.swift in Sources */, 5ED8A7D19F21FA686215F72C /* Matchable.swift in Sources */, @@ -1801,11 +1811,7 @@ "$(PROJECT_DIR)/Carthage/Build/iOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -1843,10 +1849,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; PRODUCT_NAME = Swinject; SDKROOT = macosx; SKIP_INSTALL = YES; @@ -1863,11 +1866,7 @@ "$(PROJECT_DIR)/Carthage/Build/tvOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = appletvos; TARGETED_DEVICE_FAMILY = 3; @@ -1885,10 +1884,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = Swinject; SDKROOT = appletvos; SKIP_INSTALL = YES; @@ -1906,11 +1902,7 @@ "$(PROJECT_DIR)/Carthage/Build/iOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -1927,11 +1919,7 @@ "$(PROJECT_DIR)/Carthage/Build/Mac", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - "@loader_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = macosx; }; @@ -2021,10 +2009,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = Swinject; SDKROOT = appletvos; SKIP_INSTALL = YES; @@ -2042,11 +2027,7 @@ "$(PROJECT_DIR)/Carthage/Build/watchOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = watchos; SKIP_INSTALL = YES; @@ -2065,10 +2046,7 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; SDKROOT = macosx; SKIP_INSTALL = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -2086,10 +2064,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = Swinject; SDKROOT = iphoneos; SKIP_INSTALL = YES; @@ -2107,11 +2082,7 @@ "$(PROJECT_DIR)/Carthage/Build/watchOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = watchos; SKIP_INSTALL = YES; @@ -2129,11 +2100,7 @@ "$(PROJECT_DIR)/Carthage/Build/Mac", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - "@loader_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = macosx; }; @@ -2148,11 +2115,7 @@ "$(PROJECT_DIR)/Carthage/Build/tvOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = appletvos; TARGETED_DEVICE_FAMILY = 3; @@ -2170,10 +2133,7 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; SDKROOT = macosx; SKIP_INSTALL = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -2192,10 +2152,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; PRODUCT_NAME = Swinject; SDKROOT = macosx; SKIP_INSTALL = YES; @@ -2214,10 +2171,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = Swinject; SDKROOT = iphoneos; SKIP_INSTALL = YES; diff --git a/Tests/3.0 API/RetrievalSpec.swift b/Tests/3.0 API/RetrievalSpec.swift new file mode 100644 index 00000000..300e63f4 --- /dev/null +++ b/Tests/3.0 API/RetrievalSpec.swift @@ -0,0 +1,24 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +import Nimble +import Quick +import Swinject +// swiftlint:disable force_try + +class RetrievalSpec: QuickSpec { override func spec() { #if swift(>=5.1) + it("can retrieve bound types") { + struct IntHolder: SwinjectAware { + let swinject: Resolver + lazy var int: Int = try! instance() + } + let swinject = Swinject { + bbind(IntHolder.self) & provider { IntHolder(swinject: $0) } + bbind(Int.self) & 42 + } + var holder = try? swinject.instance() as IntHolder + expect(holder?.int) == 42 + } + #endif +} } diff --git a/Tests/LinuxConfig.swift b/Tests/LinuxConfig.swift index 80e50d2d..6c9b4f9c 100644 --- a/Tests/LinuxConfig.swift +++ b/Tests/LinuxConfig.swift @@ -24,6 +24,7 @@ let allSpecs: [QuickSpec.Type] = [ ContextSpec.self, ScopesSpec.self, OptionalsSpec.self, + RetrievalSpec.self, // Unit Specs StandardScopeRegistrySpec.self, SwinjectTreeBuilderSpec.self, From af9ab32095ab85129ff679d289cbec80c3d30d0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Mon, 29 Jul 2019 21:29:43 +0200 Subject: [PATCH 168/239] Define basic rules for duplicit bindings --- Sources/2.0 API/ServiceEntry.swift | 2 +- Sources/Core/Binding.swift | 13 +++- Sources/Core/SwinjectTree.swift | 1 + Swinject.xcodeproj/project.pbxproj | 114 +++++++++++++++++++++++------ Tests/3.0 API/BindingSpec.swift | 7 -- Tests/3.0 API/OptionalsSpec.swift | 20 +++-- Tests/3.0 API/OverrideSpec.swift | 38 ++++++++++ 7 files changed, 155 insertions(+), 40 deletions(-) create mode 100644 Tests/3.0 API/OverrideSpec.swift diff --git a/Sources/2.0 API/ServiceEntry.swift b/Sources/2.0 API/ServiceEntry.swift index 7997c17b..ffcf7680 100644 --- a/Sources/2.0 API/ServiceEntry.swift +++ b/Sources/2.0 API/ServiceEntry.swift @@ -88,7 +88,7 @@ extension ServiceEntry: Binding { } } - private var key: BindingKey { + public var key: BindingKey { return BindingKey( descriptor: { if let name = name { diff --git a/Sources/Core/Binding.swift b/Sources/Core/Binding.swift index 89de9d89..ec3ac415 100644 --- a/Sources/Core/Binding.swift +++ b/Sources/Core/Binding.swift @@ -2,7 +2,7 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -public struct BindingKey { +public struct BindingKey: Hashable { let descriptor: AnyTypeDescriptor let contextType: Any.Type let argumentType: Any.Type @@ -12,9 +12,20 @@ public struct BindingKey { && (contextType == other.contextType || contextType == Any.self) && argumentType == other.argumentType } + + public func hash(into hasher: inout Hasher) { + descriptor.hash(into: &hasher) + String(describing: contextType).hash(into: &hasher) + String(describing: argumentType).hash(into: &hasher) + } + + public static func == (lhs: BindingKey, rhs: BindingKey) -> Bool { + return lhs.matches(rhs) || rhs.matches(lhs) + } } public protocol Binding: SwinjectEntry { + var key: BindingKey { get } func matches(_ key: BindingKey) -> Bool func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any } diff --git a/Sources/Core/SwinjectTree.swift b/Sources/Core/SwinjectTree.swift index 23de44b7..6152aefa 100644 --- a/Sources/Core/SwinjectTree.swift +++ b/Sources/Core/SwinjectTree.swift @@ -22,6 +22,7 @@ extension SwinjectTree { func assertValid() { let allModuleNames = allModules.map { $0.name } assert(allModuleNames.count == Set(allModuleNames).count) + assert(allBindings.count == Set(allBindings.map { $0.key }).count) } } diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index f33d4eca..2cd6cebb 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -261,6 +261,10 @@ CB9E8D16D7A0620A1F7A32A3 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; CBBE28990E0EA82AD8D5E3AF /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; CBE63031F33303F3E503CEF2 /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; + CD03917422EF610800DE44C4 /* OverrideSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD03917322EF610800DE44C4 /* OverrideSpec.swift */; }; + CD03917522EF610800DE44C4 /* OverrideSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD03917322EF610800DE44C4 /* OverrideSpec.swift */; }; + CD03917622EF610800DE44C4 /* OverrideSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD03917322EF610800DE44C4 /* OverrideSpec.swift */; }; + CD03917722EF610800DE44C4 /* OverrideSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD03917322EF610800DE44C4 /* OverrideSpec.swift */; }; CE5AFED22F04B96713ED76D7 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ADC44E9312C3B974AFD8F07B /* Nimble.framework */; }; CECF5BD14BCDF5248771A06A /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; CEE763218A90832454A6E2DE /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */; }; @@ -434,7 +438,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 01DEC4D20CE554C9DFBD0A8D /* Resolver+Injection.swifttemplate */ = {isa = PBXFileReference; path = "Resolver+Injection.swifttemplate"; sourceTree = ""; }; + 01DEC4D20CE554C9DFBD0A8D /* Resolver+Injection.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+Injection.swifttemplate"; sourceTree = ""; }; 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.swift; sourceTree = ""; }; 09FC792715B1658721F76885 /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 0CA449690AE00F6300DE8ACA /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -442,7 +446,7 @@ 0DC67CB109091002AB433A46 /* SwinjectTests.xctest */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.cfbundle; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 0E0B580B43E1891812C97209 /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; 10480F2154EAA0414D4C1F55 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */ = {isa = PBXFileReference; path = .swiftlint.yml; sourceTree = ""; }; + 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .swiftlint.yml; sourceTree = ""; }; 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SynchronizedResolverSpec.swift; sourceTree = ""; }; 13513FA012659ADE699A3608 /* LazySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LazySpec.swift; sourceTree = ""; }; 1A006CC804F9AB8ACC121029 /* Utils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = ""; }; @@ -451,7 +455,7 @@ 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Circularity.swift; sourceTree = ""; }; 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Behavior.swift; sourceTree = ""; }; 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Arguments.swift; sourceTree = ""; }; - 26EEC28683E4A26B3092E8BA /* BinderEnvironment.swifttemplate */ = {isa = PBXFileReference; path = BinderEnvironment.swifttemplate; sourceTree = ""; }; + 26EEC28683E4A26B3092E8BA /* BinderEnvironment.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = BinderEnvironment.swifttemplate; sourceTree = ""; }; 273FB7A6277E0841E1570990 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; 2E0C3E4D518BC1FEF3EF8D33 /* BinderVariation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderVariation.swift; sourceTree = ""; }; 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; @@ -494,11 +498,11 @@ 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ServiceEntry+TypeForwarding.swift"; sourceTree = ""; }; 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextTranslator.swift; sourceTree = ""; }; 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistry.swift; sourceTree = ""; }; - 808C1063CA90CC593C7E0E9C /* MatchableBoxes.swifttemplate */ = {isa = PBXFileReference; path = MatchableBoxes.swifttemplate; sourceTree = ""; }; + 808C1063CA90CC593C7E0E9C /* MatchableBoxes.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = MatchableBoxes.swifttemplate; sourceTree = ""; }; 823617F3B8A9192F56B13331 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; 8B9785AAE94A5447FA307242 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTreeBuilderSpec.swift; sourceTree = ""; }; - 90191C25A2D66E07C4E9CD73 /* SwiftCode.swifttemplate */ = {isa = PBXFileReference; path = SwiftCode.swifttemplate; sourceTree = ""; }; + 90191C25A2D66E07C4E9CD73 /* SwiftCode.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = SwiftCode.swifttemplate; sourceTree = ""; }; 938425B216B78A06EC10504A /* LinuxConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinuxConfig.swift; sourceTree = ""; }; 9620155728133F451B31C0AD /* Swinject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Swinject.swift; sourceTree = ""; }; 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistryKey.swift; sourceTree = ""; }; @@ -514,7 +518,7 @@ B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderEnvironment.swift; sourceTree = ""; }; B92B8E618A08408404FB2A7A /* TypeBinder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinder.swift; sourceTree = ""; }; BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StandardScopeRegistrySpec.swift; sourceTree = ""; }; - BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */ = {isa = PBXFileReference; path = "ServiceEntry+TypeForwarding.swifttemplate"; sourceTree = ""; }; + BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "ServiceEntry+TypeForwarding.swifttemplate"; sourceTree = ""; }; BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Behavior.swift; sourceTree = ""; }; C074BAC560F277E806146C60 /* SimpleBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleBinding.swift; sourceTree = ""; }; C1E726A651C3AFE92C19608B /* SwinjectModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectModule.swift; sourceTree = ""; }; @@ -522,8 +526,9 @@ C68B98C653ABDED9C3D17DB3 /* Opaque.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Opaque.swift; sourceTree = ""; }; C765B92B00C0AC8625BB4AC9 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; CC85CB215058F95C0BC190B1 /* Bridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bridge.swift; sourceTree = ""; }; + CD03917322EF610800DE44C4 /* OverrideSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OverrideSpec.swift; sourceTree = ""; }; CDA78290D6D60BD0B808571F /* Container+Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Logging.swift"; sourceTree = ""; }; - CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; + CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextSpec.swift; sourceTree = ""; }; E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRequest.swift; sourceTree = ""; }; E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; @@ -531,7 +536,7 @@ F290F6B1207A0557A528220B /* Assembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Assembly.swift; sourceTree = ""; }; F446D6BD4C44E16A1D608BFB /* Container+TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+TypeForwarding.swift"; sourceTree = ""; }; F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.TypeForwarding.swift; sourceTree = ""; }; - FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */ = {isa = PBXFileReference; path = "Resolver+LegacyApi.swifttemplate"; sourceTree = ""; }; + FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+LegacyApi.swifttemplate"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -731,6 +736,7 @@ 0D8B3342E2AC3236F12072F5 /* RetrievalSpec.swift */, 1D3C59E84B5FD0C13F487838 /* ScopesSpec.swift */, 46F05CC591903E2B04B6D8ED /* SingletonSpec.swift */, + CD03917322EF610800DE44C4 /* OverrideSpec.swift */, ); path = "3.0 API"; sourceTree = ""; @@ -1420,6 +1426,7 @@ DD29D2E60DA979D61F32A39A /* BasicAssembly.swift in Sources */, 3129A37CDC1653C11800E24A /* BehaviorFakes.swift in Sources */, 9A2A6978519F2BBA97DA6EA6 /* BindingSpec.swift in Sources */, + CD03917422EF610800DE44C4 /* OverrideSpec.swift in Sources */, 89E2997CB8B90368A15A91CE /* Bridge.swift in Sources */, 0946D0D940D38828FD0DFBAD /* Circularity.swift in Sources */, 68D828A3C583DDD28CFE882B /* ContainerSpec.Arguments.swift in Sources */, @@ -1460,6 +1467,7 @@ 401592294E5D528379BE1AB2 /* BasicAssembly.swift in Sources */, A3BFFED76688F149FBAF7C53 /* BehaviorFakes.swift in Sources */, BB77A5D81C58392964D07233 /* BindingSpec.swift in Sources */, + CD03917522EF610800DE44C4 /* OverrideSpec.swift in Sources */, 13CDEC7A6C8E43B58D5CBE3D /* Bridge.swift in Sources */, 2B88BFD81C226C858E0AE2B6 /* Circularity.swift in Sources */, 83464EDC08380F5CE2190F30 /* ContainerSpec.Arguments.swift in Sources */, @@ -1500,6 +1508,7 @@ 03122D1B2EA65C89ADC78EC7 /* BasicAssembly.swift in Sources */, 1CA5DF3F93203B226A6FA059 /* BehaviorFakes.swift in Sources */, CAA5241DAA201FBB5818C803 /* BindingSpec.swift in Sources */, + CD03917722EF610800DE44C4 /* OverrideSpec.swift in Sources */, E4CE31B7B9616EFC93C69341 /* Bridge.swift in Sources */, 4DC8A58B6607898BAF6504A3 /* Circularity.swift in Sources */, 8436D091ED844817C8CE3AF2 /* ContainerSpec.Arguments.swift in Sources */, @@ -1540,6 +1549,7 @@ 599C7F009F954CDA522244B3 /* BasicAssembly.swift in Sources */, 8E1E051646BBD6E38F4199C2 /* BehaviorFakes.swift in Sources */, 0207493E1CEE8456E91E3DAE /* BindingSpec.swift in Sources */, + CD03917622EF610800DE44C4 /* OverrideSpec.swift in Sources */, 43A74237D8933572BAA0F3B4 /* Bridge.swift in Sources */, C177D9C6969ADA38C1094F6D /* Circularity.swift in Sources */, A70936B898139A6C5F83F616 /* ContainerSpec.Arguments.swift in Sources */, @@ -1811,7 +1821,11 @@ "$(PROJECT_DIR)/Carthage/Build/iOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -1849,7 +1863,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = macosx; SKIP_INSTALL = YES; @@ -1866,7 +1883,11 @@ "$(PROJECT_DIR)/Carthage/Build/tvOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = appletvos; TARGETED_DEVICE_FAMILY = 3; @@ -1884,7 +1905,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = appletvos; SKIP_INSTALL = YES; @@ -1902,7 +1926,11 @@ "$(PROJECT_DIR)/Carthage/Build/iOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -1919,7 +1947,11 @@ "$(PROJECT_DIR)/Carthage/Build/Mac", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = macosx; }; @@ -2009,7 +2041,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = appletvos; SKIP_INSTALL = YES; @@ -2027,7 +2062,11 @@ "$(PROJECT_DIR)/Carthage/Build/watchOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = watchos; SKIP_INSTALL = YES; @@ -2046,7 +2085,10 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); SDKROOT = macosx; SKIP_INSTALL = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -2064,7 +2106,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = iphoneos; SKIP_INSTALL = YES; @@ -2082,7 +2127,11 @@ "$(PROJECT_DIR)/Carthage/Build/watchOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = watchos; SKIP_INSTALL = YES; @@ -2100,7 +2149,11 @@ "$(PROJECT_DIR)/Carthage/Build/Mac", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = macosx; }; @@ -2115,7 +2168,11 @@ "$(PROJECT_DIR)/Carthage/Build/tvOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = appletvos; TARGETED_DEVICE_FAMILY = 3; @@ -2133,7 +2190,10 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); SDKROOT = macosx; SKIP_INSTALL = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -2152,7 +2212,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = macosx; SKIP_INSTALL = YES; @@ -2171,7 +2234,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = iphoneos; SKIP_INSTALL = YES; diff --git a/Tests/3.0 API/BindingSpec.swift b/Tests/3.0 API/BindingSpec.swift index d20cc532..18c654fe 100644 --- a/Tests/3.0 API/BindingSpec.swift +++ b/Tests/3.0 API/BindingSpec.swift @@ -15,13 +15,6 @@ class BindingSpec: QuickSpec { override func spec() { #if swift(>=5.1) expect { try swinject.instance() as Int } == 42 expect { try swinject.instance() as Double } == 42 } - it("does not allow multiple bindings for the same type") { - let swinject = Swinject { - bbind(Int.self).with(42) - bbind(Int.self) & 27 - } - expect { try swinject.instance() as Int }.to(throwError()) - } it("can bind the same type with different tags") { let swinject = Swinject { bbind(String.self) & "Plain" diff --git a/Tests/3.0 API/OptionalsSpec.swift b/Tests/3.0 API/OptionalsSpec.swift index 57343470..a296022c 100644 --- a/Tests/3.0 API/OptionalsSpec.swift +++ b/Tests/3.0 API/OptionalsSpec.swift @@ -13,6 +13,19 @@ class OptionalsSpec: QuickSpec { override func spec() { #if swift(>=5.1) } expect { try swinject.instance() as Int? } == 42 } + // TODO: Maybe nice to have? +// it("can use a binding of the injected type's optional") { +// let swinject = Swinject { +// bbind(Int?.self) & 42 +// } +// expect { try swinject.instance() as Int } == 42 +// } + it("throws if binding of the type's optional produces nil") { + let swinject = Swinject { + bbind(Int?.self) & nil + } + expect { try swinject.instance() as Int }.to(throwError()) + } it("can use a binding for bound type's double optional") { let swinject = Swinject { bbind(Int.self) & 42 @@ -29,13 +42,6 @@ class OptionalsSpec: QuickSpec { override func spec() { #if swift(>=5.1) } expect { try swinject.instance() as Int? }.to(throwError()) } - it("throws if has multiple bindings for optional") { - let swinject = Swinject { - bbind(Int.self) & 42 - bbind(Int.self) & 25 - } - expect { try swinject.instance() as Int? }.to(throwError()) - } it("injects same singleton instance for type and it's optional") { let swinject = Swinject { bbind(Human.self) & singleton { Human() } diff --git a/Tests/3.0 API/OverrideSpec.swift b/Tests/3.0 API/OverrideSpec.swift new file mode 100644 index 00000000..5832d0d9 --- /dev/null +++ b/Tests/3.0 API/OverrideSpec.swift @@ -0,0 +1,38 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +import Nimble +import Quick +import Swinject + +class OverrideSpec: QuickSpec { override func spec() { #if swift(>=5.1) + it("does not allow multiple bindings for the same type") { + expect { + _ = Swinject { + bbind(Int.self) & 42 + bbind(Int.self) & provider { 25 + 17 } + } + }.ifDebugTo(throwAssertion()) + } + it("does not allow bindings for type and it's optional") { + expect { + _ = Swinject { + bbind(Int?.self) & 42 + bbind(Int.self) & provider { 25 + 17 } + } + }.ifDebugTo(throwAssertion()) + } + it("does not allow multiple bindings for the same type in a module hierarchy") { + let firstModule = Swinject.Module("first") { + bbind(Int.self) & 42 + } + expect { + _ = Swinject { + include(firstModule) + bbind(Int.self) & provider { 25 + 17 } + } + }.ifDebugTo(throwAssertion()) + } + #endif +} } From 79cfc0ad198b27fa1c4f6c449c351703c86cd43a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Mon, 29 Jul 2019 22:50:56 +0200 Subject: [PATCH 169/239] Describe basic rules for binding overrides --- Sources/2.0 API/ServiceEntry.swift | 7 +++++ Sources/3.0 API/TypeBinder.swift | 46 +++++++++++++++++++--------- Sources/Core/Binding.swift | 11 ++++--- Sources/Core/ScopedBinding.swift | 6 ++-- Sources/Core/SimpleBinding.swift | 6 ++-- Sources/Core/Swinject.swift | 16 +++++++--- Sources/Core/SwinjectContainer.swift | 37 ++++++++++++++++++++++ Sources/Core/SwinjectTree.swift | 22 +------------ Swinject.xcodeproj/project.pbxproj | 10 ++++++ Tests/3.0 API/OverrideSpec.swift | 30 ++++++++++++++++++ Tests/Support/Bridge.swift | 15 ++++++--- 11 files changed, 153 insertions(+), 53 deletions(-) create mode 100644 Sources/Core/SwinjectContainer.swift diff --git a/Sources/2.0 API/ServiceEntry.swift b/Sources/2.0 API/ServiceEntry.swift index ffcf7680..9b4e1793 100644 --- a/Sources/2.0 API/ServiceEntry.swift +++ b/Sources/2.0 API/ServiceEntry.swift @@ -69,6 +69,13 @@ public class ServiceEntry { } extension ServiceEntry: Binding { + public var properties: BindingProperties { + return BindingProperties( + descriptor: key.descriptor, + overrides: false + ) + } + public func matches(_ key: BindingKey) -> Bool { let forwardedKeys = forwardedDescriptors.map { BindingKey(descriptor: $0, contextType: scope?.contextType ?? Any.self, argumentType: argumentType) diff --git a/Sources/3.0 API/TypeBinder.swift b/Sources/3.0 API/TypeBinder.swift index a7817ac0..59f003ff 100644 --- a/Sources/3.0 API/TypeBinder.swift +++ b/Sources/3.0 API/TypeBinder.swift @@ -2,36 +2,54 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -public struct TypeBinder where Descriptor: TypeDescriptor { - let descriptor: Descriptor +public struct BindingProperties { + let descriptor: AnyTypeDescriptor + let overrides: Bool } -public func bind(_: Type.Type) -> TypeBinder> { - return TypeBinder(descriptor: plain(Type.self).opaque) +public struct TypeBinder { + let properties: BindingProperties } -public func bind(_: Type.Type, tagged tag: Tag) -> TypeBinder> where Tag: Hashable { - return TypeBinder(descriptor: tagged(Type.self, with: tag).opaque) +public func bind( + _: Type.Type, + overrides: Bool = false +) -> TypeBinder { + return TypeBinder(properties: BindingProperties( + descriptor: plain(Type.self), + overrides: overrides + )) +} + +public func bind( + _: Type.Type, + tagged tag: Tag, + overrides: Bool = false +) -> TypeBinder where Tag: Hashable { + return TypeBinder(properties: BindingProperties( + descriptor: tagged(Type.self, with: tag), + overrides: overrides + )) } public extension TypeBinder { func with( _ builder: Builder - ) -> Binding where Builder: BindingBuilder, Builder.BoundType == Descriptor.BaseType { - return builder.makeBinding(for: descriptor) + ) -> Binding where Builder: BindingBuilder, Builder.BoundType == BoundType { + return builder.makeBinding(with: properties) } - func with(_ value: Descriptor.BaseType) -> Binding { - return instance(value).makeBinding(for: descriptor) + func with(_ value: BoundType) -> Binding { + return instance(value).makeBinding(with: properties) } } -public func & ( - lhs: TypeBinder, rhs: Builder -) -> Binding where Builder: BindingBuilder, Builder.BoundType == Descriptor.BaseType { +public func & ( + lhs: TypeBinder, rhs: Builder +) -> Binding where Builder: BindingBuilder, Builder.BoundType == BoundType { return lhs.with(rhs) } -public func & (lhs: TypeBinder, rhs: Descriptor.BaseType) -> Binding { +public func & (lhs: TypeBinder, rhs: BoundType) -> Binding { return lhs.with(rhs) } diff --git a/Sources/Core/Binding.swift b/Sources/Core/Binding.swift index ec3ac415..a208b5ad 100644 --- a/Sources/Core/Binding.swift +++ b/Sources/Core/Binding.swift @@ -26,26 +26,27 @@ public struct BindingKey: Hashable { public protocol Binding: SwinjectEntry { var key: BindingKey { get } + var properties: BindingProperties { get } func matches(_ key: BindingKey) -> Bool func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any } public protocol BindingBuilder { associatedtype BoundType - func makeBinding(for descriptor: AnyTypeDescriptor) -> Binding + func makeBinding(with properties: BindingProperties) -> Binding } public struct SomeBindingBuilder: BindingBuilder, AnyOpaque { let anyActual: Any - fileprivate let _makeBinding: (AnyTypeDescriptor) -> Binding + fileprivate let _makeBinding: (BindingProperties) -> Binding - public func makeBinding(for descriptor: AnyTypeDescriptor) -> Binding { - return _makeBinding(descriptor) + public func makeBinding(with properties: BindingProperties) -> Binding { + return _makeBinding(properties) } } public extension BindingBuilder { var opaque: SomeBindingBuilder { - return SomeBindingBuilder(anyActual: self) { self.makeBinding(for: $0) } + return SomeBindingBuilder(anyActual: self) { self.makeBinding(with: $0) } } } diff --git a/Sources/Core/ScopedBinding.swift b/Sources/Core/ScopedBinding.swift index b601e86d..3516ab0a 100644 --- a/Sources/Core/ScopedBinding.swift +++ b/Sources/Core/ScopedBinding.swift @@ -4,6 +4,7 @@ struct ScopedBinding { let key: BindingKey + let properties: BindingProperties let builder: AnyInstanceBuilder let scope: AnyScope let makeRef: ReferenceMaker @@ -57,9 +58,10 @@ extension ScopedBinding.Builder: InstanceBuilder { extension ScopedBinding.Builder: BindingBuilder { typealias BoundType = Type - func makeBinding(for descriptor: AnyTypeDescriptor) -> Binding { + func makeBinding(with properties: BindingProperties) -> Binding { return ScopedBinding( - key: BindingKey(descriptor: descriptor, contextType: Context.self, argumentType: Argument.self), + key: BindingKey(descriptor: properties.descriptor, contextType: Context.self, argumentType: Argument.self), + properties: properties, builder: self, scope: scope, makeRef: makeRef diff --git a/Sources/Core/SimpleBinding.swift b/Sources/Core/SimpleBinding.swift index 009a6952..dde2c0eb 100644 --- a/Sources/Core/SimpleBinding.swift +++ b/Sources/Core/SimpleBinding.swift @@ -4,6 +4,7 @@ struct SimpleBinding { let key: BindingKey + let properties: BindingProperties let builder: AnyInstanceBuilder } @@ -38,9 +39,10 @@ extension SimpleBinding.Builder: InstanceBuilder { extension SimpleBinding.Builder: BindingBuilder { typealias BoundType = Type - func makeBinding(for descriptor: AnyTypeDescriptor) -> Binding { + func makeBinding(with properties: BindingProperties) -> Binding { return SimpleBinding( - key: BindingKey(descriptor: descriptor, contextType: Context.self, argumentType: Argument.self), + key: BindingKey(descriptor: properties.descriptor, contextType: Context.self, argumentType: Argument.self), + properties: properties, builder: self ) } diff --git a/Sources/Core/Swinject.swift b/Sources/Core/Swinject.swift index 54d2a4ff..8a79b7dd 100644 --- a/Sources/Core/Swinject.swift +++ b/Sources/Core/Swinject.swift @@ -4,15 +4,21 @@ public struct Swinject { let tree: SwinjectTree + let container: Container let context: Any let contextType: Any.Type init(tree: SwinjectTree) { - self.init(tree: tree, context: ()) + self.init( + tree: tree, + container: .makeContainer(with: tree), + context: () + ) } - init(tree: SwinjectTree, context: Context) { + private init(tree: SwinjectTree, container: Swinject.Container, context: Context) { self.tree = tree + self.container = container self.context = context contextType = Context.self } @@ -20,7 +26,7 @@ public struct Swinject { extension Swinject { public func on(_ context: Context) -> Swinject { - return Swinject(tree: tree, context: context) + return Swinject(tree: tree, container: container, context: context) } } @@ -44,14 +50,14 @@ extension Swinject: Resolver { } private func findTranslator(for request: AnyInstanceRequest, and binding: Binding) throws -> AnyContextTranslator { - return try (tree.translators + [IdentityTranslator(for: contextType)]) + return try (container.translators + [IdentityTranslator(for: contextType)]) .filter { $0.sourceType == contextType } .filter { binding.matches(request.key(forContextType: $0.targetType)) } .first ?? { throw SwinjectError() }() } private func findBinding(for request: AnyInstanceRequest) throws -> Binding { - let bindings = tree.allBindings.filter { (try? findTranslator(for: request, and: $0)) != nil } + let bindings = container.bindings.filter { (try? findTranslator(for: request, and: $0)) != nil } if bindings.isEmpty { throw NoBindingError() } if bindings.count > 1 { throw MultipleBindingsError() } return bindings[0] diff --git a/Sources/Core/SwinjectContainer.swift b/Sources/Core/SwinjectContainer.swift new file mode 100644 index 00000000..ad8449a2 --- /dev/null +++ b/Sources/Core/SwinjectContainer.swift @@ -0,0 +1,37 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +extension Swinject { + struct Container { + let bindings: [Binding] + let translators: [AnyContextTranslator] + } +} + +extension Swinject.Container { + static func makeContainer(with tree: SwinjectTree) -> Swinject.Container { + let allModuleNames = makeModules(with: tree).map { $0.name } + assert(allModuleNames.count == Set(allModuleNames).count) + + let allBindings = makeBindings(with: tree) + .reduce(into: [BindingKey: Binding]()) { dict, binding in + assert((dict[binding.key] == nil) != binding.properties.overrides) + dict[binding.key] = binding + } + .map { $0.value } + + return .init( + bindings: allBindings, + translators: tree.translators + ) + } + + static func makeModules(with tree: SwinjectTree) -> [Swinject.Module] { + return tree.modules + tree.modules.flatMap { makeModules(with: $0.tree) } + } + + static func makeBindings(with tree: SwinjectTree) -> [Binding] { + return tree.bindings + tree.modules.flatMap { makeBindings(with: $0.tree) } + } +} diff --git a/Sources/Core/SwinjectTree.swift b/Sources/Core/SwinjectTree.swift index 6152aefa..613ed855 100644 --- a/Sources/Core/SwinjectTree.swift +++ b/Sources/Core/SwinjectTree.swift @@ -8,24 +8,6 @@ public struct SwinjectTree { let translators: [AnyContextTranslator] } -extension SwinjectTree { - var allBindings: [Binding] { - return bindings + modules.flatMap { $0.tree.allBindings } - } - - var allModules: [Swinject.Module] { - return modules + modules.flatMap { $0.tree.allModules } - } -} - -extension SwinjectTree { - func assertValid() { - let allModuleNames = allModules.map { $0.name } - assert(allModuleNames.count == Set(allModuleNames).count) - assert(allBindings.count == Set(allBindings.map { $0.key }).count) - } -} - #if swift(>=5.1) @_functionBuilder public enum SwinjectTreeBuilder {} @@ -57,13 +39,11 @@ extension SwinjectTreeBuilder { // This is not used by compiler implicitly yet public static func buildFunction(_ input: [SwinjectEntry]) -> SwinjectTree { let entries = input.flatMap(unpack) - let tree = SwinjectTree( + return SwinjectTree( bindings: entries.compactMap { $0 as? Binding }, modules: entries.compactMap { $0 as? Swinject.Module }, translators: entries.compactMap { $0 as? AnyContextTranslator } ) - tree.assertValid() - return tree } } diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 2cd6cebb..008a12e8 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -265,6 +265,10 @@ CD03917522EF610800DE44C4 /* OverrideSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD03917322EF610800DE44C4 /* OverrideSpec.swift */; }; CD03917622EF610800DE44C4 /* OverrideSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD03917322EF610800DE44C4 /* OverrideSpec.swift */; }; CD03917722EF610800DE44C4 /* OverrideSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD03917322EF610800DE44C4 /* OverrideSpec.swift */; }; + CD367C0E22EF8A83008B3E82 /* SwinjectContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD367C0D22EF8A83008B3E82 /* SwinjectContainer.swift */; }; + CD367C0F22EF8A83008B3E82 /* SwinjectContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD367C0D22EF8A83008B3E82 /* SwinjectContainer.swift */; }; + CD367C1022EF8A83008B3E82 /* SwinjectContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD367C0D22EF8A83008B3E82 /* SwinjectContainer.swift */; }; + CD367C1122EF8A83008B3E82 /* SwinjectContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD367C0D22EF8A83008B3E82 /* SwinjectContainer.swift */; }; CE5AFED22F04B96713ED76D7 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ADC44E9312C3B974AFD8F07B /* Nimble.framework */; }; CECF5BD14BCDF5248771A06A /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; CEE763218A90832454A6E2DE /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */; }; @@ -527,6 +531,7 @@ C765B92B00C0AC8625BB4AC9 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; CC85CB215058F95C0BC190B1 /* Bridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bridge.swift; sourceTree = ""; }; CD03917322EF610800DE44C4 /* OverrideSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OverrideSpec.swift; sourceTree = ""; }; + CD367C0D22EF8A83008B3E82 /* SwinjectContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectContainer.swift; sourceTree = ""; }; CDA78290D6D60BD0B808571F /* Container+Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Logging.swift"; sourceTree = ""; }; CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextSpec.swift; sourceTree = ""; }; @@ -830,6 +835,7 @@ 9620155728133F451B31C0AD /* Swinject.swift */, A3586A4987B7C7C8122D674E /* SwinjectError.swift */, C1E726A651C3AFE92C19608B /* SwinjectModule.swift */, + CD367C0D22EF8A83008B3E82 /* SwinjectContainer.swift */, 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */, E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */, ); @@ -1400,6 +1406,7 @@ B9550BE2BA6FA5731BEC87FD /* Swinject+Builder.swift in Sources */, 33391EBA040E82DFB0A37015 /* Swinject.swift in Sources */, 020DA1718FCC68D889FB5A5F /* SwinjectError.swift in Sources */, + CD367C0F22EF8A83008B3E82 /* SwinjectContainer.swift in Sources */, CF4EBB60C21F8C503BCD7A29 /* SwinjectModule.swift in Sources */, 0D5C4A278A16AB3A163148AF /* SwinjectTree.swift in Sources */, AB864E029E996492ED4A3A52 /* TypeBinder.swift in Sources */, @@ -1615,6 +1622,7 @@ EFD2F695B86E74C77F46B7D1 /* Swinject+Builder.swift in Sources */, 63528D45A548DD58D748D54C /* Swinject.swift in Sources */, 91E435894038C42335086FA8 /* SwinjectError.swift in Sources */, + CD367C1022EF8A83008B3E82 /* SwinjectContainer.swift in Sources */, C637E97E193BB1DADDDC6C21 /* SwinjectModule.swift in Sources */, 0CE1126436F680F9684837E4 /* SwinjectTree.swift in Sources */, 4B9811CF0604946CCF323ED2 /* TypeBinder.swift in Sources */, @@ -1656,6 +1664,7 @@ DCB7C4BF24782862BE9DB135 /* Swinject+Builder.swift in Sources */, 75D74C8C25EDACF5A7A75A5C /* Swinject.swift in Sources */, 4DF3DC1CDD3C4948F9BDD3DF /* SwinjectError.swift in Sources */, + CD367C1122EF8A83008B3E82 /* SwinjectContainer.swift in Sources */, 82299769BC637A14E7827DB0 /* SwinjectModule.swift in Sources */, 372F0061E762BF8FFF05457F /* SwinjectTree.swift in Sources */, 9425887520AC2DBDCBACB252 /* TypeBinder.swift in Sources */, @@ -1697,6 +1706,7 @@ 6C01E868DE44BD396D94858B /* Swinject+Builder.swift in Sources */, 4EC94A51037C79DE0C5C8CB1 /* Swinject.swift in Sources */, 820307073A53AED47AC99B8D /* SwinjectError.swift in Sources */, + CD367C0E22EF8A83008B3E82 /* SwinjectContainer.swift in Sources */, 8E77B56EE7F90BF723600DDF /* SwinjectModule.swift in Sources */, 6922AE734E84B515C94D9480 /* SwinjectTree.swift in Sources */, EF79F0B3D497215D4BBBC038 /* TypeBinder.swift in Sources */, diff --git a/Tests/3.0 API/OverrideSpec.swift b/Tests/3.0 API/OverrideSpec.swift index 5832d0d9..9cebf561 100644 --- a/Tests/3.0 API/OverrideSpec.swift +++ b/Tests/3.0 API/OverrideSpec.swift @@ -34,5 +34,35 @@ class OverrideSpec: QuickSpec { override func spec() { #if swift(>=5.1) } }.ifDebugTo(throwAssertion()) } + it("can declare that binding overrides previous binding for the same type") { + let swinject = Swinject { + bbind(Int.self) & 0 + bbind(Int.self, overrides: true) & 42 + } + expect { try swinject.instance(of: Int.self) } == 42 + } + it("uses the last overriding binding for the injection") { + let swinject = Swinject { + bbind(Int.self) & 1 + bbind(Int.self, overrides: true) & 2 + bbind(Int.self, overrides: true) & 42 + } + expect { try swinject.instance(of: Int.self) } == 42 + } + it("must declare overriding binding after the overriden one") { + expect { + _ = Swinject { + bbind(Int.self, overrides: true) & 42 + bbind(Int.self) & 0 + } + }.ifDebugTo(throwAssertion()) + } + it("does not allow overriding binding if there is nothing to override") { + expect { + _ = Swinject { + bbind(Int.self, overrides: true) & 42 + } + }.ifDebugTo(throwAssertion()) + } #endif } } diff --git a/Tests/Support/Bridge.swift b/Tests/Support/Bridge.swift index 964a0669..d9ef5164 100644 --- a/Tests/Support/Bridge.swift +++ b/Tests/Support/Bridge.swift @@ -8,10 +8,17 @@ import struct Swinject.TypeBinder import protocol Swinject.TypeDescriptor // Original Swinject functions conflict with QuickSpec's instance methods -func bbind(_: Type.Type) -> TypeBinder> { - return bind(Type.self) +func bbind( + _: Type.Type, + overrides: Bool = false +) -> TypeBinder { + return bind(Type.self, overrides: overrides) } -func bbind(_: Type.Type, tagged tag: Tag) -> TypeBinder> where Tag: Hashable { - return bind(Type.self, tagged: tag) +func bbind( + _: Type.Type, + tagged tag: Tag, + overrides: Bool = false +) -> TypeBinder where Tag: Hashable { + return bind(Type.self, tagged: tag, overrides: overrides) } From a5d9e9bb1e7d3906710843dc8f68b86576e2563c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Mon, 29 Jul 2019 23:46:32 +0200 Subject: [PATCH 170/239] Define rules for overriding in modules --- Sources/2.0 API/Container.swift | 13 +-- Sources/3.0 API/Swinject+Builder.swift | 60 ++++++++++---- Sources/Core/Swinject.swift | 4 +- Sources/Core/SwinjectContainer.swift | 42 ++++++++-- Sources/Core/SwinjectModule.swift | 16 +++- Sources/Core/SwinjectTree.swift | 4 +- Tests/3.0 API/OverrideSpec.swift | 80 +++++++++++++++++++ .../Unit Specs/SwinjectTreeBuilderSpec.swift | 4 +- 8 files changed, 185 insertions(+), 38 deletions(-) diff --git a/Sources/2.0 API/Container.swift b/Sources/2.0 API/Container.swift index 19376902..4b03b3d2 100644 --- a/Sources/2.0 API/Container.swift +++ b/Sources/2.0 API/Container.swift @@ -29,11 +29,14 @@ public final class Container { let defaultObjectScope: ObjectScope var bindings = [Binding & CustomStringConvertible]() var behaviors = [Behavior]() - var swinject: Swinject { return Swinject(tree: SwinjectTree( - bindings: allBindings, - modules: [], - translators: [registerContextTranslator(from: Graph.self) { $0.container }] - )) } + var swinject: Swinject { return Swinject( + tree: SwinjectTree( + bindings: allBindings, + modules: [], + translators: [registerContextTranslator(from: Graph.self) { $0.container }] + ), + allowsSilentOverride: true + ) } var allBindings: [Binding] { return bindings + (parent?.allBindings ?? []) } diff --git a/Sources/3.0 API/Swinject+Builder.swift b/Sources/3.0 API/Swinject+Builder.swift index c9ec47e2..21d483da 100644 --- a/Sources/3.0 API/Swinject+Builder.swift +++ b/Sources/3.0 API/Swinject+Builder.swift @@ -3,43 +3,71 @@ // public extension Swinject { - init(_ entries: SwinjectEntry ...) { - self.init(tree: SwinjectTreeBuilder.buildFunction(entries)) + init(allowsSilentOverride: Bool = false, _ entries: SwinjectEntry ...) { + self.init( + tree: SwinjectTreeBuilder.buildFunction(entries), + allowsSilentOverride: allowsSilentOverride + ) } } public extension Swinject { #if swift(>=5.1) - init(@SwinjectTreeBuilder builder: () -> [SwinjectEntry]) { - self.init(tree: SwinjectTreeBuilder.buildFunction(builder())) + init(allowsSilentOverride: Bool = false, @SwinjectTreeBuilder builder: () -> [SwinjectEntry]) { + self.init( + tree: SwinjectTreeBuilder.buildFunction(builder()), + allowsSilentOverride: allowsSilentOverride + ) } - init(@SwinjectTreeBuilder builder: () -> SwinjectEntry) { - self.init(tree: SwinjectTreeBuilder.buildFunction([builder()])) + init(allowsSilentOverride: Bool = false, @SwinjectTreeBuilder builder: () -> SwinjectEntry) { + self.init( + tree: SwinjectTreeBuilder.buildFunction([builder()]), + allowsSilentOverride: allowsSilentOverride + ) } - init(@SwinjectTreeBuilder _: () -> Void) { - self.init(tree: SwinjectTreeBuilder.buildFunction([])) + init(allowsSilentOverride: Bool = false, @SwinjectTreeBuilder _: () -> Void) { + self.init( + tree: SwinjectTreeBuilder.buildFunction([]), + allowsSilentOverride: allowsSilentOverride + ) } #endif } public extension Swinject.Module { - init(_ name: String, _ entries: SwinjectEntry ...) { - self.init(name: name, tree: SwinjectTreeBuilder.buildFunction(entries)) + init(_ name: String, allowsSilentOverride: Bool = false, _ entries: SwinjectEntry ...) { + self.init( + name: name, + tree: SwinjectTreeBuilder.buildFunction(entries), + allowsSilentOverride: allowsSilentOverride + ) } } public extension Swinject.Module { #if swift(>=5.1) - init(_ name: String, @SwinjectTreeBuilder builder: () -> [SwinjectEntry]) { - self.init(name: name, tree: SwinjectTreeBuilder.buildFunction(builder())) + init(_ name: String, allowsSilentOverride: Bool = false, @SwinjectTreeBuilder builder: () -> [SwinjectEntry]) { + self.init( + name: name, + tree: SwinjectTreeBuilder.buildFunction(builder()), + allowsSilentOverride: allowsSilentOverride + ) } - init(_ name: String, @SwinjectTreeBuilder builder: () -> SwinjectEntry) { - self.init(name: name, tree: SwinjectTreeBuilder.buildFunction([builder()])) + init(_ name: String, allowsSilentOverride: Bool = false, @SwinjectTreeBuilder builder: () -> SwinjectEntry) { + self.init( + name: name, + tree: SwinjectTreeBuilder.buildFunction([builder()]), + allowsSilentOverride: allowsSilentOverride + ) } - init(_ name: String, @SwinjectTreeBuilder _: () -> Void) { - self.init(name: name, tree: SwinjectTreeBuilder.buildFunction([])) + init(_ name: String, allowsSilentOverride: Bool = false, @SwinjectTreeBuilder _: () -> Void) { + self.init( + name: name, + tree: SwinjectTreeBuilder.buildFunction([]), + allowsSilentOverride: allowsSilentOverride + ) } #endif } diff --git a/Sources/Core/Swinject.swift b/Sources/Core/Swinject.swift index 8a79b7dd..74825574 100644 --- a/Sources/Core/Swinject.swift +++ b/Sources/Core/Swinject.swift @@ -8,10 +8,10 @@ public struct Swinject { let context: Any let contextType: Any.Type - init(tree: SwinjectTree) { + init(tree: SwinjectTree, allowsSilentOverride: Bool) { self.init( tree: tree, - container: .makeContainer(with: tree), + container: .makeContainer(with: tree, allowsSilentOverride), context: () ) } diff --git a/Sources/Core/SwinjectContainer.swift b/Sources/Core/SwinjectContainer.swift index ad8449a2..d89fe90a 100644 --- a/Sources/Core/SwinjectContainer.swift +++ b/Sources/Core/SwinjectContainer.swift @@ -10,14 +10,24 @@ extension Swinject { } extension Swinject.Container { - static func makeContainer(with tree: SwinjectTree) -> Swinject.Container { + struct BindingEntry { + let binding: Binding + let key: BindingKey + let properties: BindingProperties + let canOverride: Bool + let canOverrideSilently: Bool + } + + // TODO: Create throwing version for testing convenience + static func makeContainer(with tree: SwinjectTree, _ allowsSilentOverride: Bool) -> Swinject.Container { let allModuleNames = makeModules(with: tree).map { $0.name } assert(allModuleNames.count == Set(allModuleNames).count) - let allBindings = makeBindings(with: tree) - .reduce(into: [BindingKey: Binding]()) { dict, binding in - assert((dict[binding.key] == nil) != binding.properties.overrides) - dict[binding.key] = binding + let allBindings = makeBindings(with: tree, canOverrideSilently: allowsSilentOverride) + .reduce(into: [BindingKey: Binding]()) { dict, entry in + assert(entry.canOverride || !entry.properties.overrides) + assert((dict[entry.key] == nil) != entry.properties.overrides || entry.canOverrideSilently) + dict[entry.key] = entry.binding } .map { $0.value } @@ -28,10 +38,26 @@ extension Swinject.Container { } static func makeModules(with tree: SwinjectTree) -> [Swinject.Module] { - return tree.modules + tree.modules.flatMap { makeModules(with: $0.tree) } + return tree.modules.map { $0.module } + tree.modules.flatMap { makeModules(with: $0.module.tree) } } - static func makeBindings(with tree: SwinjectTree) -> [Binding] { - return tree.bindings + tree.modules.flatMap { makeBindings(with: $0.tree) } + static func makeBindings( + with tree: SwinjectTree, + canOverride: Bool? = nil, + canOverrideSilently: Bool + ) -> [BindingEntry] { + return tree.bindings + .map { BindingEntry( + binding: $0, + key: $0.key, + properties: $0.properties, + canOverride: canOverride ?? true, + canOverrideSilently: canOverrideSilently + ) } + + tree.modules.flatMap { makeBindings( + with: $0.module.tree, + canOverride: canOverride ?? $0.canOverride, + canOverrideSilently: $0.module.allowsSilentOverride + ) } } } diff --git a/Sources/Core/SwinjectModule.swift b/Sources/Core/SwinjectModule.swift index 3bf7ff9c..644b1f60 100644 --- a/Sources/Core/SwinjectModule.swift +++ b/Sources/Core/SwinjectModule.swift @@ -3,12 +3,22 @@ // extension Swinject { - public struct Module: SwinjectEntry { + public struct Module { let name: String let tree: SwinjectTree + let allowsSilentOverride: Bool } } -public func include(_ module: Swinject.Module) -> Swinject.Module { - return module +public struct ModuleInclusion: SwinjectEntry { + let module: Swinject.Module + let canOverride: Bool +} + +// TODO: This should only be allowed on top level +public func include(_ module: Swinject.Module, allowToOverride: Bool = false) -> ModuleInclusion { + return ModuleInclusion( + module: module, + canOverride: allowToOverride || module.allowsSilentOverride + ) } diff --git a/Sources/Core/SwinjectTree.swift b/Sources/Core/SwinjectTree.swift index 613ed855..240f0961 100644 --- a/Sources/Core/SwinjectTree.swift +++ b/Sources/Core/SwinjectTree.swift @@ -4,7 +4,7 @@ public struct SwinjectTree { let bindings: [Binding] - let modules: [Swinject.Module] + let modules: [ModuleInclusion] let translators: [AnyContextTranslator] } @@ -41,7 +41,7 @@ extension SwinjectTreeBuilder { let entries = input.flatMap(unpack) return SwinjectTree( bindings: entries.compactMap { $0 as? Binding }, - modules: entries.compactMap { $0 as? Swinject.Module }, + modules: entries.compactMap { $0 as? ModuleInclusion }, translators: entries.compactMap { $0 as? AnyContextTranslator } ) } diff --git a/Tests/3.0 API/OverrideSpec.swift b/Tests/3.0 API/OverrideSpec.swift index 9cebf561..d420edd1 100644 --- a/Tests/3.0 API/OverrideSpec.swift +++ b/Tests/3.0 API/OverrideSpec.swift @@ -64,5 +64,85 @@ class OverrideSpec: QuickSpec { override func spec() { #if swift(>=5.1) } }.ifDebugTo(throwAssertion()) } + it("does not allow overriding bindings in modules by default") { + let firstModule = Swinject.Module("first") { + bbind(Int.self) & 0 + } + let secondModule = Swinject.Module("second") { + bbind(Int.self, overrides: true) & 42 + } + expect { + _ = Swinject { + include(firstModule) + include(secondModule) + } + }.ifDebugTo(throwAssertion()) + } + it("can allow module to have overriding bindings when including it") { + let firstModule = Swinject.Module("first") { + bbind(Int.self) & 0 + } + let secondModule = Swinject.Module("second") { + bbind(Int.self, overrides: true) & 42 + } + let swinject = Swinject { + include(firstModule) + include(secondModule, allowToOverride: true) + } + expect { try swinject.instance(of: Int.self) } == 42 + } + it("allows overriding bindings in the entire included module tree") { + let firstModule = Swinject.Module("first") { + bbind(Int.self) & 0 + } + let secondModule = Swinject.Module("second") { + bbind(Int.self, overrides: true) & 42 + } + let thirdModule = Swinject.Module("third") { + include(secondModule) + } + let swinject = Swinject { + include(firstModule) + include(thirdModule, allowToOverride: true) + } + expect { try swinject.instance(of: Int.self) } == 42 + } + it("can allow silent overrides in a module") { + let firstModule = Swinject.Module("first") { + bbind(Int.self) & 0 + } + let secondModule = Swinject.Module("second", allowsSilentOverride: true) { + bbind(Int.self) & 42 + } + let swinject = Swinject { + include(firstModule) + include(secondModule) + } + expect { try swinject.instance(of: Int.self) } == 42 + } + it("does not apply silent override transitively") { + let firstModule = Swinject.Module("first") { + bbind(Int.self) & 0 + } + let secondModule = Swinject.Module("second") { + bbind(Int.self) & 42 + } + let thirdModule = Swinject.Module("third", allowsSilentOverride: true) { + include(secondModule) + } + expect { + _ = Swinject { + include(firstModule) + include(thirdModule) + } + }.ifDebugTo(throwAssertion()) + } + it("can allow silent override on the Swinject declaration") { + let swinject = Swinject(allowsSilentOverride: true) { + bbind(Int.self) & 0 + bbind(Int.self) & 42 + } + expect { try swinject.instance(of: Int.self) } == 42 + } #endif } } diff --git a/Tests/Unit Specs/SwinjectTreeBuilderSpec.swift b/Tests/Unit Specs/SwinjectTreeBuilderSpec.swift index bc858d69..a3abfacf 100644 --- a/Tests/Unit Specs/SwinjectTreeBuilderSpec.swift +++ b/Tests/Unit Specs/SwinjectTreeBuilderSpec.swift @@ -52,8 +52,8 @@ class SwinjectTreeBuilderSpec: QuickSpec { override func spec() { #if swift(>=5. } it("builds closure with maker & include entries") { let tree = makeTree { - Swinject.Module("1") - Swinject.Module("2") + include(Swinject.Module("1")) + include(Swinject.Module("2")) bbind(Int.self).with(42) bbind(UInt.self).with(42) bbind(Float.self).with(42) From 9c50ce55279a5fefd88e53cbf0da78b003557c10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Mon, 29 Jul 2019 23:48:49 +0200 Subject: [PATCH 171/239] Add test for legacy behavior on duplicit registrations --- Sources/Core/SwinjectContainer.swift | 1 + Sources/Core/SwinjectModule.swift | 2 +- Tests/2.0 API/ContainerSpec.swift | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Sources/Core/SwinjectContainer.swift b/Sources/Core/SwinjectContainer.swift index d89fe90a..6ee27d04 100644 --- a/Sources/Core/SwinjectContainer.swift +++ b/Sources/Core/SwinjectContainer.swift @@ -19,6 +19,7 @@ extension Swinject.Container { } // TODO: Create throwing version for testing convenience + // TODO: Cleanup implementation static func makeContainer(with tree: SwinjectTree, _ allowsSilentOverride: Bool) -> Swinject.Container { let allModuleNames = makeModules(with: tree).map { $0.name } assert(allModuleNames.count == Set(allModuleNames).count) diff --git a/Sources/Core/SwinjectModule.swift b/Sources/Core/SwinjectModule.swift index 644b1f60..2c1b36c9 100644 --- a/Sources/Core/SwinjectModule.swift +++ b/Sources/Core/SwinjectModule.swift @@ -15,7 +15,7 @@ public struct ModuleInclusion: SwinjectEntry { let canOverride: Bool } -// TODO: This should only be allowed on top level +// TODO: `allowToOverride` should only be allowed on top level include public func include(_ module: Swinject.Module, allowToOverride: Bool = false) -> ModuleInclusion { return ModuleInclusion( module: module, diff --git a/Tests/2.0 API/ContainerSpec.swift b/Tests/2.0 API/ContainerSpec.swift index 44ccee83..2b6fd5bb 100644 --- a/Tests/2.0 API/ContainerSpec.swift +++ b/Tests/2.0 API/ContainerSpec.swift @@ -45,6 +45,12 @@ class ContainerSpec: QuickSpec { expect(mew?.name) == "Mew" expect(noname?.name).to(beNil()) } + it("resolves the last one registered") { + container.register(Animal.self) { _ in Cat(name: "Mimi") } + container.register(Animal.self) { _ in Cat(name: "Mew") } + let cat = container.resolve(Animal.self) as? Cat + expect(cat?.name) == "Mew" + } } describe("Removal of registered services") { it("can remove all registered services.") { From c101b4048d9c80d3eef46baacbc96b6bd600506e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Tue, 30 Jul 2019 20:32:56 +0200 Subject: [PATCH 172/239] Refactor swinject container builder --- Sources/Core/Swinject.swift | 14 ++--- Sources/Core/SwinjectContainer.swift | 79 +++++++++++++++++++--------- Sources/Core/SwinjectError.swift | 8 ++- Tests/3.0 API/ModulesSpec.swift | 4 +- Tests/3.0 API/OverrideSpec.swift | 14 ++--- Tests/Support/Convenience.swift | 10 ---- 6 files changed, 76 insertions(+), 53 deletions(-) diff --git a/Sources/Core/Swinject.swift b/Sources/Core/Swinject.swift index 74825574..05cc8aac 100644 --- a/Sources/Core/Swinject.swift +++ b/Sources/Core/Swinject.swift @@ -4,19 +4,21 @@ public struct Swinject { let tree: SwinjectTree - let container: Container + let container: SwinjectContainer let context: Any let contextType: Any.Type init(tree: SwinjectTree, allowsSilentOverride: Bool) { self.init( tree: tree, - container: .makeContainer(with: tree, allowsSilentOverride), + container: SwinjectContainer + .Builder(tree: tree, allowsSilentOverride: allowsSilentOverride) + .makeContainer(), context: () ) } - private init(tree: SwinjectTree, container: Swinject.Container, context: Context) { + private init(tree: SwinjectTree, container: SwinjectContainer, context: Context) { self.tree = tree self.container = container self.context = context @@ -38,7 +40,7 @@ extension Swinject: Resolver { // FIXME: Refactor this do { binding = try findBinding(for: request) - } catch let error as NoBindingError { + } catch let error as NoBinding { if let optional = Descriptor.BaseType.self as? OptionalProtocol.Type { return optional.init() as! Descriptor.BaseType } else { @@ -58,8 +60,8 @@ extension Swinject: Resolver { private func findBinding(for request: AnyInstanceRequest) throws -> Binding { let bindings = container.bindings.filter { (try? findTranslator(for: request, and: $0)) != nil } - if bindings.isEmpty { throw NoBindingError() } - if bindings.count > 1 { throw MultipleBindingsError() } + if bindings.isEmpty { throw NoBinding() } + if bindings.count > 1 { throw MultipleBindings() } return bindings[0] } diff --git a/Sources/Core/SwinjectContainer.swift b/Sources/Core/SwinjectContainer.swift index 6ee27d04..4b7cd162 100644 --- a/Sources/Core/SwinjectContainer.swift +++ b/Sources/Core/SwinjectContainer.swift @@ -2,15 +2,43 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -extension Swinject { - struct Container { - let bindings: [Binding] - let translators: [AnyContextTranslator] +struct SwinjectContainer { + let bindings: [Binding] + let translators: [AnyContextTranslator] + + struct Builder { + let tree: SwinjectTree + let allowsSilentOverride: Bool + } +} + +extension SwinjectContainer.Builder { + func makeContainer() -> SwinjectContainer { + do { return try makeContainerOrThrow() } catch { fatalError("\(error)") } + } + + private func makeContainerOrThrow() throws -> SwinjectContainer { + try checkDuplicitModules() + return try SwinjectContainer( + bindings: collectBindings(), + translators: tree.translators + ) + } +} + +extension SwinjectContainer.Builder { + private func checkDuplicitModules() throws { + let names = collectModules(from: tree).map { $0.name } + if names.containsDuplicates { throw DuplicateModules() } + } + + private func collectModules(from tree: SwinjectTree) -> [Swinject.Module] { + return tree.modules.map { $0.module } + tree.modules.flatMap { collectModules(from: $0.module.tree) } } } -extension Swinject.Container { - struct BindingEntry { +extension SwinjectContainer.Builder { + private struct BindingEntry { let binding: Binding let key: BindingKey let properties: BindingProperties @@ -18,32 +46,25 @@ extension Swinject.Container { let canOverrideSilently: Bool } - // TODO: Create throwing version for testing convenience - // TODO: Cleanup implementation - static func makeContainer(with tree: SwinjectTree, _ allowsSilentOverride: Bool) -> Swinject.Container { - let allModuleNames = makeModules(with: tree).map { $0.name } - assert(allModuleNames.count == Set(allModuleNames).count) - - let allBindings = makeBindings(with: tree, canOverrideSilently: allowsSilentOverride) + private func collectBindings() throws -> [Binding] { + return try collectBindingEntries(from: tree, canOverrideSilently: allowsSilentOverride) .reduce(into: [BindingKey: Binding]()) { dict, entry in - assert(entry.canOverride || !entry.properties.overrides) - assert((dict[entry.key] == nil) != entry.properties.overrides || entry.canOverrideSilently) + try checkOverrideRules(for: entry, beingAddedTo: dict) dict[entry.key] = entry.binding } .map { $0.value } - - return .init( - bindings: allBindings, - translators: tree.translators - ) } - static func makeModules(with tree: SwinjectTree) -> [Swinject.Module] { - return tree.modules.map { $0.module } + tree.modules.flatMap { makeModules(with: $0.module.tree) } + private func checkOverrideRules(for entry: BindingEntry, beingAddedTo dict: [BindingKey: Binding]) throws { + if entry.properties.overrides, !entry.canOverride { throw OverrideNotAllowed() } + if !entry.canOverrideSilently { + if dict[entry.key] == nil, entry.properties.overrides { throw NothingToOverride() } + if dict[entry.key] != nil, !entry.properties.overrides { throw SilentOverrideNotAllowed() } + } } - static func makeBindings( - with tree: SwinjectTree, + private func collectBindingEntries( + from tree: SwinjectTree, canOverride: Bool? = nil, canOverrideSilently: Bool ) -> [BindingEntry] { @@ -55,10 +76,16 @@ extension Swinject.Container { canOverride: canOverride ?? true, canOverrideSilently: canOverrideSilently ) } - + tree.modules.flatMap { makeBindings( - with: $0.module.tree, + + tree.modules.flatMap { collectBindingEntries( + from: $0.module.tree, canOverride: canOverride ?? $0.canOverride, canOverrideSilently: $0.module.allowsSilentOverride ) } } } + +private extension Array where Element: Hashable { + var containsDuplicates: Bool { + return count != Set(self).count + } +} diff --git a/Sources/Core/SwinjectError.swift b/Sources/Core/SwinjectError.swift index 45adbe87..51a87d2d 100644 --- a/Sources/Core/SwinjectError.swift +++ b/Sources/Core/SwinjectError.swift @@ -12,7 +12,11 @@ public class SwinjectError: Error { } } -public class NoBindingError: SwinjectError {} -public class MultipleBindingsError: SwinjectError {} +public class NoBinding: SwinjectError {} +public class MultipleBindings: SwinjectError {} +public class DuplicateModules: SwinjectError {} +public class OverrideNotAllowed: SwinjectError {} +public class NothingToOverride: SwinjectError {} +public class SilentOverrideNotAllowed: SwinjectError {} // TODO: Debugging error description diff --git a/Tests/3.0 API/ModulesSpec.swift b/Tests/3.0 API/ModulesSpec.swift index e2c7d9c5..e5dbceb1 100644 --- a/Tests/3.0 API/ModulesSpec.swift +++ b/Tests/3.0 API/ModulesSpec.swift @@ -43,7 +43,7 @@ class ModulesSpec: QuickSpec { override func spec() { #if swift(>=5.1) include(firstModule) include(secondModule) } - }.ifDebugTo(throwAssertion()) + }.to(throwAssertion()) } it("fails if module is included multiple times") { let firstModule = Swinject.Module("first") @@ -58,7 +58,7 @@ class ModulesSpec: QuickSpec { override func spec() { #if swift(>=5.1) include(secondModule) include(thirdModule) } - }.ifDebugTo(throwAssertion()) + }.to(throwAssertion()) } #endif } } diff --git a/Tests/3.0 API/OverrideSpec.swift b/Tests/3.0 API/OverrideSpec.swift index d420edd1..1271cfa8 100644 --- a/Tests/3.0 API/OverrideSpec.swift +++ b/Tests/3.0 API/OverrideSpec.swift @@ -13,7 +13,7 @@ class OverrideSpec: QuickSpec { override func spec() { #if swift(>=5.1) bbind(Int.self) & 42 bbind(Int.self) & provider { 25 + 17 } } - }.ifDebugTo(throwAssertion()) + }.to(throwAssertion()) } it("does not allow bindings for type and it's optional") { expect { @@ -21,7 +21,7 @@ class OverrideSpec: QuickSpec { override func spec() { #if swift(>=5.1) bbind(Int?.self) & 42 bbind(Int.self) & provider { 25 + 17 } } - }.ifDebugTo(throwAssertion()) + }.to(throwAssertion()) } it("does not allow multiple bindings for the same type in a module hierarchy") { let firstModule = Swinject.Module("first") { @@ -32,7 +32,7 @@ class OverrideSpec: QuickSpec { override func spec() { #if swift(>=5.1) include(firstModule) bbind(Int.self) & provider { 25 + 17 } } - }.ifDebugTo(throwAssertion()) + }.to(throwAssertion()) } it("can declare that binding overrides previous binding for the same type") { let swinject = Swinject { @@ -55,14 +55,14 @@ class OverrideSpec: QuickSpec { override func spec() { #if swift(>=5.1) bbind(Int.self, overrides: true) & 42 bbind(Int.self) & 0 } - }.ifDebugTo(throwAssertion()) + }.to(throwAssertion()) } it("does not allow overriding binding if there is nothing to override") { expect { _ = Swinject { bbind(Int.self, overrides: true) & 42 } - }.ifDebugTo(throwAssertion()) + }.to(throwAssertion()) } it("does not allow overriding bindings in modules by default") { let firstModule = Swinject.Module("first") { @@ -76,7 +76,7 @@ class OverrideSpec: QuickSpec { override func spec() { #if swift(>=5.1) include(firstModule) include(secondModule) } - }.ifDebugTo(throwAssertion()) + }.to(throwAssertion()) } it("can allow module to have overriding bindings when including it") { let firstModule = Swinject.Module("first") { @@ -135,7 +135,7 @@ class OverrideSpec: QuickSpec { override func spec() { #if swift(>=5.1) include(firstModule) include(thirdModule) } - }.ifDebugTo(throwAssertion()) + }.to(throwAssertion()) } it("can allow silent override on the Swinject declaration") { let swinject = Swinject(allowsSilentOverride: true) { diff --git a/Tests/Support/Convenience.swift b/Tests/Support/Convenience.swift index a20645ee..87ec40f7 100644 --- a/Tests/Support/Convenience.swift +++ b/Tests/Support/Convenience.swift @@ -24,13 +24,3 @@ extension Matchable { return hasher.finalize() } } - -extension Expectation { - public func ifDebugTo(_ predicate: Predicate, description: String? = nil) { - #if DEBUG - to(predicate, description: description) - #else - toNot(predicate, description: description) - #endif - } -} From c09832877f0142fd936be80fbab358a0ac870c94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Tue, 30 Jul 2019 22:44:50 +0200 Subject: [PATCH 173/239] Release instances in container scope as soon as it is cleared --- Sources/2.0 API/Container+Registration.swift | 20 +++++++++---------- Sources/2.0 API/Container.swift | 10 +++------- Sources/2.0 API/ObjectScope.swift | 12 +++-------- Sources/2.0 API/ServiceEntry.swift | 12 +++++++++-- .../Container+Registration.swifttemplate | 4 ++-- Tests/2.0 API/ContainerSpec.swift | 11 ++++++++++ 6 files changed, 39 insertions(+), 30 deletions(-) diff --git a/Sources/2.0 API/Container+Registration.swift b/Sources/2.0 API/Container+Registration.swift index 37194232..8028726e 100644 --- a/Sources/2.0 API/Container+Registration.swift +++ b/Sources/2.0 API/Container+Registration.swift @@ -19,7 +19,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef(in: self)) { (r, _, _: Void) in factory(r) } + let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef) { (r, _, _: Void) in factory(r) } addEntry(entry, with: name) return entry } @@ -38,7 +38,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef(in: self)) { (r, _, a: Arg1) in factory(r, a) } + let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef) { (r, _, a: Arg1) in factory(r, a) } addEntry(entry, with: name) return entry } @@ -57,7 +57,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef(in: self)) { (r, _, a: (Arg1, Arg2)) in factory(r, a.0, a.1) } + let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef) { (r, _, a: (Arg1, Arg2)) in factory(r, a.0, a.1) } addEntry(entry, with: name) return entry } @@ -76,7 +76,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef(in: self)) { (r, _, a: (Arg1, Arg2, Arg3)) in factory(r, a.0, a.1, a.2) } + let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef) { (r, _, a: (Arg1, Arg2, Arg3)) in factory(r, a.0, a.1, a.2) } addEntry(entry, with: name) return entry } @@ -95,7 +95,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef(in: self)) { (r, _, a: (Arg1, Arg2, Arg3, Arg4)) in factory(r, a.0, a.1, a.2, a.3) } + let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef) { (r, _, a: (Arg1, Arg2, Arg3, Arg4)) in factory(r, a.0, a.1, a.2, a.3) } addEntry(entry, with: name) return entry } @@ -114,7 +114,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef(in: self)) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5)) in factory(r, a.0, a.1, a.2, a.3, a.4) } + let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5)) in factory(r, a.0, a.1, a.2, a.3, a.4) } addEntry(entry, with: name) return entry } @@ -133,7 +133,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef(in: self)) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5) } + let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5) } addEntry(entry, with: name) return entry } @@ -152,7 +152,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef(in: self)) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6) } + let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6) } addEntry(entry, with: name) return entry } @@ -171,7 +171,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef(in: self)) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6, a.7) } + let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6, a.7) } addEntry(entry, with: name) return entry } @@ -190,7 +190,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef(in: self)) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6, a.7, a.8) } + let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6, a.7, a.8) } addEntry(entry, with: name) return entry } diff --git a/Sources/2.0 API/Container.swift b/Sources/2.0 API/Container.swift index 4b03b3d2..498c6ed9 100644 --- a/Sources/2.0 API/Container.swift +++ b/Sources/2.0 API/Container.swift @@ -20,10 +20,7 @@ import Foundation /// where `A` and `X` are protocols, `B` is a type conforming `A`, and `Y` is a type conforming `X` /// and depending on `A`. public final class Container { - private class Handle {} - var referenceHandle: AnyObject = Handle() - - let registry: StandardScopeRegistry + let registry = StandardScopeRegistry() let parent: Container? // TODO: Enable arbitrary scope as default let defaultObjectScope: ObjectScope @@ -60,14 +57,13 @@ public final class Container { self.parent = parent self.defaultObjectScope = defaultObjectScope self.behaviors = behaviors - registry = parent?.registry ?? StandardScopeRegistry() registeringClosure(self) } /// Removes all registrations in the container. public func removeAll() { bindings = [] - referenceHandle = Handle() + registry.clear() } /// Discards instances for services registered in the given `ObjectsScopeProtocol`. @@ -79,7 +75,7 @@ public final class Container { /// - objectScope: All instances registered in given `ObjectsScopeProtocol` will be discarded. public func resetObjectScope(_ scope: ObjectScope) { switch scope { - case .container, .weak: referenceHandle = Handle() + case .container, .weak: registry.clear() case .graph, .transient: break } } diff --git a/Sources/2.0 API/ObjectScope.swift b/Sources/2.0 API/ObjectScope.swift index b8f5b188..4076d2a4 100644 --- a/Sources/2.0 API/ObjectScope.swift +++ b/Sources/2.0 API/ObjectScope.swift @@ -32,16 +32,10 @@ extension ObjectScope { } } - func makeRef(in container: Container?) -> ReferenceMaker { - weak var container = container - func containerRef(_ value: Any) -> Reference { - return Reference(currentValue: value) { [weak handle = container?.referenceHandle] in - handle == nil ? nil : value - } - } + var makeRef: ReferenceMaker { switch self { - case .graph: return containerRef - case .container: return containerRef + case .graph: return strongRef + case .container: return strongRef case .weak: return weakRef case .transient: return noRef } diff --git a/Sources/2.0 API/ServiceEntry.swift b/Sources/2.0 API/ServiceEntry.swift index 9b4e1793..4949233d 100644 --- a/Sources/2.0 API/ServiceEntry.swift +++ b/Sources/2.0 API/ServiceEntry.swift @@ -50,7 +50,7 @@ public class ServiceEntry { @discardableResult public func inObjectScope(_ objectScope: ObjectScope) -> Self { scope = objectScope.scope - makeRef = container.map(objectScope.makeRef) ?? noRef + makeRef = objectScope.makeRef return self } @@ -85,7 +85,7 @@ extension ServiceEntry: Binding { public func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any { if let scope = scope { - return scope.registry(for: context).instance( + return getRegistry(scope: scope, context: context).instance( for: ScopeRegistryKey(descriptor: key.descriptor, argument: arg), builder: { makeRef(builder(resolver, context, arg)) }, finalizer: { instance in finalizers.forEach { $0(resolver, instance as! Service) } } @@ -95,6 +95,14 @@ extension ServiceEntry: Binding { } } + private func getRegistry(scope: AnyScope, context: Any) -> ScopeRegistry { + if scope is ContainerScope, let container = container { + return scope.registry(for: container) + } else { + return scope.registry(for: context) + } + } + public var key: BindingKey { return BindingKey( descriptor: { diff --git a/Templates/Container+Registration.swifttemplate b/Templates/Container+Registration.swifttemplate index 329cac86..f65c48f2 100644 --- a/Templates/Container+Registration.swifttemplate +++ b/Templates/Container+Registration.swifttemplate @@ -16,7 +16,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef(in: self)) { (r, _, _: Void) in factory(r) } + let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef) { (r, _, _: Void) in factory(r) } addEntry(entry, with: name) return entry } @@ -41,7 +41,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register>(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, <%= arg_types %>) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef(in: self)) { (r, _, a: <%= arg_closure_type %>) in factory(r, <%= arg_vars %>) } + let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef) { (r, _, a: <%= arg_closure_type %>) in factory(r, <%= arg_vars %>) } addEntry(entry, with: name) return entry }<%= i < arg_count ? "\n" : "" %> diff --git a/Tests/2.0 API/ContainerSpec.swift b/Tests/2.0 API/ContainerSpec.swift index 2b6fd5bb..d8f537d5 100644 --- a/Tests/2.0 API/ContainerSpec.swift +++ b/Tests/2.0 API/ContainerSpec.swift @@ -227,6 +227,17 @@ class ContainerSpec: QuickSpec { expect(first) !== second } + it("releases instance after releasing child container") { + let parent = Container() + var container = Container(parent: parent) as Container? + container?.register(Animal.self) { _ in Cat() } + .inObjectScope(.container) + weak var cat = container?.resolve(Animal.self) as? Cat + + container = nil + + expect(cat).to(beNil()) + } it("after resetting child it resolves parent type to the same instance") { let parent = Container() let child = Container(parent: parent) From bce648ce6a445283dc986f78c4b63857c7014eea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Tue, 30 Jul 2019 22:58:18 +0200 Subject: [PATCH 174/239] Enable custom default scopes for container & assembler --- Sources/2.0 API/Assembler.swift | 29 +++++++++++++-- Sources/2.0 API/Container+Registration.swift | 20 +++++------ Sources/2.0 API/Container.swift | 36 ++++++++++++++++--- Sources/2.0 API/ServiceEntry.swift | 19 +++++----- .../Container+Registration.swifttemplate | 4 +-- 5 files changed, 80 insertions(+), 28 deletions(-) diff --git a/Sources/2.0 API/Assembler.swift b/Sources/2.0 API/Assembler.swift index 9352f6f8..7a986e23 100644 --- a/Sources/2.0 API/Assembler.swift +++ b/Sources/2.0 API/Assembler.swift @@ -36,16 +36,39 @@ public final class Assembler { /// - parameter parent: the baseline assembler /// - parameter defaultObjectScope: default object scope for container /// - parameter behaviors: list of behaviors to be added to the container - public init( + public convenience init( _ assemblies: [Assembly] = [], parent: Assembler? = nil, - // TODO: Enable arbitrary default scope defaultObjectScope: ObjectScope = .graph, behaviors: [Behavior] = [] + ) { + self.init( + assemblies, + parent: parent, + defaultScope: defaultObjectScope.scope, + defaultMakeRef: defaultObjectScope.makeRef, + behaviors: behaviors + ) + } + + /// Will create a new `Assembler` with the given `Assembly` instances to build a `Container` + /// + /// - parameter assemblies: the list of assemblies to build the container from + /// - parameter parent: the baseline assembler + /// - parameter defaultScope: default scope for container + /// - parameter defaultMakeRef: default reference maker for container (`strongRef` by default) + /// - parameter behaviors: list of behaviors to be added to the container + public init( + _ assemblies: [Assembly] = [], + parent: Assembler? = nil, + defaultScope: AnyScope?, + defaultMakeRef: @escaping ReferenceMaker = strongRef, + behaviors: [Behavior] = [] ) { container = Container( parent: parent?.container, - defaultObjectScope: defaultObjectScope, + defaultScope: defaultScope, + defaultMakeRef: defaultMakeRef, behaviors: behaviors ) run(assemblies: assemblies) diff --git a/Sources/2.0 API/Container+Registration.swift b/Sources/2.0 API/Container+Registration.swift index 8028726e..7721be7d 100644 --- a/Sources/2.0 API/Container+Registration.swift +++ b/Sources/2.0 API/Container+Registration.swift @@ -19,7 +19,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef) { (r, _, _: Void) in factory(r) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, _: Void) in factory(r) } addEntry(entry, with: name) return entry } @@ -38,7 +38,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef) { (r, _, a: Arg1) in factory(r, a) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, a: Arg1) in factory(r, a) } addEntry(entry, with: name) return entry } @@ -57,7 +57,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef) { (r, _, a: (Arg1, Arg2)) in factory(r, a.0, a.1) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, a: (Arg1, Arg2)) in factory(r, a.0, a.1) } addEntry(entry, with: name) return entry } @@ -76,7 +76,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef) { (r, _, a: (Arg1, Arg2, Arg3)) in factory(r, a.0, a.1, a.2) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, a: (Arg1, Arg2, Arg3)) in factory(r, a.0, a.1, a.2) } addEntry(entry, with: name) return entry } @@ -95,7 +95,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef) { (r, _, a: (Arg1, Arg2, Arg3, Arg4)) in factory(r, a.0, a.1, a.2, a.3) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, a: (Arg1, Arg2, Arg3, Arg4)) in factory(r, a.0, a.1, a.2, a.3) } addEntry(entry, with: name) return entry } @@ -114,7 +114,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5)) in factory(r, a.0, a.1, a.2, a.3, a.4) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5)) in factory(r, a.0, a.1, a.2, a.3, a.4) } addEntry(entry, with: name) return entry } @@ -133,7 +133,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5) } addEntry(entry, with: name) return entry } @@ -152,7 +152,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6) } addEntry(entry, with: name) return entry } @@ -171,7 +171,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6, a.7) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6, a.7) } addEntry(entry, with: name) return entry } @@ -190,7 +190,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6, a.7, a.8) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6, a.7, a.8) } addEntry(entry, with: name) return entry } diff --git a/Sources/2.0 API/Container.swift b/Sources/2.0 API/Container.swift index 498c6ed9..c425b40e 100644 --- a/Sources/2.0 API/Container.swift +++ b/Sources/2.0 API/Container.swift @@ -22,8 +22,8 @@ import Foundation public final class Container { let registry = StandardScopeRegistry() let parent: Container? - // TODO: Enable arbitrary scope as default - let defaultObjectScope: ObjectScope + let defaultScope: AnyScope? + let defaultMakeRef: ReferenceMaker var bindings = [Binding & CustomStringConvertible]() var behaviors = [Behavior]() var swinject: Swinject { return Swinject( @@ -48,14 +48,42 @@ public final class Container { /// /// - Remark: Compile time may be long if you pass a long closure to this initializer. /// Use `init()` or `init(parent:)` instead. - public init( + public convenience init( parent: Container? = nil, defaultObjectScope: ObjectScope = .graph, behaviors: [Behavior] = [], registeringClosure: (Container) -> Void = { _ in } + ) { + self.init( + parent: parent, + defaultScope: defaultObjectScope.scope, + defaultMakeRef: defaultObjectScope.makeRef, + behaviors: behaviors, + registeringClosure: registeringClosure + ) + } + + /// Instantiates a `Container` + /// + /// - Parameters + /// - parent: The optional parent `Container`. + /// - defaultScope: Default scope + /// - defaultMakeRef: Default reference maker (`strongRef` by default) + /// - behaviors: List of behaviors to be added to the container + /// - registeringClosure: The closure registering services to the new container instance. + /// + /// - Remark: Compile time may be long if you pass a long closure to this initializer. + /// Use `init()` or `init(parent:)` instead. + public init( + parent: Container? = nil, + defaultScope: AnyScope?, + defaultMakeRef: @escaping ReferenceMaker = strongRef, + behaviors: [Behavior] = [], + registeringClosure: (Container) -> Void = { _ in } ) { self.parent = parent - self.defaultObjectScope = defaultObjectScope + self.defaultScope = defaultScope + self.defaultMakeRef = defaultMakeRef self.behaviors = behaviors registeringClosure(self) } diff --git a/Sources/2.0 API/ServiceEntry.swift b/Sources/2.0 API/ServiceEntry.swift index 4949233d..6dff8912 100644 --- a/Sources/2.0 API/ServiceEntry.swift +++ b/Sources/2.0 API/ServiceEntry.swift @@ -29,29 +29,30 @@ public class ServiceEntry { argumentType = Argument.self } - /// Specifies the object scope to resolve the service. + /// Specifies a custom scope & reference maker to use for the service. /// - /// - Parameter scope: The `ObjectScopeProtocol` value. + /// - Parameter scope: A custom scope to be used with entry. + /// - Parameter makeRef: A reference maker, `strongRef` by default /// /// - Returns: `self` to add another configuration fluently. @discardableResult - public func inObjectScope(_ scope: ObjectScope) -> Self where ObjectScope: Scope { + public func inObjectScope( + _ scope: AnyScope?, + makeRef: @escaping ReferenceMaker = strongRef + ) -> Self { self.scope = scope + self.makeRef = makeRef return self } - /// Specifies the object scope to resolve the service. - /// Performs the same functionality as `inObjectScope(_: ObjectScopeProtocol) -> Self`, - /// but provides more convenient usage syntax. + /// Specifies the object scope to use for the service. /// /// - Parameter scope: The `ObjectScope` value. /// /// - Returns: `self` to add another configuration fluently. @discardableResult public func inObjectScope(_ objectScope: ObjectScope) -> Self { - scope = objectScope.scope - makeRef = objectScope.makeRef - return self + return inObjectScope(objectScope.scope, makeRef: objectScope.makeRef) } /// Adds the callback to setup the instance after its `init` completes. diff --git a/Templates/Container+Registration.swifttemplate b/Templates/Container+Registration.swifttemplate index f65c48f2..973c5101 100644 --- a/Templates/Container+Registration.swifttemplate +++ b/Templates/Container+Registration.swifttemplate @@ -16,7 +16,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef) { (r, _, _: Void) in factory(r) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, _: Void) in factory(r) } addEntry(entry, with: name) return entry } @@ -41,7 +41,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register>(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, <%= arg_types %>) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultObjectScope.scope, makeRef: defaultObjectScope.makeRef) { (r, _, a: <%= arg_closure_type %>) in factory(r, <%= arg_vars %>) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, a: <%= arg_closure_type %>) in factory(r, <%= arg_vars %>) } addEntry(entry, with: name) return entry }<%= i < arg_count ? "\n" : "" %> From 64aa82ce37be5682973cfd357318481b5cc94346 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Tue, 30 Jul 2019 23:56:59 +0200 Subject: [PATCH 175/239] Fix override rules --- Sources/Core/SwinjectContainer.swift | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Sources/Core/SwinjectContainer.swift b/Sources/Core/SwinjectContainer.swift index 4b7cd162..08b7df2f 100644 --- a/Sources/Core/SwinjectContainer.swift +++ b/Sources/Core/SwinjectContainer.swift @@ -56,10 +56,14 @@ extension SwinjectContainer.Builder { } private func checkOverrideRules(for entry: BindingEntry, beingAddedTo dict: [BindingKey: Binding]) throws { - if entry.properties.overrides, !entry.canOverride { throw OverrideNotAllowed() } - if !entry.canOverrideSilently { - if dict[entry.key] == nil, entry.properties.overrides { throw NothingToOverride() } - if dict[entry.key] != nil, !entry.properties.overrides { throw SilentOverrideNotAllowed() } + if !entry.canOverride, entry.properties.overrides { + throw OverrideNotAllowed() + } + if dict[entry.key] == nil, entry.properties.overrides { + throw NothingToOverride() + } + if dict[entry.key] != nil, !entry.properties.overrides, !entry.canOverrideSilently { + throw SilentOverrideNotAllowed() } } From 63d2700a3ebd5e1f0c658251f4c2eba714f486b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Thu, 1 Aug 2019 20:24:08 +0200 Subject: [PATCH 176/239] Store bindings in a dictionary --- Sources/2.0 API/ServiceEntry.swift | 7 -- Sources/Core/Binding.swift | 3 +- Sources/Core/ContextTranslator.swift | 11 ++ Sources/Core/ScopedBinding.swift | 4 - Sources/Core/SimpleBinding.swift | 4 - Sources/Core/Swinject.swift | 12 +- Sources/Core/SwinjectContainer.swift | 5 +- Swinject.xcodeproj/project.pbxproj | 176 +++++++++++++-------------- 8 files changed, 111 insertions(+), 111 deletions(-) diff --git a/Sources/2.0 API/ServiceEntry.swift b/Sources/2.0 API/ServiceEntry.swift index 6dff8912..7b8a5834 100644 --- a/Sources/2.0 API/ServiceEntry.swift +++ b/Sources/2.0 API/ServiceEntry.swift @@ -77,13 +77,6 @@ extension ServiceEntry: Binding { ) } - public func matches(_ key: BindingKey) -> Bool { - let forwardedKeys = forwardedDescriptors.map { - BindingKey(descriptor: $0, contextType: scope?.contextType ?? Any.self, argumentType: argumentType) - } - return ([self.key] + forwardedKeys).contains { $0.matches(key) } - } - public func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any { if let scope = scope { return getRegistry(scope: scope, context: context).instance( diff --git a/Sources/Core/Binding.swift b/Sources/Core/Binding.swift index a208b5ad..b5cb218d 100644 --- a/Sources/Core/Binding.swift +++ b/Sources/Core/Binding.swift @@ -9,7 +9,7 @@ public struct BindingKey: Hashable { func matches(_ other: BindingKey) -> Bool { return descriptor.matches(other.descriptor) - && (contextType == other.contextType || contextType == Any.self) + && contextType == other.contextType && argumentType == other.argumentType } @@ -27,7 +27,6 @@ public struct BindingKey: Hashable { public protocol Binding: SwinjectEntry { var key: BindingKey { get } var properties: BindingProperties { get } - func matches(_ key: BindingKey) -> Bool func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any } diff --git a/Sources/Core/ContextTranslator.swift b/Sources/Core/ContextTranslator.swift index db9cb4eb..cd051642 100644 --- a/Sources/Core/ContextTranslator.swift +++ b/Sources/Core/ContextTranslator.swift @@ -31,6 +31,17 @@ struct IdentityTranslator: AnyContextTranslator { func translate(_ context: Any) throws -> Any { return context } } +struct ToAnyTranslator: AnyContextTranslator { + let sourceType: Any.Type + let targetType: Any.Type = Any.self + + init(for contextType: Any.Type) { + sourceType = contextType + } + + func translate(_ context: Any) throws -> Any { return context } +} + public func registerContextTranslator( from _: Source.Type = Source.self, to _: Target.Type = Target.self, diff --git a/Sources/Core/ScopedBinding.swift b/Sources/Core/ScopedBinding.swift index 3516ab0a..b1be1e57 100644 --- a/Sources/Core/ScopedBinding.swift +++ b/Sources/Core/ScopedBinding.swift @@ -11,10 +11,6 @@ struct ScopedBinding { } extension ScopedBinding: Binding { - func matches(_ key: BindingKey) -> Bool { - return self.key.matches(key) - } - func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any { return try scope .registry(for: context) diff --git a/Sources/Core/SimpleBinding.swift b/Sources/Core/SimpleBinding.swift index dde2c0eb..814757ad 100644 --- a/Sources/Core/SimpleBinding.swift +++ b/Sources/Core/SimpleBinding.swift @@ -9,10 +9,6 @@ struct SimpleBinding { } extension SimpleBinding: Binding { - func matches(_ key: BindingKey) -> Bool { - return self.key.matches(key) - } - func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any { return try builder.makeInstance(arg: arg, context: context, resolver: resolver) } diff --git a/Sources/Core/Swinject.swift b/Sources/Core/Swinject.swift index 05cc8aac..cc18e6f9 100644 --- a/Sources/Core/Swinject.swift +++ b/Sources/Core/Swinject.swift @@ -52,14 +52,20 @@ extension Swinject: Resolver { } private func findTranslator(for request: AnyInstanceRequest, and binding: Binding) throws -> AnyContextTranslator { - return try (container.translators + [IdentityTranslator(for: contextType)]) + return try (container.translators + [IdentityTranslator(for: contextType), ToAnyTranslator(for: contextType)]) .filter { $0.sourceType == contextType } - .filter { binding.matches(request.key(forContextType: $0.targetType)) } + .filter { binding.key == request.key(forContextType: $0.targetType) } .first ?? { throw SwinjectError() }() } + private func translatableKeys(for request: AnyInstanceRequest) -> [BindingKey] { + return (container.translators + [IdentityTranslator(for: contextType), ToAnyTranslator(for: contextType)]) + .filter { $0.sourceType == contextType } + .map { request.key(forContextType: $0.targetType) } + } + private func findBinding(for request: AnyInstanceRequest) throws -> Binding { - let bindings = container.bindings.filter { (try? findTranslator(for: request, and: $0)) != nil } + let bindings = translatableKeys(for: request).compactMap { container.bindings[$0] } if bindings.isEmpty { throw NoBinding() } if bindings.count > 1 { throw MultipleBindings() } return bindings[0] diff --git a/Sources/Core/SwinjectContainer.swift b/Sources/Core/SwinjectContainer.swift index 08b7df2f..6c5c5230 100644 --- a/Sources/Core/SwinjectContainer.swift +++ b/Sources/Core/SwinjectContainer.swift @@ -3,7 +3,7 @@ // struct SwinjectContainer { - let bindings: [Binding] + let bindings: [BindingKey: Binding] let translators: [AnyContextTranslator] struct Builder { @@ -46,13 +46,12 @@ extension SwinjectContainer.Builder { let canOverrideSilently: Bool } - private func collectBindings() throws -> [Binding] { + private func collectBindings() throws -> [BindingKey: Binding] { return try collectBindingEntries(from: tree, canOverrideSilently: allowsSilentOverride) .reduce(into: [BindingKey: Binding]()) { dict, entry in try checkOverrideRules(for: entry, beingAddedTo: dict) dict[entry.key] = entry.binding } - .map { $0.value } } private func checkOverrideRules(for entry: BindingEntry, beingAddedTo dict: [BindingKey: Binding]) throws { diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 008a12e8..6b454af7 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -11,7 +11,6 @@ 0068DAA4AA322F00AF53731F /* ScopesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D3C59E84B5FD0C13F487838 /* ScopesSpec.swift */; }; 0207493E1CEE8456E91E3DAE /* BindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E59A67F3548663368788B17 /* BindingSpec.swift */; }; 020DA1718FCC68D889FB5A5F /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3586A4987B7C7C8122D674E /* SwinjectError.swift */; }; - 02410BD4FB357F4C6B521608 /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; 02556F149C9AAEF5CE353AC1 /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; 03122D1B2EA65C89ADC78EC7 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62682D6ED38742996624B041 /* BasicAssembly.swift */; }; 0509EE8D41BF354EB91ACC80 /* Reference.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73B4B777290FF5D38A8914CC /* Reference.swift */; }; @@ -21,10 +20,8 @@ 06F4CAB352B4F623FF7BD885 /* ScopeRegistryKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */; }; 0720BEA814AD514378380ACB /* StandardScopeRegistrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */; }; 0781579818FC4A2CA1CD3CAE /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */; }; - 0946D0D940D38828FD0DFBAD /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */; }; 09470890A74A5DDE7114891B /* TaggedTypeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */; }; 0B61DC733616A8ED4ED77FA7 /* StandardScopeRegistrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */; }; - 0CD787EACEBFD1051D358E7D /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; 0CE1126436F680F9684837E4 /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; 0CE158916595980A7C8272D3 /* SingletonSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46F05CC591903E2B04B6D8ED /* SingletonSpec.swift */; }; 0D5C4A278A16AB3A163148AF /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; @@ -32,7 +29,6 @@ 13CDEC7A6C8E43B58D5CBE3D /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; 180DB4397B4C05E26F819C85 /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADA1541ABC1365DFD7E3377F /* Food.swift */; }; 19416C867F15E88394A0ABD1 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */; }; - 196338EA802A39E205C33B43 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; 19EBB651BD06BD0C03C1ACB5 /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59111BE319C59E4CD6CF68CD /* Assembler.swift */; }; 1A40A26942A65246D7DD268E /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = ADC44E9312C3B974AFD8F07B /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 1A68A8D05D9974002BF34CF8 /* RetrievalSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D8B3342E2AC3236F12072F5 /* RetrievalSpec.swift */; }; @@ -49,9 +45,6 @@ 283C77045DA55C2134EC9C48 /* Container+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F446D6BD4C44E16A1D608BFB /* Container+TypeForwarding.swift */; }; 290C9E9420A1EE30456476CB /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59111BE319C59E4CD6CF68CD /* Assembler.swift */; }; 293985649250DF270DC89135 /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; - 2AA60B7E6EBA9EC6BE92D7CB /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; - 2B506344F37CE5F5C5C02C05 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; - 2B88BFD81C226C858E0AE2B6 /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */; }; 2C352AAD1AC7D82A4A059046 /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; 2C3EB507FFA03D18B2909405 /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8B9785AAE94A5447FA307242 /* Swinject.framework */; }; 2CB057F2A16DA462E0517AAB /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; @@ -73,8 +66,6 @@ 389C54E04DD794DA4F648571 /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */; }; 3A0B409E840B44B281DB3C54 /* Container+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F446D6BD4C44E16A1D608BFB /* Container+TypeForwarding.swift */; }; 3BD6055555A5C30DABDC8ED2 /* Reference.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73B4B777290FF5D38A8914CC /* Reference.swift */; }; - 3BDB44DE92D2377334894804 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; - 3C270A77DE4F1E6BC2F8E863 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; 3CEF021295AD9AF9BF26B71E /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; 3DEFB7CA42D9EFF0B4FBC0F4 /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 38BCCF3F950869BD1891F7A8 /* Swinject.framework */; }; 3F8F5645D6D37FCEC1D89393 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B580B43E1891812C97209 /* Binding.swift */; }; @@ -85,19 +76,14 @@ 43A74237D8933572BAA0F3B4 /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; 44F458F61B21D78A91664160 /* BinderVariation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E0C3E4D518BC1FEF3EF8D33 /* BinderVariation.swift */; }; 48D1568CB41BE4B6597FD535 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; - 48F40377D116C6B1B786C329 /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; - 4954CBB07E38E98752AC3347 /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; 49685AB40BEE856C62005C87 /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; 49D71F6CC12C12FE7B6A097A /* ContextSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */; }; 4B9811CF0604946CCF323ED2 /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92B8E618A08408404FB2A7A /* TypeBinder.swift */; }; - 4DC8A58B6607898BAF6504A3 /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */; }; 4DF3DC1CDD3C4948F9BDD3DF /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3586A4987B7C7C8122D674E /* SwinjectError.swift */; }; 4E4DC8CDD1BA51FB66A332C2 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */; }; 4EC94A51037C79DE0C5C8CB1 /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; 4EE5C1207C57C85A928FA89B /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 273FB7A6277E0841E1570990 /* Nimble.framework */; }; 53EBF7A46EF65F2A8DAADC7A /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; - 546FF827DB6D42490D1CA439 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; - 54956014A1774DF8357B69E6 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; 55CA3AA3F28B7CC221ABEC83 /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6D54F152C11C966ECFC55ECB /* Swinject.framework */; }; 55F2E72EA8C3564130F66946 /* ModulesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75BE3AE3E30DFE42A919D825 /* ModulesSpec.swift */; }; 57BFBA2077E70DC1C2FE796C /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */; }; @@ -119,11 +105,9 @@ 658AEDC8D802A6788E959E0C /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B580B43E1891812C97209 /* Binding.swift */; }; 658C98B4AA17C58E8556E0AC /* Opaque.swift in Sources */ = {isa = PBXBuildFile; fileRef = C68B98C653ABDED9C3D17DB3 /* Opaque.swift */; }; 68C95FCB0D345CA3BA24D320 /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; - 68D828A3C583DDD28CFE882B /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; 6922AE734E84B515C94D9480 /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; 694C2C891D581371B2B051D7 /* Container+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDA78290D6D60BD0B808571F /* Container+Logging.swift */; }; 6A03ABEED82EF31E8E6E297E /* Container+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDA78290D6D60BD0B808571F /* Container+Logging.swift */; }; - 6A0FD11468B3852E48B682BE /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; 6BB1E24C1CE55C9F6EA6CC28 /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C765B92B00C0AC8625BB4AC9 /* Quick.framework */; }; 6C01E868DE44BD396D94858B /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; 6C4D29A3FB54416D5E4D4C89 /* InstanceBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED41A352529A5B2950F39D8F /* InstanceBuilder.swift */; }; @@ -132,7 +116,6 @@ 6FCCBA9D2E4C2A225CB1A152 /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */; }; 70368EC369287B4EE767E929 /* LinuxConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 938425B216B78A06EC10504A /* LinuxConfig.swift */; }; 703F8B3AD111A6CFAFF66A49 /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; - 708E1C453CBC76ED26FA2FCB /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; 70BAF056528B2B33B3A65E9D /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A006CC804F9AB8ACC121029 /* Utils.swift */; }; 71895EBC0803EEE3BFCD7001 /* Resolver+Injection.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 01DEC4D20CE554C9DFBD0A8D /* Resolver+Injection.swifttemplate */; }; 72217E47D83C3CA6D97640B9 /* StandardScopeRegistrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */; }; @@ -147,7 +130,6 @@ 789BF74652A2424EB8F7EF47 /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 7A7032384E07DAD308D4F70A /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 8B9785AAE94A5447FA307242 /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 7D0683F36CE56228AC2CD489 /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C074BAC560F277E806146C60 /* SimpleBinding.swift */; }; - 7D6F664091C70BABBFB61D53 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; 7E3C3E6FD07F3BD76024770A /* InjectionVariation.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C516EFA0CA22D19F07B27E /* InjectionVariation.swift */; }; 7F9686F3669BF35E5AC970B3 /* InstanceBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED41A352529A5B2950F39D8F /* InstanceBuilder.swift */; }; 8016512839FE61EC3127E489 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */; }; @@ -156,14 +138,10 @@ 820307073A53AED47AC99B8D /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3586A4987B7C7C8122D674E /* SwinjectError.swift */; }; 8228FEB1DF3C41DEDCE0FB1D /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = A10187BB3A994165E7FC1528 /* ScopedBinding.swift */; }; 82299769BC637A14E7827DB0 /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1E726A651C3AFE92C19608B /* SwinjectModule.swift */; }; - 829853126CDB7464599AFC85 /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; 832C9ABB8DCF5340D796F5F8 /* ContextSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */; }; - 83464EDC08380F5CE2190F30 /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; - 8436D091ED844817C8CE3AF2 /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; 848227742D4ABA298D340485 /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; 86CBC40FDC90E2A2051386C5 /* ContextSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */; }; 87FEAEF562B99522083CB87D /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; - 890CCD2800597F6FB7C6FD31 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; 89E2997CB8B90368A15A91CE /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; 8B5927517B567B1DFAB5B935 /* ContextTranslator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */; }; 8BE1DA0A9876AB47BB76E2CD /* Opaque.swift in Sources */ = {isa = PBXBuildFile; fileRef = C68B98C653ABDED9C3D17DB3 /* Opaque.swift */; }; @@ -176,7 +154,6 @@ 9425887520AC2DBDCBACB252 /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92B8E618A08408404FB2A7A /* TypeBinder.swift */; }; 95A6654089875BCC863FB53B /* InjectionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 670DB253ECD5CE1468A7F2E3 /* InjectionSpec.swift */; }; 96EA0A5DF33F025EBE0B67D2 /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; - 979518E078B187549E11DF48 /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; 97C2EA47D7623AFD723AFE93 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */; }; 980FED1DBC62B65597E2828B /* SingletonSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46F05CC591903E2B04B6D8ED /* SingletonSpec.swift */; }; 98322F9371E1A8461BC614D1 /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; @@ -184,7 +161,6 @@ 996CCFE825834C7D3236E742 /* Container+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F446D6BD4C44E16A1D608BFB /* Container+TypeForwarding.swift */; }; 999AF7221D3F2E1F83C3ACB1 /* Container+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDA78290D6D60BD0B808571F /* Container+Logging.swift */; }; 99C5D861B16FAFAD3F9E28C5 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */; }; - 9A21ECA8F283E1E144CEC763 /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; 9A2A6978519F2BBA97DA6EA6 /* BindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E59A67F3548663368788B17 /* BindingSpec.swift */; }; 9AD60A86D5A0DF4513C1EA8D /* TaggedTypeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */; }; 9C15BE01C1EA41061CDB7918 /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C074BAC560F277E806146C60 /* SimpleBinding.swift */; }; @@ -192,7 +168,6 @@ 9CEE20BD42795D5E5F39BF20 /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; 9DEAC620F2F00D0DDD3B5D3E /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; A193BF10196FBDE32833E292 /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = A10187BB3A994165E7FC1528 /* ScopedBinding.swift */; }; - A1A2D0FA98038EACAC04E64C /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; A2D3B18BE38948A427B60BC5 /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61EE5DDBE705B47AFC9A6986 /* LoadAwareAssembly.swift */; }; A308578B99D33C7E33632E85 /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; A3BFFED76688F149FBAF7C53 /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EA566CD336DB8343ADFAF9B /* BehaviorFakes.swift */; }; @@ -202,13 +177,10 @@ A59C6C434288333EDAF951C4 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */; }; A5E4C79F89E1A8AB3A4D8D6E /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59A3946B59EB4D787CCE9F2 /* Container+Registration.swift */; }; A6EECC339FA54CA0BBFF4146 /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BC5108ED11A3A3084D864CC /* Animal.swift */; }; - A70936B898139A6C5F83F616 /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; A75BAA10EC6F738EBC2C5BE8 /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */; }; - A7DD08A60F12EC078BBE086F /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; A834D948AB86794CA3304B98 /* LinuxConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 938425B216B78A06EC10504A /* LinuxConfig.swift */; }; A882705E4199EF759E80B311 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; A91EDAFBC3606EDFBD739899 /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */; }; - A9A242086D1EDE408DC556D0 /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; AAD8D0551B8A26A9B22AECEC /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59A3946B59EB4D787CCE9F2 /* Container+Registration.swift */; }; AB864E029E996492ED4A3A52 /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92B8E618A08408404FB2A7A /* TypeBinder.swift */; }; AC470B4322599B0A076DD3FF /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; @@ -216,14 +188,12 @@ AD3E7135985F1046E35C39DE /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */; }; ADCF273AF041E74DBEC2C13A /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */; }; ADF0B21969FE77CEFBB2AAAC /* Quick.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 823617F3B8A9192F56B13331 /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - AE6EAB8CC32ED5E1789D55B7 /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; AE93BDC3AA7962AFD574B32B /* Quick.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 1C58FC14EEA170B0DC079DE4 /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; B00627BABCF9181C7B58609E /* LinuxConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 938425B216B78A06EC10504A /* LinuxConfig.swift */; }; B06306286CC5EA66C88F24D1 /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 38BCCF3F950869BD1891F7A8 /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; B0B139FADA6AE07C79847EBA /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61EE5DDBE705B47AFC9A6986 /* LoadAwareAssembly.swift */; }; B293894FEB67831DDA5F000E /* Reference.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73B4B777290FF5D38A8914CC /* Reference.swift */; }; B2FAD41F7726502822AF913B /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42490D1D0C395951243F5CFF /* Container.swift */; }; - B3062AB22373AD23052B61DF /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; B42331BF00B482369B908BB8 /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BFF4BA99493C54260878C4 /* ObjectScope.swift */; }; B4B66D7251BDDE25D6D7FB3C /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BFF4BA99493C54260878C4 /* ObjectScope.swift */; }; B5FF5DFE394B6B1BB930D88D /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */; }; @@ -245,21 +215,16 @@ BEEFBE87EB17D56BA8D47358 /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 351C4221896DDB8572BD6CB5 /* Person.swift */; }; BEFFC7B36FE5810169C81B97 /* BinderEnvironment.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 26EEC28683E4A26B3092E8BA /* BinderEnvironment.swifttemplate */; }; BFE22F9F2E88F177302E9D19 /* Container+Registration.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */; }; - C1687ACA897DEFD3A8197CCD /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; - C177D9C6969ADA38C1094F6D /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */; }; C223101DB417F1237A8421E1 /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 6D434EB4C13CF9D9FA6D80CB /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; C38A2EBF4D1904E7D6989989 /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADA1541ABC1365DFD7E3377F /* Food.swift */; }; C3FDE105B08336F26CC95BAA /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = A10187BB3A994165E7FC1528 /* ScopedBinding.swift */; }; C637E97E193BB1DADDDC6C21 /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1E726A651C3AFE92C19608B /* SwinjectModule.swift */; }; C6D60E2AEC381998223145B2 /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; C76374CAFE7C2BCCE52F1BB1 /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 351C4221896DDB8572BD6CB5 /* Person.swift */; }; - C950785B81C6DB22F41FA3CE /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; C952D5869D87743297968E9A /* StandardScopeRegistrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */; }; - CA5523B60E51EB98719CF1F8 /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; CAA5241DAA201FBB5818C803 /* BindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E59A67F3548663368788B17 /* BindingSpec.swift */; }; CB0B308F3D3A831A28127462 /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59A3946B59EB4D787CCE9F2 /* Container+Registration.swift */; }; CB9E8D16D7A0620A1F7A32A3 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; - CBBE28990E0EA82AD8D5E3AF /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; CBE63031F33303F3E503CEF2 /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; CD03917422EF610800DE44C4 /* OverrideSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD03917322EF610800DE44C4 /* OverrideSpec.swift */; }; CD03917522EF610800DE44C4 /* OverrideSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD03917322EF610800DE44C4 /* OverrideSpec.swift */; }; @@ -269,12 +234,54 @@ CD367C0F22EF8A83008B3E82 /* SwinjectContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD367C0D22EF8A83008B3E82 /* SwinjectContainer.swift */; }; CD367C1022EF8A83008B3E82 /* SwinjectContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD367C0D22EF8A83008B3E82 /* SwinjectContainer.swift */; }; CD367C1122EF8A83008B3E82 /* SwinjectContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD367C0D22EF8A83008B3E82 /* SwinjectContainer.swift */; }; + CD73B9AB22F239A4004BB84E /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; + CD73B9AC22F239A4004BB84E /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */; }; + CD73B9AD22F239A4004BB84E /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; + CD73B9AE22F239A4004BB84E /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; + CD73B9AF22F239A4004BB84E /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; + CD73B9B022F239A4004BB84E /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; + CD73B9B122F239A4004BB84E /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; + CD73B9B222F239A4004BB84E /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; + CD73B9B322F239A4004BB84E /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; + CD73B9B422F239A4004BB84E /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; + CD73B9B522F239A4004BB84E /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; + CD73B9B622F239A4004BB84E /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; + CD73B9B722F239A4004BB84E /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */; }; + CD73B9B822F239A4004BB84E /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; + CD73B9B922F239A4004BB84E /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; + CD73B9BA22F239A4004BB84E /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; + CD73B9BB22F239A4004BB84E /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; + CD73B9BC22F239A4004BB84E /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; + CD73B9BD22F239A4004BB84E /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; + CD73B9BE22F239A4004BB84E /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; + CD73B9BF22F239A4004BB84E /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; + CD73B9C022F239A4004BB84E /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; + CD73B9C122F239A5004BB84E /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; + CD73B9C222F239A5004BB84E /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */; }; + CD73B9C322F239A5004BB84E /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; + CD73B9C422F239A5004BB84E /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; + CD73B9C522F239A5004BB84E /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; + CD73B9C622F239A5004BB84E /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; + CD73B9C722F239A5004BB84E /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; + CD73B9C822F239A5004BB84E /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; + CD73B9C922F239A5004BB84E /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; + CD73B9CA22F239A5004BB84E /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; + CD73B9CB22F239A5004BB84E /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; + CD73B9CC22F239A6004BB84E /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; + CD73B9CD22F239A6004BB84E /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */; }; + CD73B9CE22F239A6004BB84E /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; + CD73B9CF22F239A6004BB84E /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; + CD73B9D022F239A6004BB84E /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; + CD73B9D122F239A6004BB84E /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; + CD73B9D222F239A6004BB84E /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; + CD73B9D322F239A6004BB84E /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; + CD73B9D422F239A6004BB84E /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; + CD73B9D522F239A6004BB84E /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; + CD73B9D622F239A6004BB84E /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; CE5AFED22F04B96713ED76D7 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ADC44E9312C3B974AFD8F07B /* Nimble.framework */; }; CECF5BD14BCDF5248771A06A /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; CEE763218A90832454A6E2DE /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */; }; - CF4516872D3DA7118DB2B90B /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; CF4EBB60C21F8C503BCD7A29 /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1E726A651C3AFE92C19608B /* SwinjectModule.swift */; }; - CF9535A0DCAFF23F4D62F871 /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; D0D71F9C22A0EE82B6E4F61A /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 74DE57FB3E8228904E6FE0D7 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; D13208E63523A97A0B840283 /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BC5108ED11A3A3084D864CC /* Animal.swift */; }; D1DF4740A9D86362B63104B8 /* ContextTranslator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */; }; @@ -282,7 +289,6 @@ D3FB9F7B3F791A83FF86205C /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 273FB7A6277E0841E1570990 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; D4936DC1A47A8C85325FB52E /* Resolver+LegacyApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A784E2DEC7691D14DDBECD8 /* Resolver+LegacyApi.swift */; }; D600D0EFA0FE12A719EF095F /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 683A1FB7D7F4E9508D57E936 /* Quick.framework */; }; - D69ED6990417ED1E921ACFCA /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; D861595482464ED95CF81922 /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; D9084C826F7A798508CD66F5 /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; D941D81F59900A52805D6B4A /* OptionalsSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50D6F2639990DD5BAD9578B0 /* OptionalsSpec.swift */; }; @@ -295,17 +301,14 @@ DCB7C4BF24782862BE9DB135 /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; DD29D2E60DA979D61F32A39A /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62682D6ED38742996624B041 /* BasicAssembly.swift */; }; DD5E3AF2B5FCE5E81EBDF606 /* ContextTranslator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */; }; - E01D0D443FBA4DB82A6EC298 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; E177D354B1F410129D921C69 /* Resolver+LegacyApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A784E2DEC7691D14DDBECD8 /* Resolver+LegacyApi.swift */; }; E1B95D3EEA5BB989CCFFE70D /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = A10187BB3A994165E7FC1528 /* ScopedBinding.swift */; }; E227D08034E08AA0909BC043 /* RetrievalSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D8B3342E2AC3236F12072F5 /* RetrievalSpec.swift */; }; E3EABE098DBFB561A20632E3 /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; E4CE31B7B9616EFC93C69341 /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; - E5880DBBB91CC5F8F47FBF73 /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; E7D1045D25FAB592401DCAF0 /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; EA0D19F7DF0355C774B0F40B /* ScopesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D3C59E84B5FD0C13F487838 /* ScopesSpec.swift */; }; EB3420214A9E68A0247D0F2C /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 351C4221896DDB8572BD6CB5 /* Person.swift */; }; - EB79ECF5C893F63B22355167 /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; EBC64A1515C868E410C83451 /* SwiftCode.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 90191C25A2D66E07C4E9CD73 /* SwiftCode.swifttemplate */; }; ED6CB3935B15F30A182ED6D0 /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61EE5DDBE705B47AFC9A6986 /* LoadAwareAssembly.swift */; }; EE0D3637D2524AC1CD21780D /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 74DE57FB3E8228904E6FE0D7 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -315,13 +318,10 @@ EFD2F695B86E74C77F46B7D1 /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; F06DEB671A4B85ABB0E96E51 /* ContextTranslator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */; }; F1F3BA81462E2362374BD4C4 /* ModulesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75BE3AE3E30DFE42A919D825 /* ModulesSpec.swift */; }; - F270DC6FF3901F58C76F3872 /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; F504C2ABEFCFFCAC8B858751 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; F568382FB877060127790413 /* Resolver+LegacyApi.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */; }; F6EEF5F7B57DC0E44EF569A4 /* OptionalsSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50D6F2639990DD5BAD9578B0 /* OptionalsSpec.swift */; }; F7979BE4BE1B1C7101D15E61 /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; - F7CD04FB09FC7F18E9E001CF /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; - F8EB47A631D482A0D7B621DE /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; F9A4BF18B0085B7DCD3440EC /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B580B43E1891812C97209 /* Binding.swift */; }; FA805A162E989A22990B99AA /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; FD7B2663F2F931B78EB330EE /* Resolver+LegacyApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A784E2DEC7691D14DDBECD8 /* Resolver+LegacyApi.swift */; }; @@ -1429,37 +1429,37 @@ buildActionMask = 2147483647; files = ( BD08D3E155AFD841CFECA0AD /* Animal.swift in Sources */, - 02410BD4FB357F4C6B521608 /* AssemblerSpec.swift in Sources */, + CD73B9AF22F239A4004BB84E /* ContainerSpec.Circularity.swift in Sources */, DD29D2E60DA979D61F32A39A /* BasicAssembly.swift in Sources */, + CD73B9AE22F239A4004BB84E /* ContainerSpec.Behavior.swift in Sources */, 3129A37CDC1653C11800E24A /* BehaviorFakes.swift in Sources */, 9A2A6978519F2BBA97DA6EA6 /* BindingSpec.swift in Sources */, + CD73B9B122F239A4004BB84E /* ContainerSpec.swift in Sources */, + CD73B9AC22F239A4004BB84E /* Circularity.swift in Sources */, + CD73B9B022F239A4004BB84E /* ContainerSpec.CustomStringConvertible.swift in Sources */, CD03917422EF610800DE44C4 /* OverrideSpec.swift in Sources */, 89E2997CB8B90368A15A91CE /* Bridge.swift in Sources */, - 0946D0D940D38828FD0DFBAD /* Circularity.swift in Sources */, - 68D828A3C583DDD28CFE882B /* ContainerSpec.Arguments.swift in Sources */, - D69ED6990417ED1E921ACFCA /* ContainerSpec.Behavior.swift in Sources */, - 9A21ECA8F283E1E144CEC763 /* ContainerSpec.Circularity.swift in Sources */, - B3062AB22373AD23052B61DF /* ContainerSpec.CustomStringConvertible.swift in Sources */, - A1A2D0FA98038EACAC04E64C /* ContainerSpec.TypeForwarding.swift in Sources */, - C1687ACA897DEFD3A8197CCD /* ContainerSpec.swift in Sources */, 832C9ABB8DCF5340D796F5F8 /* ContextSpec.swift in Sources */, + CD73B9AB22F239A4004BB84E /* AssemblerSpec.swift in Sources */, EE35DF2D353E2C5110DA5C42 /* Convenience.swift in Sources */, 934AFACA6BFF24AD3503F98D /* EmploymentAssembly.swift in Sources */, 180DB4397B4C05E26F819C85 /* Food.swift in Sources */, 818DF17D671EA1022CE59A2A /* InjectionSpec.swift in Sources */, - AE6EAB8CC32ED5E1789D55B7 /* LazySpec.swift in Sources */, A834D948AB86794CA3304B98 /* LinuxConfig.swift in Sources */, B0B139FADA6AE07C79847EBA /* LoadAwareAssembly.swift in Sources */, F1F3BA81462E2362374BD4C4 /* ModulesSpec.swift in Sources */, + CD73B9B322F239A4004BB84E /* LazySpec.swift in Sources */, 72F09FC92FFB0F7C32D8E2A5 /* OptionalsSpec.swift in Sources */, 628EBFBA0031B1FA2E29F583 /* Person.swift in Sources */, - 708E1C453CBC76ED26FA2FCB /* ProviderSpec.swift in Sources */, + CD73B9AD22F239A4004BB84E /* ContainerSpec.Arguments.swift in Sources */, E227D08034E08AA0909BC043 /* RetrievalSpec.swift in Sources */, + CD73B9B422F239A4004BB84E /* ProviderSpec.swift in Sources */, + CD73B9B522F239A4004BB84E /* SynchronizedResolverSpec.swift in Sources */, + CD73B9B222F239A4004BB84E /* ContainerSpec.TypeForwarding.swift in Sources */, 33B86F2D33219879731CDDF0 /* ScopesSpec.swift in Sources */, 30D247E8083858C233B92908 /* SingletonSpec.swift in Sources */, 72217E47D83C3CA6D97640B9 /* StandardScopeRegistrySpec.swift in Sources */, 640F7A55D9A671FA112C8083 /* SwinjectTreeBuilderSpec.swift in Sources */, - F7CD04FB09FC7F18E9E001CF /* SynchronizedResolverSpec.swift in Sources */, 9AD60A86D5A0DF4513C1EA8D /* TaggedTypeSpec.swift in Sources */, 778D9AB6470D4280254AC140 /* TestModels.swift in Sources */, ); @@ -1470,37 +1470,37 @@ buildActionMask = 2147483647; files = ( A6EECC339FA54CA0BBFF4146 /* Animal.swift in Sources */, - CBBE28990E0EA82AD8D5E3AF /* AssemblerSpec.swift in Sources */, + CD73B9C522F239A5004BB84E /* ContainerSpec.Circularity.swift in Sources */, 401592294E5D528379BE1AB2 /* BasicAssembly.swift in Sources */, + CD73B9C422F239A5004BB84E /* ContainerSpec.Behavior.swift in Sources */, A3BFFED76688F149FBAF7C53 /* BehaviorFakes.swift in Sources */, BB77A5D81C58392964D07233 /* BindingSpec.swift in Sources */, + CD73B9C722F239A5004BB84E /* ContainerSpec.swift in Sources */, + CD73B9C222F239A5004BB84E /* Circularity.swift in Sources */, + CD73B9C622F239A5004BB84E /* ContainerSpec.CustomStringConvertible.swift in Sources */, CD03917522EF610800DE44C4 /* OverrideSpec.swift in Sources */, 13CDEC7A6C8E43B58D5CBE3D /* Bridge.swift in Sources */, - 2B88BFD81C226C858E0AE2B6 /* Circularity.swift in Sources */, - 83464EDC08380F5CE2190F30 /* ContainerSpec.Arguments.swift in Sources */, - F8EB47A631D482A0D7B621DE /* ContainerSpec.Behavior.swift in Sources */, - E5880DBBB91CC5F8F47FBF73 /* ContainerSpec.Circularity.swift in Sources */, - 2B506344F37CE5F5C5C02C05 /* ContainerSpec.CustomStringConvertible.swift in Sources */, - E01D0D443FBA4DB82A6EC298 /* ContainerSpec.TypeForwarding.swift in Sources */, - A9A242086D1EDE408DC556D0 /* ContainerSpec.swift in Sources */, 1C62135FAE3D64DC7BFBF861 /* ContextSpec.swift in Sources */, + CD73B9C122F239A5004BB84E /* AssemblerSpec.swift in Sources */, A882705E4199EF759E80B311 /* Convenience.swift in Sources */, 19416C867F15E88394A0ABD1 /* EmploymentAssembly.swift in Sources */, 590B861A863A056A0B7FA368 /* Food.swift in Sources */, 95A6654089875BCC863FB53B /* InjectionSpec.swift in Sources */, - 979518E078B187549E11DF48 /* LazySpec.swift in Sources */, B96A6370D549AAC383360ABC /* LinuxConfig.swift in Sources */, 335CE53CEC2360DC86D58F07 /* LoadAwareAssembly.swift in Sources */, 004B06007E4FDD8F44B7EC89 /* ModulesSpec.swift in Sources */, + CD73B9C922F239A5004BB84E /* LazySpec.swift in Sources */, D941D81F59900A52805D6B4A /* OptionalsSpec.swift in Sources */, EB3420214A9E68A0247D0F2C /* Person.swift in Sources */, - CF9535A0DCAFF23F4D62F871 /* ProviderSpec.swift in Sources */, + CD73B9C322F239A5004BB84E /* ContainerSpec.Arguments.swift in Sources */, 1A68A8D05D9974002BF34CF8 /* RetrievalSpec.swift in Sources */, + CD73B9CA22F239A5004BB84E /* ProviderSpec.swift in Sources */, + CD73B9CB22F239A5004BB84E /* SynchronizedResolverSpec.swift in Sources */, + CD73B9C822F239A5004BB84E /* ContainerSpec.TypeForwarding.swift in Sources */, 0068DAA4AA322F00AF53731F /* ScopesSpec.swift in Sources */, B65DE0B0562540CC8CEC48F3 /* SingletonSpec.swift in Sources */, C952D5869D87743297968E9A /* StandardScopeRegistrySpec.swift in Sources */, A308578B99D33C7E33632E85 /* SwinjectTreeBuilderSpec.swift in Sources */, - 3BDB44DE92D2377334894804 /* SynchronizedResolverSpec.swift in Sources */, A5302886A31C90F38512B88E /* TaggedTypeSpec.swift in Sources */, 2615FC1C92B7E381116B9E57 /* TestModels.swift in Sources */, ); @@ -1511,37 +1511,37 @@ buildActionMask = 2147483647; files = ( A53B5A8E2188F8C4A3F29C2E /* Animal.swift in Sources */, - CF4516872D3DA7118DB2B90B /* AssemblerSpec.swift in Sources */, + CD73B9D022F239A6004BB84E /* ContainerSpec.Circularity.swift in Sources */, 03122D1B2EA65C89ADC78EC7 /* BasicAssembly.swift in Sources */, + CD73B9CF22F239A6004BB84E /* ContainerSpec.Behavior.swift in Sources */, 1CA5DF3F93203B226A6FA059 /* BehaviorFakes.swift in Sources */, CAA5241DAA201FBB5818C803 /* BindingSpec.swift in Sources */, + CD73B9D222F239A6004BB84E /* ContainerSpec.swift in Sources */, + CD73B9CD22F239A6004BB84E /* Circularity.swift in Sources */, + CD73B9D122F239A6004BB84E /* ContainerSpec.CustomStringConvertible.swift in Sources */, CD03917722EF610800DE44C4 /* OverrideSpec.swift in Sources */, E4CE31B7B9616EFC93C69341 /* Bridge.swift in Sources */, - 4DC8A58B6607898BAF6504A3 /* Circularity.swift in Sources */, - 8436D091ED844817C8CE3AF2 /* ContainerSpec.Arguments.swift in Sources */, - 829853126CDB7464599AFC85 /* ContainerSpec.Behavior.swift in Sources */, - C950785B81C6DB22F41FA3CE /* ContainerSpec.Circularity.swift in Sources */, - 7D6F664091C70BABBFB61D53 /* ContainerSpec.CustomStringConvertible.swift in Sources */, - 196338EA802A39E205C33B43 /* ContainerSpec.TypeForwarding.swift in Sources */, - F270DC6FF3901F58C76F3872 /* ContainerSpec.swift in Sources */, 49D71F6CC12C12FE7B6A097A /* ContextSpec.swift in Sources */, + CD73B9CC22F239A6004BB84E /* AssemblerSpec.swift in Sources */, EEAD7E215908DF939ECCDCC9 /* Convenience.swift in Sources */, 4E4DC8CDD1BA51FB66A332C2 /* EmploymentAssembly.swift in Sources */, BE6C13A3492E3CFC08E231B0 /* Food.swift in Sources */, 42FE916C1593A9289E1A28BC /* InjectionSpec.swift in Sources */, - 6A0FD11468B3852E48B682BE /* LazySpec.swift in Sources */, B00627BABCF9181C7B58609E /* LinuxConfig.swift in Sources */, ED6CB3935B15F30A182ED6D0 /* LoadAwareAssembly.swift in Sources */, D9F132E4A6F6BC2BDD5DFCAA /* ModulesSpec.swift in Sources */, + CD73B9D422F239A6004BB84E /* LazySpec.swift in Sources */, A453A5A7E0EC0FE161AA34D5 /* OptionalsSpec.swift in Sources */, C76374CAFE7C2BCCE52F1BB1 /* Person.swift in Sources */, - 4954CBB07E38E98752AC3347 /* ProviderSpec.swift in Sources */, + CD73B9CE22F239A6004BB84E /* ContainerSpec.Arguments.swift in Sources */, 2F664F8534CA1D92ED2F81E2 /* RetrievalSpec.swift in Sources */, + CD73B9D522F239A6004BB84E /* ProviderSpec.swift in Sources */, + CD73B9D622F239A6004BB84E /* SynchronizedResolverSpec.swift in Sources */, + CD73B9D322F239A6004BB84E /* ContainerSpec.TypeForwarding.swift in Sources */, 31729A1E5F50EF30FDD427AD /* ScopesSpec.swift in Sources */, 0CE158916595980A7C8272D3 /* SingletonSpec.swift in Sources */, 0720BEA814AD514378380ACB /* StandardScopeRegistrySpec.swift in Sources */, 3CEF021295AD9AF9BF26B71E /* SwinjectTreeBuilderSpec.swift in Sources */, - 546FF827DB6D42490D1CA439 /* SynchronizedResolverSpec.swift in Sources */, 09470890A74A5DDE7114891B /* TaggedTypeSpec.swift in Sources */, CB9E8D16D7A0620A1F7A32A3 /* TestModels.swift in Sources */, ); @@ -1552,37 +1552,37 @@ buildActionMask = 2147483647; files = ( D13208E63523A97A0B840283 /* Animal.swift in Sources */, - 2AA60B7E6EBA9EC6BE92D7CB /* AssemblerSpec.swift in Sources */, + CD73B9BA22F239A4004BB84E /* ContainerSpec.Circularity.swift in Sources */, 599C7F009F954CDA522244B3 /* BasicAssembly.swift in Sources */, + CD73B9B922F239A4004BB84E /* ContainerSpec.Behavior.swift in Sources */, 8E1E051646BBD6E38F4199C2 /* BehaviorFakes.swift in Sources */, 0207493E1CEE8456E91E3DAE /* BindingSpec.swift in Sources */, + CD73B9BC22F239A4004BB84E /* ContainerSpec.swift in Sources */, + CD73B9B722F239A4004BB84E /* Circularity.swift in Sources */, + CD73B9BB22F239A4004BB84E /* ContainerSpec.CustomStringConvertible.swift in Sources */, CD03917622EF610800DE44C4 /* OverrideSpec.swift in Sources */, 43A74237D8933572BAA0F3B4 /* Bridge.swift in Sources */, - C177D9C6969ADA38C1094F6D /* Circularity.swift in Sources */, - A70936B898139A6C5F83F616 /* ContainerSpec.Arguments.swift in Sources */, - A7DD08A60F12EC078BBE086F /* ContainerSpec.Behavior.swift in Sources */, - EB79ECF5C893F63B22355167 /* ContainerSpec.Circularity.swift in Sources */, - 54956014A1774DF8357B69E6 /* ContainerSpec.CustomStringConvertible.swift in Sources */, - 3C270A77DE4F1E6BC2F8E863 /* ContainerSpec.TypeForwarding.swift in Sources */, - CA5523B60E51EB98719CF1F8 /* ContainerSpec.swift in Sources */, 86CBC40FDC90E2A2051386C5 /* ContextSpec.swift in Sources */, + CD73B9B622F239A4004BB84E /* AssemblerSpec.swift in Sources */, 48D1568CB41BE4B6597FD535 /* Convenience.swift in Sources */, A59C6C434288333EDAF951C4 /* EmploymentAssembly.swift in Sources */, C38A2EBF4D1904E7D6989989 /* Food.swift in Sources */, AD214F3DBAB4F16C88322CAC /* InjectionSpec.swift in Sources */, - 0CD787EACEBFD1051D358E7D /* LazySpec.swift in Sources */, 70368EC369287B4EE767E929 /* LinuxConfig.swift in Sources */, A2D3B18BE38948A427B60BC5 /* LoadAwareAssembly.swift in Sources */, 55F2E72EA8C3564130F66946 /* ModulesSpec.swift in Sources */, + CD73B9BE22F239A4004BB84E /* LazySpec.swift in Sources */, F6EEF5F7B57DC0E44EF569A4 /* OptionalsSpec.swift in Sources */, BEEFBE87EB17D56BA8D47358 /* Person.swift in Sources */, - 48F40377D116C6B1B786C329 /* ProviderSpec.swift in Sources */, + CD73B9B822F239A4004BB84E /* ContainerSpec.Arguments.swift in Sources */, 06CD85528AABB15BDFBF3166 /* RetrievalSpec.swift in Sources */, + CD73B9BF22F239A4004BB84E /* ProviderSpec.swift in Sources */, + CD73B9C022F239A4004BB84E /* SynchronizedResolverSpec.swift in Sources */, + CD73B9BD22F239A4004BB84E /* ContainerSpec.TypeForwarding.swift in Sources */, EA0D19F7DF0355C774B0F40B /* ScopesSpec.swift in Sources */, 980FED1DBC62B65597E2828B /* SingletonSpec.swift in Sources */, 0B61DC733616A8ED4ED77FA7 /* StandardScopeRegistrySpec.swift in Sources */, 233F3E25FF0B51A3E6611F58 /* SwinjectTreeBuilderSpec.swift in Sources */, - 890CCD2800597F6FB7C6FD31 /* SynchronizedResolverSpec.swift in Sources */, 24114725AE1A834C6E3118F7 /* TaggedTypeSpec.swift in Sources */, 6034CF5459D96497AF36E4B6 /* TestModels.swift in Sources */, ); From 5a045b8ef874f77971fd8850a90e231d63882b9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Thu, 1 Aug 2019 21:10:15 +0200 Subject: [PATCH 177/239] Make type forwarding work again --- .../2.0 API/Container+TypeForwarding.swift | 18 ++++++----- Sources/2.0 API/Container.swift | 31 ++++++++++++------- Sources/2.0 API/ServiceEntry.swift | 10 ++---- Sources/Core/Swinject.swift | 6 ++-- Sources/Core/TypeDescriptor.swift | 8 +++++ 5 files changed, 43 insertions(+), 30 deletions(-) diff --git a/Sources/2.0 API/Container+TypeForwarding.swift b/Sources/2.0 API/Container+TypeForwarding.swift index de9cea5a..d93c5ff6 100644 --- a/Sources/2.0 API/Container+TypeForwarding.swift +++ b/Sources/2.0 API/Container+TypeForwarding.swift @@ -19,13 +19,15 @@ extension Container { /// - name: A registration name, which is used to differentiate from other registrations of the same `type` /// - service: ServiceEntry which should be used for resolution of `type` public func forward(_ type: T.Type, name: String? = nil, to service: ServiceEntry) { - if let name = name { - service.forwardedDescriptors.append(tagged(type, with: name)) - } else { - service.forwardedDescriptors.append(plain(type)) - } - behaviors.forEach { - $0.container(self, didRegisterType: T.self, toService: service, withName: name) - } + addBinding( + type: type, + key: BindingKey( + descriptor: named(T.self, name: name), + contextType: service.key.contextType, + argumentType: service.key.argumentType + ), + name: name, + entry: service + ) } } diff --git a/Sources/2.0 API/Container.swift b/Sources/2.0 API/Container.swift index c425b40e..7a96c0ab 100644 --- a/Sources/2.0 API/Container.swift +++ b/Sources/2.0 API/Container.swift @@ -24,18 +24,18 @@ public final class Container { let parent: Container? let defaultScope: AnyScope? let defaultMakeRef: ReferenceMaker - var bindings = [Binding & CustomStringConvertible]() + var bindings = [BindingKey: Binding]() var behaviors = [Behavior]() var swinject: Swinject { return Swinject( - tree: SwinjectTree( + tree: SwinjectTree(bindings: [], modules: [], translators: []), + container: SwinjectContainer( bindings: allBindings, - modules: [], translators: [registerContextTranslator(from: Graph.self) { $0.container }] ), - allowsSilentOverride: true + context: () ) } - var allBindings: [Binding] { - return bindings + (parent?.allBindings ?? []) + var allBindings: [BindingKey: Binding] { + return bindings.merging(parent?.allBindings ?? [:]) { mine, _ in mine } } /// Instantiates a `Container` @@ -90,7 +90,7 @@ public final class Container { /// Removes all registrations in the container. public func removeAll() { - bindings = [] + bindings = [:] registry.clear() } @@ -127,9 +127,13 @@ public final class Container { } func addEntry(_ entry: ServiceEntry, with name: String?) { - bindings.append(entry) + addBinding(type: Service.self, key: entry.key, name: name, entry: entry) + } + + func addBinding(type _: T.Type, key: BindingKey, name: String?, entry: ServiceEntry) { + bindings[key] = entry behaviors.forEach { - $0.container(self, didRegisterType: Service.self, toService: entry, withName: name) + $0.container(self, didRegisterType: T.self, toService: entry, withName: name) } } } @@ -139,7 +143,7 @@ public final class Container { extension Container: CustomStringConvertible { public var description: String { return "[" - + bindings.map { "\n { \($0.description) }" }.sorted().joined(separator: ",") + + bindings.values.map { "\n { \($0) }" }.sorted().joined(separator: ",") + "\n]" } } @@ -150,6 +154,11 @@ extension Container: Resolver { public func resolve( _ request: InstanceRequest ) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { - return try swinject.on(Graph(on: self)).resolve(request) + do { + return try swinject.on(Graph(on: self)).resolve(request) + } catch { + print(error) + throw error + } } } diff --git a/Sources/2.0 API/ServiceEntry.swift b/Sources/2.0 API/ServiceEntry.swift index 7b8a5834..83cf3748 100644 --- a/Sources/2.0 API/ServiceEntry.swift +++ b/Sources/2.0 API/ServiceEntry.swift @@ -99,13 +99,7 @@ extension ServiceEntry: Binding { public var key: BindingKey { return BindingKey( - descriptor: { - if let name = name { - return tagged(Service.self, with: name) - } else { - return plain(Service.self) - } - }(), + descriptor: named(Service.self, name: name), contextType: scope?.contextType ?? Any.self, argumentType: argumentType ) @@ -117,7 +111,7 @@ extension ServiceEntry: CustomStringConvertible { return [ "Service: \(Service.self)", name.map { "Name: \"\($0)\"" }, - "Factory: (\(factoryInputs)) -> Animal", + "Factory: (\(factoryInputs)) -> \(Service.self)", "ObjectScope: \(scopeDescription)", finalizers.isEmpty ? nil : "InitCompleted: Specified \(finalizers.count) closures", ].compactMap { $0 }.joined(separator: ", ") diff --git a/Sources/Core/Swinject.swift b/Sources/Core/Swinject.swift index cc18e6f9..cc537d71 100644 --- a/Sources/Core/Swinject.swift +++ b/Sources/Core/Swinject.swift @@ -18,7 +18,7 @@ public struct Swinject { ) } - private init(tree: SwinjectTree, container: SwinjectContainer, context: Context) { + init(tree: SwinjectTree, container: SwinjectContainer, context: Context) { self.tree = tree self.container = container self.context = context @@ -51,10 +51,10 @@ extension Swinject: Resolver { return try instance(from: binding, context: translator.translate(context), arg: request.argument) } - private func findTranslator(for request: AnyInstanceRequest, and binding: Binding) throws -> AnyContextTranslator { + private func findTranslator(for _: AnyInstanceRequest, and binding: Binding) throws -> AnyContextTranslator { return try (container.translators + [IdentityTranslator(for: contextType), ToAnyTranslator(for: contextType)]) .filter { $0.sourceType == contextType } - .filter { binding.key == request.key(forContextType: $0.targetType) } + .filter { binding.key.contextType == Any.self || binding.key.contextType == $0.targetType } .first ?? { throw SwinjectError() }() } diff --git a/Sources/Core/TypeDescriptor.swift b/Sources/Core/TypeDescriptor.swift index ea3de5ec..b62067ae 100644 --- a/Sources/Core/TypeDescriptor.swift +++ b/Sources/Core/TypeDescriptor.swift @@ -72,6 +72,14 @@ func plain(_: Type.Type) -> Tagged { return Tagged(tag: NoTag()) } +func named(_: Type.Type, name: String?) -> AnyTypeDescriptor { + if let name = name { + return tagged(Type.self, with: name) + } else { + return plain(Type.self) + } +} + protocol OptionalProtocol { static var wrappedType: Any.Type { get } init() From 2808ebaf471ba6f5576458462e855c059f9e4dc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Fri, 2 Aug 2019 17:13:19 +0200 Subject: [PATCH 178/239] Improve hash computation performance --- Sources/Core/Binding.swift | 4 ++-- Sources/Core/TypeDescriptor.swift | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/Core/Binding.swift b/Sources/Core/Binding.swift index b5cb218d..5508155b 100644 --- a/Sources/Core/Binding.swift +++ b/Sources/Core/Binding.swift @@ -15,8 +15,8 @@ public struct BindingKey: Hashable { public func hash(into hasher: inout Hasher) { descriptor.hash(into: &hasher) - String(describing: contextType).hash(into: &hasher) - String(describing: argumentType).hash(into: &hasher) + ObjectIdentifier(contextType).hash(into: &hasher) + ObjectIdentifier(argumentType).hash(into: &hasher) } public static func == (lhs: BindingKey, rhs: BindingKey) -> Bool { diff --git a/Sources/Core/TypeDescriptor.swift b/Sources/Core/TypeDescriptor.swift index b62067ae..fdb4f4fb 100644 --- a/Sources/Core/TypeDescriptor.swift +++ b/Sources/Core/TypeDescriptor.swift @@ -47,7 +47,7 @@ struct Tagged: TypeDescriptor where Tag: Hashable { } func hash(into hasher: inout Hasher) { - hasher.combine(String(describing: hashedType)) + hasher.combine(ObjectIdentifier(hashedType)) hasher.combine(tag) } From bafe98c1a4d70a68b8234da28860d3d4ae0abee5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Fri, 2 Aug 2019 18:23:45 +0200 Subject: [PATCH 179/239] Speed up binding key equality computation --- Sources/2.0 API/Container.swift | 7 +--- Sources/Core/Binding.swift | 10 ++--- Sources/Core/ScopeRegistryKey.swift | 6 +-- Sources/Core/TypeDescriptor.swift | 60 ++++++++++++++------------- Swinject.xcodeproj/project.pbxproj | 10 ----- Tests/LinuxConfig.swift | 1 - Tests/Unit Specs/TaggedTypeSpec.swift | 37 ----------------- 7 files changed, 36 insertions(+), 95 deletions(-) delete mode 100644 Tests/Unit Specs/TaggedTypeSpec.swift diff --git a/Sources/2.0 API/Container.swift b/Sources/2.0 API/Container.swift index 7a96c0ab..6f1bf34c 100644 --- a/Sources/2.0 API/Container.swift +++ b/Sources/2.0 API/Container.swift @@ -154,11 +154,6 @@ extension Container: Resolver { public func resolve( _ request: InstanceRequest ) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { - do { - return try swinject.on(Graph(on: self)).resolve(request) - } catch { - print(error) - throw error - } + return try swinject.on(Graph(on: self)).resolve(request) } } diff --git a/Sources/Core/Binding.swift b/Sources/Core/Binding.swift index 5508155b..cc5d7717 100644 --- a/Sources/Core/Binding.swift +++ b/Sources/Core/Binding.swift @@ -7,12 +7,6 @@ public struct BindingKey: Hashable { let contextType: Any.Type let argumentType: Any.Type - func matches(_ other: BindingKey) -> Bool { - return descriptor.matches(other.descriptor) - && contextType == other.contextType - && argumentType == other.argumentType - } - public func hash(into hasher: inout Hasher) { descriptor.hash(into: &hasher) ObjectIdentifier(contextType).hash(into: &hasher) @@ -20,7 +14,9 @@ public struct BindingKey: Hashable { } public static func == (lhs: BindingKey, rhs: BindingKey) -> Bool { - return lhs.matches(rhs) || rhs.matches(lhs) + return lhs.descriptor.isEqual(to: rhs.descriptor) + && lhs.contextType == rhs.contextType + && lhs.argumentType == rhs.argumentType } } diff --git a/Sources/Core/ScopeRegistryKey.swift b/Sources/Core/ScopeRegistryKey.swift index f83f2e2c..58addfa6 100644 --- a/Sources/Core/ScopeRegistryKey.swift +++ b/Sources/Core/ScopeRegistryKey.swift @@ -9,11 +9,7 @@ public struct ScopeRegistryKey { extension ScopeRegistryKey: Hashable { public static func == (lhs: ScopeRegistryKey, rhs: ScopeRegistryKey) -> Bool { - return areDescriptorsEqual(lhs.descriptor, rhs.descriptor) && areArgumentsEqual(lhs.argument, rhs.argument) - } - - private static func areDescriptorsEqual(_ lhs: AnyTypeDescriptor, _ rhs: AnyTypeDescriptor) -> Bool { - return lhs.matches(rhs) && rhs.matches(lhs) + return lhs.descriptor.isEqual(to: rhs.descriptor) && areArgumentsEqual(lhs.argument, rhs.argument) } private static func areArgumentsEqual(_ lhs: Any, _ rhs: Any) -> Bool { diff --git a/Sources/Core/TypeDescriptor.swift b/Sources/Core/TypeDescriptor.swift index fdb4f4fb..ba5ffdad 100644 --- a/Sources/Core/TypeDescriptor.swift +++ b/Sources/Core/TypeDescriptor.swift @@ -2,7 +2,12 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -public protocol AnyTypeDescriptor: Matchable {} +public protocol AnyTypeDescriptor { + var anyTag: Any { get } + var rootType: Any.Type { get } + func isEqual(to other: AnyTypeDescriptor) -> Bool + func hash(into hasher: inout Hasher) +} public protocol TypeDescriptor: AnyTypeDescriptor { associatedtype BaseType @@ -11,12 +16,16 @@ public protocol TypeDescriptor: AnyTypeDescriptor { public struct SomeTypeDescriptor: TypeDescriptor, Opaque { let actual: AnyTypeDescriptor - public func matches(_ other: Any) -> Bool { - if let other = other as? AnyOpaque { - return actual.matches(other.anyActual) - } else { - return actual.matches(other) - } + public var anyTag: Any { + return actual.anyTag + } + + public var rootType: Any.Type { + return actual.rootType + } + + public func isEqual(to other: AnyTypeDescriptor) -> Bool { + return actual.isEqual(to: other) } public func hash(into hasher: inout Hasher) { @@ -32,44 +41,37 @@ struct NoTag: Hashable {} struct Tagged: TypeDescriptor where Tag: Hashable { let tag: Tag + let rootType: Any.Type - func matches(_ other: Any) -> Bool { - if let other = other as? Tagged { - return tag == other.tag - } - if let other = other as? Tagged { - return tag == other.tag - } - if let other = other as? Tagged { - return tag == other.tag + var anyTag: Any { return tag } + + func isEqual(to other: AnyTypeDescriptor) -> Bool { + if let otherTag = other.anyTag as? Tag { + return rootType == other.rootType && tag == otherTag } return false } func hash(into hasher: inout Hasher) { - hasher.combine(ObjectIdentifier(hashedType)) + hasher.combine(ObjectIdentifier(rootType)) hasher.combine(tag) } +} - var hashedType: Any.Type { - if let optional = BaseType.self as? OptionalProtocol.Type { +func tagged(_: Type.Type, with tag: Tag) -> Tagged where Tag: Hashable { + return Tagged(tag: tag, rootType: { + if let optional = Type.self as? OptionalProtocol.Type { if let doubleOptional = optional.wrappedType as? OptionalProtocol.Type { return doubleOptional.wrappedType - } else { - return optional.wrappedType } - } else { - return BaseType.self + return optional.wrappedType } - } -} - -func tagged(_: Type.Type, with tag: Tag) -> Tagged where Tag: Hashable { - return Tagged(tag: tag) + return Type.self + }()) } func plain(_: Type.Type) -> Tagged { - return Tagged(tag: NoTag()) + return tagged(Type.self, with: NoTag()) } func named(_: Type.Type, name: String?) -> AnyTypeDescriptor { diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 6b454af7..a3fdc7c1 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -20,7 +20,6 @@ 06F4CAB352B4F623FF7BD885 /* ScopeRegistryKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */; }; 0720BEA814AD514378380ACB /* StandardScopeRegistrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */; }; 0781579818FC4A2CA1CD3CAE /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */; }; - 09470890A74A5DDE7114891B /* TaggedTypeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */; }; 0B61DC733616A8ED4ED77FA7 /* StandardScopeRegistrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */; }; 0CE1126436F680F9684837E4 /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; 0CE158916595980A7C8272D3 /* SingletonSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46F05CC591903E2B04B6D8ED /* SingletonSpec.swift */; }; @@ -39,7 +38,6 @@ 1ED6BD68D92F4FE60978EF22 /* Container+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDA78290D6D60BD0B808571F /* Container+Logging.swift */; }; 21285CED416F1317E993397A /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59A3946B59EB4D787CCE9F2 /* Container+Registration.swift */; }; 233F3E25FF0B51A3E6611F58 /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; - 24114725AE1A834C6E3118F7 /* TaggedTypeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */; }; 2615FC1C92B7E381116B9E57 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; 26C4C6118D189E8813ABD5A2 /* Quick.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = C765B92B00C0AC8625BB4AC9 /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 283C77045DA55C2134EC9C48 /* Container+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F446D6BD4C44E16A1D608BFB /* Container+TypeForwarding.swift */; }; @@ -162,7 +160,6 @@ 999AF7221D3F2E1F83C3ACB1 /* Container+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDA78290D6D60BD0B808571F /* Container+Logging.swift */; }; 99C5D861B16FAFAD3F9E28C5 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */; }; 9A2A6978519F2BBA97DA6EA6 /* BindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E59A67F3548663368788B17 /* BindingSpec.swift */; }; - 9AD60A86D5A0DF4513C1EA8D /* TaggedTypeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */; }; 9C15BE01C1EA41061CDB7918 /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C074BAC560F277E806146C60 /* SimpleBinding.swift */; }; 9CCAB8EE342CCC8D2FB187C1 /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */; }; 9CEE20BD42795D5E5F39BF20 /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; @@ -172,7 +169,6 @@ A308578B99D33C7E33632E85 /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; A3BFFED76688F149FBAF7C53 /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EA566CD336DB8343ADFAF9B /* BehaviorFakes.swift */; }; A453A5A7E0EC0FE161AA34D5 /* OptionalsSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50D6F2639990DD5BAD9578B0 /* OptionalsSpec.swift */; }; - A5302886A31C90F38512B88E /* TaggedTypeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */; }; A53B5A8E2188F8C4A3F29C2E /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BC5108ED11A3A3084D864CC /* Animal.swift */; }; A59C6C434288333EDAF951C4 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */; }; A5E4C79F89E1A8AB3A4D8D6E /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59A3946B59EB4D787CCE9F2 /* Container+Registration.swift */; }; @@ -469,7 +465,6 @@ 38615FC8EEB466C5C1EAD21C /* ServiceEntry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServiceEntry.swift; sourceTree = ""; }; 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Swinject+Builder.swift"; sourceTree = ""; }; 38BCCF3F950869BD1891F7A8 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaggedTypeSpec.swift; sourceTree = ""; }; 42490D1D0C395951243F5CFF /* Container.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.swift; sourceTree = ""; }; 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmploymentAssembly.swift; sourceTree = ""; }; 46F05CC591903E2B04B6D8ED /* SingletonSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingletonSpec.swift; sourceTree = ""; }; @@ -610,7 +605,6 @@ children = ( BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */, 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */, - 3AC3AF9B0B132A8597D6F3FD /* TaggedTypeSpec.swift */, ); path = "Unit Specs"; sourceTree = ""; @@ -1460,7 +1454,6 @@ 30D247E8083858C233B92908 /* SingletonSpec.swift in Sources */, 72217E47D83C3CA6D97640B9 /* StandardScopeRegistrySpec.swift in Sources */, 640F7A55D9A671FA112C8083 /* SwinjectTreeBuilderSpec.swift in Sources */, - 9AD60A86D5A0DF4513C1EA8D /* TaggedTypeSpec.swift in Sources */, 778D9AB6470D4280254AC140 /* TestModels.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1501,7 +1494,6 @@ B65DE0B0562540CC8CEC48F3 /* SingletonSpec.swift in Sources */, C952D5869D87743297968E9A /* StandardScopeRegistrySpec.swift in Sources */, A308578B99D33C7E33632E85 /* SwinjectTreeBuilderSpec.swift in Sources */, - A5302886A31C90F38512B88E /* TaggedTypeSpec.swift in Sources */, 2615FC1C92B7E381116B9E57 /* TestModels.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1542,7 +1534,6 @@ 0CE158916595980A7C8272D3 /* SingletonSpec.swift in Sources */, 0720BEA814AD514378380ACB /* StandardScopeRegistrySpec.swift in Sources */, 3CEF021295AD9AF9BF26B71E /* SwinjectTreeBuilderSpec.swift in Sources */, - 09470890A74A5DDE7114891B /* TaggedTypeSpec.swift in Sources */, CB9E8D16D7A0620A1F7A32A3 /* TestModels.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1583,7 +1574,6 @@ 980FED1DBC62B65597E2828B /* SingletonSpec.swift in Sources */, 0B61DC733616A8ED4ED77FA7 /* StandardScopeRegistrySpec.swift in Sources */, 233F3E25FF0B51A3E6611F58 /* SwinjectTreeBuilderSpec.swift in Sources */, - 24114725AE1A834C6E3118F7 /* TaggedTypeSpec.swift in Sources */, 6034CF5459D96497AF36E4B6 /* TestModels.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Tests/LinuxConfig.swift b/Tests/LinuxConfig.swift index 6c9b4f9c..13e8a23f 100644 --- a/Tests/LinuxConfig.swift +++ b/Tests/LinuxConfig.swift @@ -28,5 +28,4 @@ let allSpecs: [QuickSpec.Type] = [ // Unit Specs StandardScopeRegistrySpec.self, SwinjectTreeBuilderSpec.self, - TaggedTypeSpec.self, ] diff --git a/Tests/Unit Specs/TaggedTypeSpec.swift b/Tests/Unit Specs/TaggedTypeSpec.swift deleted file mode 100644 index 680e4b91..00000000 --- a/Tests/Unit Specs/TaggedTypeSpec.swift +++ /dev/null @@ -1,37 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -import Nimble -import Quick -@testable import Swinject - -class TaggedTypeSpec: QuickSpec { override func spec() { - describe("hashValue") { - it("is different for different types") { - let first = plain(Int.self) - let second = plain(String.self) - expect(first.hashValue) != second.hashValue - } - it("is different for different tags") { - let first = tagged(Int.self, with: "tag1") - let second = tagged(Int.self, with: "tag2") - expect(first.hashValue) != second.hashValue - } - it("is same for the same descriptor") { - let first = tagged(Int.self, with: "tag1") - let second = tagged(Int.self, with: "tag1") - expect(first.hashValue) == second.hashValue - } - it("is same for the type and it's optional") { - let first = plain(Int.self) - let second = plain(Int?.self) - expect(first.hashValue) == second.hashValue - } - it("is same for the type and it's double optional") { - let first = plain(Int.self) - let second = plain(Int??.self) - expect(first.hashValue) == second.hashValue - } - } -} } From d1e2118c71fa5a135a57b06a9d4ddecc9113a038 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sat, 3 Aug 2019 11:20:19 +0200 Subject: [PATCH 180/239] Fix scope registry key matching --- Sources/Core/ScopeRegistryKey.swift | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Sources/Core/ScopeRegistryKey.swift b/Sources/Core/ScopeRegistryKey.swift index 58addfa6..5f6b1d65 100644 --- a/Sources/Core/ScopeRegistryKey.swift +++ b/Sources/Core/ScopeRegistryKey.swift @@ -14,12 +14,9 @@ extension ScopeRegistryKey: Hashable { private static func areArgumentsEqual(_ lhs: Any, _ rhs: Any) -> Bool { switch (lhs, rhs) { - case is (Void, Void): - return true - case let (lhs as Matchable, rhs as Matchable): - return lhs.matches(rhs) && rhs.matches(lhs) - default: - return false + case let (lhs as Matchable, _): return lhs.matches(rhs) + case let (_, rhs as Matchable): return rhs.matches(lhs) + default: return true } } From b635ebf01c2ac248a4b17739de4a35367372c680 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sat, 3 Aug 2019 11:48:59 +0200 Subject: [PATCH 181/239] Remove redundant code --- Sources/2.0 API/Container.swift | 4 +--- Sources/Core/InstanceRequest.swift | 6 +++--- Sources/Core/Resolver.swift | 10 +++------- Sources/Core/Swinject.swift | 8 +++----- Sources/Core/TypeDescriptor.swift | 30 +----------------------------- Tests/Support/Bridge.swift | 13 ++----------- 6 files changed, 13 insertions(+), 58 deletions(-) diff --git a/Sources/2.0 API/Container.swift b/Sources/2.0 API/Container.swift index 6f1bf34c..7797336c 100644 --- a/Sources/2.0 API/Container.swift +++ b/Sources/2.0 API/Container.swift @@ -151,9 +151,7 @@ extension Container: CustomStringConvertible { // MARK: Resolver extension Container: Resolver { - public func resolve( - _ request: InstanceRequest - ) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { + public func resolve(_ request: InstanceRequest) throws -> Type { return try swinject.on(Graph(on: self)).resolve(request) } } diff --git a/Sources/Core/InstanceRequest.swift b/Sources/Core/InstanceRequest.swift index db2012ca..8058aaa8 100644 --- a/Sources/Core/InstanceRequest.swift +++ b/Sources/Core/InstanceRequest.swift @@ -8,17 +8,17 @@ protocol AnyInstanceRequest { var argumentType: Any.Type { get } } -public struct InstanceRequest: AnyInstanceRequest where Descriptor: TypeDescriptor { +public struct InstanceRequest: AnyInstanceRequest { let argumentType: Any.Type = Argument.self let descriptor: AnyTypeDescriptor let argument: Any } -func request( +func request( type: Type.Type = Type.self, tag: Tag, arg: Argument -) -> InstanceRequest, Argument> { +) -> InstanceRequest { return InstanceRequest(descriptor: tagged(type, with: tag), argument: arg) } diff --git a/Sources/Core/Resolver.swift b/Sources/Core/Resolver.swift index c99a6a77..3b92e722 100644 --- a/Sources/Core/Resolver.swift +++ b/Sources/Core/Resolver.swift @@ -3,19 +3,15 @@ // public protocol Resolver { - func resolve( - _ request: InstanceRequest - ) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor + func resolve(_ request: InstanceRequest) throws -> Type } public protocol SwinjectAware: Resolver { var swinject: Resolver { get } } -extension SwinjectAware { - public func resolve( - _ request: InstanceRequest - ) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { +public extension SwinjectAware { + func resolve(_ request: InstanceRequest) throws -> Type { return try swinject.resolve(request) } } diff --git a/Sources/Core/Swinject.swift b/Sources/Core/Swinject.swift index cc537d71..c6906741 100644 --- a/Sources/Core/Swinject.swift +++ b/Sources/Core/Swinject.swift @@ -33,16 +33,14 @@ extension Swinject { } extension Swinject: Resolver { - public func resolve( - _ request: InstanceRequest - ) throws -> Descriptor.BaseType where Descriptor: TypeDescriptor { + public func resolve(_ request: InstanceRequest) throws -> Type { var binding: Binding! // FIXME: Refactor this do { binding = try findBinding(for: request) } catch let error as NoBinding { - if let optional = Descriptor.BaseType.self as? OptionalProtocol.Type { - return optional.init() as! Descriptor.BaseType + if let optional = Type.self as? OptionalProtocol.Type { + return optional.init() as! Type } else { throw error } diff --git a/Sources/Core/TypeDescriptor.swift b/Sources/Core/TypeDescriptor.swift index ba5ffdad..d3736ce1 100644 --- a/Sources/Core/TypeDescriptor.swift +++ b/Sources/Core/TypeDescriptor.swift @@ -9,37 +9,9 @@ public protocol AnyTypeDescriptor { func hash(into hasher: inout Hasher) } -public protocol TypeDescriptor: AnyTypeDescriptor { - associatedtype BaseType -} - -public struct SomeTypeDescriptor: TypeDescriptor, Opaque { - let actual: AnyTypeDescriptor - - public var anyTag: Any { - return actual.anyTag - } - - public var rootType: Any.Type { - return actual.rootType - } - - public func isEqual(to other: AnyTypeDescriptor) -> Bool { - return actual.isEqual(to: other) - } - - public func hash(into hasher: inout Hasher) { - actual.hash(into: &hasher) - } -} - -public extension TypeDescriptor { - var opaque: SomeTypeDescriptor { return SomeTypeDescriptor(actual: self) } -} - struct NoTag: Hashable {} -struct Tagged: TypeDescriptor where Tag: Hashable { +struct Tagged: AnyTypeDescriptor where Tag: Hashable { let tag: Tag let rootType: Any.Type diff --git a/Tests/Support/Bridge.swift b/Tests/Support/Bridge.swift index d9ef5164..c05aa286 100644 --- a/Tests/Support/Bridge.swift +++ b/Tests/Support/Bridge.swift @@ -3,22 +3,13 @@ // import func Swinject.bind -import struct Swinject.SomeTypeDescriptor import struct Swinject.TypeBinder -import protocol Swinject.TypeDescriptor // Original Swinject functions conflict with QuickSpec's instance methods -func bbind( - _: Type.Type, - overrides: Bool = false -) -> TypeBinder { +func bbind(_: Type.Type, overrides: Bool = false) -> TypeBinder { return bind(Type.self, overrides: overrides) } -func bbind( - _: Type.Type, - tagged tag: Tag, - overrides: Bool = false -) -> TypeBinder where Tag: Hashable { +func bbind(_: Type.Type, tagged tag: Tag, overrides: Bool = false) -> TypeBinder where Tag: Hashable { return bind(Type.self, tagged: tag, overrides: overrides) } From 4cf35f2ee2da70539fd3660a9c9c73de15f9bd2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sat, 3 Aug 2019 17:01:51 +0200 Subject: [PATCH 182/239] Implement lazy provider --- Sources/2.0 API/Container.swift | 2 +- Sources/2.0 API/InstanceWrapper.swift | 6 +- Sources/Core/InstanceProvider.swift | 46 ++++ Sources/Core/InstanceRequest.swift | 4 +- Sources/Core/Resolver.swift | 4 +- Sources/Core/Swinject.swift | 9 +- Swinject.xcodeproj/project.pbxproj | 20 ++ Tests/2.0 API/LazySpec.swift | 197 +++++++++--------- Tests/3.0 API/InstanceProviderSpec.swift | 73 +++++++ Tests/LinuxConfig.swift | 1 + Tests/Support/Legacy/EmploymentAssembly.swift | 42 ++-- 11 files changed, 275 insertions(+), 129 deletions(-) create mode 100644 Sources/Core/InstanceProvider.swift create mode 100644 Tests/3.0 API/InstanceProviderSpec.swift diff --git a/Sources/2.0 API/Container.swift b/Sources/2.0 API/Container.swift index 7797336c..e4633aab 100644 --- a/Sources/2.0 API/Container.swift +++ b/Sources/2.0 API/Container.swift @@ -151,7 +151,7 @@ extension Container: CustomStringConvertible { // MARK: Resolver extension Container: Resolver { - public func resolve(_ request: InstanceRequest) throws -> Type { + public func resolve(_ request: InstanceRequest) throws -> Type { return try swinject.on(Graph(on: self)).resolve(request) } } diff --git a/Sources/2.0 API/InstanceWrapper.swift b/Sources/2.0 API/InstanceWrapper.swift index 64c2de8e..e7a17c59 100644 --- a/Sources/2.0 API/InstanceWrapper.swift +++ b/Sources/2.0 API/InstanceWrapper.swift @@ -5,11 +5,11 @@ /// Wrapper to enable delayed dependency instantiation. /// `Lazy` does not need to be explicitly registered into the `Container` - resolution will work /// as long as there is a registration for the `Type`. -public final class Lazy { +public extension Lazy { /// Getter for the wrapped object. /// It will be resolved from the `Container` when first accessed, all other calls will return the same instance. - public var instance: Service { - fatalError() + var instance: Value { + mutating get { return wrappedValue } } } diff --git a/Sources/Core/InstanceProvider.swift b/Sources/Core/InstanceProvider.swift new file mode 100644 index 00000000..d3a4eedc --- /dev/null +++ b/Sources/Core/InstanceProvider.swift @@ -0,0 +1,46 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +protocol InstanceProvider { + init(resolver: Resolver, request: InstanceRequest) + static func transform(_ request: InstanceRequest) -> AnyInstanceRequest +} + +@propertyWrapper public enum Lazy { + case uninitialized(() -> Value) + case initialized(Value) + + public init(wrappedValue: @autoclosure @escaping () -> Value) { + self = .uninitialized(wrappedValue) + } + + public var wrappedValue: Value { + mutating get { + switch self { + case let .uninitialized(initializer): + let value = initializer() + self = .initialized(value) + return value + case let .initialized(value): + return value + } + } + set { + self = .initialized(newValue) + } + } +} + +extension Lazy: InstanceProvider { + init(resolver: Resolver, request: InstanceRequest) { + self.init(wrappedValue: try! resolver.instance( // swiftlint:disable:this force_try + tagged: request.descriptor.anyTag as! Tag, + arg: request.argument as! Argument + )) + } + + static func transform(_ aRequest: InstanceRequest) -> AnyInstanceRequest { + return request(type: Value.self, tag: aRequest.descriptor.anyTag as! Tag, arg: aRequest.argument as! Argument) + } +} diff --git a/Sources/Core/InstanceRequest.swift b/Sources/Core/InstanceRequest.swift index 8058aaa8..8abec036 100644 --- a/Sources/Core/InstanceRequest.swift +++ b/Sources/Core/InstanceRequest.swift @@ -8,7 +8,7 @@ protocol AnyInstanceRequest { var argumentType: Any.Type { get } } -public struct InstanceRequest: AnyInstanceRequest { +public struct InstanceRequest: AnyInstanceRequest where Tag: Hashable { let argumentType: Any.Type = Argument.self let descriptor: AnyTypeDescriptor let argument: Any @@ -18,7 +18,7 @@ func request( type: Type.Type = Type.self, tag: Tag, arg: Argument -) -> InstanceRequest { +) -> InstanceRequest { return InstanceRequest(descriptor: tagged(type, with: tag), argument: arg) } diff --git a/Sources/Core/Resolver.swift b/Sources/Core/Resolver.swift index 3b92e722..b7381138 100644 --- a/Sources/Core/Resolver.swift +++ b/Sources/Core/Resolver.swift @@ -3,7 +3,7 @@ // public protocol Resolver { - func resolve(_ request: InstanceRequest) throws -> Type + func resolve(_ request: InstanceRequest) throws -> Type } public protocol SwinjectAware: Resolver { @@ -11,7 +11,7 @@ public protocol SwinjectAware: Resolver { } public extension SwinjectAware { - func resolve(_ request: InstanceRequest) throws -> Type { + func resolve(_ request: InstanceRequest) throws -> Type { return try swinject.resolve(request) } } diff --git a/Sources/Core/Swinject.swift b/Sources/Core/Swinject.swift index c6906741..2234aa09 100644 --- a/Sources/Core/Swinject.swift +++ b/Sources/Core/Swinject.swift @@ -33,7 +33,7 @@ extension Swinject { } extension Swinject: Resolver { - public func resolve(_ request: InstanceRequest) throws -> Type { + public func resolve(_ request: InstanceRequest) throws -> Type { var binding: Binding! // FIXME: Refactor this do { @@ -41,9 +41,12 @@ extension Swinject: Resolver { } catch let error as NoBinding { if let optional = Type.self as? OptionalProtocol.Type { return optional.init() as! Type - } else { - throw error } + if let provider = Type.self as? InstanceProvider.Type { + _ = try findBinding(for: provider.transform(request)) + return provider.init(resolver: self, request: request) as! Type + } + throw error } let translator = try findTranslator(for: request, and: binding) return try instance(from: binding, context: translator.translate(context), arg: request.argument) diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index a3fdc7c1..df32bd72 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -230,6 +230,14 @@ CD367C0F22EF8A83008B3E82 /* SwinjectContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD367C0D22EF8A83008B3E82 /* SwinjectContainer.swift */; }; CD367C1022EF8A83008B3E82 /* SwinjectContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD367C0D22EF8A83008B3E82 /* SwinjectContainer.swift */; }; CD367C1122EF8A83008B3E82 /* SwinjectContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD367C0D22EF8A83008B3E82 /* SwinjectContainer.swift */; }; + CD68676022F5C60800F7D9E3 /* InstanceProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD68675F22F5C60800F7D9E3 /* InstanceProvider.swift */; }; + CD68676122F5C85B00F7D9E3 /* InstanceProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD68675F22F5C60800F7D9E3 /* InstanceProvider.swift */; }; + CD68676222F5C85B00F7D9E3 /* InstanceProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD68675F22F5C60800F7D9E3 /* InstanceProvider.swift */; }; + CD68676322F5C85B00F7D9E3 /* InstanceProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD68675F22F5C60800F7D9E3 /* InstanceProvider.swift */; }; + CD68676522F5CA5D00F7D9E3 /* InstanceProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD68676422F5CA5D00F7D9E3 /* InstanceProviderSpec.swift */; }; + CD68676622F5CA5D00F7D9E3 /* InstanceProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD68676422F5CA5D00F7D9E3 /* InstanceProviderSpec.swift */; }; + CD68676722F5CA5D00F7D9E3 /* InstanceProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD68676422F5CA5D00F7D9E3 /* InstanceProviderSpec.swift */; }; + CD68676822F5CA5D00F7D9E3 /* InstanceProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD68676422F5CA5D00F7D9E3 /* InstanceProviderSpec.swift */; }; CD73B9AB22F239A4004BB84E /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; CD73B9AC22F239A4004BB84E /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */; }; CD73B9AD22F239A4004BB84E /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; @@ -527,6 +535,8 @@ CC85CB215058F95C0BC190B1 /* Bridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bridge.swift; sourceTree = ""; }; CD03917322EF610800DE44C4 /* OverrideSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OverrideSpec.swift; sourceTree = ""; }; CD367C0D22EF8A83008B3E82 /* SwinjectContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectContainer.swift; sourceTree = ""; }; + CD68675F22F5C60800F7D9E3 /* InstanceProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceProvider.swift; sourceTree = ""; }; + CD68676422F5CA5D00F7D9E3 /* InstanceProviderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceProviderSpec.swift; sourceTree = ""; }; CDA78290D6D60BD0B808571F /* Container+Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Logging.swift"; sourceTree = ""; }; CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextSpec.swift; sourceTree = ""; }; @@ -736,6 +746,7 @@ 1D3C59E84B5FD0C13F487838 /* ScopesSpec.swift */, 46F05CC591903E2B04B6D8ED /* SingletonSpec.swift */, CD03917322EF610800DE44C4 /* OverrideSpec.swift */, + CD68676422F5CA5D00F7D9E3 /* InstanceProviderSpec.swift */, ); path = "3.0 API"; sourceTree = ""; @@ -832,6 +843,7 @@ CD367C0D22EF8A83008B3E82 /* SwinjectContainer.swift */, 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */, E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */, + CD68675F22F5C60800F7D9E3 /* InstanceProvider.swift */, ); path = Core; sourceTree = ""; @@ -1379,6 +1391,7 @@ AAD8D0551B8A26A9B22AECEC /* Container+Registration.swift in Sources */, 996CCFE825834C7D3236E742 /* Container+TypeForwarding.swift in Sources */, B2FAD41F7726502822AF913B /* Container.swift in Sources */, + CD68676122F5C85B00F7D9E3 /* InstanceProvider.swift in Sources */, 8B5927517B567B1DFAB5B935 /* ContextTranslator.swift in Sources */, 6C4D29A3FB54416D5E4D4C89 /* InstanceBuilder.swift in Sources */, 53EBF7A46EF65F2A8DAADC7A /* InstanceRequest.swift in Sources */, @@ -1422,6 +1435,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + CD68676522F5CA5D00F7D9E3 /* InstanceProviderSpec.swift in Sources */, BD08D3E155AFD841CFECA0AD /* Animal.swift in Sources */, CD73B9AF22F239A4004BB84E /* ContainerSpec.Circularity.swift in Sources */, DD29D2E60DA979D61F32A39A /* BasicAssembly.swift in Sources */, @@ -1462,6 +1476,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + CD68676622F5CA5D00F7D9E3 /* InstanceProviderSpec.swift in Sources */, A6EECC339FA54CA0BBFF4146 /* Animal.swift in Sources */, CD73B9C522F239A5004BB84E /* ContainerSpec.Circularity.swift in Sources */, 401592294E5D528379BE1AB2 /* BasicAssembly.swift in Sources */, @@ -1502,6 +1517,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + CD68676822F5CA5D00F7D9E3 /* InstanceProviderSpec.swift in Sources */, A53B5A8E2188F8C4A3F29C2E /* Animal.swift in Sources */, CD73B9D022F239A6004BB84E /* ContainerSpec.Circularity.swift in Sources */, 03122D1B2EA65C89ADC78EC7 /* BasicAssembly.swift in Sources */, @@ -1542,6 +1558,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + CD68676722F5CA5D00F7D9E3 /* InstanceProviderSpec.swift in Sources */, D13208E63523A97A0B840283 /* Animal.swift in Sources */, CD73B9BA22F239A4004BB84E /* ContainerSpec.Circularity.swift in Sources */, 599C7F009F954CDA522244B3 /* BasicAssembly.swift in Sources */, @@ -1591,6 +1608,7 @@ A5E4C79F89E1A8AB3A4D8D6E /* Container+Registration.swift in Sources */, BD9B57E26722C80B7EF990DB /* Container+TypeForwarding.swift in Sources */, DB74F17CDFF4886B9C38AD14 /* Container.swift in Sources */, + CD68676222F5C85B00F7D9E3 /* InstanceProvider.swift in Sources */, DD5E3AF2B5FCE5E81EBDF606 /* ContextTranslator.swift in Sources */, 7F9686F3669BF35E5AC970B3 /* InstanceBuilder.swift in Sources */, 9DEAC620F2F00D0DDD3B5D3E /* InstanceRequest.swift in Sources */, @@ -1633,6 +1651,7 @@ CB0B308F3D3A831A28127462 /* Container+Registration.swift in Sources */, 283C77045DA55C2134EC9C48 /* Container+TypeForwarding.swift in Sources */, 58ABEE0321A3061048B65EA2 /* Container.swift in Sources */, + CD68676322F5C85B00F7D9E3 /* InstanceProvider.swift in Sources */, F06DEB671A4B85ABB0E96E51 /* ContextTranslator.swift in Sources */, DBEFC5C6A51FCEBF9E4F70EE /* InstanceBuilder.swift in Sources */, CECF5BD14BCDF5248771A06A /* InstanceRequest.swift in Sources */, @@ -1684,6 +1703,7 @@ 658C98B4AA17C58E8556E0AC /* Opaque.swift in Sources */, 0509EE8D41BF354EB91ACC80 /* Reference.swift in Sources */, CBE63031F33303F3E503CEF2 /* Resolver+Injection.swift in Sources */, + CD68676022F5C60800F7D9E3 /* InstanceProvider.swift in Sources */, 41C7340BFD2EB66359772733 /* Resolver+LegacyApi.swift in Sources */, BE94EF7BCF976A703F961389 /* Resolver.swift in Sources */, 96EA0A5DF33F025EBE0B67D2 /* Scope.swift in Sources */, diff --git a/Tests/2.0 API/LazySpec.swift b/Tests/2.0 API/LazySpec.swift index 8b0d5791..8bb9c1c4 100644 --- a/Tests/2.0 API/LazySpec.swift +++ b/Tests/2.0 API/LazySpec.swift @@ -7,103 +7,102 @@ import Quick import Swinject class LazySpec: QuickSpec { - // TODO: Enable Lazy injection -// override func spec() { -// var container: Container! -// beforeEach { -// container = Container() -// } -// -// describe("instance production") { -// it("provides instance from container") { -// container.register(Animal.self) { _ in Dog() } -// let lazy = container.resolve(Lazy.self) -// expect(lazy?.instance is Dog).to(beTrue()) -// } -// it("does not create instance until requested") { -// var created = false -// container.register(Animal.self) { _ in created = true; return Dog() } -// -// _ = container.resolve(Lazy.self) -// -// expect(created).to(beFalse()) -// } -// it("resolves instance from container only once") { -// var created = 0 -// container.register(Animal.self) { _ in created += 1; return Dog() } -// -// let lazy = container.resolve(Lazy.self) -// _ = lazy?.instance -// _ = lazy?.instance -// -// expect(created) == 1 -// } -// it("does not resolve lazy if base type is not registered") { -// let lazy = container.resolve(Lazy.self) -// expect(lazy).to(beNil()) -// } -// } -// describe("object scopes") { -// context("in transient scope") { -// it("always produces different instance for related objects") { -// EmploymentAssembly(scope: .transient).assemble(container: container) -// let employer = container.resolve(Employer.self)! -// expect(employer.lazyCustomer.instance).notTo(beIdenticalTo(employer.employee.lazyCustomer.instance)) -// expect(employer.lazyCustomer.instance).notTo(beIdenticalTo(employer.customer)) -// } -// } -// context("in container scope") { -// it("always produces the same instance for related objects") { -// EmploymentAssembly(scope: .container).assemble(container: container) -// let employer = container.resolve(Employer.self)! -// expect(employer.lazyCustomer.instance).to(beIdenticalTo(employer.employee.lazyCustomer.instance)) -// expect(employer.lazyCustomer.instance).to(beIdenticalTo(employer.customer)) -// } -// } -// context("in graph scope") { -// it("always produces the same instance for related objects") { -// EmploymentAssembly(scope: .graph).assemble(container: container) -// let employer = container.resolve(Employer.self)! -// expect(employer.lazyCustomer.instance).to(beIdenticalTo(employer.employee.lazyCustomer.instance)) -// expect(employer.lazyCustomer.instance).to(beIdenticalTo(employer.customer)) -// } -// } -// } -// describe("complex registrations") { -// it("resolves lazy with arguments") { -// container.register(Dog.self) { (_, name, _: Int) in Dog(name: name) } -// let lazy = container.resolve(Lazy.self, arguments: "Hachi", 42) -// expect(lazy?.instance.name) == "Hachi" -// } -// it("resolves lazy with name") { -// container.register(Dog.self, name: "Hachi") { _ in Dog() } -// let lazy = container.resolve(Lazy.self, name: "Hachi") -// expect(lazy).notTo(beNil()) -// } -// it("does not resolve lazy with wrong name") { -// container.register(Dog.self, name: "Hachi") { _ in Dog() } -// let lazy = container.resolve(Lazy.self, name: "Mimi") -// expect(lazy).to(beNil()) -// } -// it("does resolve forwarded lazy type") { -// container.register(Dog.self) { _ in Dog() }.implements(Animal.self) -// let lazy = container.resolve(Lazy.self) -// expect(lazy).notTo(beNil()) -// } -// } -// describe("circular dependencies") { -// beforeEach { -// EmploymentAssembly(scope: .graph).assemble(container: container) -// } -// it("resolves dependencies to same instance") { -// let employer = container.resolve(Employer.self) -// expect(employer?.employee.employer) === employer -// expect(employer?.lazyEmployee.instance.employer) === employer -// } -// it("resolves circular dependencies for lazy instance") { -// let employee = container.resolve(Lazy.self) -// expect(employee?.instance.employer).notTo(beNil()) -// } -// } -// } + override func spec() { + var container: Container! + beforeEach { + container = Container() + } + + describe("instance production") { + it("provides instance from container") { + container.register(Animal.self) { _ in Dog() } + var lazy = container.resolve(Lazy.self) + expect(lazy?.instance is Dog).to(beTrue()) + } + it("does not create instance until requested") { + var created = false + container.register(Animal.self) { _ in created = true; return Dog() } + + _ = container.resolve(Lazy.self) + + expect(created).to(beFalse()) + } + it("resolves instance from container only once") { + var created = 0 + container.register(Animal.self) { _ in created += 1; return Dog() } + + var lazy = container.resolve(Lazy.self) + _ = lazy?.instance + _ = lazy?.instance + + expect(created) == 1 + } + it("does not resolve lazy if base type is not registered") { + let lazy = container.resolve(Lazy.self) + expect(lazy).to(beNil()) + } + } + describe("object scopes") { + context("in transient scope") { + it("always produces different instance for related objects") { + EmploymentAssembly(scope: .transient).assemble(container: container) + let employer = container.resolve(Employer.self)! + expect(employer.lazyCustomer.instance).notTo(beIdenticalTo(employer.employee.lazyCustomer.instance)) + expect(employer.lazyCustomer.instance).notTo(beIdenticalTo(employer.customer)) + } + } + context("in container scope") { + it("always produces the same instance for related objects") { + EmploymentAssembly(scope: .container).assemble(container: container) + let employer = container.resolve(Employer.self)! + expect(employer.lazyCustomer.instance).to(beIdenticalTo(employer.employee.lazyCustomer.instance)) + expect(employer.lazyCustomer.instance).to(beIdenticalTo(employer.customer)) + } + } + context("in graph scope") { + it("always produces the same instance for related objects") { + EmploymentAssembly(scope: .graph).assemble(container: container) + let employer = container.resolve(Employer.self)! + expect(employer.lazyCustomer.instance).to(beIdenticalTo(employer.employee.lazyCustomer.instance)) + expect(employer.lazyCustomer.instance).to(beIdenticalTo(employer.customer)) + } + } + } + describe("complex registrations") { + it("resolves lazy with arguments") { + container.register(Dog.self) { (_, name, _: Int) in Dog(name: name) } + var lazy = container.resolve(Lazy.self, arguments: "Hachi", 42) + expect(lazy?.instance.name) == "Hachi" + } + it("resolves lazy with name") { + container.register(Dog.self, name: "Hachi") { _ in Dog() } + let lazy = container.resolve(Lazy.self, name: "Hachi") + expect(lazy).notTo(beNil()) + } + it("does not resolve lazy with wrong name") { + container.register(Dog.self, name: "Hachi") { _ in Dog() } + let lazy = container.resolve(Lazy.self, name: "Mimi") + expect(lazy).to(beNil()) + } + it("does resolve forwarded lazy type") { + container.register(Dog.self) { _ in Dog() }.implements(Animal.self) + let lazy = container.resolve(Lazy.self) + expect(lazy).notTo(beNil()) + } + } + describe("circular dependencies") { + beforeEach { + EmploymentAssembly(scope: .graph).assemble(container: container) + } + it("resolves dependencies to same instance") { + let employer = container.resolve(Employer.self) + expect(employer?.employee.employer) === employer + expect(employer?.lazyEmployee.instance.employer) === employer + } + it("resolves circular dependencies for lazy instance") { + var employee = container.resolve(Lazy.self) + expect(employee?.instance.employer).notTo(beNil()) + } + } + } } diff --git a/Tests/3.0 API/InstanceProviderSpec.swift b/Tests/3.0 API/InstanceProviderSpec.swift new file mode 100644 index 00000000..1e0bb5f2 --- /dev/null +++ b/Tests/3.0 API/InstanceProviderSpec.swift @@ -0,0 +1,73 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +import Nimble +import Quick +import Swinject + +class InstanceProviderSpec: QuickSpec { override func spec() { #if swift(>=5.1) + describe("Lazy") { + it("can inject lazy provider of a bound type") { + let swinject = Swinject { + bbind(Int.self) & 42 + } + var lazyInt = try? swinject.instance() as Lazy + expect { lazyInt?.instance } == 42 + } + it("throws if provided type is not bound") { + let swinject = Swinject {} + expect { try swinject.instance() as Lazy }.to(throwError()) + } + it("throws if provided type is bound with different arguments") { + let swinject = Swinject { + bbind(Int.self) & 42 + } + expect { try swinject.instance(arg: "arg") as Lazy }.to(throwError()) + } + it("can inject lazy provider of bound type with arguments") { + let swinject = Swinject { + bbind(Int.self) & factory { Int($1 as String)! } + } + var lazyInt = try? swinject.instance(arg: "42") as Lazy + expect { lazyInt?.instance } == 42 + } + it("throws if provided type is bound with different tag") { + let swinject = Swinject { + bbind(Int.self) & 42 + } + expect { try swinject.instance(tagged: "tag") as Lazy }.to(throwError()) + } + it("can inject lazy provider of tagged bound type") { + let swinject = Swinject { + bbind(Int.self, tagged: "tag") & 42 + } + var lazyInt = try? swinject.instance(tagged: "tag") as Lazy + expect { lazyInt?.instance } == 42 + } + it("can use lazy as a property wrapper") { + struct IntHolder { + @Lazy var int: Int + } + let swinject = Swinject { + bbind(Int.self) & 42 + bbind(IntHolder.self) & provider { IntHolder(int: try $0.instance()) } + } + var holder = try? swinject.instance(of: IntHolder.self) + expect { holder?.int } == 42 + } + it("does not invoke value builder until lazy value is accessed") { + var invoked = false + struct IntHolder { + @Lazy var int: Int + } + let swinject = Swinject { + bbind(Int.self) & provider { invoked = true; return 42 } + bbind(IntHolder.self) & provider { IntHolder(int: try $0.instance()) } + } + _ = try? swinject.instance(of: IntHolder.self) + expect(invoked) == false + } + } + #endif +} } diff --git a/Tests/LinuxConfig.swift b/Tests/LinuxConfig.swift index 13e8a23f..41e73e7c 100644 --- a/Tests/LinuxConfig.swift +++ b/Tests/LinuxConfig.swift @@ -25,6 +25,7 @@ let allSpecs: [QuickSpec.Type] = [ ScopesSpec.self, OptionalsSpec.self, RetrievalSpec.self, + InstanceProviderSpec.self, // Unit Specs StandardScopeRegistrySpec.self, SwinjectTreeBuilderSpec.self, diff --git a/Tests/Support/Legacy/EmploymentAssembly.swift b/Tests/Support/Legacy/EmploymentAssembly.swift index 1259a77c..d6a0f00a 100644 --- a/Tests/Support/Legacy/EmploymentAssembly.swift +++ b/Tests/Support/Legacy/EmploymentAssembly.swift @@ -8,39 +8,43 @@ class Customer {} class Employee { let customer: Customer - let lazyCustomer: Lazy - let providedCustomer: Provider + var lazyCustomer: Lazy +// let providedCustomer: Provider var employer: Employer? - init(customer: Customer, lazyCustomer: Lazy, providedCustomer: Provider) { + init( + customer: Customer, + lazyCustomer: Lazy +// providedCustomer: Provider + ) { self.customer = customer self.lazyCustomer = lazyCustomer - self.providedCustomer = providedCustomer +// self.providedCustomer = providedCustomer } } class Employer { let customer: Customer - let lazyCustomer: Lazy - let providedCustomer: Provider - let employee: Employee - let lazyEmployee: Lazy - let providedEmployee: Provider + var lazyCustomer: Lazy +// let providedCustomer: Provider + var employee: Employee + var lazyEmployee: Lazy +// let providedEmployee: Provider init( customer: Customer, lazyCustomer: Lazy, - providedCustomer: Provider, + // providedCustomer: Provider, employee: Employee, - lazyEmployee: Lazy, - providedEmployee: Provider + lazyEmployee: Lazy +// providedEmployee: Provider ) { self.customer = customer self.lazyCustomer = lazyCustomer - self.providedCustomer = providedCustomer +// self.providedCustomer = providedCustomer self.employee = employee self.lazyEmployee = lazyEmployee - self.providedEmployee = providedEmployee +// self.providedEmployee = providedEmployee } } @@ -57,8 +61,8 @@ final class EmploymentAssembly: Assembly { container.register(Employee.self) { Employee( customer: $0.resolve(Customer.self)!, - lazyCustomer: $0.resolve(Lazy.self)!, - providedCustomer: $0.resolve(Provider.self)! + lazyCustomer: $0.resolve(Lazy.self)! +// providedCustomer: $0.resolve(Provider.self)! ) }.initCompleted { if self.scope != ObjectScope.transient { @@ -70,10 +74,10 @@ final class EmploymentAssembly: Assembly { Employer( customer: $0.resolve(Customer.self)!, lazyCustomer: $0.resolve(Lazy.self)!, - providedCustomer: $0.resolve(Provider.self)!, + // providedCustomer: $0.resolve(Provider.self)!, employee: $0.resolve(Employee.self)!, - lazyEmployee: $0.resolve(Lazy.self)!, - providedEmployee: $0.resolve(Provider.self)! + lazyEmployee: $0.resolve(Lazy.self)! +// providedEmployee: $0.resolve(Provider.self)! ) }.inObjectScope(scope) } From ac2292a80dff8f1e4e28e45e4726274ae39ada28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sat, 3 Aug 2019 17:20:51 +0200 Subject: [PATCH 183/239] Refactor to enable injection of any property wrapper --- ...ceProvider.swift => PropertyWrapper.swift} | 35 ++++++++------ Sources/Core/Swinject.swift | 2 +- Swinject.xcodeproj/project.pbxproj | 40 ++++++++-------- ...rSpec.swift => PropertyWrappersSpec.swift} | 46 +++++++++---------- Tests/LinuxConfig.swift | 2 +- 5 files changed, 64 insertions(+), 61 deletions(-) rename Sources/Core/{InstanceProvider.swift => PropertyWrapper.swift} (85%) rename Tests/3.0 API/{InstanceProviderSpec.swift => PropertyWrappersSpec.swift} (57%) diff --git a/Sources/Core/InstanceProvider.swift b/Sources/Core/PropertyWrapper.swift similarity index 85% rename from Sources/Core/InstanceProvider.swift rename to Sources/Core/PropertyWrapper.swift index d3a4eedc..b485f430 100644 --- a/Sources/Core/InstanceProvider.swift +++ b/Sources/Core/PropertyWrapper.swift @@ -2,12 +2,30 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -protocol InstanceProvider { +protocol AnyPropertyWrapper { init(resolver: Resolver, request: InstanceRequest) static func transform(_ request: InstanceRequest) -> AnyInstanceRequest } -@propertyWrapper public enum Lazy { +protocol PropertyWrapper: AnyPropertyWrapper { + associatedtype Value + init(wrappedValue: @autoclosure @escaping () -> Value) +} + +extension PropertyWrapper { + init(resolver: Resolver, request: InstanceRequest) { + self.init(wrappedValue: try! resolver.instance( // swiftlint:disable:this force_try + tagged: request.descriptor.anyTag as! Tag, + arg: request.argument as! Argument + )) + } + + static func transform(_ aRequest: InstanceRequest) -> AnyInstanceRequest { + return request(type: Value.self, tag: aRequest.descriptor.anyTag as! Tag, arg: aRequest.argument as! Argument) + } +} + +@propertyWrapper public enum Lazy: PropertyWrapper { case uninitialized(() -> Value) case initialized(Value) @@ -31,16 +49,3 @@ protocol InstanceProvider { } } } - -extension Lazy: InstanceProvider { - init(resolver: Resolver, request: InstanceRequest) { - self.init(wrappedValue: try! resolver.instance( // swiftlint:disable:this force_try - tagged: request.descriptor.anyTag as! Tag, - arg: request.argument as! Argument - )) - } - - static func transform(_ aRequest: InstanceRequest) -> AnyInstanceRequest { - return request(type: Value.self, tag: aRequest.descriptor.anyTag as! Tag, arg: aRequest.argument as! Argument) - } -} diff --git a/Sources/Core/Swinject.swift b/Sources/Core/Swinject.swift index 2234aa09..914ac88e 100644 --- a/Sources/Core/Swinject.swift +++ b/Sources/Core/Swinject.swift @@ -42,7 +42,7 @@ extension Swinject: Resolver { if let optional = Type.self as? OptionalProtocol.Type { return optional.init() as! Type } - if let provider = Type.self as? InstanceProvider.Type { + if let provider = Type.self as? AnyPropertyWrapper.Type { _ = try findBinding(for: provider.transform(request)) return provider.init(resolver: self, request: request) as! Type } diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index df32bd72..f29b5d67 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -230,14 +230,14 @@ CD367C0F22EF8A83008B3E82 /* SwinjectContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD367C0D22EF8A83008B3E82 /* SwinjectContainer.swift */; }; CD367C1022EF8A83008B3E82 /* SwinjectContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD367C0D22EF8A83008B3E82 /* SwinjectContainer.swift */; }; CD367C1122EF8A83008B3E82 /* SwinjectContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD367C0D22EF8A83008B3E82 /* SwinjectContainer.swift */; }; - CD68676022F5C60800F7D9E3 /* InstanceProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD68675F22F5C60800F7D9E3 /* InstanceProvider.swift */; }; - CD68676122F5C85B00F7D9E3 /* InstanceProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD68675F22F5C60800F7D9E3 /* InstanceProvider.swift */; }; - CD68676222F5C85B00F7D9E3 /* InstanceProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD68675F22F5C60800F7D9E3 /* InstanceProvider.swift */; }; - CD68676322F5C85B00F7D9E3 /* InstanceProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD68675F22F5C60800F7D9E3 /* InstanceProvider.swift */; }; - CD68676522F5CA5D00F7D9E3 /* InstanceProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD68676422F5CA5D00F7D9E3 /* InstanceProviderSpec.swift */; }; - CD68676622F5CA5D00F7D9E3 /* InstanceProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD68676422F5CA5D00F7D9E3 /* InstanceProviderSpec.swift */; }; - CD68676722F5CA5D00F7D9E3 /* InstanceProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD68676422F5CA5D00F7D9E3 /* InstanceProviderSpec.swift */; }; - CD68676822F5CA5D00F7D9E3 /* InstanceProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD68676422F5CA5D00F7D9E3 /* InstanceProviderSpec.swift */; }; + CD68676022F5C60800F7D9E3 /* PropertyWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD68675F22F5C60800F7D9E3 /* PropertyWrapper.swift */; }; + CD68676122F5C85B00F7D9E3 /* PropertyWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD68675F22F5C60800F7D9E3 /* PropertyWrapper.swift */; }; + CD68676222F5C85B00F7D9E3 /* PropertyWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD68675F22F5C60800F7D9E3 /* PropertyWrapper.swift */; }; + CD68676322F5C85B00F7D9E3 /* PropertyWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD68675F22F5C60800F7D9E3 /* PropertyWrapper.swift */; }; + CD68676522F5CA5D00F7D9E3 /* PropertyWrappersSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD68676422F5CA5D00F7D9E3 /* PropertyWrappersSpec.swift */; }; + CD68676622F5CA5D00F7D9E3 /* PropertyWrappersSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD68676422F5CA5D00F7D9E3 /* PropertyWrappersSpec.swift */; }; + CD68676722F5CA5D00F7D9E3 /* PropertyWrappersSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD68676422F5CA5D00F7D9E3 /* PropertyWrappersSpec.swift */; }; + CD68676822F5CA5D00F7D9E3 /* PropertyWrappersSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD68676422F5CA5D00F7D9E3 /* PropertyWrappersSpec.swift */; }; CD73B9AB22F239A4004BB84E /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; CD73B9AC22F239A4004BB84E /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */; }; CD73B9AD22F239A4004BB84E /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; @@ -535,8 +535,8 @@ CC85CB215058F95C0BC190B1 /* Bridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bridge.swift; sourceTree = ""; }; CD03917322EF610800DE44C4 /* OverrideSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OverrideSpec.swift; sourceTree = ""; }; CD367C0D22EF8A83008B3E82 /* SwinjectContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectContainer.swift; sourceTree = ""; }; - CD68675F22F5C60800F7D9E3 /* InstanceProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceProvider.swift; sourceTree = ""; }; - CD68676422F5CA5D00F7D9E3 /* InstanceProviderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceProviderSpec.swift; sourceTree = ""; }; + CD68675F22F5C60800F7D9E3 /* PropertyWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PropertyWrapper.swift; sourceTree = ""; }; + CD68676422F5CA5D00F7D9E3 /* PropertyWrappersSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PropertyWrappersSpec.swift; sourceTree = ""; }; CDA78290D6D60BD0B808571F /* Container+Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Logging.swift"; sourceTree = ""; }; CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextSpec.swift; sourceTree = ""; }; @@ -746,7 +746,7 @@ 1D3C59E84B5FD0C13F487838 /* ScopesSpec.swift */, 46F05CC591903E2B04B6D8ED /* SingletonSpec.swift */, CD03917322EF610800DE44C4 /* OverrideSpec.swift */, - CD68676422F5CA5D00F7D9E3 /* InstanceProviderSpec.swift */, + CD68676422F5CA5D00F7D9E3 /* PropertyWrappersSpec.swift */, ); path = "3.0 API"; sourceTree = ""; @@ -843,7 +843,7 @@ CD367C0D22EF8A83008B3E82 /* SwinjectContainer.swift */, 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */, E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */, - CD68675F22F5C60800F7D9E3 /* InstanceProvider.swift */, + CD68675F22F5C60800F7D9E3 /* PropertyWrapper.swift */, ); path = Core; sourceTree = ""; @@ -1391,7 +1391,7 @@ AAD8D0551B8A26A9B22AECEC /* Container+Registration.swift in Sources */, 996CCFE825834C7D3236E742 /* Container+TypeForwarding.swift in Sources */, B2FAD41F7726502822AF913B /* Container.swift in Sources */, - CD68676122F5C85B00F7D9E3 /* InstanceProvider.swift in Sources */, + CD68676122F5C85B00F7D9E3 /* PropertyWrapper.swift in Sources */, 8B5927517B567B1DFAB5B935 /* ContextTranslator.swift in Sources */, 6C4D29A3FB54416D5E4D4C89 /* InstanceBuilder.swift in Sources */, 53EBF7A46EF65F2A8DAADC7A /* InstanceRequest.swift in Sources */, @@ -1435,7 +1435,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - CD68676522F5CA5D00F7D9E3 /* InstanceProviderSpec.swift in Sources */, + CD68676522F5CA5D00F7D9E3 /* PropertyWrappersSpec.swift in Sources */, BD08D3E155AFD841CFECA0AD /* Animal.swift in Sources */, CD73B9AF22F239A4004BB84E /* ContainerSpec.Circularity.swift in Sources */, DD29D2E60DA979D61F32A39A /* BasicAssembly.swift in Sources */, @@ -1476,7 +1476,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - CD68676622F5CA5D00F7D9E3 /* InstanceProviderSpec.swift in Sources */, + CD68676622F5CA5D00F7D9E3 /* PropertyWrappersSpec.swift in Sources */, A6EECC339FA54CA0BBFF4146 /* Animal.swift in Sources */, CD73B9C522F239A5004BB84E /* ContainerSpec.Circularity.swift in Sources */, 401592294E5D528379BE1AB2 /* BasicAssembly.swift in Sources */, @@ -1517,7 +1517,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - CD68676822F5CA5D00F7D9E3 /* InstanceProviderSpec.swift in Sources */, + CD68676822F5CA5D00F7D9E3 /* PropertyWrappersSpec.swift in Sources */, A53B5A8E2188F8C4A3F29C2E /* Animal.swift in Sources */, CD73B9D022F239A6004BB84E /* ContainerSpec.Circularity.swift in Sources */, 03122D1B2EA65C89ADC78EC7 /* BasicAssembly.swift in Sources */, @@ -1558,7 +1558,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - CD68676722F5CA5D00F7D9E3 /* InstanceProviderSpec.swift in Sources */, + CD68676722F5CA5D00F7D9E3 /* PropertyWrappersSpec.swift in Sources */, D13208E63523A97A0B840283 /* Animal.swift in Sources */, CD73B9BA22F239A4004BB84E /* ContainerSpec.Circularity.swift in Sources */, 599C7F009F954CDA522244B3 /* BasicAssembly.swift in Sources */, @@ -1608,7 +1608,7 @@ A5E4C79F89E1A8AB3A4D8D6E /* Container+Registration.swift in Sources */, BD9B57E26722C80B7EF990DB /* Container+TypeForwarding.swift in Sources */, DB74F17CDFF4886B9C38AD14 /* Container.swift in Sources */, - CD68676222F5C85B00F7D9E3 /* InstanceProvider.swift in Sources */, + CD68676222F5C85B00F7D9E3 /* PropertyWrapper.swift in Sources */, DD5E3AF2B5FCE5E81EBDF606 /* ContextTranslator.swift in Sources */, 7F9686F3669BF35E5AC970B3 /* InstanceBuilder.swift in Sources */, 9DEAC620F2F00D0DDD3B5D3E /* InstanceRequest.swift in Sources */, @@ -1651,7 +1651,7 @@ CB0B308F3D3A831A28127462 /* Container+Registration.swift in Sources */, 283C77045DA55C2134EC9C48 /* Container+TypeForwarding.swift in Sources */, 58ABEE0321A3061048B65EA2 /* Container.swift in Sources */, - CD68676322F5C85B00F7D9E3 /* InstanceProvider.swift in Sources */, + CD68676322F5C85B00F7D9E3 /* PropertyWrapper.swift in Sources */, F06DEB671A4B85ABB0E96E51 /* ContextTranslator.swift in Sources */, DBEFC5C6A51FCEBF9E4F70EE /* InstanceBuilder.swift in Sources */, CECF5BD14BCDF5248771A06A /* InstanceRequest.swift in Sources */, @@ -1703,7 +1703,7 @@ 658C98B4AA17C58E8556E0AC /* Opaque.swift in Sources */, 0509EE8D41BF354EB91ACC80 /* Reference.swift in Sources */, CBE63031F33303F3E503CEF2 /* Resolver+Injection.swift in Sources */, - CD68676022F5C60800F7D9E3 /* InstanceProvider.swift in Sources */, + CD68676022F5C60800F7D9E3 /* PropertyWrapper.swift in Sources */, 41C7340BFD2EB66359772733 /* Resolver+LegacyApi.swift in Sources */, BE94EF7BCF976A703F961389 /* Resolver.swift in Sources */, 96EA0A5DF33F025EBE0B67D2 /* Scope.swift in Sources */, diff --git a/Tests/3.0 API/InstanceProviderSpec.swift b/Tests/3.0 API/PropertyWrappersSpec.swift similarity index 57% rename from Tests/3.0 API/InstanceProviderSpec.swift rename to Tests/3.0 API/PropertyWrappersSpec.swift index 1e0bb5f2..7015c640 100644 --- a/Tests/3.0 API/InstanceProviderSpec.swift +++ b/Tests/3.0 API/PropertyWrappersSpec.swift @@ -4,58 +4,56 @@ import Nimble import Quick -import Swinject +@testable import Swinject -class InstanceProviderSpec: QuickSpec { override func spec() { #if swift(>=5.1) - describe("Lazy") { - it("can inject lazy provider of a bound type") { +class PropertyWrappersSpec: QuickSpec { override func spec() { #if swift(>=5.1) + describe("any wrapper") { + @propertyWrapper struct Wrapped: PropertyWrapper { + var wrappedValue: Value + + public init(wrappedValue: @autoclosure @escaping () -> Value) { + self.wrappedValue = wrappedValue() + } + } + it("can inject wrapped provider of a bound type") { let swinject = Swinject { bbind(Int.self) & 42 } - var lazyInt = try? swinject.instance() as Lazy - expect { lazyInt?.instance } == 42 + let wrappedInt = try? swinject.instance() as Wrapped + expect { wrappedInt?.wrappedValue } == 42 } it("throws if provided type is not bound") { let swinject = Swinject {} - expect { try swinject.instance() as Lazy }.to(throwError()) + expect { try swinject.instance() as Wrapped }.to(throwError()) } it("throws if provided type is bound with different arguments") { let swinject = Swinject { bbind(Int.self) & 42 } - expect { try swinject.instance(arg: "arg") as Lazy }.to(throwError()) + expect { try swinject.instance(arg: "arg") as Wrapped }.to(throwError()) } it("can inject lazy provider of bound type with arguments") { let swinject = Swinject { bbind(Int.self) & factory { Int($1 as String)! } } - var lazyInt = try? swinject.instance(arg: "42") as Lazy - expect { lazyInt?.instance } == 42 + let wrappedInt = try? swinject.instance(arg: "42") as Wrapped + expect { wrappedInt?.wrappedValue } == 42 } it("throws if provided type is bound with different tag") { let swinject = Swinject { bbind(Int.self) & 42 } - expect { try swinject.instance(tagged: "tag") as Lazy }.to(throwError()) + expect { try swinject.instance(tagged: "tag") as Wrapped }.to(throwError()) } it("can inject lazy provider of tagged bound type") { let swinject = Swinject { bbind(Int.self, tagged: "tag") & 42 } - var lazyInt = try? swinject.instance(tagged: "tag") as Lazy - expect { lazyInt?.instance } == 42 - } - it("can use lazy as a property wrapper") { - struct IntHolder { - @Lazy var int: Int - } - let swinject = Swinject { - bbind(Int.self) & 42 - bbind(IntHolder.self) & provider { IntHolder(int: try $0.instance()) } - } - var holder = try? swinject.instance(of: IntHolder.self) - expect { holder?.int } == 42 + let wrappedInt = try? swinject.instance(tagged: "tag") as Wrapped + expect { wrappedInt?.wrappedValue } == 42 } + } + describe("lazy") { it("does not invoke value builder until lazy value is accessed") { var invoked = false struct IntHolder { diff --git a/Tests/LinuxConfig.swift b/Tests/LinuxConfig.swift index 41e73e7c..bdc04e96 100644 --- a/Tests/LinuxConfig.swift +++ b/Tests/LinuxConfig.swift @@ -25,7 +25,7 @@ let allSpecs: [QuickSpec.Type] = [ ScopesSpec.self, OptionalsSpec.self, RetrievalSpec.self, - InstanceProviderSpec.self, + PropertyWrappersSpec.self, // Unit Specs StandardScopeRegistrySpec.self, SwinjectTreeBuilderSpec.self, From d515ca1982fe1bd9dce6266b8ee5ac4baf9a6691 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sat, 3 Aug 2019 17:53:06 +0200 Subject: [PATCH 184/239] Enable nested property wrappers --- Sources/Core/PropertyWrapper.swift | 10 +++++++++- Sources/Core/Swinject.swift | 2 +- Tests/3.0 API/PropertyWrappersSpec.swift | 7 +++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Sources/Core/PropertyWrapper.swift b/Sources/Core/PropertyWrapper.swift index b485f430..10fe8126 100644 --- a/Sources/Core/PropertyWrapper.swift +++ b/Sources/Core/PropertyWrapper.swift @@ -21,7 +21,15 @@ extension PropertyWrapper { } static func transform(_ aRequest: InstanceRequest) -> AnyInstanceRequest { - return request(type: Value.self, tag: aRequest.descriptor.anyTag as! Tag, arg: aRequest.argument as! Argument) + if let wrapper = Value.self as? AnyPropertyWrapper.Type { + return wrapper.transform(aRequest) + } else { + return request( + type: Value.self, + tag: aRequest.descriptor.anyTag as! Tag, + arg: aRequest.argument as! Argument + ) + } } } diff --git a/Sources/Core/Swinject.swift b/Sources/Core/Swinject.swift index 914ac88e..8559b621 100644 --- a/Sources/Core/Swinject.swift +++ b/Sources/Core/Swinject.swift @@ -34,7 +34,7 @@ extension Swinject { extension Swinject: Resolver { public func resolve(_ request: InstanceRequest) throws -> Type { - var binding: Binding! + var binding: Binding // FIXME: Refactor this do { binding = try findBinding(for: request) diff --git a/Tests/3.0 API/PropertyWrappersSpec.swift b/Tests/3.0 API/PropertyWrappersSpec.swift index 7015c640..fa473503 100644 --- a/Tests/3.0 API/PropertyWrappersSpec.swift +++ b/Tests/3.0 API/PropertyWrappersSpec.swift @@ -52,6 +52,13 @@ class PropertyWrappersSpec: QuickSpec { override func spec() { #if swift(>=5.1) let wrappedInt = try? swinject.instance(tagged: "tag") as Wrapped expect { wrappedInt?.wrappedValue } == 42 } + it("can inject nested property wrappers") { + let swinject = Swinject { + bbind(Int.self) & 42 + } + let doubleWrappedInt = try? swinject.instance() as Wrapped> + expect { doubleWrappedInt?.wrappedValue.wrappedValue } == 42 + } } describe("lazy") { it("does not invoke value builder until lazy value is accessed") { From bde873b53251a57edc069aaf098b22f18f203de4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sat, 3 Aug 2019 18:23:24 +0200 Subject: [PATCH 185/239] Implement provider property wrapper --- Sources/2.0 API/InstanceWrapper.swift | 43 +++- Sources/Core/PropertyWrapper.swift | 25 -- Swinject.xcodeproj/project.pbxproj | 2 +- Tests/2.0 API/ContainerSpec.Circularity.swift | 2 +- Tests/2.0 API/LazySpec.swift | 1 - Tests/2.0 API/ProviderSpec.swift | 224 ++++++++++-------- Tests/3.0 API/PropertyWrappersSpec.swift | 14 -- .../Legacy}/Circularity.swift | 0 Tests/Support/Legacy/EmploymentAssembly.swift | 32 +-- 9 files changed, 176 insertions(+), 167 deletions(-) rename Tests/{2.0 API => Support/Legacy}/Circularity.swift (100%) diff --git a/Sources/2.0 API/InstanceWrapper.swift b/Sources/2.0 API/InstanceWrapper.swift index e7a17c59..8e6d40a0 100644 --- a/Sources/2.0 API/InstanceWrapper.swift +++ b/Sources/2.0 API/InstanceWrapper.swift @@ -5,21 +5,54 @@ /// Wrapper to enable delayed dependency instantiation. /// `Lazy` does not need to be explicitly registered into the `Container` - resolution will work /// as long as there is a registration for the `Type`. -public extension Lazy { +@propertyWrapper public enum Lazy: PropertyWrapper { /// Getter for the wrapped object. /// It will be resolved from the `Container` when first accessed, all other calls will return the same instance. - var instance: Value { + public var instance: Value { mutating get { return wrappedValue } } + + case uninitialized(() -> Value) + case initialized(Value) + + public init(wrappedValue: @autoclosure @escaping () -> Value) { + self = .uninitialized(wrappedValue) + } + + public var wrappedValue: Value { + mutating get { + switch self { + case let .uninitialized(initializer): + let value = initializer() + self = .initialized(value) + return value + case let .initialized(value): + return value + } + } + set { + self = .initialized(newValue) + } + } } /// Wrapper to enable delayed dependency instantiation. /// `Provider` does not need to be explicitly registered into the `Container` - resolution will work /// as long as there is a registration for the `Type`. -public final class Provider { +public struct Provider: PropertyWrapper { /// Getter for the wrapped object. /// New instance will be resolved from the `Container` every time it is accessed. - public var instance: Service { - fatalError() + public var instance: Type { + return wrappedValue + } + + private let provider: () -> Type + + public init(wrappedValue: @autoclosure @escaping () -> Type) { + provider = wrappedValue + } + + public var wrappedValue: Type { + return provider() } } diff --git a/Sources/Core/PropertyWrapper.swift b/Sources/Core/PropertyWrapper.swift index 10fe8126..693c5352 100644 --- a/Sources/Core/PropertyWrapper.swift +++ b/Sources/Core/PropertyWrapper.swift @@ -32,28 +32,3 @@ extension PropertyWrapper { } } } - -@propertyWrapper public enum Lazy: PropertyWrapper { - case uninitialized(() -> Value) - case initialized(Value) - - public init(wrappedValue: @autoclosure @escaping () -> Value) { - self = .uninitialized(wrappedValue) - } - - public var wrappedValue: Value { - mutating get { - switch self { - case let .uninitialized(initializer): - let value = initializer() - self = .initialized(value) - return value - case let .initialized(value): - return value - } - } - set { - self = .initialized(newValue) - } - } -} diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index f29b5d67..72c3b896 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -622,6 +622,7 @@ 1F06930A1A2C8BA94D6875BA /* Legacy */ = { isa = PBXGroup; children = ( + 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */, 4BC5108ED11A3A3084D864CC /* Animal.swift */, 62682D6ED38742996624B041 /* BasicAssembly.swift */, 5EA566CD336DB8343ADFAF9B /* BehaviorFakes.swift */, @@ -807,7 +808,6 @@ isa = PBXGroup; children = ( B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */, - 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */, 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */, BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */, ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */, diff --git a/Tests/2.0 API/ContainerSpec.Circularity.swift b/Tests/2.0 API/ContainerSpec.Circularity.swift index 9fe7e882..a3332178 100644 --- a/Tests/2.0 API/ContainerSpec.Circularity.swift +++ b/Tests/2.0 API/ContainerSpec.Circularity.swift @@ -116,7 +116,7 @@ class ContainerSpec_Circularity: QuickSpec { expect(d.c as? CDependingOnAD === c).to(beTrue()) // Workaround for crash in Nimble } } - // Implement subscopes + // TODO: Implement subscopes // describe("Graph root is in weak object scope") { // it("does not deallocate during graph resolution") { // container.register(B.self) { r in BDependingOnC(c: r.resolve(C.self)!) } diff --git a/Tests/2.0 API/LazySpec.swift b/Tests/2.0 API/LazySpec.swift index 8bb9c1c4..f1e5c98e 100644 --- a/Tests/2.0 API/LazySpec.swift +++ b/Tests/2.0 API/LazySpec.swift @@ -12,7 +12,6 @@ class LazySpec: QuickSpec { beforeEach { container = Container() } - describe("instance production") { it("provides instance from container") { container.register(Animal.self) { _ in Dog() } diff --git a/Tests/2.0 API/ProviderSpec.swift b/Tests/2.0 API/ProviderSpec.swift index 289b40cb..c87054ff 100644 --- a/Tests/2.0 API/ProviderSpec.swift +++ b/Tests/2.0 API/ProviderSpec.swift @@ -7,108 +7,124 @@ import Quick import Swinject class ProviderSpec: QuickSpec { - // TODO: Enable Provider injection -// override func spec() { -// var container: Container! -// beforeEach { -// container = Container() -// } -// -// describe("instance production") { -// it("provides instance from container") { -// container.register(Animal.self) { _ in Dog() } -// let provider = container.resolve(Provider.self) -// expect(provider?.instance is Dog).to(beTrue()) -// } -// it("does not create instance until requested") { -// var created = false -// container.register(Animal.self) { _ in created = true; return Dog() } -// -// _ = container.resolve(Provider.self) -// -// expect(created).to(beFalse()) -// } -// it("resolves instance from the container each time") { -// var created = 0 -// container.register(Animal.self) { _ in created += 1; return Dog() } -// -// let provider = container.resolve(Provider.self) -// _ = provider?.instance -// _ = provider?.instance -// -// expect(created) == 2 -// } -// it("does not resolve provider if base type is not registered") { -// let provider = container.resolve(Provider.self) -// expect(provider).to(beNil()) -// } -// } -// describe("object scopes") { -// context("in transient scope") { -// beforeEach { -// EmploymentAssembly(scope: .transient).assemble(container: container) -// } -// it("always produces different instance") { -// let employer = container.resolve(Employer.self)! -// expect(employer.providedEmployee.instance) !== employer.providedEmployee.instance -// expect(employer.employee.providedCustomer.instance) !== employer.providedCustomer.instance -// } -// } -// context("in graph scope") { -// beforeEach { -// EmploymentAssembly(scope: .graph).assemble(container: container) -// } -// it("always produces different instance") { -// let employer = container.resolve(Employer.self)! -// expect(employer.providedEmployee.instance) !== employer.providedEmployee.instance -// expect(employer.employee.providedCustomer.instance) !== employer.providedCustomer.instance -// } -// } -// context("in container scope") { -// beforeEach { -// EmploymentAssembly(scope: .container).assemble(container: container) -// } -// it("always produces the same instance") { -// let employer = container.resolve(Employer.self)! -// expect(employer.providedEmployee.instance) === employer.providedEmployee.instance -// expect(employer.employee.providedCustomer.instance) === employer.providedCustomer.instance -// } -// } -// } -// describe("complex registrations") { -// it("resolves provider with arguments") { -// container.register(Dog.self) { (_, name, _: Int) in Dog(name: name) } -// let provider = container.resolve(Provider.self, arguments: "Hachi", 42) -// expect(provider?.instance.name) == "Hachi" -// } -// it("resolves provider with name") { -// container.register(Dog.self, name: "Hachi") { _ in Dog() } -// let provider = container.resolve(Provider.self, name: "Hachi") -// expect(provider).notTo(beNil()) -// } -// it("does not resolve provider with wrong name") { -// container.register(Dog.self, name: "Hachi") { _ in Dog() } -// let provider = container.resolve(Provider.self, name: "Mimi") -// expect(provider).to(beNil()) -// } -// it("does resolve forwarded provider type") { -// container.register(Dog.self) { _ in Dog() }.implements(Animal.self) -// let provider = container.resolve(Provider.self) -// expect(provider).notTo(beNil()) -// } -// } -// describe("circular dependencies") { -// beforeEach { -// EmploymentAssembly(scope: .graph).assemble(container: container) -// } -// it("resolves non-provided dependencies to the same instance") { -// let employer = container.resolve(Provider.self)?.instance -// expect(employer?.employee.employer) === employer -// } -// it("resolves provided dependencies to different instances") { -// let employer = container.resolve(Employer.self) -// expect(employer?.providedEmployee.instance.employer) !== employer -// } -// } -// } + override func spec() { + var container: Container! + beforeEach { + container = Container() + } + describe("instance production") { + it("provides instance from container") { + container.register(Animal.self) { _ in Dog() } + let provider = container.resolve(Provider.self) + expect(provider?.instance is Dog).to(beTrue()) + } + it("does not create instance until requested") { + var created = false + container.register(Animal.self) { _ in created = true; return Dog() } + + _ = container.resolve(Provider.self) + + expect(created).to(beFalse()) + } + it("does not resolve provider if base type is not registered") { + let provider = container.resolve(Provider.self) + expect(provider).to(beNil()) + } + } + describe("object scopes") { + context("in transient scope") { + it("resolves instance from the container each time") { + var created = 0 + container.register(Animal.self) { _ in created += 1; return Dog() } + .inObjectScope(.transient) + + let provider = container.resolve(Provider.self) + _ = provider?.instance + _ = provider?.instance + + expect(created) == 2 + } + it("always produces different instance from different providers") { + EmploymentAssembly(scope: .transient).assemble(container: container) + let employer = container.resolve(Employer.self)! + expect(employer.providedEmployee.instance) !== employer.providedEmployee.instance + expect(employer.employee.providedCustomer.instance) !== employer.providedCustomer.instance + } + } + context("in graph scope") { + it("resolves instance from the container only once") { + var created = 0 + container.register(Animal.self) { _ in created += 1; return Dog() } + .inObjectScope(.graph) + + let provider = container.resolve(Provider.self) + _ = provider?.instance + _ = provider?.instance + + expect(created) == 1 + } + it("always produces the same instance from different providers") { + EmploymentAssembly(scope: .graph).assemble(container: container) + let employer = container.resolve(Employer.self)! + expect(employer.providedEmployee.instance) === employer.providedEmployee.instance + expect(employer.employee.providedCustomer.instance) === employer.providedCustomer.instance + } + } + context("in container scope") { + it("resolves instance from the container only once") { + var created = 0 + container.register(Animal.self) { _ in created += 1; return Dog() } + .inObjectScope(.container) + + let provider = container.resolve(Provider.self) + _ = provider?.instance + _ = provider?.instance + + expect(created) == 1 + } + it("always produces the same instance from different providers") { + EmploymentAssembly(scope: .container).assemble(container: container) + let employer = container.resolve(Employer.self)! + expect(employer.providedEmployee.instance) === employer.providedEmployee.instance + expect(employer.employee.providedCustomer.instance) === employer.providedCustomer.instance + } + } + } + describe("complex registrations") { + it("resolves provider with arguments") { + container.register(Dog.self) { (_, name, _: Int) in Dog(name: name) } + let provider = container.resolve(Provider.self, arguments: "Hachi", 42) + expect(provider?.instance.name) == "Hachi" + } + it("resolves provider with name") { + container.register(Dog.self, name: "Hachi") { _ in Dog() } + let provider = container.resolve(Provider.self, name: "Hachi") + expect(provider).notTo(beNil()) + } + it("does not resolve provider with wrong name") { + container.register(Dog.self, name: "Hachi") { _ in Dog() } + let provider = container.resolve(Provider.self, name: "Mimi") + expect(provider).to(beNil()) + } + it("does resolve forwarded provider type") { + container.register(Dog.self) { _ in Dog() }.implements(Animal.self) + let provider = container.resolve(Provider.self) + expect(provider).notTo(beNil()) + } + } + describe("circular dependencies") { + beforeEach { + EmploymentAssembly(scope: .graph).assemble(container: container) + } + it("resolves dependencies to same instance") { + let employer = container.resolve(Employer.self) + expect(employer?.employee.employer) === employer + expect(employer?.providedEmployee.instance.employer) === employer + } + it("resolves circular dependencies for lazy instance") { + let employee = container.resolve(Provider.self) + expect(employee?.instance.employer).notTo(beNil()) + } + } + } } diff --git a/Tests/3.0 API/PropertyWrappersSpec.swift b/Tests/3.0 API/PropertyWrappersSpec.swift index fa473503..72e07323 100644 --- a/Tests/3.0 API/PropertyWrappersSpec.swift +++ b/Tests/3.0 API/PropertyWrappersSpec.swift @@ -60,19 +60,5 @@ class PropertyWrappersSpec: QuickSpec { override func spec() { #if swift(>=5.1) expect { doubleWrappedInt?.wrappedValue.wrappedValue } == 42 } } - describe("lazy") { - it("does not invoke value builder until lazy value is accessed") { - var invoked = false - struct IntHolder { - @Lazy var int: Int - } - let swinject = Swinject { - bbind(Int.self) & provider { invoked = true; return 42 } - bbind(IntHolder.self) & provider { IntHolder(int: try $0.instance()) } - } - _ = try? swinject.instance(of: IntHolder.self) - expect(invoked) == false - } - } #endif } } diff --git a/Tests/2.0 API/Circularity.swift b/Tests/Support/Legacy/Circularity.swift similarity index 100% rename from Tests/2.0 API/Circularity.swift rename to Tests/Support/Legacy/Circularity.swift diff --git a/Tests/Support/Legacy/EmploymentAssembly.swift b/Tests/Support/Legacy/EmploymentAssembly.swift index d6a0f00a..ddd9de24 100644 --- a/Tests/Support/Legacy/EmploymentAssembly.swift +++ b/Tests/Support/Legacy/EmploymentAssembly.swift @@ -9,42 +9,42 @@ class Customer {} class Employee { let customer: Customer var lazyCustomer: Lazy -// let providedCustomer: Provider + let providedCustomer: Provider var employer: Employer? init( customer: Customer, - lazyCustomer: Lazy -// providedCustomer: Provider + lazyCustomer: Lazy, + providedCustomer: Provider ) { self.customer = customer self.lazyCustomer = lazyCustomer -// self.providedCustomer = providedCustomer + self.providedCustomer = providedCustomer } } class Employer { let customer: Customer var lazyCustomer: Lazy -// let providedCustomer: Provider + let providedCustomer: Provider var employee: Employee var lazyEmployee: Lazy -// let providedEmployee: Provider + let providedEmployee: Provider init( customer: Customer, lazyCustomer: Lazy, - // providedCustomer: Provider, + providedCustomer: Provider, employee: Employee, - lazyEmployee: Lazy -// providedEmployee: Provider + lazyEmployee: Lazy, + providedEmployee: Provider ) { self.customer = customer self.lazyCustomer = lazyCustomer -// self.providedCustomer = providedCustomer + self.providedCustomer = providedCustomer self.employee = employee self.lazyEmployee = lazyEmployee -// self.providedEmployee = providedEmployee + self.providedEmployee = providedEmployee } } @@ -61,8 +61,8 @@ final class EmploymentAssembly: Assembly { container.register(Employee.self) { Employee( customer: $0.resolve(Customer.self)!, - lazyCustomer: $0.resolve(Lazy.self)! -// providedCustomer: $0.resolve(Provider.self)! + lazyCustomer: $0.resolve(Lazy.self)!, + providedCustomer: $0.resolve(Provider.self)! ) }.initCompleted { if self.scope != ObjectScope.transient { @@ -74,10 +74,10 @@ final class EmploymentAssembly: Assembly { Employer( customer: $0.resolve(Customer.self)!, lazyCustomer: $0.resolve(Lazy.self)!, - // providedCustomer: $0.resolve(Provider.self)!, + providedCustomer: $0.resolve(Provider.self)!, employee: $0.resolve(Employee.self)!, - lazyEmployee: $0.resolve(Lazy.self)! -// providedEmployee: $0.resolve(Provider.self)! + lazyEmployee: $0.resolve(Lazy.self)!, + providedEmployee: $0.resolve(Provider.self)! ) }.inObjectScope(scope) } From 5ecfcf99ca9fe256dac3046e0f154b93cc3b4570 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sat, 3 Aug 2019 19:35:33 +0200 Subject: [PATCH 186/239] Cleanup property wrapers resolution --- Sources/2.0 API/Container.swift | 2 +- Sources/2.0 API/Resolver+LegacyApi.swift | 40 ++-- Sources/2.0 API/ServiceEntry.swift | 2 +- Sources/3.0 API/Resolver+Injection.swift | 208 ++++++++++----------- Sources/3.0 API/TypeBinder.swift | 11 +- Sources/Core/Binding.swift | 2 +- Sources/Core/InjectionRequest.swift | 23 +++ Sources/Core/InstanceRequest.swift | 29 --- Sources/Core/PropertyWrapper.swift | 41 ++-- Sources/Core/Resolver.swift | 4 +- Sources/Core/ScopeRegistryKey.swift | 2 +- Sources/Core/Swinject.swift | 17 +- Sources/Core/TypeDescriptor.swift | 36 ++-- Swinject.xcodeproj/project.pbxproj | 20 +- Templates/InjectionVariation.swift | 1 + Templates/Resolver+LegacyApi.swifttemplate | 8 +- Templates/SwiftCode.swifttemplate | 1 + 17 files changed, 218 insertions(+), 229 deletions(-) create mode 100644 Sources/Core/InjectionRequest.swift delete mode 100644 Sources/Core/InstanceRequest.swift diff --git a/Sources/2.0 API/Container.swift b/Sources/2.0 API/Container.swift index e4633aab..fed0b0c3 100644 --- a/Sources/2.0 API/Container.swift +++ b/Sources/2.0 API/Container.swift @@ -151,7 +151,7 @@ extension Container: CustomStringConvertible { // MARK: Resolver extension Container: Resolver { - public func resolve(_ request: InstanceRequest) throws -> Type { + public func resolve(_ request: InjectionRequest) throws -> Type { return try swinject.on(Graph(on: self)).resolve(request) } } diff --git a/Sources/2.0 API/Resolver+LegacyApi.swift b/Sources/2.0 API/Resolver+LegacyApi.swift index d2dfebb3..ef41b22c 100644 --- a/Sources/2.0 API/Resolver+LegacyApi.swift +++ b/Sources/2.0 API/Resolver+LegacyApi.swift @@ -13,9 +13,9 @@ public extension Resolver { /// - Returns: The resolved service type instance, or nil if no service with the name is found. func resolve(_ serviceType: Service.Type, name: String? = nil) -> Service? { if let name = name { - return try? resolve(request(type: serviceType, tag: name, arg: ())) + return try? resolve(request(type: serviceType, tag: name, arg: ())) as Service } else { - return try? resolve(request(type: serviceType, tag: NoTag(), arg: ())) + return try? resolve(request(type: serviceType, tag: NoTag(), arg: ())) as Service } } @@ -30,9 +30,9 @@ public extension Resolver { /// 1 argument and name is found. func resolve(_ serviceType: Service.Type, name: String? = nil, argument: Arg1) -> Service? { if let name = name { - return try? resolve(request(type: serviceType, tag: name, arg: ())) + return try? resolve(request(type: serviceType, tag: name, arg: ())) as Service } else { - return try? resolve(request(type: serviceType, tag: NoTag(), arg: argument)) + return try? resolve(request(type: serviceType, tag: NoTag(), arg: argument)) as Service } } @@ -47,9 +47,9 @@ public extension Resolver { /// list of 2 arguments and name is found. func resolve(_ serviceType: Service.Type, name: String? = nil, arguments arg1: Arg1, _ arg2: Arg2) -> Service? { if let name = name { - return try? resolve(request(type: serviceType, tag: name, arg: ())) + return try? resolve(request(type: serviceType, tag: name, arg: ())) as Service } else { - return try? resolve(request(type: serviceType, tag: NoTag(), arg: (arg1, arg2))) + return try? resolve(request(type: serviceType, tag: NoTag(), arg: (arg1, arg2))) as Service } } @@ -64,9 +64,9 @@ public extension Resolver { /// list of 3 arguments and name is found. func resolve(_ serviceType: Service.Type, name: String? = nil, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> Service? { if let name = name { - return try? resolve(request(type: serviceType, tag: name, arg: ())) + return try? resolve(request(type: serviceType, tag: name, arg: ())) as Service } else { - return try? resolve(request(type: serviceType, tag: NoTag(), arg: (arg1, arg2, arg3))) + return try? resolve(request(type: serviceType, tag: NoTag(), arg: (arg1, arg2, arg3))) as Service } } @@ -81,9 +81,9 @@ public extension Resolver { /// list of 4 arguments and name is found. func resolve(_ serviceType: Service.Type, name: String? = nil, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> Service? { if let name = name { - return try? resolve(request(type: serviceType, tag: name, arg: ())) + return try? resolve(request(type: serviceType, tag: name, arg: ())) as Service } else { - return try? resolve(request(type: serviceType, tag: NoTag(), arg: (arg1, arg2, arg3, arg4))) + return try? resolve(request(type: serviceType, tag: NoTag(), arg: (arg1, arg2, arg3, arg4))) as Service } } @@ -98,9 +98,9 @@ public extension Resolver { /// list of 5 arguments and name is found. func resolve(_ serviceType: Service.Type, name: String? = nil, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> Service? { if let name = name { - return try? resolve(request(type: serviceType, tag: name, arg: ())) + return try? resolve(request(type: serviceType, tag: name, arg: ())) as Service } else { - return try? resolve(request(type: serviceType, tag: NoTag(), arg: (arg1, arg2, arg3, arg4, arg5))) + return try? resolve(request(type: serviceType, tag: NoTag(), arg: (arg1, arg2, arg3, arg4, arg5))) as Service } } @@ -115,9 +115,9 @@ public extension Resolver { /// list of 6 arguments and name is found. func resolve(_ serviceType: Service.Type, name: String? = nil, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6) -> Service? { if let name = name { - return try? resolve(request(type: serviceType, tag: name, arg: ())) + return try? resolve(request(type: serviceType, tag: name, arg: ())) as Service } else { - return try? resolve(request(type: serviceType, tag: NoTag(), arg: (arg1, arg2, arg3, arg4, arg5, arg6))) + return try? resolve(request(type: serviceType, tag: NoTag(), arg: (arg1, arg2, arg3, arg4, arg5, arg6))) as Service } } @@ -132,9 +132,9 @@ public extension Resolver { /// list of 7 arguments and name is found. func resolve(_ serviceType: Service.Type, name: String? = nil, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7) -> Service? { if let name = name { - return try? resolve(request(type: serviceType, tag: name, arg: ())) + return try? resolve(request(type: serviceType, tag: name, arg: ())) as Service } else { - return try? resolve(request(type: serviceType, tag: NoTag(), arg: (arg1, arg2, arg3, arg4, arg5, arg6, arg7))) + return try? resolve(request(type: serviceType, tag: NoTag(), arg: (arg1, arg2, arg3, arg4, arg5, arg6, arg7))) as Service } } @@ -149,9 +149,9 @@ public extension Resolver { /// list of 8 arguments and name is found. func resolve(_ serviceType: Service.Type, name: String? = nil, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8) -> Service? { if let name = name { - return try? resolve(request(type: serviceType, tag: name, arg: ())) + return try? resolve(request(type: serviceType, tag: name, arg: ())) as Service } else { - return try? resolve(request(type: serviceType, tag: NoTag(), arg: (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8))) + return try? resolve(request(type: serviceType, tag: NoTag(), arg: (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8))) as Service } } @@ -166,9 +166,9 @@ public extension Resolver { /// list of 9 arguments and name is found. func resolve(_ serviceType: Service.Type, name: String? = nil, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8, _ arg9: Arg9) -> Service? { if let name = name { - return try? resolve(request(type: serviceType, tag: name, arg: ())) + return try? resolve(request(type: serviceType, tag: name, arg: ())) as Service } else { - return try? resolve(request(type: serviceType, tag: NoTag(), arg: (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9))) + return try? resolve(request(type: serviceType, tag: NoTag(), arg: (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9))) as Service } } } diff --git a/Sources/2.0 API/ServiceEntry.swift b/Sources/2.0 API/ServiceEntry.swift index 83cf3748..45e89b36 100644 --- a/Sources/2.0 API/ServiceEntry.swift +++ b/Sources/2.0 API/ServiceEntry.swift @@ -12,7 +12,7 @@ public class ServiceEntry { var scope: AnyScope? var makeRef: ReferenceMaker var finalizers = [(Resolver, Service) -> Void]() - var forwardedDescriptors = [AnyTypeDescriptor]() + var forwardedDescriptors = [TypeDescriptor]() init( container: Container, diff --git a/Sources/3.0 API/Resolver+Injection.swift b/Sources/3.0 API/Resolver+Injection.swift index 637fb71b..466f9bd6 100644 --- a/Sources/3.0 API/Resolver+Injection.swift +++ b/Sources/3.0 API/Resolver+Injection.swift @@ -8,423 +8,423 @@ // sourcery:inline:ResolverInjectionApi public extension Resolver { func instance(of _: Type.Type = Type.self) throws -> Type { - return try resolve(request(tag: NoTag(), arg: ())) + return try resolve(request(type: Type.self, tag: NoTag(), arg: ())) } func instance(of _: Type.Type = Type.self, tagged tag: Tag) throws -> Type where Tag: Hashable { - return try resolve(request(tag: tag, arg: ())) + return try resolve(request(type: Type.self, tag: tag, arg: ())) } func instance(of _: Type.Type = Type.self, arg arg1: Arg1) throws -> Type { - return try resolve(request(tag: NoTag(), arg: box(arg1))) + return try resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1))) } func instance(of _: Type.Type = Type.self, arg arg1: Arg1) throws -> Type where Arg1: Hashable { - return try resolve(request(tag: NoTag(), arg: box(arg1))) + return try resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1))) } func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) throws -> Type where Tag: Hashable { - return try resolve(request(tag: tag, arg: box(arg1))) + return try resolve(request(type: Type.self, tag: tag, arg: box(arg1))) } func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) throws -> Type where Tag: Hashable, Arg1: Hashable { - return try resolve(request(tag: tag, arg: box(arg1))) + return try resolve(request(type: Type.self, tag: tag, arg: box(arg1))) } func instance(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2) throws -> Type { - return try resolve(request(tag: NoTag(), arg: box(arg1, arg2))) + return try resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2))) } func instance(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2) throws -> Type where Arg1: Hashable, Arg2: Hashable { - return try resolve(request(tag: NoTag(), arg: box(arg1, arg2))) + return try resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2))) } func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2) throws -> Type where Tag: Hashable { - return try resolve(request(tag: tag, arg: box(arg1, arg2))) + return try resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2))) } func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable { - return try resolve(request(tag: tag, arg: box(arg1, arg2))) + return try resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2))) } func instance(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) throws -> Type { - return try resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3))) + return try resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, arg3))) } func instance(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - return try resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3))) + return try resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, arg3))) } func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) throws -> Type where Tag: Hashable { - return try resolve(request(tag: tag, arg: box(arg1, arg2, arg3))) + return try resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3))) } func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - return try resolve(request(tag: tag, arg: box(arg1, arg2, arg3))) + return try resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3))) } func instance(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) throws -> Type { - return try resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3, arg4))) + return try resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, arg3, arg4))) } func instance(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return try resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3, arg4))) + return try resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, arg3, arg4))) } func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) throws -> Type where Tag: Hashable { - return try resolve(request(tag: tag, arg: box(arg1, arg2, arg3, arg4))) + return try resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, arg4))) } func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return try resolve(request(tag: tag, arg: box(arg1, arg2, arg3, arg4))) + return try resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, arg4))) } func instance(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) throws -> Type { - return try resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3, arg4, arg5))) + return try resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, arg3, arg4, arg5))) } func instance(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return try resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3, arg4, arg5))) + return try resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, arg3, arg4, arg5))) } func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) throws -> Type where Tag: Hashable { - return try resolve(request(tag: tag, arg: box(arg1, arg2, arg3, arg4, arg5))) + return try resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, arg4, arg5))) } func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return try resolve(request(tag: tag, arg: box(arg1, arg2, arg3, arg4, arg5))) + return try resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, arg4, arg5))) } } public extension Resolver { func provider(of _: Type.Type = Type.self) -> () throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: ())) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: ())) } } func provider(of _: Type.Type = Type.self, tagged tag: Tag) -> () throws -> Type where Tag: Hashable { - return { try self.resolve(request(tag: tag, arg: ())) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: ())) } } func provider(of _: Type.Type = Type.self, arg arg1: Arg1) -> () throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: box(arg1))) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1))) } } func provider(of _: Type.Type = Type.self, arg arg1: Arg1) -> () throws -> Type where Arg1: Hashable { - return { try self.resolve(request(tag: NoTag(), arg: box(arg1))) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1))) } } func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) -> () throws -> Type where Tag: Hashable { - return { try self.resolve(request(tag: tag, arg: box(arg1))) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1))) } } func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) -> () throws -> Type where Tag: Hashable, Arg1: Hashable { - return { try self.resolve(request(tag: tag, arg: box(arg1))) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1))) } } func provider(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2) -> () throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: box(arg1, arg2))) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2))) } } func provider(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2) -> () throws -> Type where Arg1: Hashable, Arg2: Hashable { - return { try self.resolve(request(tag: NoTag(), arg: box(arg1, arg2))) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2))) } } func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2) -> () throws -> Type where Tag: Hashable { - return { try self.resolve(request(tag: tag, arg: box(arg1, arg2))) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2))) } } func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2) -> () throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable { - return { try self.resolve(request(tag: tag, arg: box(arg1, arg2))) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2))) } } func provider(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> () throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3))) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, arg3))) } } func provider(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> () throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - return { try self.resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3))) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, arg3))) } } func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> () throws -> Type where Tag: Hashable { - return { try self.resolve(request(tag: tag, arg: box(arg1, arg2, arg3))) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3))) } } func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> () throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - return { try self.resolve(request(tag: tag, arg: box(arg1, arg2, arg3))) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3))) } } func provider(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> () throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3, arg4))) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, arg3, arg4))) } } func provider(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> () throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return { try self.resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3, arg4))) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, arg3, arg4))) } } func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> () throws -> Type where Tag: Hashable { - return { try self.resolve(request(tag: tag, arg: box(arg1, arg2, arg3, arg4))) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, arg4))) } } func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> () throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return { try self.resolve(request(tag: tag, arg: box(arg1, arg2, arg3, arg4))) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, arg4))) } } func provider(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> () throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3, arg4, arg5))) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, arg3, arg4, arg5))) } } func provider(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> () throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return { try self.resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3, arg4, arg5))) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, arg3, arg4, arg5))) } } func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> () throws -> Type where Tag: Hashable { - return { try self.resolve(request(tag: tag, arg: box(arg1, arg2, arg3, arg4, arg5))) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, arg4, arg5))) } } func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> () throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return { try self.resolve(request(tag: tag, arg: box(arg1, arg2, arg3, arg4, arg5))) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, arg4, arg5))) } } } public extension Resolver { func factory(of _: Type.Type = Type.self) -> (Arg1) throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: box($0))) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box($0))) } } func factory(of _: Type.Type = Type.self) -> (Arg1) throws -> Type where Arg1: Hashable { - return { try self.resolve(request(tag: NoTag(), arg: box($0))) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box($0))) } } func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1) throws -> Type where Tag: Hashable { - return { try self.resolve(request(tag: tag, arg: box($0))) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: box($0))) } } func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1) throws -> Type where Tag: Hashable, Arg1: Hashable { - return { try self.resolve(request(tag: tag, arg: box($0))) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: box($0))) } } func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2) throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: box($0, $1))) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box($0, $1))) } } func factory(of _: Type.Type = Type.self, arg arg1: Arg1) -> (Arg2) throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: box(arg1, $0))) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, $0))) } } func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2) throws -> Type where Arg1: Hashable, Arg2: Hashable { - return { try self.resolve(request(tag: NoTag(), arg: box($0, $1))) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box($0, $1))) } } func factory(of _: Type.Type = Type.self, arg arg1: Arg1) -> (Arg2) throws -> Type where Arg1: Hashable, Arg2: Hashable { - return { try self.resolve(request(tag: NoTag(), arg: box(arg1, $0))) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, $0))) } } func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1, Arg2) throws -> Type where Tag: Hashable { - return { try self.resolve(request(tag: tag, arg: box($0, $1))) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: box($0, $1))) } } func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) -> (Arg2) throws -> Type where Tag: Hashable { - return { try self.resolve(request(tag: tag, arg: box(arg1, $0))) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, $0))) } } func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1, Arg2) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable { - return { try self.resolve(request(tag: tag, arg: box($0, $1))) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: box($0, $1))) } } func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) -> (Arg2) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable { - return { try self.resolve(request(tag: tag, arg: box(arg1, $0))) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, $0))) } } func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2, Arg3) throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: box($0, $1, $2))) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box($0, $1, $2))) } } func factory(of _: Type.Type = Type.self, arg arg1: Arg1) -> (Arg2, Arg3) throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: box(arg1, $0, $1))) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, $0, $1))) } } func factory(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3) throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: box(arg1, arg2, $0))) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, $0))) } } func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2, Arg3) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - return { try self.resolve(request(tag: NoTag(), arg: box($0, $1, $2))) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box($0, $1, $2))) } } func factory(of _: Type.Type = Type.self, arg arg1: Arg1) -> (Arg2, Arg3) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - return { try self.resolve(request(tag: NoTag(), arg: box(arg1, $0, $1))) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, $0, $1))) } } func factory(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - return { try self.resolve(request(tag: NoTag(), arg: box(arg1, arg2, $0))) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, $0))) } } func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1, Arg2, Arg3) throws -> Type where Tag: Hashable { - return { try self.resolve(request(tag: tag, arg: box($0, $1, $2))) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: box($0, $1, $2))) } } func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) -> (Arg2, Arg3) throws -> Type where Tag: Hashable { - return { try self.resolve(request(tag: tag, arg: box(arg1, $0, $1))) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, $0, $1))) } } func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3) throws -> Type where Tag: Hashable { - return { try self.resolve(request(tag: tag, arg: box(arg1, arg2, $0))) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, $0))) } } func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1, Arg2, Arg3) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - return { try self.resolve(request(tag: tag, arg: box($0, $1, $2))) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: box($0, $1, $2))) } } func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) -> (Arg2, Arg3) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - return { try self.resolve(request(tag: tag, arg: box(arg1, $0, $1))) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, $0, $1))) } } func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - return { try self.resolve(request(tag: tag, arg: box(arg1, arg2, $0))) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, $0))) } } func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2, Arg3, Arg4) throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: box($0, $1, $2, $3))) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box($0, $1, $2, $3))) } } func factory(of _: Type.Type = Type.self, arg arg1: Arg1) -> (Arg2, Arg3, Arg4) throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: box(arg1, $0, $1, $2))) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, $0, $1, $2))) } } func factory(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3, Arg4) throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: box(arg1, arg2, $0, $1))) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, $0, $1))) } } func factory(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> (Arg4) throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3, $0))) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, arg3, $0))) } } func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2, Arg3, Arg4) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return { try self.resolve(request(tag: NoTag(), arg: box($0, $1, $2, $3))) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box($0, $1, $2, $3))) } } func factory(of _: Type.Type = Type.self, arg arg1: Arg1) -> (Arg2, Arg3, Arg4) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return { try self.resolve(request(tag: NoTag(), arg: box(arg1, $0, $1, $2))) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, $0, $1, $2))) } } func factory(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3, Arg4) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return { try self.resolve(request(tag: NoTag(), arg: box(arg1, arg2, $0, $1))) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, $0, $1))) } } func factory(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> (Arg4) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return { try self.resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3, $0))) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, arg3, $0))) } } func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1, Arg2, Arg3, Arg4) throws -> Type where Tag: Hashable { - return { try self.resolve(request(tag: tag, arg: box($0, $1, $2, $3))) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: box($0, $1, $2, $3))) } } func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) -> (Arg2, Arg3, Arg4) throws -> Type where Tag: Hashable { - return { try self.resolve(request(tag: tag, arg: box(arg1, $0, $1, $2))) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, $0, $1, $2))) } } func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3, Arg4) throws -> Type where Tag: Hashable { - return { try self.resolve(request(tag: tag, arg: box(arg1, arg2, $0, $1))) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, $0, $1))) } } func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> (Arg4) throws -> Type where Tag: Hashable { - return { try self.resolve(request(tag: tag, arg: box(arg1, arg2, arg3, $0))) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, $0))) } } func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1, Arg2, Arg3, Arg4) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return { try self.resolve(request(tag: tag, arg: box($0, $1, $2, $3))) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: box($0, $1, $2, $3))) } } func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) -> (Arg2, Arg3, Arg4) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return { try self.resolve(request(tag: tag, arg: box(arg1, $0, $1, $2))) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, $0, $1, $2))) } } func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3, Arg4) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return { try self.resolve(request(tag: tag, arg: box(arg1, arg2, $0, $1))) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, $0, $1))) } } func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> (Arg4) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return { try self.resolve(request(tag: tag, arg: box(arg1, arg2, arg3, $0))) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, $0))) } } func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: box($0, $1, $2, $3, $4))) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box($0, $1, $2, $3, $4))) } } func factory(of _: Type.Type = Type.self, arg arg1: Arg1) -> (Arg2, Arg3, Arg4, Arg5) throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: box(arg1, $0, $1, $2, $3))) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, $0, $1, $2, $3))) } } func factory(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3, Arg4, Arg5) throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: box(arg1, arg2, $0, $1, $2))) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, $0, $1, $2))) } } func factory(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> (Arg4, Arg5) throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3, $0, $1))) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, arg3, $0, $1))) } } func factory(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> (Arg5) throws -> Type { - return { try self.resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3, arg4, $0))) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, arg3, arg4, $0))) } } func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return { try self.resolve(request(tag: NoTag(), arg: box($0, $1, $2, $3, $4))) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box($0, $1, $2, $3, $4))) } } func factory(of _: Type.Type = Type.self, arg arg1: Arg1) -> (Arg2, Arg3, Arg4, Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return { try self.resolve(request(tag: NoTag(), arg: box(arg1, $0, $1, $2, $3))) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, $0, $1, $2, $3))) } } func factory(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3, Arg4, Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return { try self.resolve(request(tag: NoTag(), arg: box(arg1, arg2, $0, $1, $2))) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, $0, $1, $2))) } } func factory(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> (Arg4, Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return { try self.resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3, $0, $1))) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, arg3, $0, $1))) } } func factory(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> (Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return { try self.resolve(request(tag: NoTag(), arg: box(arg1, arg2, arg3, arg4, $0))) } + return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, arg3, arg4, $0))) } } func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type where Tag: Hashable { - return { try self.resolve(request(tag: tag, arg: box($0, $1, $2, $3, $4))) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: box($0, $1, $2, $3, $4))) } } func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) -> (Arg2, Arg3, Arg4, Arg5) throws -> Type where Tag: Hashable { - return { try self.resolve(request(tag: tag, arg: box(arg1, $0, $1, $2, $3))) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, $0, $1, $2, $3))) } } func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3, Arg4, Arg5) throws -> Type where Tag: Hashable { - return { try self.resolve(request(tag: tag, arg: box(arg1, arg2, $0, $1, $2))) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, $0, $1, $2))) } } func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> (Arg4, Arg5) throws -> Type where Tag: Hashable { - return { try self.resolve(request(tag: tag, arg: box(arg1, arg2, arg3, $0, $1))) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, $0, $1))) } } func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> (Arg5) throws -> Type where Tag: Hashable { - return { try self.resolve(request(tag: tag, arg: box(arg1, arg2, arg3, arg4, $0))) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, arg4, $0))) } } func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return { try self.resolve(request(tag: tag, arg: box($0, $1, $2, $3, $4))) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: box($0, $1, $2, $3, $4))) } } func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) -> (Arg2, Arg3, Arg4, Arg5) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return { try self.resolve(request(tag: tag, arg: box(arg1, $0, $1, $2, $3))) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, $0, $1, $2, $3))) } } func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3, Arg4, Arg5) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return { try self.resolve(request(tag: tag, arg: box(arg1, arg2, $0, $1, $2))) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, $0, $1, $2))) } } func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> (Arg4, Arg5) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return { try self.resolve(request(tag: tag, arg: box(arg1, arg2, arg3, $0, $1))) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, $0, $1))) } } func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> (Arg5) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return { try self.resolve(request(tag: tag, arg: box(arg1, arg2, arg3, arg4, $0))) } + return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, arg4, $0))) } } } diff --git a/Sources/3.0 API/TypeBinder.swift b/Sources/3.0 API/TypeBinder.swift index 59f003ff..b07a07d0 100644 --- a/Sources/3.0 API/TypeBinder.swift +++ b/Sources/3.0 API/TypeBinder.swift @@ -3,7 +3,7 @@ // public struct BindingProperties { - let descriptor: AnyTypeDescriptor + let descriptor: TypeDescriptor let overrides: Bool } @@ -11,10 +11,7 @@ public struct TypeBinder { let properties: BindingProperties } -public func bind( - _: Type.Type, - overrides: Bool = false -) -> TypeBinder { +public func bind(_: Type.Type, overrides: Bool = false) -> TypeBinder { return TypeBinder(properties: BindingProperties( descriptor: plain(Type.self), overrides: overrides @@ -22,9 +19,7 @@ public func bind( } public func bind( - _: Type.Type, - tagged tag: Tag, - overrides: Bool = false + _: Type.Type, tagged tag: Tag, overrides: Bool = false ) -> TypeBinder where Tag: Hashable { return TypeBinder(properties: BindingProperties( descriptor: tagged(Type.self, with: tag), diff --git a/Sources/Core/Binding.swift b/Sources/Core/Binding.swift index cc5d7717..96a8e0ee 100644 --- a/Sources/Core/Binding.swift +++ b/Sources/Core/Binding.swift @@ -3,7 +3,7 @@ // public struct BindingKey: Hashable { - let descriptor: AnyTypeDescriptor + let descriptor: TypeDescriptor let contextType: Any.Type let argumentType: Any.Type diff --git a/Sources/Core/InjectionRequest.swift b/Sources/Core/InjectionRequest.swift new file mode 100644 index 00000000..2d5e11c2 --- /dev/null +++ b/Sources/Core/InjectionRequest.swift @@ -0,0 +1,23 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +public struct InjectionRequest { + let descriptor: TypeDescriptor + let argument: Any + let argumentType: Any.Type +} + +func request( + type: Type.Type = Type.self, + tag: Tag, + arg: Argument +) -> InjectionRequest { + return InjectionRequest(descriptor: tagged(type, with: tag), argument: arg, argumentType: Argument.self) +} + +extension InjectionRequest { + func key(forContextType contextType: Any.Type) -> BindingKey { + return BindingKey(descriptor: descriptor, contextType: contextType, argumentType: argumentType) + } +} diff --git a/Sources/Core/InstanceRequest.swift b/Sources/Core/InstanceRequest.swift deleted file mode 100644 index 8abec036..00000000 --- a/Sources/Core/InstanceRequest.swift +++ /dev/null @@ -1,29 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -protocol AnyInstanceRequest { - var descriptor: AnyTypeDescriptor { get } - var argument: Any { get } - var argumentType: Any.Type { get } -} - -public struct InstanceRequest: AnyInstanceRequest where Tag: Hashable { - let argumentType: Any.Type = Argument.self - let descriptor: AnyTypeDescriptor - let argument: Any -} - -func request( - type: Type.Type = Type.self, - tag: Tag, - arg: Argument -) -> InstanceRequest { - return InstanceRequest(descriptor: tagged(type, with: tag), argument: arg) -} - -extension AnyInstanceRequest { - func key(forContextType contextType: Any.Type) -> BindingKey { - return BindingKey(descriptor: descriptor, contextType: contextType, argumentType: argumentType) - } -} diff --git a/Sources/Core/PropertyWrapper.swift b/Sources/Core/PropertyWrapper.swift index 693c5352..c4bf0db8 100644 --- a/Sources/Core/PropertyWrapper.swift +++ b/Sources/Core/PropertyWrapper.swift @@ -2,33 +2,40 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -protocol AnyPropertyWrapper { - init(resolver: Resolver, request: InstanceRequest) - static func transform(_ request: InstanceRequest) -> AnyInstanceRequest +protocol CustomResolvable { + init(resolver: Resolver, request: InjectionRequest) + static func requiredRequest(for request: InjectionRequest) -> InjectionRequest? } -protocol PropertyWrapper: AnyPropertyWrapper { +protocol PropertyWrapper: CustomResolvable { associatedtype Value init(wrappedValue: @autoclosure @escaping () -> Value) } extension PropertyWrapper { - init(resolver: Resolver, request: InstanceRequest) { - self.init(wrappedValue: try! resolver.instance( // swiftlint:disable:this force_try - tagged: request.descriptor.anyTag as! Tag, - arg: request.argument as! Argument - )) + init(resolver: Resolver, request: InjectionRequest) { + // swiftlint:disable:next force_try + self.init(wrappedValue: try! resolver.resolve(request.replacingType(with: Value.self))) } - static func transform(_ aRequest: InstanceRequest) -> AnyInstanceRequest { - if let wrapper = Value.self as? AnyPropertyWrapper.Type { - return wrapper.transform(aRequest) + static func requiredRequest(for request: InjectionRequest) -> InjectionRequest? { + if let wrapper = Value.self as? CustomResolvable.Type { + return wrapper.requiredRequest(for: request) } else { - return request( - type: Value.self, - tag: aRequest.descriptor.anyTag as! Tag, - arg: aRequest.argument as! Argument - ) + return request.replacingType(with: Value.self) } } } + +private extension InjectionRequest { + func replacingType(with _: Type.Type) -> InjectionRequest { + InjectionRequest( + descriptor: TypeDescriptor( + tag: descriptor.tag, + rootType: Type.self + ), + argument: argument, + argumentType: argumentType + ) + } +} diff --git a/Sources/Core/Resolver.swift b/Sources/Core/Resolver.swift index b7381138..0f807ba7 100644 --- a/Sources/Core/Resolver.swift +++ b/Sources/Core/Resolver.swift @@ -3,7 +3,7 @@ // public protocol Resolver { - func resolve(_ request: InstanceRequest) throws -> Type + func resolve(_ request: InjectionRequest) throws -> Type } public protocol SwinjectAware: Resolver { @@ -11,7 +11,7 @@ public protocol SwinjectAware: Resolver { } public extension SwinjectAware { - func resolve(_ request: InstanceRequest) throws -> Type { + func resolve(_ request: InjectionRequest) throws -> Type { return try swinject.resolve(request) } } diff --git a/Sources/Core/ScopeRegistryKey.swift b/Sources/Core/ScopeRegistryKey.swift index 5f6b1d65..f44108ad 100644 --- a/Sources/Core/ScopeRegistryKey.swift +++ b/Sources/Core/ScopeRegistryKey.swift @@ -3,7 +3,7 @@ // public struct ScopeRegistryKey { - let descriptor: AnyTypeDescriptor + let descriptor: TypeDescriptor let argument: Any } diff --git a/Sources/Core/Swinject.swift b/Sources/Core/Swinject.swift index 8559b621..e7982458 100644 --- a/Sources/Core/Swinject.swift +++ b/Sources/Core/Swinject.swift @@ -33,18 +33,21 @@ extension Swinject { } extension Swinject: Resolver { - public func resolve(_ request: InstanceRequest) throws -> Type { + public func resolve(_ request: InjectionRequest) throws -> Type { var binding: Binding // FIXME: Refactor this + // TODO: Can we unify Optional handling with Custom resolvable? do { binding = try findBinding(for: request) } catch let error as NoBinding { if let optional = Type.self as? OptionalProtocol.Type { return optional.init() as! Type } - if let provider = Type.self as? AnyPropertyWrapper.Type { - _ = try findBinding(for: provider.transform(request)) - return provider.init(resolver: self, request: request) as! Type + if let custom = Type.self as? CustomResolvable.Type { + if let requiredRequest = custom.requiredRequest(for: request) { + _ = try findBinding(for: requiredRequest) + } + return custom.init(resolver: self, request: request) as! Type } throw error } @@ -52,20 +55,20 @@ extension Swinject: Resolver { return try instance(from: binding, context: translator.translate(context), arg: request.argument) } - private func findTranslator(for _: AnyInstanceRequest, and binding: Binding) throws -> AnyContextTranslator { + private func findTranslator(for _: InjectionRequest, and binding: Binding) throws -> AnyContextTranslator { return try (container.translators + [IdentityTranslator(for: contextType), ToAnyTranslator(for: contextType)]) .filter { $0.sourceType == contextType } .filter { binding.key.contextType == Any.self || binding.key.contextType == $0.targetType } .first ?? { throw SwinjectError() }() } - private func translatableKeys(for request: AnyInstanceRequest) -> [BindingKey] { + private func translatableKeys(for request: InjectionRequest) -> [BindingKey] { return (container.translators + [IdentityTranslator(for: contextType), ToAnyTranslator(for: contextType)]) .filter { $0.sourceType == contextType } .map { request.key(forContextType: $0.targetType) } } - private func findBinding(for request: AnyInstanceRequest) throws -> Binding { + private func findBinding(for request: InjectionRequest) throws -> Binding { let bindings = translatableKeys(for: request).compactMap { container.bindings[$0] } if bindings.isEmpty { throw NoBinding() } if bindings.count > 1 { throw MultipleBindings() } diff --git a/Sources/Core/TypeDescriptor.swift b/Sources/Core/TypeDescriptor.swift index d3736ce1..bdae2ac4 100644 --- a/Sources/Core/TypeDescriptor.swift +++ b/Sources/Core/TypeDescriptor.swift @@ -2,36 +2,24 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -public protocol AnyTypeDescriptor { - var anyTag: Any { get } - var rootType: Any.Type { get } - func isEqual(to other: AnyTypeDescriptor) -> Bool - func hash(into hasher: inout Hasher) -} - -struct NoTag: Hashable {} - -struct Tagged: AnyTypeDescriptor where Tag: Hashable { - let tag: Tag +public struct TypeDescriptor { + let tag: Matchable let rootType: Any.Type - var anyTag: Any { return tag } - - func isEqual(to other: AnyTypeDescriptor) -> Bool { - if let otherTag = other.anyTag as? Tag { - return rootType == other.rootType && tag == otherTag - } - return false + func isEqual(to other: TypeDescriptor) -> Bool { + return rootType == other.rootType && tag.matches(other.tag) } func hash(into hasher: inout Hasher) { - hasher.combine(ObjectIdentifier(rootType)) - hasher.combine(tag) + ObjectIdentifier(rootType).hash(into: &hasher) + tag.hash(into: &hasher) } } -func tagged(_: Type.Type, with tag: Tag) -> Tagged where Tag: Hashable { - return Tagged(tag: tag, rootType: { +struct NoTag: Hashable {} + +func tagged(_: Type.Type, with tag: Tag) -> TypeDescriptor where Tag: Hashable { + return TypeDescriptor(tag: box(tag), rootType: { if let optional = Type.self as? OptionalProtocol.Type { if let doubleOptional = optional.wrappedType as? OptionalProtocol.Type { return doubleOptional.wrappedType @@ -42,11 +30,11 @@ func tagged(_: Type.Type, with tag: Tag) -> Tagged where T }()) } -func plain(_: Type.Type) -> Tagged { +func plain(_: Type.Type) -> TypeDescriptor { return tagged(Type.self, with: NoTag()) } -func named(_: Type.Type, name: String?) -> AnyTypeDescriptor { +func named(_: Type.Type, name: String?) -> TypeDescriptor { if let name = name { return tagged(Type.self, with: name) } else { diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 72c3b896..90e42412 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -24,7 +24,7 @@ 0CE1126436F680F9684837E4 /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; 0CE158916595980A7C8272D3 /* SingletonSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46F05CC591903E2B04B6D8ED /* SingletonSpec.swift */; }; 0D5C4A278A16AB3A163148AF /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; - 128913D570B4A8BBF40866BE /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; + 128913D570B4A8BBF40866BE /* InjectionRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InjectionRequest.swift */; }; 13CDEC7A6C8E43B58D5CBE3D /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; 180DB4397B4C05E26F819C85 /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADA1541ABC1365DFD7E3377F /* Food.swift */; }; 19416C867F15E88394A0ABD1 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */; }; @@ -81,7 +81,7 @@ 4E4DC8CDD1BA51FB66A332C2 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */; }; 4EC94A51037C79DE0C5C8CB1 /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; 4EE5C1207C57C85A928FA89B /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 273FB7A6277E0841E1570990 /* Nimble.framework */; }; - 53EBF7A46EF65F2A8DAADC7A /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; + 53EBF7A46EF65F2A8DAADC7A /* InjectionRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InjectionRequest.swift */; }; 55CA3AA3F28B7CC221ABEC83 /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6D54F152C11C966ECFC55ECB /* Swinject.framework */; }; 55F2E72EA8C3564130F66946 /* ModulesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75BE3AE3E30DFE42A919D825 /* ModulesSpec.swift */; }; 57BFBA2077E70DC1C2FE796C /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */; }; @@ -163,7 +163,7 @@ 9C15BE01C1EA41061CDB7918 /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C074BAC560F277E806146C60 /* SimpleBinding.swift */; }; 9CCAB8EE342CCC8D2FB187C1 /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */; }; 9CEE20BD42795D5E5F39BF20 /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; - 9DEAC620F2F00D0DDD3B5D3E /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; + 9DEAC620F2F00D0DDD3B5D3E /* InjectionRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InjectionRequest.swift */; }; A193BF10196FBDE32833E292 /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = A10187BB3A994165E7FC1528 /* ScopedBinding.swift */; }; A2D3B18BE38948A427B60BC5 /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61EE5DDBE705B47AFC9A6986 /* LoadAwareAssembly.swift */; }; A308578B99D33C7E33632E85 /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; @@ -283,7 +283,7 @@ CD73B9D522F239A6004BB84E /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; CD73B9D622F239A6004BB84E /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; CE5AFED22F04B96713ED76D7 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ADC44E9312C3B974AFD8F07B /* Nimble.framework */; }; - CECF5BD14BCDF5248771A06A /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; + CECF5BD14BCDF5248771A06A /* InjectionRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InjectionRequest.swift */; }; CEE763218A90832454A6E2DE /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */; }; CF4EBB60C21F8C503BCD7A29 /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1E726A651C3AFE92C19608B /* SwinjectModule.swift */; }; D0D71F9C22A0EE82B6E4F61A /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 74DE57FB3E8228904E6FE0D7 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -540,7 +540,7 @@ CDA78290D6D60BD0B808571F /* Container+Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Logging.swift"; sourceTree = ""; }; CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextSpec.swift; sourceTree = ""; }; - E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRequest.swift; sourceTree = ""; }; + E0874A043EAEE3C7CF1EA063 /* InjectionRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InjectionRequest.swift; sourceTree = ""; }; E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; ED41A352529A5B2950F39D8F /* InstanceBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceBuilder.swift; sourceTree = ""; }; F290F6B1207A0557A528220B /* Assembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Assembly.swift; sourceTree = ""; }; @@ -827,7 +827,7 @@ 0E0B580B43E1891812C97209 /* Binding.swift */, 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */, ED41A352529A5B2950F39D8F /* InstanceBuilder.swift */, - E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */, + E0874A043EAEE3C7CF1EA063 /* InjectionRequest.swift */, 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */, C68B98C653ABDED9C3D17DB3 /* Opaque.swift */, 73B4B777290FF5D38A8914CC /* Reference.swift */, @@ -1394,7 +1394,7 @@ CD68676122F5C85B00F7D9E3 /* PropertyWrapper.swift in Sources */, 8B5927517B567B1DFAB5B935 /* ContextTranslator.swift in Sources */, 6C4D29A3FB54416D5E4D4C89 /* InstanceBuilder.swift in Sources */, - 53EBF7A46EF65F2A8DAADC7A /* InstanceRequest.swift in Sources */, + 53EBF7A46EF65F2A8DAADC7A /* InjectionRequest.swift in Sources */, A91EDAFBC3606EDFBD739899 /* InstanceWrapper.swift in Sources */, 98322F9371E1A8461BC614D1 /* Matchable.swift in Sources */, 3753FB83A1FB4B83891AA5C8 /* ObjectScope.swift in Sources */, @@ -1611,7 +1611,7 @@ CD68676222F5C85B00F7D9E3 /* PropertyWrapper.swift in Sources */, DD5E3AF2B5FCE5E81EBDF606 /* ContextTranslator.swift in Sources */, 7F9686F3669BF35E5AC970B3 /* InstanceBuilder.swift in Sources */, - 9DEAC620F2F00D0DDD3B5D3E /* InstanceRequest.swift in Sources */, + 9DEAC620F2F00D0DDD3B5D3E /* InjectionRequest.swift in Sources */, 57BFBA2077E70DC1C2FE796C /* InstanceWrapper.swift in Sources */, 293985649250DF270DC89135 /* Matchable.swift in Sources */, B4B66D7251BDDE25D6D7FB3C /* ObjectScope.swift in Sources */, @@ -1654,7 +1654,7 @@ CD68676322F5C85B00F7D9E3 /* PropertyWrapper.swift in Sources */, F06DEB671A4B85ABB0E96E51 /* ContextTranslator.swift in Sources */, DBEFC5C6A51FCEBF9E4F70EE /* InstanceBuilder.swift in Sources */, - CECF5BD14BCDF5248771A06A /* InstanceRequest.swift in Sources */, + CECF5BD14BCDF5248771A06A /* InjectionRequest.swift in Sources */, 389C54E04DD794DA4F648571 /* InstanceWrapper.swift in Sources */, 87FEAEF562B99522083CB87D /* Matchable.swift in Sources */, 6DA49F84E2592B32F81F268B /* ObjectScope.swift in Sources */, @@ -1696,7 +1696,7 @@ 0622539110A7430776A307C7 /* Container.swift in Sources */, D1DF4740A9D86362B63104B8 /* ContextTranslator.swift in Sources */, B90EA5A6764CEFA2BCB6C4D9 /* InstanceBuilder.swift in Sources */, - 128913D570B4A8BBF40866BE /* InstanceRequest.swift in Sources */, + 128913D570B4A8BBF40866BE /* InjectionRequest.swift in Sources */, 98ACB1A09194572A946CA90D /* InstanceWrapper.swift in Sources */, 5ED8A7D19F21FA686215F72C /* Matchable.swift in Sources */, B42331BF00B482369B908BB8 /* ObjectScope.swift in Sources */, diff --git a/Templates/InjectionVariation.swift b/Templates/InjectionVariation.swift index 51eda4d0..2a44bee7 100644 --- a/Templates/InjectionVariation.swift +++ b/Templates/InjectionVariation.swift @@ -48,6 +48,7 @@ extension InjectionVariation { let paramVars = (0 ..< paramArgs).map { "arg\($0 + 1)" } let factoryVars = (0 ..< factoryArgs).map { "$\($0)" } return join( + "type: Type.self", isTagged ? "tag: tag" : "tag: NoTag()", args == 0 ? "arg: ()" : "arg: box(\(join(paramVars + factoryVars)))" ) diff --git a/Templates/Resolver+LegacyApi.swifttemplate b/Templates/Resolver+LegacyApi.swifttemplate index e86edd89..af711bb9 100644 --- a/Templates/Resolver+LegacyApi.swifttemplate +++ b/Templates/Resolver+LegacyApi.swifttemplate @@ -10,9 +10,9 @@ public extension Resolver { /// - Returns: The resolved service type instance, or nil if no service with the name is found. func resolve(_ serviceType: Service.Type, name: String? = nil) -> Service? { if let name = name { - return try? resolve(request(type: serviceType, tag: name, arg: ())) + return try? resolve(request(type: serviceType, tag: name, arg: ())) as Service } else { - return try? resolve(request(type: serviceType, tag: NoTag(), arg: ())) + return try? resolve(request(type: serviceType, tag: NoTag(), arg: ())) as Service } } @@ -34,9 +34,9 @@ public extension Resolver { /// <%= arg_param_description %> and name is found. func resolve>(_ serviceType: Service.Type, name: String? = nil, <%= arg_param %>) -> Service? { if let name = name { - return try? resolve(request(type: serviceType, tag: name, arg: ())) + return try? resolve(request(type: serviceType, tag: name, arg: ())) as Service } else { - return try? resolve(request(type: serviceType, tag: NoTag(), arg: <%= arg_vars %>)) + return try? resolve(request(type: serviceType, tag: NoTag(), arg: <%= arg_vars %>)) as Service } }<%= i < arg_count ? "\n" : "" %> <%_ } -%> diff --git a/Templates/SwiftCode.swifttemplate b/Templates/SwiftCode.swifttemplate index f782f0f0..5a34b5b3 100644 --- a/Templates/SwiftCode.swifttemplate +++ b/Templates/SwiftCode.swifttemplate @@ -204,6 +204,7 @@ extension InjectionVariation { let paramVars = (0 ..< paramArgs).map { "arg\($0 + 1)" } let factoryVars = (0 ..< factoryArgs).map { "$\($0)" } return join( + "type: Type.self", isTagged ? "tag: tag" : "tag: NoTag()", args == 0 ? "arg: ()" : "arg: box(\(join(paramVars + factoryVars)))" ) From 01bd01edf13c1c800369a2730f8c6e22cf73c82e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sat, 3 Aug 2019 22:26:19 +0200 Subject: [PATCH 187/239] Refactor request resolution --- Sources/Core/PropertyWrapper.swift | 10 +++++++ Sources/Core/Swinject.swift | 48 +++++++++++++++++------------- Sources/Core/TypeDescriptor.swift | 2 -- 3 files changed, 38 insertions(+), 22 deletions(-) diff --git a/Sources/Core/PropertyWrapper.swift b/Sources/Core/PropertyWrapper.swift index c4bf0db8..aebff18b 100644 --- a/Sources/Core/PropertyWrapper.swift +++ b/Sources/Core/PropertyWrapper.swift @@ -39,3 +39,13 @@ private extension InjectionRequest { ) } } + +extension Optional: CustomResolvable { + init(resolver _: Resolver, request _: InjectionRequest) { + self = nil + } + + static func requiredRequest(for _: InjectionRequest) -> InjectionRequest? { + return nil + } +} diff --git a/Sources/Core/Swinject.swift b/Sources/Core/Swinject.swift index e7982458..d82637b5 100644 --- a/Sources/Core/Swinject.swift +++ b/Sources/Core/Swinject.swift @@ -34,38 +34,46 @@ extension Swinject { extension Swinject: Resolver { public func resolve(_ request: InjectionRequest) throws -> Type { - var binding: Binding - // FIXME: Refactor this - // TODO: Can we unify Optional handling with Custom resolvable? + let binding: Binding do { binding = try findBinding(for: request) } catch let error as NoBinding { - if let optional = Type.self as? OptionalProtocol.Type { - return optional.init() as! Type - } - if let custom = Type.self as? CustomResolvable.Type { - if let requiredRequest = custom.requiredRequest(for: request) { - _ = try findBinding(for: requiredRequest) - } - return custom.init(resolver: self, request: request) as! Type - } + if let custom = resolve(request, asCustom: Type.self) { return custom } throw error } - let translator = try findTranslator(for: request, and: binding) - return try instance(from: binding, context: translator.translate(context), arg: request.argument) + return try instance( + from: binding, + context: findTranslator(for: binding).translate(context), + arg: request.argument + ) + } + + private func resolve(_ request: InjectionRequest, asCustom _: Type.Type) -> Type? { + guard let custom = Type.self as? CustomResolvable.Type else { return nil } + if let request = custom.requiredRequest(for: request), !hasBinding(for: request) { return nil } + return custom.init(resolver: self, request: request) as? Type } - private func findTranslator(for _: InjectionRequest, and binding: Binding) throws -> AnyContextTranslator { - return try (container.translators + [IdentityTranslator(for: contextType), ToAnyTranslator(for: contextType)]) - .filter { $0.sourceType == contextType } + private func findTranslator(for binding: Binding) throws -> AnyContextTranslator { + return try allTranslators .filter { binding.key.contextType == Any.self || binding.key.contextType == $0.targetType } .first ?? { throw SwinjectError() }() } private func translatableKeys(for request: InjectionRequest) -> [BindingKey] { - return (container.translators + [IdentityTranslator(for: contextType), ToAnyTranslator(for: contextType)]) - .filter { $0.sourceType == contextType } - .map { request.key(forContextType: $0.targetType) } + return allTranslators.map { request.key(forContextType: $0.targetType) } + } + + private var allTranslators: [AnyContextTranslator] { + return container.translators.filter { $0.sourceType == contextType } + defaultTranslators + } + + private var defaultTranslators: [AnyContextTranslator] { + return [IdentityTranslator(for: contextType), ToAnyTranslator(for: contextType)] + } + + private func hasBinding(for request: InjectionRequest) -> Bool { + return (try? findBinding(for: request)) != nil } private func findBinding(for request: InjectionRequest) throws -> Binding { diff --git a/Sources/Core/TypeDescriptor.swift b/Sources/Core/TypeDescriptor.swift index bdae2ac4..20b0ef6d 100644 --- a/Sources/Core/TypeDescriptor.swift +++ b/Sources/Core/TypeDescriptor.swift @@ -44,10 +44,8 @@ func named(_: Type.Type, name: String?) -> TypeDescriptor { protocol OptionalProtocol { static var wrappedType: Any.Type { get } - init() } extension Optional: OptionalProtocol { static var wrappedType: Any.Type { return Wrapped.self } - init() { self = .none } } From 671f17f4e9b0ed1755476e1b11683b486faed57c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sat, 3 Aug 2019 23:23:40 +0200 Subject: [PATCH 188/239] Refactor type descriptor --- Sources/2.0 API/InstanceWrapper.swift | 2 +- Sources/Core/Binding.swift | 2 +- Sources/Core/ScopeRegistryKey.swift | 2 +- Sources/Core/TypeDescriptor.swift | 27 ++++++++++++--------------- 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/Sources/2.0 API/InstanceWrapper.swift b/Sources/2.0 API/InstanceWrapper.swift index 8e6d40a0..e75b4a05 100644 --- a/Sources/2.0 API/InstanceWrapper.swift +++ b/Sources/2.0 API/InstanceWrapper.swift @@ -39,7 +39,7 @@ /// Wrapper to enable delayed dependency instantiation. /// `Provider` does not need to be explicitly registered into the `Container` - resolution will work /// as long as there is a registration for the `Type`. -public struct Provider: PropertyWrapper { +@propertyWrapper public struct Provider: PropertyWrapper { /// Getter for the wrapped object. /// New instance will be resolved from the `Container` every time it is accessed. public var instance: Type { diff --git a/Sources/Core/Binding.swift b/Sources/Core/Binding.swift index 96a8e0ee..7e00e112 100644 --- a/Sources/Core/Binding.swift +++ b/Sources/Core/Binding.swift @@ -14,7 +14,7 @@ public struct BindingKey: Hashable { } public static func == (lhs: BindingKey, rhs: BindingKey) -> Bool { - return lhs.descriptor.isEqual(to: rhs.descriptor) + return lhs.descriptor == rhs.descriptor && lhs.contextType == rhs.contextType && lhs.argumentType == rhs.argumentType } diff --git a/Sources/Core/ScopeRegistryKey.swift b/Sources/Core/ScopeRegistryKey.swift index f44108ad..6ef70cb2 100644 --- a/Sources/Core/ScopeRegistryKey.swift +++ b/Sources/Core/ScopeRegistryKey.swift @@ -9,7 +9,7 @@ public struct ScopeRegistryKey { extension ScopeRegistryKey: Hashable { public static func == (lhs: ScopeRegistryKey, rhs: ScopeRegistryKey) -> Bool { - return lhs.descriptor.isEqual(to: rhs.descriptor) && areArgumentsEqual(lhs.argument, rhs.argument) + return lhs.descriptor == rhs.descriptor && areArgumentsEqual(lhs.argument, rhs.argument) } private static func areArgumentsEqual(_ lhs: Any, _ rhs: Any) -> Bool { diff --git a/Sources/Core/TypeDescriptor.swift b/Sources/Core/TypeDescriptor.swift index 20b0ef6d..d06ff8a5 100644 --- a/Sources/Core/TypeDescriptor.swift +++ b/Sources/Core/TypeDescriptor.swift @@ -2,32 +2,24 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -public struct TypeDescriptor { +public struct TypeDescriptor: Hashable { let tag: Matchable let rootType: Any.Type - func isEqual(to other: TypeDescriptor) -> Bool { - return rootType == other.rootType && tag.matches(other.tag) - } - - func hash(into hasher: inout Hasher) { + public func hash(into hasher: inout Hasher) { ObjectIdentifier(rootType).hash(into: &hasher) tag.hash(into: &hasher) } + + public static func == (lhs: TypeDescriptor, rhs: TypeDescriptor) -> Bool { + return lhs.rootType == rhs.rootType && lhs.tag.matches(rhs.tag) + } } struct NoTag: Hashable {} func tagged(_: Type.Type, with tag: Tag) -> TypeDescriptor where Tag: Hashable { - return TypeDescriptor(tag: box(tag), rootType: { - if let optional = Type.self as? OptionalProtocol.Type { - if let doubleOptional = optional.wrappedType as? OptionalProtocol.Type { - return doubleOptional.wrappedType - } - return optional.wrappedType - } - return Type.self - }()) + return TypeDescriptor(tag: box(tag), rootType: root(of: Type.self)) } func plain(_: Type.Type) -> TypeDescriptor { @@ -42,6 +34,11 @@ func named(_: Type.Type, name: String?) -> TypeDescriptor { } } +private func root(of type: Any.Type) -> Any.Type { + guard let optional = type as? OptionalProtocol.Type else { return type } + return root(of: optional.wrappedType) +} + protocol OptionalProtocol { static var wrappedType: Any.Type { get } } From 699282a5433dd956509dcd1fe1fea74721402826 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 4 Aug 2019 09:26:46 +0200 Subject: [PATCH 189/239] Make property wrappers compile on swift 5 --- Sources/2.0 API/InstanceWrapper.swift | 61 ++++++++++++++++++--------- Sources/Core/PropertyWrapper.swift | 2 +- 2 files changed, 41 insertions(+), 22 deletions(-) diff --git a/Sources/2.0 API/InstanceWrapper.swift b/Sources/2.0 API/InstanceWrapper.swift index e75b4a05..9f75e639 100644 --- a/Sources/2.0 API/InstanceWrapper.swift +++ b/Sources/2.0 API/InstanceWrapper.swift @@ -5,21 +5,27 @@ /// Wrapper to enable delayed dependency instantiation. /// `Lazy` does not need to be explicitly registered into the `Container` - resolution will work /// as long as there is a registration for the `Type`. -@propertyWrapper public enum Lazy: PropertyWrapper { - /// Getter for the wrapped object. - /// It will be resolved from the `Container` when first accessed, all other calls will return the same instance. - public var instance: Value { - mutating get { return wrappedValue } - } +#if swift(>=5.1) + @propertyWrapper public enum Lazy: PropertyWrapper { + case uninitialized(() -> Value) + case initialized(Value) - case uninitialized(() -> Value) - case initialized(Value) + public var wrappedValue: Value { + mutating get { instance } + } + } - public init(wrappedValue: @autoclosure @escaping () -> Value) { - self = .uninitialized(wrappedValue) +#else + public enum Lazy: PropertyWrapper { + case uninitialized(() -> Value) + case initialized(Value) } +#endif - public var wrappedValue: Value { +public extension Lazy { + /// Getter for the wrapped object. + /// It will be resolved from the `Container` when first accessed, all other calls will return the same instance. + var instance: Value { mutating get { switch self { case let .uninitialized(initializer): @@ -34,25 +40,38 @@ self = .initialized(newValue) } } + + init(wrappedValue: @autoclosure @escaping () -> Value) { + self = .uninitialized(wrappedValue) + } } /// Wrapper to enable delayed dependency instantiation. /// `Provider` does not need to be explicitly registered into the `Container` - resolution will work /// as long as there is a registration for the `Type`. -@propertyWrapper public struct Provider: PropertyWrapper { - /// Getter for the wrapped object. - /// New instance will be resolved from the `Container` every time it is accessed. - public var instance: Type { - return wrappedValue - } +#if swift(>=5.1) + @propertyWrapper public struct Provider: PropertyWrapper { + private let provider: () -> Type - private let provider: () -> Type + public var wrappedValue: Type { + return instance + } + } - public init(wrappedValue: @autoclosure @escaping () -> Type) { - provider = wrappedValue +#else + public struct Provider: PropertyWrapper { + private let provider: () -> Type } +#endif - public var wrappedValue: Type { +public extension Provider { + /// Getter for the wrapped object. + /// New instance will be resolved from the `Container` every time it is accessed. + var instance: Type { return provider() } + + init(wrappedValue: @autoclosure @escaping () -> Type) { + provider = wrappedValue + } } diff --git a/Sources/Core/PropertyWrapper.swift b/Sources/Core/PropertyWrapper.swift index aebff18b..38c2e90f 100644 --- a/Sources/Core/PropertyWrapper.swift +++ b/Sources/Core/PropertyWrapper.swift @@ -29,7 +29,7 @@ extension PropertyWrapper { private extension InjectionRequest { func replacingType(with _: Type.Type) -> InjectionRequest { - InjectionRequest( + return InjectionRequest( descriptor: TypeDescriptor( tag: descriptor.tag, rootType: Type.self From 7ea1be7601470b8e7c812f9d07598072e923d359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 4 Aug 2019 09:57:58 +0200 Subject: [PATCH 190/239] Revert Provider behavior on graph scope --- Sources/2.0 API/Container.swift | 23 +++++---- Sources/2.0 API/InstanceWrapper.swift | 5 ++ Sources/2.0 API/ObjectScope.swift | 9 +--- Sources/Core/PropertyWrapper.swift | 2 +- Sources/Core/Resolver.swift | 5 ++ Sources/Core/Swinject.swift | 10 ++-- Tests/2.0 API/ProviderSpec.swift | 71 ++++++++++----------------- 7 files changed, 55 insertions(+), 70 deletions(-) diff --git a/Sources/2.0 API/Container.swift b/Sources/2.0 API/Container.swift index fed0b0c3..6e48e7c8 100644 --- a/Sources/2.0 API/Container.swift +++ b/Sources/2.0 API/Container.swift @@ -26,14 +26,6 @@ public final class Container { let defaultMakeRef: ReferenceMaker var bindings = [BindingKey: Binding]() var behaviors = [Behavior]() - var swinject: Swinject { return Swinject( - tree: SwinjectTree(bindings: [], modules: [], translators: []), - container: SwinjectContainer( - bindings: allBindings, - translators: [registerContextTranslator(from: Graph.self) { $0.container }] - ), - context: () - ) } var allBindings: [BindingKey: Binding] { return bindings.merging(parent?.allBindings ?? [:]) { mine, _ in mine } } @@ -148,10 +140,17 @@ extension Container: CustomStringConvertible { } } -// MARK: Resolver +// MARK: Swinject Aware -extension Container: Resolver { - public func resolve(_ request: InjectionRequest) throws -> Type { - return try swinject.on(Graph(on: self)).resolve(request) +extension Container: SwinjectAware { + public var swinject: Resolver { + return Swinject( + tree: SwinjectTree(bindings: [], modules: [], translators: []), + container: SwinjectContainer( + bindings: allBindings, + translators: [] + ), + context: Graph() + ) } } diff --git a/Sources/2.0 API/InstanceWrapper.swift b/Sources/2.0 API/InstanceWrapper.swift index 9f75e639..29753019 100644 --- a/Sources/2.0 API/InstanceWrapper.swift +++ b/Sources/2.0 API/InstanceWrapper.swift @@ -74,4 +74,9 @@ public extension Provider { init(wrappedValue: @autoclosure @escaping () -> Type) { provider = wrappedValue } + + init(resolver: Resolver, request: InjectionRequest) { + // swiftlint:disable:next force_try + self.init(wrappedValue: try! resolver.on(Graph()).resolve(request.replacingType(with: Value.self))) + } } diff --git a/Sources/2.0 API/ObjectScope.swift b/Sources/2.0 API/ObjectScope.swift index 4076d2a4..c3c88b72 100644 --- a/Sources/2.0 API/ObjectScope.swift +++ b/Sources/2.0 API/ObjectScope.swift @@ -44,11 +44,6 @@ extension ObjectScope { final class Graph { let registry = StandardScopeRegistry() - let container: Container - - init(on container: Container) { - self.container = container - } } final class GraphScope: Scope, CustomStringConvertible { @@ -70,7 +65,7 @@ final class ContainerScope: Scope, CustomStringConvertible { self.description = description } - func registry(for container: Container) -> ScopeRegistry { - return container.registry + func registry(for context: Any) -> ScopeRegistry { + return (context as! Container).registry } } diff --git a/Sources/Core/PropertyWrapper.swift b/Sources/Core/PropertyWrapper.swift index 38c2e90f..f5abe891 100644 --- a/Sources/Core/PropertyWrapper.swift +++ b/Sources/Core/PropertyWrapper.swift @@ -27,7 +27,7 @@ extension PropertyWrapper { } } -private extension InjectionRequest { +extension InjectionRequest { func replacingType(with _: Type.Type) -> InjectionRequest { return InjectionRequest( descriptor: TypeDescriptor( diff --git a/Sources/Core/Resolver.swift b/Sources/Core/Resolver.swift index 0f807ba7..10ac76cb 100644 --- a/Sources/Core/Resolver.swift +++ b/Sources/Core/Resolver.swift @@ -4,6 +4,7 @@ public protocol Resolver { func resolve(_ request: InjectionRequest) throws -> Type + func on(_ context: Context) -> Resolver } public protocol SwinjectAware: Resolver { @@ -14,4 +15,8 @@ public extension SwinjectAware { func resolve(_ request: InjectionRequest) throws -> Type { return try swinject.resolve(request) } + + func on(_ context: Context) -> Resolver { + return swinject.on(context) + } } diff --git a/Sources/Core/Swinject.swift b/Sources/Core/Swinject.swift index d82637b5..5cea5501 100644 --- a/Sources/Core/Swinject.swift +++ b/Sources/Core/Swinject.swift @@ -26,12 +26,6 @@ public struct Swinject { } } -extension Swinject { - public func on(_ context: Context) -> Swinject { - return Swinject(tree: tree, container: container, context: context) - } -} - extension Swinject: Resolver { public func resolve(_ request: InjectionRequest) throws -> Type { let binding: Binding @@ -48,6 +42,10 @@ extension Swinject: Resolver { ) } + public func on(_ context: Context) -> Resolver { + return Swinject(tree: tree, container: container, context: context) + } + private func resolve(_ request: InjectionRequest, asCustom _: Type.Type) -> Type? { guard let custom = Type.self as? CustomResolvable.Type else { return nil } if let request = custom.requiredRequest(for: request), !hasBinding(for: request) { return nil } diff --git a/Tests/2.0 API/ProviderSpec.swift b/Tests/2.0 API/ProviderSpec.swift index c87054ff..fd202068 100644 --- a/Tests/2.0 API/ProviderSpec.swift +++ b/Tests/2.0 API/ProviderSpec.swift @@ -12,6 +12,7 @@ class ProviderSpec: QuickSpec { beforeEach { container = Container() } + describe("instance production") { it("provides instance from container") { container.register(Animal.self) { _ in Dog() } @@ -26,6 +27,16 @@ class ProviderSpec: QuickSpec { expect(created).to(beFalse()) } + it("resolves instance from the container each time") { + var created = 0 + container.register(Animal.self) { _ in created += 1; return Dog() } + + let provider = container.resolve(Provider.self) + _ = provider?.instance + _ = provider?.instance + + expect(created) == 2 + } it("does not resolve provider if base type is not registered") { let provider = container.resolve(Provider.self) expect(provider).to(beNil()) @@ -33,57 +44,30 @@ class ProviderSpec: QuickSpec { } describe("object scopes") { context("in transient scope") { - it("resolves instance from the container each time") { - var created = 0 - container.register(Animal.self) { _ in created += 1; return Dog() } - .inObjectScope(.transient) - - let provider = container.resolve(Provider.self) - _ = provider?.instance - _ = provider?.instance - - expect(created) == 2 - } - it("always produces different instance from different providers") { + beforeEach { EmploymentAssembly(scope: .transient).assemble(container: container) + } + it("always produces different instance") { let employer = container.resolve(Employer.self)! expect(employer.providedEmployee.instance) !== employer.providedEmployee.instance expect(employer.employee.providedCustomer.instance) !== employer.providedCustomer.instance } } context("in graph scope") { - it("resolves instance from the container only once") { - var created = 0 - container.register(Animal.self) { _ in created += 1; return Dog() } - .inObjectScope(.graph) - - let provider = container.resolve(Provider.self) - _ = provider?.instance - _ = provider?.instance - - expect(created) == 1 - } - it("always produces the same instance from different providers") { + beforeEach { EmploymentAssembly(scope: .graph).assemble(container: container) + } + it("always produces different instance") { let employer = container.resolve(Employer.self)! - expect(employer.providedEmployee.instance) === employer.providedEmployee.instance - expect(employer.employee.providedCustomer.instance) === employer.providedCustomer.instance + expect(employer.providedEmployee.instance) !== employer.providedEmployee.instance + expect(employer.employee.providedCustomer.instance) !== employer.providedCustomer.instance } } context("in container scope") { - it("resolves instance from the container only once") { - var created = 0 - container.register(Animal.self) { _ in created += 1; return Dog() } - .inObjectScope(.container) - - let provider = container.resolve(Provider.self) - _ = provider?.instance - _ = provider?.instance - - expect(created) == 1 - } - it("always produces the same instance from different providers") { + beforeEach { EmploymentAssembly(scope: .container).assemble(container: container) + } + it("always produces the same instance") { let employer = container.resolve(Employer.self)! expect(employer.providedEmployee.instance) === employer.providedEmployee.instance expect(employer.employee.providedCustomer.instance) === employer.providedCustomer.instance @@ -116,14 +100,13 @@ class ProviderSpec: QuickSpec { beforeEach { EmploymentAssembly(scope: .graph).assemble(container: container) } - it("resolves dependencies to same instance") { - let employer = container.resolve(Employer.self) + it("resolves non-provided dependencies to the same instance") { + let employer = container.resolve(Provider.self)?.instance expect(employer?.employee.employer) === employer - expect(employer?.providedEmployee.instance.employer) === employer } - it("resolves circular dependencies for lazy instance") { - let employee = container.resolve(Provider.self) - expect(employee?.instance.employer).notTo(beNil()) + it("resolves provided dependencies to different instances") { + let employer = container.resolve(Employer.self) + expect(employer?.providedEmployee.instance.employer) !== employer } } } From e6cc08f7f65f2ffc6b09f16ed03e4c2cd20dc82c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 4 Aug 2019 10:35:41 +0200 Subject: [PATCH 191/239] Do not release instance in .weak scope during graph resolution --- Sources/2.0 API/ObjectScope.swift | 42 +++++++++++++++---- Sources/2.0 API/ServiceEntry.swift | 6 ++- Tests/2.0 API/ContainerSpec.Circularity.swift | 27 ++++++------ 3 files changed, 50 insertions(+), 25 deletions(-) diff --git a/Sources/2.0 API/ObjectScope.swift b/Sources/2.0 API/ObjectScope.swift index c3c88b72..a4f5a6c9 100644 --- a/Sources/2.0 API/ObjectScope.swift +++ b/Sources/2.0 API/ObjectScope.swift @@ -26,8 +26,8 @@ extension ObjectScope { var scope: AnyScope? { switch self { case .graph: return GraphScope.shared - case .container: return ContainerScope.container - case .weak: return ContainerScope.weak + case .container: return ContainerScope.shared + case .weak: return WeakScope.shared case .transient: return nil } } @@ -56,16 +56,40 @@ final class GraphScope: Scope, CustomStringConvertible { } final class ContainerScope: Scope, CustomStringConvertible { - static let container = ContainerScope("container") - static let weak = ContainerScope("weak") + static let shared = ContainerScope() + let description = "container" - let description: String - - init(_ description: String) { - self.description = description + func registry(for context: Any) -> ScopeRegistry { + return (context as! Container).registry } +} + +final class WeakScope: Scope, CustomStringConvertible { + static let shared = WeakScope() + let description = "weak" func registry(for context: Any) -> ScopeRegistry { - return (context as! Container).registry + let (container, graph) = context as! (Container, Graph) + return ComposedRegistry( + primary: container.registry, + backup: graph.registry + ) + } +} + +struct ComposedRegistry: ScopeRegistry { + let primary: ScopeRegistry + let backup: ScopeRegistry + + func instance( + for key: ScopeRegistryKey, builder: () throws -> Reference, finalizer: (Any) throws -> Void + ) rethrows -> Any { + let instance = try primary.instance(for: key, builder: builder, finalizer: finalizer) + _ = backup.instance(for: key) { strongRef(instance) } + return instance + } + + func clear() { + primary.clear() } } diff --git a/Sources/2.0 API/ServiceEntry.swift b/Sources/2.0 API/ServiceEntry.swift index 45e89b36..0a26eed9 100644 --- a/Sources/2.0 API/ServiceEntry.swift +++ b/Sources/2.0 API/ServiceEntry.swift @@ -92,9 +92,11 @@ extension ServiceEntry: Binding { private func getRegistry(scope: AnyScope, context: Any) -> ScopeRegistry { if scope is ContainerScope, let container = container { return scope.registry(for: container) - } else { - return scope.registry(for: context) } + if scope is WeakScope, let container = container, let graph = context as? Graph { + return scope.registry(for: (container, graph)) + } + return scope.registry(for: context) } public var key: BindingKey { diff --git a/Tests/2.0 API/ContainerSpec.Circularity.swift b/Tests/2.0 API/ContainerSpec.Circularity.swift index a3332178..6855ac4a 100644 --- a/Tests/2.0 API/ContainerSpec.Circularity.swift +++ b/Tests/2.0 API/ContainerSpec.Circularity.swift @@ -116,19 +116,18 @@ class ContainerSpec_Circularity: QuickSpec { expect(d.c as? CDependingOnAD === c).to(beTrue()) // Workaround for crash in Nimble } } - // TODO: Implement subscopes -// describe("Graph root is in weak object scope") { -// it("does not deallocate during graph resolution") { -// container.register(B.self) { r in BDependingOnC(c: r.resolve(C.self)!) } -// .inObjectScope(.weak) -// container.register(C.self) { _ in CDependingOnWeakB() } -// .initCompleted { r, c in (c as! CDependingOnWeakB).b = r.resolve(B.self) } -// -// let b = container.resolve(B.self) as? BDependingOnC -// let c = b?.c as? CDependingOnWeakB -// -// expect(c?.b).notTo(beNil()) -// } -// } + describe("Graph root is in weak object scope") { + it("does not deallocate during graph resolution") { + container.register(B.self) { r in BDependingOnC(c: r.resolve(C.self)!) } + .inObjectScope(.weak) + container.register(C.self) { _ in CDependingOnWeakB() } + .initCompleted { r, c in (c as! CDependingOnWeakB).b = r.resolve(B.self) } + + let b = container.resolve(B.self) as? BDependingOnC + let c = b?.c as? CDependingOnWeakB + + expect(c?.b).notTo(beNil()) + } + } } } From 02fcc1bf0a007fd4ab1a9cce92651b3c77a8598f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 4 Aug 2019 11:03:41 +0200 Subject: [PATCH 192/239] Enable injection on optional contexts --- Sources/Core/Binding.swift | 12 ++++++++++++ Sources/Core/PropertyWrapper.swift | 2 +- Sources/Core/Swinject.swift | 4 ++-- Sources/Core/SwinjectError.swift | 1 + Sources/Core/TypeDescriptor.swift | 12 ++++++------ Tests/3.0 API/OptionalsSpec.swift | 26 ++++++++++++-------------- 6 files changed, 34 insertions(+), 23 deletions(-) diff --git a/Sources/Core/Binding.swift b/Sources/Core/Binding.swift index 7e00e112..80fc671d 100644 --- a/Sources/Core/Binding.swift +++ b/Sources/Core/Binding.swift @@ -7,6 +7,12 @@ public struct BindingKey: Hashable { let contextType: Any.Type let argumentType: Any.Type + init(descriptor: TypeDescriptor, contextType: Any.Type, argumentType: Any.Type) { + self.descriptor = descriptor + self.contextType = unwrapOptionals(contextType) + self.argumentType = argumentType + } + public func hash(into hasher: inout Hasher) { descriptor.hash(into: &hasher) ObjectIdentifier(contextType).hash(into: &hasher) @@ -20,6 +26,12 @@ public struct BindingKey: Hashable { } } +extension BindingKey { + func matches(contextType: Any.Type) -> Bool { + return self.contextType == Any.self || self.contextType == unwrapOptionals(contextType) + } +} + public protocol Binding: SwinjectEntry { var key: BindingKey { get } var properties: BindingProperties { get } diff --git a/Sources/Core/PropertyWrapper.swift b/Sources/Core/PropertyWrapper.swift index f5abe891..8a9700ba 100644 --- a/Sources/Core/PropertyWrapper.swift +++ b/Sources/Core/PropertyWrapper.swift @@ -32,7 +32,7 @@ extension InjectionRequest { return InjectionRequest( descriptor: TypeDescriptor( tag: descriptor.tag, - rootType: Type.self + type: Type.self ), argument: argument, argumentType: argumentType diff --git a/Sources/Core/Swinject.swift b/Sources/Core/Swinject.swift index 5cea5501..fedadfd4 100644 --- a/Sources/Core/Swinject.swift +++ b/Sources/Core/Swinject.swift @@ -54,8 +54,8 @@ extension Swinject: Resolver { private func findTranslator(for binding: Binding) throws -> AnyContextTranslator { return try allTranslators - .filter { binding.key.contextType == Any.self || binding.key.contextType == $0.targetType } - .first ?? { throw SwinjectError() }() + .filter { binding.key.matches(contextType: $0.targetType) } + .first ?? { throw NoContextTranslator() }() } private func translatableKeys(for request: InjectionRequest) -> [BindingKey] { diff --git a/Sources/Core/SwinjectError.swift b/Sources/Core/SwinjectError.swift index 51a87d2d..49c24d4c 100644 --- a/Sources/Core/SwinjectError.swift +++ b/Sources/Core/SwinjectError.swift @@ -18,5 +18,6 @@ public class DuplicateModules: SwinjectError {} public class OverrideNotAllowed: SwinjectError {} public class NothingToOverride: SwinjectError {} public class SilentOverrideNotAllowed: SwinjectError {} +public class NoContextTranslator: SwinjectError {} // TODO: Debugging error description diff --git a/Sources/Core/TypeDescriptor.swift b/Sources/Core/TypeDescriptor.swift index d06ff8a5..85b5d370 100644 --- a/Sources/Core/TypeDescriptor.swift +++ b/Sources/Core/TypeDescriptor.swift @@ -4,22 +4,22 @@ public struct TypeDescriptor: Hashable { let tag: Matchable - let rootType: Any.Type + let type: Any.Type public func hash(into hasher: inout Hasher) { - ObjectIdentifier(rootType).hash(into: &hasher) + ObjectIdentifier(type).hash(into: &hasher) tag.hash(into: &hasher) } public static func == (lhs: TypeDescriptor, rhs: TypeDescriptor) -> Bool { - return lhs.rootType == rhs.rootType && lhs.tag.matches(rhs.tag) + return lhs.type == rhs.type && lhs.tag.matches(rhs.tag) } } struct NoTag: Hashable {} func tagged(_: Type.Type, with tag: Tag) -> TypeDescriptor where Tag: Hashable { - return TypeDescriptor(tag: box(tag), rootType: root(of: Type.self)) + return TypeDescriptor(tag: box(tag), type: unwrapOptionals(Type.self)) } func plain(_: Type.Type) -> TypeDescriptor { @@ -34,9 +34,9 @@ func named(_: Type.Type, name: String?) -> TypeDescriptor { } } -private func root(of type: Any.Type) -> Any.Type { +func unwrapOptionals(_ type: Any.Type) -> Any.Type { guard let optional = type as? OptionalProtocol.Type else { return type } - return root(of: optional.wrappedType) + return unwrapOptionals(optional.wrappedType) } protocol OptionalProtocol { diff --git a/Tests/3.0 API/OptionalsSpec.swift b/Tests/3.0 API/OptionalsSpec.swift index a296022c..f0ee5acc 100644 --- a/Tests/3.0 API/OptionalsSpec.swift +++ b/Tests/3.0 API/OptionalsSpec.swift @@ -13,13 +13,12 @@ class OptionalsSpec: QuickSpec { override func spec() { #if swift(>=5.1) } expect { try swinject.instance() as Int? } == 42 } - // TODO: Maybe nice to have? -// it("can use a binding of the injected type's optional") { -// let swinject = Swinject { -// bbind(Int?.self) & 42 -// } -// expect { try swinject.instance() as Int } == 42 -// } + it("can use a binding of the injected type's optional") { + let swinject = Swinject { + bbind(Int?.self) & 42 + } + expect { try swinject.instance() as Int } == 42 + } it("throws if binding of the type's optional produces nil") { let swinject = Swinject { bbind(Int?.self) & nil @@ -50,12 +49,11 @@ class OptionalsSpec: QuickSpec { override func spec() { #if swift(>=5.1) let optional = try? swinject.instance(of: Human?.self) expect(direct) === optional } - // TODO: Optional contexts -// it("injects instance on the optional of a binding's context") { -// let swinject = Swinject { -// bbind(Int.self) & contexted(String.self).provider { (_, c: String) in Int(c)! } -// } -// expect { try swinject.on("42" as String?).instance(of: Int.self) } == 42 -// } + it("injects instance on the optional of a binding's context") { + let swinject = Swinject { + bbind(Int.self) & contexted(String.self).provider { (_, c: String) in Int(c)! } + } + expect { try swinject.on("42" as String?).instance(of: Int.self) } == 42 + } #endif } } From e3e29399ed2c429063683c24bc3145630ff3a2bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 4 Aug 2019 12:01:56 +0200 Subject: [PATCH 193/239] Implement function parameters injection --- Sources/3.0 API/Resolver+FunctionCall.swift | 89 +++++++++++++++++++ Swinject.xcodeproj/project.pbxproj | 14 +++ .../Resolver+FunctionCallApi.swifttemplate | 14 +++ Tests/3.0 API/InjectionSpec.swift | 45 ++++++++++ Tests/Support/TestModels.swift | 6 ++ 5 files changed, 168 insertions(+) create mode 100644 Sources/3.0 API/Resolver+FunctionCall.swift create mode 100644 Templates/Resolver+FunctionCallApi.swifttemplate diff --git a/Sources/3.0 API/Resolver+FunctionCall.swift b/Sources/3.0 API/Resolver+FunctionCall.swift new file mode 100644 index 00000000..2ff328c4 --- /dev/null +++ b/Sources/3.0 API/Resolver+FunctionCall.swift @@ -0,0 +1,89 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +// swiftlint:disable line_length +// sourcery:inline:ResolverFunctionCallApi +public extension Resolver { + func call1(_ function: (P1) -> Output) throws -> Output { + return try function(instance()) + } + + func call(_ function: (P1, P2) -> Output) throws -> Output { + return try function(instance(), instance()) + } + + func call(_ function: (P1, P2, P3) -> Output) throws -> Output { + return try function(instance(), instance(), instance()) + } + + func call(_ function: (P1, P2, P3, P4) -> Output) throws -> Output { + return try function(instance(), instance(), instance(), instance()) + } + + func call(_ function: (P1, P2, P3, P4, P5) -> Output) throws -> Output { + return try function(instance(), instance(), instance(), instance(), instance()) + } + + func call(_ function: (P1, P2, P3, P4, P5, P6) -> Output) throws -> Output { + return try function(instance(), instance(), instance(), instance(), instance(), instance()) + } + + func call(_ function: (P1, P2, P3, P4, P5, P6, P7) -> Output) throws -> Output { + return try function(instance(), instance(), instance(), instance(), instance(), instance(), instance()) + } + + func call(_ function: (P1, P2, P3, P4, P5, P6, P7, P8) -> Output) throws -> Output { + return try function(instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance()) + } + + func call(_ function: (P1, P2, P3, P4, P5, P6, P7, P8, P9) -> Output) throws -> Output { + return try function(instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance()) + } + + func call(_ function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10) -> Output) throws -> Output { + return try function(instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance()) + } + + func call(_ function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11) -> Output) throws -> Output { + return try function(instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance()) + } + + func call(_ function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12) -> Output) throws -> Output { + return try function(instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance()) + } + + func call(_ function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13) -> Output) throws -> Output { + return try function(instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance()) + } + + func call(_ function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14) -> Output) throws -> Output { + return try function(instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance()) + } + + func call(_ function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15) -> Output) throws -> Output { + return try function(instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance()) + } + + func call(_ function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16) -> Output) throws -> Output { + return try function(instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance()) + } + + func call(_ function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17) -> Output) throws -> Output { + return try function(instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance()) + } + + func call(_ function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18) -> Output) throws -> Output { + return try function(instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance()) + } + + func call(_ function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19) -> Output) throws -> Output { + return try function(instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance()) + } + + func call(_ function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20) -> Output) throws -> Output { + return try function(instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance()) + } +} + +// sourcery:end diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 90e42412..d6cd4629 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -282,6 +282,11 @@ CD73B9D422F239A6004BB84E /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; CD73B9D522F239A6004BB84E /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; CD73B9D622F239A6004BB84E /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; + CDE303DC22F6DDA900846EFA /* Resolver+FunctionCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE303DB22F6DDA900846EFA /* Resolver+FunctionCall.swift */; }; + CDE303DD22F6DDA900846EFA /* Resolver+FunctionCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE303DB22F6DDA900846EFA /* Resolver+FunctionCall.swift */; }; + CDE303DE22F6DDA900846EFA /* Resolver+FunctionCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE303DB22F6DDA900846EFA /* Resolver+FunctionCall.swift */; }; + CDE303DF22F6DDA900846EFA /* Resolver+FunctionCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE303DB22F6DDA900846EFA /* Resolver+FunctionCall.swift */; }; + CDE303E122F6DF7500846EFA /* Resolver+FunctionCallApi.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = CDE303E022F6DF7500846EFA /* Resolver+FunctionCallApi.swifttemplate */; }; CE5AFED22F04B96713ED76D7 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ADC44E9312C3B974AFD8F07B /* Nimble.framework */; }; CECF5BD14BCDF5248771A06A /* InjectionRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InjectionRequest.swift */; }; CEE763218A90832454A6E2DE /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */; }; @@ -538,6 +543,8 @@ CD68675F22F5C60800F7D9E3 /* PropertyWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PropertyWrapper.swift; sourceTree = ""; }; CD68676422F5CA5D00F7D9E3 /* PropertyWrappersSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PropertyWrappersSpec.swift; sourceTree = ""; }; CDA78290D6D60BD0B808571F /* Container+Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Logging.swift"; sourceTree = ""; }; + CDE303DB22F6DDA900846EFA /* Resolver+FunctionCall.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Resolver+FunctionCall.swift"; sourceTree = ""; }; + CDE303E022F6DF7500846EFA /* Resolver+FunctionCallApi.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+FunctionCallApi.swifttemplate"; sourceTree = ""; }; CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextSpec.swift; sourceTree = ""; }; E0874A043EAEE3C7CF1EA063 /* InjectionRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InjectionRequest.swift; sourceTree = ""; }; @@ -606,6 +613,7 @@ BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */, 90191C25A2D66E07C4E9CD73 /* SwiftCode.swifttemplate */, 1A006CC804F9AB8ACC121029 /* Utils.swift */, + CDE303E022F6DF7500846EFA /* Resolver+FunctionCallApi.swifttemplate */, ); path = Templates; sourceTree = ""; @@ -648,6 +656,7 @@ children = ( B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */, 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */, + CDE303DB22F6DDA900846EFA /* Resolver+FunctionCall.swift */, 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */, B92B8E618A08408404FB2A7A /* TypeBinder.swift */, ); @@ -1129,6 +1138,7 @@ buildActionMask = 2147483647; files = ( BEFFC7B36FE5810169C81B97 /* BinderEnvironment.swifttemplate in Resources */, + CDE303E122F6DF7500846EFA /* Resolver+FunctionCallApi.swifttemplate in Resources */, BFE22F9F2E88F177302E9D19 /* Container+Registration.swifttemplate in Resources */, 1C82BFD00FCC384DB3AE6A89 /* MatchableBoxes.swifttemplate in Resources */, 71895EBC0803EEE3BFCD7001 /* Resolver+Injection.swifttemplate in Resources */, @@ -1391,6 +1401,7 @@ AAD8D0551B8A26A9B22AECEC /* Container+Registration.swift in Sources */, 996CCFE825834C7D3236E742 /* Container+TypeForwarding.swift in Sources */, B2FAD41F7726502822AF913B /* Container.swift in Sources */, + CDE303DD22F6DDA900846EFA /* Resolver+FunctionCall.swift in Sources */, CD68676122F5C85B00F7D9E3 /* PropertyWrapper.swift in Sources */, 8B5927517B567B1DFAB5B935 /* ContextTranslator.swift in Sources */, 6C4D29A3FB54416D5E4D4C89 /* InstanceBuilder.swift in Sources */, @@ -1608,6 +1619,7 @@ A5E4C79F89E1A8AB3A4D8D6E /* Container+Registration.swift in Sources */, BD9B57E26722C80B7EF990DB /* Container+TypeForwarding.swift in Sources */, DB74F17CDFF4886B9C38AD14 /* Container.swift in Sources */, + CDE303DE22F6DDA900846EFA /* Resolver+FunctionCall.swift in Sources */, CD68676222F5C85B00F7D9E3 /* PropertyWrapper.swift in Sources */, DD5E3AF2B5FCE5E81EBDF606 /* ContextTranslator.swift in Sources */, 7F9686F3669BF35E5AC970B3 /* InstanceBuilder.swift in Sources */, @@ -1651,6 +1663,7 @@ CB0B308F3D3A831A28127462 /* Container+Registration.swift in Sources */, 283C77045DA55C2134EC9C48 /* Container+TypeForwarding.swift in Sources */, 58ABEE0321A3061048B65EA2 /* Container.swift in Sources */, + CDE303DF22F6DDA900846EFA /* Resolver+FunctionCall.swift in Sources */, CD68676322F5C85B00F7D9E3 /* PropertyWrapper.swift in Sources */, F06DEB671A4B85ABB0E96E51 /* ContextTranslator.swift in Sources */, DBEFC5C6A51FCEBF9E4F70EE /* InstanceBuilder.swift in Sources */, @@ -1694,6 +1707,7 @@ 21285CED416F1317E993397A /* Container+Registration.swift in Sources */, 3A0B409E840B44B281DB3C54 /* Container+TypeForwarding.swift in Sources */, 0622539110A7430776A307C7 /* Container.swift in Sources */, + CDE303DC22F6DDA900846EFA /* Resolver+FunctionCall.swift in Sources */, D1DF4740A9D86362B63104B8 /* ContextTranslator.swift in Sources */, B90EA5A6764CEFA2BCB6C4D9 /* InstanceBuilder.swift in Sources */, 128913D570B4A8BBF40866BE /* InjectionRequest.swift in Sources */, diff --git a/Templates/Resolver+FunctionCallApi.swifttemplate b/Templates/Resolver+FunctionCallApi.swifttemplate new file mode 100644 index 00000000..f13c0042 --- /dev/null +++ b/Templates/Resolver+FunctionCallApi.swifttemplate @@ -0,0 +1,14 @@ +<% let maxParams = 20 %> +// sourcery:inline:ResolverFunctionCallApi +public extension Resolver { +<%_ for n in 1 ... maxParams { + let paramTypes = (1 ... n).map { "P\($0)" }.joined(separator: ", ") + let instances = (1 ... n).map { _ in "instance()" }.joined(separator: ", ") + let methodName = n == 1 ? "call1" : "call" +-%> + func <%= methodName %>>(_ function: (<%= paramTypes %>) -> Output) throws -> Output { + return try function(<%= instances %>) + }<%= n < maxParams ? "\n" : "" %> +<%_ } -%> +} +// sourcery:end diff --git a/Tests/3.0 API/InjectionSpec.swift b/Tests/3.0 API/InjectionSpec.swift index 2d171d40..1d2507b4 100644 --- a/Tests/3.0 API/InjectionSpec.swift +++ b/Tests/3.0 API/InjectionSpec.swift @@ -105,5 +105,50 @@ class InjectionSpec: QuickSpec { override func spec() { #if swift(>=5.1) expect { try swinject.instance(arg: 11, 14.0, "17") as Int } == 42 } } + describe("function call") { + it("can inject parameter to the function") { + func echo(int: Int) -> Int { + return int + } + let swinject = Swinject { + bbind(Int.self) & 42 + } + expect { try swinject.call1(echo) } == 42 + } + it("can inject multiple parameters to the function") { + func sum(int: Int, double: Double, string: String) -> Int { + return int + Int(double) + Int(string)! + } + let swinject = Swinject { + bbind(Int.self) & 17 + bbind(Double.self) & 14.0 + bbind(String.self) & "11" + } + expect { try swinject.call(sum) } == 42 + } + it("can call initializer when declaring bindings") { + let john = Human() + let swinject = Swinject { + bbind(String.self) & "mimi" + bbind(Human.self) & john + bbind(Pet.self) & provider { try $0.call(Pet.init) } + } + let pet = try? swinject.instance(of: Pet.self) + expect(pet?.name) == "mimi" + expect(pet?.owner) === john + } + it("can be used for property injection") { + let swinject = Swinject { + bbind(Int.self) & 42 + bbind(Double.self) & 124 + bbind(String.self) & "john" + } + let john = Human() + try? swinject.call(john.injectProperties) + expect(john.age) == 42 + expect(john.height) == 124 + expect(john.name) == "john" + } + } #endif } } diff --git a/Tests/Support/TestModels.swift b/Tests/Support/TestModels.swift index 6c1ffbf0..5b822666 100644 --- a/Tests/Support/TestModels.swift +++ b/Tests/Support/TestModels.swift @@ -10,6 +10,12 @@ class Human: Mammal { var age = 0 var height = 0.0 var name = "" + + func injectProperties(age: Int, height: Double, name: String) { + self.age = age + self.height = height + self.name = name + } } class Pet { From 87f1626fba13ed06c11d11b7fbe596efac5945f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 4 Aug 2019 12:49:14 +0200 Subject: [PATCH 194/239] Allow only String as tag --- .../2.0 API/Container+TypeForwarding.swift | 2 +- Sources/2.0 API/Resolver+LegacyApi.swift | 60 +--- Sources/2.0 API/ServiceEntry.swift | 2 +- Sources/3.0 API/Resolver+Injection.swift | 314 +++--------------- Sources/3.0 API/TypeBinder.swift | 11 +- Sources/Core/InjectionRequest.swift | 4 +- Sources/Core/TypeDescriptor.swift | 22 +- Templates/InjectionVariation.swift | 11 +- Templates/Resolver+LegacyApi.swifttemplate | 12 +- Templates/SwiftCode.swifttemplate | 11 +- Tests/3.0 API/BindingSpec.swift | 2 - Tests/Support/Bridge.swift | 8 +- .../StandardScopeRegistrySpec.swift | 2 +- 13 files changed, 82 insertions(+), 379 deletions(-) diff --git a/Sources/2.0 API/Container+TypeForwarding.swift b/Sources/2.0 API/Container+TypeForwarding.swift index d93c5ff6..c331dd1e 100644 --- a/Sources/2.0 API/Container+TypeForwarding.swift +++ b/Sources/2.0 API/Container+TypeForwarding.swift @@ -22,7 +22,7 @@ extension Container { addBinding( type: type, key: BindingKey( - descriptor: named(T.self, name: name), + descriptor: tagged(T.self, with: name), contextType: service.key.contextType, argumentType: service.key.argumentType ), diff --git a/Sources/2.0 API/Resolver+LegacyApi.swift b/Sources/2.0 API/Resolver+LegacyApi.swift index ef41b22c..309b29ac 100644 --- a/Sources/2.0 API/Resolver+LegacyApi.swift +++ b/Sources/2.0 API/Resolver+LegacyApi.swift @@ -12,11 +12,7 @@ public extension Resolver { /// /// - Returns: The resolved service type instance, or nil if no service with the name is found. func resolve(_ serviceType: Service.Type, name: String? = nil) -> Service? { - if let name = name { - return try? resolve(request(type: serviceType, tag: name, arg: ())) as Service - } else { - return try? resolve(request(type: serviceType, tag: NoTag(), arg: ())) as Service - } + return try? resolve(request(type: serviceType, tag: name, arg: ())) as Service } /// Retrieves the instance with the specified service type, 1 argument to the factory closure and registration name. @@ -29,11 +25,7 @@ public extension Resolver { /// - Returns: The resolved service type instance, or nil if no registration for the service type, /// 1 argument and name is found. func resolve(_ serviceType: Service.Type, name: String? = nil, argument: Arg1) -> Service? { - if let name = name { - return try? resolve(request(type: serviceType, tag: name, arg: ())) as Service - } else { - return try? resolve(request(type: serviceType, tag: NoTag(), arg: argument)) as Service - } + return try? resolve(request(type: serviceType, tag: name, arg: argument)) as Service } /// Retrieves the instance with the specified service type, list of 2 arguments to the factory closure and registration name. @@ -46,11 +38,7 @@ public extension Resolver { /// - Returns: The resolved service type instance, or nil if no registration for the service type, /// list of 2 arguments and name is found. func resolve(_ serviceType: Service.Type, name: String? = nil, arguments arg1: Arg1, _ arg2: Arg2) -> Service? { - if let name = name { - return try? resolve(request(type: serviceType, tag: name, arg: ())) as Service - } else { - return try? resolve(request(type: serviceType, tag: NoTag(), arg: (arg1, arg2))) as Service - } + return try? resolve(request(type: serviceType, tag: name, arg: (arg1, arg2))) as Service } /// Retrieves the instance with the specified service type, list of 3 arguments to the factory closure and registration name. @@ -63,11 +51,7 @@ public extension Resolver { /// - Returns: The resolved service type instance, or nil if no registration for the service type, /// list of 3 arguments and name is found. func resolve(_ serviceType: Service.Type, name: String? = nil, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> Service? { - if let name = name { - return try? resolve(request(type: serviceType, tag: name, arg: ())) as Service - } else { - return try? resolve(request(type: serviceType, tag: NoTag(), arg: (arg1, arg2, arg3))) as Service - } + return try? resolve(request(type: serviceType, tag: name, arg: (arg1, arg2, arg3))) as Service } /// Retrieves the instance with the specified service type, list of 4 arguments to the factory closure and registration name. @@ -80,11 +64,7 @@ public extension Resolver { /// - Returns: The resolved service type instance, or nil if no registration for the service type, /// list of 4 arguments and name is found. func resolve(_ serviceType: Service.Type, name: String? = nil, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> Service? { - if let name = name { - return try? resolve(request(type: serviceType, tag: name, arg: ())) as Service - } else { - return try? resolve(request(type: serviceType, tag: NoTag(), arg: (arg1, arg2, arg3, arg4))) as Service - } + return try? resolve(request(type: serviceType, tag: name, arg: (arg1, arg2, arg3, arg4))) as Service } /// Retrieves the instance with the specified service type, list of 5 arguments to the factory closure and registration name. @@ -97,11 +77,7 @@ public extension Resolver { /// - Returns: The resolved service type instance, or nil if no registration for the service type, /// list of 5 arguments and name is found. func resolve(_ serviceType: Service.Type, name: String? = nil, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> Service? { - if let name = name { - return try? resolve(request(type: serviceType, tag: name, arg: ())) as Service - } else { - return try? resolve(request(type: serviceType, tag: NoTag(), arg: (arg1, arg2, arg3, arg4, arg5))) as Service - } + return try? resolve(request(type: serviceType, tag: name, arg: (arg1, arg2, arg3, arg4, arg5))) as Service } /// Retrieves the instance with the specified service type, list of 6 arguments to the factory closure and registration name. @@ -114,11 +90,7 @@ public extension Resolver { /// - Returns: The resolved service type instance, or nil if no registration for the service type, /// list of 6 arguments and name is found. func resolve(_ serviceType: Service.Type, name: String? = nil, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6) -> Service? { - if let name = name { - return try? resolve(request(type: serviceType, tag: name, arg: ())) as Service - } else { - return try? resolve(request(type: serviceType, tag: NoTag(), arg: (arg1, arg2, arg3, arg4, arg5, arg6))) as Service - } + return try? resolve(request(type: serviceType, tag: name, arg: (arg1, arg2, arg3, arg4, arg5, arg6))) as Service } /// Retrieves the instance with the specified service type, list of 7 arguments to the factory closure and registration name. @@ -131,11 +103,7 @@ public extension Resolver { /// - Returns: The resolved service type instance, or nil if no registration for the service type, /// list of 7 arguments and name is found. func resolve(_ serviceType: Service.Type, name: String? = nil, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7) -> Service? { - if let name = name { - return try? resolve(request(type: serviceType, tag: name, arg: ())) as Service - } else { - return try? resolve(request(type: serviceType, tag: NoTag(), arg: (arg1, arg2, arg3, arg4, arg5, arg6, arg7))) as Service - } + return try? resolve(request(type: serviceType, tag: name, arg: (arg1, arg2, arg3, arg4, arg5, arg6, arg7))) as Service } /// Retrieves the instance with the specified service type, list of 8 arguments to the factory closure and registration name. @@ -148,11 +116,7 @@ public extension Resolver { /// - Returns: The resolved service type instance, or nil if no registration for the service type, /// list of 8 arguments and name is found. func resolve(_ serviceType: Service.Type, name: String? = nil, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8) -> Service? { - if let name = name { - return try? resolve(request(type: serviceType, tag: name, arg: ())) as Service - } else { - return try? resolve(request(type: serviceType, tag: NoTag(), arg: (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8))) as Service - } + return try? resolve(request(type: serviceType, tag: name, arg: (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8))) as Service } /// Retrieves the instance with the specified service type, list of 9 arguments to the factory closure and registration name. @@ -165,11 +129,7 @@ public extension Resolver { /// - Returns: The resolved service type instance, or nil if no registration for the service type, /// list of 9 arguments and name is found. func resolve(_ serviceType: Service.Type, name: String? = nil, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8, _ arg9: Arg9) -> Service? { - if let name = name { - return try? resolve(request(type: serviceType, tag: name, arg: ())) as Service - } else { - return try? resolve(request(type: serviceType, tag: NoTag(), arg: (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9))) as Service - } + return try? resolve(request(type: serviceType, tag: name, arg: (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9))) as Service } } diff --git a/Sources/2.0 API/ServiceEntry.swift b/Sources/2.0 API/ServiceEntry.swift index 0a26eed9..fb6554dd 100644 --- a/Sources/2.0 API/ServiceEntry.swift +++ b/Sources/2.0 API/ServiceEntry.swift @@ -101,7 +101,7 @@ extension ServiceEntry: Binding { public var key: BindingKey { return BindingKey( - descriptor: named(Service.self, name: name), + descriptor: tagged(Service.self, with: name), contextType: scope?.contextType ?? Any.self, argumentType: argumentType ) diff --git a/Sources/3.0 API/Resolver+Injection.swift b/Sources/3.0 API/Resolver+Injection.swift index 466f9bd6..7cdeafc0 100644 --- a/Sources/3.0 API/Resolver+Injection.swift +++ b/Sources/3.0 API/Resolver+Injection.swift @@ -3,427 +3,217 @@ // // swiftlint:disable line_length -// swiftlint:disable function_parameter_count -// swiftlint:disable file_length // sourcery:inline:ResolverInjectionApi public extension Resolver { - func instance(of _: Type.Type = Type.self) throws -> Type { - return try resolve(request(type: Type.self, tag: NoTag(), arg: ())) - } - - func instance(of _: Type.Type = Type.self, tagged tag: Tag) throws -> Type where Tag: Hashable { + func instance(of _: Type.Type = Type.self, tagged tag: String? = nil) throws -> Type { return try resolve(request(type: Type.self, tag: tag, arg: ())) } - func instance(of _: Type.Type = Type.self, arg arg1: Arg1) throws -> Type { - return try resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1))) - } - - func instance(of _: Type.Type = Type.self, arg arg1: Arg1) throws -> Type where Arg1: Hashable { - return try resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1))) - } - - func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) throws -> Type where Tag: Hashable { + func instance(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1) throws -> Type { return try resolve(request(type: Type.self, tag: tag, arg: box(arg1))) } - func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) throws -> Type where Tag: Hashable, Arg1: Hashable { + func instance(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1) throws -> Type where Arg1: Hashable { return try resolve(request(type: Type.self, tag: tag, arg: box(arg1))) } - func instance(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2) throws -> Type { - return try resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2))) - } - - func instance(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2) throws -> Type where Arg1: Hashable, Arg2: Hashable { - return try resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2))) - } - - func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2) throws -> Type where Tag: Hashable { + func instance(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2) throws -> Type { return try resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2))) } - func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable { + func instance(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2) throws -> Type where Arg1: Hashable, Arg2: Hashable { return try resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2))) } - func instance(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) throws -> Type { - return try resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, arg3))) - } - - func instance(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - return try resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, arg3))) - } - - func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) throws -> Type where Tag: Hashable { + func instance(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) throws -> Type { return try resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3))) } - func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + func instance(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { return try resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3))) } - func instance(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) throws -> Type { - return try resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, arg3, arg4))) - } - - func instance(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return try resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, arg3, arg4))) - } - - func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) throws -> Type where Tag: Hashable { + func instance(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) throws -> Type { return try resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, arg4))) } - func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + func instance(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { return try resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, arg4))) } - func instance(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) throws -> Type { - return try resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, arg3, arg4, arg5))) - } - - func instance(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return try resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, arg3, arg4, arg5))) - } - - func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) throws -> Type where Tag: Hashable { + func instance(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) throws -> Type { return try resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, arg4, arg5))) } - func instance(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + func instance(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { return try resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, arg4, arg5))) } } public extension Resolver { - func provider(of _: Type.Type = Type.self) -> () throws -> Type { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: ())) } - } - - func provider(of _: Type.Type = Type.self, tagged tag: Tag) -> () throws -> Type where Tag: Hashable { + func provider(of _: Type.Type = Type.self, tagged tag: String? = nil) -> () throws -> Type { return { try self.resolve(request(type: Type.self, tag: tag, arg: ())) } } - func provider(of _: Type.Type = Type.self, arg arg1: Arg1) -> () throws -> Type { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1))) } - } - - func provider(of _: Type.Type = Type.self, arg arg1: Arg1) -> () throws -> Type where Arg1: Hashable { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1))) } - } - - func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) -> () throws -> Type where Tag: Hashable { + func provider(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1) -> () throws -> Type { return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1))) } } - func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) -> () throws -> Type where Tag: Hashable, Arg1: Hashable { + func provider(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1) -> () throws -> Type where Arg1: Hashable { return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1))) } } - func provider(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2) -> () throws -> Type { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2))) } - } - - func provider(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2) -> () throws -> Type where Arg1: Hashable, Arg2: Hashable { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2))) } - } - - func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2) -> () throws -> Type where Tag: Hashable { + func provider(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2) -> () throws -> Type { return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2))) } } - func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2) -> () throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable { + func provider(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2) -> () throws -> Type where Arg1: Hashable, Arg2: Hashable { return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2))) } } - func provider(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> () throws -> Type { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, arg3))) } - } - - func provider(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> () throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, arg3))) } - } - - func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> () throws -> Type where Tag: Hashable { + func provider(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> () throws -> Type { return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3))) } } - func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> () throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + func provider(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> () throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3))) } } - func provider(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> () throws -> Type { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, arg3, arg4))) } - } - - func provider(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> () throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, arg3, arg4))) } - } - - func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> () throws -> Type where Tag: Hashable { + func provider(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> () throws -> Type { return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, arg4))) } } - func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> () throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + func provider(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> () throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, arg4))) } } - func provider(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> () throws -> Type { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, arg3, arg4, arg5))) } - } - - func provider(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> () throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, arg3, arg4, arg5))) } - } - - func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> () throws -> Type where Tag: Hashable { + func provider(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> () throws -> Type { return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, arg4, arg5))) } } - func provider(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> () throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + func provider(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> () throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, arg4, arg5))) } } } public extension Resolver { - func factory(of _: Type.Type = Type.self) -> (Arg1) throws -> Type { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box($0))) } - } - - func factory(of _: Type.Type = Type.self) -> (Arg1) throws -> Type where Arg1: Hashable { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box($0))) } - } - - func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1) throws -> Type where Tag: Hashable { + func factory(of _: Type.Type = Type.self, tagged tag: String? = nil) -> (Arg1) throws -> Type { return { try self.resolve(request(type: Type.self, tag: tag, arg: box($0))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1) throws -> Type where Tag: Hashable, Arg1: Hashable { + func factory(of _: Type.Type = Type.self, tagged tag: String? = nil) -> (Arg1) throws -> Type where Arg1: Hashable { return { try self.resolve(request(type: Type.self, tag: tag, arg: box($0))) } } - func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2) throws -> Type { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box($0, $1))) } - } - - func factory(of _: Type.Type = Type.self, arg arg1: Arg1) -> (Arg2) throws -> Type { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, $0))) } - } - - func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2) throws -> Type where Arg1: Hashable, Arg2: Hashable { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box($0, $1))) } - } - - func factory(of _: Type.Type = Type.self, arg arg1: Arg1) -> (Arg2) throws -> Type where Arg1: Hashable, Arg2: Hashable { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, $0))) } - } - - func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1, Arg2) throws -> Type where Tag: Hashable { + func factory(of _: Type.Type = Type.self, tagged tag: String? = nil) -> (Arg1, Arg2) throws -> Type { return { try self.resolve(request(type: Type.self, tag: tag, arg: box($0, $1))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) -> (Arg2) throws -> Type where Tag: Hashable { + func factory(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1) -> (Arg2) throws -> Type { return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, $0))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1, Arg2) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable { + func factory(of _: Type.Type = Type.self, tagged tag: String? = nil) -> (Arg1, Arg2) throws -> Type where Arg1: Hashable, Arg2: Hashable { return { try self.resolve(request(type: Type.self, tag: tag, arg: box($0, $1))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) -> (Arg2) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable { + func factory(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1) -> (Arg2) throws -> Type where Arg1: Hashable, Arg2: Hashable { return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, $0))) } } - func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2, Arg3) throws -> Type { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box($0, $1, $2))) } - } - - func factory(of _: Type.Type = Type.self, arg arg1: Arg1) -> (Arg2, Arg3) throws -> Type { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, $0, $1))) } - } - - func factory(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3) throws -> Type { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, $0))) } - } - - func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2, Arg3) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box($0, $1, $2))) } - } - - func factory(of _: Type.Type = Type.self, arg arg1: Arg1) -> (Arg2, Arg3) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, $0, $1))) } - } - - func factory(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, $0))) } - } - - func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1, Arg2, Arg3) throws -> Type where Tag: Hashable { + func factory(of _: Type.Type = Type.self, tagged tag: String? = nil) -> (Arg1, Arg2, Arg3) throws -> Type { return { try self.resolve(request(type: Type.self, tag: tag, arg: box($0, $1, $2))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) -> (Arg2, Arg3) throws -> Type where Tag: Hashable { + func factory(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1) -> (Arg2, Arg3) throws -> Type { return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, $0, $1))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3) throws -> Type where Tag: Hashable { + func factory(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3) throws -> Type { return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, $0))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1, Arg2, Arg3) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + func factory(of _: Type.Type = Type.self, tagged tag: String? = nil) -> (Arg1, Arg2, Arg3) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { return { try self.resolve(request(type: Type.self, tag: tag, arg: box($0, $1, $2))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) -> (Arg2, Arg3) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + func factory(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1) -> (Arg2, Arg3) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, $0, $1))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + func factory(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, $0))) } } - func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2, Arg3, Arg4) throws -> Type { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box($0, $1, $2, $3))) } - } - - func factory(of _: Type.Type = Type.self, arg arg1: Arg1) -> (Arg2, Arg3, Arg4) throws -> Type { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, $0, $1, $2))) } - } - - func factory(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3, Arg4) throws -> Type { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, $0, $1))) } - } - - func factory(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> (Arg4) throws -> Type { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, arg3, $0))) } - } - - func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2, Arg3, Arg4) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box($0, $1, $2, $3))) } - } - - func factory(of _: Type.Type = Type.self, arg arg1: Arg1) -> (Arg2, Arg3, Arg4) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, $0, $1, $2))) } - } - - func factory(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3, Arg4) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, $0, $1))) } - } - - func factory(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> (Arg4) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, arg3, $0))) } - } - - func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1, Arg2, Arg3, Arg4) throws -> Type where Tag: Hashable { + func factory(of _: Type.Type = Type.self, tagged tag: String? = nil) -> (Arg1, Arg2, Arg3, Arg4) throws -> Type { return { try self.resolve(request(type: Type.self, tag: tag, arg: box($0, $1, $2, $3))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) -> (Arg2, Arg3, Arg4) throws -> Type where Tag: Hashable { + func factory(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1) -> (Arg2, Arg3, Arg4) throws -> Type { return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, $0, $1, $2))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3, Arg4) throws -> Type where Tag: Hashable { + func factory(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3, Arg4) throws -> Type { return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, $0, $1))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> (Arg4) throws -> Type where Tag: Hashable { + func factory(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> (Arg4) throws -> Type { return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, $0))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1, Arg2, Arg3, Arg4) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + func factory(of _: Type.Type = Type.self, tagged tag: String? = nil) -> (Arg1, Arg2, Arg3, Arg4) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { return { try self.resolve(request(type: Type.self, tag: tag, arg: box($0, $1, $2, $3))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) -> (Arg2, Arg3, Arg4) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + func factory(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1) -> (Arg2, Arg3, Arg4) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, $0, $1, $2))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3, Arg4) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + func factory(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3, Arg4) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, $0, $1))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> (Arg4) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + func factory(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> (Arg4) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, $0))) } } - func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box($0, $1, $2, $3, $4))) } - } - - func factory(of _: Type.Type = Type.self, arg arg1: Arg1) -> (Arg2, Arg3, Arg4, Arg5) throws -> Type { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, $0, $1, $2, $3))) } - } - - func factory(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3, Arg4, Arg5) throws -> Type { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, $0, $1, $2))) } - } - - func factory(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> (Arg4, Arg5) throws -> Type { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, arg3, $0, $1))) } - } - - func factory(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> (Arg5) throws -> Type { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, arg3, arg4, $0))) } - } - - func factory(of _: Type.Type = Type.self) -> (Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box($0, $1, $2, $3, $4))) } - } - - func factory(of _: Type.Type = Type.self, arg arg1: Arg1) -> (Arg2, Arg3, Arg4, Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, $0, $1, $2, $3))) } - } - - func factory(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3, Arg4, Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, $0, $1, $2))) } - } - - func factory(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> (Arg4, Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, arg3, $0, $1))) } - } - - func factory(of _: Type.Type = Type.self, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> (Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return { try self.resolve(request(type: Type.self, tag: NoTag(), arg: box(arg1, arg2, arg3, arg4, $0))) } - } - - func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type where Tag: Hashable { + func factory(of _: Type.Type = Type.self, tagged tag: String? = nil) -> (Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type { return { try self.resolve(request(type: Type.self, tag: tag, arg: box($0, $1, $2, $3, $4))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) -> (Arg2, Arg3, Arg4, Arg5) throws -> Type where Tag: Hashable { + func factory(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1) -> (Arg2, Arg3, Arg4, Arg5) throws -> Type { return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, $0, $1, $2, $3))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3, Arg4, Arg5) throws -> Type where Tag: Hashable { + func factory(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3, Arg4, Arg5) throws -> Type { return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, $0, $1, $2))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> (Arg4, Arg5) throws -> Type where Tag: Hashable { + func factory(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> (Arg4, Arg5) throws -> Type { return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, $0, $1))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> (Arg5) throws -> Type where Tag: Hashable { + func factory(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> (Arg5) throws -> Type { return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, arg4, $0))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag) -> (Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + func factory(of _: Type.Type = Type.self, tagged tag: String? = nil) -> (Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { return { try self.resolve(request(type: Type.self, tag: tag, arg: box($0, $1, $2, $3, $4))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1) -> (Arg2, Arg3, Arg4, Arg5) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + func factory(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1) -> (Arg2, Arg3, Arg4, Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, $0, $1, $2, $3))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3, Arg4, Arg5) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + func factory(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3, Arg4, Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, $0, $1, $2))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> (Arg4, Arg5) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + func factory(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> (Arg4, Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, $0, $1))) } } - func factory(of _: Type.Type = Type.self, tagged tag: Tag, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> (Arg5) throws -> Type where Tag: Hashable, Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + func factory(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> (Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, arg4, $0))) } } } diff --git a/Sources/3.0 API/TypeBinder.swift b/Sources/3.0 API/TypeBinder.swift index b07a07d0..81b54d43 100644 --- a/Sources/3.0 API/TypeBinder.swift +++ b/Sources/3.0 API/TypeBinder.swift @@ -11,16 +11,7 @@ public struct TypeBinder { let properties: BindingProperties } -public func bind(_: Type.Type, overrides: Bool = false) -> TypeBinder { - return TypeBinder(properties: BindingProperties( - descriptor: plain(Type.self), - overrides: overrides - )) -} - -public func bind( - _: Type.Type, tagged tag: Tag, overrides: Bool = false -) -> TypeBinder where Tag: Hashable { +public func bind(_: Type.Type, tagged tag: String? = nil, overrides: Bool = false) -> TypeBinder { return TypeBinder(properties: BindingProperties( descriptor: tagged(Type.self, with: tag), overrides: overrides diff --git a/Sources/Core/InjectionRequest.swift b/Sources/Core/InjectionRequest.swift index 2d5e11c2..7cfd904a 100644 --- a/Sources/Core/InjectionRequest.swift +++ b/Sources/Core/InjectionRequest.swift @@ -8,9 +8,9 @@ public struct InjectionRequest { let argumentType: Any.Type } -func request( +func request( type: Type.Type = Type.self, - tag: Tag, + tag: String?, arg: Argument ) -> InjectionRequest { return InjectionRequest(descriptor: tagged(type, with: tag), argument: arg, argumentType: Argument.self) diff --git a/Sources/Core/TypeDescriptor.swift b/Sources/Core/TypeDescriptor.swift index 85b5d370..4a389195 100644 --- a/Sources/Core/TypeDescriptor.swift +++ b/Sources/Core/TypeDescriptor.swift @@ -3,7 +3,7 @@ // public struct TypeDescriptor: Hashable { - let tag: Matchable + let tag: String? let type: Any.Type public func hash(into hasher: inout Hasher) { @@ -12,26 +12,12 @@ public struct TypeDescriptor: Hashable { } public static func == (lhs: TypeDescriptor, rhs: TypeDescriptor) -> Bool { - return lhs.type == rhs.type && lhs.tag.matches(rhs.tag) + return lhs.type == rhs.type && lhs.tag == rhs.tag } } -struct NoTag: Hashable {} - -func tagged(_: Type.Type, with tag: Tag) -> TypeDescriptor where Tag: Hashable { - return TypeDescriptor(tag: box(tag), type: unwrapOptionals(Type.self)) -} - -func plain(_: Type.Type) -> TypeDescriptor { - return tagged(Type.self, with: NoTag()) -} - -func named(_: Type.Type, name: String?) -> TypeDescriptor { - if let name = name { - return tagged(Type.self, with: name) - } else { - return plain(Type.self) - } +func tagged(_: Type.Type, with tag: String?) -> TypeDescriptor { + return TypeDescriptor(tag: tag, type: unwrapOptionals(Type.self)) } func unwrapOptionals(_ type: Any.Type) -> Any.Type { diff --git a/Templates/InjectionVariation.swift b/Templates/InjectionVariation.swift index 2a44bee7..cdc20622 100644 --- a/Templates/InjectionVariation.swift +++ b/Templates/InjectionVariation.swift @@ -5,7 +5,6 @@ struct InjectionVariation { let paramArgs: Int let factoryArgs: Int - let isTagged: Bool let isMatchable: Bool let isDelayed: Bool } @@ -16,7 +15,6 @@ extension InjectionVariation { var genericTypes: String { return join( "Type", - isTagged ? "Tag" : nil, args > 0 ? join((1 ... args).map { "Arg\($0)" }) : nil ) } @@ -24,7 +22,7 @@ extension InjectionVariation { var params: String { return join( "of _: Type.Type = Type.self", - isTagged ? "tagged tag: Tag" : nil, + "tagged tag: String? = nil", paramArgs >= 1 ? "arg " + join(separator: ", _ ", (1 ... paramArgs).map { "arg\($0): Arg\($0)" }) : nil ) } @@ -35,7 +33,6 @@ extension InjectionVariation { var constraints: String { return join( - isTagged ? "Tag: Hashable" : nil, isMatchable && args > 0 ? join((1 ... args).map { "Arg\($0): Hashable" }) : nil ) } @@ -49,7 +46,7 @@ extension InjectionVariation { let factoryVars = (0 ..< factoryArgs).map { "$\($0)" } return join( "type: Type.self", - isTagged ? "tag: tag" : "tag: NoTag()", + "tag: tag", args == 0 ? "arg: ()" : "arg: box(\(join(paramVars + factoryVars)))" ) } @@ -88,13 +85,11 @@ extension InjectionVariation { .flatMap { t in (t ... maxArgs).map { (t, maxArgs - $0) } } .flatMap { t in [false, true].map { (t.0, t.1, $0) } } .flatMap { t in [false, true].map { (t.0, t.1, t.2, $0) } } - .flatMap { t in [false, true].map { (t.0, t.1, t.2, t.3, $0) } } .map(InjectionVariation.init) static let sortedCases = allCases.sorted { [ $0.args < $1.args, - !$0.isTagged && $1.isTagged && $0.args == $1.args, - !$0.isMatchable && $1.isMatchable && $0.args == $1.args && $0.isTagged == $1.isTagged, + !$0.isMatchable && $1.isMatchable && $0.args == $1.args, ].contains(true) } static let publicCases = sortedCases diff --git a/Templates/Resolver+LegacyApi.swifttemplate b/Templates/Resolver+LegacyApi.swifttemplate index af711bb9..c3779ac5 100644 --- a/Templates/Resolver+LegacyApi.swifttemplate +++ b/Templates/Resolver+LegacyApi.swifttemplate @@ -9,11 +9,7 @@ public extension Resolver { /// /// - Returns: The resolved service type instance, or nil if no service with the name is found. func resolve(_ serviceType: Service.Type, name: String? = nil) -> Service? { - if let name = name { - return try? resolve(request(type: serviceType, tag: name, arg: ())) as Service - } else { - return try? resolve(request(type: serviceType, tag: NoTag(), arg: ())) as Service - } + return try? resolve(request(type: serviceType, tag: name, arg: ())) as Service } <%_ (1...arg_count).forEach { i in @@ -33,11 +29,7 @@ public extension Resolver { /// - Returns: The resolved service type instance, or nil if no registration for the service type, /// <%= arg_param_description %> and name is found. func resolve>(_ serviceType: Service.Type, name: String? = nil, <%= arg_param %>) -> Service? { - if let name = name { - return try? resolve(request(type: serviceType, tag: name, arg: ())) as Service - } else { - return try? resolve(request(type: serviceType, tag: NoTag(), arg: <%= arg_vars %>)) as Service - } + return try? resolve(request(type: serviceType, tag: name, arg: <%= arg_vars %>)) as Service }<%= i < arg_count ? "\n" : "" %> <%_ } -%> } diff --git a/Templates/SwiftCode.swifttemplate b/Templates/SwiftCode.swifttemplate index 5a34b5b3..b71bd266 100644 --- a/Templates/SwiftCode.swifttemplate +++ b/Templates/SwiftCode.swifttemplate @@ -161,7 +161,6 @@ extension BinderVariation { struct InjectionVariation { let paramArgs: Int let factoryArgs: Int - let isTagged: Bool let isMatchable: Bool let isDelayed: Bool } @@ -172,7 +171,6 @@ extension InjectionVariation { var genericTypes: String { return join( "Type", - isTagged ? "Tag" : nil, args > 0 ? join((1 ... args).map { "Arg\($0)" }) : nil ) } @@ -180,7 +178,7 @@ extension InjectionVariation { var params: String { return join( "of _: Type.Type = Type.self", - isTagged ? "tagged tag: Tag" : nil, + "tagged tag: String? = nil", paramArgs >= 1 ? "arg " + join(separator: ", _ ", (1 ... paramArgs).map { "arg\($0): Arg\($0)" }) : nil ) } @@ -191,7 +189,6 @@ extension InjectionVariation { var constraints: String { return join( - isTagged ? "Tag: Hashable" : nil, isMatchable && args > 0 ? join((1 ... args).map { "Arg\($0): Hashable" }) : nil ) } @@ -205,7 +202,7 @@ extension InjectionVariation { let factoryVars = (0 ..< factoryArgs).map { "$\($0)" } return join( "type: Type.self", - isTagged ? "tag: tag" : "tag: NoTag()", + "tag: tag", args == 0 ? "arg: ()" : "arg: box(\(join(paramVars + factoryVars)))" ) } @@ -244,13 +241,11 @@ extension InjectionVariation { .flatMap { t in (t ... maxArgs).map { (t, maxArgs - $0) } } .flatMap { t in [false, true].map { (t.0, t.1, $0) } } .flatMap { t in [false, true].map { (t.0, t.1, t.2, $0) } } - .flatMap { t in [false, true].map { (t.0, t.1, t.2, t.3, $0) } } .map(InjectionVariation.init) static let sortedCases = allCases.sorted { [ $0.args < $1.args, - !$0.isTagged && $1.isTagged && $0.args == $1.args, - !$0.isMatchable && $1.isMatchable && $0.args == $1.args && $0.isTagged == $1.isTagged, + !$0.isMatchable && $1.isMatchable && $0.args == $1.args, ].contains(true) } static let publicCases = sortedCases diff --git a/Tests/3.0 API/BindingSpec.swift b/Tests/3.0 API/BindingSpec.swift index 18c654fe..a2d2a558 100644 --- a/Tests/3.0 API/BindingSpec.swift +++ b/Tests/3.0 API/BindingSpec.swift @@ -19,11 +19,9 @@ class BindingSpec: QuickSpec { override func spec() { #if swift(>=5.1) let swinject = Swinject { bbind(String.self) & "Plain" bbind(String.self, tagged: "Tag") & "Tagged" - bbind(String.self, tagged: 42) & "42" } expect { try swinject.instance(of: String.self) } == "Plain" expect { try swinject.instance(of: String.self, tagged: "Tag") } == "Tagged" - expect { try swinject.instance(of: String.self, tagged: 42) } == "42" } it("throws if has no binding with given tag") { let swinject = Swinject { diff --git a/Tests/Support/Bridge.swift b/Tests/Support/Bridge.swift index c05aa286..8cb0be50 100644 --- a/Tests/Support/Bridge.swift +++ b/Tests/Support/Bridge.swift @@ -5,11 +5,7 @@ import func Swinject.bind import struct Swinject.TypeBinder -// Original Swinject functions conflict with QuickSpec's instance methods -func bbind(_: Type.Type, overrides: Bool = false) -> TypeBinder { - return bind(Type.self, overrides: overrides) -} - -func bbind(_: Type.Type, tagged tag: Tag, overrides: Bool = false) -> TypeBinder where Tag: Hashable { +// Original Swinject `bind` function conflicts with QuickSpec's instance methods +func bbind(_: Type.Type, tagged tag: String? = nil, overrides: Bool = false) -> TypeBinder { return bind(Type.self, tagged: tag, overrides: overrides) } diff --git a/Tests/Unit Specs/StandardScopeRegistrySpec.swift b/Tests/Unit Specs/StandardScopeRegistrySpec.swift index 57ad63f9..3bac4fdf 100644 --- a/Tests/Unit Specs/StandardScopeRegistrySpec.swift +++ b/Tests/Unit Specs/StandardScopeRegistrySpec.swift @@ -9,7 +9,7 @@ import Quick class StandardScopeRegistrySpec: QuickSpec { override func spec() { var registry: StandardScopeRegistry! - let key = (1 ... 5).map { ScopeRegistryKey(descriptor: tagged(Int.self, with: $0), argument: ()) } + let key = (1 ... 5).map { ScopeRegistryKey(descriptor: tagged(Int.self, with: "\($0)"), argument: ()) } var doors = [Door]() beforeEach { doors = (1 ... 3).map { _ in Door() } From 9e8542f6ca6cccebd0b2476600d556e8a8a59598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 4 Aug 2019 13:04:26 +0200 Subject: [PATCH 195/239] Illustrate property wrapper usage --- Tests/3.0 API/PropertyWrappersSpec.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Tests/3.0 API/PropertyWrappersSpec.swift b/Tests/3.0 API/PropertyWrappersSpec.swift index 72e07323..238f429e 100644 --- a/Tests/3.0 API/PropertyWrappersSpec.swift +++ b/Tests/3.0 API/PropertyWrappersSpec.swift @@ -59,6 +59,16 @@ class PropertyWrappersSpec: QuickSpec { override func spec() { #if swift(>=5.1) let doubleWrappedInt = try? swinject.instance() as Wrapped> expect { doubleWrappedInt?.wrappedValue.wrappedValue } == 42 } + it("can inject attributed properties") { + struct IntHolder { + @Wrapped var int: Int + } + let swinject = Swinject { + bbind(Int.self) & 42 + bbind(IntHolder.self) & provider { try IntHolder(int: $0.instance()) } + } + expect { try swinject.instance(of: IntHolder.self).int } == 42 + } } #endif } } From 86557e9a0267311f41fcffc6d9d9141de2e1a029 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 4 Aug 2019 14:32:56 +0200 Subject: [PATCH 196/239] Implement circular dependency detection --- Sources/2.0 API/Container.swift | 3 +- Sources/3.0 API/Swinject+Builder.swift | 36 +++++++++++---- Sources/Core/InjectionRequest.swift | 14 +++++- Sources/Core/ScopeRegistryKey.swift | 16 +++---- Sources/Core/Swinject.swift | 61 +++++++++++++++++++++++--- Sources/Core/SwinjectError.swift | 1 + Swinject.xcodeproj/project.pbxproj | 10 +++++ Tests/3.0 API/CIrcularitySpec.swift | 20 +++++++++ 8 files changed, 137 insertions(+), 24 deletions(-) create mode 100644 Tests/3.0 API/CIrcularitySpec.swift diff --git a/Sources/2.0 API/Container.swift b/Sources/2.0 API/Container.swift index 6e48e7c8..3fadeb56 100644 --- a/Sources/2.0 API/Container.swift +++ b/Sources/2.0 API/Container.swift @@ -150,7 +150,8 @@ extension Container: SwinjectAware { bindings: allBindings, translators: [] ), - context: Graph() + context: Graph(), + detectsCircularDependencies: false ) } } diff --git a/Sources/3.0 API/Swinject+Builder.swift b/Sources/3.0 API/Swinject+Builder.swift index 21d483da..10496e27 100644 --- a/Sources/3.0 API/Swinject+Builder.swift +++ b/Sources/3.0 API/Swinject+Builder.swift @@ -3,33 +3,53 @@ // public extension Swinject { - init(allowsSilentOverride: Bool = false, _ entries: SwinjectEntry ...) { + init( + allowsSilentOverride: Bool = false, + detectsCircularDependencies: Bool = true, + _ entries: SwinjectEntry ... + ) { self.init( tree: SwinjectTreeBuilder.buildFunction(entries), - allowsSilentOverride: allowsSilentOverride + allowsSilentOverride: allowsSilentOverride, + detectsCircularDependencies: detectsCircularDependencies ) } } public extension Swinject { #if swift(>=5.1) - init(allowsSilentOverride: Bool = false, @SwinjectTreeBuilder builder: () -> [SwinjectEntry]) { + init( + allowsSilentOverride: Bool = false, + detectsCircularDependencies: Bool = true, + @SwinjectTreeBuilder builder: () -> [SwinjectEntry] + ) { self.init( tree: SwinjectTreeBuilder.buildFunction(builder()), - allowsSilentOverride: allowsSilentOverride + allowsSilentOverride: allowsSilentOverride, + detectsCircularDependencies: detectsCircularDependencies ) } - init(allowsSilentOverride: Bool = false, @SwinjectTreeBuilder builder: () -> SwinjectEntry) { + init( + allowsSilentOverride: Bool = false, + detectsCircularDependencies: Bool = true, + @SwinjectTreeBuilder builder: () -> SwinjectEntry + ) { self.init( tree: SwinjectTreeBuilder.buildFunction([builder()]), - allowsSilentOverride: allowsSilentOverride + allowsSilentOverride: allowsSilentOverride, + detectsCircularDependencies: detectsCircularDependencies ) } - init(allowsSilentOverride: Bool = false, @SwinjectTreeBuilder _: () -> Void) { + init( + allowsSilentOverride: Bool = false, + detectsCircularDependencies: Bool = true, + @SwinjectTreeBuilder _: () -> Void + ) { self.init( tree: SwinjectTreeBuilder.buildFunction([]), - allowsSilentOverride: allowsSilentOverride + allowsSilentOverride: allowsSilentOverride, + detectsCircularDependencies: detectsCircularDependencies ) } #endif diff --git a/Sources/Core/InjectionRequest.swift b/Sources/Core/InjectionRequest.swift index 7cfd904a..915be719 100644 --- a/Sources/Core/InjectionRequest.swift +++ b/Sources/Core/InjectionRequest.swift @@ -2,10 +2,22 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -public struct InjectionRequest { +public struct InjectionRequest: Hashable { let descriptor: TypeDescriptor let argument: Any let argumentType: Any.Type + + public func hash(into hasher: inout Hasher) { + descriptor.hash(into: &hasher) + ObjectIdentifier(argumentType).hash(into: &hasher) + (argument as? Matchable)?.hash(into: &hasher) + } + + public static func == (lhs: InjectionRequest, rhs: InjectionRequest) -> Bool { + return lhs.descriptor == rhs.descriptor + && lhs.argumentType == rhs.argumentType + && areArgumentsEqual(lhs.argument, rhs.argument) + } } func request( diff --git a/Sources/Core/ScopeRegistryKey.swift b/Sources/Core/ScopeRegistryKey.swift index 6ef70cb2..0c23fc1d 100644 --- a/Sources/Core/ScopeRegistryKey.swift +++ b/Sources/Core/ScopeRegistryKey.swift @@ -12,16 +12,16 @@ extension ScopeRegistryKey: Hashable { return lhs.descriptor == rhs.descriptor && areArgumentsEqual(lhs.argument, rhs.argument) } - private static func areArgumentsEqual(_ lhs: Any, _ rhs: Any) -> Bool { - switch (lhs, rhs) { - case let (lhs as Matchable, _): return lhs.matches(rhs) - case let (_, rhs as Matchable): return rhs.matches(lhs) - default: return true - } - } - public func hash(into hasher: inout Hasher) { descriptor.hash(into: &hasher) (argument as? Matchable)?.hash(into: &hasher) } } + +func areArgumentsEqual(_ lhs: Any, _ rhs: Any) -> Bool { + switch (lhs, rhs) { + case let (lhs as Matchable, _): return lhs.matches(rhs) + case let (_, rhs as Matchable): return rhs.matches(lhs) + default: return true + } +} diff --git a/Sources/Core/Swinject.swift b/Sources/Core/Swinject.swift index fedadfd4..209a38e2 100644 --- a/Sources/Core/Swinject.swift +++ b/Sources/Core/Swinject.swift @@ -7,22 +7,51 @@ public struct Swinject { let container: SwinjectContainer let context: Any let contextType: Any.Type + let requestStack: [InjectionRequest] + let detectsCircularDependencies: Bool - init(tree: SwinjectTree, allowsSilentOverride: Bool) { + // TODO: Improve properties management / construction + init(tree: SwinjectTree, allowsSilentOverride: Bool, detectsCircularDependencies: Bool) { self.init( tree: tree, container: SwinjectContainer .Builder(tree: tree, allowsSilentOverride: allowsSilentOverride) .makeContainer(), - context: () + context: (), + detectsCircularDependencies: detectsCircularDependencies ) } - init(tree: SwinjectTree, container: SwinjectContainer, context: Context) { + init( + tree: SwinjectTree, + container: SwinjectContainer, + context: Context, + detectsCircularDependencies: Bool + ) { + self.init( + tree: tree, + container: container, + context: context, + contextType: Context.self, + requestStack: [], + detectsCircularDependencies: detectsCircularDependencies + ) + } + + private init( + tree: SwinjectTree, + container: SwinjectContainer, + context: Any, + contextType: Any.Type, + requestStack: [InjectionRequest], + detectsCircularDependencies: Bool + ) { self.tree = tree self.container = container self.context = context - contextType = Context.self + self.contextType = contextType + self.requestStack = requestStack + self.detectsCircularDependencies = detectsCircularDependencies } } @@ -35,7 +64,7 @@ extension Swinject: Resolver { if let custom = resolve(request, asCustom: Type.self) { return custom } throw error } - return try instance( + return try whileTracking(request).instance( from: binding, context: findTranslator(for: binding).translate(context), arg: request.argument @@ -43,7 +72,12 @@ extension Swinject: Resolver { } public func on(_ context: Context) -> Resolver { - return Swinject(tree: tree, container: container, context: context) + return Swinject( + tree: tree, + container: container, + context: context, + detectsCircularDependencies: detectsCircularDependencies + ) } private func resolve(_ request: InjectionRequest, asCustom _: Type.Type) -> Type? { @@ -87,3 +121,18 @@ extension Swinject: Resolver { return try binding.instance(arg: arg, context: context, resolver: self) as? Type ?? { throw SwinjectError() }() } } + +extension Swinject { + func whileTracking(_ request: InjectionRequest) throws -> Swinject { + guard detectsCircularDependencies else { return self } + guard !requestStack.contains(request) else { throw CircularDependency() } + return Swinject( + tree: tree, + container: container, + context: context, + contextType: contextType, + requestStack: requestStack + [request], + detectsCircularDependencies: detectsCircularDependencies + ) + } +} diff --git a/Sources/Core/SwinjectError.swift b/Sources/Core/SwinjectError.swift index 49c24d4c..c56de058 100644 --- a/Sources/Core/SwinjectError.swift +++ b/Sources/Core/SwinjectError.swift @@ -19,5 +19,6 @@ public class OverrideNotAllowed: SwinjectError {} public class NothingToOverride: SwinjectError {} public class SilentOverrideNotAllowed: SwinjectError {} public class NoContextTranslator: SwinjectError {} +public class CircularDependency: SwinjectError {} // TODO: Debugging error description diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index d6cd4629..f60bff93 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -287,6 +287,10 @@ CDE303DE22F6DDA900846EFA /* Resolver+FunctionCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE303DB22F6DDA900846EFA /* Resolver+FunctionCall.swift */; }; CDE303DF22F6DDA900846EFA /* Resolver+FunctionCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE303DB22F6DDA900846EFA /* Resolver+FunctionCall.swift */; }; CDE303E122F6DF7500846EFA /* Resolver+FunctionCallApi.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = CDE303E022F6DF7500846EFA /* Resolver+FunctionCallApi.swifttemplate */; }; + CDE303F622F7009B00846EFA /* CIrcularitySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE303F122F7008600846EFA /* CIrcularitySpec.swift */; }; + CDE303F722F7009B00846EFA /* CIrcularitySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE303F122F7008600846EFA /* CIrcularitySpec.swift */; }; + CDE303F822F7009C00846EFA /* CIrcularitySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE303F122F7008600846EFA /* CIrcularitySpec.swift */; }; + CDE303F922F7009C00846EFA /* CIrcularitySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE303F122F7008600846EFA /* CIrcularitySpec.swift */; }; CE5AFED22F04B96713ED76D7 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ADC44E9312C3B974AFD8F07B /* Nimble.framework */; }; CECF5BD14BCDF5248771A06A /* InjectionRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InjectionRequest.swift */; }; CEE763218A90832454A6E2DE /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */; }; @@ -545,6 +549,7 @@ CDA78290D6D60BD0B808571F /* Container+Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Logging.swift"; sourceTree = ""; }; CDE303DB22F6DDA900846EFA /* Resolver+FunctionCall.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Resolver+FunctionCall.swift"; sourceTree = ""; }; CDE303E022F6DF7500846EFA /* Resolver+FunctionCallApi.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+FunctionCallApi.swifttemplate"; sourceTree = ""; }; + CDE303F122F7008600846EFA /* CIrcularitySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CIrcularitySpec.swift; sourceTree = ""; }; CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextSpec.swift; sourceTree = ""; }; E0874A043EAEE3C7CF1EA063 /* InjectionRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InjectionRequest.swift; sourceTree = ""; }; @@ -757,6 +762,7 @@ 46F05CC591903E2B04B6D8ED /* SingletonSpec.swift */, CD03917322EF610800DE44C4 /* OverrideSpec.swift */, CD68676422F5CA5D00F7D9E3 /* PropertyWrappersSpec.swift */, + CDE303F122F7008600846EFA /* CIrcularitySpec.swift */, ); path = "3.0 API"; sourceTree = ""; @@ -1474,6 +1480,7 @@ E227D08034E08AA0909BC043 /* RetrievalSpec.swift in Sources */, CD73B9B422F239A4004BB84E /* ProviderSpec.swift in Sources */, CD73B9B522F239A4004BB84E /* SynchronizedResolverSpec.swift in Sources */, + CDE303F622F7009B00846EFA /* CIrcularitySpec.swift in Sources */, CD73B9B222F239A4004BB84E /* ContainerSpec.TypeForwarding.swift in Sources */, 33B86F2D33219879731CDDF0 /* ScopesSpec.swift in Sources */, 30D247E8083858C233B92908 /* SingletonSpec.swift in Sources */, @@ -1515,6 +1522,7 @@ 1A68A8D05D9974002BF34CF8 /* RetrievalSpec.swift in Sources */, CD73B9CA22F239A5004BB84E /* ProviderSpec.swift in Sources */, CD73B9CB22F239A5004BB84E /* SynchronizedResolverSpec.swift in Sources */, + CDE303F722F7009B00846EFA /* CIrcularitySpec.swift in Sources */, CD73B9C822F239A5004BB84E /* ContainerSpec.TypeForwarding.swift in Sources */, 0068DAA4AA322F00AF53731F /* ScopesSpec.swift in Sources */, B65DE0B0562540CC8CEC48F3 /* SingletonSpec.swift in Sources */, @@ -1556,6 +1564,7 @@ 2F664F8534CA1D92ED2F81E2 /* RetrievalSpec.swift in Sources */, CD73B9D522F239A6004BB84E /* ProviderSpec.swift in Sources */, CD73B9D622F239A6004BB84E /* SynchronizedResolverSpec.swift in Sources */, + CDE303F922F7009C00846EFA /* CIrcularitySpec.swift in Sources */, CD73B9D322F239A6004BB84E /* ContainerSpec.TypeForwarding.swift in Sources */, 31729A1E5F50EF30FDD427AD /* ScopesSpec.swift in Sources */, 0CE158916595980A7C8272D3 /* SingletonSpec.swift in Sources */, @@ -1597,6 +1606,7 @@ 06CD85528AABB15BDFBF3166 /* RetrievalSpec.swift in Sources */, CD73B9BF22F239A4004BB84E /* ProviderSpec.swift in Sources */, CD73B9C022F239A4004BB84E /* SynchronizedResolverSpec.swift in Sources */, + CDE303F822F7009C00846EFA /* CIrcularitySpec.swift in Sources */, CD73B9BD22F239A4004BB84E /* ContainerSpec.TypeForwarding.swift in Sources */, EA0D19F7DF0355C774B0F40B /* ScopesSpec.swift in Sources */, 980FED1DBC62B65597E2828B /* SingletonSpec.swift in Sources */, diff --git a/Tests/3.0 API/CIrcularitySpec.swift b/Tests/3.0 API/CIrcularitySpec.swift new file mode 100644 index 00000000..87462abf --- /dev/null +++ b/Tests/3.0 API/CIrcularitySpec.swift @@ -0,0 +1,20 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +import Nimble +import Quick +@testable import Swinject + +class CircularitySpec: QuickSpec { override func spec() { #if swift(>=5.1) + it("does not allow circular dependencies") { + class Foo { init(_: Bar) {} } + class Bar { init(_: Foo) {} } + let swinject = Swinject { + bbind(Foo.self) & provider { Foo(try $0.instance()) } + bbind(Bar.self) & provider { Bar(try $0.instance()) } + } + expect { try swinject.instance(of: Foo.self) }.to(throwError()) + } + #endif +} } From 9d005ba7b1a47a7d46046cf6835c168c189cf58e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 4 Aug 2019 16:02:00 +0200 Subject: [PATCH 197/239] Draft usage of Lazy & Weak wrappers to break circular dependencies --- Sources/3.0 API/WeakWrapper.swift | 11 +++++ Sources/Core/Swinject.swift | 13 +++++- Swinject.xcodeproj/project.pbxproj | 10 ++++ Tests/3.0 API/CIrcularitySpec.swift | 71 +++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 Sources/3.0 API/WeakWrapper.swift diff --git a/Sources/3.0 API/WeakWrapper.swift b/Sources/3.0 API/WeakWrapper.swift new file mode 100644 index 00000000..27a34d7a --- /dev/null +++ b/Sources/3.0 API/WeakWrapper.swift @@ -0,0 +1,11 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +@propertyWrapper public struct Weak: PropertyWrapper where Value: AnyObject { + public weak var wrappedValue: Value? + + public init(wrappedValue: @autoclosure @escaping () -> Value) { + self.wrappedValue = wrappedValue() + } +} diff --git a/Sources/Core/Swinject.swift b/Sources/Core/Swinject.swift index 209a38e2..9091e3ae 100644 --- a/Sources/Core/Swinject.swift +++ b/Sources/Core/Swinject.swift @@ -83,7 +83,7 @@ extension Swinject: Resolver { private func resolve(_ request: InjectionRequest, asCustom _: Type.Type) -> Type? { guard let custom = Type.self as? CustomResolvable.Type else { return nil } if let request = custom.requiredRequest(for: request), !hasBinding(for: request) { return nil } - return custom.init(resolver: self, request: request) as? Type + return custom.init(resolver: withTrackingReset(), request: request) as? Type } private func findTranslator(for binding: Binding) throws -> AnyContextTranslator { @@ -135,4 +135,15 @@ extension Swinject { detectsCircularDependencies: detectsCircularDependencies ) } + + func withTrackingReset() -> Swinject { + return Swinject( + tree: tree, + container: container, + context: context, + contextType: contextType, + requestStack: [], + detectsCircularDependencies: detectsCircularDependencies + ) + } } diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index f60bff93..fc69d79f 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -291,6 +291,10 @@ CDE303F722F7009B00846EFA /* CIrcularitySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE303F122F7008600846EFA /* CIrcularitySpec.swift */; }; CDE303F822F7009C00846EFA /* CIrcularitySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE303F122F7008600846EFA /* CIrcularitySpec.swift */; }; CDE303F922F7009C00846EFA /* CIrcularitySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE303F122F7008600846EFA /* CIrcularitySpec.swift */; }; + CDE303FB22F70A2500846EFA /* WeakWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE303FA22F70A2500846EFA /* WeakWrapper.swift */; }; + CDE303FC22F70A2500846EFA /* WeakWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE303FA22F70A2500846EFA /* WeakWrapper.swift */; }; + CDE303FD22F70A2500846EFA /* WeakWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE303FA22F70A2500846EFA /* WeakWrapper.swift */; }; + CDE303FE22F70A2500846EFA /* WeakWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE303FA22F70A2500846EFA /* WeakWrapper.swift */; }; CE5AFED22F04B96713ED76D7 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ADC44E9312C3B974AFD8F07B /* Nimble.framework */; }; CECF5BD14BCDF5248771A06A /* InjectionRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InjectionRequest.swift */; }; CEE763218A90832454A6E2DE /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */; }; @@ -550,6 +554,7 @@ CDE303DB22F6DDA900846EFA /* Resolver+FunctionCall.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Resolver+FunctionCall.swift"; sourceTree = ""; }; CDE303E022F6DF7500846EFA /* Resolver+FunctionCallApi.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+FunctionCallApi.swifttemplate"; sourceTree = ""; }; CDE303F122F7008600846EFA /* CIrcularitySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CIrcularitySpec.swift; sourceTree = ""; }; + CDE303FA22F70A2500846EFA /* WeakWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeakWrapper.swift; sourceTree = ""; }; CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextSpec.swift; sourceTree = ""; }; E0874A043EAEE3C7CF1EA063 /* InjectionRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InjectionRequest.swift; sourceTree = ""; }; @@ -664,6 +669,7 @@ CDE303DB22F6DDA900846EFA /* Resolver+FunctionCall.swift */, 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */, B92B8E618A08408404FB2A7A /* TypeBinder.swift */, + CDE303FA22F70A2500846EFA /* WeakWrapper.swift */, ); path = "3.0 API"; sourceTree = ""; @@ -1423,6 +1429,7 @@ 68C95FCB0D345CA3BA24D320 /* Scope.swift in Sources */, BB571B9A78FC53231A18E18C /* ScopeRegistry.swift in Sources */, 593B93BA2EE3FE4418A1C579 /* ScopeRegistryKey.swift in Sources */, + CDE303FC22F70A2500846EFA /* WeakWrapper.swift in Sources */, C3FDE105B08336F26CC95BAA /* ScopedBinding.swift in Sources */, AD3E7135985F1046E35C39DE /* ServiceEntry+TypeForwarding.swift in Sources */, 93BCD12CEFB88BAD49BEA431 /* ServiceEntry.swift in Sources */, @@ -1645,6 +1652,7 @@ B84167AC8C6BEB57C4D0695A /* Scope.swift in Sources */, E7D1045D25FAB592401DCAF0 /* ScopeRegistry.swift in Sources */, 4347EE17D0C0ED574C899D85 /* ScopeRegistryKey.swift in Sources */, + CDE303FD22F70A2500846EFA /* WeakWrapper.swift in Sources */, 8228FEB1DF3C41DEDCE0FB1D /* ScopedBinding.swift in Sources */, 5FCE2A2AE5DD0DBECA4A9953 /* ServiceEntry+TypeForwarding.swift in Sources */, D98BB7F59E98FC197D1C97A2 /* ServiceEntry.swift in Sources */, @@ -1689,6 +1697,7 @@ 2C352AAD1AC7D82A4A059046 /* Scope.swift in Sources */, 02556F149C9AAEF5CE353AC1 /* ScopeRegistry.swift in Sources */, 06F4CAB352B4F623FF7BD885 /* ScopeRegistryKey.swift in Sources */, + CDE303FE22F70A2500846EFA /* WeakWrapper.swift in Sources */, A193BF10196FBDE32833E292 /* ScopedBinding.swift in Sources */, A75BAA10EC6F738EBC2C5BE8 /* ServiceEntry+TypeForwarding.swift in Sources */, 59FD1167CD4A913E04D3EAFD /* ServiceEntry.swift in Sources */, @@ -1733,6 +1742,7 @@ 96EA0A5DF33F025EBE0B67D2 /* Scope.swift in Sources */, D861595482464ED95CF81922 /* ScopeRegistry.swift in Sources */, 920DE2CAB9895D10FAE48FBA /* ScopeRegistryKey.swift in Sources */, + CDE303FB22F70A2500846EFA /* WeakWrapper.swift in Sources */, E1B95D3EEA5BB989CCFFE70D /* ScopedBinding.swift in Sources */, CEE763218A90832454A6E2DE /* ServiceEntry+TypeForwarding.swift in Sources */, 36A706F87ED2E88F3390C6C2 /* ServiceEntry.swift in Sources */, diff --git a/Tests/3.0 API/CIrcularitySpec.swift b/Tests/3.0 API/CIrcularitySpec.swift index 87462abf..1b91936e 100644 --- a/Tests/3.0 API/CIrcularitySpec.swift +++ b/Tests/3.0 API/CIrcularitySpec.swift @@ -7,6 +7,9 @@ import Quick @testable import Swinject class CircularitySpec: QuickSpec { override func spec() { #if swift(>=5.1) + beforeEach { + UnboundScope.root.close() + } it("does not allow circular dependencies") { class Foo { init(_: Bar) {} } class Bar { init(_: Foo) {} } @@ -16,5 +19,73 @@ class CircularitySpec: QuickSpec { override func spec() { #if swift(>=5.1) } expect { try swinject.instance(of: Foo.self) }.to(throwError()) } + it("does not produce false circularity detections") { + let swinject = Swinject { + bbind(Int.self) & 21 + bbind(Int.self, tagged: "computed") & provider { try $0.instance() + $0.instance() } + } + expect { try swinject.instance(of: Int.self, tagged: "computed") } == 42 + } + it("can break circularity using Lazy wrapper") { + class Foo { init(_: Bar) {} } + class Bar { init(_: Lazy) {} } + let swinject = Swinject { + bbind(Foo.self) & provider { Foo(try $0.instance()) } + bbind(Bar.self) & provider { Bar(try $0.instance()) } + } + expect { try swinject.instance(of: Foo.self) }.notTo(throwError()) + } + it("correctly injects dependencies if root is weak singleton") { + class Foo { + let bar: Bar + init(_ bar: Bar) { self.bar = bar } + } + class Bar { + @Lazy var foo: Foo + init(_ foo: Lazy) { _foo = foo } + } + let swinject = Swinject { + bbind(Foo.self) & singleton(ref: weakRef) { Foo(try $0.instance()) } + bbind(Bar.self) & provider { Bar(try $0.instance()) } + } + let foo = try? swinject.instance(of: Foo.self) + expect { foo?.bar.foo } === foo + } + it("correctly injects dependencies if using Lazy Weak wrapper") { + class Foo { + let bar: Bar + init(_ bar: Bar) { self.bar = bar } + } + class Bar { + @Lazy> @Weak var foo: Foo? + init(_ foo: Lazy>) { _foo = foo } + } + let swinject = Swinject { + bbind(Foo.self) & singleton(ref: weakRef) { Foo(try $0.instance()) } + bbind(Bar.self) & provider { Bar(try $0.instance()) } + } + let foo = try? swinject.instance(of: Foo.self) + expect { foo?.bar.foo } === foo + } + it("can avoid reference cycles if using Lazy Weak wrapper and weak singleton") { + class Foo { + let bar: Bar + init(_ bar: Bar) { self.bar = bar } + } + class Bar { + @Lazy> @Weak var foo: Foo? + init(_ foo: Lazy>) { _foo = foo } + } + let swinject = Swinject { + bbind(Foo.self) & singleton(ref: weakRef) { Foo(try $0.instance()) } + bbind(Bar.self) & provider { Bar(try $0.instance()) } + } + var foo = try? swinject.instance(of: Foo.self) + let bar = foo?.bar + + foo = nil + + expect(bar?.foo).to(beNil()) + } #endif } } From 5319ee04b513e5604a1acc4c3f074556553a042f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 4 Aug 2019 17:25:05 +0200 Subject: [PATCH 198/239] Cleanup --- Sources/2.0 API/InstanceWrapper.swift | 10 +++++----- Sources/3.0 API/Weak.swift | 22 ++++++++++++++++++++++ Sources/3.0 API/WeakWrapper.swift | 11 ----------- Sources/Core/PropertyWrapper.swift | 8 ++++---- Sources/Core/Swinject.swift | 1 + Swinject.xcodeproj/project.pbxproj | 20 ++++++++++---------- Tests/3.0 API/CIrcularitySpec.swift | 4 ++-- Tests/3.0 API/PropertyWrappersSpec.swift | 4 ++-- 8 files changed, 46 insertions(+), 34 deletions(-) create mode 100644 Sources/3.0 API/Weak.swift delete mode 100644 Sources/3.0 API/WeakWrapper.swift diff --git a/Sources/2.0 API/InstanceWrapper.swift b/Sources/2.0 API/InstanceWrapper.swift index 29753019..0b674903 100644 --- a/Sources/2.0 API/InstanceWrapper.swift +++ b/Sources/2.0 API/InstanceWrapper.swift @@ -41,8 +41,8 @@ public extension Lazy { } } - init(wrappedValue: @autoclosure @escaping () -> Value) { - self = .uninitialized(wrappedValue) + init(initialValue: @autoclosure @escaping () -> Value) { + self = .uninitialized(initialValue) } } @@ -71,12 +71,12 @@ public extension Provider { return provider() } - init(wrappedValue: @autoclosure @escaping () -> Type) { - provider = wrappedValue + init(initialValue: @autoclosure @escaping () -> Type) { + provider = initialValue } init(resolver: Resolver, request: InjectionRequest) { // swiftlint:disable:next force_try - self.init(wrappedValue: try! resolver.on(Graph()).resolve(request.replacingType(with: Value.self))) + self.init(initialValue: try! resolver.on(Graph()).resolve(request.replacingType(with: Value.self))) } } diff --git a/Sources/3.0 API/Weak.swift b/Sources/3.0 API/Weak.swift new file mode 100644 index 00000000..9e121d61 --- /dev/null +++ b/Sources/3.0 API/Weak.swift @@ -0,0 +1,22 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +#if swift(>=5.1) + @propertyWrapper public struct Weak: PropertyWrapper where Value: AnyObject { + public weak var wrappedValue: Value? + + public init(initialValue: @autoclosure () -> Value?) { + wrappedValue = initialValue() + } + } + +#else + public struct Weak: PropertyWrapper where Value: AnyObject { + public weak var wrappedValue: Value? + + public init(initialValue: @autoclosure () -> Value?) { + wrappedValue = initialValue() + } + } +#endif diff --git a/Sources/3.0 API/WeakWrapper.swift b/Sources/3.0 API/WeakWrapper.swift deleted file mode 100644 index 27a34d7a..00000000 --- a/Sources/3.0 API/WeakWrapper.swift +++ /dev/null @@ -1,11 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -@propertyWrapper public struct Weak: PropertyWrapper where Value: AnyObject { - public weak var wrappedValue: Value? - - public init(wrappedValue: @autoclosure @escaping () -> Value) { - self.wrappedValue = wrappedValue() - } -} diff --git a/Sources/Core/PropertyWrapper.swift b/Sources/Core/PropertyWrapper.swift index 8a9700ba..4984f248 100644 --- a/Sources/Core/PropertyWrapper.swift +++ b/Sources/Core/PropertyWrapper.swift @@ -9,13 +9,13 @@ protocol CustomResolvable { protocol PropertyWrapper: CustomResolvable { associatedtype Value - init(wrappedValue: @autoclosure @escaping () -> Value) + init(initialValue: @autoclosure @escaping () -> Value) } extension PropertyWrapper { init(resolver: Resolver, request: InjectionRequest) { // swiftlint:disable:next force_try - self.init(wrappedValue: try! resolver.resolve(request.replacingType(with: Value.self))) + self.init(initialValue: try! resolver.resolve(request.replacingType(with: Value.self))) } static func requiredRequest(for request: InjectionRequest) -> InjectionRequest? { @@ -41,8 +41,8 @@ extension InjectionRequest { } extension Optional: CustomResolvable { - init(resolver _: Resolver, request _: InjectionRequest) { - self = nil + init(resolver: Resolver, request: InjectionRequest) { + self = try? resolver.resolve(request.replacingType(with: Wrapped.self)) as Wrapped } static func requiredRequest(for _: InjectionRequest) -> InjectionRequest? { diff --git a/Sources/Core/Swinject.swift b/Sources/Core/Swinject.swift index 9091e3ae..f78221a9 100644 --- a/Sources/Core/Swinject.swift +++ b/Sources/Core/Swinject.swift @@ -83,6 +83,7 @@ extension Swinject: Resolver { private func resolve(_ request: InjectionRequest, asCustom _: Type.Type) -> Type? { guard let custom = Type.self as? CustomResolvable.Type else { return nil } if let request = custom.requiredRequest(for: request), !hasBinding(for: request) { return nil } + // TODO: We should reset tracking only for "delayed" custom resolutions return custom.init(resolver: withTrackingReset(), request: request) as? Type } diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index fc69d79f..179a40bf 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -291,10 +291,10 @@ CDE303F722F7009B00846EFA /* CIrcularitySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE303F122F7008600846EFA /* CIrcularitySpec.swift */; }; CDE303F822F7009C00846EFA /* CIrcularitySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE303F122F7008600846EFA /* CIrcularitySpec.swift */; }; CDE303F922F7009C00846EFA /* CIrcularitySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE303F122F7008600846EFA /* CIrcularitySpec.swift */; }; - CDE303FB22F70A2500846EFA /* WeakWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE303FA22F70A2500846EFA /* WeakWrapper.swift */; }; - CDE303FC22F70A2500846EFA /* WeakWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE303FA22F70A2500846EFA /* WeakWrapper.swift */; }; - CDE303FD22F70A2500846EFA /* WeakWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE303FA22F70A2500846EFA /* WeakWrapper.swift */; }; - CDE303FE22F70A2500846EFA /* WeakWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE303FA22F70A2500846EFA /* WeakWrapper.swift */; }; + CDE303FB22F70A2500846EFA /* Weak.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE303FA22F70A2500846EFA /* Weak.swift */; }; + CDE303FC22F70A2500846EFA /* Weak.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE303FA22F70A2500846EFA /* Weak.swift */; }; + CDE303FD22F70A2500846EFA /* Weak.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE303FA22F70A2500846EFA /* Weak.swift */; }; + CDE303FE22F70A2500846EFA /* Weak.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE303FA22F70A2500846EFA /* Weak.swift */; }; CE5AFED22F04B96713ED76D7 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ADC44E9312C3B974AFD8F07B /* Nimble.framework */; }; CECF5BD14BCDF5248771A06A /* InjectionRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InjectionRequest.swift */; }; CEE763218A90832454A6E2DE /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */; }; @@ -554,7 +554,7 @@ CDE303DB22F6DDA900846EFA /* Resolver+FunctionCall.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Resolver+FunctionCall.swift"; sourceTree = ""; }; CDE303E022F6DF7500846EFA /* Resolver+FunctionCallApi.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+FunctionCallApi.swifttemplate"; sourceTree = ""; }; CDE303F122F7008600846EFA /* CIrcularitySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CIrcularitySpec.swift; sourceTree = ""; }; - CDE303FA22F70A2500846EFA /* WeakWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeakWrapper.swift; sourceTree = ""; }; + CDE303FA22F70A2500846EFA /* Weak.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Weak.swift; sourceTree = ""; }; CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextSpec.swift; sourceTree = ""; }; E0874A043EAEE3C7CF1EA063 /* InjectionRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InjectionRequest.swift; sourceTree = ""; }; @@ -669,7 +669,7 @@ CDE303DB22F6DDA900846EFA /* Resolver+FunctionCall.swift */, 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */, B92B8E618A08408404FB2A7A /* TypeBinder.swift */, - CDE303FA22F70A2500846EFA /* WeakWrapper.swift */, + CDE303FA22F70A2500846EFA /* Weak.swift */, ); path = "3.0 API"; sourceTree = ""; @@ -1429,7 +1429,7 @@ 68C95FCB0D345CA3BA24D320 /* Scope.swift in Sources */, BB571B9A78FC53231A18E18C /* ScopeRegistry.swift in Sources */, 593B93BA2EE3FE4418A1C579 /* ScopeRegistryKey.swift in Sources */, - CDE303FC22F70A2500846EFA /* WeakWrapper.swift in Sources */, + CDE303FC22F70A2500846EFA /* Weak.swift in Sources */, C3FDE105B08336F26CC95BAA /* ScopedBinding.swift in Sources */, AD3E7135985F1046E35C39DE /* ServiceEntry+TypeForwarding.swift in Sources */, 93BCD12CEFB88BAD49BEA431 /* ServiceEntry.swift in Sources */, @@ -1652,7 +1652,7 @@ B84167AC8C6BEB57C4D0695A /* Scope.swift in Sources */, E7D1045D25FAB592401DCAF0 /* ScopeRegistry.swift in Sources */, 4347EE17D0C0ED574C899D85 /* ScopeRegistryKey.swift in Sources */, - CDE303FD22F70A2500846EFA /* WeakWrapper.swift in Sources */, + CDE303FD22F70A2500846EFA /* Weak.swift in Sources */, 8228FEB1DF3C41DEDCE0FB1D /* ScopedBinding.swift in Sources */, 5FCE2A2AE5DD0DBECA4A9953 /* ServiceEntry+TypeForwarding.swift in Sources */, D98BB7F59E98FC197D1C97A2 /* ServiceEntry.swift in Sources */, @@ -1697,7 +1697,7 @@ 2C352AAD1AC7D82A4A059046 /* Scope.swift in Sources */, 02556F149C9AAEF5CE353AC1 /* ScopeRegistry.swift in Sources */, 06F4CAB352B4F623FF7BD885 /* ScopeRegistryKey.swift in Sources */, - CDE303FE22F70A2500846EFA /* WeakWrapper.swift in Sources */, + CDE303FE22F70A2500846EFA /* Weak.swift in Sources */, A193BF10196FBDE32833E292 /* ScopedBinding.swift in Sources */, A75BAA10EC6F738EBC2C5BE8 /* ServiceEntry+TypeForwarding.swift in Sources */, 59FD1167CD4A913E04D3EAFD /* ServiceEntry.swift in Sources */, @@ -1742,7 +1742,7 @@ 96EA0A5DF33F025EBE0B67D2 /* Scope.swift in Sources */, D861595482464ED95CF81922 /* ScopeRegistry.swift in Sources */, 920DE2CAB9895D10FAE48FBA /* ScopeRegistryKey.swift in Sources */, - CDE303FB22F70A2500846EFA /* WeakWrapper.swift in Sources */, + CDE303FB22F70A2500846EFA /* Weak.swift in Sources */, E1B95D3EEA5BB989CCFFE70D /* ScopedBinding.swift in Sources */, CEE763218A90832454A6E2DE /* ServiceEntry+TypeForwarding.swift in Sources */, 36A706F87ED2E88F3390C6C2 /* ServiceEntry.swift in Sources */, diff --git a/Tests/3.0 API/CIrcularitySpec.swift b/Tests/3.0 API/CIrcularitySpec.swift index 1b91936e..e8928e12 100644 --- a/Tests/3.0 API/CIrcularitySpec.swift +++ b/Tests/3.0 API/CIrcularitySpec.swift @@ -57,7 +57,7 @@ class CircularitySpec: QuickSpec { override func spec() { #if swift(>=5.1) init(_ bar: Bar) { self.bar = bar } } class Bar { - @Lazy> @Weak var foo: Foo? + @Lazy @Weak var foo = nil as Foo? init(_ foo: Lazy>) { _foo = foo } } let swinject = Swinject { @@ -73,7 +73,7 @@ class CircularitySpec: QuickSpec { override func spec() { #if swift(>=5.1) init(_ bar: Bar) { self.bar = bar } } class Bar { - @Lazy> @Weak var foo: Foo? + @Lazy @Weak var foo = nil as Foo? init(_ foo: Lazy>) { _foo = foo } } let swinject = Swinject { diff --git a/Tests/3.0 API/PropertyWrappersSpec.swift b/Tests/3.0 API/PropertyWrappersSpec.swift index 238f429e..3beb186f 100644 --- a/Tests/3.0 API/PropertyWrappersSpec.swift +++ b/Tests/3.0 API/PropertyWrappersSpec.swift @@ -11,8 +11,8 @@ class PropertyWrappersSpec: QuickSpec { override func spec() { #if swift(>=5.1) @propertyWrapper struct Wrapped: PropertyWrapper { var wrappedValue: Value - public init(wrappedValue: @autoclosure @escaping () -> Value) { - self.wrappedValue = wrappedValue() + public init(initialValue: @autoclosure () -> Value) { + self.wrappedValue = initialValue() } } it("can inject wrapped provider of a bound type") { From 41e36d6adba0cf2cde6467fc9c3fe35cf17ac83e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 4 Aug 2019 18:22:37 +0200 Subject: [PATCH 199/239] Cleanup context spec --- Tests/3.0 API/ContextSpec.swift | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Tests/3.0 API/ContextSpec.swift b/Tests/3.0 API/ContextSpec.swift index cd3e7c40..bcef88d0 100644 --- a/Tests/3.0 API/ContextSpec.swift +++ b/Tests/3.0 API/ContextSpec.swift @@ -55,10 +55,8 @@ class ContextSpec: QuickSpec { override func spec() { #if swift(>=5.1) describe("translators") { it("can translate contexts") { let john = Human() - // FIXME: compiler segfaults if declaring this provider in functionBuilder - let petProvider = contexted(Human.self).provider { Pet(owner: $1) } let swinject = Swinject { - bbind(Pet.self) & petProvider + bbind(Pet.self) & contexted(Human.self).provider { Pet(owner: $1) } registerContextTranslator(from: String.self) { $0 == "john" ? john : Human() } } let pet = try? swinject.on("john").instance(of: Pet.self) From 67fd9f3da07ef3329670ab8e1ec1d994c5283d39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 4 Aug 2019 20:38:44 +0200 Subject: [PATCH 200/239] Refactor swinject construction --- Sources/2.0 API/Container.swift | 12 +-- Sources/3.0 API/Swinject+Builder.swift | 20 ++--- Sources/Core/Swinject.swift | 104 +++++++++---------------- Sources/Core/SwinjectContainer.swift | 4 +- 4 files changed, 52 insertions(+), 88 deletions(-) diff --git a/Sources/2.0 API/Container.swift b/Sources/2.0 API/Container.swift index 3fadeb56..54bdee9d 100644 --- a/Sources/2.0 API/Container.swift +++ b/Sources/2.0 API/Container.swift @@ -146,12 +146,14 @@ extension Container: SwinjectAware { public var swinject: Resolver { return Swinject( tree: SwinjectTree(bindings: [], modules: [], translators: []), - container: SwinjectContainer( - bindings: allBindings, - translators: [] - ), + container: SwinjectContainer(bindings: allBindings, translators: []), context: Graph(), - detectsCircularDependencies: false + contextType: Graph.self, + stack: [], + properties: Swinject.Properties( + allowsSilentOverride: true, + detectsCircularDependencies: false + ) ) } } diff --git a/Sources/3.0 API/Swinject+Builder.swift b/Sources/3.0 API/Swinject+Builder.swift index 10496e27..4ba738f1 100644 --- a/Sources/3.0 API/Swinject+Builder.swift +++ b/Sources/3.0 API/Swinject+Builder.swift @@ -8,11 +8,10 @@ public extension Swinject { detectsCircularDependencies: Bool = true, _ entries: SwinjectEntry ... ) { - self.init( - tree: SwinjectTreeBuilder.buildFunction(entries), + self.init(tree: SwinjectTreeBuilder.buildFunction(entries), properties: Properties( allowsSilentOverride: allowsSilentOverride, detectsCircularDependencies: detectsCircularDependencies - ) + )) } } @@ -22,11 +21,10 @@ public extension Swinject { #if swift(>=5.1) detectsCircularDependencies: Bool = true, @SwinjectTreeBuilder builder: () -> [SwinjectEntry] ) { - self.init( - tree: SwinjectTreeBuilder.buildFunction(builder()), + self.init(tree: SwinjectTreeBuilder.buildFunction(builder()), properties: Properties( allowsSilentOverride: allowsSilentOverride, detectsCircularDependencies: detectsCircularDependencies - ) + )) } init( @@ -34,11 +32,10 @@ public extension Swinject { #if swift(>=5.1) detectsCircularDependencies: Bool = true, @SwinjectTreeBuilder builder: () -> SwinjectEntry ) { - self.init( - tree: SwinjectTreeBuilder.buildFunction([builder()]), + self.init(tree: SwinjectTreeBuilder.buildFunction([builder()]), properties: Properties( allowsSilentOverride: allowsSilentOverride, detectsCircularDependencies: detectsCircularDependencies - ) + )) } init( @@ -46,11 +43,10 @@ public extension Swinject { #if swift(>=5.1) detectsCircularDependencies: Bool = true, @SwinjectTreeBuilder _: () -> Void ) { - self.init( - tree: SwinjectTreeBuilder.buildFunction([]), + self.init(tree: SwinjectTreeBuilder.buildFunction([]), properties: Properties( allowsSilentOverride: allowsSilentOverride, detectsCircularDependencies: detectsCircularDependencies - ) + )) } #endif } diff --git a/Sources/Core/Swinject.swift b/Sources/Core/Swinject.swift index f78221a9..cb428e05 100644 --- a/Sources/Core/Swinject.swift +++ b/Sources/Core/Swinject.swift @@ -3,56 +3,17 @@ // public struct Swinject { + struct Properties { + let allowsSilentOverride: Bool + let detectsCircularDependencies: Bool + } + let tree: SwinjectTree let container: SwinjectContainer let context: Any let contextType: Any.Type - let requestStack: [InjectionRequest] - let detectsCircularDependencies: Bool - - // TODO: Improve properties management / construction - init(tree: SwinjectTree, allowsSilentOverride: Bool, detectsCircularDependencies: Bool) { - self.init( - tree: tree, - container: SwinjectContainer - .Builder(tree: tree, allowsSilentOverride: allowsSilentOverride) - .makeContainer(), - context: (), - detectsCircularDependencies: detectsCircularDependencies - ) - } - - init( - tree: SwinjectTree, - container: SwinjectContainer, - context: Context, - detectsCircularDependencies: Bool - ) { - self.init( - tree: tree, - container: container, - context: context, - contextType: Context.self, - requestStack: [], - detectsCircularDependencies: detectsCircularDependencies - ) - } - - private init( - tree: SwinjectTree, - container: SwinjectContainer, - context: Any, - contextType: Any.Type, - requestStack: [InjectionRequest], - detectsCircularDependencies: Bool - ) { - self.tree = tree - self.container = container - self.context = context - self.contextType = contextType - self.requestStack = requestStack - self.detectsCircularDependencies = detectsCircularDependencies - } + let stack: [InjectionRequest] + let properties: Properties } extension Swinject: Resolver { @@ -64,7 +25,7 @@ extension Swinject: Resolver { if let custom = resolve(request, asCustom: Type.self) { return custom } throw error } - return try whileTracking(request).instance( + return try tracking(request).makeInstance( from: binding, context: findTranslator(for: binding).translate(context), arg: request.argument @@ -72,19 +33,16 @@ extension Swinject: Resolver { } public func on(_ context: Context) -> Resolver { - return Swinject( - tree: tree, - container: container, - context: context, - detectsCircularDependencies: detectsCircularDependencies - ) + return with(context: context, contextType: Context.self) } +} +extension Swinject { private func resolve(_ request: InjectionRequest, asCustom _: Type.Type) -> Type? { guard let custom = Type.self as? CustomResolvable.Type else { return nil } if let request = custom.requiredRequest(for: request), !hasBinding(for: request) { return nil } // TODO: We should reset tracking only for "delayed" custom resolutions - return custom.init(resolver: withTrackingReset(), request: request) as? Type + return custom.init(resolver: with(stack: []), request: request) as? Type } private func findTranslator(for binding: Binding) throws -> AnyContextTranslator { @@ -93,6 +51,12 @@ extension Swinject: Resolver { .first ?? { throw NoContextTranslator() }() } + private func tracking(_ request: InjectionRequest) throws -> Swinject { + guard properties.detectsCircularDependencies else { return self } + guard !stack.contains(request) else { throw CircularDependency() } + return with(stack: stack + [request]) + } + private func translatableKeys(for request: InjectionRequest) -> [BindingKey] { return allTranslators.map { request.key(forContextType: $0.targetType) } } @@ -116,7 +80,7 @@ extension Swinject: Resolver { return bindings[0] } - private func instance( + private func makeInstance( from binding: Binding, context: Context, arg: Argument ) throws -> Type { return try binding.instance(arg: arg, context: context, resolver: self) as? Type ?? { throw SwinjectError() }() @@ -124,27 +88,29 @@ extension Swinject: Resolver { } extension Swinject { - func whileTracking(_ request: InjectionRequest) throws -> Swinject { - guard detectsCircularDependencies else { return self } - guard !requestStack.contains(request) else { throw CircularDependency() } - return Swinject( + init(tree: SwinjectTree, properties: Properties) { + self.init( tree: tree, - container: container, - context: context, - contextType: contextType, - requestStack: requestStack + [request], - detectsCircularDependencies: detectsCircularDependencies + container: SwinjectContainer.Builder(tree: tree, properties: properties).makeContainer(), + context: (), + contextType: Void.self, + stack: [], + properties: properties ) } - func withTrackingReset() -> Swinject { + func with( + context: Any? = nil, + contextType: Any.Type? = nil, + stack: [InjectionRequest]? = nil + ) -> Swinject { return Swinject( tree: tree, container: container, - context: context, - contextType: contextType, - requestStack: [], - detectsCircularDependencies: detectsCircularDependencies + context: context ?? self.context, + contextType: contextType ?? self.contextType, + stack: stack ?? self.stack, + properties: properties ) } } diff --git a/Sources/Core/SwinjectContainer.swift b/Sources/Core/SwinjectContainer.swift index 6c5c5230..190214ec 100644 --- a/Sources/Core/SwinjectContainer.swift +++ b/Sources/Core/SwinjectContainer.swift @@ -8,7 +8,7 @@ struct SwinjectContainer { struct Builder { let tree: SwinjectTree - let allowsSilentOverride: Bool + let properties: Swinject.Properties } } @@ -47,7 +47,7 @@ extension SwinjectContainer.Builder { } private func collectBindings() throws -> [BindingKey: Binding] { - return try collectBindingEntries(from: tree, canOverrideSilently: allowsSilentOverride) + return try collectBindingEntries(from: tree, canOverrideSilently: properties.allowsSilentOverride) .reduce(into: [BindingKey: Binding]()) { dict, entry in try checkOverrideRules(for: entry, beingAddedTo: dict) dict[entry.key] = entry.binding From 559629523bf04fa839d32023ec9b75a3979cefb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Sun, 4 Aug 2019 13:15:07 +0200 Subject: [PATCH 201/239] Update API / core separation --- Sources/3.0 API/BindingBuilder.swift | 23 + .../{Core => 3.0 API}/InstanceBuilder.swift | 0 Sources/{Core => 3.0 API}/Opaque.swift | 0 Sources/{Core => 3.0 API}/ScopedBinding.swift | 0 Sources/{Core => 3.0 API}/SimpleBinding.swift | 0 Sources/3.0 API/UnboundScope.swift | 25 + Sources/Core/Binding.swift | 20 - Sources/Core/Scope.swift | 22 - Swinject.xcodeproj/project.pbxproj | 552 ++++++++---------- 9 files changed, 306 insertions(+), 336 deletions(-) create mode 100644 Sources/3.0 API/BindingBuilder.swift rename Sources/{Core => 3.0 API}/InstanceBuilder.swift (100%) rename Sources/{Core => 3.0 API}/Opaque.swift (100%) rename Sources/{Core => 3.0 API}/ScopedBinding.swift (100%) rename Sources/{Core => 3.0 API}/SimpleBinding.swift (100%) create mode 100644 Sources/3.0 API/UnboundScope.swift diff --git a/Sources/3.0 API/BindingBuilder.swift b/Sources/3.0 API/BindingBuilder.swift new file mode 100644 index 00000000..84936852 --- /dev/null +++ b/Sources/3.0 API/BindingBuilder.swift @@ -0,0 +1,23 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +public protocol BindingBuilder { + associatedtype BoundType + func makeBinding(with properties: BindingProperties) -> Binding +} + +public struct SomeBindingBuilder: BindingBuilder, AnyOpaque { + let anyActual: Any + fileprivate let _makeBinding: (BindingProperties) -> Binding + + public func makeBinding(with properties: BindingProperties) -> Binding { + return _makeBinding(properties) + } +} + +public extension BindingBuilder { + var opaque: SomeBindingBuilder { + return SomeBindingBuilder(anyActual: self) { self.makeBinding(with: $0) } + } +} diff --git a/Sources/Core/InstanceBuilder.swift b/Sources/3.0 API/InstanceBuilder.swift similarity index 100% rename from Sources/Core/InstanceBuilder.swift rename to Sources/3.0 API/InstanceBuilder.swift diff --git a/Sources/Core/Opaque.swift b/Sources/3.0 API/Opaque.swift similarity index 100% rename from Sources/Core/Opaque.swift rename to Sources/3.0 API/Opaque.swift diff --git a/Sources/Core/ScopedBinding.swift b/Sources/3.0 API/ScopedBinding.swift similarity index 100% rename from Sources/Core/ScopedBinding.swift rename to Sources/3.0 API/ScopedBinding.swift diff --git a/Sources/Core/SimpleBinding.swift b/Sources/3.0 API/SimpleBinding.swift similarity index 100% rename from Sources/Core/SimpleBinding.swift rename to Sources/3.0 API/SimpleBinding.swift diff --git a/Sources/3.0 API/UnboundScope.swift b/Sources/3.0 API/UnboundScope.swift new file mode 100644 index 00000000..01e03bda --- /dev/null +++ b/Sources/3.0 API/UnboundScope.swift @@ -0,0 +1,25 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +public class UnboundScope: Scope, Closable { + public typealias Context = Any + + private let _registry: ScopeRegistry + + public init(registry: ScopeRegistry = StandardScopeRegistry()) { + _registry = registry + } + + public func registry(for _: Any) -> ScopeRegistry { + return _registry + } + + public func close() { + _registry.clear() + } +} + +extension UnboundScope { + static let root = UnboundScope() +} diff --git a/Sources/Core/Binding.swift b/Sources/Core/Binding.swift index 80fc671d..d070bc4a 100644 --- a/Sources/Core/Binding.swift +++ b/Sources/Core/Binding.swift @@ -37,23 +37,3 @@ public protocol Binding: SwinjectEntry { var properties: BindingProperties { get } func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any } - -public protocol BindingBuilder { - associatedtype BoundType - func makeBinding(with properties: BindingProperties) -> Binding -} - -public struct SomeBindingBuilder: BindingBuilder, AnyOpaque { - let anyActual: Any - fileprivate let _makeBinding: (BindingProperties) -> Binding - - public func makeBinding(with properties: BindingProperties) -> Binding { - return _makeBinding(properties) - } -} - -public extension BindingBuilder { - var opaque: SomeBindingBuilder { - return SomeBindingBuilder(anyActual: self) { self.makeBinding(with: $0) } - } -} diff --git a/Sources/Core/Scope.swift b/Sources/Core/Scope.swift index eb236e56..8d71f469 100644 --- a/Sources/Core/Scope.swift +++ b/Sources/Core/Scope.swift @@ -23,25 +23,3 @@ public extension Scope { public protocol Closable { func close() } - -public class UnboundScope: Scope, Closable { - public typealias Context = Any - - private let _registry: ScopeRegistry - - public init(registry: ScopeRegistry = StandardScopeRegistry()) { - _registry = registry - } - - public func registry(for _: Any) -> ScopeRegistry { - return _registry - } - - public func close() { - _registry.clear() - } -} - -extension UnboundScope { - static let root = UnboundScope() -} diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 179a40bf..6c464a3f 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -11,7 +11,9 @@ 0068DAA4AA322F00AF53731F /* ScopesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D3C59E84B5FD0C13F487838 /* ScopesSpec.swift */; }; 0207493E1CEE8456E91E3DAE /* BindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E59A67F3548663368788B17 /* BindingSpec.swift */; }; 020DA1718FCC68D889FB5A5F /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3586A4987B7C7C8122D674E /* SwinjectError.swift */; }; + 02410BD4FB357F4C6B521608 /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; 02556F149C9AAEF5CE353AC1 /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; + 027015812E961322FE3D942B /* InjectionRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57F4D977AC4289A6145383C9 /* InjectionRequest.swift */; }; 03122D1B2EA65C89ADC78EC7 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62682D6ED38742996624B041 /* BasicAssembly.swift */; }; 0509EE8D41BF354EB91ACC80 /* Reference.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73B4B777290FF5D38A8914CC /* Reference.swift */; }; 0622539110A7430776A307C7 /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42490D1D0C395951243F5CFF /* Container.swift */; }; @@ -21,20 +23,28 @@ 0720BEA814AD514378380ACB /* StandardScopeRegistrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */; }; 0781579818FC4A2CA1CD3CAE /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */; }; 0B61DC733616A8ED4ED77FA7 /* StandardScopeRegistrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */; }; + 0CD787EACEBFD1051D358E7D /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; 0CE1126436F680F9684837E4 /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; 0CE158916595980A7C8272D3 /* SingletonSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46F05CC591903E2B04B6D8ED /* SingletonSpec.swift */; }; 0D5C4A278A16AB3A163148AF /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; - 128913D570B4A8BBF40866BE /* InjectionRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InjectionRequest.swift */; }; 13CDEC7A6C8E43B58D5CBE3D /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; + 14C8DA4FCCDFA87885038D38 /* PropertyWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 424C647FF08FCB7C2A54E085 /* PropertyWrapper.swift */; }; + 157A967F9BAD0B8DAFAC2A36 /* InstanceBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 419FB96A1F4B72278B9A6665 /* InstanceBuilder.swift */; }; + 16393BD60FDDD38B5A977C55 /* InstanceBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 419FB96A1F4B72278B9A6665 /* InstanceBuilder.swift */; }; 180DB4397B4C05E26F819C85 /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADA1541ABC1365DFD7E3377F /* Food.swift */; }; + 18AAA07DCD6FAB4A7D7E8B76 /* OverrideSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86C18DDD83715886DF7F1818 /* OverrideSpec.swift */; }; 19416C867F15E88394A0ABD1 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */; }; + 196338EA802A39E205C33B43 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; + 19E02C4326FB05E0630B56E3 /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7D394F381E60F6E6E92E7DB /* SimpleBinding.swift */; }; 19EBB651BD06BD0C03C1ACB5 /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59111BE319C59E4CD6CF68CD /* Assembler.swift */; }; + 19F21849D1E173F5AC724281 /* UnboundScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 667B13B528642272FC0794B6 /* UnboundScope.swift */; }; 1A40A26942A65246D7DD268E /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = ADC44E9312C3B974AFD8F07B /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 1A68A8D05D9974002BF34CF8 /* RetrievalSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D8B3342E2AC3236F12072F5 /* RetrievalSpec.swift */; }; + 1AC00BCB4DB26B078203DAD8 /* Resolver+FunctionCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F626B9D3E547621787E4D7 /* Resolver+FunctionCall.swift */; }; 1C62135FAE3D64DC7BFBF861 /* ContextSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */; }; 1C82BFD00FCC384DB3AE6A89 /* MatchableBoxes.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 808C1063CA90CC593C7E0E9C /* MatchableBoxes.swifttemplate */; }; 1CA5DF3F93203B226A6FA059 /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EA566CD336DB8343ADFAF9B /* BehaviorFakes.swift */; }; - 1E1CAA4156D94E3A73AEA9F6 /* Opaque.swift in Sources */ = {isa = PBXBuildFile; fileRef = C68B98C653ABDED9C3D17DB3 /* Opaque.swift */; }; + 1D17DBC27F25717BF7A87AF3 /* InjectionRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57F4D977AC4289A6145383C9 /* InjectionRequest.swift */; }; 1ED6BD68D92F4FE60978EF22 /* Container+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDA78290D6D60BD0B808571F /* Container+Logging.swift */; }; 21285CED416F1317E993397A /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59A3946B59EB4D787CCE9F2 /* Container+Registration.swift */; }; 233F3E25FF0B51A3E6611F58 /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; @@ -43,6 +53,9 @@ 283C77045DA55C2134EC9C48 /* Container+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F446D6BD4C44E16A1D608BFB /* Container+TypeForwarding.swift */; }; 290C9E9420A1EE30456476CB /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59111BE319C59E4CD6CF68CD /* Assembler.swift */; }; 293985649250DF270DC89135 /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; + 2A6D2874ADB24B08DAE1EC04 /* BindingBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = A367B4D6F7E5331620430ECF /* BindingBuilder.swift */; }; + 2AA60B7E6EBA9EC6BE92D7CB /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; + 2B506344F37CE5F5C5C02C05 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; 2C352AAD1AC7D82A4A059046 /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; 2C3EB507FFA03D18B2909405 /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8B9785AAE94A5447FA307242 /* Swinject.framework */; }; 2CB057F2A16DA462E0517AAB /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; @@ -52,20 +65,25 @@ 3099172980F9E9143C0A1C20 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; 30D247E8083858C233B92908 /* SingletonSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46F05CC591903E2B04B6D8ED /* SingletonSpec.swift */; }; 3129A37CDC1653C11800E24A /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EA566CD336DB8343ADFAF9B /* BehaviorFakes.swift */; }; - 31392A9EF619329716144F95 /* Opaque.swift in Sources */ = {isa = PBXBuildFile; fileRef = C68B98C653ABDED9C3D17DB3 /* Opaque.swift */; }; 31729A1E5F50EF30FDD427AD /* ScopesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D3C59E84B5FD0C13F487838 /* ScopesSpec.swift */; }; 328DED07602120E3EE252D57 /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 823617F3B8A9192F56B13331 /* Quick.framework */; }; + 3328937B7BBFA77FA3CD303E /* SwinjectContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8C4916168E81D76536892122 /* SwinjectContainer.swift */; }; 33391EBA040E82DFB0A37015 /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; 335CE53CEC2360DC86D58F07 /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61EE5DDBE705B47AFC9A6986 /* LoadAwareAssembly.swift */; }; 33B86F2D33219879731CDDF0 /* ScopesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D3C59E84B5FD0C13F487838 /* ScopesSpec.swift */; }; 36A706F87ED2E88F3390C6C2 /* ServiceEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38615FC8EEB466C5C1EAD21C /* ServiceEntry.swift */; }; + 36D0B5EFA3B4AB4D464C9260 /* InstanceBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 419FB96A1F4B72278B9A6665 /* InstanceBuilder.swift */; }; 372F0061E762BF8FFF05457F /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; 3753FB83A1FB4B83891AA5C8 /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BFF4BA99493C54260878C4 /* ObjectScope.swift */; }; 389C54E04DD794DA4F648571 /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */; }; + 39AE6864444BC1CE491142E5 /* CIrcularitySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 118ABC654C4144496848AD74 /* CIrcularitySpec.swift */; }; 3A0B409E840B44B281DB3C54 /* Container+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F446D6BD4C44E16A1D608BFB /* Container+TypeForwarding.swift */; }; 3BD6055555A5C30DABDC8ED2 /* Reference.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73B4B777290FF5D38A8914CC /* Reference.swift */; }; + 3BDB44DE92D2377334894804 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; + 3C270A77DE4F1E6BC2F8E863 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; 3CEF021295AD9AF9BF26B71E /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; 3DEFB7CA42D9EFF0B4FBC0F4 /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 38BCCF3F950869BD1891F7A8 /* Swinject.framework */; }; + 3EC8383BEAC339595CF7F927 /* Resolver+FunctionCallApi.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 176824B29DD1A0DAA5CBD241 /* Resolver+FunctionCallApi.swifttemplate */; }; 3F8F5645D6D37FCEC1D89393 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B580B43E1891812C97209 /* Binding.swift */; }; 401592294E5D528379BE1AB2 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62682D6ED38742996624B041 /* BasicAssembly.swift */; }; 41C7340BFD2EB66359772733 /* Resolver+LegacyApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A784E2DEC7691D14DDBECD8 /* Resolver+LegacyApi.swift */; }; @@ -73,85 +91,115 @@ 4347EE17D0C0ED574C899D85 /* ScopeRegistryKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */; }; 43A74237D8933572BAA0F3B4 /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; 44F458F61B21D78A91664160 /* BinderVariation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E0C3E4D518BC1FEF3EF8D33 /* BinderVariation.swift */; }; + 45F1654C204C7A2C87397BCD /* PropertyWrappersSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49B24254B9F0E48ED3713565 /* PropertyWrappersSpec.swift */; }; 48D1568CB41BE4B6597FD535 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; + 48F40377D116C6B1B786C329 /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; + 4954CBB07E38E98752AC3347 /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; 49685AB40BEE856C62005C87 /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; 49D71F6CC12C12FE7B6A097A /* ContextSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */; }; 4B9811CF0604946CCF323ED2 /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92B8E618A08408404FB2A7A /* TypeBinder.swift */; }; + 4D86550CC5C281A58B4A6F61 /* SwinjectContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8C4916168E81D76536892122 /* SwinjectContainer.swift */; }; 4DF3DC1CDD3C4948F9BDD3DF /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3586A4987B7C7C8122D674E /* SwinjectError.swift */; }; 4E4DC8CDD1BA51FB66A332C2 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */; }; 4EC94A51037C79DE0C5C8CB1 /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; 4EE5C1207C57C85A928FA89B /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 273FB7A6277E0841E1570990 /* Nimble.framework */; }; - 53EBF7A46EF65F2A8DAADC7A /* InjectionRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InjectionRequest.swift */; }; + 5365FDFB2DDA6491F3049654 /* Opaque.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E7DC2C5AA87B18BD465EB77 /* Opaque.swift */; }; + 5393E5DE21B568A88498E454 /* PropertyWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 424C647FF08FCB7C2A54E085 /* PropertyWrapper.swift */; }; + 546FF827DB6D42490D1CA439 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; + 54956014A1774DF8357B69E6 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; 55CA3AA3F28B7CC221ABEC83 /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6D54F152C11C966ECFC55ECB /* Swinject.framework */; }; 55F2E72EA8C3564130F66946 /* ModulesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75BE3AE3E30DFE42A919D825 /* ModulesSpec.swift */; }; 57BFBA2077E70DC1C2FE796C /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */; }; + 581B08428C6AACAFC8017F8A /* Weak.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57A7E35B2B22650208F904B8 /* Weak.swift */; }; 58ABEE0321A3061048B65EA2 /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42490D1D0C395951243F5CFF /* Container.swift */; }; 590B861A863A056A0B7FA368 /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADA1541ABC1365DFD7E3377F /* Food.swift */; }; 593B93BA2EE3FE4418A1C579 /* ScopeRegistryKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */; }; 599C7F009F954CDA522244B3 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62682D6ED38742996624B041 /* BasicAssembly.swift */; }; 59FD1167CD4A913E04D3EAFD /* ServiceEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38615FC8EEB466C5C1EAD21C /* ServiceEntry.swift */; }; - 5BF9899C59F4BFAA6440D04B /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C074BAC560F277E806146C60 /* SimpleBinding.swift */; }; + 5A78C354D420D64CF8A787C1 /* Resolver+FunctionCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F626B9D3E547621787E4D7 /* Resolver+FunctionCall.swift */; }; + 5BD767B85CFE5FADDFE0A7B5 /* UnboundScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 667B13B528642272FC0794B6 /* UnboundScope.swift */; }; 5C56C1E893D53B2311D27416 /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */; }; 5D5852F610358DFF7230C35C /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59111BE319C59E4CD6CF68CD /* Assembler.swift */; }; 5D7E26A00B055803A50CD9C2 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */; }; 5ED8A7D19F21FA686215F72C /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; + 5F1647DCC0D437A782647372 /* PropertyWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 424C647FF08FCB7C2A54E085 /* PropertyWrapper.swift */; }; + 5F49839A5C17677861F5971B /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7D394F381E60F6E6E92E7DB /* SimpleBinding.swift */; }; 5FCE2A2AE5DD0DBECA4A9953 /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */; }; 6034CF5459D96497AF36E4B6 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; + 6251955691663E4495DE310D /* Opaque.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E7DC2C5AA87B18BD465EB77 /* Opaque.swift */; }; 628EBFBA0031B1FA2E29F583 /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 351C4221896DDB8572BD6CB5 /* Person.swift */; }; 63528D45A548DD58D748D54C /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; 640F7A55D9A671FA112C8083 /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; 658AEDC8D802A6788E959E0C /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B580B43E1891812C97209 /* Binding.swift */; }; - 658C98B4AA17C58E8556E0AC /* Opaque.swift in Sources */ = {isa = PBXBuildFile; fileRef = C68B98C653ABDED9C3D17DB3 /* Opaque.swift */; }; 68C95FCB0D345CA3BA24D320 /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; + 68D828A3C583DDD28CFE882B /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; 6922AE734E84B515C94D9480 /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; 694C2C891D581371B2B051D7 /* Container+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDA78290D6D60BD0B808571F /* Container+Logging.swift */; }; + 69EE97FE7F5AF3A227E7FE22 /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2E291E30E191A1E202A013A /* ScopedBinding.swift */; }; 6A03ABEED82EF31E8E6E297E /* Container+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDA78290D6D60BD0B808571F /* Container+Logging.swift */; }; + 6A0FD11468B3852E48B682BE /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; + 6A967AE5710606998C2BE070 /* PropertyWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 424C647FF08FCB7C2A54E085 /* PropertyWrapper.swift */; }; 6BB1E24C1CE55C9F6EA6CC28 /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C765B92B00C0AC8625BB4AC9 /* Quick.framework */; }; 6C01E868DE44BD396D94858B /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; - 6C4D29A3FB54416D5E4D4C89 /* InstanceBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED41A352529A5B2950F39D8F /* InstanceBuilder.swift */; }; + 6CFE30E5595611778893D147 /* BindingBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = A367B4D6F7E5331620430ECF /* BindingBuilder.swift */; }; 6DA49F84E2592B32F81F268B /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BFF4BA99493C54260878C4 /* ObjectScope.swift */; }; + 6DD80811E5FD658CAFEEA647 /* CIrcularitySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 118ABC654C4144496848AD74 /* CIrcularitySpec.swift */; }; 6F6FAD0EEF84580DD53BB755 /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1C58FC14EEA170B0DC079DE4 /* Quick.framework */; }; 6FCCBA9D2E4C2A225CB1A152 /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */; }; 70368EC369287B4EE767E929 /* LinuxConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 938425B216B78A06EC10504A /* LinuxConfig.swift */; }; 703F8B3AD111A6CFAFF66A49 /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; + 708D400457552769A54A406B /* OverrideSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86C18DDD83715886DF7F1818 /* OverrideSpec.swift */; }; + 708E1C453CBC76ED26FA2FCB /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; 70BAF056528B2B33B3A65E9D /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A006CC804F9AB8ACC121029 /* Utils.swift */; }; 71895EBC0803EEE3BFCD7001 /* Resolver+Injection.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 01DEC4D20CE554C9DFBD0A8D /* Resolver+Injection.swifttemplate */; }; 72217E47D83C3CA6D97640B9 /* StandardScopeRegistrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */; }; 725EF35B0CC5E62791D5EA09 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 34AFFAC41BA9D02A38BDB7A3 /* Nimble.framework */; }; - 7295E928A18E6055CF796840 /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C074BAC560F277E806146C60 /* SimpleBinding.swift */; }; 72F09FC92FFB0F7C32D8E2A5 /* OptionalsSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50D6F2639990DD5BAD9578B0 /* OptionalsSpec.swift */; }; 737740CDFB89189DFF5FD165 /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 74DE57FB3E8228904E6FE0D7 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; 74E1FC692A27C56510363364 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; + 751F545653B0F1E30341C312 /* OverrideSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86C18DDD83715886DF7F1818 /* OverrideSpec.swift */; }; 75D74C8C25EDACF5A7A75A5C /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; + 76FB9AFE299316E7F3F4C3BB /* InjectionRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57F4D977AC4289A6145383C9 /* InjectionRequest.swift */; }; 778D9AB6470D4280254AC140 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; 77BF219EAB4FC8475943CECC /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6D434EB4C13CF9D9FA6D80CB /* Swinject.framework */; }; 789BF74652A2424EB8F7EF47 /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 7A7032384E07DAD308D4F70A /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 8B9785AAE94A5447FA307242 /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 7D0683F36CE56228AC2CD489 /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C074BAC560F277E806146C60 /* SimpleBinding.swift */; }; + 7A956FAB419F74D7EB9CAD0B /* Opaque.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E7DC2C5AA87B18BD465EB77 /* Opaque.swift */; }; + 7C745281CA1627BCC8A8A92A /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2E291E30E191A1E202A013A /* ScopedBinding.swift */; }; + 7D6F664091C70BABBFB61D53 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; 7E3C3E6FD07F3BD76024770A /* InjectionVariation.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C516EFA0CA22D19F07B27E /* InjectionVariation.swift */; }; - 7F9686F3669BF35E5AC970B3 /* InstanceBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED41A352529A5B2950F39D8F /* InstanceBuilder.swift */; }; 8016512839FE61EC3127E489 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */; }; 811BA1018E9BF86A7DEB728F /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */; }; 818DF17D671EA1022CE59A2A /* InjectionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 670DB253ECD5CE1468A7F2E3 /* InjectionSpec.swift */; }; 820307073A53AED47AC99B8D /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3586A4987B7C7C8122D674E /* SwinjectError.swift */; }; - 8228FEB1DF3C41DEDCE0FB1D /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = A10187BB3A994165E7FC1528 /* ScopedBinding.swift */; }; 82299769BC637A14E7827DB0 /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1E726A651C3AFE92C19608B /* SwinjectModule.swift */; }; + 826D63FA91E370F0061768B0 /* InjectionRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57F4D977AC4289A6145383C9 /* InjectionRequest.swift */; }; + 829853126CDB7464599AFC85 /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; 832C9ABB8DCF5340D796F5F8 /* ContextSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */; }; + 83464EDC08380F5CE2190F30 /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; + 8436D091ED844817C8CE3AF2 /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; 848227742D4ABA298D340485 /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; + 85CBEFBB558636EAC76E5F0C /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2E291E30E191A1E202A013A /* ScopedBinding.swift */; }; 86CBC40FDC90E2A2051386C5 /* ContextSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */; }; 87FEAEF562B99522083CB87D /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; + 890CCD2800597F6FB7C6FD31 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; 89E2997CB8B90368A15A91CE /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; + 8A4E9E736239F92F878C070C /* Resolver+FunctionCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F626B9D3E547621787E4D7 /* Resolver+FunctionCall.swift */; }; 8B5927517B567B1DFAB5B935 /* ContextTranslator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */; }; - 8BE1DA0A9876AB47BB76E2CD /* Opaque.swift in Sources */ = {isa = PBXBuildFile; fileRef = C68B98C653ABDED9C3D17DB3 /* Opaque.swift */; }; + 8B711CBE6A5B86DC2D6CABDC /* UnboundScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 667B13B528642272FC0794B6 /* UnboundScope.swift */; }; 8E1E051646BBD6E38F4199C2 /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EA566CD336DB8343ADFAF9B /* BehaviorFakes.swift */; }; 8E77B56EE7F90BF723600DDF /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1E726A651C3AFE92C19608B /* SwinjectModule.swift */; }; + 90C399A2AF93F0897169E413 /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96AEC72A42A227A50CF9845B /* Circularity.swift */; }; 91E435894038C42335086FA8 /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3586A4987B7C7C8122D674E /* SwinjectError.swift */; }; 920DE2CAB9895D10FAE48FBA /* ScopeRegistryKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */; }; 934AFACA6BFF24AD3503F98D /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */; }; 93BCD12CEFB88BAD49BEA431 /* ServiceEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38615FC8EEB466C5C1EAD21C /* ServiceEntry.swift */; }; 9425887520AC2DBDCBACB252 /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92B8E618A08408404FB2A7A /* TypeBinder.swift */; }; 95A6654089875BCC863FB53B /* InjectionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 670DB253ECD5CE1468A7F2E3 /* InjectionSpec.swift */; }; + 95E6DD9D94BE64420EEC1298 /* Weak.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57A7E35B2B22650208F904B8 /* Weak.swift */; }; 96EA0A5DF33F025EBE0B67D2 /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; + 976E692202CF33EEE4C3A997 /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7D394F381E60F6E6E92E7DB /* SimpleBinding.swift */; }; + 979518E078B187549E11DF48 /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; 97C2EA47D7623AFD723AFE93 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */; }; 980FED1DBC62B65597E2828B /* SingletonSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46F05CC591903E2B04B6D8ED /* SingletonSpec.swift */; }; 98322F9371E1A8461BC614D1 /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; @@ -159,12 +207,12 @@ 996CCFE825834C7D3236E742 /* Container+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F446D6BD4C44E16A1D608BFB /* Container+TypeForwarding.swift */; }; 999AF7221D3F2E1F83C3ACB1 /* Container+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDA78290D6D60BD0B808571F /* Container+Logging.swift */; }; 99C5D861B16FAFAD3F9E28C5 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */; }; + 9A21ECA8F283E1E144CEC763 /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; 9A2A6978519F2BBA97DA6EA6 /* BindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E59A67F3548663368788B17 /* BindingSpec.swift */; }; - 9C15BE01C1EA41061CDB7918 /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C074BAC560F277E806146C60 /* SimpleBinding.swift */; }; + 9AA68475ABE3E7502F59216D /* PropertyWrappersSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49B24254B9F0E48ED3713565 /* PropertyWrappersSpec.swift */; }; 9CCAB8EE342CCC8D2FB187C1 /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */; }; 9CEE20BD42795D5E5F39BF20 /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; - 9DEAC620F2F00D0DDD3B5D3E /* InjectionRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InjectionRequest.swift */; }; - A193BF10196FBDE32833E292 /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = A10187BB3A994165E7FC1528 /* ScopedBinding.swift */; }; + A1A2D0FA98038EACAC04E64C /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; A2D3B18BE38948A427B60BC5 /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61EE5DDBE705B47AFC9A6986 /* LoadAwareAssembly.swift */; }; A308578B99D33C7E33632E85 /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; A3BFFED76688F149FBAF7C53 /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EA566CD336DB8343ADFAF9B /* BehaviorFakes.swift */; }; @@ -172,34 +220,45 @@ A53B5A8E2188F8C4A3F29C2E /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BC5108ED11A3A3084D864CC /* Animal.swift */; }; A59C6C434288333EDAF951C4 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */; }; A5E4C79F89E1A8AB3A4D8D6E /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59A3946B59EB4D787CCE9F2 /* Container+Registration.swift */; }; + A6721BA534AD082E1E7C1D08 /* SwinjectContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8C4916168E81D76536892122 /* SwinjectContainer.swift */; }; A6EECC339FA54CA0BBFF4146 /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BC5108ED11A3A3084D864CC /* Animal.swift */; }; + A70936B898139A6C5F83F616 /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; A75BAA10EC6F738EBC2C5BE8 /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */; }; + A7DD08A60F12EC078BBE086F /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; A834D948AB86794CA3304B98 /* LinuxConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 938425B216B78A06EC10504A /* LinuxConfig.swift */; }; A882705E4199EF759E80B311 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; + A9112F7CF871475B94A077D7 /* Resolver+FunctionCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F626B9D3E547621787E4D7 /* Resolver+FunctionCall.swift */; }; A91EDAFBC3606EDFBD739899 /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */; }; + A9A242086D1EDE408DC556D0 /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; + AAC6F2F5EC2928943BF2BED1 /* PropertyWrappersSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49B24254B9F0E48ED3713565 /* PropertyWrappersSpec.swift */; }; AAD8D0551B8A26A9B22AECEC /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59A3946B59EB4D787CCE9F2 /* Container+Registration.swift */; }; AB864E029E996492ED4A3A52 /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92B8E618A08408404FB2A7A /* TypeBinder.swift */; }; AC470B4322599B0A076DD3FF /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; + ACA8E10AADBFC063A6F345D7 /* CIrcularitySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 118ABC654C4144496848AD74 /* CIrcularitySpec.swift */; }; AD214F3DBAB4F16C88322CAC /* InjectionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 670DB253ECD5CE1468A7F2E3 /* InjectionSpec.swift */; }; AD3E7135985F1046E35C39DE /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */; }; ADCF273AF041E74DBEC2C13A /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */; }; ADF0B21969FE77CEFBB2AAAC /* Quick.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 823617F3B8A9192F56B13331 /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + AE6EAB8CC32ED5E1789D55B7 /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; AE93BDC3AA7962AFD574B32B /* Quick.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 1C58FC14EEA170B0DC079DE4 /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; B00627BABCF9181C7B58609E /* LinuxConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 938425B216B78A06EC10504A /* LinuxConfig.swift */; }; B06306286CC5EA66C88F24D1 /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 38BCCF3F950869BD1891F7A8 /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; B0B139FADA6AE07C79847EBA /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61EE5DDBE705B47AFC9A6986 /* LoadAwareAssembly.swift */; }; + B0B65F494A88CDEFE8EF79F6 /* BindingBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = A367B4D6F7E5331620430ECF /* BindingBuilder.swift */; }; B293894FEB67831DDA5F000E /* Reference.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73B4B777290FF5D38A8914CC /* Reference.swift */; }; B2FAD41F7726502822AF913B /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42490D1D0C395951243F5CFF /* Container.swift */; }; + B3062AB22373AD23052B61DF /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; B42331BF00B482369B908BB8 /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BFF4BA99493C54260878C4 /* ObjectScope.swift */; }; B4B66D7251BDDE25D6D7FB3C /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BFF4BA99493C54260878C4 /* ObjectScope.swift */; }; B5FF5DFE394B6B1BB930D88D /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */; }; B65DE0B0562540CC8CEC48F3 /* SingletonSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46F05CC591903E2B04B6D8ED /* SingletonSpec.swift */; }; B7653A6427A5E284E9A1D6D3 /* ServiceEntry+TypeForwarding.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */; }; B84167AC8C6BEB57C4D0695A /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; - B90EA5A6764CEFA2BCB6C4D9 /* InstanceBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED41A352529A5B2950F39D8F /* InstanceBuilder.swift */; }; + B91523667CD2A31E889A4669 /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2E291E30E191A1E202A013A /* ScopedBinding.swift */; }; B9550BE2BA6FA5731BEC87FD /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; B96A6370D549AAC383360ABC /* LinuxConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 938425B216B78A06EC10504A /* LinuxConfig.swift */; }; BB571B9A78FC53231A18E18C /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; + BB64AE6DFE526629918211B7 /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96AEC72A42A227A50CF9845B /* Circularity.swift */; }; BB77A5D81C58392964D07233 /* BindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E59A67F3548663368788B17 /* BindingSpec.swift */; }; BB8FDF4F2A0AF8C1DA615854 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; BCD130E9F1D33C66AA6A12F7 /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 74DE57FB3E8228904E6FE0D7 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -211,101 +270,40 @@ BEEFBE87EB17D56BA8D47358 /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 351C4221896DDB8572BD6CB5 /* Person.swift */; }; BEFFC7B36FE5810169C81B97 /* BinderEnvironment.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 26EEC28683E4A26B3092E8BA /* BinderEnvironment.swifttemplate */; }; BFE22F9F2E88F177302E9D19 /* Container+Registration.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */; }; + C1687ACA897DEFD3A8197CCD /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; C223101DB417F1237A8421E1 /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 6D434EB4C13CF9D9FA6D80CB /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + C22853F014054A6DCDF0CB6A /* OverrideSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86C18DDD83715886DF7F1818 /* OverrideSpec.swift */; }; C38A2EBF4D1904E7D6989989 /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADA1541ABC1365DFD7E3377F /* Food.swift */; }; - C3FDE105B08336F26CC95BAA /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = A10187BB3A994165E7FC1528 /* ScopedBinding.swift */; }; C637E97E193BB1DADDDC6C21 /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1E726A651C3AFE92C19608B /* SwinjectModule.swift */; }; C6D60E2AEC381998223145B2 /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; + C6E443EAD892B0B69DA61144 /* InstanceBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 419FB96A1F4B72278B9A6665 /* InstanceBuilder.swift */; }; C76374CAFE7C2BCCE52F1BB1 /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 351C4221896DDB8572BD6CB5 /* Person.swift */; }; + C8462BEE06316286B9CA85AC /* SwinjectContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8C4916168E81D76536892122 /* SwinjectContainer.swift */; }; + C950785B81C6DB22F41FA3CE /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; C952D5869D87743297968E9A /* StandardScopeRegistrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */; }; + CA5523B60E51EB98719CF1F8 /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; CAA5241DAA201FBB5818C803 /* BindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E59A67F3548663368788B17 /* BindingSpec.swift */; }; CB0B308F3D3A831A28127462 /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59A3946B59EB4D787CCE9F2 /* Container+Registration.swift */; }; CB9E8D16D7A0620A1F7A32A3 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; + CBBE28990E0EA82AD8D5E3AF /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; CBE63031F33303F3E503CEF2 /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; - CD03917422EF610800DE44C4 /* OverrideSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD03917322EF610800DE44C4 /* OverrideSpec.swift */; }; - CD03917522EF610800DE44C4 /* OverrideSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD03917322EF610800DE44C4 /* OverrideSpec.swift */; }; - CD03917622EF610800DE44C4 /* OverrideSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD03917322EF610800DE44C4 /* OverrideSpec.swift */; }; - CD03917722EF610800DE44C4 /* OverrideSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD03917322EF610800DE44C4 /* OverrideSpec.swift */; }; - CD367C0E22EF8A83008B3E82 /* SwinjectContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD367C0D22EF8A83008B3E82 /* SwinjectContainer.swift */; }; - CD367C0F22EF8A83008B3E82 /* SwinjectContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD367C0D22EF8A83008B3E82 /* SwinjectContainer.swift */; }; - CD367C1022EF8A83008B3E82 /* SwinjectContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD367C0D22EF8A83008B3E82 /* SwinjectContainer.swift */; }; - CD367C1122EF8A83008B3E82 /* SwinjectContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD367C0D22EF8A83008B3E82 /* SwinjectContainer.swift */; }; - CD68676022F5C60800F7D9E3 /* PropertyWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD68675F22F5C60800F7D9E3 /* PropertyWrapper.swift */; }; - CD68676122F5C85B00F7D9E3 /* PropertyWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD68675F22F5C60800F7D9E3 /* PropertyWrapper.swift */; }; - CD68676222F5C85B00F7D9E3 /* PropertyWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD68675F22F5C60800F7D9E3 /* PropertyWrapper.swift */; }; - CD68676322F5C85B00F7D9E3 /* PropertyWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD68675F22F5C60800F7D9E3 /* PropertyWrapper.swift */; }; - CD68676522F5CA5D00F7D9E3 /* PropertyWrappersSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD68676422F5CA5D00F7D9E3 /* PropertyWrappersSpec.swift */; }; - CD68676622F5CA5D00F7D9E3 /* PropertyWrappersSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD68676422F5CA5D00F7D9E3 /* PropertyWrappersSpec.swift */; }; - CD68676722F5CA5D00F7D9E3 /* PropertyWrappersSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD68676422F5CA5D00F7D9E3 /* PropertyWrappersSpec.swift */; }; - CD68676822F5CA5D00F7D9E3 /* PropertyWrappersSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD68676422F5CA5D00F7D9E3 /* PropertyWrappersSpec.swift */; }; - CD73B9AB22F239A4004BB84E /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; - CD73B9AC22F239A4004BB84E /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */; }; - CD73B9AD22F239A4004BB84E /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; - CD73B9AE22F239A4004BB84E /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; - CD73B9AF22F239A4004BB84E /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; - CD73B9B022F239A4004BB84E /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; - CD73B9B122F239A4004BB84E /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; - CD73B9B222F239A4004BB84E /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; - CD73B9B322F239A4004BB84E /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; - CD73B9B422F239A4004BB84E /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; - CD73B9B522F239A4004BB84E /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; - CD73B9B622F239A4004BB84E /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; - CD73B9B722F239A4004BB84E /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */; }; - CD73B9B822F239A4004BB84E /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; - CD73B9B922F239A4004BB84E /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; - CD73B9BA22F239A4004BB84E /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; - CD73B9BB22F239A4004BB84E /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; - CD73B9BC22F239A4004BB84E /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; - CD73B9BD22F239A4004BB84E /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; - CD73B9BE22F239A4004BB84E /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; - CD73B9BF22F239A4004BB84E /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; - CD73B9C022F239A4004BB84E /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; - CD73B9C122F239A5004BB84E /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; - CD73B9C222F239A5004BB84E /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */; }; - CD73B9C322F239A5004BB84E /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; - CD73B9C422F239A5004BB84E /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; - CD73B9C522F239A5004BB84E /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; - CD73B9C622F239A5004BB84E /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; - CD73B9C722F239A5004BB84E /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; - CD73B9C822F239A5004BB84E /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; - CD73B9C922F239A5004BB84E /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; - CD73B9CA22F239A5004BB84E /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; - CD73B9CB22F239A5004BB84E /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; - CD73B9CC22F239A6004BB84E /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; - CD73B9CD22F239A6004BB84E /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */; }; - CD73B9CE22F239A6004BB84E /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; - CD73B9CF22F239A6004BB84E /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; - CD73B9D022F239A6004BB84E /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; - CD73B9D122F239A6004BB84E /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; - CD73B9D222F239A6004BB84E /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; - CD73B9D322F239A6004BB84E /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; - CD73B9D422F239A6004BB84E /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; - CD73B9D522F239A6004BB84E /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; - CD73B9D622F239A6004BB84E /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; - CDE303DC22F6DDA900846EFA /* Resolver+FunctionCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE303DB22F6DDA900846EFA /* Resolver+FunctionCall.swift */; }; - CDE303DD22F6DDA900846EFA /* Resolver+FunctionCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE303DB22F6DDA900846EFA /* Resolver+FunctionCall.swift */; }; - CDE303DE22F6DDA900846EFA /* Resolver+FunctionCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE303DB22F6DDA900846EFA /* Resolver+FunctionCall.swift */; }; - CDE303DF22F6DDA900846EFA /* Resolver+FunctionCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE303DB22F6DDA900846EFA /* Resolver+FunctionCall.swift */; }; - CDE303E122F6DF7500846EFA /* Resolver+FunctionCallApi.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = CDE303E022F6DF7500846EFA /* Resolver+FunctionCallApi.swifttemplate */; }; - CDE303F622F7009B00846EFA /* CIrcularitySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE303F122F7008600846EFA /* CIrcularitySpec.swift */; }; - CDE303F722F7009B00846EFA /* CIrcularitySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE303F122F7008600846EFA /* CIrcularitySpec.swift */; }; - CDE303F822F7009C00846EFA /* CIrcularitySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE303F122F7008600846EFA /* CIrcularitySpec.swift */; }; - CDE303F922F7009C00846EFA /* CIrcularitySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE303F122F7008600846EFA /* CIrcularitySpec.swift */; }; - CDE303FB22F70A2500846EFA /* Weak.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE303FA22F70A2500846EFA /* Weak.swift */; }; - CDE303FC22F70A2500846EFA /* Weak.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE303FA22F70A2500846EFA /* Weak.swift */; }; - CDE303FD22F70A2500846EFA /* Weak.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE303FA22F70A2500846EFA /* Weak.swift */; }; - CDE303FE22F70A2500846EFA /* Weak.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE303FA22F70A2500846EFA /* Weak.swift */; }; + CDE8EA7EC1D8096F12BDD8C2 /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96AEC72A42A227A50CF9845B /* Circularity.swift */; }; CE5AFED22F04B96713ED76D7 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ADC44E9312C3B974AFD8F07B /* Nimble.framework */; }; - CECF5BD14BCDF5248771A06A /* InjectionRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InjectionRequest.swift */; }; CEE763218A90832454A6E2DE /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */; }; + CF4516872D3DA7118DB2B90B /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; CF4EBB60C21F8C503BCD7A29 /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1E726A651C3AFE92C19608B /* SwinjectModule.swift */; }; + CF9535A0DCAFF23F4D62F871 /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; D0D71F9C22A0EE82B6E4F61A /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 74DE57FB3E8228904E6FE0D7 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; D13208E63523A97A0B840283 /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BC5108ED11A3A3084D864CC /* Animal.swift */; }; D1DF4740A9D86362B63104B8 /* ContextTranslator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */; }; D2BAE1CB997A4D052CB8EFC8 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B580B43E1891812C97209 /* Binding.swift */; }; D3FB9F7B3F791A83FF86205C /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 273FB7A6277E0841E1570990 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + D3FD513CDD70AF674C453B83 /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96AEC72A42A227A50CF9845B /* Circularity.swift */; }; D4936DC1A47A8C85325FB52E /* Resolver+LegacyApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A784E2DEC7691D14DDBECD8 /* Resolver+LegacyApi.swift */; }; D600D0EFA0FE12A719EF095F /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 683A1FB7D7F4E9508D57E936 /* Quick.framework */; }; + D669A1E2657CC868027395D9 /* UnboundScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 667B13B528642272FC0794B6 /* UnboundScope.swift */; }; + D69ED6990417ED1E921ACFCA /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; + D7915D8FCF67D0FFCC41E9D6 /* PropertyWrappersSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49B24254B9F0E48ED3713565 /* PropertyWrappersSpec.swift */; }; D861595482464ED95CF81922 /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; D9084C826F7A798508CD66F5 /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; D941D81F59900A52805D6B4A /* OptionalsSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50D6F2639990DD5BAD9578B0 /* OptionalsSpec.swift */; }; @@ -313,35 +311,45 @@ D9C5E21A1B6F43FA4C9DAD3C /* Quick.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 683A1FB7D7F4E9508D57E936 /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; D9F132E4A6F6BC2BDD5DFCAA /* ModulesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75BE3AE3E30DFE42A919D825 /* ModulesSpec.swift */; }; DB74F17CDFF4886B9C38AD14 /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42490D1D0C395951243F5CFF /* Container.swift */; }; - DBEFC5C6A51FCEBF9E4F70EE /* InstanceBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED41A352529A5B2950F39D8F /* InstanceBuilder.swift */; }; DC5B169FD525CC1C01518312 /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59111BE319C59E4CD6CF68CD /* Assembler.swift */; }; DCB7C4BF24782862BE9DB135 /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; DD29D2E60DA979D61F32A39A /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62682D6ED38742996624B041 /* BasicAssembly.swift */; }; DD5E3AF2B5FCE5E81EBDF606 /* ContextTranslator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */; }; + E01D0D443FBA4DB82A6EC298 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; E177D354B1F410129D921C69 /* Resolver+LegacyApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A784E2DEC7691D14DDBECD8 /* Resolver+LegacyApi.swift */; }; - E1B95D3EEA5BB989CCFFE70D /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = A10187BB3A994165E7FC1528 /* ScopedBinding.swift */; }; E227D08034E08AA0909BC043 /* RetrievalSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D8B3342E2AC3236F12072F5 /* RetrievalSpec.swift */; }; + E39152E9059357CF0C9B21AF /* CIrcularitySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 118ABC654C4144496848AD74 /* CIrcularitySpec.swift */; }; E3EABE098DBFB561A20632E3 /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; E4CE31B7B9616EFC93C69341 /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; + E5880DBBB91CC5F8F47FBF73 /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; E7D1045D25FAB592401DCAF0 /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; EA0D19F7DF0355C774B0F40B /* ScopesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D3C59E84B5FD0C13F487838 /* ScopesSpec.swift */; }; EB3420214A9E68A0247D0F2C /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 351C4221896DDB8572BD6CB5 /* Person.swift */; }; + EB73B06547A273D2534528E3 /* Opaque.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E7DC2C5AA87B18BD465EB77 /* Opaque.swift */; }; + EB79ECF5C893F63B22355167 /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; EBC64A1515C868E410C83451 /* SwiftCode.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 90191C25A2D66E07C4E9CD73 /* SwiftCode.swifttemplate */; }; ED6CB3935B15F30A182ED6D0 /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61EE5DDBE705B47AFC9A6986 /* LoadAwareAssembly.swift */; }; EE0D3637D2524AC1CD21780D /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 74DE57FB3E8228904E6FE0D7 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; + EE3063E3D1582D3BB7CC43F0 /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7D394F381E60F6E6E92E7DB /* SimpleBinding.swift */; }; EE35DF2D353E2C5110DA5C42 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; EEAD7E215908DF939ECCDCC9 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; EF79F0B3D497215D4BBBC038 /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92B8E618A08408404FB2A7A /* TypeBinder.swift */; }; EFD2F695B86E74C77F46B7D1 /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; F06DEB671A4B85ABB0E96E51 /* ContextTranslator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */; }; F1F3BA81462E2362374BD4C4 /* ModulesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75BE3AE3E30DFE42A919D825 /* ModulesSpec.swift */; }; + F270DC6FF3901F58C76F3872 /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; F504C2ABEFCFFCAC8B858751 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; F568382FB877060127790413 /* Resolver+LegacyApi.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */; }; F6EEF5F7B57DC0E44EF569A4 /* OptionalsSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50D6F2639990DD5BAD9578B0 /* OptionalsSpec.swift */; }; F7979BE4BE1B1C7101D15E61 /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; + F7CD04FB09FC7F18E9E001CF /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; + F88700BAAFFB47B1BD4D3BFA /* Weak.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57A7E35B2B22650208F904B8 /* Weak.swift */; }; + F8EB47A631D482A0D7B621DE /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; F9A4BF18B0085B7DCD3440EC /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B580B43E1891812C97209 /* Binding.swift */; }; FA805A162E989A22990B99AA /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; + FC339851D7EEE4D17178CC1F /* Weak.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57A7E35B2B22650208F904B8 /* Weak.swift */; }; FD7B2663F2F931B78EB330EE /* Resolver+LegacyApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A784E2DEC7691D14DDBECD8 /* Resolver+LegacyApi.swift */; }; + FD8BB4CC8DA0E560E39FA491 /* BindingBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = A367B4D6F7E5331620430ECF /* BindingBuilder.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -459,24 +467,26 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 01DEC4D20CE554C9DFBD0A8D /* Resolver+Injection.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+Injection.swifttemplate"; sourceTree = ""; }; + 01DEC4D20CE554C9DFBD0A8D /* Resolver+Injection.swifttemplate */ = {isa = PBXFileReference; path = "Resolver+Injection.swifttemplate"; sourceTree = ""; }; 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.swift; sourceTree = ""; }; 09FC792715B1658721F76885 /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 0CA449690AE00F6300DE8ACA /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 0D8B3342E2AC3236F12072F5 /* RetrievalSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RetrievalSpec.swift; sourceTree = ""; }; 0DC67CB109091002AB433A46 /* SwinjectTests.xctest */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.cfbundle; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 0E0B580B43E1891812C97209 /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; + 0E7DC2C5AA87B18BD465EB77 /* Opaque.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Opaque.swift; sourceTree = ""; }; 10480F2154EAA0414D4C1F55 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .swiftlint.yml; sourceTree = ""; }; + 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */ = {isa = PBXFileReference; path = .swiftlint.yml; sourceTree = ""; }; + 118ABC654C4144496848AD74 /* CIrcularitySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CIrcularitySpec.swift; sourceTree = ""; }; 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SynchronizedResolverSpec.swift; sourceTree = ""; }; 13513FA012659ADE699A3608 /* LazySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LazySpec.swift; sourceTree = ""; }; + 176824B29DD1A0DAA5CBD241 /* Resolver+FunctionCallApi.swifttemplate */ = {isa = PBXFileReference; path = "Resolver+FunctionCallApi.swifttemplate"; sourceTree = ""; }; 1A006CC804F9AB8ACC121029 /* Utils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = ""; }; 1C58FC14EEA170B0DC079DE4 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; 1D3C59E84B5FD0C13F487838 /* ScopesSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopesSpec.swift; sourceTree = ""; }; - 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Circularity.swift; sourceTree = ""; }; 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Behavior.swift; sourceTree = ""; }; 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Arguments.swift; sourceTree = ""; }; - 26EEC28683E4A26B3092E8BA /* BinderEnvironment.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = BinderEnvironment.swifttemplate; sourceTree = ""; }; + 26EEC28683E4A26B3092E8BA /* BinderEnvironment.swifttemplate */ = {isa = PBXFileReference; path = BinderEnvironment.swifttemplate; sourceTree = ""; }; 273FB7A6277E0841E1570990 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; 2E0C3E4D518BC1FEF3EF8D33 /* BinderVariation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderVariation.swift; sourceTree = ""; }; 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; @@ -486,16 +496,21 @@ 38615FC8EEB466C5C1EAD21C /* ServiceEntry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServiceEntry.swift; sourceTree = ""; }; 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Swinject+Builder.swift"; sourceTree = ""; }; 38BCCF3F950869BD1891F7A8 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 419FB96A1F4B72278B9A6665 /* InstanceBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceBuilder.swift; sourceTree = ""; }; 42490D1D0C395951243F5CFF /* Container.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.swift; sourceTree = ""; }; + 424C647FF08FCB7C2A54E085 /* PropertyWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PropertyWrapper.swift; sourceTree = ""; }; 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmploymentAssembly.swift; sourceTree = ""; }; 46F05CC591903E2B04B6D8ED /* SingletonSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingletonSpec.swift; sourceTree = ""; }; 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTree.swift; sourceTree = ""; }; 494AA2AA587975747596C157 /* ProviderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProviderSpec.swift; sourceTree = ""; }; + 49B24254B9F0E48ED3713565 /* PropertyWrappersSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PropertyWrappersSpec.swift; sourceTree = ""; }; 4A784E2DEC7691D14DDBECD8 /* Resolver+LegacyApi.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Resolver+LegacyApi.swift"; sourceTree = ""; }; 4BC5108ED11A3A3084D864CC /* Animal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Animal.swift; sourceTree = ""; }; 4D31F8718D2E847922530C20 /* Templates.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Templates.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 5057BAB33984E3E33469452B /* Scope.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Scope.swift; sourceTree = ""; }; 50D6F2639990DD5BAD9578B0 /* OptionalsSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OptionalsSpec.swift; sourceTree = ""; }; + 57A7E35B2B22650208F904B8 /* Weak.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Weak.swift; sourceTree = ""; }; + 57F4D977AC4289A6145383C9 /* InjectionRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InjectionRequest.swift; sourceTree = ""; }; 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Resolver+Injection.swift"; sourceTree = ""; }; 59111BE319C59E4CD6CF68CD /* Assembler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Assembler.swift; sourceTree = ""; }; 5AB605ED0F735221D0EB1D5F /* Convenience.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Convenience.swift; sourceTree = ""; }; @@ -504,6 +519,7 @@ 5F7BC1C4169BB4382C6D3E1F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 61EE5DDBE705B47AFC9A6986 /* LoadAwareAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadAwareAssembly.swift; sourceTree = ""; }; 62682D6ED38742996624B041 /* BasicAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BasicAssembly.swift; sourceTree = ""; }; + 667B13B528642272FC0794B6 /* UnboundScope.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnboundScope.swift; sourceTree = ""; }; 670DB253ECD5CE1468A7F2E3 /* InjectionSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InjectionSpec.swift; sourceTree = ""; }; 683A1FB7D7F4E9508D57E936 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceWrapper.swift; sourceTree = ""; }; @@ -518,17 +534,20 @@ 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ServiceEntry+TypeForwarding.swift"; sourceTree = ""; }; 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextTranslator.swift; sourceTree = ""; }; 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistry.swift; sourceTree = ""; }; - 808C1063CA90CC593C7E0E9C /* MatchableBoxes.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = MatchableBoxes.swifttemplate; sourceTree = ""; }; + 808C1063CA90CC593C7E0E9C /* MatchableBoxes.swifttemplate */ = {isa = PBXFileReference; path = MatchableBoxes.swifttemplate; sourceTree = ""; }; 823617F3B8A9192F56B13331 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; + 86C18DDD83715886DF7F1818 /* OverrideSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OverrideSpec.swift; sourceTree = ""; }; 8B9785AAE94A5447FA307242 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 8C4916168E81D76536892122 /* SwinjectContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectContainer.swift; sourceTree = ""; }; 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTreeBuilderSpec.swift; sourceTree = ""; }; - 90191C25A2D66E07C4E9CD73 /* SwiftCode.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = SwiftCode.swifttemplate; sourceTree = ""; }; + 90191C25A2D66E07C4E9CD73 /* SwiftCode.swifttemplate */ = {isa = PBXFileReference; path = SwiftCode.swifttemplate; sourceTree = ""; }; 938425B216B78A06EC10504A /* LinuxConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinuxConfig.swift; sourceTree = ""; }; 9620155728133F451B31C0AD /* Swinject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Swinject.swift; sourceTree = ""; }; + 96AEC72A42A227A50CF9845B /* Circularity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Circularity.swift; sourceTree = ""; }; 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistryKey.swift; sourceTree = ""; }; - A10187BB3A994165E7FC1528 /* ScopedBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopedBinding.swift; sourceTree = ""; }; A20C1319AF31EC7F8E6945FE /* SwinjectTests.xctest */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.cfbundle; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; A3586A4987B7C7C8122D674E /* SwinjectError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectError.swift; sourceTree = ""; }; + A367B4D6F7E5331620430ECF /* BindingBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingBuilder.swift; sourceTree = ""; }; A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Resolver.swift; sourceTree = ""; }; ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Circularity.swift; sourceTree = ""; }; ADA1541ABC1365DFD7E3377F /* Food.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Food.swift; sourceTree = ""; }; @@ -537,33 +556,24 @@ B59A3946B59EB4D787CCE9F2 /* Container+Registration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Registration.swift"; sourceTree = ""; }; B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderEnvironment.swift; sourceTree = ""; }; B92B8E618A08408404FB2A7A /* TypeBinder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinder.swift; sourceTree = ""; }; + B9F626B9D3E547621787E4D7 /* Resolver+FunctionCall.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Resolver+FunctionCall.swift"; sourceTree = ""; }; BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StandardScopeRegistrySpec.swift; sourceTree = ""; }; - BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "ServiceEntry+TypeForwarding.swifttemplate"; sourceTree = ""; }; + BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */ = {isa = PBXFileReference; path = "ServiceEntry+TypeForwarding.swifttemplate"; sourceTree = ""; }; BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Behavior.swift; sourceTree = ""; }; - C074BAC560F277E806146C60 /* SimpleBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleBinding.swift; sourceTree = ""; }; C1E726A651C3AFE92C19608B /* SwinjectModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectModule.swift; sourceTree = ""; }; C3C516EFA0CA22D19F07B27E /* InjectionVariation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InjectionVariation.swift; sourceTree = ""; }; - C68B98C653ABDED9C3D17DB3 /* Opaque.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Opaque.swift; sourceTree = ""; }; C765B92B00C0AC8625BB4AC9 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; CC85CB215058F95C0BC190B1 /* Bridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bridge.swift; sourceTree = ""; }; - CD03917322EF610800DE44C4 /* OverrideSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OverrideSpec.swift; sourceTree = ""; }; - CD367C0D22EF8A83008B3E82 /* SwinjectContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectContainer.swift; sourceTree = ""; }; - CD68675F22F5C60800F7D9E3 /* PropertyWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PropertyWrapper.swift; sourceTree = ""; }; - CD68676422F5CA5D00F7D9E3 /* PropertyWrappersSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PropertyWrappersSpec.swift; sourceTree = ""; }; CDA78290D6D60BD0B808571F /* Container+Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Logging.swift"; sourceTree = ""; }; - CDE303DB22F6DDA900846EFA /* Resolver+FunctionCall.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Resolver+FunctionCall.swift"; sourceTree = ""; }; - CDE303E022F6DF7500846EFA /* Resolver+FunctionCallApi.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+FunctionCallApi.swifttemplate"; sourceTree = ""; }; - CDE303F122F7008600846EFA /* CIrcularitySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CIrcularitySpec.swift; sourceTree = ""; }; - CDE303FA22F70A2500846EFA /* Weak.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Weak.swift; sourceTree = ""; }; - CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; + CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; + D7D394F381E60F6E6E92E7DB /* SimpleBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleBinding.swift; sourceTree = ""; }; DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextSpec.swift; sourceTree = ""; }; - E0874A043EAEE3C7CF1EA063 /* InjectionRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InjectionRequest.swift; sourceTree = ""; }; E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; - ED41A352529A5B2950F39D8F /* InstanceBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceBuilder.swift; sourceTree = ""; }; F290F6B1207A0557A528220B /* Assembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Assembly.swift; sourceTree = ""; }; + F2E291E30E191A1E202A013A /* ScopedBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopedBinding.swift; sourceTree = ""; }; F446D6BD4C44E16A1D608BFB /* Container+TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+TypeForwarding.swift"; sourceTree = ""; }; F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.TypeForwarding.swift; sourceTree = ""; }; - FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+LegacyApi.swifttemplate"; sourceTree = ""; }; + FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */ = {isa = PBXFileReference; path = "Resolver+LegacyApi.swifttemplate"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -618,12 +628,12 @@ CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */, C3C516EFA0CA22D19F07B27E /* InjectionVariation.swift */, 808C1063CA90CC593C7E0E9C /* MatchableBoxes.swifttemplate */, + 176824B29DD1A0DAA5CBD241 /* Resolver+FunctionCallApi.swifttemplate */, 01DEC4D20CE554C9DFBD0A8D /* Resolver+Injection.swifttemplate */, FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */, BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */, 90191C25A2D66E07C4E9CD73 /* SwiftCode.swifttemplate */, 1A006CC804F9AB8ACC121029 /* Utils.swift */, - CDE303E022F6DF7500846EFA /* Resolver+FunctionCallApi.swifttemplate */, ); path = Templates; sourceTree = ""; @@ -640,10 +650,10 @@ 1F06930A1A2C8BA94D6875BA /* Legacy */ = { isa = PBXGroup; children = ( - 1E612D299FB31D27FF9BDCE6 /* Circularity.swift */, 4BC5108ED11A3A3084D864CC /* Animal.swift */, 62682D6ED38742996624B041 /* BasicAssembly.swift */, 5EA566CD336DB8343ADFAF9B /* BehaviorFakes.swift */, + 96AEC72A42A227A50CF9845B /* Circularity.swift */, 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */, ADA1541ABC1365DFD7E3377F /* Food.swift */, 61EE5DDBE705B47AFC9A6986 /* LoadAwareAssembly.swift */, @@ -665,11 +675,17 @@ isa = PBXGroup; children = ( B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */, + A367B4D6F7E5331620430ECF /* BindingBuilder.swift */, + 419FB96A1F4B72278B9A6665 /* InstanceBuilder.swift */, + 0E7DC2C5AA87B18BD465EB77 /* Opaque.swift */, + B9F626B9D3E547621787E4D7 /* Resolver+FunctionCall.swift */, 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */, - CDE303DB22F6DDA900846EFA /* Resolver+FunctionCall.swift */, + F2E291E30E191A1E202A013A /* ScopedBinding.swift */, + D7D394F381E60F6E6E92E7DB /* SimpleBinding.swift */, 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */, B92B8E618A08408404FB2A7A /* TypeBinder.swift */, - CDE303FA22F70A2500846EFA /* Weak.swift */, + 667B13B528642272FC0794B6 /* UnboundScope.swift */, + 57A7E35B2B22650208F904B8 /* Weak.swift */, ); path = "3.0 API"; sourceTree = ""; @@ -759,16 +775,16 @@ isa = PBXGroup; children = ( 6E59A67F3548663368788B17 /* BindingSpec.swift */, + 118ABC654C4144496848AD74 /* CIrcularitySpec.swift */, DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */, 670DB253ECD5CE1468A7F2E3 /* InjectionSpec.swift */, 75BE3AE3E30DFE42A919D825 /* ModulesSpec.swift */, 50D6F2639990DD5BAD9578B0 /* OptionalsSpec.swift */, + 86C18DDD83715886DF7F1818 /* OverrideSpec.swift */, + 49B24254B9F0E48ED3713565 /* PropertyWrappersSpec.swift */, 0D8B3342E2AC3236F12072F5 /* RetrievalSpec.swift */, 1D3C59E84B5FD0C13F487838 /* ScopesSpec.swift */, 46F05CC591903E2B04B6D8ED /* SingletonSpec.swift */, - CD03917322EF610800DE44C4 /* OverrideSpec.swift */, - CD68676422F5CA5D00F7D9E3 /* PropertyWrappersSpec.swift */, - CDE303F122F7008600846EFA /* CIrcularitySpec.swift */, ); path = "3.0 API"; sourceTree = ""; @@ -847,24 +863,20 @@ children = ( 0E0B580B43E1891812C97209 /* Binding.swift */, 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */, - ED41A352529A5B2950F39D8F /* InstanceBuilder.swift */, - E0874A043EAEE3C7CF1EA063 /* InjectionRequest.swift */, + 57F4D977AC4289A6145383C9 /* InjectionRequest.swift */, 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */, - C68B98C653ABDED9C3D17DB3 /* Opaque.swift */, + 424C647FF08FCB7C2A54E085 /* PropertyWrapper.swift */, 73B4B777290FF5D38A8914CC /* Reference.swift */, A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */, 5057BAB33984E3E33469452B /* Scope.swift */, - A10187BB3A994165E7FC1528 /* ScopedBinding.swift */, 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */, 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */, - C074BAC560F277E806146C60 /* SimpleBinding.swift */, 9620155728133F451B31C0AD /* Swinject.swift */, + 8C4916168E81D76536892122 /* SwinjectContainer.swift */, A3586A4987B7C7C8122D674E /* SwinjectError.swift */, C1E726A651C3AFE92C19608B /* SwinjectModule.swift */, - CD367C0D22EF8A83008B3E82 /* SwinjectContainer.swift */, 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */, E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */, - CD68675F22F5C60800F7D9E3 /* PropertyWrapper.swift */, ); path = Core; sourceTree = ""; @@ -1150,9 +1162,9 @@ buildActionMask = 2147483647; files = ( BEFFC7B36FE5810169C81B97 /* BinderEnvironment.swifttemplate in Resources */, - CDE303E122F6DF7500846EFA /* Resolver+FunctionCallApi.swifttemplate in Resources */, BFE22F9F2E88F177302E9D19 /* Container+Registration.swifttemplate in Resources */, 1C82BFD00FCC384DB3AE6A89 /* MatchableBoxes.swifttemplate in Resources */, + 3EC8383BEAC339595CF7F927 /* Resolver+FunctionCallApi.swifttemplate in Resources */, 71895EBC0803EEE3BFCD7001 /* Resolver+Injection.swifttemplate in Resources */, F568382FB877060127790413 /* Resolver+LegacyApi.swifttemplate in Resources */, B7653A6427A5E284E9A1D6D3 /* ServiceEntry+TypeForwarding.swifttemplate in Resources */, @@ -1409,39 +1421,41 @@ 703F8B3AD111A6CFAFF66A49 /* Behavior.swift in Sources */, ADCF273AF041E74DBEC2C13A /* BinderEnvironment.swift in Sources */, 658AEDC8D802A6788E959E0C /* Binding.swift in Sources */, + B0B65F494A88CDEFE8EF79F6 /* BindingBuilder.swift in Sources */, 694C2C891D581371B2B051D7 /* Container+Logging.swift in Sources */, AAD8D0551B8A26A9B22AECEC /* Container+Registration.swift in Sources */, 996CCFE825834C7D3236E742 /* Container+TypeForwarding.swift in Sources */, B2FAD41F7726502822AF913B /* Container.swift in Sources */, - CDE303DD22F6DDA900846EFA /* Resolver+FunctionCall.swift in Sources */, - CD68676122F5C85B00F7D9E3 /* PropertyWrapper.swift in Sources */, 8B5927517B567B1DFAB5B935 /* ContextTranslator.swift in Sources */, - 6C4D29A3FB54416D5E4D4C89 /* InstanceBuilder.swift in Sources */, - 53EBF7A46EF65F2A8DAADC7A /* InjectionRequest.swift in Sources */, + 1D17DBC27F25717BF7A87AF3 /* InjectionRequest.swift in Sources */, + 36D0B5EFA3B4AB4D464C9260 /* InstanceBuilder.swift in Sources */, A91EDAFBC3606EDFBD739899 /* InstanceWrapper.swift in Sources */, 98322F9371E1A8461BC614D1 /* Matchable.swift in Sources */, 3753FB83A1FB4B83891AA5C8 /* ObjectScope.swift in Sources */, - 31392A9EF619329716144F95 /* Opaque.swift in Sources */, + 7A956FAB419F74D7EB9CAD0B /* Opaque.swift in Sources */, + 5393E5DE21B568A88498E454 /* PropertyWrapper.swift in Sources */, 3BD6055555A5C30DABDC8ED2 /* Reference.swift in Sources */, + A9112F7CF871475B94A077D7 /* Resolver+FunctionCall.swift in Sources */, D9084C826F7A798508CD66F5 /* Resolver+Injection.swift in Sources */, D4936DC1A47A8C85325FB52E /* Resolver+LegacyApi.swift in Sources */, 8016512839FE61EC3127E489 /* Resolver.swift in Sources */, 68C95FCB0D345CA3BA24D320 /* Scope.swift in Sources */, BB571B9A78FC53231A18E18C /* ScopeRegistry.swift in Sources */, 593B93BA2EE3FE4418A1C579 /* ScopeRegistryKey.swift in Sources */, - CDE303FC22F70A2500846EFA /* Weak.swift in Sources */, - C3FDE105B08336F26CC95BAA /* ScopedBinding.swift in Sources */, + 69EE97FE7F5AF3A227E7FE22 /* ScopedBinding.swift in Sources */, AD3E7135985F1046E35C39DE /* ServiceEntry+TypeForwarding.swift in Sources */, 93BCD12CEFB88BAD49BEA431 /* ServiceEntry.swift in Sources */, - 7295E928A18E6055CF796840 /* SimpleBinding.swift in Sources */, + 976E692202CF33EEE4C3A997 /* SimpleBinding.swift in Sources */, B9550BE2BA6FA5731BEC87FD /* Swinject+Builder.swift in Sources */, 33391EBA040E82DFB0A37015 /* Swinject.swift in Sources */, + 3328937B7BBFA77FA3CD303E /* SwinjectContainer.swift in Sources */, 020DA1718FCC68D889FB5A5F /* SwinjectError.swift in Sources */, - CD367C0F22EF8A83008B3E82 /* SwinjectContainer.swift in Sources */, CF4EBB60C21F8C503BCD7A29 /* SwinjectModule.swift in Sources */, 0D5C4A278A16AB3A163148AF /* SwinjectTree.swift in Sources */, AB864E029E996492ED4A3A52 /* TypeBinder.swift in Sources */, 49685AB40BEE856C62005C87 /* TypeDescriptor.swift in Sources */, + 5BD767B85CFE5FADDFE0A7B5 /* UnboundScope.swift in Sources */, + F88700BAAFFB47B1BD4D3BFA /* Weak.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1459,40 +1473,40 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - CD68676522F5CA5D00F7D9E3 /* PropertyWrappersSpec.swift in Sources */, BD08D3E155AFD841CFECA0AD /* Animal.swift in Sources */, - CD73B9AF22F239A4004BB84E /* ContainerSpec.Circularity.swift in Sources */, + 02410BD4FB357F4C6B521608 /* AssemblerSpec.swift in Sources */, DD29D2E60DA979D61F32A39A /* BasicAssembly.swift in Sources */, - CD73B9AE22F239A4004BB84E /* ContainerSpec.Behavior.swift in Sources */, 3129A37CDC1653C11800E24A /* BehaviorFakes.swift in Sources */, 9A2A6978519F2BBA97DA6EA6 /* BindingSpec.swift in Sources */, - CD73B9B122F239A4004BB84E /* ContainerSpec.swift in Sources */, - CD73B9AC22F239A4004BB84E /* Circularity.swift in Sources */, - CD73B9B022F239A4004BB84E /* ContainerSpec.CustomStringConvertible.swift in Sources */, - CD03917422EF610800DE44C4 /* OverrideSpec.swift in Sources */, 89E2997CB8B90368A15A91CE /* Bridge.swift in Sources */, + E39152E9059357CF0C9B21AF /* CIrcularitySpec.swift in Sources */, + BB64AE6DFE526629918211B7 /* Circularity.swift in Sources */, + 68D828A3C583DDD28CFE882B /* ContainerSpec.Arguments.swift in Sources */, + D69ED6990417ED1E921ACFCA /* ContainerSpec.Behavior.swift in Sources */, + 9A21ECA8F283E1E144CEC763 /* ContainerSpec.Circularity.swift in Sources */, + B3062AB22373AD23052B61DF /* ContainerSpec.CustomStringConvertible.swift in Sources */, + A1A2D0FA98038EACAC04E64C /* ContainerSpec.TypeForwarding.swift in Sources */, + C1687ACA897DEFD3A8197CCD /* ContainerSpec.swift in Sources */, 832C9ABB8DCF5340D796F5F8 /* ContextSpec.swift in Sources */, - CD73B9AB22F239A4004BB84E /* AssemblerSpec.swift in Sources */, EE35DF2D353E2C5110DA5C42 /* Convenience.swift in Sources */, 934AFACA6BFF24AD3503F98D /* EmploymentAssembly.swift in Sources */, 180DB4397B4C05E26F819C85 /* Food.swift in Sources */, 818DF17D671EA1022CE59A2A /* InjectionSpec.swift in Sources */, + AE6EAB8CC32ED5E1789D55B7 /* LazySpec.swift in Sources */, A834D948AB86794CA3304B98 /* LinuxConfig.swift in Sources */, B0B139FADA6AE07C79847EBA /* LoadAwareAssembly.swift in Sources */, F1F3BA81462E2362374BD4C4 /* ModulesSpec.swift in Sources */, - CD73B9B322F239A4004BB84E /* LazySpec.swift in Sources */, 72F09FC92FFB0F7C32D8E2A5 /* OptionalsSpec.swift in Sources */, + 751F545653B0F1E30341C312 /* OverrideSpec.swift in Sources */, 628EBFBA0031B1FA2E29F583 /* Person.swift in Sources */, - CD73B9AD22F239A4004BB84E /* ContainerSpec.Arguments.swift in Sources */, + 45F1654C204C7A2C87397BCD /* PropertyWrappersSpec.swift in Sources */, + 708E1C453CBC76ED26FA2FCB /* ProviderSpec.swift in Sources */, E227D08034E08AA0909BC043 /* RetrievalSpec.swift in Sources */, - CD73B9B422F239A4004BB84E /* ProviderSpec.swift in Sources */, - CD73B9B522F239A4004BB84E /* SynchronizedResolverSpec.swift in Sources */, - CDE303F622F7009B00846EFA /* CIrcularitySpec.swift in Sources */, - CD73B9B222F239A4004BB84E /* ContainerSpec.TypeForwarding.swift in Sources */, 33B86F2D33219879731CDDF0 /* ScopesSpec.swift in Sources */, 30D247E8083858C233B92908 /* SingletonSpec.swift in Sources */, 72217E47D83C3CA6D97640B9 /* StandardScopeRegistrySpec.swift in Sources */, 640F7A55D9A671FA112C8083 /* SwinjectTreeBuilderSpec.swift in Sources */, + F7CD04FB09FC7F18E9E001CF /* SynchronizedResolverSpec.swift in Sources */, 778D9AB6470D4280254AC140 /* TestModels.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1501,40 +1515,40 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - CD68676622F5CA5D00F7D9E3 /* PropertyWrappersSpec.swift in Sources */, A6EECC339FA54CA0BBFF4146 /* Animal.swift in Sources */, - CD73B9C522F239A5004BB84E /* ContainerSpec.Circularity.swift in Sources */, + CBBE28990E0EA82AD8D5E3AF /* AssemblerSpec.swift in Sources */, 401592294E5D528379BE1AB2 /* BasicAssembly.swift in Sources */, - CD73B9C422F239A5004BB84E /* ContainerSpec.Behavior.swift in Sources */, A3BFFED76688F149FBAF7C53 /* BehaviorFakes.swift in Sources */, BB77A5D81C58392964D07233 /* BindingSpec.swift in Sources */, - CD73B9C722F239A5004BB84E /* ContainerSpec.swift in Sources */, - CD73B9C222F239A5004BB84E /* Circularity.swift in Sources */, - CD73B9C622F239A5004BB84E /* ContainerSpec.CustomStringConvertible.swift in Sources */, - CD03917522EF610800DE44C4 /* OverrideSpec.swift in Sources */, 13CDEC7A6C8E43B58D5CBE3D /* Bridge.swift in Sources */, + 39AE6864444BC1CE491142E5 /* CIrcularitySpec.swift in Sources */, + CDE8EA7EC1D8096F12BDD8C2 /* Circularity.swift in Sources */, + 83464EDC08380F5CE2190F30 /* ContainerSpec.Arguments.swift in Sources */, + F8EB47A631D482A0D7B621DE /* ContainerSpec.Behavior.swift in Sources */, + E5880DBBB91CC5F8F47FBF73 /* ContainerSpec.Circularity.swift in Sources */, + 2B506344F37CE5F5C5C02C05 /* ContainerSpec.CustomStringConvertible.swift in Sources */, + E01D0D443FBA4DB82A6EC298 /* ContainerSpec.TypeForwarding.swift in Sources */, + A9A242086D1EDE408DC556D0 /* ContainerSpec.swift in Sources */, 1C62135FAE3D64DC7BFBF861 /* ContextSpec.swift in Sources */, - CD73B9C122F239A5004BB84E /* AssemblerSpec.swift in Sources */, A882705E4199EF759E80B311 /* Convenience.swift in Sources */, 19416C867F15E88394A0ABD1 /* EmploymentAssembly.swift in Sources */, 590B861A863A056A0B7FA368 /* Food.swift in Sources */, 95A6654089875BCC863FB53B /* InjectionSpec.swift in Sources */, + 979518E078B187549E11DF48 /* LazySpec.swift in Sources */, B96A6370D549AAC383360ABC /* LinuxConfig.swift in Sources */, 335CE53CEC2360DC86D58F07 /* LoadAwareAssembly.swift in Sources */, 004B06007E4FDD8F44B7EC89 /* ModulesSpec.swift in Sources */, - CD73B9C922F239A5004BB84E /* LazySpec.swift in Sources */, D941D81F59900A52805D6B4A /* OptionalsSpec.swift in Sources */, + 18AAA07DCD6FAB4A7D7E8B76 /* OverrideSpec.swift in Sources */, EB3420214A9E68A0247D0F2C /* Person.swift in Sources */, - CD73B9C322F239A5004BB84E /* ContainerSpec.Arguments.swift in Sources */, + 9AA68475ABE3E7502F59216D /* PropertyWrappersSpec.swift in Sources */, + CF9535A0DCAFF23F4D62F871 /* ProviderSpec.swift in Sources */, 1A68A8D05D9974002BF34CF8 /* RetrievalSpec.swift in Sources */, - CD73B9CA22F239A5004BB84E /* ProviderSpec.swift in Sources */, - CD73B9CB22F239A5004BB84E /* SynchronizedResolverSpec.swift in Sources */, - CDE303F722F7009B00846EFA /* CIrcularitySpec.swift in Sources */, - CD73B9C822F239A5004BB84E /* ContainerSpec.TypeForwarding.swift in Sources */, 0068DAA4AA322F00AF53731F /* ScopesSpec.swift in Sources */, B65DE0B0562540CC8CEC48F3 /* SingletonSpec.swift in Sources */, C952D5869D87743297968E9A /* StandardScopeRegistrySpec.swift in Sources */, A308578B99D33C7E33632E85 /* SwinjectTreeBuilderSpec.swift in Sources */, + 3BDB44DE92D2377334894804 /* SynchronizedResolverSpec.swift in Sources */, 2615FC1C92B7E381116B9E57 /* TestModels.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1543,40 +1557,40 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - CD68676822F5CA5D00F7D9E3 /* PropertyWrappersSpec.swift in Sources */, A53B5A8E2188F8C4A3F29C2E /* Animal.swift in Sources */, - CD73B9D022F239A6004BB84E /* ContainerSpec.Circularity.swift in Sources */, + CF4516872D3DA7118DB2B90B /* AssemblerSpec.swift in Sources */, 03122D1B2EA65C89ADC78EC7 /* BasicAssembly.swift in Sources */, - CD73B9CF22F239A6004BB84E /* ContainerSpec.Behavior.swift in Sources */, 1CA5DF3F93203B226A6FA059 /* BehaviorFakes.swift in Sources */, CAA5241DAA201FBB5818C803 /* BindingSpec.swift in Sources */, - CD73B9D222F239A6004BB84E /* ContainerSpec.swift in Sources */, - CD73B9CD22F239A6004BB84E /* Circularity.swift in Sources */, - CD73B9D122F239A6004BB84E /* ContainerSpec.CustomStringConvertible.swift in Sources */, - CD03917722EF610800DE44C4 /* OverrideSpec.swift in Sources */, E4CE31B7B9616EFC93C69341 /* Bridge.swift in Sources */, + ACA8E10AADBFC063A6F345D7 /* CIrcularitySpec.swift in Sources */, + D3FD513CDD70AF674C453B83 /* Circularity.swift in Sources */, + 8436D091ED844817C8CE3AF2 /* ContainerSpec.Arguments.swift in Sources */, + 829853126CDB7464599AFC85 /* ContainerSpec.Behavior.swift in Sources */, + C950785B81C6DB22F41FA3CE /* ContainerSpec.Circularity.swift in Sources */, + 7D6F664091C70BABBFB61D53 /* ContainerSpec.CustomStringConvertible.swift in Sources */, + 196338EA802A39E205C33B43 /* ContainerSpec.TypeForwarding.swift in Sources */, + F270DC6FF3901F58C76F3872 /* ContainerSpec.swift in Sources */, 49D71F6CC12C12FE7B6A097A /* ContextSpec.swift in Sources */, - CD73B9CC22F239A6004BB84E /* AssemblerSpec.swift in Sources */, EEAD7E215908DF939ECCDCC9 /* Convenience.swift in Sources */, 4E4DC8CDD1BA51FB66A332C2 /* EmploymentAssembly.swift in Sources */, BE6C13A3492E3CFC08E231B0 /* Food.swift in Sources */, 42FE916C1593A9289E1A28BC /* InjectionSpec.swift in Sources */, + 6A0FD11468B3852E48B682BE /* LazySpec.swift in Sources */, B00627BABCF9181C7B58609E /* LinuxConfig.swift in Sources */, ED6CB3935B15F30A182ED6D0 /* LoadAwareAssembly.swift in Sources */, D9F132E4A6F6BC2BDD5DFCAA /* ModulesSpec.swift in Sources */, - CD73B9D422F239A6004BB84E /* LazySpec.swift in Sources */, A453A5A7E0EC0FE161AA34D5 /* OptionalsSpec.swift in Sources */, + C22853F014054A6DCDF0CB6A /* OverrideSpec.swift in Sources */, C76374CAFE7C2BCCE52F1BB1 /* Person.swift in Sources */, - CD73B9CE22F239A6004BB84E /* ContainerSpec.Arguments.swift in Sources */, + D7915D8FCF67D0FFCC41E9D6 /* PropertyWrappersSpec.swift in Sources */, + 4954CBB07E38E98752AC3347 /* ProviderSpec.swift in Sources */, 2F664F8534CA1D92ED2F81E2 /* RetrievalSpec.swift in Sources */, - CD73B9D522F239A6004BB84E /* ProviderSpec.swift in Sources */, - CD73B9D622F239A6004BB84E /* SynchronizedResolverSpec.swift in Sources */, - CDE303F922F7009C00846EFA /* CIrcularitySpec.swift in Sources */, - CD73B9D322F239A6004BB84E /* ContainerSpec.TypeForwarding.swift in Sources */, 31729A1E5F50EF30FDD427AD /* ScopesSpec.swift in Sources */, 0CE158916595980A7C8272D3 /* SingletonSpec.swift in Sources */, 0720BEA814AD514378380ACB /* StandardScopeRegistrySpec.swift in Sources */, 3CEF021295AD9AF9BF26B71E /* SwinjectTreeBuilderSpec.swift in Sources */, + 546FF827DB6D42490D1CA439 /* SynchronizedResolverSpec.swift in Sources */, CB9E8D16D7A0620A1F7A32A3 /* TestModels.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1585,40 +1599,40 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - CD68676722F5CA5D00F7D9E3 /* PropertyWrappersSpec.swift in Sources */, D13208E63523A97A0B840283 /* Animal.swift in Sources */, - CD73B9BA22F239A4004BB84E /* ContainerSpec.Circularity.swift in Sources */, + 2AA60B7E6EBA9EC6BE92D7CB /* AssemblerSpec.swift in Sources */, 599C7F009F954CDA522244B3 /* BasicAssembly.swift in Sources */, - CD73B9B922F239A4004BB84E /* ContainerSpec.Behavior.swift in Sources */, 8E1E051646BBD6E38F4199C2 /* BehaviorFakes.swift in Sources */, 0207493E1CEE8456E91E3DAE /* BindingSpec.swift in Sources */, - CD73B9BC22F239A4004BB84E /* ContainerSpec.swift in Sources */, - CD73B9B722F239A4004BB84E /* Circularity.swift in Sources */, - CD73B9BB22F239A4004BB84E /* ContainerSpec.CustomStringConvertible.swift in Sources */, - CD03917622EF610800DE44C4 /* OverrideSpec.swift in Sources */, 43A74237D8933572BAA0F3B4 /* Bridge.swift in Sources */, + 6DD80811E5FD658CAFEEA647 /* CIrcularitySpec.swift in Sources */, + 90C399A2AF93F0897169E413 /* Circularity.swift in Sources */, + A70936B898139A6C5F83F616 /* ContainerSpec.Arguments.swift in Sources */, + A7DD08A60F12EC078BBE086F /* ContainerSpec.Behavior.swift in Sources */, + EB79ECF5C893F63B22355167 /* ContainerSpec.Circularity.swift in Sources */, + 54956014A1774DF8357B69E6 /* ContainerSpec.CustomStringConvertible.swift in Sources */, + 3C270A77DE4F1E6BC2F8E863 /* ContainerSpec.TypeForwarding.swift in Sources */, + CA5523B60E51EB98719CF1F8 /* ContainerSpec.swift in Sources */, 86CBC40FDC90E2A2051386C5 /* ContextSpec.swift in Sources */, - CD73B9B622F239A4004BB84E /* AssemblerSpec.swift in Sources */, 48D1568CB41BE4B6597FD535 /* Convenience.swift in Sources */, A59C6C434288333EDAF951C4 /* EmploymentAssembly.swift in Sources */, C38A2EBF4D1904E7D6989989 /* Food.swift in Sources */, AD214F3DBAB4F16C88322CAC /* InjectionSpec.swift in Sources */, + 0CD787EACEBFD1051D358E7D /* LazySpec.swift in Sources */, 70368EC369287B4EE767E929 /* LinuxConfig.swift in Sources */, A2D3B18BE38948A427B60BC5 /* LoadAwareAssembly.swift in Sources */, 55F2E72EA8C3564130F66946 /* ModulesSpec.swift in Sources */, - CD73B9BE22F239A4004BB84E /* LazySpec.swift in Sources */, F6EEF5F7B57DC0E44EF569A4 /* OptionalsSpec.swift in Sources */, + 708D400457552769A54A406B /* OverrideSpec.swift in Sources */, BEEFBE87EB17D56BA8D47358 /* Person.swift in Sources */, - CD73B9B822F239A4004BB84E /* ContainerSpec.Arguments.swift in Sources */, + AAC6F2F5EC2928943BF2BED1 /* PropertyWrappersSpec.swift in Sources */, + 48F40377D116C6B1B786C329 /* ProviderSpec.swift in Sources */, 06CD85528AABB15BDFBF3166 /* RetrievalSpec.swift in Sources */, - CD73B9BF22F239A4004BB84E /* ProviderSpec.swift in Sources */, - CD73B9C022F239A4004BB84E /* SynchronizedResolverSpec.swift in Sources */, - CDE303F822F7009C00846EFA /* CIrcularitySpec.swift in Sources */, - CD73B9BD22F239A4004BB84E /* ContainerSpec.TypeForwarding.swift in Sources */, EA0D19F7DF0355C774B0F40B /* ScopesSpec.swift in Sources */, 980FED1DBC62B65597E2828B /* SingletonSpec.swift in Sources */, 0B61DC733616A8ED4ED77FA7 /* StandardScopeRegistrySpec.swift in Sources */, 233F3E25FF0B51A3E6611F58 /* SwinjectTreeBuilderSpec.swift in Sources */, + 890CCD2800597F6FB7C6FD31 /* SynchronizedResolverSpec.swift in Sources */, 6034CF5459D96497AF36E4B6 /* TestModels.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1632,39 +1646,41 @@ FA805A162E989A22990B99AA /* Behavior.swift in Sources */, 6FCCBA9D2E4C2A225CB1A152 /* BinderEnvironment.swift in Sources */, F9A4BF18B0085B7DCD3440EC /* Binding.swift in Sources */, + 6CFE30E5595611778893D147 /* BindingBuilder.swift in Sources */, 6A03ABEED82EF31E8E6E297E /* Container+Logging.swift in Sources */, A5E4C79F89E1A8AB3A4D8D6E /* Container+Registration.swift in Sources */, BD9B57E26722C80B7EF990DB /* Container+TypeForwarding.swift in Sources */, DB74F17CDFF4886B9C38AD14 /* Container.swift in Sources */, - CDE303DE22F6DDA900846EFA /* Resolver+FunctionCall.swift in Sources */, - CD68676222F5C85B00F7D9E3 /* PropertyWrapper.swift in Sources */, DD5E3AF2B5FCE5E81EBDF606 /* ContextTranslator.swift in Sources */, - 7F9686F3669BF35E5AC970B3 /* InstanceBuilder.swift in Sources */, - 9DEAC620F2F00D0DDD3B5D3E /* InjectionRequest.swift in Sources */, + 76FB9AFE299316E7F3F4C3BB /* InjectionRequest.swift in Sources */, + 157A967F9BAD0B8DAFAC2A36 /* InstanceBuilder.swift in Sources */, 57BFBA2077E70DC1C2FE796C /* InstanceWrapper.swift in Sources */, 293985649250DF270DC89135 /* Matchable.swift in Sources */, B4B66D7251BDDE25D6D7FB3C /* ObjectScope.swift in Sources */, - 1E1CAA4156D94E3A73AEA9F6 /* Opaque.swift in Sources */, + 5365FDFB2DDA6491F3049654 /* Opaque.swift in Sources */, + 6A967AE5710606998C2BE070 /* PropertyWrapper.swift in Sources */, B293894FEB67831DDA5F000E /* Reference.swift in Sources */, + 8A4E9E736239F92F878C070C /* Resolver+FunctionCall.swift in Sources */, 848227742D4ABA298D340485 /* Resolver+Injection.swift in Sources */, E177D354B1F410129D921C69 /* Resolver+LegacyApi.swift in Sources */, 5D7E26A00B055803A50CD9C2 /* Resolver.swift in Sources */, B84167AC8C6BEB57C4D0695A /* Scope.swift in Sources */, E7D1045D25FAB592401DCAF0 /* ScopeRegistry.swift in Sources */, 4347EE17D0C0ED574C899D85 /* ScopeRegistryKey.swift in Sources */, - CDE303FD22F70A2500846EFA /* Weak.swift in Sources */, - 8228FEB1DF3C41DEDCE0FB1D /* ScopedBinding.swift in Sources */, + B91523667CD2A31E889A4669 /* ScopedBinding.swift in Sources */, 5FCE2A2AE5DD0DBECA4A9953 /* ServiceEntry+TypeForwarding.swift in Sources */, D98BB7F59E98FC197D1C97A2 /* ServiceEntry.swift in Sources */, - 7D0683F36CE56228AC2CD489 /* SimpleBinding.swift in Sources */, + 5F49839A5C17677861F5971B /* SimpleBinding.swift in Sources */, EFD2F695B86E74C77F46B7D1 /* Swinject+Builder.swift in Sources */, 63528D45A548DD58D748D54C /* Swinject.swift in Sources */, + C8462BEE06316286B9CA85AC /* SwinjectContainer.swift in Sources */, 91E435894038C42335086FA8 /* SwinjectError.swift in Sources */, - CD367C1022EF8A83008B3E82 /* SwinjectContainer.swift in Sources */, C637E97E193BB1DADDDC6C21 /* SwinjectModule.swift in Sources */, 0CE1126436F680F9684837E4 /* SwinjectTree.swift in Sources */, 4B9811CF0604946CCF323ED2 /* TypeBinder.swift in Sources */, 9CEE20BD42795D5E5F39BF20 /* TypeDescriptor.swift in Sources */, + 8B711CBE6A5B86DC2D6CABDC /* UnboundScope.swift in Sources */, + FC339851D7EEE4D17178CC1F /* Weak.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1677,39 +1693,41 @@ 2CB057F2A16DA462E0517AAB /* Behavior.swift in Sources */, 2DD6F290740EA69B3E73E0EA /* BinderEnvironment.swift in Sources */, D2BAE1CB997A4D052CB8EFC8 /* Binding.swift in Sources */, + FD8BB4CC8DA0E560E39FA491 /* BindingBuilder.swift in Sources */, 1ED6BD68D92F4FE60978EF22 /* Container+Logging.swift in Sources */, CB0B308F3D3A831A28127462 /* Container+Registration.swift in Sources */, 283C77045DA55C2134EC9C48 /* Container+TypeForwarding.swift in Sources */, 58ABEE0321A3061048B65EA2 /* Container.swift in Sources */, - CDE303DF22F6DDA900846EFA /* Resolver+FunctionCall.swift in Sources */, - CD68676322F5C85B00F7D9E3 /* PropertyWrapper.swift in Sources */, F06DEB671A4B85ABB0E96E51 /* ContextTranslator.swift in Sources */, - DBEFC5C6A51FCEBF9E4F70EE /* InstanceBuilder.swift in Sources */, - CECF5BD14BCDF5248771A06A /* InjectionRequest.swift in Sources */, + 027015812E961322FE3D942B /* InjectionRequest.swift in Sources */, + C6E443EAD892B0B69DA61144 /* InstanceBuilder.swift in Sources */, 389C54E04DD794DA4F648571 /* InstanceWrapper.swift in Sources */, 87FEAEF562B99522083CB87D /* Matchable.swift in Sources */, 6DA49F84E2592B32F81F268B /* ObjectScope.swift in Sources */, - 8BE1DA0A9876AB47BB76E2CD /* Opaque.swift in Sources */, + 6251955691663E4495DE310D /* Opaque.swift in Sources */, + 5F1647DCC0D437A782647372 /* PropertyWrapper.swift in Sources */, 2D020C6391A4F6A2118585B8 /* Reference.swift in Sources */, + 1AC00BCB4DB26B078203DAD8 /* Resolver+FunctionCall.swift in Sources */, C6D60E2AEC381998223145B2 /* Resolver+Injection.swift in Sources */, FD7B2663F2F931B78EB330EE /* Resolver+LegacyApi.swift in Sources */, 97C2EA47D7623AFD723AFE93 /* Resolver.swift in Sources */, 2C352AAD1AC7D82A4A059046 /* Scope.swift in Sources */, 02556F149C9AAEF5CE353AC1 /* ScopeRegistry.swift in Sources */, 06F4CAB352B4F623FF7BD885 /* ScopeRegistryKey.swift in Sources */, - CDE303FE22F70A2500846EFA /* Weak.swift in Sources */, - A193BF10196FBDE32833E292 /* ScopedBinding.swift in Sources */, + 7C745281CA1627BCC8A8A92A /* ScopedBinding.swift in Sources */, A75BAA10EC6F738EBC2C5BE8 /* ServiceEntry+TypeForwarding.swift in Sources */, 59FD1167CD4A913E04D3EAFD /* ServiceEntry.swift in Sources */, - 9C15BE01C1EA41061CDB7918 /* SimpleBinding.swift in Sources */, + EE3063E3D1582D3BB7CC43F0 /* SimpleBinding.swift in Sources */, DCB7C4BF24782862BE9DB135 /* Swinject+Builder.swift in Sources */, 75D74C8C25EDACF5A7A75A5C /* Swinject.swift in Sources */, + 4D86550CC5C281A58B4A6F61 /* SwinjectContainer.swift in Sources */, 4DF3DC1CDD3C4948F9BDD3DF /* SwinjectError.swift in Sources */, - CD367C1122EF8A83008B3E82 /* SwinjectContainer.swift in Sources */, 82299769BC637A14E7827DB0 /* SwinjectModule.swift in Sources */, 372F0061E762BF8FFF05457F /* SwinjectTree.swift in Sources */, 9425887520AC2DBDCBACB252 /* TypeBinder.swift in Sources */, AC470B4322599B0A076DD3FF /* TypeDescriptor.swift in Sources */, + D669A1E2657CC868027395D9 /* UnboundScope.swift in Sources */, + 95E6DD9D94BE64420EEC1298 /* Weak.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1722,39 +1740,41 @@ F7979BE4BE1B1C7101D15E61 /* Behavior.swift in Sources */, B5FF5DFE394B6B1BB930D88D /* BinderEnvironment.swift in Sources */, 3F8F5645D6D37FCEC1D89393 /* Binding.swift in Sources */, + 2A6D2874ADB24B08DAE1EC04 /* BindingBuilder.swift in Sources */, 999AF7221D3F2E1F83C3ACB1 /* Container+Logging.swift in Sources */, 21285CED416F1317E993397A /* Container+Registration.swift in Sources */, 3A0B409E840B44B281DB3C54 /* Container+TypeForwarding.swift in Sources */, 0622539110A7430776A307C7 /* Container.swift in Sources */, - CDE303DC22F6DDA900846EFA /* Resolver+FunctionCall.swift in Sources */, D1DF4740A9D86362B63104B8 /* ContextTranslator.swift in Sources */, - B90EA5A6764CEFA2BCB6C4D9 /* InstanceBuilder.swift in Sources */, - 128913D570B4A8BBF40866BE /* InjectionRequest.swift in Sources */, + 826D63FA91E370F0061768B0 /* InjectionRequest.swift in Sources */, + 16393BD60FDDD38B5A977C55 /* InstanceBuilder.swift in Sources */, 98ACB1A09194572A946CA90D /* InstanceWrapper.swift in Sources */, 5ED8A7D19F21FA686215F72C /* Matchable.swift in Sources */, B42331BF00B482369B908BB8 /* ObjectScope.swift in Sources */, - 658C98B4AA17C58E8556E0AC /* Opaque.swift in Sources */, + EB73B06547A273D2534528E3 /* Opaque.swift in Sources */, + 14C8DA4FCCDFA87885038D38 /* PropertyWrapper.swift in Sources */, 0509EE8D41BF354EB91ACC80 /* Reference.swift in Sources */, + 5A78C354D420D64CF8A787C1 /* Resolver+FunctionCall.swift in Sources */, CBE63031F33303F3E503CEF2 /* Resolver+Injection.swift in Sources */, - CD68676022F5C60800F7D9E3 /* PropertyWrapper.swift in Sources */, 41C7340BFD2EB66359772733 /* Resolver+LegacyApi.swift in Sources */, BE94EF7BCF976A703F961389 /* Resolver.swift in Sources */, 96EA0A5DF33F025EBE0B67D2 /* Scope.swift in Sources */, D861595482464ED95CF81922 /* ScopeRegistry.swift in Sources */, 920DE2CAB9895D10FAE48FBA /* ScopeRegistryKey.swift in Sources */, - CDE303FB22F70A2500846EFA /* Weak.swift in Sources */, - E1B95D3EEA5BB989CCFFE70D /* ScopedBinding.swift in Sources */, + 85CBEFBB558636EAC76E5F0C /* ScopedBinding.swift in Sources */, CEE763218A90832454A6E2DE /* ServiceEntry+TypeForwarding.swift in Sources */, 36A706F87ED2E88F3390C6C2 /* ServiceEntry.swift in Sources */, - 5BF9899C59F4BFAA6440D04B /* SimpleBinding.swift in Sources */, + 19E02C4326FB05E0630B56E3 /* SimpleBinding.swift in Sources */, 6C01E868DE44BD396D94858B /* Swinject+Builder.swift in Sources */, 4EC94A51037C79DE0C5C8CB1 /* Swinject.swift in Sources */, + A6721BA534AD082E1E7C1D08 /* SwinjectContainer.swift in Sources */, 820307073A53AED47AC99B8D /* SwinjectError.swift in Sources */, - CD367C0E22EF8A83008B3E82 /* SwinjectContainer.swift in Sources */, 8E77B56EE7F90BF723600DDF /* SwinjectModule.swift in Sources */, 6922AE734E84B515C94D9480 /* SwinjectTree.swift in Sources */, EF79F0B3D497215D4BBBC038 /* TypeBinder.swift in Sources */, E3EABE098DBFB561A20632E3 /* TypeDescriptor.swift in Sources */, + 19F21849D1E173F5AC724281 /* UnboundScope.swift in Sources */, + 581B08428C6AACAFC8017F8A /* Weak.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1875,11 +1895,7 @@ "$(PROJECT_DIR)/Carthage/Build/iOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -1917,10 +1933,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; PRODUCT_NAME = Swinject; SDKROOT = macosx; SKIP_INSTALL = YES; @@ -1937,11 +1950,7 @@ "$(PROJECT_DIR)/Carthage/Build/tvOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = appletvos; TARGETED_DEVICE_FAMILY = 3; @@ -1959,10 +1968,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = Swinject; SDKROOT = appletvos; SKIP_INSTALL = YES; @@ -1980,11 +1986,7 @@ "$(PROJECT_DIR)/Carthage/Build/iOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -2001,11 +2003,7 @@ "$(PROJECT_DIR)/Carthage/Build/Mac", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - "@loader_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = macosx; }; @@ -2095,10 +2093,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = Swinject; SDKROOT = appletvos; SKIP_INSTALL = YES; @@ -2116,11 +2111,7 @@ "$(PROJECT_DIR)/Carthage/Build/watchOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = watchos; SKIP_INSTALL = YES; @@ -2139,10 +2130,7 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; SDKROOT = macosx; SKIP_INSTALL = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -2160,10 +2148,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = Swinject; SDKROOT = iphoneos; SKIP_INSTALL = YES; @@ -2181,11 +2166,7 @@ "$(PROJECT_DIR)/Carthage/Build/watchOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = watchos; SKIP_INSTALL = YES; @@ -2203,11 +2184,7 @@ "$(PROJECT_DIR)/Carthage/Build/Mac", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - "@loader_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = macosx; }; @@ -2222,11 +2199,7 @@ "$(PROJECT_DIR)/Carthage/Build/tvOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = SwinjectTests; SDKROOT = appletvos; TARGETED_DEVICE_FAMILY = 3; @@ -2244,10 +2217,7 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; SDKROOT = macosx; SKIP_INSTALL = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -2266,10 +2236,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; PRODUCT_NAME = Swinject; SDKROOT = macosx; SKIP_INSTALL = YES; @@ -2288,10 +2255,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = Swinject; SDKROOT = iphoneos; SKIP_INSTALL = YES; From 2fdac3c991f72ab6f9e5e2767de351e5ccf7e94b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Van=CC=8Co?= Date: Thu, 8 Aug 2019 04:13:00 +0200 Subject: [PATCH 202/239] Pass binding builder to the tree builder --- Sources/3.0 API/BindingBuilder.swift | 12 ++++++++++++ Sources/3.0 API/TypeBinder.swift | 12 ++++++------ Sources/Core/Binding.swift | 2 +- Sources/Core/SwinjectTree.swift | 2 +- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Sources/3.0 API/BindingBuilder.swift b/Sources/3.0 API/BindingBuilder.swift index 84936852..0bc59940 100644 --- a/Sources/3.0 API/BindingBuilder.swift +++ b/Sources/3.0 API/BindingBuilder.swift @@ -21,3 +21,15 @@ public extension BindingBuilder { return SomeBindingBuilder(anyActual: self) { self.makeBinding(with: $0) } } } + +public protocol AnyBindingBuilder: SwinjectEntry { + func makeBinding() -> Binding +} + +struct FinalBindingBuilder: AnyBindingBuilder { + let binidngFactory: () -> Binding + + func makeBinding() -> Binding { + return binidngFactory() + } +} diff --git a/Sources/3.0 API/TypeBinder.swift b/Sources/3.0 API/TypeBinder.swift index 81b54d43..a1047335 100644 --- a/Sources/3.0 API/TypeBinder.swift +++ b/Sources/3.0 API/TypeBinder.swift @@ -21,21 +21,21 @@ public func bind(_: Type.Type, tagged tag: String? = nil, overrides: Bool public extension TypeBinder { func with( _ builder: Builder - ) -> Binding where Builder: BindingBuilder, Builder.BoundType == BoundType { - return builder.makeBinding(with: properties) + ) -> AnyBindingBuilder where Builder: BindingBuilder, Builder.BoundType == BoundType { + return FinalBindingBuilder { builder.makeBinding(with: self.properties) } } - func with(_ value: BoundType) -> Binding { - return instance(value).makeBinding(with: properties) + func with(_ value: BoundType) -> AnyBindingBuilder { + return FinalBindingBuilder { instance(value).makeBinding(with: self.properties) } } } public func & ( lhs: TypeBinder, rhs: Builder -) -> Binding where Builder: BindingBuilder, Builder.BoundType == BoundType { +) -> AnyBindingBuilder where Builder: BindingBuilder, Builder.BoundType == BoundType { return lhs.with(rhs) } -public func & (lhs: TypeBinder, rhs: BoundType) -> Binding { +public func & (lhs: TypeBinder, rhs: BoundType) -> AnyBindingBuilder { return lhs.with(rhs) } diff --git a/Sources/Core/Binding.swift b/Sources/Core/Binding.swift index d070bc4a..e119827f 100644 --- a/Sources/Core/Binding.swift +++ b/Sources/Core/Binding.swift @@ -32,7 +32,7 @@ extension BindingKey { } } -public protocol Binding: SwinjectEntry { +public protocol Binding { var key: BindingKey { get } var properties: BindingProperties { get } func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any diff --git a/Sources/Core/SwinjectTree.swift b/Sources/Core/SwinjectTree.swift index 240f0961..2ea78bf7 100644 --- a/Sources/Core/SwinjectTree.swift +++ b/Sources/Core/SwinjectTree.swift @@ -40,7 +40,7 @@ extension SwinjectTreeBuilder { public static func buildFunction(_ input: [SwinjectEntry]) -> SwinjectTree { let entries = input.flatMap(unpack) return SwinjectTree( - bindings: entries.compactMap { $0 as? Binding }, + bindings: entries.compactMap { $0 as? AnyBindingBuilder }.map { $0.makeBinding() }, modules: entries.compactMap { $0 as? ModuleInclusion }, translators: entries.compactMap { $0 as? AnyContextTranslator } ) From a68e55dabcf8ce05db31e1ae5fff9c32d42c07a4 Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Sat, 24 Aug 2019 08:58:54 +0200 Subject: [PATCH 203/239] Mark segfault --- Swinject.xcodeproj/project.pbxproj | 108 +++++++++++++++++++++------- Tests/3.0 API/CIrcularitySpec.swift | 73 +++++++++---------- 2 files changed, 119 insertions(+), 62 deletions(-) diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 6c464a3f..dc347107 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -467,7 +467,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 01DEC4D20CE554C9DFBD0A8D /* Resolver+Injection.swifttemplate */ = {isa = PBXFileReference; path = "Resolver+Injection.swifttemplate"; sourceTree = ""; }; + 01DEC4D20CE554C9DFBD0A8D /* Resolver+Injection.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+Injection.swifttemplate"; sourceTree = ""; }; 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.swift; sourceTree = ""; }; 09FC792715B1658721F76885 /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 0CA449690AE00F6300DE8ACA /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -476,17 +476,17 @@ 0E0B580B43E1891812C97209 /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; 0E7DC2C5AA87B18BD465EB77 /* Opaque.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Opaque.swift; sourceTree = ""; }; 10480F2154EAA0414D4C1F55 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */ = {isa = PBXFileReference; path = .swiftlint.yml; sourceTree = ""; }; + 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */ = {isa = PBXFileReference; lastKnownFileType = text.yaml; path = .swiftlint.yml; sourceTree = ""; }; 118ABC654C4144496848AD74 /* CIrcularitySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CIrcularitySpec.swift; sourceTree = ""; }; 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SynchronizedResolverSpec.swift; sourceTree = ""; }; 13513FA012659ADE699A3608 /* LazySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LazySpec.swift; sourceTree = ""; }; - 176824B29DD1A0DAA5CBD241 /* Resolver+FunctionCallApi.swifttemplate */ = {isa = PBXFileReference; path = "Resolver+FunctionCallApi.swifttemplate"; sourceTree = ""; }; + 176824B29DD1A0DAA5CBD241 /* Resolver+FunctionCallApi.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+FunctionCallApi.swifttemplate"; sourceTree = ""; }; 1A006CC804F9AB8ACC121029 /* Utils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = ""; }; 1C58FC14EEA170B0DC079DE4 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; 1D3C59E84B5FD0C13F487838 /* ScopesSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopesSpec.swift; sourceTree = ""; }; 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Behavior.swift; sourceTree = ""; }; 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Arguments.swift; sourceTree = ""; }; - 26EEC28683E4A26B3092E8BA /* BinderEnvironment.swifttemplate */ = {isa = PBXFileReference; path = BinderEnvironment.swifttemplate; sourceTree = ""; }; + 26EEC28683E4A26B3092E8BA /* BinderEnvironment.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = BinderEnvironment.swifttemplate; sourceTree = ""; }; 273FB7A6277E0841E1570990 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; 2E0C3E4D518BC1FEF3EF8D33 /* BinderVariation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderVariation.swift; sourceTree = ""; }; 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; @@ -534,13 +534,13 @@ 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ServiceEntry+TypeForwarding.swift"; sourceTree = ""; }; 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextTranslator.swift; sourceTree = ""; }; 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistry.swift; sourceTree = ""; }; - 808C1063CA90CC593C7E0E9C /* MatchableBoxes.swifttemplate */ = {isa = PBXFileReference; path = MatchableBoxes.swifttemplate; sourceTree = ""; }; + 808C1063CA90CC593C7E0E9C /* MatchableBoxes.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = MatchableBoxes.swifttemplate; sourceTree = ""; }; 823617F3B8A9192F56B13331 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; 86C18DDD83715886DF7F1818 /* OverrideSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OverrideSpec.swift; sourceTree = ""; }; 8B9785AAE94A5447FA307242 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 8C4916168E81D76536892122 /* SwinjectContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectContainer.swift; sourceTree = ""; }; 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectTreeBuilderSpec.swift; sourceTree = ""; }; - 90191C25A2D66E07C4E9CD73 /* SwiftCode.swifttemplate */ = {isa = PBXFileReference; path = SwiftCode.swifttemplate; sourceTree = ""; }; + 90191C25A2D66E07C4E9CD73 /* SwiftCode.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = SwiftCode.swifttemplate; sourceTree = ""; }; 938425B216B78A06EC10504A /* LinuxConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinuxConfig.swift; sourceTree = ""; }; 9620155728133F451B31C0AD /* Swinject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Swinject.swift; sourceTree = ""; }; 96AEC72A42A227A50CF9845B /* Circularity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Circularity.swift; sourceTree = ""; }; @@ -558,14 +558,14 @@ B92B8E618A08408404FB2A7A /* TypeBinder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinder.swift; sourceTree = ""; }; B9F626B9D3E547621787E4D7 /* Resolver+FunctionCall.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Resolver+FunctionCall.swift"; sourceTree = ""; }; BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StandardScopeRegistrySpec.swift; sourceTree = ""; }; - BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */ = {isa = PBXFileReference; path = "ServiceEntry+TypeForwarding.swifttemplate"; sourceTree = ""; }; + BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "ServiceEntry+TypeForwarding.swifttemplate"; sourceTree = ""; }; BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Behavior.swift; sourceTree = ""; }; C1E726A651C3AFE92C19608B /* SwinjectModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectModule.swift; sourceTree = ""; }; C3C516EFA0CA22D19F07B27E /* InjectionVariation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InjectionVariation.swift; sourceTree = ""; }; C765B92B00C0AC8625BB4AC9 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; CC85CB215058F95C0BC190B1 /* Bridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bridge.swift; sourceTree = ""; }; CDA78290D6D60BD0B808571F /* Container+Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Logging.swift"; sourceTree = ""; }; - CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; + CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; D7D394F381E60F6E6E92E7DB /* SimpleBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleBinding.swift; sourceTree = ""; }; DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextSpec.swift; sourceTree = ""; }; E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; @@ -573,7 +573,7 @@ F2E291E30E191A1E202A013A /* ScopedBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopedBinding.swift; sourceTree = ""; }; F446D6BD4C44E16A1D608BFB /* Container+TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+TypeForwarding.swift"; sourceTree = ""; }; F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.TypeForwarding.swift; sourceTree = ""; }; - FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */ = {isa = PBXFileReference; path = "Resolver+LegacyApi.swifttemplate"; sourceTree = ""; }; + FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+LegacyApi.swifttemplate"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -674,10 +674,10 @@ 2D9982F0E5050BAE1832702E /* 3.0 API */ = { isa = PBXGroup; children = ( + 0E7DC2C5AA87B18BD465EB77 /* Opaque.swift */, B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */, A367B4D6F7E5331620430ECF /* BindingBuilder.swift */, 419FB96A1F4B72278B9A6665 /* InstanceBuilder.swift */, - 0E7DC2C5AA87B18BD465EB77 /* Opaque.swift */, B9F626B9D3E547621787E4D7 /* Resolver+FunctionCall.swift */, 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */, F2E291E30E191A1E202A013A /* ScopedBinding.swift */, @@ -1895,7 +1895,11 @@ "$(PROJECT_DIR)/Carthage/Build/iOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -1933,7 +1937,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = macosx; SKIP_INSTALL = YES; @@ -1950,7 +1957,11 @@ "$(PROJECT_DIR)/Carthage/Build/tvOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = appletvos; TARGETED_DEVICE_FAMILY = 3; @@ -1968,7 +1979,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = appletvos; SKIP_INSTALL = YES; @@ -1986,7 +2000,11 @@ "$(PROJECT_DIR)/Carthage/Build/iOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -2003,7 +2021,11 @@ "$(PROJECT_DIR)/Carthage/Build/Mac", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = macosx; }; @@ -2093,7 +2115,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = appletvos; SKIP_INSTALL = YES; @@ -2111,7 +2136,11 @@ "$(PROJECT_DIR)/Carthage/Build/watchOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = watchos; SKIP_INSTALL = YES; @@ -2130,7 +2159,10 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); SDKROOT = macosx; SKIP_INSTALL = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -2148,7 +2180,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = iphoneos; SKIP_INSTALL = YES; @@ -2166,7 +2201,11 @@ "$(PROJECT_DIR)/Carthage/Build/watchOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = watchos; SKIP_INSTALL = YES; @@ -2184,7 +2223,11 @@ "$(PROJECT_DIR)/Carthage/Build/Mac", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = macosx; }; @@ -2199,7 +2242,11 @@ "$(PROJECT_DIR)/Carthage/Build/tvOS", ); INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_NAME = SwinjectTests; SDKROOT = appletvos; TARGETED_DEVICE_FAMILY = 3; @@ -2217,7 +2264,10 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); SDKROOT = macosx; SKIP_INSTALL = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -2236,7 +2286,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = macosx; SKIP_INSTALL = YES; @@ -2255,7 +2308,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); PRODUCT_NAME = Swinject; SDKROOT = iphoneos; SKIP_INSTALL = YES; diff --git a/Tests/3.0 API/CIrcularitySpec.swift b/Tests/3.0 API/CIrcularitySpec.swift index e8928e12..b6a21740 100644 --- a/Tests/3.0 API/CIrcularitySpec.swift +++ b/Tests/3.0 API/CIrcularitySpec.swift @@ -51,41 +51,42 @@ class CircularitySpec: QuickSpec { override func spec() { #if swift(>=5.1) let foo = try? swinject.instance(of: Foo.self) expect { foo?.bar.foo } === foo } - it("correctly injects dependencies if using Lazy Weak wrapper") { - class Foo { - let bar: Bar - init(_ bar: Bar) { self.bar = bar } - } - class Bar { - @Lazy @Weak var foo = nil as Foo? - init(_ foo: Lazy>) { _foo = foo } - } - let swinject = Swinject { - bbind(Foo.self) & singleton(ref: weakRef) { Foo(try $0.instance()) } - bbind(Bar.self) & provider { Bar(try $0.instance()) } - } - let foo = try? swinject.instance(of: Foo.self) - expect { foo?.bar.foo } === foo - } - it("can avoid reference cycles if using Lazy Weak wrapper and weak singleton") { - class Foo { - let bar: Bar - init(_ bar: Bar) { self.bar = bar } - } - class Bar { - @Lazy @Weak var foo = nil as Foo? - init(_ foo: Lazy>) { _foo = foo } - } - let swinject = Swinject { - bbind(Foo.self) & singleton(ref: weakRef) { Foo(try $0.instance()) } - bbind(Bar.self) & provider { Bar(try $0.instance()) } - } - var foo = try? swinject.instance(of: Foo.self) - let bar = foo?.bar - - foo = nil - - expect(bar?.foo).to(beNil()) - } + // FIXME: This segfaults on Xcode11 beta5 +// it("correctly injects dependencies if using Lazy Weak wrapper") { +// class Foo { +// let bar: Bar +// init(_ bar: Bar) { self.bar = bar } +// } +// class Bar { +// @Lazy @Weak var foo = nil as Foo? +// init(_ foo: Lazy>) { _foo = foo } +// } +// let swinject = Swinject { +// bbind(Foo.self) & singleton(ref: weakRef) { Foo(try $0.instance()) } +// bbind(Bar.self) & provider { Bar(try $0.instance()) } +// } +// let foo = try? swinject.instance(of: Foo.self) +// expect { foo?.bar.foo } === foo +// } +// it("can avoid reference cycles if using Lazy Weak wrapper and weak singleton") { +// class Foo { +// let bar: Bar +// init(_ bar: Bar) { self.bar = bar } +// } +// class Bar { +// @Lazy @Weak var foo = nil as Foo? +// init(_ foo: Lazy>) { _foo = foo } +// } +// let swinject = Swinject { +// bbind(Foo.self) & singleton(ref: weakRef) { Foo(try $0.instance()) } +// bbind(Bar.self) & provider { Bar(try $0.instance()) } +// } +// var foo = try? swinject.instance(of: Foo.self) +// let bar = foo?.bar +// +// foo = nil +// +// expect(bar?.foo).to(beNil()) +// } #endif } } From 9aba6bbe3c1865774b03ba62cee570bef8b1fb68 Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Sat, 24 Aug 2019 09:11:01 +0200 Subject: [PATCH 204/239] Rename binding builder --- Sources/3.0 API/BinderEnvironment.swift | 82 +++++++++---------- ...lder.swift => PartialBindingBuilder.swift} | 14 ++-- Sources/3.0 API/ScopedBinding.swift | 2 +- Sources/3.0 API/SimpleBinding.swift | 2 +- Sources/3.0 API/TypeBinder.swift | 4 +- Sources/3.1 API/BindingBuilder.swift | 7 ++ Swinject.xcodeproj/project.pbxproj | 36 +++++--- Templates/BinderVariation.swift | 2 +- Templates/SwiftCode.swifttemplate | 2 +- 9 files changed, 85 insertions(+), 66 deletions(-) rename Sources/3.0 API/{BindingBuilder.swift => PartialBindingBuilder.swift} (61%) create mode 100644 Sources/3.1 API/BindingBuilder.swift diff --git a/Sources/3.0 API/BinderEnvironment.swift b/Sources/3.0 API/BinderEnvironment.swift index 340c4873..468988d6 100644 --- a/Sources/3.0 API/BinderEnvironment.swift +++ b/Sources/3.0 API/BinderEnvironment.swift @@ -20,172 +20,172 @@ public func scoped(_ scope: AScope) -> ScopedEnvironment where A // swiftlint:disable line_length // swiftlint:disable identifier_name -public func instance(_ instance: Type) -> SomeBindingBuilder { +public func instance(_ instance: Type) -> SomePartialBindingBuilder { return SimpleBinding.Builder { _, _, _ in instance }.opaque } // sourcery:inline:BindingBuilders extension ContextedEnvironment { - public func provider(_ builder: @escaping () throws -> Type) -> SomeBindingBuilder { + public func provider(_ builder: @escaping () throws -> Type) -> SomePartialBindingBuilder { return SimpleBinding.Builder { _, _, _ in try builder() }.opaque } - public func provider(_ builder: @escaping (Resolver) throws -> Type) -> SomeBindingBuilder { + public func provider(_ builder: @escaping (Resolver) throws -> Type) -> SomePartialBindingBuilder { return SimpleBinding.Builder { r, _, _ in try builder(r) }.opaque } - public func provider(_ builder: @escaping (Resolver, Context) throws -> Type) -> SomeBindingBuilder { + public func provider(_ builder: @escaping (Resolver, Context) throws -> Type) -> SomePartialBindingBuilder { return SimpleBinding.Builder { r, c, _ in try builder(r, c) }.opaque } - public func factory(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SomeBindingBuilder { + public func factory(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SomePartialBindingBuilder { return SimpleBinding.Builder { r, c, a in try builder(r, c, a) }.opaque } - public func factory(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable { + public func factory(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SomePartialBindingBuilder where Arg1: Hashable { return SimpleBinding.Builder> { r, c, a in try builder(r, c, a.arg1) }.opaque } - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SomeBindingBuilder { + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SomePartialBindingBuilder { return SimpleBinding.Builder { r, c, a in try builder(r, c, a.0, a.1) }.opaque } - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable { + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SomePartialBindingBuilder where Arg1: Hashable, Arg2: Hashable { return SimpleBinding.Builder> { r, c, a in try builder(r, c, a.arg1, a.arg2) }.opaque } - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingBuilder { + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SomePartialBindingBuilder { return SimpleBinding.Builder { r, c, a in try builder(r, c, a.0, a.1, a.2) }.opaque } - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SomePartialBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { return SimpleBinding.Builder> { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3) }.opaque } - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingBuilder { + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomePartialBindingBuilder { return SimpleBinding.Builder { r, c, a in try builder(r, c, a.0, a.1, a.2, a.3) }.opaque } - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomePartialBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { return SimpleBinding.Builder> { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3, a.arg4) }.opaque } - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingBuilder { + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomePartialBindingBuilder { return SimpleBinding.Builder { r, c, a in try builder(r, c, a.0, a.1, a.2, a.3, a.4) }.opaque } - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomePartialBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { return SimpleBinding.Builder> { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) }.opaque } } extension ScopedEnvironment { - public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping () throws -> Type) -> SomeBindingBuilder { + public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping () throws -> Type) -> SomePartialBindingBuilder { return ScopedBinding.Builder(scope, ref) { _, _, _ in try builder() }.opaque } - public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver) throws -> Type) -> SomeBindingBuilder { + public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver) throws -> Type) -> SomePartialBindingBuilder { return ScopedBinding.Builder(scope, ref) { r, _, _ in try builder(r) }.opaque } - public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context) throws -> Type) -> SomeBindingBuilder { + public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context) throws -> Type) -> SomePartialBindingBuilder { return ScopedBinding.Builder(scope, ref) { r, c, _ in try builder(r, c) }.opaque } - public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable { + public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SomePartialBindingBuilder where Arg1: Hashable { return ScopedBinding.Builder>(scope, ref) { r, c, a in try builder(r, c, a.arg1) }.opaque } - public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable { + public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SomePartialBindingBuilder where Arg1: Hashable, Arg2: Hashable { return ScopedBinding.Builder>(scope, ref) { r, c, a in try builder(r, c, a.arg1, a.arg2) }.opaque } - public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SomePartialBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { return ScopedBinding.Builder>(scope, ref) { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3) }.opaque } - public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomePartialBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { return ScopedBinding.Builder>(scope, ref) { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3, a.arg4) }.opaque } - public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomePartialBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { return ScopedBinding.Builder>(scope, ref) { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) }.opaque } } -public func provider(_ builder: @escaping () throws -> Type) -> SomeBindingBuilder { +public func provider(_ builder: @escaping () throws -> Type) -> SomePartialBindingBuilder { return SimpleBinding.Builder { _, _, _ in try builder() }.opaque } -public func provider(_ builder: @escaping (Resolver) throws -> Type) -> SomeBindingBuilder { +public func provider(_ builder: @escaping (Resolver) throws -> Type) -> SomePartialBindingBuilder { return SimpleBinding.Builder { r, _, _ in try builder(r) }.opaque } -public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> SomeBindingBuilder { +public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> SomePartialBindingBuilder { return SimpleBinding.Builder { r, _, a in try builder(r, a) }.opaque } -public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable { +public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> SomePartialBindingBuilder where Arg1: Hashable { return SimpleBinding.Builder> { r, _, a in try builder(r, a.arg1) }.opaque } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SomeBindingBuilder { +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SomePartialBindingBuilder { return SimpleBinding.Builder { r, _, a in try builder(r, a.0, a.1) }.opaque } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable { +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SomePartialBindingBuilder where Arg1: Hashable, Arg2: Hashable { return SimpleBinding.Builder> { r, _, a in try builder(r, a.arg1, a.arg2) }.opaque } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingBuilder { +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SomePartialBindingBuilder { return SimpleBinding.Builder { r, _, a in try builder(r, a.0, a.1, a.2) }.opaque } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SomePartialBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { return SimpleBinding.Builder> { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3) }.opaque } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingBuilder { +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomePartialBindingBuilder { return SimpleBinding.Builder { r, _, a in try builder(r, a.0, a.1, a.2, a.3) }.opaque } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomePartialBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { return SimpleBinding.Builder> { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3, a.arg4) }.opaque } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingBuilder { +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomePartialBindingBuilder { return SimpleBinding.Builder { r, _, a in try builder(r, a.0, a.1, a.2, a.3, a.4) }.opaque } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomePartialBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { return SimpleBinding.Builder> { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) }.opaque } -public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping () throws -> Type) -> SomeBindingBuilder { +public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping () throws -> Type) -> SomePartialBindingBuilder { return ScopedBinding.Builder(.root, ref) { _, _, _ in try builder() }.opaque } -public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver) throws -> Type) -> SomeBindingBuilder { +public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver) throws -> Type) -> SomePartialBindingBuilder { return ScopedBinding.Builder(.root, ref) { r, _, _ in try builder(r) }.opaque } -public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable { +public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1) throws -> Type) -> SomePartialBindingBuilder where Arg1: Hashable { return ScopedBinding.Builder>(.root, ref) { r, _, a in try builder(r, a.arg1) }.opaque } -public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable { +public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SomePartialBindingBuilder where Arg1: Hashable, Arg2: Hashable { return ScopedBinding.Builder>(.root, ref) { r, _, a in try builder(r, a.arg1, a.arg2) }.opaque } -public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { +public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SomePartialBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { return ScopedBinding.Builder>(.root, ref) { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3) }.opaque } -public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { +public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomePartialBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { return ScopedBinding.Builder>(.root, ref) { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3, a.arg4) }.opaque } -public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { +public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomePartialBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { return ScopedBinding.Builder>(.root, ref) { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) }.opaque } diff --git a/Sources/3.0 API/BindingBuilder.swift b/Sources/3.0 API/PartialBindingBuilder.swift similarity index 61% rename from Sources/3.0 API/BindingBuilder.swift rename to Sources/3.0 API/PartialBindingBuilder.swift index 0bc59940..067fcee6 100644 --- a/Sources/3.0 API/BindingBuilder.swift +++ b/Sources/3.0 API/PartialBindingBuilder.swift @@ -2,12 +2,12 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -public protocol BindingBuilder { +public protocol PartialBindingBuilder { associatedtype BoundType func makeBinding(with properties: BindingProperties) -> Binding } -public struct SomeBindingBuilder: BindingBuilder, AnyOpaque { +public struct SomePartialBindingBuilder: PartialBindingBuilder, AnyOpaque { let anyActual: Any fileprivate let _makeBinding: (BindingProperties) -> Binding @@ -16,16 +16,12 @@ public struct SomeBindingBuilder: BindingBuilder, AnyOpaque { } } -public extension BindingBuilder { - var opaque: SomeBindingBuilder { - return SomeBindingBuilder(anyActual: self) { self.makeBinding(with: $0) } +public extension PartialBindingBuilder { + var opaque: SomePartialBindingBuilder { + return SomePartialBindingBuilder(anyActual: self) { self.makeBinding(with: $0) } } } -public protocol AnyBindingBuilder: SwinjectEntry { - func makeBinding() -> Binding -} - struct FinalBindingBuilder: AnyBindingBuilder { let binidngFactory: () -> Binding diff --git a/Sources/3.0 API/ScopedBinding.swift b/Sources/3.0 API/ScopedBinding.swift index b1be1e57..7221d98a 100644 --- a/Sources/3.0 API/ScopedBinding.swift +++ b/Sources/3.0 API/ScopedBinding.swift @@ -51,7 +51,7 @@ extension ScopedBinding.Builder: InstanceBuilder { } } -extension ScopedBinding.Builder: BindingBuilder { +extension ScopedBinding.Builder: PartialBindingBuilder { typealias BoundType = Type func makeBinding(with properties: BindingProperties) -> Binding { diff --git a/Sources/3.0 API/SimpleBinding.swift b/Sources/3.0 API/SimpleBinding.swift index 814757ad..3eb415ed 100644 --- a/Sources/3.0 API/SimpleBinding.swift +++ b/Sources/3.0 API/SimpleBinding.swift @@ -32,7 +32,7 @@ extension SimpleBinding.Builder: InstanceBuilder { } } -extension SimpleBinding.Builder: BindingBuilder { +extension SimpleBinding.Builder: PartialBindingBuilder { typealias BoundType = Type func makeBinding(with properties: BindingProperties) -> Binding { diff --git a/Sources/3.0 API/TypeBinder.swift b/Sources/3.0 API/TypeBinder.swift index a1047335..fd0a015a 100644 --- a/Sources/3.0 API/TypeBinder.swift +++ b/Sources/3.0 API/TypeBinder.swift @@ -21,7 +21,7 @@ public func bind(_: Type.Type, tagged tag: String? = nil, overrides: Bool public extension TypeBinder { func with( _ builder: Builder - ) -> AnyBindingBuilder where Builder: BindingBuilder, Builder.BoundType == BoundType { + ) -> AnyBindingBuilder where Builder: PartialBindingBuilder, Builder.BoundType == BoundType { return FinalBindingBuilder { builder.makeBinding(with: self.properties) } } @@ -32,7 +32,7 @@ public extension TypeBinder { public func & ( lhs: TypeBinder, rhs: Builder -) -> AnyBindingBuilder where Builder: BindingBuilder, Builder.BoundType == BoundType { +) -> AnyBindingBuilder where Builder: PartialBindingBuilder, Builder.BoundType == BoundType { return lhs.with(rhs) } diff --git a/Sources/3.1 API/BindingBuilder.swift b/Sources/3.1 API/BindingBuilder.swift new file mode 100644 index 00000000..8e4b5026 --- /dev/null +++ b/Sources/3.1 API/BindingBuilder.swift @@ -0,0 +1,7 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +public protocol AnyBindingBuilder: SwinjectEntry { + func makeBinding() -> Binding +} diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index dc347107..2b61abca 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -53,7 +53,7 @@ 283C77045DA55C2134EC9C48 /* Container+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F446D6BD4C44E16A1D608BFB /* Container+TypeForwarding.swift */; }; 290C9E9420A1EE30456476CB /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59111BE319C59E4CD6CF68CD /* Assembler.swift */; }; 293985649250DF270DC89135 /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; - 2A6D2874ADB24B08DAE1EC04 /* BindingBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = A367B4D6F7E5331620430ECF /* BindingBuilder.swift */; }; + 2A6D2874ADB24B08DAE1EC04 /* PartialBindingBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = A367B4D6F7E5331620430ECF /* PartialBindingBuilder.swift */; }; 2AA60B7E6EBA9EC6BE92D7CB /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; 2B506344F37CE5F5C5C02C05 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; 2C352AAD1AC7D82A4A059046 /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; @@ -141,7 +141,7 @@ 6A967AE5710606998C2BE070 /* PropertyWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 424C647FF08FCB7C2A54E085 /* PropertyWrapper.swift */; }; 6BB1E24C1CE55C9F6EA6CC28 /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C765B92B00C0AC8625BB4AC9 /* Quick.framework */; }; 6C01E868DE44BD396D94858B /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; - 6CFE30E5595611778893D147 /* BindingBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = A367B4D6F7E5331620430ECF /* BindingBuilder.swift */; }; + 6CFE30E5595611778893D147 /* PartialBindingBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = A367B4D6F7E5331620430ECF /* PartialBindingBuilder.swift */; }; 6DA49F84E2592B32F81F268B /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BFF4BA99493C54260878C4 /* ObjectScope.swift */; }; 6DD80811E5FD658CAFEEA647 /* CIrcularitySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 118ABC654C4144496848AD74 /* CIrcularitySpec.swift */; }; 6F6FAD0EEF84580DD53BB755 /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1C58FC14EEA170B0DC079DE4 /* Quick.framework */; }; @@ -160,6 +160,9 @@ 751F545653B0F1E30341C312 /* OverrideSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86C18DDD83715886DF7F1818 /* OverrideSpec.swift */; }; 75D74C8C25EDACF5A7A75A5C /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; 76FB9AFE299316E7F3F4C3BB /* InjectionRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57F4D977AC4289A6145383C9 /* InjectionRequest.swift */; }; + 773C6DDC23111956007A40BF /* BindingBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773C6DDB23111956007A40BF /* BindingBuilder.swift */; }; + 773C6DDD23111956007A40BF /* BindingBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773C6DDB23111956007A40BF /* BindingBuilder.swift */; }; + 773C6DDE23111956007A40BF /* BindingBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773C6DDB23111956007A40BF /* BindingBuilder.swift */; }; 778D9AB6470D4280254AC140 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; 77BF219EAB4FC8475943CECC /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6D434EB4C13CF9D9FA6D80CB /* Swinject.framework */; }; 789BF74652A2424EB8F7EF47 /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -244,7 +247,7 @@ B00627BABCF9181C7B58609E /* LinuxConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 938425B216B78A06EC10504A /* LinuxConfig.swift */; }; B06306286CC5EA66C88F24D1 /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 38BCCF3F950869BD1891F7A8 /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; B0B139FADA6AE07C79847EBA /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61EE5DDBE705B47AFC9A6986 /* LoadAwareAssembly.swift */; }; - B0B65F494A88CDEFE8EF79F6 /* BindingBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = A367B4D6F7E5331620430ECF /* BindingBuilder.swift */; }; + B0B65F494A88CDEFE8EF79F6 /* PartialBindingBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = A367B4D6F7E5331620430ECF /* PartialBindingBuilder.swift */; }; B293894FEB67831DDA5F000E /* Reference.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73B4B777290FF5D38A8914CC /* Reference.swift */; }; B2FAD41F7726502822AF913B /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42490D1D0C395951243F5CFF /* Container.swift */; }; B3062AB22373AD23052B61DF /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; @@ -349,7 +352,7 @@ FA805A162E989A22990B99AA /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; FC339851D7EEE4D17178CC1F /* Weak.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57A7E35B2B22650208F904B8 /* Weak.swift */; }; FD7B2663F2F931B78EB330EE /* Resolver+LegacyApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A784E2DEC7691D14DDBECD8 /* Resolver+LegacyApi.swift */; }; - FD8BB4CC8DA0E560E39FA491 /* BindingBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = A367B4D6F7E5331620430ECF /* BindingBuilder.swift */; }; + FD8BB4CC8DA0E560E39FA491 /* PartialBindingBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = A367B4D6F7E5331620430ECF /* PartialBindingBuilder.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -531,6 +534,7 @@ 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.CustomStringConvertible.swift; sourceTree = ""; }; 74DE57FB3E8228904E6FE0D7 /* Swinject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Swinject.h; sourceTree = ""; }; 75BE3AE3E30DFE42A919D825 /* ModulesSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModulesSpec.swift; sourceTree = ""; }; + 773C6DDB23111956007A40BF /* BindingBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingBuilder.swift; sourceTree = ""; }; 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ServiceEntry+TypeForwarding.swift"; sourceTree = ""; }; 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextTranslator.swift; sourceTree = ""; }; 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistry.swift; sourceTree = ""; }; @@ -547,7 +551,7 @@ 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistryKey.swift; sourceTree = ""; }; A20C1319AF31EC7F8E6945FE /* SwinjectTests.xctest */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.cfbundle; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; A3586A4987B7C7C8122D674E /* SwinjectError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectError.swift; sourceTree = ""; }; - A367B4D6F7E5331620430ECF /* BindingBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingBuilder.swift; sourceTree = ""; }; + A367B4D6F7E5331620430ECF /* PartialBindingBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PartialBindingBuilder.swift; sourceTree = ""; }; A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Resolver.swift; sourceTree = ""; }; ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Circularity.swift; sourceTree = ""; }; ADA1541ABC1365DFD7E3377F /* Food.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Food.swift; sourceTree = ""; }; @@ -676,7 +680,7 @@ children = ( 0E7DC2C5AA87B18BD465EB77 /* Opaque.swift */, B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */, - A367B4D6F7E5331620430ECF /* BindingBuilder.swift */, + A367B4D6F7E5331620430ECF /* PartialBindingBuilder.swift */, 419FB96A1F4B72278B9A6665 /* InstanceBuilder.swift */, B9F626B9D3E547621787E4D7 /* Resolver+FunctionCall.swift */, 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */, @@ -738,6 +742,14 @@ path = watchOS; sourceTree = ""; }; + 773C6DDA23111910007A40BF /* 3.1 API */ = { + isa = PBXGroup; + children = ( + 773C6DDB23111956007A40BF /* BindingBuilder.swift */, + ); + path = "3.1 API"; + sourceTree = ""; + }; 80E97D8FD5574A96B6BC9EB9 /* Frameworks */ = { isa = PBXGroup; children = ( @@ -832,6 +844,7 @@ D026A6699A2A932511D29E14 /* Sources */ = { isa = PBXGroup; children = ( + 773C6DDA23111910007A40BF /* 3.1 API */, 5F7BC1C4169BB4382C6D3E1F /* Info.plist */, 74DE57FB3E8228904E6FE0D7 /* Swinject.h */, 5F6AA1259C61A4D472220C36 /* 2.0 API */, @@ -1421,7 +1434,7 @@ 703F8B3AD111A6CFAFF66A49 /* Behavior.swift in Sources */, ADCF273AF041E74DBEC2C13A /* BinderEnvironment.swift in Sources */, 658AEDC8D802A6788E959E0C /* Binding.swift in Sources */, - B0B65F494A88CDEFE8EF79F6 /* BindingBuilder.swift in Sources */, + B0B65F494A88CDEFE8EF79F6 /* PartialBindingBuilder.swift in Sources */, 694C2C891D581371B2B051D7 /* Container+Logging.swift in Sources */, AAD8D0551B8A26A9B22AECEC /* Container+Registration.swift in Sources */, 996CCFE825834C7D3236E742 /* Container+TypeForwarding.swift in Sources */, @@ -1439,6 +1452,7 @@ D9084C826F7A798508CD66F5 /* Resolver+Injection.swift in Sources */, D4936DC1A47A8C85325FB52E /* Resolver+LegacyApi.swift in Sources */, 8016512839FE61EC3127E489 /* Resolver.swift in Sources */, + 773C6DDD23111956007A40BF /* BindingBuilder.swift in Sources */, 68C95FCB0D345CA3BA24D320 /* Scope.swift in Sources */, BB571B9A78FC53231A18E18C /* ScopeRegistry.swift in Sources */, 593B93BA2EE3FE4418A1C579 /* ScopeRegistryKey.swift in Sources */, @@ -1646,7 +1660,7 @@ FA805A162E989A22990B99AA /* Behavior.swift in Sources */, 6FCCBA9D2E4C2A225CB1A152 /* BinderEnvironment.swift in Sources */, F9A4BF18B0085B7DCD3440EC /* Binding.swift in Sources */, - 6CFE30E5595611778893D147 /* BindingBuilder.swift in Sources */, + 6CFE30E5595611778893D147 /* PartialBindingBuilder.swift in Sources */, 6A03ABEED82EF31E8E6E297E /* Container+Logging.swift in Sources */, A5E4C79F89E1A8AB3A4D8D6E /* Container+Registration.swift in Sources */, BD9B57E26722C80B7EF990DB /* Container+TypeForwarding.swift in Sources */, @@ -1693,7 +1707,7 @@ 2CB057F2A16DA462E0517AAB /* Behavior.swift in Sources */, 2DD6F290740EA69B3E73E0EA /* BinderEnvironment.swift in Sources */, D2BAE1CB997A4D052CB8EFC8 /* Binding.swift in Sources */, - FD8BB4CC8DA0E560E39FA491 /* BindingBuilder.swift in Sources */, + FD8BB4CC8DA0E560E39FA491 /* PartialBindingBuilder.swift in Sources */, 1ED6BD68D92F4FE60978EF22 /* Container+Logging.swift in Sources */, CB0B308F3D3A831A28127462 /* Container+Registration.swift in Sources */, 283C77045DA55C2134EC9C48 /* Container+TypeForwarding.swift in Sources */, @@ -1711,6 +1725,7 @@ C6D60E2AEC381998223145B2 /* Resolver+Injection.swift in Sources */, FD7B2663F2F931B78EB330EE /* Resolver+LegacyApi.swift in Sources */, 97C2EA47D7623AFD723AFE93 /* Resolver.swift in Sources */, + 773C6DDE23111956007A40BF /* BindingBuilder.swift in Sources */, 2C352AAD1AC7D82A4A059046 /* Scope.swift in Sources */, 02556F149C9AAEF5CE353AC1 /* ScopeRegistry.swift in Sources */, 06F4CAB352B4F623FF7BD885 /* ScopeRegistryKey.swift in Sources */, @@ -1740,7 +1755,7 @@ F7979BE4BE1B1C7101D15E61 /* Behavior.swift in Sources */, B5FF5DFE394B6B1BB930D88D /* BinderEnvironment.swift in Sources */, 3F8F5645D6D37FCEC1D89393 /* Binding.swift in Sources */, - 2A6D2874ADB24B08DAE1EC04 /* BindingBuilder.swift in Sources */, + 2A6D2874ADB24B08DAE1EC04 /* PartialBindingBuilder.swift in Sources */, 999AF7221D3F2E1F83C3ACB1 /* Container+Logging.swift in Sources */, 21285CED416F1317E993397A /* Container+Registration.swift in Sources */, 3A0B409E840B44B281DB3C54 /* Container+TypeForwarding.swift in Sources */, @@ -1758,6 +1773,7 @@ CBE63031F33303F3E503CEF2 /* Resolver+Injection.swift in Sources */, 41C7340BFD2EB66359772733 /* Resolver+LegacyApi.swift in Sources */, BE94EF7BCF976A703F961389 /* Resolver.swift in Sources */, + 773C6DDC23111956007A40BF /* BindingBuilder.swift in Sources */, 96EA0A5DF33F025EBE0B67D2 /* Scope.swift in Sources */, D861595482464ED95CF81922 /* ScopeRegistry.swift in Sources */, 920DE2CAB9895D10FAE48FBA /* ScopeRegistryKey.swift in Sources */, diff --git a/Templates/BinderVariation.swift b/Templates/BinderVariation.swift index 295be62f..79e77eb1 100644 --- a/Templates/BinderVariation.swift +++ b/Templates/BinderVariation.swift @@ -60,7 +60,7 @@ extension BinderVariation { } var returnType: String { - return "SomeBindingBuilder" + return "SomePartialBindingBuilder" } var actualReturnType: String { diff --git a/Templates/SwiftCode.swifttemplate b/Templates/SwiftCode.swifttemplate index b71bd266..a0d21f5c 100644 --- a/Templates/SwiftCode.swifttemplate +++ b/Templates/SwiftCode.swifttemplate @@ -61,7 +61,7 @@ extension BinderVariation { } var returnType: String { - return "SomeBindingBuilder" + return "SomePartialBindingBuilder" } var actualReturnType: String { From 5f704a5134ff56ae4e583fca2287d38d094e84e5 Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Sat, 24 Aug 2019 09:33:13 +0200 Subject: [PATCH 205/239] Add type parametner to the instance request --- Sources/2.0 API/InstanceWrapper.swift | 4 +++- ...ionRequest.swift => InstanceRequest.swift} | 16 ++++++++++----- Sources/Core/PropertyWrapper.swift | 18 ++++++++--------- Sources/Core/Resolver.swift | 4 ++-- Sources/Core/Swinject.swift | 18 ++++++++--------- Swinject.xcodeproj/project.pbxproj | 20 +++++++++---------- 6 files changed, 44 insertions(+), 36 deletions(-) rename Sources/Core/{InjectionRequest.swift => InstanceRequest.swift} (63%) diff --git a/Sources/2.0 API/InstanceWrapper.swift b/Sources/2.0 API/InstanceWrapper.swift index 0b674903..c79b475b 100644 --- a/Sources/2.0 API/InstanceWrapper.swift +++ b/Sources/2.0 API/InstanceWrapper.swift @@ -70,12 +70,14 @@ public extension Provider { var instance: Type { return provider() } +} +extension Provider { init(initialValue: @autoclosure @escaping () -> Type) { provider = initialValue } - init(resolver: Resolver, request: InjectionRequest) { + init(resolver: Resolver, request: AnyInstanceRequest) { // swiftlint:disable:next force_try self.init(initialValue: try! resolver.on(Graph()).resolve(request.replacingType(with: Value.self))) } diff --git a/Sources/Core/InjectionRequest.swift b/Sources/Core/InstanceRequest.swift similarity index 63% rename from Sources/Core/InjectionRequest.swift rename to Sources/Core/InstanceRequest.swift index 915be719..5022f1b1 100644 --- a/Sources/Core/InjectionRequest.swift +++ b/Sources/Core/InstanceRequest.swift @@ -2,7 +2,13 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -public struct InjectionRequest: Hashable { +protocol AnyInstanceRequest: Matchable { + var descriptor: TypeDescriptor { get } + var argument: Any { get } + var argumentType: Any.Type { get } +} + +public struct InstanceRequest: AnyInstanceRequest, Hashable { let descriptor: TypeDescriptor let argument: Any let argumentType: Any.Type @@ -13,7 +19,7 @@ public struct InjectionRequest: Hashable { (argument as? Matchable)?.hash(into: &hasher) } - public static func == (lhs: InjectionRequest, rhs: InjectionRequest) -> Bool { + public static func == (lhs: InstanceRequest, rhs: InstanceRequest) -> Bool { return lhs.descriptor == rhs.descriptor && lhs.argumentType == rhs.argumentType && areArgumentsEqual(lhs.argument, rhs.argument) @@ -24,11 +30,11 @@ func request( type: Type.Type = Type.self, tag: String?, arg: Argument -) -> InjectionRequest { - return InjectionRequest(descriptor: tagged(type, with: tag), argument: arg, argumentType: Argument.self) +) -> InstanceRequest { + return InstanceRequest(descriptor: tagged(type, with: tag), argument: arg, argumentType: Argument.self) } -extension InjectionRequest { +extension AnyInstanceRequest { func key(forContextType contextType: Any.Type) -> BindingKey { return BindingKey(descriptor: descriptor, contextType: contextType, argumentType: argumentType) } diff --git a/Sources/Core/PropertyWrapper.swift b/Sources/Core/PropertyWrapper.swift index 4984f248..9a4d8c52 100644 --- a/Sources/Core/PropertyWrapper.swift +++ b/Sources/Core/PropertyWrapper.swift @@ -3,8 +3,8 @@ // protocol CustomResolvable { - init(resolver: Resolver, request: InjectionRequest) - static func requiredRequest(for request: InjectionRequest) -> InjectionRequest? + init(resolver: Resolver, request: AnyInstanceRequest) + static func requiredRequest(for request: AnyInstanceRequest) -> AnyInstanceRequest? } protocol PropertyWrapper: CustomResolvable { @@ -13,12 +13,12 @@ protocol PropertyWrapper: CustomResolvable { } extension PropertyWrapper { - init(resolver: Resolver, request: InjectionRequest) { + init(resolver: Resolver, request: AnyInstanceRequest) { // swiftlint:disable:next force_try self.init(initialValue: try! resolver.resolve(request.replacingType(with: Value.self))) } - static func requiredRequest(for request: InjectionRequest) -> InjectionRequest? { + static func requiredRequest(for request: AnyInstanceRequest) -> AnyInstanceRequest? { if let wrapper = Value.self as? CustomResolvable.Type { return wrapper.requiredRequest(for: request) } else { @@ -27,9 +27,9 @@ extension PropertyWrapper { } } -extension InjectionRequest { - func replacingType(with _: Type.Type) -> InjectionRequest { - return InjectionRequest( +extension AnyInstanceRequest { + func replacingType(with _: Type.Type) -> InstanceRequest { + return InstanceRequest( descriptor: TypeDescriptor( tag: descriptor.tag, type: Type.self @@ -41,11 +41,11 @@ extension InjectionRequest { } extension Optional: CustomResolvable { - init(resolver: Resolver, request: InjectionRequest) { + init(resolver: Resolver, request: AnyInstanceRequest) { self = try? resolver.resolve(request.replacingType(with: Wrapped.self)) as Wrapped } - static func requiredRequest(for _: InjectionRequest) -> InjectionRequest? { + static func requiredRequest(for _: AnyInstanceRequest) -> AnyInstanceRequest? { return nil } } diff --git a/Sources/Core/Resolver.swift b/Sources/Core/Resolver.swift index 10ac76cb..b0a5a116 100644 --- a/Sources/Core/Resolver.swift +++ b/Sources/Core/Resolver.swift @@ -3,7 +3,7 @@ // public protocol Resolver { - func resolve(_ request: InjectionRequest) throws -> Type + func resolve(_ request: InstanceRequest) throws -> Type func on(_ context: Context) -> Resolver } @@ -12,7 +12,7 @@ public protocol SwinjectAware: Resolver { } public extension SwinjectAware { - func resolve(_ request: InjectionRequest) throws -> Type { + func resolve(_ request: InstanceRequest) throws -> Type { return try swinject.resolve(request) } diff --git a/Sources/Core/Swinject.swift b/Sources/Core/Swinject.swift index cb428e05..c262d667 100644 --- a/Sources/Core/Swinject.swift +++ b/Sources/Core/Swinject.swift @@ -12,12 +12,12 @@ public struct Swinject { let container: SwinjectContainer let context: Any let contextType: Any.Type - let stack: [InjectionRequest] + let stack: [AnyInstanceRequest] let properties: Properties } extension Swinject: Resolver { - public func resolve(_ request: InjectionRequest) throws -> Type { + public func resolve(_ request: InstanceRequest) throws -> Type { let binding: Binding do { binding = try findBinding(for: request) @@ -38,7 +38,7 @@ extension Swinject: Resolver { } extension Swinject { - private func resolve(_ request: InjectionRequest, asCustom _: Type.Type) -> Type? { + private func resolve(_ request: InstanceRequest, asCustom _: Type.Type) -> Type? { guard let custom = Type.self as? CustomResolvable.Type else { return nil } if let request = custom.requiredRequest(for: request), !hasBinding(for: request) { return nil } // TODO: We should reset tracking only for "delayed" custom resolutions @@ -51,13 +51,13 @@ extension Swinject { .first ?? { throw NoContextTranslator() }() } - private func tracking(_ request: InjectionRequest) throws -> Swinject { + private func tracking(_ request: AnyInstanceRequest) throws -> Swinject { guard properties.detectsCircularDependencies else { return self } - guard !stack.contains(request) else { throw CircularDependency() } + guard !stack.contains(where: { request.matches($0) }) else { throw CircularDependency() } return with(stack: stack + [request]) } - private func translatableKeys(for request: InjectionRequest) -> [BindingKey] { + private func translatableKeys(for request: AnyInstanceRequest) -> [BindingKey] { return allTranslators.map { request.key(forContextType: $0.targetType) } } @@ -69,11 +69,11 @@ extension Swinject { return [IdentityTranslator(for: contextType), ToAnyTranslator(for: contextType)] } - private func hasBinding(for request: InjectionRequest) -> Bool { + private func hasBinding(for request: AnyInstanceRequest) -> Bool { return (try? findBinding(for: request)) != nil } - private func findBinding(for request: InjectionRequest) throws -> Binding { + private func findBinding(for request: AnyInstanceRequest) throws -> Binding { let bindings = translatableKeys(for: request).compactMap { container.bindings[$0] } if bindings.isEmpty { throw NoBinding() } if bindings.count > 1 { throw MultipleBindings() } @@ -102,7 +102,7 @@ extension Swinject { func with( context: Any? = nil, contextType: Any.Type? = nil, - stack: [InjectionRequest]? = nil + stack: [AnyInstanceRequest]? = nil ) -> Swinject { return Swinject( tree: tree, diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 2b61abca..f218fe58 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -13,7 +13,7 @@ 020DA1718FCC68D889FB5A5F /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3586A4987B7C7C8122D674E /* SwinjectError.swift */; }; 02410BD4FB357F4C6B521608 /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; 02556F149C9AAEF5CE353AC1 /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; - 027015812E961322FE3D942B /* InjectionRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57F4D977AC4289A6145383C9 /* InjectionRequest.swift */; }; + 027015812E961322FE3D942B /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57F4D977AC4289A6145383C9 /* InstanceRequest.swift */; }; 03122D1B2EA65C89ADC78EC7 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62682D6ED38742996624B041 /* BasicAssembly.swift */; }; 0509EE8D41BF354EB91ACC80 /* Reference.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73B4B777290FF5D38A8914CC /* Reference.swift */; }; 0622539110A7430776A307C7 /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42490D1D0C395951243F5CFF /* Container.swift */; }; @@ -44,7 +44,7 @@ 1C62135FAE3D64DC7BFBF861 /* ContextSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */; }; 1C82BFD00FCC384DB3AE6A89 /* MatchableBoxes.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 808C1063CA90CC593C7E0E9C /* MatchableBoxes.swifttemplate */; }; 1CA5DF3F93203B226A6FA059 /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EA566CD336DB8343ADFAF9B /* BehaviorFakes.swift */; }; - 1D17DBC27F25717BF7A87AF3 /* InjectionRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57F4D977AC4289A6145383C9 /* InjectionRequest.swift */; }; + 1D17DBC27F25717BF7A87AF3 /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57F4D977AC4289A6145383C9 /* InstanceRequest.swift */; }; 1ED6BD68D92F4FE60978EF22 /* Container+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDA78290D6D60BD0B808571F /* Container+Logging.swift */; }; 21285CED416F1317E993397A /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59A3946B59EB4D787CCE9F2 /* Container+Registration.swift */; }; 233F3E25FF0B51A3E6611F58 /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; @@ -159,7 +159,7 @@ 74E1FC692A27C56510363364 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; 751F545653B0F1E30341C312 /* OverrideSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86C18DDD83715886DF7F1818 /* OverrideSpec.swift */; }; 75D74C8C25EDACF5A7A75A5C /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; - 76FB9AFE299316E7F3F4C3BB /* InjectionRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57F4D977AC4289A6145383C9 /* InjectionRequest.swift */; }; + 76FB9AFE299316E7F3F4C3BB /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57F4D977AC4289A6145383C9 /* InstanceRequest.swift */; }; 773C6DDC23111956007A40BF /* BindingBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773C6DDB23111956007A40BF /* BindingBuilder.swift */; }; 773C6DDD23111956007A40BF /* BindingBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773C6DDB23111956007A40BF /* BindingBuilder.swift */; }; 773C6DDE23111956007A40BF /* BindingBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773C6DDB23111956007A40BF /* BindingBuilder.swift */; }; @@ -176,7 +176,7 @@ 818DF17D671EA1022CE59A2A /* InjectionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 670DB253ECD5CE1468A7F2E3 /* InjectionSpec.swift */; }; 820307073A53AED47AC99B8D /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3586A4987B7C7C8122D674E /* SwinjectError.swift */; }; 82299769BC637A14E7827DB0 /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1E726A651C3AFE92C19608B /* SwinjectModule.swift */; }; - 826D63FA91E370F0061768B0 /* InjectionRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57F4D977AC4289A6145383C9 /* InjectionRequest.swift */; }; + 826D63FA91E370F0061768B0 /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57F4D977AC4289A6145383C9 /* InstanceRequest.swift */; }; 829853126CDB7464599AFC85 /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; 832C9ABB8DCF5340D796F5F8 /* ContextSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */; }; 83464EDC08380F5CE2190F30 /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; @@ -513,7 +513,7 @@ 5057BAB33984E3E33469452B /* Scope.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Scope.swift; sourceTree = ""; }; 50D6F2639990DD5BAD9578B0 /* OptionalsSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OptionalsSpec.swift; sourceTree = ""; }; 57A7E35B2B22650208F904B8 /* Weak.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Weak.swift; sourceTree = ""; }; - 57F4D977AC4289A6145383C9 /* InjectionRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InjectionRequest.swift; sourceTree = ""; }; + 57F4D977AC4289A6145383C9 /* InstanceRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRequest.swift; sourceTree = ""; }; 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Resolver+Injection.swift"; sourceTree = ""; }; 59111BE319C59E4CD6CF68CD /* Assembler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Assembler.swift; sourceTree = ""; }; 5AB605ED0F735221D0EB1D5F /* Convenience.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Convenience.swift; sourceTree = ""; }; @@ -876,7 +876,7 @@ children = ( 0E0B580B43E1891812C97209 /* Binding.swift */, 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */, - 57F4D977AC4289A6145383C9 /* InjectionRequest.swift */, + 57F4D977AC4289A6145383C9 /* InstanceRequest.swift */, 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */, 424C647FF08FCB7C2A54E085 /* PropertyWrapper.swift */, 73B4B777290FF5D38A8914CC /* Reference.swift */, @@ -1440,7 +1440,7 @@ 996CCFE825834C7D3236E742 /* Container+TypeForwarding.swift in Sources */, B2FAD41F7726502822AF913B /* Container.swift in Sources */, 8B5927517B567B1DFAB5B935 /* ContextTranslator.swift in Sources */, - 1D17DBC27F25717BF7A87AF3 /* InjectionRequest.swift in Sources */, + 1D17DBC27F25717BF7A87AF3 /* InstanceRequest.swift in Sources */, 36D0B5EFA3B4AB4D464C9260 /* InstanceBuilder.swift in Sources */, A91EDAFBC3606EDFBD739899 /* InstanceWrapper.swift in Sources */, 98322F9371E1A8461BC614D1 /* Matchable.swift in Sources */, @@ -1666,7 +1666,7 @@ BD9B57E26722C80B7EF990DB /* Container+TypeForwarding.swift in Sources */, DB74F17CDFF4886B9C38AD14 /* Container.swift in Sources */, DD5E3AF2B5FCE5E81EBDF606 /* ContextTranslator.swift in Sources */, - 76FB9AFE299316E7F3F4C3BB /* InjectionRequest.swift in Sources */, + 76FB9AFE299316E7F3F4C3BB /* InstanceRequest.swift in Sources */, 157A967F9BAD0B8DAFAC2A36 /* InstanceBuilder.swift in Sources */, 57BFBA2077E70DC1C2FE796C /* InstanceWrapper.swift in Sources */, 293985649250DF270DC89135 /* Matchable.swift in Sources */, @@ -1713,7 +1713,7 @@ 283C77045DA55C2134EC9C48 /* Container+TypeForwarding.swift in Sources */, 58ABEE0321A3061048B65EA2 /* Container.swift in Sources */, F06DEB671A4B85ABB0E96E51 /* ContextTranslator.swift in Sources */, - 027015812E961322FE3D942B /* InjectionRequest.swift in Sources */, + 027015812E961322FE3D942B /* InstanceRequest.swift in Sources */, C6E443EAD892B0B69DA61144 /* InstanceBuilder.swift in Sources */, 389C54E04DD794DA4F648571 /* InstanceWrapper.swift in Sources */, 87FEAEF562B99522083CB87D /* Matchable.swift in Sources */, @@ -1761,7 +1761,7 @@ 3A0B409E840B44B281DB3C54 /* Container+TypeForwarding.swift in Sources */, 0622539110A7430776A307C7 /* Container.swift in Sources */, D1DF4740A9D86362B63104B8 /* ContextTranslator.swift in Sources */, - 826D63FA91E370F0061768B0 /* InjectionRequest.swift in Sources */, + 826D63FA91E370F0061768B0 /* InstanceRequest.swift in Sources */, 16393BD60FDDD38B5A977C55 /* InstanceBuilder.swift in Sources */, 98ACB1A09194572A946CA90D /* InstanceWrapper.swift in Sources */, 5ED8A7D19F21FA686215F72C /* Matchable.swift in Sources */, From cc82f5d085731e8f2381cba385308a7163e79c3a Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Sat, 24 Aug 2019 10:17:43 +0200 Subject: [PATCH 206/239] Do not use builders during tree construction --- Sources/2.0 API/Container.swift | 4 +- Sources/2.0 API/ServiceEntry.swift | 2 +- Sources/3.0 API/BinderEnvironment.swift | 82 +++++++++---------- Sources/3.0 API/BindingBuilder.swift | 23 ++++++ Sources/3.0 API/PartialBindingBuilder.swift | 31 ------- Sources/3.0 API/ScopedBinding.swift | 6 +- Sources/3.0 API/SimpleBinding.swift | 6 +- Sources/3.0 API/TypeBinder.swift | 12 +-- .../Core/{Binding.swift => AnyBinding.swift} | 3 +- Sources/Core/Swinject.swift | 8 +- Sources/Core/SwinjectContainer.swift | 10 +-- Sources/Core/SwinjectTree.swift | 4 +- Swinject.xcodeproj/project.pbxproj | 78 +++++++++++------- Templates/BinderVariation.swift | 2 +- Templates/SwiftCode.swifttemplate | 2 +- 15 files changed, 144 insertions(+), 129 deletions(-) create mode 100644 Sources/3.0 API/BindingBuilder.swift delete mode 100644 Sources/3.0 API/PartialBindingBuilder.swift rename Sources/Core/{Binding.swift => AnyBinding.swift} (93%) diff --git a/Sources/2.0 API/Container.swift b/Sources/2.0 API/Container.swift index 54bdee9d..192dfd11 100644 --- a/Sources/2.0 API/Container.swift +++ b/Sources/2.0 API/Container.swift @@ -24,9 +24,9 @@ public final class Container { let parent: Container? let defaultScope: AnyScope? let defaultMakeRef: ReferenceMaker - var bindings = [BindingKey: Binding]() + var bindings = [BindingKey: AnyBinding]() var behaviors = [Behavior]() - var allBindings: [BindingKey: Binding] { + var allBindings: [BindingKey: AnyBinding] { return bindings.merging(parent?.allBindings ?? [:]) { mine, _ in mine } } diff --git a/Sources/2.0 API/ServiceEntry.swift b/Sources/2.0 API/ServiceEntry.swift index fb6554dd..04aecf60 100644 --- a/Sources/2.0 API/ServiceEntry.swift +++ b/Sources/2.0 API/ServiceEntry.swift @@ -69,7 +69,7 @@ public class ServiceEntry { } } -extension ServiceEntry: Binding { +extension ServiceEntry: AnyBinding { public var properties: BindingProperties { return BindingProperties( descriptor: key.descriptor, diff --git a/Sources/3.0 API/BinderEnvironment.swift b/Sources/3.0 API/BinderEnvironment.swift index 468988d6..340c4873 100644 --- a/Sources/3.0 API/BinderEnvironment.swift +++ b/Sources/3.0 API/BinderEnvironment.swift @@ -20,172 +20,172 @@ public func scoped(_ scope: AScope) -> ScopedEnvironment where A // swiftlint:disable line_length // swiftlint:disable identifier_name -public func instance(_ instance: Type) -> SomePartialBindingBuilder { +public func instance(_ instance: Type) -> SomeBindingBuilder { return SimpleBinding.Builder { _, _, _ in instance }.opaque } // sourcery:inline:BindingBuilders extension ContextedEnvironment { - public func provider(_ builder: @escaping () throws -> Type) -> SomePartialBindingBuilder { + public func provider(_ builder: @escaping () throws -> Type) -> SomeBindingBuilder { return SimpleBinding.Builder { _, _, _ in try builder() }.opaque } - public func provider(_ builder: @escaping (Resolver) throws -> Type) -> SomePartialBindingBuilder { + public func provider(_ builder: @escaping (Resolver) throws -> Type) -> SomeBindingBuilder { return SimpleBinding.Builder { r, _, _ in try builder(r) }.opaque } - public func provider(_ builder: @escaping (Resolver, Context) throws -> Type) -> SomePartialBindingBuilder { + public func provider(_ builder: @escaping (Resolver, Context) throws -> Type) -> SomeBindingBuilder { return SimpleBinding.Builder { r, c, _ in try builder(r, c) }.opaque } - public func factory(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SomePartialBindingBuilder { + public func factory(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SomeBindingBuilder { return SimpleBinding.Builder { r, c, a in try builder(r, c, a) }.opaque } - public func factory(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SomePartialBindingBuilder where Arg1: Hashable { + public func factory(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable { return SimpleBinding.Builder> { r, c, a in try builder(r, c, a.arg1) }.opaque } - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SomePartialBindingBuilder { + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SomeBindingBuilder { return SimpleBinding.Builder { r, c, a in try builder(r, c, a.0, a.1) }.opaque } - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SomePartialBindingBuilder where Arg1: Hashable, Arg2: Hashable { + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable { return SimpleBinding.Builder> { r, c, a in try builder(r, c, a.arg1, a.arg2) }.opaque } - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SomePartialBindingBuilder { + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingBuilder { return SimpleBinding.Builder { r, c, a in try builder(r, c, a.0, a.1, a.2) }.opaque } - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SomePartialBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { return SimpleBinding.Builder> { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3) }.opaque } - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomePartialBindingBuilder { + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingBuilder { return SimpleBinding.Builder { r, c, a in try builder(r, c, a.0, a.1, a.2, a.3) }.opaque } - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomePartialBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { return SimpleBinding.Builder> { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3, a.arg4) }.opaque } - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomePartialBindingBuilder { + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingBuilder { return SimpleBinding.Builder { r, c, a in try builder(r, c, a.0, a.1, a.2, a.3, a.4) }.opaque } - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomePartialBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { return SimpleBinding.Builder> { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) }.opaque } } extension ScopedEnvironment { - public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping () throws -> Type) -> SomePartialBindingBuilder { + public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping () throws -> Type) -> SomeBindingBuilder { return ScopedBinding.Builder(scope, ref) { _, _, _ in try builder() }.opaque } - public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver) throws -> Type) -> SomePartialBindingBuilder { + public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver) throws -> Type) -> SomeBindingBuilder { return ScopedBinding.Builder(scope, ref) { r, _, _ in try builder(r) }.opaque } - public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context) throws -> Type) -> SomePartialBindingBuilder { + public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context) throws -> Type) -> SomeBindingBuilder { return ScopedBinding.Builder(scope, ref) { r, c, _ in try builder(r, c) }.opaque } - public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SomePartialBindingBuilder where Arg1: Hashable { + public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable { return ScopedBinding.Builder>(scope, ref) { r, c, a in try builder(r, c, a.arg1) }.opaque } - public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SomePartialBindingBuilder where Arg1: Hashable, Arg2: Hashable { + public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable { return ScopedBinding.Builder>(scope, ref) { r, c, a in try builder(r, c, a.arg1, a.arg2) }.opaque } - public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SomePartialBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { return ScopedBinding.Builder>(scope, ref) { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3) }.opaque } - public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomePartialBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { return ScopedBinding.Builder>(scope, ref) { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3, a.arg4) }.opaque } - public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomePartialBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { return ScopedBinding.Builder>(scope, ref) { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) }.opaque } } -public func provider(_ builder: @escaping () throws -> Type) -> SomePartialBindingBuilder { +public func provider(_ builder: @escaping () throws -> Type) -> SomeBindingBuilder { return SimpleBinding.Builder { _, _, _ in try builder() }.opaque } -public func provider(_ builder: @escaping (Resolver) throws -> Type) -> SomePartialBindingBuilder { +public func provider(_ builder: @escaping (Resolver) throws -> Type) -> SomeBindingBuilder { return SimpleBinding.Builder { r, _, _ in try builder(r) }.opaque } -public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> SomePartialBindingBuilder { +public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> SomeBindingBuilder { return SimpleBinding.Builder { r, _, a in try builder(r, a) }.opaque } -public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> SomePartialBindingBuilder where Arg1: Hashable { +public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable { return SimpleBinding.Builder> { r, _, a in try builder(r, a.arg1) }.opaque } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SomePartialBindingBuilder { +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SomeBindingBuilder { return SimpleBinding.Builder { r, _, a in try builder(r, a.0, a.1) }.opaque } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SomePartialBindingBuilder where Arg1: Hashable, Arg2: Hashable { +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable { return SimpleBinding.Builder> { r, _, a in try builder(r, a.arg1, a.arg2) }.opaque } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SomePartialBindingBuilder { +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingBuilder { return SimpleBinding.Builder { r, _, a in try builder(r, a.0, a.1, a.2) }.opaque } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SomePartialBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { return SimpleBinding.Builder> { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3) }.opaque } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomePartialBindingBuilder { +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingBuilder { return SimpleBinding.Builder { r, _, a in try builder(r, a.0, a.1, a.2, a.3) }.opaque } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomePartialBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { return SimpleBinding.Builder> { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3, a.arg4) }.opaque } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomePartialBindingBuilder { +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingBuilder { return SimpleBinding.Builder { r, _, a in try builder(r, a.0, a.1, a.2, a.3, a.4) }.opaque } -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomePartialBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { +public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { return SimpleBinding.Builder> { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) }.opaque } -public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping () throws -> Type) -> SomePartialBindingBuilder { +public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping () throws -> Type) -> SomeBindingBuilder { return ScopedBinding.Builder(.root, ref) { _, _, _ in try builder() }.opaque } -public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver) throws -> Type) -> SomePartialBindingBuilder { +public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver) throws -> Type) -> SomeBindingBuilder { return ScopedBinding.Builder(.root, ref) { r, _, _ in try builder(r) }.opaque } -public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1) throws -> Type) -> SomePartialBindingBuilder where Arg1: Hashable { +public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable { return ScopedBinding.Builder>(.root, ref) { r, _, a in try builder(r, a.arg1) }.opaque } -public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SomePartialBindingBuilder where Arg1: Hashable, Arg2: Hashable { +public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable { return ScopedBinding.Builder>(.root, ref) { r, _, a in try builder(r, a.arg1, a.arg2) }.opaque } -public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SomePartialBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { +public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { return ScopedBinding.Builder>(.root, ref) { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3) }.opaque } -public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomePartialBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { +public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { return ScopedBinding.Builder>(.root, ref) { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3, a.arg4) }.opaque } -public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomePartialBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { +public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { return ScopedBinding.Builder>(.root, ref) { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) }.opaque } diff --git a/Sources/3.0 API/BindingBuilder.swift b/Sources/3.0 API/BindingBuilder.swift new file mode 100644 index 00000000..dba8914b --- /dev/null +++ b/Sources/3.0 API/BindingBuilder.swift @@ -0,0 +1,23 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +public protocol BindingBuilder { + associatedtype BoundType + func makeBinding(with properties: BindingProperties) -> AnyBinding +} + +public struct SomeBindingBuilder: BindingBuilder, AnyOpaque { + let anyActual: Any + fileprivate let _makeBinding: (BindingProperties) -> AnyBinding + + public func makeBinding(with properties: BindingProperties) -> AnyBinding { + return _makeBinding(properties) + } +} + +public extension BindingBuilder { + var opaque: SomeBindingBuilder { + return SomeBindingBuilder(anyActual: self) { self.makeBinding(with: $0) } + } +} diff --git a/Sources/3.0 API/PartialBindingBuilder.swift b/Sources/3.0 API/PartialBindingBuilder.swift deleted file mode 100644 index 067fcee6..00000000 --- a/Sources/3.0 API/PartialBindingBuilder.swift +++ /dev/null @@ -1,31 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -public protocol PartialBindingBuilder { - associatedtype BoundType - func makeBinding(with properties: BindingProperties) -> Binding -} - -public struct SomePartialBindingBuilder: PartialBindingBuilder, AnyOpaque { - let anyActual: Any - fileprivate let _makeBinding: (BindingProperties) -> Binding - - public func makeBinding(with properties: BindingProperties) -> Binding { - return _makeBinding(properties) - } -} - -public extension PartialBindingBuilder { - var opaque: SomePartialBindingBuilder { - return SomePartialBindingBuilder(anyActual: self) { self.makeBinding(with: $0) } - } -} - -struct FinalBindingBuilder: AnyBindingBuilder { - let binidngFactory: () -> Binding - - func makeBinding() -> Binding { - return binidngFactory() - } -} diff --git a/Sources/3.0 API/ScopedBinding.swift b/Sources/3.0 API/ScopedBinding.swift index 7221d98a..af66b56b 100644 --- a/Sources/3.0 API/ScopedBinding.swift +++ b/Sources/3.0 API/ScopedBinding.swift @@ -10,7 +10,7 @@ struct ScopedBinding { let makeRef: ReferenceMaker } -extension ScopedBinding: Binding { +extension ScopedBinding: AnyBinding { func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any { return try scope .registry(for: context) @@ -51,10 +51,10 @@ extension ScopedBinding.Builder: InstanceBuilder { } } -extension ScopedBinding.Builder: PartialBindingBuilder { +extension ScopedBinding.Builder: BindingBuilder { typealias BoundType = Type - func makeBinding(with properties: BindingProperties) -> Binding { + func makeBinding(with properties: BindingProperties) -> AnyBinding { return ScopedBinding( key: BindingKey(descriptor: properties.descriptor, contextType: Context.self, argumentType: Argument.self), properties: properties, diff --git a/Sources/3.0 API/SimpleBinding.swift b/Sources/3.0 API/SimpleBinding.swift index 3eb415ed..4a57cf85 100644 --- a/Sources/3.0 API/SimpleBinding.swift +++ b/Sources/3.0 API/SimpleBinding.swift @@ -8,7 +8,7 @@ struct SimpleBinding { let builder: AnyInstanceBuilder } -extension SimpleBinding: Binding { +extension SimpleBinding: AnyBinding { func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any { return try builder.makeInstance(arg: arg, context: context, resolver: resolver) } @@ -32,10 +32,10 @@ extension SimpleBinding.Builder: InstanceBuilder { } } -extension SimpleBinding.Builder: PartialBindingBuilder { +extension SimpleBinding.Builder: BindingBuilder { typealias BoundType = Type - func makeBinding(with properties: BindingProperties) -> Binding { + func makeBinding(with properties: BindingProperties) -> AnyBinding { return SimpleBinding( key: BindingKey(descriptor: properties.descriptor, contextType: Context.self, argumentType: Argument.self), properties: properties, diff --git a/Sources/3.0 API/TypeBinder.swift b/Sources/3.0 API/TypeBinder.swift index fd0a015a..86f6525c 100644 --- a/Sources/3.0 API/TypeBinder.swift +++ b/Sources/3.0 API/TypeBinder.swift @@ -21,21 +21,21 @@ public func bind(_: Type.Type, tagged tag: String? = nil, overrides: Bool public extension TypeBinder { func with( _ builder: Builder - ) -> AnyBindingBuilder where Builder: PartialBindingBuilder, Builder.BoundType == BoundType { - return FinalBindingBuilder { builder.makeBinding(with: self.properties) } + ) -> AnyBinding where Builder: BindingBuilder, Builder.BoundType == BoundType { + return builder.makeBinding(with: properties) } - func with(_ value: BoundType) -> AnyBindingBuilder { - return FinalBindingBuilder { instance(value).makeBinding(with: self.properties) } + func with(_ value: BoundType) -> AnyBinding { + return instance(value).makeBinding(with: properties) } } public func & ( lhs: TypeBinder, rhs: Builder -) -> AnyBindingBuilder where Builder: PartialBindingBuilder, Builder.BoundType == BoundType { +) -> AnyBinding where Builder: BindingBuilder, Builder.BoundType == BoundType { return lhs.with(rhs) } -public func & (lhs: TypeBinder, rhs: BoundType) -> AnyBindingBuilder { +public func & (lhs: TypeBinder, rhs: BoundType) -> AnyBinding { return lhs.with(rhs) } diff --git a/Sources/Core/Binding.swift b/Sources/Core/AnyBinding.swift similarity index 93% rename from Sources/Core/Binding.swift rename to Sources/Core/AnyBinding.swift index e119827f..fe4b3128 100644 --- a/Sources/Core/Binding.swift +++ b/Sources/Core/AnyBinding.swift @@ -32,7 +32,8 @@ extension BindingKey { } } -public protocol Binding { +// TODO: Can We make this internal? +public protocol AnyBinding: SwinjectEntry { var key: BindingKey { get } var properties: BindingProperties { get } func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any diff --git a/Sources/Core/Swinject.swift b/Sources/Core/Swinject.swift index c262d667..b5d3c567 100644 --- a/Sources/Core/Swinject.swift +++ b/Sources/Core/Swinject.swift @@ -18,7 +18,7 @@ public struct Swinject { extension Swinject: Resolver { public func resolve(_ request: InstanceRequest) throws -> Type { - let binding: Binding + let binding: AnyBinding do { binding = try findBinding(for: request) } catch let error as NoBinding { @@ -45,7 +45,7 @@ extension Swinject { return custom.init(resolver: with(stack: []), request: request) as? Type } - private func findTranslator(for binding: Binding) throws -> AnyContextTranslator { + private func findTranslator(for binding: AnyBinding) throws -> AnyContextTranslator { return try allTranslators .filter { binding.key.matches(contextType: $0.targetType) } .first ?? { throw NoContextTranslator() }() @@ -73,7 +73,7 @@ extension Swinject { return (try? findBinding(for: request)) != nil } - private func findBinding(for request: AnyInstanceRequest) throws -> Binding { + private func findBinding(for request: AnyInstanceRequest) throws -> AnyBinding { let bindings = translatableKeys(for: request).compactMap { container.bindings[$0] } if bindings.isEmpty { throw NoBinding() } if bindings.count > 1 { throw MultipleBindings() } @@ -81,7 +81,7 @@ extension Swinject { } private func makeInstance( - from binding: Binding, context: Context, arg: Argument + from binding: AnyBinding, context: Context, arg: Argument ) throws -> Type { return try binding.instance(arg: arg, context: context, resolver: self) as? Type ?? { throw SwinjectError() }() } diff --git a/Sources/Core/SwinjectContainer.swift b/Sources/Core/SwinjectContainer.swift index 190214ec..6b9ca8b9 100644 --- a/Sources/Core/SwinjectContainer.swift +++ b/Sources/Core/SwinjectContainer.swift @@ -3,7 +3,7 @@ // struct SwinjectContainer { - let bindings: [BindingKey: Binding] + let bindings: [BindingKey: AnyBinding] let translators: [AnyContextTranslator] struct Builder { @@ -39,22 +39,22 @@ extension SwinjectContainer.Builder { extension SwinjectContainer.Builder { private struct BindingEntry { - let binding: Binding + let binding: AnyBinding let key: BindingKey let properties: BindingProperties let canOverride: Bool let canOverrideSilently: Bool } - private func collectBindings() throws -> [BindingKey: Binding] { + private func collectBindings() throws -> [BindingKey: AnyBinding] { return try collectBindingEntries(from: tree, canOverrideSilently: properties.allowsSilentOverride) - .reduce(into: [BindingKey: Binding]()) { dict, entry in + .reduce(into: [BindingKey: AnyBinding]()) { dict, entry in try checkOverrideRules(for: entry, beingAddedTo: dict) dict[entry.key] = entry.binding } } - private func checkOverrideRules(for entry: BindingEntry, beingAddedTo dict: [BindingKey: Binding]) throws { + private func checkOverrideRules(for entry: BindingEntry, beingAddedTo dict: [BindingKey: AnyBinding]) throws { if !entry.canOverride, entry.properties.overrides { throw OverrideNotAllowed() } diff --git a/Sources/Core/SwinjectTree.swift b/Sources/Core/SwinjectTree.swift index 2ea78bf7..443da165 100644 --- a/Sources/Core/SwinjectTree.swift +++ b/Sources/Core/SwinjectTree.swift @@ -3,7 +3,7 @@ // public struct SwinjectTree { - let bindings: [Binding] + let bindings: [AnyBinding] let modules: [ModuleInclusion] let translators: [AnyContextTranslator] } @@ -40,7 +40,7 @@ extension SwinjectTreeBuilder { public static func buildFunction(_ input: [SwinjectEntry]) -> SwinjectTree { let entries = input.flatMap(unpack) return SwinjectTree( - bindings: entries.compactMap { $0 as? AnyBindingBuilder }.map { $0.makeBinding() }, + bindings: entries.compactMap { $0 as? AnyBinding }, modules: entries.compactMap { $0 as? ModuleInclusion }, translators: entries.compactMap { $0 as? AnyContextTranslator } ) diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index f218fe58..1fcf4bd5 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -53,7 +53,7 @@ 283C77045DA55C2134EC9C48 /* Container+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F446D6BD4C44E16A1D608BFB /* Container+TypeForwarding.swift */; }; 290C9E9420A1EE30456476CB /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59111BE319C59E4CD6CF68CD /* Assembler.swift */; }; 293985649250DF270DC89135 /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; - 2A6D2874ADB24B08DAE1EC04 /* PartialBindingBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = A367B4D6F7E5331620430ECF /* PartialBindingBuilder.swift */; }; + 2A6D2874ADB24B08DAE1EC04 /* BindingBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = A367B4D6F7E5331620430ECF /* BindingBuilder.swift */; }; 2AA60B7E6EBA9EC6BE92D7CB /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; 2B506344F37CE5F5C5C02C05 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; 2C352AAD1AC7D82A4A059046 /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; @@ -84,7 +84,7 @@ 3CEF021295AD9AF9BF26B71E /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; 3DEFB7CA42D9EFF0B4FBC0F4 /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 38BCCF3F950869BD1891F7A8 /* Swinject.framework */; }; 3EC8383BEAC339595CF7F927 /* Resolver+FunctionCallApi.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 176824B29DD1A0DAA5CBD241 /* Resolver+FunctionCallApi.swifttemplate */; }; - 3F8F5645D6D37FCEC1D89393 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B580B43E1891812C97209 /* Binding.swift */; }; + 3F8F5645D6D37FCEC1D89393 /* AnyBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B580B43E1891812C97209 /* AnyBinding.swift */; }; 401592294E5D528379BE1AB2 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62682D6ED38742996624B041 /* BasicAssembly.swift */; }; 41C7340BFD2EB66359772733 /* Resolver+LegacyApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A784E2DEC7691D14DDBECD8 /* Resolver+LegacyApi.swift */; }; 42FE916C1593A9289E1A28BC /* InjectionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 670DB253ECD5CE1468A7F2E3 /* InjectionSpec.swift */; }; @@ -130,7 +130,7 @@ 628EBFBA0031B1FA2E29F583 /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 351C4221896DDB8572BD6CB5 /* Person.swift */; }; 63528D45A548DD58D748D54C /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; 640F7A55D9A671FA112C8083 /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; - 658AEDC8D802A6788E959E0C /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B580B43E1891812C97209 /* Binding.swift */; }; + 658AEDC8D802A6788E959E0C /* AnyBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B580B43E1891812C97209 /* AnyBinding.swift */; }; 68C95FCB0D345CA3BA24D320 /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; 68D828A3C583DDD28CFE882B /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; 6922AE734E84B515C94D9480 /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; @@ -141,7 +141,7 @@ 6A967AE5710606998C2BE070 /* PropertyWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 424C647FF08FCB7C2A54E085 /* PropertyWrapper.swift */; }; 6BB1E24C1CE55C9F6EA6CC28 /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C765B92B00C0AC8625BB4AC9 /* Quick.framework */; }; 6C01E868DE44BD396D94858B /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; - 6CFE30E5595611778893D147 /* PartialBindingBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = A367B4D6F7E5331620430ECF /* PartialBindingBuilder.swift */; }; + 6CFE30E5595611778893D147 /* BindingBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = A367B4D6F7E5331620430ECF /* BindingBuilder.swift */; }; 6DA49F84E2592B32F81F268B /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BFF4BA99493C54260878C4 /* ObjectScope.swift */; }; 6DD80811E5FD658CAFEEA647 /* CIrcularitySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 118ABC654C4144496848AD74 /* CIrcularitySpec.swift */; }; 6F6FAD0EEF84580DD53BB755 /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1C58FC14EEA170B0DC079DE4 /* Quick.framework */; }; @@ -160,11 +160,20 @@ 751F545653B0F1E30341C312 /* OverrideSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86C18DDD83715886DF7F1818 /* OverrideSpec.swift */; }; 75D74C8C25EDACF5A7A75A5C /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; 76FB9AFE299316E7F3F4C3BB /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57F4D977AC4289A6145383C9 /* InstanceRequest.swift */; }; - 773C6DDC23111956007A40BF /* BindingBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773C6DDB23111956007A40BF /* BindingBuilder.swift */; }; - 773C6DDD23111956007A40BF /* BindingBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773C6DDB23111956007A40BF /* BindingBuilder.swift */; }; - 773C6DDE23111956007A40BF /* BindingBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773C6DDB23111956007A40BF /* BindingBuilder.swift */; }; + 773BE491231124AD000AA1A9 /* SomeBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773C6DDB23111956007A40BF /* SomeBinding.swift */; }; + 773C6DDC23111956007A40BF /* SomeBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773C6DDB23111956007A40BF /* SomeBinding.swift */; }; + 773C6DDD23111956007A40BF /* SomeBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773C6DDB23111956007A40BF /* SomeBinding.swift */; }; + 773C6DDE23111956007A40BF /* SomeBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773C6DDB23111956007A40BF /* SomeBinding.swift */; }; 778D9AB6470D4280254AC140 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; 77BF219EAB4FC8475943CECC /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6D434EB4C13CF9D9FA6D80CB /* Swinject.framework */; }; + 77ED80052311221600AC48F9 /* ValueRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77ED80042311221600AC48F9 /* ValueRequest.swift */; }; + 77ED80062311221600AC48F9 /* ValueRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77ED80042311221600AC48F9 /* ValueRequest.swift */; }; + 77ED80072311221600AC48F9 /* ValueRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77ED80042311221600AC48F9 /* ValueRequest.swift */; }; + 77ED80082311221600AC48F9 /* ValueRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77ED80042311221600AC48F9 /* ValueRequest.swift */; }; + 77ED800A2311231500AC48F9 /* Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77ED80092311231500AC48F9 /* Arguments.swift */; }; + 77ED800B2311231500AC48F9 /* Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77ED80092311231500AC48F9 /* Arguments.swift */; }; + 77ED800C2311231500AC48F9 /* Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77ED80092311231500AC48F9 /* Arguments.swift */; }; + 77ED800D2311231500AC48F9 /* Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77ED80092311231500AC48F9 /* Arguments.swift */; }; 789BF74652A2424EB8F7EF47 /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 7A7032384E07DAD308D4F70A /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 8B9785AAE94A5447FA307242 /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 7A956FAB419F74D7EB9CAD0B /* Opaque.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E7DC2C5AA87B18BD465EB77 /* Opaque.swift */; }; @@ -247,7 +256,7 @@ B00627BABCF9181C7B58609E /* LinuxConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 938425B216B78A06EC10504A /* LinuxConfig.swift */; }; B06306286CC5EA66C88F24D1 /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 38BCCF3F950869BD1891F7A8 /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; B0B139FADA6AE07C79847EBA /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61EE5DDBE705B47AFC9A6986 /* LoadAwareAssembly.swift */; }; - B0B65F494A88CDEFE8EF79F6 /* PartialBindingBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = A367B4D6F7E5331620430ECF /* PartialBindingBuilder.swift */; }; + B0B65F494A88CDEFE8EF79F6 /* BindingBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = A367B4D6F7E5331620430ECF /* BindingBuilder.swift */; }; B293894FEB67831DDA5F000E /* Reference.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73B4B777290FF5D38A8914CC /* Reference.swift */; }; B2FAD41F7726502822AF913B /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42490D1D0C395951243F5CFF /* Container.swift */; }; B3062AB22373AD23052B61DF /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; @@ -299,7 +308,7 @@ D0D71F9C22A0EE82B6E4F61A /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 74DE57FB3E8228904E6FE0D7 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; D13208E63523A97A0B840283 /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BC5108ED11A3A3084D864CC /* Animal.swift */; }; D1DF4740A9D86362B63104B8 /* ContextTranslator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */; }; - D2BAE1CB997A4D052CB8EFC8 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B580B43E1891812C97209 /* Binding.swift */; }; + D2BAE1CB997A4D052CB8EFC8 /* AnyBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B580B43E1891812C97209 /* AnyBinding.swift */; }; D3FB9F7B3F791A83FF86205C /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 273FB7A6277E0841E1570990 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; D3FD513CDD70AF674C453B83 /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96AEC72A42A227A50CF9845B /* Circularity.swift */; }; D4936DC1A47A8C85325FB52E /* Resolver+LegacyApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A784E2DEC7691D14DDBECD8 /* Resolver+LegacyApi.swift */; }; @@ -348,11 +357,11 @@ F7CD04FB09FC7F18E9E001CF /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; F88700BAAFFB47B1BD4D3BFA /* Weak.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57A7E35B2B22650208F904B8 /* Weak.swift */; }; F8EB47A631D482A0D7B621DE /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; - F9A4BF18B0085B7DCD3440EC /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B580B43E1891812C97209 /* Binding.swift */; }; + F9A4BF18B0085B7DCD3440EC /* AnyBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B580B43E1891812C97209 /* AnyBinding.swift */; }; FA805A162E989A22990B99AA /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; FC339851D7EEE4D17178CC1F /* Weak.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57A7E35B2B22650208F904B8 /* Weak.swift */; }; FD7B2663F2F931B78EB330EE /* Resolver+LegacyApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A784E2DEC7691D14DDBECD8 /* Resolver+LegacyApi.swift */; }; - FD8BB4CC8DA0E560E39FA491 /* PartialBindingBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = A367B4D6F7E5331620430ECF /* PartialBindingBuilder.swift */; }; + FD8BB4CC8DA0E560E39FA491 /* BindingBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = A367B4D6F7E5331620430ECF /* BindingBuilder.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -476,7 +485,7 @@ 0CA449690AE00F6300DE8ACA /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 0D8B3342E2AC3236F12072F5 /* RetrievalSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RetrievalSpec.swift; sourceTree = ""; }; 0DC67CB109091002AB433A46 /* SwinjectTests.xctest */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.cfbundle; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - 0E0B580B43E1891812C97209 /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; + 0E0B580B43E1891812C97209 /* AnyBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnyBinding.swift; sourceTree = ""; }; 0E7DC2C5AA87B18BD465EB77 /* Opaque.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Opaque.swift; sourceTree = ""; }; 10480F2154EAA0414D4C1F55 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */ = {isa = PBXFileReference; lastKnownFileType = text.yaml; path = .swiftlint.yml; sourceTree = ""; }; @@ -534,7 +543,9 @@ 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.CustomStringConvertible.swift; sourceTree = ""; }; 74DE57FB3E8228904E6FE0D7 /* Swinject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Swinject.h; sourceTree = ""; }; 75BE3AE3E30DFE42A919D825 /* ModulesSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModulesSpec.swift; sourceTree = ""; }; - 773C6DDB23111956007A40BF /* BindingBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingBuilder.swift; sourceTree = ""; }; + 773C6DDB23111956007A40BF /* SomeBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SomeBinding.swift; sourceTree = ""; }; + 77ED80042311221600AC48F9 /* ValueRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ValueRequest.swift; sourceTree = ""; }; + 77ED80092311231500AC48F9 /* Arguments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Arguments.swift; sourceTree = ""; }; 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ServiceEntry+TypeForwarding.swift"; sourceTree = ""; }; 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextTranslator.swift; sourceTree = ""; }; 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistry.swift; sourceTree = ""; }; @@ -551,7 +562,7 @@ 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistryKey.swift; sourceTree = ""; }; A20C1319AF31EC7F8E6945FE /* SwinjectTests.xctest */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.cfbundle; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; A3586A4987B7C7C8122D674E /* SwinjectError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectError.swift; sourceTree = ""; }; - A367B4D6F7E5331620430ECF /* PartialBindingBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PartialBindingBuilder.swift; sourceTree = ""; }; + A367B4D6F7E5331620430ECF /* BindingBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingBuilder.swift; sourceTree = ""; }; A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Resolver.swift; sourceTree = ""; }; ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Circularity.swift; sourceTree = ""; }; ADA1541ABC1365DFD7E3377F /* Food.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Food.swift; sourceTree = ""; }; @@ -680,7 +691,7 @@ children = ( 0E7DC2C5AA87B18BD465EB77 /* Opaque.swift */, B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */, - A367B4D6F7E5331620430ECF /* PartialBindingBuilder.swift */, + A367B4D6F7E5331620430ECF /* BindingBuilder.swift */, 419FB96A1F4B72278B9A6665 /* InstanceBuilder.swift */, B9F626B9D3E547621787E4D7 /* Resolver+FunctionCall.swift */, 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */, @@ -745,7 +756,9 @@ 773C6DDA23111910007A40BF /* 3.1 API */ = { isa = PBXGroup; children = ( - 773C6DDB23111956007A40BF /* BindingBuilder.swift */, + 773C6DDB23111956007A40BF /* SomeBinding.swift */, + 77ED80042311221600AC48F9 /* ValueRequest.swift */, + 77ED80092311231500AC48F9 /* Arguments.swift */, ); path = "3.1 API"; sourceTree = ""; @@ -874,7 +887,7 @@ FCA9C6262A4D071C8E7EEBD0 /* Core */ = { isa = PBXGroup; children = ( - 0E0B580B43E1891812C97209 /* Binding.swift */, + 0E0B580B43E1891812C97209 /* AnyBinding.swift */, 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */, 57F4D977AC4289A6145383C9 /* InstanceRequest.swift */, 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */, @@ -1433,9 +1446,10 @@ F504C2ABEFCFFCAC8B858751 /* Assembly.swift in Sources */, 703F8B3AD111A6CFAFF66A49 /* Behavior.swift in Sources */, ADCF273AF041E74DBEC2C13A /* BinderEnvironment.swift in Sources */, - 658AEDC8D802A6788E959E0C /* Binding.swift in Sources */, - B0B65F494A88CDEFE8EF79F6 /* PartialBindingBuilder.swift in Sources */, + 658AEDC8D802A6788E959E0C /* AnyBinding.swift in Sources */, + B0B65F494A88CDEFE8EF79F6 /* BindingBuilder.swift in Sources */, 694C2C891D581371B2B051D7 /* Container+Logging.swift in Sources */, + 77ED80062311221600AC48F9 /* ValueRequest.swift in Sources */, AAD8D0551B8A26A9B22AECEC /* Container+Registration.swift in Sources */, 996CCFE825834C7D3236E742 /* Container+TypeForwarding.swift in Sources */, B2FAD41F7726502822AF913B /* Container.swift in Sources */, @@ -1452,7 +1466,7 @@ D9084C826F7A798508CD66F5 /* Resolver+Injection.swift in Sources */, D4936DC1A47A8C85325FB52E /* Resolver+LegacyApi.swift in Sources */, 8016512839FE61EC3127E489 /* Resolver.swift in Sources */, - 773C6DDD23111956007A40BF /* BindingBuilder.swift in Sources */, + 773C6DDD23111956007A40BF /* SomeBinding.swift in Sources */, 68C95FCB0D345CA3BA24D320 /* Scope.swift in Sources */, BB571B9A78FC53231A18E18C /* ScopeRegistry.swift in Sources */, 593B93BA2EE3FE4418A1C579 /* ScopeRegistryKey.swift in Sources */, @@ -1465,6 +1479,7 @@ 3328937B7BBFA77FA3CD303E /* SwinjectContainer.swift in Sources */, 020DA1718FCC68D889FB5A5F /* SwinjectError.swift in Sources */, CF4EBB60C21F8C503BCD7A29 /* SwinjectModule.swift in Sources */, + 77ED800B2311231500AC48F9 /* Arguments.swift in Sources */, 0D5C4A278A16AB3A163148AF /* SwinjectTree.swift in Sources */, AB864E029E996492ED4A3A52 /* TypeBinder.swift in Sources */, 49685AB40BEE856C62005C87 /* TypeDescriptor.swift in Sources */, @@ -1659,8 +1674,8 @@ 74E1FC692A27C56510363364 /* Assembly.swift in Sources */, FA805A162E989A22990B99AA /* Behavior.swift in Sources */, 6FCCBA9D2E4C2A225CB1A152 /* BinderEnvironment.swift in Sources */, - F9A4BF18B0085B7DCD3440EC /* Binding.swift in Sources */, - 6CFE30E5595611778893D147 /* PartialBindingBuilder.swift in Sources */, + F9A4BF18B0085B7DCD3440EC /* AnyBinding.swift in Sources */, + 6CFE30E5595611778893D147 /* BindingBuilder.swift in Sources */, 6A03ABEED82EF31E8E6E297E /* Container+Logging.swift in Sources */, A5E4C79F89E1A8AB3A4D8D6E /* Container+Registration.swift in Sources */, BD9B57E26722C80B7EF990DB /* Container+TypeForwarding.swift in Sources */, @@ -1670,7 +1685,9 @@ 157A967F9BAD0B8DAFAC2A36 /* InstanceBuilder.swift in Sources */, 57BFBA2077E70DC1C2FE796C /* InstanceWrapper.swift in Sources */, 293985649250DF270DC89135 /* Matchable.swift in Sources */, + 77ED80072311221600AC48F9 /* ValueRequest.swift in Sources */, B4B66D7251BDDE25D6D7FB3C /* ObjectScope.swift in Sources */, + 773BE491231124AD000AA1A9 /* SomeBinding.swift in Sources */, 5365FDFB2DDA6491F3049654 /* Opaque.swift in Sources */, 6A967AE5710606998C2BE070 /* PropertyWrapper.swift in Sources */, B293894FEB67831DDA5F000E /* Reference.swift in Sources */, @@ -1691,6 +1708,7 @@ 91E435894038C42335086FA8 /* SwinjectError.swift in Sources */, C637E97E193BB1DADDDC6C21 /* SwinjectModule.swift in Sources */, 0CE1126436F680F9684837E4 /* SwinjectTree.swift in Sources */, + 77ED800C2311231500AC48F9 /* Arguments.swift in Sources */, 4B9811CF0604946CCF323ED2 /* TypeBinder.swift in Sources */, 9CEE20BD42795D5E5F39BF20 /* TypeDescriptor.swift in Sources */, 8B711CBE6A5B86DC2D6CABDC /* UnboundScope.swift in Sources */, @@ -1706,9 +1724,10 @@ 3099172980F9E9143C0A1C20 /* Assembly.swift in Sources */, 2CB057F2A16DA462E0517AAB /* Behavior.swift in Sources */, 2DD6F290740EA69B3E73E0EA /* BinderEnvironment.swift in Sources */, - D2BAE1CB997A4D052CB8EFC8 /* Binding.swift in Sources */, - FD8BB4CC8DA0E560E39FA491 /* PartialBindingBuilder.swift in Sources */, + D2BAE1CB997A4D052CB8EFC8 /* AnyBinding.swift in Sources */, + FD8BB4CC8DA0E560E39FA491 /* BindingBuilder.swift in Sources */, 1ED6BD68D92F4FE60978EF22 /* Container+Logging.swift in Sources */, + 77ED80082311221600AC48F9 /* ValueRequest.swift in Sources */, CB0B308F3D3A831A28127462 /* Container+Registration.swift in Sources */, 283C77045DA55C2134EC9C48 /* Container+TypeForwarding.swift in Sources */, 58ABEE0321A3061048B65EA2 /* Container.swift in Sources */, @@ -1725,7 +1744,7 @@ C6D60E2AEC381998223145B2 /* Resolver+Injection.swift in Sources */, FD7B2663F2F931B78EB330EE /* Resolver+LegacyApi.swift in Sources */, 97C2EA47D7623AFD723AFE93 /* Resolver.swift in Sources */, - 773C6DDE23111956007A40BF /* BindingBuilder.swift in Sources */, + 773C6DDE23111956007A40BF /* SomeBinding.swift in Sources */, 2C352AAD1AC7D82A4A059046 /* Scope.swift in Sources */, 02556F149C9AAEF5CE353AC1 /* ScopeRegistry.swift in Sources */, 06F4CAB352B4F623FF7BD885 /* ScopeRegistryKey.swift in Sources */, @@ -1738,6 +1757,7 @@ 4D86550CC5C281A58B4A6F61 /* SwinjectContainer.swift in Sources */, 4DF3DC1CDD3C4948F9BDD3DF /* SwinjectError.swift in Sources */, 82299769BC637A14E7827DB0 /* SwinjectModule.swift in Sources */, + 77ED800D2311231500AC48F9 /* Arguments.swift in Sources */, 372F0061E762BF8FFF05457F /* SwinjectTree.swift in Sources */, 9425887520AC2DBDCBACB252 /* TypeBinder.swift in Sources */, AC470B4322599B0A076DD3FF /* TypeDescriptor.swift in Sources */, @@ -1754,9 +1774,10 @@ BB8FDF4F2A0AF8C1DA615854 /* Assembly.swift in Sources */, F7979BE4BE1B1C7101D15E61 /* Behavior.swift in Sources */, B5FF5DFE394B6B1BB930D88D /* BinderEnvironment.swift in Sources */, - 3F8F5645D6D37FCEC1D89393 /* Binding.swift in Sources */, - 2A6D2874ADB24B08DAE1EC04 /* PartialBindingBuilder.swift in Sources */, + 3F8F5645D6D37FCEC1D89393 /* AnyBinding.swift in Sources */, + 2A6D2874ADB24B08DAE1EC04 /* BindingBuilder.swift in Sources */, 999AF7221D3F2E1F83C3ACB1 /* Container+Logging.swift in Sources */, + 77ED80052311221600AC48F9 /* ValueRequest.swift in Sources */, 21285CED416F1317E993397A /* Container+Registration.swift in Sources */, 3A0B409E840B44B281DB3C54 /* Container+TypeForwarding.swift in Sources */, 0622539110A7430776A307C7 /* Container.swift in Sources */, @@ -1773,7 +1794,7 @@ CBE63031F33303F3E503CEF2 /* Resolver+Injection.swift in Sources */, 41C7340BFD2EB66359772733 /* Resolver+LegacyApi.swift in Sources */, BE94EF7BCF976A703F961389 /* Resolver.swift in Sources */, - 773C6DDC23111956007A40BF /* BindingBuilder.swift in Sources */, + 773C6DDC23111956007A40BF /* SomeBinding.swift in Sources */, 96EA0A5DF33F025EBE0B67D2 /* Scope.swift in Sources */, D861595482464ED95CF81922 /* ScopeRegistry.swift in Sources */, 920DE2CAB9895D10FAE48FBA /* ScopeRegistryKey.swift in Sources */, @@ -1786,6 +1807,7 @@ A6721BA534AD082E1E7C1D08 /* SwinjectContainer.swift in Sources */, 820307073A53AED47AC99B8D /* SwinjectError.swift in Sources */, 8E77B56EE7F90BF723600DDF /* SwinjectModule.swift in Sources */, + 77ED800A2311231500AC48F9 /* Arguments.swift in Sources */, 6922AE734E84B515C94D9480 /* SwinjectTree.swift in Sources */, EF79F0B3D497215D4BBBC038 /* TypeBinder.swift in Sources */, E3EABE098DBFB561A20632E3 /* TypeDescriptor.swift in Sources */, diff --git a/Templates/BinderVariation.swift b/Templates/BinderVariation.swift index 79e77eb1..295be62f 100644 --- a/Templates/BinderVariation.swift +++ b/Templates/BinderVariation.swift @@ -60,7 +60,7 @@ extension BinderVariation { } var returnType: String { - return "SomePartialBindingBuilder" + return "SomeBindingBuilder" } var actualReturnType: String { diff --git a/Templates/SwiftCode.swifttemplate b/Templates/SwiftCode.swifttemplate index a0d21f5c..b71bd266 100644 --- a/Templates/SwiftCode.swifttemplate +++ b/Templates/SwiftCode.swifttemplate @@ -61,7 +61,7 @@ extension BinderVariation { } var returnType: String { - return "SomePartialBindingBuilder" + return "SomeBindingBuilder" } var actualReturnType: String { From f73b1ebcb477d9bfc522138683c6200daa9d5521 Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Sat, 24 Aug 2019 10:31:56 +0200 Subject: [PATCH 207/239] Define 3.1 binding --- Sources/3.1 API/Binding.swift | 59 ++++++++++++++++++++++++++++ Sources/3.1 API/BindingBuilder.swift | 7 ---- Sources/3.1 API/ValueRequest.swift | 7 ++++ Swinject.xcodeproj/project.pbxproj | 30 +++++--------- 4 files changed, 76 insertions(+), 27 deletions(-) create mode 100644 Sources/3.1 API/Binding.swift delete mode 100644 Sources/3.1 API/BindingBuilder.swift create mode 100644 Sources/3.1 API/ValueRequest.swift diff --git a/Sources/3.1 API/Binding.swift b/Sources/3.1 API/Binding.swift new file mode 100644 index 00000000..6cd819d4 --- /dev/null +++ b/Sources/3.1 API/Binding.swift @@ -0,0 +1,59 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +protocol Binding: AnyBinding { + associatedtype Instance + associatedtype AScope + associatedtype Context + associatedtype Argument + + var keys: Set { get } + var dependencies: [ValueRequest] { get } + var factory: (Resolver, Context, Argument) throws -> Instance { get } + var scope: AScope { get } +} + +extension Binding { + public var key: BindingKey { keys.first! } // FIXME: enable multiple keys in AnyBinding +} + +extension Binding { + // TODO: swap param order + public func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any { + // TODO: scope handling + return try factory(resolver, context as! Context, arg as! Argument) + } +} + +public struct SomeBinding: Binding { + var keys: Set + var dependencies: [ValueRequest] + var factory: (Resolver, Context, Argument) throws -> Instance + public var properties: BindingProperties + var scope: AScope +} + +extension Binding { + func opaque() -> SomeBinding { + return SomeBinding( + keys: keys, dependencies: dependencies, factory: factory, properties: properties, scope: scope + ) + } +} + +extension Binding { + func updated(_ update: (inout Self) -> Void) -> Self { + var copy = self + update(©) + return copy + } + + func updated( + factory: @escaping (Resolver, Context, NewArgument) throws -> NewInstance + ) -> SomeBinding { + return SomeBinding( + keys: keys, dependencies: dependencies, factory: factory, properties: properties, scope: scope + ) + } +} diff --git a/Sources/3.1 API/BindingBuilder.swift b/Sources/3.1 API/BindingBuilder.swift deleted file mode 100644 index 8e4b5026..00000000 --- a/Sources/3.1 API/BindingBuilder.swift +++ /dev/null @@ -1,7 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -public protocol AnyBindingBuilder: SwinjectEntry { - func makeBinding() -> Binding -} diff --git a/Sources/3.1 API/ValueRequest.swift b/Sources/3.1 API/ValueRequest.swift new file mode 100644 index 00000000..6b050db7 --- /dev/null +++ b/Sources/3.1 API/ValueRequest.swift @@ -0,0 +1,7 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +public protocol ValueRequest { + var descriptor: TypeDescriptor { get } +} diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 1fcf4bd5..fbf78b15 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -160,20 +160,16 @@ 751F545653B0F1E30341C312 /* OverrideSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86C18DDD83715886DF7F1818 /* OverrideSpec.swift */; }; 75D74C8C25EDACF5A7A75A5C /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; 76FB9AFE299316E7F3F4C3BB /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57F4D977AC4289A6145383C9 /* InstanceRequest.swift */; }; - 773BE491231124AD000AA1A9 /* SomeBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773C6DDB23111956007A40BF /* SomeBinding.swift */; }; - 773C6DDC23111956007A40BF /* SomeBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773C6DDB23111956007A40BF /* SomeBinding.swift */; }; - 773C6DDD23111956007A40BF /* SomeBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773C6DDB23111956007A40BF /* SomeBinding.swift */; }; - 773C6DDE23111956007A40BF /* SomeBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773C6DDB23111956007A40BF /* SomeBinding.swift */; }; + 773BE491231124AD000AA1A9 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773C6DDB23111956007A40BF /* Binding.swift */; }; + 773C6DDC23111956007A40BF /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773C6DDB23111956007A40BF /* Binding.swift */; }; + 773C6DDD23111956007A40BF /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773C6DDB23111956007A40BF /* Binding.swift */; }; + 773C6DDE23111956007A40BF /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773C6DDB23111956007A40BF /* Binding.swift */; }; 778D9AB6470D4280254AC140 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; 77BF219EAB4FC8475943CECC /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6D434EB4C13CF9D9FA6D80CB /* Swinject.framework */; }; 77ED80052311221600AC48F9 /* ValueRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77ED80042311221600AC48F9 /* ValueRequest.swift */; }; 77ED80062311221600AC48F9 /* ValueRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77ED80042311221600AC48F9 /* ValueRequest.swift */; }; 77ED80072311221600AC48F9 /* ValueRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77ED80042311221600AC48F9 /* ValueRequest.swift */; }; 77ED80082311221600AC48F9 /* ValueRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77ED80042311221600AC48F9 /* ValueRequest.swift */; }; - 77ED800A2311231500AC48F9 /* Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77ED80092311231500AC48F9 /* Arguments.swift */; }; - 77ED800B2311231500AC48F9 /* Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77ED80092311231500AC48F9 /* Arguments.swift */; }; - 77ED800C2311231500AC48F9 /* Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77ED80092311231500AC48F9 /* Arguments.swift */; }; - 77ED800D2311231500AC48F9 /* Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77ED80092311231500AC48F9 /* Arguments.swift */; }; 789BF74652A2424EB8F7EF47 /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 7A7032384E07DAD308D4F70A /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 8B9785AAE94A5447FA307242 /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 7A956FAB419F74D7EB9CAD0B /* Opaque.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E7DC2C5AA87B18BD465EB77 /* Opaque.swift */; }; @@ -543,9 +539,8 @@ 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.CustomStringConvertible.swift; sourceTree = ""; }; 74DE57FB3E8228904E6FE0D7 /* Swinject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Swinject.h; sourceTree = ""; }; 75BE3AE3E30DFE42A919D825 /* ModulesSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModulesSpec.swift; sourceTree = ""; }; - 773C6DDB23111956007A40BF /* SomeBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SomeBinding.swift; sourceTree = ""; }; + 773C6DDB23111956007A40BF /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; 77ED80042311221600AC48F9 /* ValueRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ValueRequest.swift; sourceTree = ""; }; - 77ED80092311231500AC48F9 /* Arguments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Arguments.swift; sourceTree = ""; }; 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ServiceEntry+TypeForwarding.swift"; sourceTree = ""; }; 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextTranslator.swift; sourceTree = ""; }; 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistry.swift; sourceTree = ""; }; @@ -756,9 +751,8 @@ 773C6DDA23111910007A40BF /* 3.1 API */ = { isa = PBXGroup; children = ( - 773C6DDB23111956007A40BF /* SomeBinding.swift */, + 773C6DDB23111956007A40BF /* Binding.swift */, 77ED80042311221600AC48F9 /* ValueRequest.swift */, - 77ED80092311231500AC48F9 /* Arguments.swift */, ); path = "3.1 API"; sourceTree = ""; @@ -1466,7 +1460,7 @@ D9084C826F7A798508CD66F5 /* Resolver+Injection.swift in Sources */, D4936DC1A47A8C85325FB52E /* Resolver+LegacyApi.swift in Sources */, 8016512839FE61EC3127E489 /* Resolver.swift in Sources */, - 773C6DDD23111956007A40BF /* SomeBinding.swift in Sources */, + 773C6DDD23111956007A40BF /* Binding.swift in Sources */, 68C95FCB0D345CA3BA24D320 /* Scope.swift in Sources */, BB571B9A78FC53231A18E18C /* ScopeRegistry.swift in Sources */, 593B93BA2EE3FE4418A1C579 /* ScopeRegistryKey.swift in Sources */, @@ -1479,7 +1473,6 @@ 3328937B7BBFA77FA3CD303E /* SwinjectContainer.swift in Sources */, 020DA1718FCC68D889FB5A5F /* SwinjectError.swift in Sources */, CF4EBB60C21F8C503BCD7A29 /* SwinjectModule.swift in Sources */, - 77ED800B2311231500AC48F9 /* Arguments.swift in Sources */, 0D5C4A278A16AB3A163148AF /* SwinjectTree.swift in Sources */, AB864E029E996492ED4A3A52 /* TypeBinder.swift in Sources */, 49685AB40BEE856C62005C87 /* TypeDescriptor.swift in Sources */, @@ -1687,7 +1680,7 @@ 293985649250DF270DC89135 /* Matchable.swift in Sources */, 77ED80072311221600AC48F9 /* ValueRequest.swift in Sources */, B4B66D7251BDDE25D6D7FB3C /* ObjectScope.swift in Sources */, - 773BE491231124AD000AA1A9 /* SomeBinding.swift in Sources */, + 773BE491231124AD000AA1A9 /* Binding.swift in Sources */, 5365FDFB2DDA6491F3049654 /* Opaque.swift in Sources */, 6A967AE5710606998C2BE070 /* PropertyWrapper.swift in Sources */, B293894FEB67831DDA5F000E /* Reference.swift in Sources */, @@ -1708,7 +1701,6 @@ 91E435894038C42335086FA8 /* SwinjectError.swift in Sources */, C637E97E193BB1DADDDC6C21 /* SwinjectModule.swift in Sources */, 0CE1126436F680F9684837E4 /* SwinjectTree.swift in Sources */, - 77ED800C2311231500AC48F9 /* Arguments.swift in Sources */, 4B9811CF0604946CCF323ED2 /* TypeBinder.swift in Sources */, 9CEE20BD42795D5E5F39BF20 /* TypeDescriptor.swift in Sources */, 8B711CBE6A5B86DC2D6CABDC /* UnboundScope.swift in Sources */, @@ -1744,7 +1736,7 @@ C6D60E2AEC381998223145B2 /* Resolver+Injection.swift in Sources */, FD7B2663F2F931B78EB330EE /* Resolver+LegacyApi.swift in Sources */, 97C2EA47D7623AFD723AFE93 /* Resolver.swift in Sources */, - 773C6DDE23111956007A40BF /* SomeBinding.swift in Sources */, + 773C6DDE23111956007A40BF /* Binding.swift in Sources */, 2C352AAD1AC7D82A4A059046 /* Scope.swift in Sources */, 02556F149C9AAEF5CE353AC1 /* ScopeRegistry.swift in Sources */, 06F4CAB352B4F623FF7BD885 /* ScopeRegistryKey.swift in Sources */, @@ -1757,7 +1749,6 @@ 4D86550CC5C281A58B4A6F61 /* SwinjectContainer.swift in Sources */, 4DF3DC1CDD3C4948F9BDD3DF /* SwinjectError.swift in Sources */, 82299769BC637A14E7827DB0 /* SwinjectModule.swift in Sources */, - 77ED800D2311231500AC48F9 /* Arguments.swift in Sources */, 372F0061E762BF8FFF05457F /* SwinjectTree.swift in Sources */, 9425887520AC2DBDCBACB252 /* TypeBinder.swift in Sources */, AC470B4322599B0A076DD3FF /* TypeDescriptor.swift in Sources */, @@ -1794,7 +1785,7 @@ CBE63031F33303F3E503CEF2 /* Resolver+Injection.swift in Sources */, 41C7340BFD2EB66359772733 /* Resolver+LegacyApi.swift in Sources */, BE94EF7BCF976A703F961389 /* Resolver.swift in Sources */, - 773C6DDC23111956007A40BF /* SomeBinding.swift in Sources */, + 773C6DDC23111956007A40BF /* Binding.swift in Sources */, 96EA0A5DF33F025EBE0B67D2 /* Scope.swift in Sources */, D861595482464ED95CF81922 /* ScopeRegistry.swift in Sources */, 920DE2CAB9895D10FAE48FBA /* ScopeRegistryKey.swift in Sources */, @@ -1807,7 +1798,6 @@ A6721BA534AD082E1E7C1D08 /* SwinjectContainer.swift in Sources */, 820307073A53AED47AC99B8D /* SwinjectError.swift in Sources */, 8E77B56EE7F90BF723600DDF /* SwinjectModule.swift in Sources */, - 77ED800A2311231500AC48F9 /* Arguments.swift in Sources */, 6922AE734E84B515C94D9480 /* SwinjectTree.swift in Sources */, EF79F0B3D497215D4BBBC038 /* TypeBinder.swift in Sources */, E3EABE098DBFB561A20632E3 /* TypeDescriptor.swift in Sources */, From e66cee66632a180629186b9cec3ff303ffbdb318 Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Sat, 24 Aug 2019 10:48:48 +0200 Subject: [PATCH 208/239] Rename BindingProperties --- Sources/2.0 API/ServiceEntry.swift | 7 +------ Sources/3.0 API/BindingBuilder.swift | 6 +++--- Sources/3.0 API/ScopedBinding.swift | 6 +++--- Sources/3.0 API/SimpleBinding.swift | 6 +++--- Sources/3.0 API/TypeBinder.swift | 6 +++--- Sources/Core/AnyBinding.swift | 2 +- Sources/Core/SwinjectContainer.swift | 10 +++++----- Swinject.xcodeproj/project.pbxproj | 4 ++++ 8 files changed, 23 insertions(+), 24 deletions(-) diff --git a/Sources/2.0 API/ServiceEntry.swift b/Sources/2.0 API/ServiceEntry.swift index 04aecf60..6382fb86 100644 --- a/Sources/2.0 API/ServiceEntry.swift +++ b/Sources/2.0 API/ServiceEntry.swift @@ -70,12 +70,7 @@ public class ServiceEntry { } extension ServiceEntry: AnyBinding { - public var properties: BindingProperties { - return BindingProperties( - descriptor: key.descriptor, - overrides: false - ) - } + public var overrides: Bool { return false } public func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any { if let scope = scope { diff --git a/Sources/3.0 API/BindingBuilder.swift b/Sources/3.0 API/BindingBuilder.swift index dba8914b..78556aba 100644 --- a/Sources/3.0 API/BindingBuilder.swift +++ b/Sources/3.0 API/BindingBuilder.swift @@ -4,14 +4,14 @@ public protocol BindingBuilder { associatedtype BoundType - func makeBinding(with properties: BindingProperties) -> AnyBinding + func makeBinding(with properties: TypeBinderProperties) -> AnyBinding } public struct SomeBindingBuilder: BindingBuilder, AnyOpaque { let anyActual: Any - fileprivate let _makeBinding: (BindingProperties) -> AnyBinding + fileprivate let _makeBinding: (TypeBinderProperties) -> AnyBinding - public func makeBinding(with properties: BindingProperties) -> AnyBinding { + public func makeBinding(with properties: TypeBinderProperties) -> AnyBinding { return _makeBinding(properties) } } diff --git a/Sources/3.0 API/ScopedBinding.swift b/Sources/3.0 API/ScopedBinding.swift index af66b56b..6c9961bf 100644 --- a/Sources/3.0 API/ScopedBinding.swift +++ b/Sources/3.0 API/ScopedBinding.swift @@ -4,7 +4,7 @@ struct ScopedBinding { let key: BindingKey - let properties: BindingProperties + let overrides: Bool let builder: AnyInstanceBuilder let scope: AnyScope let makeRef: ReferenceMaker @@ -54,10 +54,10 @@ extension ScopedBinding.Builder: InstanceBuilder { extension ScopedBinding.Builder: BindingBuilder { typealias BoundType = Type - func makeBinding(with properties: BindingProperties) -> AnyBinding { + func makeBinding(with properties: TypeBinderProperties) -> AnyBinding { return ScopedBinding( key: BindingKey(descriptor: properties.descriptor, contextType: Context.self, argumentType: Argument.self), - properties: properties, + overrides: properties.overrides, builder: self, scope: scope, makeRef: makeRef diff --git a/Sources/3.0 API/SimpleBinding.swift b/Sources/3.0 API/SimpleBinding.swift index 4a57cf85..f9742888 100644 --- a/Sources/3.0 API/SimpleBinding.swift +++ b/Sources/3.0 API/SimpleBinding.swift @@ -4,7 +4,7 @@ struct SimpleBinding { let key: BindingKey - let properties: BindingProperties + let overrides: Bool let builder: AnyInstanceBuilder } @@ -35,10 +35,10 @@ extension SimpleBinding.Builder: InstanceBuilder { extension SimpleBinding.Builder: BindingBuilder { typealias BoundType = Type - func makeBinding(with properties: BindingProperties) -> AnyBinding { + func makeBinding(with properties: TypeBinderProperties) -> AnyBinding { return SimpleBinding( key: BindingKey(descriptor: properties.descriptor, contextType: Context.self, argumentType: Argument.self), - properties: properties, + overrides: properties.overrides, builder: self ) } diff --git a/Sources/3.0 API/TypeBinder.swift b/Sources/3.0 API/TypeBinder.swift index 86f6525c..6caa575c 100644 --- a/Sources/3.0 API/TypeBinder.swift +++ b/Sources/3.0 API/TypeBinder.swift @@ -2,17 +2,17 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -public struct BindingProperties { +public struct TypeBinderProperties { let descriptor: TypeDescriptor let overrides: Bool } public struct TypeBinder { - let properties: BindingProperties + let properties: TypeBinderProperties } public func bind(_: Type.Type, tagged tag: String? = nil, overrides: Bool = false) -> TypeBinder { - return TypeBinder(properties: BindingProperties( + return TypeBinder(properties: TypeBinderProperties( descriptor: tagged(Type.self, with: tag), overrides: overrides )) diff --git a/Sources/Core/AnyBinding.swift b/Sources/Core/AnyBinding.swift index fe4b3128..bcc68dfb 100644 --- a/Sources/Core/AnyBinding.swift +++ b/Sources/Core/AnyBinding.swift @@ -35,6 +35,6 @@ extension BindingKey { // TODO: Can We make this internal? public protocol AnyBinding: SwinjectEntry { var key: BindingKey { get } - var properties: BindingProperties { get } + var overrides: Bool { get } func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any } diff --git a/Sources/Core/SwinjectContainer.swift b/Sources/Core/SwinjectContainer.swift index 6b9ca8b9..9a7d7920 100644 --- a/Sources/Core/SwinjectContainer.swift +++ b/Sources/Core/SwinjectContainer.swift @@ -41,7 +41,7 @@ extension SwinjectContainer.Builder { private struct BindingEntry { let binding: AnyBinding let key: BindingKey - let properties: BindingProperties + let overrides: Bool let canOverride: Bool let canOverrideSilently: Bool } @@ -55,13 +55,13 @@ extension SwinjectContainer.Builder { } private func checkOverrideRules(for entry: BindingEntry, beingAddedTo dict: [BindingKey: AnyBinding]) throws { - if !entry.canOverride, entry.properties.overrides { + if !entry.canOverride, entry.overrides { throw OverrideNotAllowed() } - if dict[entry.key] == nil, entry.properties.overrides { + if dict[entry.key] == nil, entry.overrides { throw NothingToOverride() } - if dict[entry.key] != nil, !entry.properties.overrides, !entry.canOverrideSilently { + if dict[entry.key] != nil, !entry.overrides, !entry.canOverrideSilently { throw SilentOverrideNotAllowed() } } @@ -75,7 +75,7 @@ extension SwinjectContainer.Builder { .map { BindingEntry( binding: $0, key: $0.key, - properties: $0.properties, + overrides: $0.overrides, canOverride: canOverride ?? true, canOverrideSilently: canOverrideSilently ) } diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index fbf78b15..e2530ba7 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -165,6 +165,7 @@ 773C6DDD23111956007A40BF /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773C6DDB23111956007A40BF /* Binding.swift */; }; 773C6DDE23111956007A40BF /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773C6DDB23111956007A40BF /* Binding.swift */; }; 778D9AB6470D4280254AC140 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; + 77B87F3C23112DB100321C08 /* Binding+Api.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77B87F3B23112DB100321C08 /* Binding+Api.swift */; }; 77BF219EAB4FC8475943CECC /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6D434EB4C13CF9D9FA6D80CB /* Swinject.framework */; }; 77ED80052311221600AC48F9 /* ValueRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77ED80042311221600AC48F9 /* ValueRequest.swift */; }; 77ED80062311221600AC48F9 /* ValueRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77ED80042311221600AC48F9 /* ValueRequest.swift */; }; @@ -540,6 +541,7 @@ 74DE57FB3E8228904E6FE0D7 /* Swinject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Swinject.h; sourceTree = ""; }; 75BE3AE3E30DFE42A919D825 /* ModulesSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModulesSpec.swift; sourceTree = ""; }; 773C6DDB23111956007A40BF /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; + 77B87F3B23112DB100321C08 /* Binding+Api.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Binding+Api.swift"; sourceTree = ""; }; 77ED80042311221600AC48F9 /* ValueRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ValueRequest.swift; sourceTree = ""; }; 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ServiceEntry+TypeForwarding.swift"; sourceTree = ""; }; 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextTranslator.swift; sourceTree = ""; }; @@ -753,6 +755,7 @@ children = ( 773C6DDB23111956007A40BF /* Binding.swift */, 77ED80042311221600AC48F9 /* ValueRequest.swift */, + 77B87F3B23112DB100321C08 /* Binding+Api.swift */, ); path = "3.1 API"; sourceTree = ""; @@ -1802,6 +1805,7 @@ EF79F0B3D497215D4BBBC038 /* TypeBinder.swift in Sources */, E3EABE098DBFB561A20632E3 /* TypeDescriptor.swift in Sources */, 19F21849D1E173F5AC724281 /* UnboundScope.swift in Sources */, + 77B87F3C23112DB100321C08 /* Binding+Api.swift in Sources */, 581B08428C6AACAFC8017F8A /* Weak.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; From ff9c7c7b9ee2a67cdb15f23e621865a7d0520b32 Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Sat, 24 Aug 2019 12:03:01 +0200 Subject: [PATCH 209/239] Make context to be a property of the resolver --- Sources/2.0 API/Container.swift | 2 +- Sources/2.0 API/ServiceEntry.swift | 3 ++- Sources/3.0 API/ScopedBinding.swift | 3 ++- Sources/3.0 API/SimpleBinding.swift | 3 ++- Sources/Core/AnyBinding.swift | 2 +- Sources/Core/ContextTranslator.swift | 10 ++++----- Sources/Core/Resolver.swift | 31 ++++++++++++++++++++++++++ Sources/Core/Swinject.swift | 33 ++++++++++++---------------- 8 files changed, 58 insertions(+), 29 deletions(-) diff --git a/Sources/2.0 API/Container.swift b/Sources/2.0 API/Container.swift index 192dfd11..b7ccc902 100644 --- a/Sources/2.0 API/Container.swift +++ b/Sources/2.0 API/Container.swift @@ -147,7 +147,7 @@ extension Container: SwinjectAware { return Swinject( tree: SwinjectTree(bindings: [], modules: [], translators: []), container: SwinjectContainer(bindings: allBindings, translators: []), - context: Graph(), + anyContext: Graph(), contextType: Graph.self, stack: [], properties: Swinject.Properties( diff --git a/Sources/2.0 API/ServiceEntry.swift b/Sources/2.0 API/ServiceEntry.swift index 6382fb86..a05f802e 100644 --- a/Sources/2.0 API/ServiceEntry.swift +++ b/Sources/2.0 API/ServiceEntry.swift @@ -72,7 +72,8 @@ public class ServiceEntry { extension ServiceEntry: AnyBinding { public var overrides: Bool { return false } - public func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any { + public func instance(arg: Any, resolver: Resolver) throws -> Any { + let context = try resolver.context(as: key.contextType) if let scope = scope { return getRegistry(scope: scope, context: context).instance( for: ScopeRegistryKey(descriptor: key.descriptor, argument: arg), diff --git a/Sources/3.0 API/ScopedBinding.swift b/Sources/3.0 API/ScopedBinding.swift index 6c9961bf..bfe43d06 100644 --- a/Sources/3.0 API/ScopedBinding.swift +++ b/Sources/3.0 API/ScopedBinding.swift @@ -11,7 +11,8 @@ struct ScopedBinding { } extension ScopedBinding: AnyBinding { - func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any { + func instance(arg: Any, resolver: Resolver) throws -> Any { + let context = try resolver.context(as: key.contextType) return try scope .registry(for: context) .instance(for: ScopeRegistryKey(descriptor: key.descriptor, argument: arg)) { diff --git a/Sources/3.0 API/SimpleBinding.swift b/Sources/3.0 API/SimpleBinding.swift index f9742888..cc570d0e 100644 --- a/Sources/3.0 API/SimpleBinding.swift +++ b/Sources/3.0 API/SimpleBinding.swift @@ -9,7 +9,8 @@ struct SimpleBinding { } extension SimpleBinding: AnyBinding { - func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any { + func instance(arg: Any, resolver: Resolver) throws -> Any { + let context = try resolver.context(as: key.contextType) return try builder.makeInstance(arg: arg, context: context, resolver: resolver) } } diff --git a/Sources/Core/AnyBinding.swift b/Sources/Core/AnyBinding.swift index bcc68dfb..3f3425b9 100644 --- a/Sources/Core/AnyBinding.swift +++ b/Sources/Core/AnyBinding.swift @@ -36,5 +36,5 @@ extension BindingKey { public protocol AnyBinding: SwinjectEntry { var key: BindingKey { get } var overrides: Bool { get } - func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any + func instance(arg: Any, resolver: Resolver) throws -> Any } diff --git a/Sources/Core/ContextTranslator.swift b/Sources/Core/ContextTranslator.swift index cd051642..cf8932db 100644 --- a/Sources/Core/ContextTranslator.swift +++ b/Sources/Core/ContextTranslator.swift @@ -9,8 +9,8 @@ protocol AnyContextTranslator: SwinjectEntry { } public struct ContextTranslator: AnyContextTranslator { - let sourceType: Any.Type = Source.self - let targetType: Any.Type = Target.self + let sourceType: Any.Type = unwrapOptionals(Source.self) + let targetType: Any.Type = unwrapOptionals(Target.self) let translation: (Source) -> Target func translate(_ context: Any) throws -> Any { @@ -24,8 +24,8 @@ struct IdentityTranslator: AnyContextTranslator { let targetType: Any.Type init(for contextType: Any.Type) { - sourceType = contextType - targetType = contextType + sourceType = unwrapOptionals(contextType) + targetType = unwrapOptionals(contextType) } func translate(_ context: Any) throws -> Any { return context } @@ -36,7 +36,7 @@ struct ToAnyTranslator: AnyContextTranslator { let targetType: Any.Type = Any.self init(for contextType: Any.Type) { - sourceType = contextType + sourceType = unwrapOptionals(contextType) } func translate(_ context: Any) throws -> Any { return context } diff --git a/Sources/Core/Resolver.swift b/Sources/Core/Resolver.swift index b0a5a116..10a943f1 100644 --- a/Sources/Core/Resolver.swift +++ b/Sources/Core/Resolver.swift @@ -5,6 +5,7 @@ public protocol Resolver { func resolve(_ request: InstanceRequest) throws -> Type func on(_ context: Context) -> Resolver + func context(as contextType: Any.Type) throws -> Any // TODO: Ideally this should be internal } public protocol SwinjectAware: Resolver { @@ -19,4 +20,34 @@ public extension SwinjectAware { func on(_ context: Context) -> Resolver { return swinject.on(context) } + + func context(as contextType: Any.Type) throws -> Any { + return try swinject.context(as: contextType) + } +} + +public struct ContextedResolver: Resolver { + let actual: Resolver + + public func resolve(_ request: InstanceRequest) throws -> Type { + return try actual.resolve(request) + } + + public func on(_ context: Context) -> Resolver { + return actual.on(context) + } + + public func context(as contextType: Any.Type) throws -> Any { + return try actual.context(as: contextType) + } + + public func context() throws -> Context { + return try context(as: Context.self) as! Context + } +} + +extension Resolver { + func contexted() -> ContextedResolver { + return ContextedResolver(actual: self) + } } diff --git a/Sources/Core/Swinject.swift b/Sources/Core/Swinject.swift index b5d3c567..e538543c 100644 --- a/Sources/Core/Swinject.swift +++ b/Sources/Core/Swinject.swift @@ -10,7 +10,7 @@ public struct Swinject { let tree: SwinjectTree let container: SwinjectContainer - let context: Any + let anyContext: Any let contextType: Any.Type let stack: [AnyInstanceRequest] let properties: Properties @@ -25,15 +25,18 @@ extension Swinject: Resolver { if let custom = resolve(request, asCustom: Type.self) { return custom } throw error } - return try tracking(request).makeInstance( - from: binding, - context: findTranslator(for: binding).translate(context), - arg: request.argument - ) + return try tracking(request).makeInstance(from: binding, arg: request.argument) } public func on(_ context: Context) -> Resolver { - return with(context: context, contextType: Context.self) + return with(context: context, contextType: unwrapOptionals(Context.self)) + } + + public func context(as resultType: Any.Type) throws -> Any { + return try allTranslators + .filter { $0.sourceType == contextType && $0.targetType == resultType } + .compactMap { try $0.translate(anyContext) } + .first ?? { throw NoContextTranslator() }() } } @@ -45,12 +48,6 @@ extension Swinject { return custom.init(resolver: with(stack: []), request: request) as? Type } - private func findTranslator(for binding: AnyBinding) throws -> AnyContextTranslator { - return try allTranslators - .filter { binding.key.matches(contextType: $0.targetType) } - .first ?? { throw NoContextTranslator() }() - } - private func tracking(_ request: AnyInstanceRequest) throws -> Swinject { guard properties.detectsCircularDependencies else { return self } guard !stack.contains(where: { request.matches($0) }) else { throw CircularDependency() } @@ -80,10 +77,8 @@ extension Swinject { return bindings[0] } - private func makeInstance( - from binding: AnyBinding, context: Context, arg: Argument - ) throws -> Type { - return try binding.instance(arg: arg, context: context, resolver: self) as? Type ?? { throw SwinjectError() }() + private func makeInstance(from binding: AnyBinding, arg: Argument) throws -> Type { + return try binding.instance(arg: arg, resolver: self) as? Type ?? { throw SwinjectError() }() } } @@ -92,7 +87,7 @@ extension Swinject { self.init( tree: tree, container: SwinjectContainer.Builder(tree: tree, properties: properties).makeContainer(), - context: (), + anyContext: (), contextType: Void.self, stack: [], properties: properties @@ -107,7 +102,7 @@ extension Swinject { return Swinject( tree: tree, container: container, - context: context ?? self.context, + anyContext: context ?? anyContext, contextType: contextType ?? self.contextType, stack: stack ?? self.stack, properties: properties From 79a9aebaa5af205e8f86b3351713f2b830692cd1 Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Sat, 24 Aug 2019 12:50:01 +0200 Subject: [PATCH 210/239] Draft new version of API --- Sources/3.1 API/Binding+Api.swift | 62 +++++++++++++++++++++++++++++++ Sources/3.1 API/Binding.swift | 48 +++++++++++++++++------- 2 files changed, 96 insertions(+), 14 deletions(-) create mode 100644 Sources/3.1 API/Binding+Api.swift diff --git a/Sources/3.1 API/Binding+Api.swift b/Sources/3.1 API/Binding+Api.swift new file mode 100644 index 00000000..dda77aaa --- /dev/null +++ b/Sources/3.1 API/Binding+Api.swift @@ -0,0 +1,62 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +public typealias AnyContext = Any +public typealias NoArgument = Void +public typealias NoScope = Void + +public func register(inContextOf _: Context.Type) -> SomeBinding { + return SomeBinding(keys: Set(), dependencies: [], factory: { _, _, in }, properties: .default, scope: ()) +} + +public func register() -> SomeBinding { + return register(inContextOf: Any.self) +} + +public func registerSingle(in scope: AScope) -> SomeBinding { + return SomeBinding(keys: Set(), dependencies: [], factory: { _, _ in }, properties: .default, scope: scope) +} + +public func registerSingle() -> SomeBinding { + return registerSingle(in: .root) +} + +public extension Binding where Instance == Void { + func constant( + _ value: Value, as _: Value.Type = Value.self, tag: String? = nil + ) -> SomeBinding { + return updatedFactory { _, _ in value }.updated { + $0.products = [tagged(Value.self, with: tag)] + $0.dependencies = .none + } + } + + // TODO: Oveloads for argument variations + func factory( + for _: NewInstance.Type = NewInstance.self, + tag: String? = nil, + factory: @escaping (ContextedResolver, NewArgument) throws -> NewInstance + ) -> SomeBinding { + return updatedFactory(factory: factory).updated { + $0.products = [tagged(NewInstance.self, with: tag)] + $0.dependencies = .undefined + } + } +} + +public extension Binding where { + func toUse(_: (Instance) -> OtherInstance, tag: String? = nil) -> Self { + return updated { $0.products = [tagged(OtherInstance.self, with: tag)] } + } + + func alsoUse(_: (Instance) -> OtherInstance, tag: String? = nil) -> Self { + return updated { $0.products.append(tagged(OtherInstance.self, with: tag)) } + } +} + +public extension Binding { + func withProperties(_ update: (inout BindingProperties) -> Void) -> Self { + return updated { update(&$0.properties) } + } +} diff --git a/Sources/3.1 API/Binding.swift b/Sources/3.1 API/Binding.swift index 6cd819d4..450ab4da 100644 --- a/Sources/3.1 API/Binding.swift +++ b/Sources/3.1 API/Binding.swift @@ -2,42 +2,62 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // +struct BindingProperties { + var overrides: Bool + var reference: ReferenceMaker + + static let `default` = BindingProperties(overrides: false, reference: strongRef) +} + +enum BindingDependencies { + case undefined + case requests([ValueRequest]) + + static let none = BindingDependencies.requests([]) +} + protocol Binding: AnyBinding { associatedtype Instance associatedtype AScope associatedtype Context associatedtype Argument - var keys: Set { get } - var dependencies: [ValueRequest] { get } - var factory: (Resolver, Context, Argument) throws -> Instance { get } + var products: [TypeDescriptor] { get } + var dependencies: BindingDependencies { get } + var factory: (ContextedResolver, Argument) throws -> Instance { get } + var properties: BindingProperties { get } var scope: AScope { get } } extension Binding { - public var key: BindingKey { keys.first! } // FIXME: enable multiple keys in AnyBinding + var keys: [BindingKey] { + return products.map { BindingKey(descriptor: $0, contextType: Context.self, argumentType: Argument.self) } + } + + public var key: BindingKey { return keys.first! } // FIXME: enable multiple keys in AnyBinding + public var overrides: Bool { return properties.overrides } } extension Binding { // TODO: swap param order - public func instance(arg: Any, context: Any, resolver: Resolver) throws -> Any { + public func instance(arg: Any, resolver: Resolver) throws -> Any { // TODO: scope handling - return try factory(resolver, context as! Context, arg as! Argument) + return try factory(resolver.contexted(), arg as! Argument) } } public struct SomeBinding: Binding { - var keys: Set - var dependencies: [ValueRequest] - var factory: (Resolver, Context, Argument) throws -> Instance - public var properties: BindingProperties + var products: [TypeDescriptor] + var dependencies: BindingDependencies + var factory: (ContextedResolver, Argument) throws -> Instance + var properties: BindingProperties var scope: AScope } extension Binding { func opaque() -> SomeBinding { return SomeBinding( - keys: keys, dependencies: dependencies, factory: factory, properties: properties, scope: scope + products: products, dependencies: dependencies, factory: factory, properties: properties, scope: scope ) } } @@ -49,11 +69,11 @@ extension Binding { return copy } - func updated( - factory: @escaping (Resolver, Context, NewArgument) throws -> NewInstance + func updatedFactory( + factory: @escaping (ContextedResolver, NewArgument) throws -> NewInstance ) -> SomeBinding { return SomeBinding( - keys: keys, dependencies: dependencies, factory: factory, properties: properties, scope: scope + products: products, dependencies: dependencies, factory: factory, properties: properties, scope: scope ) } } From 1250d064f797a14f8c45247cb2b9f29680d7b4aa Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Sat, 24 Aug 2019 12:58:02 +0200 Subject: [PATCH 211/239] Update property wrappers --- Sources/2.0 API/InstanceWrapper.swift | 10 ++-- Sources/3.0 API/Weak.swift | 8 +-- Sources/Core/PropertyWrapper.swift | 4 +- Tests/3.0 API/CIrcularitySpec.swift | 73 ++++++++++++------------ Tests/3.0 API/PropertyWrappersSpec.swift | 4 +- 5 files changed, 49 insertions(+), 50 deletions(-) diff --git a/Sources/2.0 API/InstanceWrapper.swift b/Sources/2.0 API/InstanceWrapper.swift index c79b475b..d636801b 100644 --- a/Sources/2.0 API/InstanceWrapper.swift +++ b/Sources/2.0 API/InstanceWrapper.swift @@ -41,8 +41,8 @@ public extension Lazy { } } - init(initialValue: @autoclosure @escaping () -> Value) { - self = .uninitialized(initialValue) + init(wrappedValue: @autoclosure @escaping () -> Value) { + self = .uninitialized(wrappedValue) } } @@ -73,12 +73,12 @@ public extension Provider { } extension Provider { - init(initialValue: @autoclosure @escaping () -> Type) { - provider = initialValue + init(wrappedValue: @autoclosure @escaping () -> Type) { + provider = wrappedValue } init(resolver: Resolver, request: AnyInstanceRequest) { // swiftlint:disable:next force_try - self.init(initialValue: try! resolver.on(Graph()).resolve(request.replacingType(with: Value.self))) + self.init(wrappedValue: try! resolver.on(Graph()).resolve(request.replacingType(with: Value.self))) } } diff --git a/Sources/3.0 API/Weak.swift b/Sources/3.0 API/Weak.swift index 9e121d61..5e191cd3 100644 --- a/Sources/3.0 API/Weak.swift +++ b/Sources/3.0 API/Weak.swift @@ -6,8 +6,8 @@ @propertyWrapper public struct Weak: PropertyWrapper where Value: AnyObject { public weak var wrappedValue: Value? - public init(initialValue: @autoclosure () -> Value?) { - wrappedValue = initialValue() + public init(wrappedValue: @autoclosure () -> Value?) { + self.wrappedValue = wrappedValue() } } @@ -15,8 +15,8 @@ public struct Weak: PropertyWrapper where Value: AnyObject { public weak var wrappedValue: Value? - public init(initialValue: @autoclosure () -> Value?) { - wrappedValue = initialValue() + public init(wrappedValue: @autoclosure () -> Value?) { + self.wrappedValue = wrappedValue() } } #endif diff --git a/Sources/Core/PropertyWrapper.swift b/Sources/Core/PropertyWrapper.swift index 9a4d8c52..c1dbc16d 100644 --- a/Sources/Core/PropertyWrapper.swift +++ b/Sources/Core/PropertyWrapper.swift @@ -9,13 +9,13 @@ protocol CustomResolvable { protocol PropertyWrapper: CustomResolvable { associatedtype Value - init(initialValue: @autoclosure @escaping () -> Value) + init(wrappedValue: @autoclosure @escaping () -> Value) } extension PropertyWrapper { init(resolver: Resolver, request: AnyInstanceRequest) { // swiftlint:disable:next force_try - self.init(initialValue: try! resolver.resolve(request.replacingType(with: Value.self))) + self.init(wrappedValue: try! resolver.resolve(request.replacingType(with: Value.self))) } static func requiredRequest(for request: AnyInstanceRequest) -> AnyInstanceRequest? { diff --git a/Tests/3.0 API/CIrcularitySpec.swift b/Tests/3.0 API/CIrcularitySpec.swift index b6a21740..e8928e12 100644 --- a/Tests/3.0 API/CIrcularitySpec.swift +++ b/Tests/3.0 API/CIrcularitySpec.swift @@ -51,42 +51,41 @@ class CircularitySpec: QuickSpec { override func spec() { #if swift(>=5.1) let foo = try? swinject.instance(of: Foo.self) expect { foo?.bar.foo } === foo } - // FIXME: This segfaults on Xcode11 beta5 -// it("correctly injects dependencies if using Lazy Weak wrapper") { -// class Foo { -// let bar: Bar -// init(_ bar: Bar) { self.bar = bar } -// } -// class Bar { -// @Lazy @Weak var foo = nil as Foo? -// init(_ foo: Lazy>) { _foo = foo } -// } -// let swinject = Swinject { -// bbind(Foo.self) & singleton(ref: weakRef) { Foo(try $0.instance()) } -// bbind(Bar.self) & provider { Bar(try $0.instance()) } -// } -// let foo = try? swinject.instance(of: Foo.self) -// expect { foo?.bar.foo } === foo -// } -// it("can avoid reference cycles if using Lazy Weak wrapper and weak singleton") { -// class Foo { -// let bar: Bar -// init(_ bar: Bar) { self.bar = bar } -// } -// class Bar { -// @Lazy @Weak var foo = nil as Foo? -// init(_ foo: Lazy>) { _foo = foo } -// } -// let swinject = Swinject { -// bbind(Foo.self) & singleton(ref: weakRef) { Foo(try $0.instance()) } -// bbind(Bar.self) & provider { Bar(try $0.instance()) } -// } -// var foo = try? swinject.instance(of: Foo.self) -// let bar = foo?.bar -// -// foo = nil -// -// expect(bar?.foo).to(beNil()) -// } + it("correctly injects dependencies if using Lazy Weak wrapper") { + class Foo { + let bar: Bar + init(_ bar: Bar) { self.bar = bar } + } + class Bar { + @Lazy @Weak var foo = nil as Foo? + init(_ foo: Lazy>) { _foo = foo } + } + let swinject = Swinject { + bbind(Foo.self) & singleton(ref: weakRef) { Foo(try $0.instance()) } + bbind(Bar.self) & provider { Bar(try $0.instance()) } + } + let foo = try? swinject.instance(of: Foo.self) + expect { foo?.bar.foo } === foo + } + it("can avoid reference cycles if using Lazy Weak wrapper and weak singleton") { + class Foo { + let bar: Bar + init(_ bar: Bar) { self.bar = bar } + } + class Bar { + @Lazy @Weak var foo = nil as Foo? + init(_ foo: Lazy>) { _foo = foo } + } + let swinject = Swinject { + bbind(Foo.self) & singleton(ref: weakRef) { Foo(try $0.instance()) } + bbind(Bar.self) & provider { Bar(try $0.instance()) } + } + var foo = try? swinject.instance(of: Foo.self) + let bar = foo?.bar + + foo = nil + + expect(bar?.foo).to(beNil()) + } #endif } } diff --git a/Tests/3.0 API/PropertyWrappersSpec.swift b/Tests/3.0 API/PropertyWrappersSpec.swift index 3beb186f..745671bd 100644 --- a/Tests/3.0 API/PropertyWrappersSpec.swift +++ b/Tests/3.0 API/PropertyWrappersSpec.swift @@ -11,8 +11,8 @@ class PropertyWrappersSpec: QuickSpec { override func spec() { #if swift(>=5.1) @propertyWrapper struct Wrapped: PropertyWrapper { var wrappedValue: Value - public init(initialValue: @autoclosure () -> Value) { - self.wrappedValue = initialValue() + public init(wrappedValue: @autoclosure () -> Value) { + self.wrappedValue = wrappedValue() } } it("can inject wrapped provider of a bound type") { From 7177068657892cbaa086a21bae70aff6ac306fb0 Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Sat, 24 Aug 2019 13:54:48 +0200 Subject: [PATCH 212/239] Rewrite BindingSpec --- Sources/3.0 API/BinderEnvironment.swift | 2 +- Sources/3.1 API/Binding+Api.swift | 28 ++---- Sources/3.1 API/Binding+Factory.swift | 95 ++++++++++++++++++ Sources/3.1 API/Binding.swift | 55 ++++++----- Sources/Core/Matchable.swift | 11 ++- Swinject.xcodeproj/project.pbxproj | 24 +++++ Templates/BinderEnvironment.swifttemplate | 2 +- Templates/Binding+Factory.swifttemplate | 6 ++ Templates/FactoryVariation.swift | 111 ++++++++++++++++++++++ Templates/MatchableBoxes.swifttemplate | 2 +- Templates/SwiftCode.swifttemplate | 111 ++++++++++++++++++++++ Tests/3.0 API/BindingSpec.swift | 30 +++--- 12 files changed, 408 insertions(+), 69 deletions(-) create mode 100644 Sources/3.1 API/Binding+Factory.swift create mode 100644 Templates/Binding+Factory.swifttemplate create mode 100644 Templates/FactoryVariation.swift diff --git a/Sources/3.0 API/BinderEnvironment.swift b/Sources/3.0 API/BinderEnvironment.swift index 340c4873..ee3dee84 100644 --- a/Sources/3.0 API/BinderEnvironment.swift +++ b/Sources/3.0 API/BinderEnvironment.swift @@ -24,7 +24,7 @@ public func instance(_ instance: Type) -> SomeBindingBuilder { return SimpleBinding.Builder { _, _, _ in instance }.opaque } -// sourcery:inline:BindingBuilders +// sourcery:inline:SomeBindingBuilders extension ContextedEnvironment { public func provider(_ builder: @escaping () throws -> Type) -> SomeBindingBuilder { return SimpleBinding.Builder { _, _, _ in try builder() }.opaque diff --git a/Sources/3.1 API/Binding+Api.swift b/Sources/3.1 API/Binding+Api.swift index dda77aaa..262d3e9f 100644 --- a/Sources/3.1 API/Binding+Api.swift +++ b/Sources/3.1 API/Binding+Api.swift @@ -6,46 +6,34 @@ public typealias AnyContext = Any public typealias NoArgument = Void public typealias NoScope = Void -public func register(inContextOf _: Context.Type) -> SomeBinding { - return SomeBinding(keys: Set(), dependencies: [], factory: { _, _, in }, properties: .default, scope: ()) +public func register(inContextOf _: Context.Type) -> Binding { + return Binding(products: [], dependencies: .none, factory: { _, _ in }, properties: .default, scope: ()) } -public func register() -> SomeBinding { +public func register() -> Binding { return register(inContextOf: Any.self) } -public func registerSingle(in scope: AScope) -> SomeBinding { - return SomeBinding(keys: Set(), dependencies: [], factory: { _, _ in }, properties: .default, scope: scope) +public func registerSingle(in scope: AScope) -> Binding { + return Binding(products: [], dependencies: .none, factory: { _, _ in }, properties: .default, scope: scope) } -public func registerSingle() -> SomeBinding { +public func registerSingle() -> Binding { return registerSingle(in: .root) } public extension Binding where Instance == Void { func constant( _ value: Value, as _: Value.Type = Value.self, tag: String? = nil - ) -> SomeBinding { + ) -> Binding { return updatedFactory { _, _ in value }.updated { $0.products = [tagged(Value.self, with: tag)] $0.dependencies = .none } } - - // TODO: Oveloads for argument variations - func factory( - for _: NewInstance.Type = NewInstance.self, - tag: String? = nil, - factory: @escaping (ContextedResolver, NewArgument) throws -> NewInstance - ) -> SomeBinding { - return updatedFactory(factory: factory).updated { - $0.products = [tagged(NewInstance.self, with: tag)] - $0.dependencies = .undefined - } - } } -public extension Binding where { +public extension Binding { func toUse(_: (Instance) -> OtherInstance, tag: String? = nil) -> Self { return updated { $0.products = [tagged(OtherInstance.self, with: tag)] } } diff --git a/Sources/3.1 API/Binding+Factory.swift b/Sources/3.1 API/Binding+Factory.swift new file mode 100644 index 00000000..df767a52 --- /dev/null +++ b/Sources/3.1 API/Binding+Factory.swift @@ -0,0 +1,95 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +// swiftlint:disable line_length +// swiftlint:disable identifier_name +// swiftlint:disable large_tuple +// sourcery:inline:BindingFactoryApi +public extension Binding { + func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping () throws -> NewInstance) -> Binding { + return updatedFactory { _, _ in try factory() }.updated { + $0.products = [tagged(NewInstance.self, with: tag)] + $0.dependencies = .undefined + } + } + + func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver) throws -> NewInstance) -> Binding { + return updatedFactory { r, _ in try factory(r) }.updated { + $0.products = [tagged(NewInstance.self, with: tag)] + $0.dependencies = .undefined + } + } + + func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1) throws -> NewInstance) -> Binding { + return updatedFactory { r, a in try factory(r, a) }.updated { + $0.products = [tagged(NewInstance.self, with: tag)] + $0.dependencies = .undefined + } + } + + func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1) throws -> NewInstance) -> Binding> where Arg1: Hashable { + return updatedFactory { r, a in try factory(r, a.arg1) }.updated { + $0.products = [tagged(NewInstance.self, with: tag)] + $0.dependencies = .undefined + } + } + + func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2) throws -> NewInstance) -> Binding { + return updatedFactory { r, a in try factory(r, a.0, a.1) }.updated { + $0.products = [tagged(NewInstance.self, with: tag)] + $0.dependencies = .undefined + } + } + + func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2) throws -> NewInstance) -> Binding> where Arg1: Hashable, Arg2: Hashable { + return updatedFactory { r, a in try factory(r, a.arg1, a.arg2) }.updated { + $0.products = [tagged(NewInstance.self, with: tag)] + $0.dependencies = .undefined + } + } + + func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2, Arg3) throws -> NewInstance) -> Binding { + return updatedFactory { r, a in try factory(r, a.0, a.1, a.2) }.updated { + $0.products = [tagged(NewInstance.self, with: tag)] + $0.dependencies = .undefined + } + } + + func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2, Arg3) throws -> NewInstance) -> Binding> where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + return updatedFactory { r, a in try factory(r, a.arg1, a.arg2, a.arg3) }.updated { + $0.products = [tagged(NewInstance.self, with: tag)] + $0.dependencies = .undefined + } + } + + func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2, Arg3, Arg4) throws -> NewInstance) -> Binding { + return updatedFactory { r, a in try factory(r, a.0, a.1, a.2, a.3) }.updated { + $0.products = [tagged(NewInstance.self, with: tag)] + $0.dependencies = .undefined + } + } + + func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2, Arg3, Arg4) throws -> NewInstance) -> Binding> where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + return updatedFactory { r, a in try factory(r, a.arg1, a.arg2, a.arg3, a.arg4) }.updated { + $0.products = [tagged(NewInstance.self, with: tag)] + $0.dependencies = .undefined + } + } + + func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> NewInstance) -> Binding { + return updatedFactory { r, a in try factory(r, a.0, a.1, a.2, a.3, a.4) }.updated { + $0.products = [tagged(NewInstance.self, with: tag)] + $0.dependencies = .undefined + } + } + + func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> NewInstance) -> Binding> where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + return updatedFactory { r, a in try factory(r, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) }.updated { + $0.products = [tagged(NewInstance.self, with: tag)] + $0.dependencies = .undefined + } + } +} + +// sourcery:end diff --git a/Sources/3.1 API/Binding.swift b/Sources/3.1 API/Binding.swift index 450ab4da..73be94b9 100644 --- a/Sources/3.1 API/Binding.swift +++ b/Sources/3.1 API/Binding.swift @@ -2,7 +2,7 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -struct BindingProperties { +public struct BindingProperties { var overrides: Bool var reference: ReferenceMaker @@ -16,47 +16,50 @@ enum BindingDependencies { static let none = BindingDependencies.requests([]) } -protocol Binding: AnyBinding { - associatedtype Instance - associatedtype AScope - associatedtype Context - associatedtype Argument - - var products: [TypeDescriptor] { get } - var dependencies: BindingDependencies { get } - var factory: (ContextedResolver, Argument) throws -> Instance { get } - var properties: BindingProperties { get } - var scope: AScope { get } +public struct Binding { + var products: [TypeDescriptor] + var dependencies: BindingDependencies + var factory: (ContextedResolver, Argument) throws -> Instance + var properties: BindingProperties + var scope: AScope } extension Binding { var keys: [BindingKey] { return products.map { BindingKey(descriptor: $0, contextType: Context.self, argumentType: Argument.self) } } +} +extension Binding: AnyBinding { public var key: BindingKey { return keys.first! } // FIXME: enable multiple keys in AnyBinding public var overrides: Bool { return properties.overrides } } extension Binding { - // TODO: swap param order public func instance(arg: Any, resolver: Resolver) throws -> Any { - // TODO: scope handling - return try factory(resolver.contexted(), arg as! Argument) + if let scope = scope as? AnyScope { + return try scopedInstance(resolver: resolver, scope: scope, arg: arg) + } else { + return try simpleInstance(resolver: resolver, arg: arg) + } } -} -public struct SomeBinding: Binding { - var products: [TypeDescriptor] - var dependencies: BindingDependencies - var factory: (ContextedResolver, Argument) throws -> Instance - var properties: BindingProperties - var scope: AScope + private func scopedInstance(resolver: Resolver, scope: AnyScope, arg: Any) throws -> Any { + return try scope + .registry(for: resolver.context(as: Context.self)) + .instance(for: ScopeRegistryKey(descriptor: products.first!, argument: arg)) { + try properties.reference(simpleInstance(resolver: resolver, arg: arg)) + } + } + + private func simpleInstance(resolver: Resolver, arg: Any) throws -> Any { + return try factory(resolver.contexted(), arg as! Argument) + } } extension Binding { - func opaque() -> SomeBinding { - return SomeBinding( + func opaque() -> Binding { + return Binding( products: products, dependencies: dependencies, factory: factory, properties: properties, scope: scope ) } @@ -71,8 +74,8 @@ extension Binding { func updatedFactory( factory: @escaping (ContextedResolver, NewArgument) throws -> NewInstance - ) -> SomeBinding { - return SomeBinding( + ) -> Binding { + return Binding( products: products, dependencies: dependencies, factory: factory, properties: properties, scope: scope ) } diff --git a/Sources/Core/Matchable.swift b/Sources/Core/Matchable.swift index 335762c5..8bf0cfaa 100644 --- a/Sources/Core/Matchable.swift +++ b/Sources/Core/Matchable.swift @@ -13,32 +13,33 @@ public extension Matchable where Self: Equatable { } } +// TODO: Can we make boxes internal? // swiftlint:disable line_length // swiftlint:disable large_tuple // sourcery:inline:MatchableBoxes -struct MatchableBox1: Hashable, Matchable where Arg1: Hashable { +public struct MatchableBox1: Hashable, Matchable where Arg1: Hashable { let arg1: Arg1 } -struct MatchableBox2: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable { +public struct MatchableBox2: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable { let arg1: Arg1 let arg2: Arg2 } -struct MatchableBox3: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { +public struct MatchableBox3: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { let arg1: Arg1 let arg2: Arg2 let arg3: Arg3 } -struct MatchableBox4: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { +public struct MatchableBox4: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { let arg1: Arg1 let arg2: Arg2 let arg3: Arg3 let arg4: Arg4 } -struct MatchableBox5: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { +public struct MatchableBox5: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { let arg1: Arg1 let arg2: Arg2 let arg3: Arg3 diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index e2530ba7..b8adaee5 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -166,6 +166,15 @@ 773C6DDE23111956007A40BF /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773C6DDB23111956007A40BF /* Binding.swift */; }; 778D9AB6470D4280254AC140 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; 77B87F3C23112DB100321C08 /* Binding+Api.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77B87F3B23112DB100321C08 /* Binding+Api.swift */; }; + 77B87F3E231153D200321C08 /* FactoryVariation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77B87F3D231153D200321C08 /* FactoryVariation.swift */; }; + 77B87F40231155B300321C08 /* Binding+Factory.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 77B87F3F231155B300321C08 /* Binding+Factory.swifttemplate */; }; + 77B87F43231157E900321C08 /* Binding+Factory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77B87F41231157B200321C08 /* Binding+Factory.swift */; }; + 77B87F44231157E900321C08 /* Binding+Factory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77B87F41231157B200321C08 /* Binding+Factory.swift */; }; + 77B87F45231157EA00321C08 /* Binding+Factory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77B87F41231157B200321C08 /* Binding+Factory.swift */; }; + 77B87F46231157EA00321C08 /* Binding+Factory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77B87F41231157B200321C08 /* Binding+Factory.swift */; }; + 77B87F472311580500321C08 /* Binding+Api.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77B87F3B23112DB100321C08 /* Binding+Api.swift */; }; + 77B87F482311580600321C08 /* Binding+Api.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77B87F3B23112DB100321C08 /* Binding+Api.swift */; }; + 77B87F492311580600321C08 /* Binding+Api.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77B87F3B23112DB100321C08 /* Binding+Api.swift */; }; 77BF219EAB4FC8475943CECC /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6D434EB4C13CF9D9FA6D80CB /* Swinject.framework */; }; 77ED80052311221600AC48F9 /* ValueRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77ED80042311221600AC48F9 /* ValueRequest.swift */; }; 77ED80062311221600AC48F9 /* ValueRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77ED80042311221600AC48F9 /* ValueRequest.swift */; }; @@ -542,6 +551,9 @@ 75BE3AE3E30DFE42A919D825 /* ModulesSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModulesSpec.swift; sourceTree = ""; }; 773C6DDB23111956007A40BF /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; 77B87F3B23112DB100321C08 /* Binding+Api.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Binding+Api.swift"; sourceTree = ""; }; + 77B87F3D231153D200321C08 /* FactoryVariation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FactoryVariation.swift; sourceTree = ""; }; + 77B87F3F231155B300321C08 /* Binding+Factory.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Binding+Factory.swifttemplate"; sourceTree = ""; }; + 77B87F41231157B200321C08 /* Binding+Factory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Binding+Factory.swift"; sourceTree = ""; }; 77ED80042311221600AC48F9 /* ValueRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ValueRequest.swift; sourceTree = ""; }; 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ServiceEntry+TypeForwarding.swift"; sourceTree = ""; }; 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextTranslator.swift; sourceTree = ""; }; @@ -637,6 +649,8 @@ children = ( 26EEC28683E4A26B3092E8BA /* BinderEnvironment.swifttemplate */, 2E0C3E4D518BC1FEF3EF8D33 /* BinderVariation.swift */, + 77B87F3D231153D200321C08 /* FactoryVariation.swift */, + 77B87F3F231155B300321C08 /* Binding+Factory.swifttemplate */, CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */, C3C516EFA0CA22D19F07B27E /* InjectionVariation.swift */, 808C1063CA90CC593C7E0E9C /* MatchableBoxes.swifttemplate */, @@ -756,6 +770,7 @@ 773C6DDB23111956007A40BF /* Binding.swift */, 77ED80042311221600AC48F9 /* ValueRequest.swift */, 77B87F3B23112DB100321C08 /* Binding+Api.swift */, + 77B87F41231157B200321C08 /* Binding+Factory.swift */, ); path = "3.1 API"; sourceTree = ""; @@ -1190,6 +1205,7 @@ 3EC8383BEAC339595CF7F927 /* Resolver+FunctionCallApi.swifttemplate in Resources */, 71895EBC0803EEE3BFCD7001 /* Resolver+Injection.swifttemplate in Resources */, F568382FB877060127790413 /* Resolver+LegacyApi.swifttemplate in Resources */, + 77B87F40231155B300321C08 /* Binding+Factory.swifttemplate in Resources */, B7653A6427A5E284E9A1D6D3 /* ServiceEntry+TypeForwarding.swifttemplate in Resources */, EBC64A1515C868E410C83451 /* SwiftCode.swifttemplate in Resources */, ); @@ -1451,12 +1467,14 @@ 996CCFE825834C7D3236E742 /* Container+TypeForwarding.swift in Sources */, B2FAD41F7726502822AF913B /* Container.swift in Sources */, 8B5927517B567B1DFAB5B935 /* ContextTranslator.swift in Sources */, + 77B87F492311580600321C08 /* Binding+Api.swift in Sources */, 1D17DBC27F25717BF7A87AF3 /* InstanceRequest.swift in Sources */, 36D0B5EFA3B4AB4D464C9260 /* InstanceBuilder.swift in Sources */, A91EDAFBC3606EDFBD739899 /* InstanceWrapper.swift in Sources */, 98322F9371E1A8461BC614D1 /* Matchable.swift in Sources */, 3753FB83A1FB4B83891AA5C8 /* ObjectScope.swift in Sources */, 7A956FAB419F74D7EB9CAD0B /* Opaque.swift in Sources */, + 77B87F44231157E900321C08 /* Binding+Factory.swift in Sources */, 5393E5DE21B568A88498E454 /* PropertyWrapper.swift in Sources */, 3BD6055555A5C30DABDC8ED2 /* Reference.swift in Sources */, A9112F7CF871475B94A077D7 /* Resolver+FunctionCall.swift in Sources */, @@ -1490,6 +1508,7 @@ files = ( 44F458F61B21D78A91664160 /* BinderVariation.swift in Sources */, 7E3C3E6FD07F3BD76024770A /* InjectionVariation.swift in Sources */, + 77B87F3E231153D200321C08 /* FactoryVariation.swift in Sources */, 70BAF056528B2B33B3A65E9D /* Utils.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1678,12 +1697,14 @@ DB74F17CDFF4886B9C38AD14 /* Container.swift in Sources */, DD5E3AF2B5FCE5E81EBDF606 /* ContextTranslator.swift in Sources */, 76FB9AFE299316E7F3F4C3BB /* InstanceRequest.swift in Sources */, + 77B87F482311580600321C08 /* Binding+Api.swift in Sources */, 157A967F9BAD0B8DAFAC2A36 /* InstanceBuilder.swift in Sources */, 57BFBA2077E70DC1C2FE796C /* InstanceWrapper.swift in Sources */, 293985649250DF270DC89135 /* Matchable.swift in Sources */, 77ED80072311221600AC48F9 /* ValueRequest.swift in Sources */, B4B66D7251BDDE25D6D7FB3C /* ObjectScope.swift in Sources */, 773BE491231124AD000AA1A9 /* Binding.swift in Sources */, + 77B87F45231157EA00321C08 /* Binding+Factory.swift in Sources */, 5365FDFB2DDA6491F3049654 /* Opaque.swift in Sources */, 6A967AE5710606998C2BE070 /* PropertyWrapper.swift in Sources */, B293894FEB67831DDA5F000E /* Reference.swift in Sources */, @@ -1727,12 +1748,14 @@ 283C77045DA55C2134EC9C48 /* Container+TypeForwarding.swift in Sources */, 58ABEE0321A3061048B65EA2 /* Container.swift in Sources */, F06DEB671A4B85ABB0E96E51 /* ContextTranslator.swift in Sources */, + 77B87F472311580500321C08 /* Binding+Api.swift in Sources */, 027015812E961322FE3D942B /* InstanceRequest.swift in Sources */, C6E443EAD892B0B69DA61144 /* InstanceBuilder.swift in Sources */, 389C54E04DD794DA4F648571 /* InstanceWrapper.swift in Sources */, 87FEAEF562B99522083CB87D /* Matchable.swift in Sources */, 6DA49F84E2592B32F81F268B /* ObjectScope.swift in Sources */, 6251955691663E4495DE310D /* Opaque.swift in Sources */, + 77B87F46231157EA00321C08 /* Binding+Factory.swift in Sources */, 5F1647DCC0D437A782647372 /* PropertyWrapper.swift in Sources */, 2D020C6391A4F6A2118585B8 /* Reference.swift in Sources */, 1AC00BCB4DB26B078203DAD8 /* Resolver+FunctionCall.swift in Sources */, @@ -1778,6 +1801,7 @@ D1DF4740A9D86362B63104B8 /* ContextTranslator.swift in Sources */, 826D63FA91E370F0061768B0 /* InstanceRequest.swift in Sources */, 16393BD60FDDD38B5A977C55 /* InstanceBuilder.swift in Sources */, + 77B87F43231157E900321C08 /* Binding+Factory.swift in Sources */, 98ACB1A09194572A946CA90D /* InstanceWrapper.swift in Sources */, 5ED8A7D19F21FA686215F72C /* Matchable.swift in Sources */, B42331BF00B482369B908BB8 /* ObjectScope.swift in Sources */, diff --git a/Templates/BinderEnvironment.swifttemplate b/Templates/BinderEnvironment.swifttemplate index d8224c88..c374d91c 100644 --- a/Templates/BinderEnvironment.swifttemplate +++ b/Templates/BinderEnvironment.swifttemplate @@ -1,5 +1,5 @@ <%- include("SwiftCode") %> -// sourcery:inline:BindingBuilders +// sourcery:inline:SomeBindingBuilders extension ContextedEnvironment { <%= BinderVariation.publicCases.filter { $0.isContexted && !$0.isScoped }.map { $0.render(true) }.joined(separator: "\n\n") %> } diff --git a/Templates/Binding+Factory.swifttemplate b/Templates/Binding+Factory.swifttemplate new file mode 100644 index 00000000..3c0cb861 --- /dev/null +++ b/Templates/Binding+Factory.swifttemplate @@ -0,0 +1,6 @@ +<%- include("SwiftCode") %> +// sourcery:inline:BindingFactoryApi +public extension Binding { +<%= FactoryVariation.publicCases.map { $0.render() }.joined(separator: "\n\n") %> +} +// sourcery:end diff --git a/Templates/FactoryVariation.swift b/Templates/FactoryVariation.swift new file mode 100644 index 00000000..16965e0f --- /dev/null +++ b/Templates/FactoryVariation.swift @@ -0,0 +1,111 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +struct FactoryVariation { + let args: Int + let hasResolver: Bool + let isMatchable: Bool +} + +extension FactoryVariation { + var argTypes: String { + return join((1 ..< args + 1).map { "Arg\($0)" }) + } + + var argTypesOrNil: String? { + return argTypes.isEmpty ? nil : argTypes + } + + var genericTypes: String { + return join("NewInstance", argTypesOrNil) + } + + var factoryInputTypes: String { + return join( + hasResolver ? "ContextedResolver" : nil, + argTypesOrNil + ) + } + + var params: String { + return join( + "for _: NewInstance.Type = NewInstance.self", + "tag: String? = nil", + "factory: @escaping (\(factoryInputTypes)) throws -> NewInstance" + ) + } + + var argReturnType: String { + switch args { + case 0: return "NoArgument" + case 1: return isMatchable ? "MatchableBox1" : "Arg1" + default: return isMatchable ? "MatchableBox\(args)<\(argTypes)>" : "(\(argTypes))" + } + } + + var returnType: String { + return "Binding" + } + + var hashableArgTypes: String { + return join((1 ..< args + 1).map { "Arg\($0): Hashable" }) + } + + var constraints: String { + return isMatchable && args > 0 ? "where \(hashableArgTypes) " : "" + } + + var argVarsOrNil: String? { + switch args { + case 0: return nil + case 1: return isMatchable ? "a.arg1" : "a" + default: return join((1 ... args).map { isMatchable ? "a.arg\($0)" : "a.\($0 - 1)" }) + } + } + + var factoryInputs: String { + return join( + hasResolver ? "r" : "_", + args > 0 ? "a" : "_" + ) + } + + var factoryVars: String { + return join( + hasResolver ? "r" : nil, + argVarsOrNil + ) + } +} + +extension FactoryVariation { + static let maxArgs = 5 + + static let allCases = (0 ... maxArgs) + .flatMap { t in [false, true].map { (t, $0) } } + .flatMap { t in [false, true].map { (t.0, t.1, $0) } } + .map(FactoryVariation.init) + + static let sortedCases = allCases.sorted { [ + $0.args < $1.args, + !$0.isMatchable && $1.isMatchable && $0.args == $1.args, + ].contains(true) } + + static let publicCases = sortedCases + .filter { !($0.args == 0 && !$0.isMatchable) } + .filter { !($0.args > 0 && !$0.hasResolver) } +} + +extension FactoryVariation { + func render() -> String { + return """ + func factory<\(genericTypes)>(\(params)) -> \(returnType) \(constraints){ + return updatedFactory { \(factoryInputs) in try factory(\(factoryVars)) }.updated { + $0.products = [tagged(NewInstance.self, with: tag)] + $0.dependencies = .undefined + } + } + """ + } +} diff --git a/Templates/MatchableBoxes.swifttemplate b/Templates/MatchableBoxes.swifttemplate index 9156a5cf..95c82134 100644 --- a/Templates/MatchableBoxes.swifttemplate +++ b/Templates/MatchableBoxes.swifttemplate @@ -5,7 +5,7 @@ let arg_hashables = (1...i).map { "Arg\($0): Hashable" }.joined(separator: ", ") let type_name = "MatchableBox\(i)<\(arg_types)>" -%> -struct <%= type_name %>: Hashable, Matchable where <%= arg_hashables %> { +public struct <%= type_name %>: Hashable, Matchable where <%= arg_hashables %> { <%= (1...i).map { "let arg\($0): Arg\($0)" }.joined(separator: "\n ") %> } diff --git a/Templates/SwiftCode.swifttemplate b/Templates/SwiftCode.swifttemplate index b71bd266..a0a36506 100644 --- a/Templates/SwiftCode.swifttemplate +++ b/Templates/SwiftCode.swifttemplate @@ -158,6 +158,117 @@ extension BinderVariation { // Copyright © 2019 Swinject Contributors. All rights reserved. // +struct FactoryVariation { + let args: Int + let hasResolver: Bool + let isMatchable: Bool +} + +extension FactoryVariation { + var argTypes: String { + return join((1 ..< args + 1).map { "Arg\($0)" }) + } + + var argTypesOrNil: String? { + return argTypes.isEmpty ? nil : argTypes + } + + var genericTypes: String { + return join("NewInstance", argTypesOrNil) + } + + var factoryInputTypes: String { + return join( + hasResolver ? "ContextedResolver" : nil, + argTypesOrNil + ) + } + + var params: String { + return join( + "for _: NewInstance.Type = NewInstance.self", + "tag: String? = nil", + "factory: @escaping (\(factoryInputTypes)) throws -> NewInstance" + ) + } + + var argReturnType: String { + switch args { + case 0: return "NoArgument" + case 1: return isMatchable ? "MatchableBox1" : "Arg1" + default: return isMatchable ? "MatchableBox\(args)<\(argTypes)>" : "(\(argTypes))" + } + } + + var returnType: String { + return "Binding" + } + + var hashableArgTypes: String { + return join((1 ..< args + 1).map { "Arg\($0): Hashable" }) + } + + var constraints: String { + return isMatchable && args > 0 ? "where \(hashableArgTypes) " : "" + } + + var argVarsOrNil: String? { + switch args { + case 0: return nil + case 1: return isMatchable ? "a.arg1" : "a" + default: return join((1 ... args).map { isMatchable ? "a.arg\($0)" : "a.\($0 - 1)" }) + } + } + + var factoryInputs: String { + return join( + hasResolver ? "r" : "_", + args > 0 ? "a" : "_" + ) + } + + var factoryVars: String { + return join( + hasResolver ? "r" : nil, + argVarsOrNil + ) + } +} + +extension FactoryVariation { + static let maxArgs = 5 + + static let allCases = (0 ... maxArgs) + .flatMap { t in [false, true].map { (t, $0) } } + .flatMap { t in [false, true].map { (t.0, t.1, $0) } } + .map(FactoryVariation.init) + + static let sortedCases = allCases.sorted { [ + $0.args < $1.args, + !$0.isMatchable && $1.isMatchable && $0.args == $1.args, + ].contains(true) } + + static let publicCases = sortedCases + .filter { !($0.args == 0 && !$0.isMatchable) } + .filter { !($0.args > 0 && !$0.hasResolver) } +} + +extension FactoryVariation { + func render() -> String { + return """ + func factory<\(genericTypes)>(\(params)) -> \(returnType) \(constraints){ + return updatedFactory { \(factoryInputs) in try factory(\(factoryVars)) }.updated { + $0.products = [tagged(NewInstance.self, with: tag)] + $0.dependencies = .undefined + } + } + """ + } +} +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + struct InjectionVariation { let paramArgs: Int let factoryArgs: Int diff --git a/Tests/3.0 API/BindingSpec.swift b/Tests/3.0 API/BindingSpec.swift index a2d2a558..89a26060 100644 --- a/Tests/3.0 API/BindingSpec.swift +++ b/Tests/3.0 API/BindingSpec.swift @@ -9,40 +9,40 @@ import Swinject class BindingSpec: QuickSpec { override func spec() { #if swift(>=5.1) it("can define a binding for a type") { let swinject = Swinject { - bbind(Int.self).with(42) - bbind(Double.self) & 42.0 + register().constant(42) + register().constant(42, as: Double.self) } expect { try swinject.instance() as Int } == 42 expect { try swinject.instance() as Double } == 42 } it("can bind the same type with different tags") { let swinject = Swinject { - bbind(String.self) & "Plain" - bbind(String.self, tagged: "Tag") & "Tagged" + register().constant("Plain") + register().constant("Tagged", tag: "Tag") } expect { try swinject.instance(of: String.self) } == "Plain" expect { try swinject.instance(of: String.self, tagged: "Tag") } == "Tagged" } it("throws if has no binding with given tag") { let swinject = Swinject { - bbind(String.self) & "Plain" - bbind(String.self, tagged: "Tag") & "Tagged" + register().constant("Plain") + register().constant("Tagged", tag: "Tag") } expect { try swinject.instance(of: String.self, tagged: "WrongTag") }.to(throwError()) } it("can bind a protocol to it's implementation") { let swinject = Swinject { - bbind(Mammal.self).with(provider { Human() }) + register().factory(for: Mammal.self) { Human() } } expect(try? swinject.instance(of: Mammal.self) is Human) == true } it("can use up to 5 arguments in factory binding") { let swinject = Swinject { - bbind(Int.self) & factory { (_, a1: Int) in a1 } - bbind(Int.self) & factory { (_, a1: Int, a2: Int) in a1 + a2 } - bbind(Int.self) & factory { (_, a1: Int, a2: Int, a3: Int) in a1 + a2 + a3 } - bbind(Int.self) & factory { (_, a1: Int, a2: Int, a3: Int, a4: Int) in a1 + a2 + a3 + a4 } - bbind(Int.self) & factory { (_, a1: Int, a2: Int, a3: Int, a4: Int, a5: Int) in a1 + a2 + a3 + a4 + a5 } + register().factory { (_, a1: Int) in a1 } + register().factory { (_, a1: Int, a2: Int) in a1 + a2 } + register().factory { (_, a1: Int, a2: Int, a3: Int) in a1 + a2 + a3 } + register().factory { (_, a1: Int, a2: Int, a3: Int, a4: Int) in a1 + a2 + a3 + a4 } + register().factory { (_, a1: Int, a2: Int, a3: Int, a4: Int, a5: Int) in a1 + a2 + a3 + a4 + a5 } } expect { try swinject.instance(of: Int.self, arg: 1) } == 1 expect { try swinject.instance(of: Int.self, arg: 1, 2) } == 3 @@ -53,7 +53,7 @@ class BindingSpec: QuickSpec { override func spec() { #if swift(>=5.1) it("does not invoke binding until instance is required") { var invoked = false let swinject = Swinject { - bbind(Int.self) & provider { invoked = true; return 42 } + register().factory(for: Int.self) { invoked = true; return 42 } } _ = swinject.provider(of: Int.self) expect(invoked) == false @@ -61,8 +61,8 @@ class BindingSpec: QuickSpec { override func spec() { #if swift(>=5.1) it("does not invoke unnecessary bindings") { var invoked = false let swinject = Swinject { - bbind(Int.self) & provider { invoked = true; return 42 } - bbind(Int.self, tagged: "tag") & 42 + register().factory(for: Int.self) { invoked = true; return 42 } + register().constant(42, tag: "tag") } _ = try? swinject.instance(of: Int.self, tagged: "tag") expect(invoked) == false From 63032cc7f33efa16a23ad1db997d29d113f47710 Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Sat, 24 Aug 2019 14:05:23 +0200 Subject: [PATCH 213/239] Rewrite singleton spec --- Sources/3.1 API/Binding+Api.swift | 10 ++++++- Tests/3.0 API/BindingSpec.swift | 1 + Tests/3.0 API/SingletonSpec.swift | 48 ++++++++++--------------------- 3 files changed, 25 insertions(+), 34 deletions(-) diff --git a/Sources/3.1 API/Binding+Api.swift b/Sources/3.1 API/Binding+Api.swift index 262d3e9f..9ca9203e 100644 --- a/Sources/3.1 API/Binding+Api.swift +++ b/Sources/3.1 API/Binding+Api.swift @@ -34,13 +34,21 @@ public extension Binding where Instance == Void { } public extension Binding { - func toUse(_: (Instance) -> OtherInstance, tag: String? = nil) -> Self { + func toUse(_: (Instance) -> OtherInstance, tag: String?) -> Self { return updated { $0.products = [tagged(OtherInstance.self, with: tag)] } } + func toUse(_ typeCheck: (Instance) -> OtherInstance) -> Self { + return toUse(typeCheck, tag: nil) + } + func alsoUse(_: (Instance) -> OtherInstance, tag: String? = nil) -> Self { return updated { $0.products.append(tagged(OtherInstance.self, with: tag)) } } + + func alsoUse(_ typeCheck: (Instance) -> OtherInstance) -> Self { + return alsoUse(typeCheck, tag: nil) + } } public extension Binding { diff --git a/Tests/3.0 API/BindingSpec.swift b/Tests/3.0 API/BindingSpec.swift index 89a26060..b61801e3 100644 --- a/Tests/3.0 API/BindingSpec.swift +++ b/Tests/3.0 API/BindingSpec.swift @@ -36,6 +36,7 @@ class BindingSpec: QuickSpec { override func spec() { #if swift(>=5.1) } expect(try? swinject.instance(of: Mammal.self) is Human) == true } + // TODO: type forwarding it("can use up to 5 arguments in factory binding") { let swinject = Swinject { register().factory { (_, a1: Int) in a1 } diff --git a/Tests/3.0 API/SingletonSpec.swift b/Tests/3.0 API/SingletonSpec.swift index 62fa1437..499ac9c4 100644 --- a/Tests/3.0 API/SingletonSpec.swift +++ b/Tests/3.0 API/SingletonSpec.swift @@ -11,25 +11,17 @@ class SingletonSpec: QuickSpec { override func spec() { #if swift(>=5.1) beforeEach { UnboundScope.root.close() } - it("never reuses instances from a provider binding") { + it("never reuses instances from a simple binding") { let swinject = Swinject { - bbind(Human.self) & provider { Human() } + register().factory { Human() } } let first = try? swinject.instance(of: Human.self) let second = try? swinject.instance(of: Human.self) expect(first) !== second } - it("never reuses instances from a factory binding") { - let swinject = Swinject { - bbind(Human.self) & factory { (_, _: Int) in Human() } - } - let first = try? swinject.instance(of: Human.self, arg: 0) - let second = try? swinject.instance(of: Human.self, arg: 0) - expect(first) !== second - } it("injects the same instance from a singleton binding") { let swinject = Swinject { - bbind(Human.self) & singleton { Human() } + registerSingle().factory { Human() } } let first = try? swinject.instance(of: Human.self) let second = try? swinject.instance(of: Human.self) @@ -37,8 +29,8 @@ class SingletonSpec: QuickSpec { override func spec() { #if swift(>=5.1) } it("does not reuse singleton instances for different tags") { let swinject = Swinject { - bbind(Human.self, tagged: "john") & singleton { Human() } - bbind(Human.self, tagged: "rick") & singleton { Human() } + registerSingle().factory(tag: "john") { Human() } + registerSingle().factory(tag: "rick") { Human() } } let john = try? swinject.instance(of: Human.self, tagged: "john") let rick = try? swinject.instance(of: Human.self, tagged: "rick") @@ -46,8 +38,8 @@ class SingletonSpec: QuickSpec { override func spec() { #if swift(>=5.1) } it("injects the same instance from multiton binding when using the same argument") { let swinject = Swinject { - bbind(Human.self) & provider { Human() } - bbind(Pet.self) & multiton { Pet(name: $1, owner: try $0.instance()) } + register().factory { Human() } + registerSingle().factory { Pet(name: $1, owner: try $0.instance()) } } let first = try? swinject.instance(of: Pet.self, arg: "mimi") let second = try? swinject.instance(of: Pet.self, arg: "mimi") @@ -55,38 +47,28 @@ class SingletonSpec: QuickSpec { override func spec() { #if swift(>=5.1) } it("injects a different instance from multiton binding when using a different argument") { let swinject = Swinject { - bbind(Human.self) & provider { Human() } - bbind(Pet.self) & multiton { Pet(name: $1, owner: try $0.instance()) } + register().factory { Human() } + registerSingle().factory { Pet(name: $1, owner: try $0.instance()) } } let mimi = try? swinject.instance(of: Pet.self, arg: "mimi") let riff = try? swinject.instance(of: Pet.self, arg: "riff") expect(mimi) !== riff } - it("can use up to 5 arguments in multiton binding") { - let swinject = Swinject { - bbind(Int.self) & multiton { (_, a1: Int) in a1 } - bbind(Int.self) & multiton { (_, a1: Int, a2: Int) in a1 + a2 } - bbind(Int.self) & multiton { (_, a1: Int, a2: Int, a3: Int) in a1 + a2 + a3 } - bbind(Int.self) & multiton { (_, a1: Int, a2: Int, a3: Int, a4: Int) in a1 + a2 + a3 + a4 } - bbind(Int.self) & multiton { (_, a1: Int, a2: Int, a3: Int, a4: Int, a5: Int) in a1 + a2 + a3 + a4 + a5 } - } - expect { try swinject.instance(of: Int.self, arg: 1) } == 1 - expect { try swinject.instance(of: Int.self, arg: 1, 2) } == 3 - expect { try swinject.instance(of: Int.self, arg: 1, 2, 3) } == 6 - expect { try swinject.instance(of: Int.self, arg: 1, 2, 3, 4) } == 10 - expect { try swinject.instance(of: Int.self, arg: 1, 2, 3, 4, 5) } == 15 - } describe("weak reference") { it("it releases instance if it is not used") { let swinject = Swinject { - bbind(Human.self) & singleton(ref: weakRef) { Human() } + registerSingle() + .factory { Human() } + .withProperties { $0.reference = weakRef } } weak var first = try? swinject.instance() as Human expect(first).to(beNil()) } it("injects the same instance while it is used") { let swinject = Swinject { - bbind(Human.self) & singleton(ref: weakRef) { Human() } + registerSingle() + .factory { Human() } + .withProperties { $0.reference = weakRef } } let first = try? swinject.instance(of: Human.self) let second = try? swinject.instance(of: Human.self) From b1d0d1b7e5247137e9d7eacb0cce289700f62a0a Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Sat, 24 Aug 2019 14:06:52 +0200 Subject: [PATCH 214/239] Rewrite scopes spec --- Tests/3.0 API/ScopesSpec.swift | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Tests/3.0 API/ScopesSpec.swift b/Tests/3.0 API/ScopesSpec.swift index 7f4d687d..014df3d2 100644 --- a/Tests/3.0 API/ScopesSpec.swift +++ b/Tests/3.0 API/ScopesSpec.swift @@ -10,7 +10,7 @@ class ScopesSpec: QuickSpec { override func spec() { #if swift(>=5.1) it("can bind singleton on a scope without context") { let scope = UnboundScope() let swinject = Swinject { - bbind(Human.self) & scoped(scope).singleton { Human() } + registerSingle(in: scope).factory { Human() } } let first = try? swinject.instance(of: Human.self) let second = try? swinject.instance(of: Human.self) @@ -20,7 +20,7 @@ class ScopesSpec: QuickSpec { override func spec() { #if swift(>=5.1) let scope = SessionScope() let session = Session() let swinject = Swinject { - bbind(Human.self) & scoped(scope).singleton { Human() } + registerSingle(in: scope).factory { Human() } } let first = try? swinject.on(session).instance(of: Human.self) let second = try? swinject.on(session).instance(of: Human.self) @@ -29,14 +29,14 @@ class ScopesSpec: QuickSpec { override func spec() { #if swift(>=5.1) it("throws if injecting scoped singleton without context") { let scope = SessionScope() let swinject = Swinject { - bbind(Human.self) & scoped(scope).singleton { Human() } + registerSingle(in: scope).factory { Human() } } expect { try swinject.instance(of: Human.self) }.to(throwError()) } it("injects different intances on different contexts") { let scope = SessionScope() let swinject = Swinject { - bbind(Human.self) & scoped(scope).singleton { Human() } + registerSingle(in: scope).factory { Human() } } let first = try? swinject.on(Session()).instance(of: Human.self) let second = try? swinject.on(Session()).instance(of: Human.self) @@ -46,7 +46,7 @@ class ScopesSpec: QuickSpec { override func spec() { #if swift(>=5.1) it("can close (some) scopes") { let scope = UnboundScope() let swinject = Swinject { - bbind(Human.self) & scoped(scope).singleton { Human() } + registerSingle(in: scope).factory { Human() } } let first = try? swinject.instance(of: Human.self) @@ -58,7 +58,7 @@ class ScopesSpec: QuickSpec { override func spec() { #if swift(>=5.1) it("notifies instances when scope is closed") { let scope = UnboundScope() let swinject = Swinject { - bbind(Door.self) & scoped(scope).singleton { Door() } + registerSingle(in: scope).factory { Door() } } let door = try? swinject.instance() as Door @@ -70,7 +70,7 @@ class ScopesSpec: QuickSpec { override func spec() { #if swift(>=5.1) let scope = SessionScope() var session = Session() as Session? let swinject = Swinject { - bbind(Door.self) & scoped(scope).singleton { Door() } + registerSingle(in: scope).factory { Door() } } let door = try? swinject.on(session!).instance(of: Door.self) @@ -82,7 +82,7 @@ class ScopesSpec: QuickSpec { override func spec() { #if swift(>=5.1) let scope = SessionScope() var session = Session() as Session? let swinject = Swinject { - bbind(Human.self) & scoped(scope).singleton { Human() } + registerSingle(in: scope).factory { Human() } } weak var instance = try? swinject.on(session!).instance(of: Human.self) From e85efc6ceb30c1bc930306600b00e4f8ccdc0b1d Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Sat, 24 Aug 2019 14:08:35 +0200 Subject: [PATCH 215/239] Rewrite retrieval spec --- Tests/3.0 API/RetrievalSpec.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/3.0 API/RetrievalSpec.swift b/Tests/3.0 API/RetrievalSpec.swift index 300e63f4..a0dfd72a 100644 --- a/Tests/3.0 API/RetrievalSpec.swift +++ b/Tests/3.0 API/RetrievalSpec.swift @@ -14,8 +14,8 @@ class RetrievalSpec: QuickSpec { override func spec() { #if swift(>=5.1) lazy var int: Int = try! instance() } let swinject = Swinject { - bbind(IntHolder.self) & provider { IntHolder(swinject: $0) } - bbind(Int.self) & 42 + register().factory { IntHolder(swinject: $0) } + register().constant(42) } var holder = try? swinject.instance() as IntHolder expect(holder?.int) == 42 From eb80388b398c888b94e4d8d8f454f5bda8838cb0 Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Sat, 24 Aug 2019 14:10:03 +0200 Subject: [PATCH 216/239] Rewrite property wrappers spec --- Tests/3.0 API/PropertyWrappersSpec.swift | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Tests/3.0 API/PropertyWrappersSpec.swift b/Tests/3.0 API/PropertyWrappersSpec.swift index 745671bd..ca63b50e 100644 --- a/Tests/3.0 API/PropertyWrappersSpec.swift +++ b/Tests/3.0 API/PropertyWrappersSpec.swift @@ -17,7 +17,7 @@ class PropertyWrappersSpec: QuickSpec { override func spec() { #if swift(>=5.1) } it("can inject wrapped provider of a bound type") { let swinject = Swinject { - bbind(Int.self) & 42 + register().constant(42) } let wrappedInt = try? swinject.instance() as Wrapped expect { wrappedInt?.wrappedValue } == 42 @@ -34,27 +34,27 @@ class PropertyWrappersSpec: QuickSpec { override func spec() { #if swift(>=5.1) } it("can inject lazy provider of bound type with arguments") { let swinject = Swinject { - bbind(Int.self) & factory { Int($1 as String)! } + register().factory { Int($1 as String)! } } let wrappedInt = try? swinject.instance(arg: "42") as Wrapped expect { wrappedInt?.wrappedValue } == 42 } it("throws if provided type is bound with different tag") { let swinject = Swinject { - bbind(Int.self) & 42 + register().constant(42) } expect { try swinject.instance(tagged: "tag") as Wrapped }.to(throwError()) } it("can inject lazy provider of tagged bound type") { let swinject = Swinject { - bbind(Int.self, tagged: "tag") & 42 + register().constant(42, tag: "tag") } let wrappedInt = try? swinject.instance(tagged: "tag") as Wrapped expect { wrappedInt?.wrappedValue } == 42 } it("can inject nested property wrappers") { let swinject = Swinject { - bbind(Int.self) & 42 + register().constant(42) } let doubleWrappedInt = try? swinject.instance() as Wrapped> expect { doubleWrappedInt?.wrappedValue.wrappedValue } == 42 @@ -64,8 +64,8 @@ class PropertyWrappersSpec: QuickSpec { override func spec() { #if swift(>=5.1) @Wrapped var int: Int } let swinject = Swinject { - bbind(Int.self) & 42 - bbind(IntHolder.self) & provider { try IntHolder(int: $0.instance()) } + register().constant(42) + register().factory { try IntHolder(int: $0.instance()) } } expect { try swinject.instance(of: IntHolder.self).int } == 42 } From 326d27192f851389b169b41966e2e3aa7c7f8afc Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Sat, 24 Aug 2019 14:16:54 +0200 Subject: [PATCH 217/239] Rewrite override spec --- Sources/3.1 API/Binding.swift | 4 +-- Tests/3.0 API/OverrideSpec.swift | 54 ++++++++++++++++---------------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/Sources/3.1 API/Binding.swift b/Sources/3.1 API/Binding.swift index 73be94b9..d810c8cf 100644 --- a/Sources/3.1 API/Binding.swift +++ b/Sources/3.1 API/Binding.swift @@ -3,8 +3,8 @@ // public struct BindingProperties { - var overrides: Bool - var reference: ReferenceMaker + public var overrides: Bool + public var reference: ReferenceMaker static let `default` = BindingProperties(overrides: false, reference: strongRef) } diff --git a/Tests/3.0 API/OverrideSpec.swift b/Tests/3.0 API/OverrideSpec.swift index 1271cfa8..325eb446 100644 --- a/Tests/3.0 API/OverrideSpec.swift +++ b/Tests/3.0 API/OverrideSpec.swift @@ -10,66 +10,66 @@ class OverrideSpec: QuickSpec { override func spec() { #if swift(>=5.1) it("does not allow multiple bindings for the same type") { expect { _ = Swinject { - bbind(Int.self) & 42 - bbind(Int.self) & provider { 25 + 17 } + register().constant(42) + register().factory { 25 + 17 } } }.to(throwAssertion()) } it("does not allow bindings for type and it's optional") { expect { _ = Swinject { - bbind(Int?.self) & 42 - bbind(Int.self) & provider { 25 + 17 } + register().constant(42, as: Int?.self) + register().factory { 25 + 17 } } }.to(throwAssertion()) } it("does not allow multiple bindings for the same type in a module hierarchy") { let firstModule = Swinject.Module("first") { - bbind(Int.self) & 42 + register().constant(42) } expect { _ = Swinject { include(firstModule) - bbind(Int.self) & provider { 25 + 17 } + register().factory { 25 + 17 } } }.to(throwAssertion()) } it("can declare that binding overrides previous binding for the same type") { let swinject = Swinject { - bbind(Int.self) & 0 - bbind(Int.self, overrides: true) & 42 + register().constant(0) + register().constant(42).withProperties { $0.overrides = true } } expect { try swinject.instance(of: Int.self) } == 42 } it("uses the last overriding binding for the injection") { let swinject = Swinject { - bbind(Int.self) & 1 - bbind(Int.self, overrides: true) & 2 - bbind(Int.self, overrides: true) & 42 + register().constant(1) + register().constant(2).withProperties { $0.overrides = true } + register().constant(3).withProperties { $0.overrides = true } } - expect { try swinject.instance(of: Int.self) } == 42 + expect { try swinject.instance(of: Int.self) } == 3 } it("must declare overriding binding after the overriden one") { expect { _ = Swinject { - bbind(Int.self, overrides: true) & 42 - bbind(Int.self) & 0 + register().constant(42).withProperties { $0.overrides = true } + register().constant(0) } }.to(throwAssertion()) } it("does not allow overriding binding if there is nothing to override") { expect { _ = Swinject { - bbind(Int.self, overrides: true) & 42 + register().constant(42).withProperties { $0.overrides = true } } }.to(throwAssertion()) } it("does not allow overriding bindings in modules by default") { let firstModule = Swinject.Module("first") { - bbind(Int.self) & 0 + register().constant(0) } let secondModule = Swinject.Module("second") { - bbind(Int.self, overrides: true) & 42 + register().constant(42).withProperties { $0.overrides = true } } expect { _ = Swinject { @@ -80,10 +80,10 @@ class OverrideSpec: QuickSpec { override func spec() { #if swift(>=5.1) } it("can allow module to have overriding bindings when including it") { let firstModule = Swinject.Module("first") { - bbind(Int.self) & 0 + register().constant(0) } let secondModule = Swinject.Module("second") { - bbind(Int.self, overrides: true) & 42 + register().constant(42).withProperties { $0.overrides = true } } let swinject = Swinject { include(firstModule) @@ -93,10 +93,10 @@ class OverrideSpec: QuickSpec { override func spec() { #if swift(>=5.1) } it("allows overriding bindings in the entire included module tree") { let firstModule = Swinject.Module("first") { - bbind(Int.self) & 0 + register().constant(0) } let secondModule = Swinject.Module("second") { - bbind(Int.self, overrides: true) & 42 + register().constant(42).withProperties { $0.overrides = true } } let thirdModule = Swinject.Module("third") { include(secondModule) @@ -109,10 +109,10 @@ class OverrideSpec: QuickSpec { override func spec() { #if swift(>=5.1) } it("can allow silent overrides in a module") { let firstModule = Swinject.Module("first") { - bbind(Int.self) & 0 + register().constant(0) } let secondModule = Swinject.Module("second", allowsSilentOverride: true) { - bbind(Int.self) & 42 + register().constant(42).withProperties { $0.overrides = true } } let swinject = Swinject { include(firstModule) @@ -122,10 +122,10 @@ class OverrideSpec: QuickSpec { override func spec() { #if swift(>=5.1) } it("does not apply silent override transitively") { let firstModule = Swinject.Module("first") { - bbind(Int.self) & 0 + register().constant(0) } let secondModule = Swinject.Module("second") { - bbind(Int.self) & 42 + register().constant(42) } let thirdModule = Swinject.Module("third", allowsSilentOverride: true) { include(secondModule) @@ -139,8 +139,8 @@ class OverrideSpec: QuickSpec { override func spec() { #if swift(>=5.1) } it("can allow silent override on the Swinject declaration") { let swinject = Swinject(allowsSilentOverride: true) { - bbind(Int.self) & 0 - bbind(Int.self) & 42 + register().constant(0) + register().constant(42) } expect { try swinject.instance(of: Int.self) } == 42 } From 4d64da9c6d3b6c2e4beed56025bc1be1db140f6a Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Sat, 24 Aug 2019 14:21:53 +0200 Subject: [PATCH 218/239] Rewrite optionals spec --- Sources/3.1 API/Binding+Api.swift | 4 +--- Tests/3.0 API/BindingSpec.swift | 2 +- Tests/3.0 API/OptionalsSpec.swift | 14 +++++++------- Tests/3.0 API/OverrideSpec.swift | 2 +- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Sources/3.1 API/Binding+Api.swift b/Sources/3.1 API/Binding+Api.swift index 9ca9203e..acbc7489 100644 --- a/Sources/3.1 API/Binding+Api.swift +++ b/Sources/3.1 API/Binding+Api.swift @@ -23,9 +23,7 @@ public func registerSingle() -> Binding( - _ value: Value, as _: Value.Type = Value.self, tag: String? = nil - ) -> Binding { + func constant(_ value: Value, tag: String? = nil) -> Binding { return updatedFactory { _, _ in value }.updated { $0.products = [tagged(Value.self, with: tag)] $0.dependencies = .none diff --git a/Tests/3.0 API/BindingSpec.swift b/Tests/3.0 API/BindingSpec.swift index b61801e3..7ebc6ac1 100644 --- a/Tests/3.0 API/BindingSpec.swift +++ b/Tests/3.0 API/BindingSpec.swift @@ -10,7 +10,7 @@ class BindingSpec: QuickSpec { override func spec() { #if swift(>=5.1) it("can define a binding for a type") { let swinject = Swinject { register().constant(42) - register().constant(42, as: Double.self) + register().constant(42 as Double) } expect { try swinject.instance() as Int } == 42 expect { try swinject.instance() as Double } == 42 diff --git a/Tests/3.0 API/OptionalsSpec.swift b/Tests/3.0 API/OptionalsSpec.swift index f0ee5acc..542227aa 100644 --- a/Tests/3.0 API/OptionalsSpec.swift +++ b/Tests/3.0 API/OptionalsSpec.swift @@ -9,25 +9,25 @@ import Swinject class OptionalsSpec: QuickSpec { override func spec() { #if swift(>=5.1) it("can use a binding for bound type's optional") { let swinject = Swinject { - bbind(Int.self) & 42 + register().constant(42) } expect { try swinject.instance() as Int? } == 42 } it("can use a binding of the injected type's optional") { let swinject = Swinject { - bbind(Int?.self) & 42 + register().constant(42 as Int?) } expect { try swinject.instance() as Int } == 42 } it("throws if binding of the type's optional produces nil") { let swinject = Swinject { - bbind(Int?.self) & nil + register().constant(nil as Int?) } expect { try swinject.instance() as Int }.to(throwError()) } it("can use a binding for bound type's double optional") { let swinject = Swinject { - bbind(Int.self) & 42 + register().constant(42) } expect { try swinject.instance() as Int?? } == 42 } @@ -37,13 +37,13 @@ class OptionalsSpec: QuickSpec { override func spec() { #if swift(>=5.1) } it("throws if has an incomplete binding for the optional") { let swinject = Swinject { - bbind(Int.self) & provider { Int(try $0.instance() as Double) } + register().factory { Int(try $0.instance() as Double) } } expect { try swinject.instance() as Int? }.to(throwError()) } it("injects same singleton instance for type and it's optional") { let swinject = Swinject { - bbind(Human.self) & singleton { Human() } + registerSingle().factory { Human() } } let direct = try? swinject.instance(of: Human.self) let optional = try? swinject.instance(of: Human?.self) @@ -51,7 +51,7 @@ class OptionalsSpec: QuickSpec { override func spec() { #if swift(>=5.1) } it("injects instance on the optional of a binding's context") { let swinject = Swinject { - bbind(Int.self) & contexted(String.self).provider { (_, c: String) in Int(c)! } + register(inContextOf: String.self).factory { try Int($0.context())! } } expect { try swinject.on("42" as String?).instance(of: Int.self) } == 42 } diff --git a/Tests/3.0 API/OverrideSpec.swift b/Tests/3.0 API/OverrideSpec.swift index 325eb446..e1bcc4fc 100644 --- a/Tests/3.0 API/OverrideSpec.swift +++ b/Tests/3.0 API/OverrideSpec.swift @@ -18,7 +18,7 @@ class OverrideSpec: QuickSpec { override func spec() { #if swift(>=5.1) it("does not allow bindings for type and it's optional") { expect { _ = Swinject { - register().constant(42, as: Int?.self) + register().constant(42 as Int?) register().factory { 25 + 17 } } }.to(throwAssertion()) From 323143504cfca5d498ed835066989c62f99d773a Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Sat, 24 Aug 2019 14:23:24 +0200 Subject: [PATCH 219/239] Rewrite modules spec --- Tests/3.0 API/ModulesSpec.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Tests/3.0 API/ModulesSpec.swift b/Tests/3.0 API/ModulesSpec.swift index e5dbceb1..555788f7 100644 --- a/Tests/3.0 API/ModulesSpec.swift +++ b/Tests/3.0 API/ModulesSpec.swift @@ -9,10 +9,10 @@ import Swinject class ModulesSpec: QuickSpec { override func spec() { #if swift(>=5.1) it("can separate bindings into modules") { let intModule = Swinject.Module("Int") { - bbind(Int.self) & 42 + register().constant(42) } let doubleModule = Swinject.Module("Double") { - bbind(Double.self) & provider { 25 + 17 } + register().factory { 25 + 17 as Double } } let swinject = Swinject { include(intModule) @@ -23,11 +23,11 @@ class ModulesSpec: QuickSpec { override func spec() { #if swift(>=5.1) } it("can handle module hierarchies") { let intModule = Swinject.Module("Int") { - bbind(Int.self) & 42 + register().constant(42) } let numbersModule = Swinject.Module("Double") { include(intModule) - bbind(Double.self) & provider { 25 + 17 } + register().factory { 25 + 17 as Double } } let swinject = Swinject { include(numbersModule) From c7d0af4657877396dcfe72ac6f74c80efb84370d Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Sat, 24 Aug 2019 14:28:15 +0200 Subject: [PATCH 220/239] Rewrite injection spec --- Tests/3.0 API/InjectionSpec.swift | 46 +++++++++++++++---------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/Tests/3.0 API/InjectionSpec.swift b/Tests/3.0 API/InjectionSpec.swift index 1d2507b4..9631b4a6 100644 --- a/Tests/3.0 API/InjectionSpec.swift +++ b/Tests/3.0 API/InjectionSpec.swift @@ -10,21 +10,21 @@ class InjectionSpec: QuickSpec { override func spec() { #if swift(>=5.1) describe("instance") { it("throws if bound type has missing dependency") { let swinject = Swinject { - bbind(Pet.self) & provider { Pet(owner: try $0.instance()) } + register().factory { Pet(owner: try $0.instance()) } } expect { try swinject.instance(of: Pet.self) }.to(throwError()) } it("injects instance if all dependencies are bound") { let john = Human() let swinject = Swinject { - bbind(Pet.self) & provider { Pet(owner: try $0.instance()) } - bbind(Human.self) & instance(john) + register().factory { Pet(owner: try $0.instance()) } + register().constant(john) } expect { try swinject.instance(of: Pet.self).owner } === john } it("throws if type's binding requires different arguments") { let swinject = Swinject { - bbind(Int.self) & factory { (_, string: String) in Int(string)! } + register().factory { (_, string: String) in Int(string)! } } expect { try swinject.instance() as Int }.to(throwError()) expect { try swinject.instance(arg: 42.0) as Int }.to(throwError()) @@ -33,7 +33,7 @@ class InjectionSpec: QuickSpec { override func spec() { #if swift(>=5.1) describe("provider") { it("can inject instance provider") { let swinject = Swinject { - bbind(Int.self) & 42 + register().constant(42) } let intProvider = swinject.provider(of: Int.self) expect { try intProvider() } == 42 @@ -45,14 +45,14 @@ class InjectionSpec: QuickSpec { override func spec() { #if swift(>=5.1) } it("throws if provided type has missing dependency") { let swinject = Swinject { - bbind(Pet.self) & provider { Pet(owner: try $0.instance()) } + register().factory { Pet(owner: try $0.instance()) } } let petProvider = swinject.provider(of: Pet.self) expect { try petProvider() }.to(throwError()) } it("throws if provided type's binding requires different arguments") { let swinject = Swinject { - bbind(Int.self) & factory { (_, string: String) in Int(string)! } + register().factory { (_, string: String) in Int(string)! } } expect { try swinject.provider(of: Int.self)() }.to(throwError()) expect { try swinject.provider(of: Int.self, arg: 42.0)() }.to(throwError()) @@ -62,8 +62,8 @@ class InjectionSpec: QuickSpec { override func spec() { #if swift(>=5.1) it("can inject instance factory") { let john = Human() let swinject = Swinject { - bbind(Pet.self) & factory { try Pet(name: $1, owner: $0.instance()) } - bbind(Human.self) & john + register().factory { try Pet(name: $1, owner: $0.instance()) } + register().constant(john) } let petFactory = swinject.factory() as (String) throws -> Pet @@ -79,22 +79,22 @@ class InjectionSpec: QuickSpec { override func spec() { #if swift(>=5.1) } it("throws if created type has missing dependency") { let swinject = Swinject { - bbind(Pet.self) & factory { try Pet(name: $1, owner: $0.instance()) } + register().factory { try Pet(name: $1, owner: $0.instance()) } } let petFactory = swinject.factory() as (String) throws -> Pet expect { try petFactory("mimi") }.to(throwError()) } it("throws if created type's binding requires different arguments") { let swinject = Swinject { - bbind(Pet.self) & factory { try Pet(name: $1, owner: $0.instance()) } - bbind(Human.self) & provider { Human() } + register().factory { try Pet(name: $1, owner: $0.instance()) } + register().factory { Human() } } let petFactory = swinject.factory() as (Int) throws -> Pet expect { try petFactory(42) }.to(throwError()) } it("can curry factory arguments") { let swinject = Swinject { - bbind(Int.self) & factory { + register().factory { Int($1 as Int) + Int($2 as Double) + Int($3 as String)! } } @@ -111,7 +111,7 @@ class InjectionSpec: QuickSpec { override func spec() { #if swift(>=5.1) return int } let swinject = Swinject { - bbind(Int.self) & 42 + register().constant(42) } expect { try swinject.call1(echo) } == 42 } @@ -120,18 +120,18 @@ class InjectionSpec: QuickSpec { override func spec() { #if swift(>=5.1) return int + Int(double) + Int(string)! } let swinject = Swinject { - bbind(Int.self) & 17 - bbind(Double.self) & 14.0 - bbind(String.self) & "11" + register().constant(17) + register().constant(14.0) + register().constant("11") } expect { try swinject.call(sum) } == 42 } it("can call initializer when declaring bindings") { let john = Human() let swinject = Swinject { - bbind(String.self) & "mimi" - bbind(Human.self) & john - bbind(Pet.self) & provider { try $0.call(Pet.init) } + register().constant("mimi") + register().constant(john) + register().factory { try $0.call(Pet.init) } } let pet = try? swinject.instance(of: Pet.self) expect(pet?.name) == "mimi" @@ -139,9 +139,9 @@ class InjectionSpec: QuickSpec { override func spec() { #if swift(>=5.1) } it("can be used for property injection") { let swinject = Swinject { - bbind(Int.self) & 42 - bbind(Double.self) & 124 - bbind(String.self) & "john" + register().constant(42) + register().constant(124 as Double) + register().constant("john") } let john = Human() try? swinject.call(john.injectProperties) From 950b84fe62457bf6032fecb9dc61e25150944699 Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Sat, 24 Aug 2019 14:37:20 +0200 Subject: [PATCH 221/239] Rewrite context spec --- Tests/3.0 API/ContextSpec.swift | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/Tests/3.0 API/ContextSpec.swift b/Tests/3.0 API/ContextSpec.swift index bcef88d0..ed1b584a 100644 --- a/Tests/3.0 API/ContextSpec.swift +++ b/Tests/3.0 API/ContextSpec.swift @@ -10,23 +10,23 @@ import Swinject class ContextSpec: QuickSpec { override func spec() { #if swift(>=5.1) it("can pass context to the bindings") { let swinject = Swinject { - bbind(Int.self) & contexted(String.self).provider { (_, c: String) in Int(c)! } - bbind(Double.self) & contexted(String.self).factory { (_, c: String, a: Int) in Double(c)! + Double(a) } + register(inContextOf: String.self).factory { try Int($0.context())! } + register(inContextOf: String.self).factory { try Double($0.context())! + Double($1 as Int) } } expect { try swinject.on("42").instance(of: Int.self) } == 42 expect { try swinject.on("25").instance(of: Double.self, arg: 17) } == 42 } it("throws if injecting on the wrong context") { let swinject = Swinject { - bbind(Int.self) & contexted(Double.self).provider { (_, c: Double) in Int(c) } + register(inContextOf: Double.self).factory { try Int($0.context()) } } expect { try swinject.on("context").instance(of: Int.self) }.to(throwError()) } it("does not invoke bindings on other contexts") { var invoked = false let swinject = Swinject { - bbind(Int.self) & contexted(String.self).provider { (_, _: String) in 42 } - bbind(Int.self) & contexted(Double.self).provider { (_, _: Double) in + register(inContextOf: String.self).factory { 42 } + register(inContextOf: Double.self).factory(for: Int.self) { invoked = true return 42 } @@ -36,7 +36,7 @@ class ContextSpec: QuickSpec { override func spec() { #if swift(>=5.1) } it("can use binding without context in any context") { let swinject = Swinject { - bbind(Int.self) & 42 + register().constant(42) } expect { try swinject.on("context").instance() as Int } == 42 expect { try swinject.on(Human()).instance() as Int } == 42 @@ -44,10 +44,8 @@ class ContextSpec: QuickSpec { override func spec() { #if swift(>=5.1) it("passes context to the dependencies") { let john = Human() let swinject = Swinject { - bbind(Human.self) & contexted(String.self).provider { (_, c: String) in - c == "john" ? john : Human() - } - bbind(Pet.self) & provider { Pet(owner: try $0.instance()) } + register(inContextOf: String.self).factory { try $0.context() == "john" ? john : Human() } + register().factory { Pet(owner: try $0.instance()) } } let pet = try? swinject.on("john").instance(of: Pet.self) expect(pet?.owner) === john @@ -56,7 +54,7 @@ class ContextSpec: QuickSpec { override func spec() { #if swift(>=5.1) it("can translate contexts") { let john = Human() let swinject = Swinject { - bbind(Pet.self) & contexted(Human.self).provider { Pet(owner: $1) } + register(inContextOf: Human.self).factory { try Pet(owner: $0.context()) } registerContextTranslator(from: String.self) { $0 == "john" ? john : Human() } } let pet = try? swinject.on("john").instance(of: Pet.self) @@ -64,7 +62,7 @@ class ContextSpec: QuickSpec { override func spec() { #if swift(>=5.1) } it("throws if translator has incorrect types") { let swinject = Swinject { - bbind(Int.self) & contexted(String.self).provider { (_, c: String) in Int(c)! } + register(inContextOf: String.self).factory { try Int($0.context())! } registerContextTranslator(from: Float.self) { String($0) } registerContextTranslator(from: Double.self) { Int($0) } } @@ -72,8 +70,8 @@ class ContextSpec: QuickSpec { override func spec() { #if swift(>=5.1) } it("throws if multiple bindings could be used with translated contexts") { let swinject = Swinject { - bbind(Int.self) & contexted(Float.self).provider { (_, c: Float) in Int(c) } - bbind(Int.self) & contexted(Double.self).provider { (_, c: Double) in Int(c) } + register(inContextOf: Float.self).factory { try Int($0.context()) } + register(inContextOf: Double.self).factory { try Int($0.context()) } registerContextTranslator(from: String.self) { Float($0)! } registerContextTranslator(from: String.self) { Double($0)! } } @@ -81,15 +79,15 @@ class ContextSpec: QuickSpec { override func spec() { #if swift(>=5.1) } it("throws if has binding on given context and translator leading to other binding") { let swinject = Swinject { - bbind(Int.self) & contexted(String.self).provider { (_, c: String) in Int(c)! } - bbind(Int.self) & contexted(Double.self).provider { (_, c: Double) in Int(c) } + register(inContextOf: String.self).factory { try Int($0.context())! } + register(inContextOf: Double.self).factory { try Int($0.context()) } registerContextTranslator(from: String.self) { Double($0)! } } expect { try swinject.on("42").instance(of: Int.self) }.to(throwError()) } it("does not throw if multiple translators lead to the same binding") { let swinject = Swinject { - bbind(Int.self) & contexted(Any.self).provider { _, _ in 42 } + register(inContextOf: Any.self).factory { 42 } registerContextTranslator(from: Double.self) { "\($0)" } registerContextTranslator(from: Double.self) { Float($0) } } From 732f6583fb517570a251f0302d81efd5a6a3574e Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Sat, 24 Aug 2019 14:40:35 +0200 Subject: [PATCH 222/239] Rewrite circularity spec --- Tests/3.0 API/CIrcularitySpec.swift | 30 +++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/Tests/3.0 API/CIrcularitySpec.swift b/Tests/3.0 API/CIrcularitySpec.swift index e8928e12..57adf234 100644 --- a/Tests/3.0 API/CIrcularitySpec.swift +++ b/Tests/3.0 API/CIrcularitySpec.swift @@ -14,15 +14,15 @@ class CircularitySpec: QuickSpec { override func spec() { #if swift(>=5.1) class Foo { init(_: Bar) {} } class Bar { init(_: Foo) {} } let swinject = Swinject { - bbind(Foo.self) & provider { Foo(try $0.instance()) } - bbind(Bar.self) & provider { Bar(try $0.instance()) } + register().factory { Foo(try $0.instance()) } + register().factory { Bar(try $0.instance()) } } expect { try swinject.instance(of: Foo.self) }.to(throwError()) } it("does not produce false circularity detections") { let swinject = Swinject { - bbind(Int.self) & 21 - bbind(Int.self, tagged: "computed") & provider { try $0.instance() + $0.instance() } + register().constant(21) + register().factory(for: Int.self, tag: "computed") { try $0.instance() + $0.instance() } } expect { try swinject.instance(of: Int.self, tagged: "computed") } == 42 } @@ -30,8 +30,8 @@ class CircularitySpec: QuickSpec { override func spec() { #if swift(>=5.1) class Foo { init(_: Bar) {} } class Bar { init(_: Lazy) {} } let swinject = Swinject { - bbind(Foo.self) & provider { Foo(try $0.instance()) } - bbind(Bar.self) & provider { Bar(try $0.instance()) } + register().factory { Foo(try $0.instance()) } + register().factory { Bar(try $0.instance()) } } expect { try swinject.instance(of: Foo.self) }.notTo(throwError()) } @@ -45,8 +45,10 @@ class CircularitySpec: QuickSpec { override func spec() { #if swift(>=5.1) init(_ foo: Lazy) { _foo = foo } } let swinject = Swinject { - bbind(Foo.self) & singleton(ref: weakRef) { Foo(try $0.instance()) } - bbind(Bar.self) & provider { Bar(try $0.instance()) } + register().factory { Bar(try $0.instance()) } + registerSingle() + .factory { Foo(try $0.instance()) } + .withProperties { $0.reference = weakRef } } let foo = try? swinject.instance(of: Foo.self) expect { foo?.bar.foo } === foo @@ -61,8 +63,10 @@ class CircularitySpec: QuickSpec { override func spec() { #if swift(>=5.1) init(_ foo: Lazy>) { _foo = foo } } let swinject = Swinject { - bbind(Foo.self) & singleton(ref: weakRef) { Foo(try $0.instance()) } - bbind(Bar.self) & provider { Bar(try $0.instance()) } + register().factory { Bar(try $0.instance()) } + registerSingle() + .factory { Foo(try $0.instance()) } + .withProperties { $0.reference = weakRef } } let foo = try? swinject.instance(of: Foo.self) expect { foo?.bar.foo } === foo @@ -77,8 +81,10 @@ class CircularitySpec: QuickSpec { override func spec() { #if swift(>=5.1) init(_ foo: Lazy>) { _foo = foo } } let swinject = Swinject { - bbind(Foo.self) & singleton(ref: weakRef) { Foo(try $0.instance()) } - bbind(Bar.self) & provider { Bar(try $0.instance()) } + register().factory { Bar(try $0.instance()) } + registerSingle() + .factory { Foo(try $0.instance()) } + .withProperties { $0.reference = weakRef } } var foo = try? swinject.instance(of: Foo.self) let bar = foo?.bar From 1c708f72c0b7c39508f494aeaa290663c26b174d Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Sat, 24 Aug 2019 14:46:07 +0200 Subject: [PATCH 223/239] Ditch bind Api --- Sources/3.0 API/BinderEnvironment.swift | 192 ------------------ .../{3.1 API => 3.0 API}/Binding+Api.swift | 0 .../Binding+Factory.swift | 0 Sources/{3.1 API => 3.0 API}/Binding.swift | 8 - Sources/3.0 API/BindingBuilder.swift | 23 --- Sources/3.0 API/InstanceBuilder.swift | 21 -- Sources/3.0 API/Opaque.swift | 16 -- Sources/3.0 API/ScopedBinding.swift | 67 ------ Sources/3.0 API/SimpleBinding.swift | 46 ----- Sources/3.0 API/TypeBinder.swift | 41 ---- .../{3.1 API => 3.0 API}/ValueRequest.swift | 0 Swinject.xcodeproj/project.pbxproj | 104 +--------- Templates/BinderEnvironment.swifttemplate | 12 -- Templates/BinderVariation.swift | 155 -------------- Templates/SwiftCode.swifttemplate | 155 -------------- Tests/3.0 API/PropertyWrappersSpec.swift | 2 +- Tests/Support/Bridge.swift | 11 - .../Unit Specs/SwinjectTreeBuilderSpec.swift | 28 +-- 18 files changed, 19 insertions(+), 862 deletions(-) delete mode 100644 Sources/3.0 API/BinderEnvironment.swift rename Sources/{3.1 API => 3.0 API}/Binding+Api.swift (100%) rename Sources/{3.1 API => 3.0 API}/Binding+Factory.swift (100%) rename Sources/{3.1 API => 3.0 API}/Binding.swift (90%) delete mode 100644 Sources/3.0 API/BindingBuilder.swift delete mode 100644 Sources/3.0 API/InstanceBuilder.swift delete mode 100644 Sources/3.0 API/Opaque.swift delete mode 100644 Sources/3.0 API/ScopedBinding.swift delete mode 100644 Sources/3.0 API/SimpleBinding.swift delete mode 100644 Sources/3.0 API/TypeBinder.swift rename Sources/{3.1 API => 3.0 API}/ValueRequest.swift (100%) delete mode 100644 Templates/BinderEnvironment.swifttemplate delete mode 100644 Templates/BinderVariation.swift delete mode 100644 Tests/Support/Bridge.swift diff --git a/Sources/3.0 API/BinderEnvironment.swift b/Sources/3.0 API/BinderEnvironment.swift deleted file mode 100644 index ee3dee84..00000000 --- a/Sources/3.0 API/BinderEnvironment.swift +++ /dev/null @@ -1,192 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -public struct ScopedEnvironment where AScope: Scope { - public typealias Context = AScope.Context - let scope: AScope -} - -public struct ContextedEnvironment {} - -public func contexted(_: Context.Type) -> ContextedEnvironment { - return ContextedEnvironment() -} - -public func scoped(_ scope: AScope) -> ScopedEnvironment where AScope: Scope { - return ScopedEnvironment(scope: scope) -} - -// swiftlint:disable line_length -// swiftlint:disable identifier_name - -public func instance(_ instance: Type) -> SomeBindingBuilder { - return SimpleBinding.Builder { _, _, _ in instance }.opaque -} - -// sourcery:inline:SomeBindingBuilders -extension ContextedEnvironment { - public func provider(_ builder: @escaping () throws -> Type) -> SomeBindingBuilder { - return SimpleBinding.Builder { _, _, _ in try builder() }.opaque - } - - public func provider(_ builder: @escaping (Resolver) throws -> Type) -> SomeBindingBuilder { - return SimpleBinding.Builder { r, _, _ in try builder(r) }.opaque - } - - public func provider(_ builder: @escaping (Resolver, Context) throws -> Type) -> SomeBindingBuilder { - return SimpleBinding.Builder { r, c, _ in try builder(r, c) }.opaque - } - - public func factory(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SomeBindingBuilder { - return SimpleBinding.Builder { r, c, a in try builder(r, c, a) }.opaque - } - - public func factory(_ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable { - return SimpleBinding.Builder> { r, c, a in try builder(r, c, a.arg1) }.opaque - } - - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SomeBindingBuilder { - return SimpleBinding.Builder { r, c, a in try builder(r, c, a.0, a.1) }.opaque - } - - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable { - return SimpleBinding.Builder> { r, c, a in try builder(r, c, a.arg1, a.arg2) }.opaque - } - - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingBuilder { - return SimpleBinding.Builder { r, c, a in try builder(r, c, a.0, a.1, a.2) }.opaque - } - - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - return SimpleBinding.Builder> { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3) }.opaque - } - - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingBuilder { - return SimpleBinding.Builder { r, c, a in try builder(r, c, a.0, a.1, a.2, a.3) }.opaque - } - - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return SimpleBinding.Builder> { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3, a.arg4) }.opaque - } - - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingBuilder { - return SimpleBinding.Builder { r, c, a in try builder(r, c, a.0, a.1, a.2, a.3, a.4) }.opaque - } - - public func factory(_ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return SimpleBinding.Builder> { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) }.opaque - } -} - -extension ScopedEnvironment { - public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping () throws -> Type) -> SomeBindingBuilder { - return ScopedBinding.Builder(scope, ref) { _, _, _ in try builder() }.opaque - } - - public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver) throws -> Type) -> SomeBindingBuilder { - return ScopedBinding.Builder(scope, ref) { r, _, _ in try builder(r) }.opaque - } - - public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context) throws -> Type) -> SomeBindingBuilder { - return ScopedBinding.Builder(scope, ref) { r, c, _ in try builder(r, c) }.opaque - } - - public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable { - return ScopedBinding.Builder>(scope, ref) { r, c, a in try builder(r, c, a.arg1) }.opaque - } - - public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable { - return ScopedBinding.Builder>(scope, ref) { r, c, a in try builder(r, c, a.arg1, a.arg2) }.opaque - } - - public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - return ScopedBinding.Builder>(scope, ref) { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3) }.opaque - } - - public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return ScopedBinding.Builder>(scope, ref) { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3, a.arg4) }.opaque - } - - public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Context, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return ScopedBinding.Builder>(scope, ref) { r, c, a in try builder(r, c, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) }.opaque - } -} - -public func provider(_ builder: @escaping () throws -> Type) -> SomeBindingBuilder { - return SimpleBinding.Builder { _, _, _ in try builder() }.opaque -} - -public func provider(_ builder: @escaping (Resolver) throws -> Type) -> SomeBindingBuilder { - return SimpleBinding.Builder { r, _, _ in try builder(r) }.opaque -} - -public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> SomeBindingBuilder { - return SimpleBinding.Builder { r, _, a in try builder(r, a) }.opaque -} - -public func factory(_ builder: @escaping (Resolver, Arg1) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable { - return SimpleBinding.Builder> { r, _, a in try builder(r, a.arg1) }.opaque -} - -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SomeBindingBuilder { - return SimpleBinding.Builder { r, _, a in try builder(r, a.0, a.1) }.opaque -} - -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable { - return SimpleBinding.Builder> { r, _, a in try builder(r, a.arg1, a.arg2) }.opaque -} - -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingBuilder { - return SimpleBinding.Builder { r, _, a in try builder(r, a.0, a.1, a.2) }.opaque -} - -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - return SimpleBinding.Builder> { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3) }.opaque -} - -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingBuilder { - return SimpleBinding.Builder { r, _, a in try builder(r, a.0, a.1, a.2, a.3) }.opaque -} - -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return SimpleBinding.Builder> { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3, a.arg4) }.opaque -} - -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingBuilder { - return SimpleBinding.Builder { r, _, a in try builder(r, a.0, a.1, a.2, a.3, a.4) }.opaque -} - -public func factory(_ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return SimpleBinding.Builder> { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) }.opaque -} - -public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping () throws -> Type) -> SomeBindingBuilder { - return ScopedBinding.Builder(.root, ref) { _, _, _ in try builder() }.opaque -} - -public func singleton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver) throws -> Type) -> SomeBindingBuilder { - return ScopedBinding.Builder(.root, ref) { r, _, _ in try builder(r) }.opaque -} - -public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable { - return ScopedBinding.Builder>(.root, ref) { r, _, a in try builder(r, a.arg1) }.opaque -} - -public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable { - return ScopedBinding.Builder>(.root, ref) { r, _, a in try builder(r, a.arg1, a.arg2) }.opaque -} - -public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - return ScopedBinding.Builder>(.root, ref) { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3) }.opaque -} - -public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return ScopedBinding.Builder>(.root, ref) { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3, a.arg4) }.opaque -} - -public func multiton(ref: @escaping ReferenceMaker = strongRef, _ builder: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type) -> SomeBindingBuilder where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return ScopedBinding.Builder>(.root, ref) { r, _, a in try builder(r, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) }.opaque -} - -// sourcery:end diff --git a/Sources/3.1 API/Binding+Api.swift b/Sources/3.0 API/Binding+Api.swift similarity index 100% rename from Sources/3.1 API/Binding+Api.swift rename to Sources/3.0 API/Binding+Api.swift diff --git a/Sources/3.1 API/Binding+Factory.swift b/Sources/3.0 API/Binding+Factory.swift similarity index 100% rename from Sources/3.1 API/Binding+Factory.swift rename to Sources/3.0 API/Binding+Factory.swift diff --git a/Sources/3.1 API/Binding.swift b/Sources/3.0 API/Binding.swift similarity index 90% rename from Sources/3.1 API/Binding.swift rename to Sources/3.0 API/Binding.swift index d810c8cf..d870e460 100644 --- a/Sources/3.1 API/Binding.swift +++ b/Sources/3.0 API/Binding.swift @@ -57,14 +57,6 @@ extension Binding { } } -extension Binding { - func opaque() -> Binding { - return Binding( - products: products, dependencies: dependencies, factory: factory, properties: properties, scope: scope - ) - } -} - extension Binding { func updated(_ update: (inout Self) -> Void) -> Self { var copy = self diff --git a/Sources/3.0 API/BindingBuilder.swift b/Sources/3.0 API/BindingBuilder.swift deleted file mode 100644 index 78556aba..00000000 --- a/Sources/3.0 API/BindingBuilder.swift +++ /dev/null @@ -1,23 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -public protocol BindingBuilder { - associatedtype BoundType - func makeBinding(with properties: TypeBinderProperties) -> AnyBinding -} - -public struct SomeBindingBuilder: BindingBuilder, AnyOpaque { - let anyActual: Any - fileprivate let _makeBinding: (TypeBinderProperties) -> AnyBinding - - public func makeBinding(with properties: TypeBinderProperties) -> AnyBinding { - return _makeBinding(properties) - } -} - -public extension BindingBuilder { - var opaque: SomeBindingBuilder { - return SomeBindingBuilder(anyActual: self) { self.makeBinding(with: $0) } - } -} diff --git a/Sources/3.0 API/InstanceBuilder.swift b/Sources/3.0 API/InstanceBuilder.swift deleted file mode 100644 index 45d45dce..00000000 --- a/Sources/3.0 API/InstanceBuilder.swift +++ /dev/null @@ -1,21 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -protocol AnyInstanceBuilder { - func makeInstance(arg: Any, context: Any, resolver: Resolver) throws -> Any -} - -protocol InstanceBuilder: AnyInstanceBuilder { - associatedtype MadeType - associatedtype Argument - associatedtype Context - func makeInstance(arg: Argument, context: Context, resolver: Resolver) throws -> MadeType -} - -extension InstanceBuilder { - func makeInstance(arg: Any, context: Any, resolver: Resolver) throws -> Any { - guard let arg = arg as? Argument, let context = context as? Context else { throw SwinjectError() } - return try makeInstance(arg: arg, context: context, resolver: resolver) as MadeType - } -} diff --git a/Sources/3.0 API/Opaque.swift b/Sources/3.0 API/Opaque.swift deleted file mode 100644 index e29ef70c..00000000 --- a/Sources/3.0 API/Opaque.swift +++ /dev/null @@ -1,16 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -protocol AnyOpaque { - var anyActual: Any { get } -} - -protocol Opaque: AnyOpaque { - associatedtype Actual - var actual: Actual { get } -} - -extension Opaque { - var anyActual: Any { return actual } -} diff --git a/Sources/3.0 API/ScopedBinding.swift b/Sources/3.0 API/ScopedBinding.swift deleted file mode 100644 index bfe43d06..00000000 --- a/Sources/3.0 API/ScopedBinding.swift +++ /dev/null @@ -1,67 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -struct ScopedBinding { - let key: BindingKey - let overrides: Bool - let builder: AnyInstanceBuilder - let scope: AnyScope - let makeRef: ReferenceMaker -} - -extension ScopedBinding: AnyBinding { - func instance(arg: Any, resolver: Resolver) throws -> Any { - let context = try resolver.context(as: key.contextType) - return try scope - .registry(for: context) - .instance(for: ScopeRegistryKey(descriptor: key.descriptor, argument: arg)) { - makeRef(try builder.makeInstance(arg: arg, context: context, resolver: resolver)) - } - } -} - -extension ScopedBinding { - struct Builder where AScope: Scope { - let scope: AScope - let makeRef: ReferenceMaker - private let builder: (Resolver, Context, Argument) throws -> Type - - init( - _ scope: AScope, - _ makeRef: @escaping ReferenceMaker, - _ builder: @escaping (Resolver, Context, Argument) throws -> Type - ) { - self.makeRef = { - let ref = makeRef($0 as! Type) - let nextValue = ref.nextValue - return Reference(currentValue: ref.currentValue, nextValue: { nextValue() }) - } - self.scope = scope - self.builder = builder - } - } -} - -extension ScopedBinding.Builder: InstanceBuilder { - typealias MadeType = Type - typealias Context = AScope.Context - - func makeInstance(arg: Argument, context: Context, resolver: Resolver) throws -> Type { - return try builder(resolver, context, arg) - } -} - -extension ScopedBinding.Builder: BindingBuilder { - typealias BoundType = Type - - func makeBinding(with properties: TypeBinderProperties) -> AnyBinding { - return ScopedBinding( - key: BindingKey(descriptor: properties.descriptor, contextType: Context.self, argumentType: Argument.self), - overrides: properties.overrides, - builder: self, - scope: scope, - makeRef: makeRef - ) - } -} diff --git a/Sources/3.0 API/SimpleBinding.swift b/Sources/3.0 API/SimpleBinding.swift deleted file mode 100644 index cc570d0e..00000000 --- a/Sources/3.0 API/SimpleBinding.swift +++ /dev/null @@ -1,46 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -struct SimpleBinding { - let key: BindingKey - let overrides: Bool - let builder: AnyInstanceBuilder -} - -extension SimpleBinding: AnyBinding { - func instance(arg: Any, resolver: Resolver) throws -> Any { - let context = try resolver.context(as: key.contextType) - return try builder.makeInstance(arg: arg, context: context, resolver: resolver) - } -} - -extension SimpleBinding { - struct Builder { - private let builder: (Resolver, Context, Argument) throws -> Type - - init(_ builder: @escaping (Resolver, Context, Argument) throws -> Type) { - self.builder = builder - } - } -} - -extension SimpleBinding.Builder: InstanceBuilder { - typealias MadeType = Type - - func makeInstance(arg: Argument, context: Context, resolver: Resolver) throws -> Type { - return try builder(resolver, context, arg) - } -} - -extension SimpleBinding.Builder: BindingBuilder { - typealias BoundType = Type - - func makeBinding(with properties: TypeBinderProperties) -> AnyBinding { - return SimpleBinding( - key: BindingKey(descriptor: properties.descriptor, contextType: Context.self, argumentType: Argument.self), - overrides: properties.overrides, - builder: self - ) - } -} diff --git a/Sources/3.0 API/TypeBinder.swift b/Sources/3.0 API/TypeBinder.swift deleted file mode 100644 index 6caa575c..00000000 --- a/Sources/3.0 API/TypeBinder.swift +++ /dev/null @@ -1,41 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -public struct TypeBinderProperties { - let descriptor: TypeDescriptor - let overrides: Bool -} - -public struct TypeBinder { - let properties: TypeBinderProperties -} - -public func bind(_: Type.Type, tagged tag: String? = nil, overrides: Bool = false) -> TypeBinder { - return TypeBinder(properties: TypeBinderProperties( - descriptor: tagged(Type.self, with: tag), - overrides: overrides - )) -} - -public extension TypeBinder { - func with( - _ builder: Builder - ) -> AnyBinding where Builder: BindingBuilder, Builder.BoundType == BoundType { - return builder.makeBinding(with: properties) - } - - func with(_ value: BoundType) -> AnyBinding { - return instance(value).makeBinding(with: properties) - } -} - -public func & ( - lhs: TypeBinder, rhs: Builder -) -> AnyBinding where Builder: BindingBuilder, Builder.BoundType == BoundType { - return lhs.with(rhs) -} - -public func & (lhs: TypeBinder, rhs: BoundType) -> AnyBinding { - return lhs.with(rhs) -} diff --git a/Sources/3.1 API/ValueRequest.swift b/Sources/3.0 API/ValueRequest.swift similarity index 100% rename from Sources/3.1 API/ValueRequest.swift rename to Sources/3.0 API/ValueRequest.swift diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index b8adaee5..bfb7a4d3 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -27,15 +27,11 @@ 0CE1126436F680F9684837E4 /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; 0CE158916595980A7C8272D3 /* SingletonSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46F05CC591903E2B04B6D8ED /* SingletonSpec.swift */; }; 0D5C4A278A16AB3A163148AF /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; - 13CDEC7A6C8E43B58D5CBE3D /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; 14C8DA4FCCDFA87885038D38 /* PropertyWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 424C647FF08FCB7C2A54E085 /* PropertyWrapper.swift */; }; - 157A967F9BAD0B8DAFAC2A36 /* InstanceBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 419FB96A1F4B72278B9A6665 /* InstanceBuilder.swift */; }; - 16393BD60FDDD38B5A977C55 /* InstanceBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 419FB96A1F4B72278B9A6665 /* InstanceBuilder.swift */; }; 180DB4397B4C05E26F819C85 /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADA1541ABC1365DFD7E3377F /* Food.swift */; }; 18AAA07DCD6FAB4A7D7E8B76 /* OverrideSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86C18DDD83715886DF7F1818 /* OverrideSpec.swift */; }; 19416C867F15E88394A0ABD1 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */; }; 196338EA802A39E205C33B43 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; - 19E02C4326FB05E0630B56E3 /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7D394F381E60F6E6E92E7DB /* SimpleBinding.swift */; }; 19EBB651BD06BD0C03C1ACB5 /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59111BE319C59E4CD6CF68CD /* Assembler.swift */; }; 19F21849D1E173F5AC724281 /* UnboundScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 667B13B528642272FC0794B6 /* UnboundScope.swift */; }; 1A40A26942A65246D7DD268E /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = ADC44E9312C3B974AFD8F07B /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -53,14 +49,12 @@ 283C77045DA55C2134EC9C48 /* Container+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F446D6BD4C44E16A1D608BFB /* Container+TypeForwarding.swift */; }; 290C9E9420A1EE30456476CB /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59111BE319C59E4CD6CF68CD /* Assembler.swift */; }; 293985649250DF270DC89135 /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; - 2A6D2874ADB24B08DAE1EC04 /* BindingBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = A367B4D6F7E5331620430ECF /* BindingBuilder.swift */; }; 2AA60B7E6EBA9EC6BE92D7CB /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; 2B506344F37CE5F5C5C02C05 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; 2C352AAD1AC7D82A4A059046 /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; 2C3EB507FFA03D18B2909405 /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8B9785AAE94A5447FA307242 /* Swinject.framework */; }; 2CB057F2A16DA462E0517AAB /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; 2D020C6391A4F6A2118585B8 /* Reference.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73B4B777290FF5D38A8914CC /* Reference.swift */; }; - 2DD6F290740EA69B3E73E0EA /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */; }; 2F664F8534CA1D92ED2F81E2 /* RetrievalSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D8B3342E2AC3236F12072F5 /* RetrievalSpec.swift */; }; 3099172980F9E9143C0A1C20 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; 30D247E8083858C233B92908 /* SingletonSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46F05CC591903E2B04B6D8ED /* SingletonSpec.swift */; }; @@ -72,7 +66,6 @@ 335CE53CEC2360DC86D58F07 /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61EE5DDBE705B47AFC9A6986 /* LoadAwareAssembly.swift */; }; 33B86F2D33219879731CDDF0 /* ScopesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D3C59E84B5FD0C13F487838 /* ScopesSpec.swift */; }; 36A706F87ED2E88F3390C6C2 /* ServiceEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38615FC8EEB466C5C1EAD21C /* ServiceEntry.swift */; }; - 36D0B5EFA3B4AB4D464C9260 /* InstanceBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 419FB96A1F4B72278B9A6665 /* InstanceBuilder.swift */; }; 372F0061E762BF8FFF05457F /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; 3753FB83A1FB4B83891AA5C8 /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BFF4BA99493C54260878C4 /* ObjectScope.swift */; }; 389C54E04DD794DA4F648571 /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */; }; @@ -89,21 +82,17 @@ 41C7340BFD2EB66359772733 /* Resolver+LegacyApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A784E2DEC7691D14DDBECD8 /* Resolver+LegacyApi.swift */; }; 42FE916C1593A9289E1A28BC /* InjectionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 670DB253ECD5CE1468A7F2E3 /* InjectionSpec.swift */; }; 4347EE17D0C0ED574C899D85 /* ScopeRegistryKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */; }; - 43A74237D8933572BAA0F3B4 /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; - 44F458F61B21D78A91664160 /* BinderVariation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E0C3E4D518BC1FEF3EF8D33 /* BinderVariation.swift */; }; 45F1654C204C7A2C87397BCD /* PropertyWrappersSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49B24254B9F0E48ED3713565 /* PropertyWrappersSpec.swift */; }; 48D1568CB41BE4B6597FD535 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; 48F40377D116C6B1B786C329 /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; 4954CBB07E38E98752AC3347 /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; 49685AB40BEE856C62005C87 /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; 49D71F6CC12C12FE7B6A097A /* ContextSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */; }; - 4B9811CF0604946CCF323ED2 /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92B8E618A08408404FB2A7A /* TypeBinder.swift */; }; 4D86550CC5C281A58B4A6F61 /* SwinjectContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8C4916168E81D76536892122 /* SwinjectContainer.swift */; }; 4DF3DC1CDD3C4948F9BDD3DF /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3586A4987B7C7C8122D674E /* SwinjectError.swift */; }; 4E4DC8CDD1BA51FB66A332C2 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */; }; 4EC94A51037C79DE0C5C8CB1 /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; 4EE5C1207C57C85A928FA89B /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 273FB7A6277E0841E1570990 /* Nimble.framework */; }; - 5365FDFB2DDA6491F3049654 /* Opaque.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E7DC2C5AA87B18BD465EB77 /* Opaque.swift */; }; 5393E5DE21B568A88498E454 /* PropertyWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 424C647FF08FCB7C2A54E085 /* PropertyWrapper.swift */; }; 546FF827DB6D42490D1CA439 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; 54956014A1774DF8357B69E6 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; @@ -123,10 +112,8 @@ 5D7E26A00B055803A50CD9C2 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */; }; 5ED8A7D19F21FA686215F72C /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; 5F1647DCC0D437A782647372 /* PropertyWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 424C647FF08FCB7C2A54E085 /* PropertyWrapper.swift */; }; - 5F49839A5C17677861F5971B /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7D394F381E60F6E6E92E7DB /* SimpleBinding.swift */; }; 5FCE2A2AE5DD0DBECA4A9953 /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */; }; 6034CF5459D96497AF36E4B6 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; - 6251955691663E4495DE310D /* Opaque.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E7DC2C5AA87B18BD465EB77 /* Opaque.swift */; }; 628EBFBA0031B1FA2E29F583 /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 351C4221896DDB8572BD6CB5 /* Person.swift */; }; 63528D45A548DD58D748D54C /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; 640F7A55D9A671FA112C8083 /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; @@ -135,17 +122,14 @@ 68D828A3C583DDD28CFE882B /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; 6922AE734E84B515C94D9480 /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; 694C2C891D581371B2B051D7 /* Container+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDA78290D6D60BD0B808571F /* Container+Logging.swift */; }; - 69EE97FE7F5AF3A227E7FE22 /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2E291E30E191A1E202A013A /* ScopedBinding.swift */; }; 6A03ABEED82EF31E8E6E297E /* Container+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDA78290D6D60BD0B808571F /* Container+Logging.swift */; }; 6A0FD11468B3852E48B682BE /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; 6A967AE5710606998C2BE070 /* PropertyWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 424C647FF08FCB7C2A54E085 /* PropertyWrapper.swift */; }; 6BB1E24C1CE55C9F6EA6CC28 /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C765B92B00C0AC8625BB4AC9 /* Quick.framework */; }; 6C01E868DE44BD396D94858B /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; - 6CFE30E5595611778893D147 /* BindingBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = A367B4D6F7E5331620430ECF /* BindingBuilder.swift */; }; 6DA49F84E2592B32F81F268B /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BFF4BA99493C54260878C4 /* ObjectScope.swift */; }; 6DD80811E5FD658CAFEEA647 /* CIrcularitySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 118ABC654C4144496848AD74 /* CIrcularitySpec.swift */; }; 6F6FAD0EEF84580DD53BB755 /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1C58FC14EEA170B0DC079DE4 /* Quick.framework */; }; - 6FCCBA9D2E4C2A225CB1A152 /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */; }; 70368EC369287B4EE767E929 /* LinuxConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 938425B216B78A06EC10504A /* LinuxConfig.swift */; }; 703F8B3AD111A6CFAFF66A49 /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; 708D400457552769A54A406B /* OverrideSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86C18DDD83715886DF7F1818 /* OverrideSpec.swift */; }; @@ -182,8 +166,6 @@ 77ED80082311221600AC48F9 /* ValueRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77ED80042311221600AC48F9 /* ValueRequest.swift */; }; 789BF74652A2424EB8F7EF47 /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 7A7032384E07DAD308D4F70A /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 8B9785AAE94A5447FA307242 /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 7A956FAB419F74D7EB9CAD0B /* Opaque.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E7DC2C5AA87B18BD465EB77 /* Opaque.swift */; }; - 7C745281CA1627BCC8A8A92A /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2E291E30E191A1E202A013A /* ScopedBinding.swift */; }; 7D6F664091C70BABBFB61D53 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; 7E3C3E6FD07F3BD76024770A /* InjectionVariation.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C516EFA0CA22D19F07B27E /* InjectionVariation.swift */; }; 8016512839FE61EC3127E489 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */; }; @@ -197,11 +179,9 @@ 83464EDC08380F5CE2190F30 /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; 8436D091ED844817C8CE3AF2 /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; 848227742D4ABA298D340485 /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; - 85CBEFBB558636EAC76E5F0C /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2E291E30E191A1E202A013A /* ScopedBinding.swift */; }; 86CBC40FDC90E2A2051386C5 /* ContextSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */; }; 87FEAEF562B99522083CB87D /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; 890CCD2800597F6FB7C6FD31 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; - 89E2997CB8B90368A15A91CE /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; 8A4E9E736239F92F878C070C /* Resolver+FunctionCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F626B9D3E547621787E4D7 /* Resolver+FunctionCall.swift */; }; 8B5927517B567B1DFAB5B935 /* ContextTranslator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */; }; 8B711CBE6A5B86DC2D6CABDC /* UnboundScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 667B13B528642272FC0794B6 /* UnboundScope.swift */; }; @@ -212,11 +192,9 @@ 920DE2CAB9895D10FAE48FBA /* ScopeRegistryKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */; }; 934AFACA6BFF24AD3503F98D /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */; }; 93BCD12CEFB88BAD49BEA431 /* ServiceEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38615FC8EEB466C5C1EAD21C /* ServiceEntry.swift */; }; - 9425887520AC2DBDCBACB252 /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92B8E618A08408404FB2A7A /* TypeBinder.swift */; }; 95A6654089875BCC863FB53B /* InjectionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 670DB253ECD5CE1468A7F2E3 /* InjectionSpec.swift */; }; 95E6DD9D94BE64420EEC1298 /* Weak.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57A7E35B2B22650208F904B8 /* Weak.swift */; }; 96EA0A5DF33F025EBE0B67D2 /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; - 976E692202CF33EEE4C3A997 /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7D394F381E60F6E6E92E7DB /* SimpleBinding.swift */; }; 979518E078B187549E11DF48 /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; 97C2EA47D7623AFD723AFE93 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */; }; 980FED1DBC62B65597E2828B /* SingletonSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46F05CC591903E2B04B6D8ED /* SingletonSpec.swift */; }; @@ -250,29 +228,24 @@ A9A242086D1EDE408DC556D0 /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; AAC6F2F5EC2928943BF2BED1 /* PropertyWrappersSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49B24254B9F0E48ED3713565 /* PropertyWrappersSpec.swift */; }; AAD8D0551B8A26A9B22AECEC /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59A3946B59EB4D787CCE9F2 /* Container+Registration.swift */; }; - AB864E029E996492ED4A3A52 /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92B8E618A08408404FB2A7A /* TypeBinder.swift */; }; AC470B4322599B0A076DD3FF /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; ACA8E10AADBFC063A6F345D7 /* CIrcularitySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 118ABC654C4144496848AD74 /* CIrcularitySpec.swift */; }; AD214F3DBAB4F16C88322CAC /* InjectionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 670DB253ECD5CE1468A7F2E3 /* InjectionSpec.swift */; }; AD3E7135985F1046E35C39DE /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */; }; - ADCF273AF041E74DBEC2C13A /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */; }; ADF0B21969FE77CEFBB2AAAC /* Quick.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 823617F3B8A9192F56B13331 /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; AE6EAB8CC32ED5E1789D55B7 /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; AE93BDC3AA7962AFD574B32B /* Quick.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 1C58FC14EEA170B0DC079DE4 /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; B00627BABCF9181C7B58609E /* LinuxConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 938425B216B78A06EC10504A /* LinuxConfig.swift */; }; B06306286CC5EA66C88F24D1 /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 38BCCF3F950869BD1891F7A8 /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; B0B139FADA6AE07C79847EBA /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61EE5DDBE705B47AFC9A6986 /* LoadAwareAssembly.swift */; }; - B0B65F494A88CDEFE8EF79F6 /* BindingBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = A367B4D6F7E5331620430ECF /* BindingBuilder.swift */; }; B293894FEB67831DDA5F000E /* Reference.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73B4B777290FF5D38A8914CC /* Reference.swift */; }; B2FAD41F7726502822AF913B /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42490D1D0C395951243F5CFF /* Container.swift */; }; B3062AB22373AD23052B61DF /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; B42331BF00B482369B908BB8 /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BFF4BA99493C54260878C4 /* ObjectScope.swift */; }; B4B66D7251BDDE25D6D7FB3C /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BFF4BA99493C54260878C4 /* ObjectScope.swift */; }; - B5FF5DFE394B6B1BB930D88D /* BinderEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */; }; B65DE0B0562540CC8CEC48F3 /* SingletonSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46F05CC591903E2B04B6D8ED /* SingletonSpec.swift */; }; B7653A6427A5E284E9A1D6D3 /* ServiceEntry+TypeForwarding.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */; }; B84167AC8C6BEB57C4D0695A /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; - B91523667CD2A31E889A4669 /* ScopedBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2E291E30E191A1E202A013A /* ScopedBinding.swift */; }; B9550BE2BA6FA5731BEC87FD /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; B96A6370D549AAC383360ABC /* LinuxConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 938425B216B78A06EC10504A /* LinuxConfig.swift */; }; BB571B9A78FC53231A18E18C /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; @@ -286,7 +259,6 @@ BE6C13A3492E3CFC08E231B0 /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADA1541ABC1365DFD7E3377F /* Food.swift */; }; BE94EF7BCF976A703F961389 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */; }; BEEFBE87EB17D56BA8D47358 /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 351C4221896DDB8572BD6CB5 /* Person.swift */; }; - BEFFC7B36FE5810169C81B97 /* BinderEnvironment.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 26EEC28683E4A26B3092E8BA /* BinderEnvironment.swifttemplate */; }; BFE22F9F2E88F177302E9D19 /* Container+Registration.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */; }; C1687ACA897DEFD3A8197CCD /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; C223101DB417F1237A8421E1 /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 6D434EB4C13CF9D9FA6D80CB /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -294,7 +266,6 @@ C38A2EBF4D1904E7D6989989 /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADA1541ABC1365DFD7E3377F /* Food.swift */; }; C637E97E193BB1DADDDC6C21 /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1E726A651C3AFE92C19608B /* SwinjectModule.swift */; }; C6D60E2AEC381998223145B2 /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; - C6E443EAD892B0B69DA61144 /* InstanceBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 419FB96A1F4B72278B9A6665 /* InstanceBuilder.swift */; }; C76374CAFE7C2BCCE52F1BB1 /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 351C4221896DDB8572BD6CB5 /* Person.swift */; }; C8462BEE06316286B9CA85AC /* SwinjectContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8C4916168E81D76536892122 /* SwinjectContainer.swift */; }; C950785B81C6DB22F41FA3CE /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; @@ -338,20 +309,16 @@ E227D08034E08AA0909BC043 /* RetrievalSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D8B3342E2AC3236F12072F5 /* RetrievalSpec.swift */; }; E39152E9059357CF0C9B21AF /* CIrcularitySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 118ABC654C4144496848AD74 /* CIrcularitySpec.swift */; }; E3EABE098DBFB561A20632E3 /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; - E4CE31B7B9616EFC93C69341 /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC85CB215058F95C0BC190B1 /* Bridge.swift */; }; E5880DBBB91CC5F8F47FBF73 /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; E7D1045D25FAB592401DCAF0 /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; EA0D19F7DF0355C774B0F40B /* ScopesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D3C59E84B5FD0C13F487838 /* ScopesSpec.swift */; }; EB3420214A9E68A0247D0F2C /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 351C4221896DDB8572BD6CB5 /* Person.swift */; }; - EB73B06547A273D2534528E3 /* Opaque.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E7DC2C5AA87B18BD465EB77 /* Opaque.swift */; }; EB79ECF5C893F63B22355167 /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; EBC64A1515C868E410C83451 /* SwiftCode.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 90191C25A2D66E07C4E9CD73 /* SwiftCode.swifttemplate */; }; ED6CB3935B15F30A182ED6D0 /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61EE5DDBE705B47AFC9A6986 /* LoadAwareAssembly.swift */; }; EE0D3637D2524AC1CD21780D /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 74DE57FB3E8228904E6FE0D7 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; - EE3063E3D1582D3BB7CC43F0 /* SimpleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7D394F381E60F6E6E92E7DB /* SimpleBinding.swift */; }; EE35DF2D353E2C5110DA5C42 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; EEAD7E215908DF939ECCDCC9 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; - EF79F0B3D497215D4BBBC038 /* TypeBinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92B8E618A08408404FB2A7A /* TypeBinder.swift */; }; EFD2F695B86E74C77F46B7D1 /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; F06DEB671A4B85ABB0E96E51 /* ContextTranslator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */; }; F1F3BA81462E2362374BD4C4 /* ModulesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75BE3AE3E30DFE42A919D825 /* ModulesSpec.swift */; }; @@ -367,7 +334,6 @@ FA805A162E989A22990B99AA /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; FC339851D7EEE4D17178CC1F /* Weak.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57A7E35B2B22650208F904B8 /* Weak.swift */; }; FD7B2663F2F931B78EB330EE /* Resolver+LegacyApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A784E2DEC7691D14DDBECD8 /* Resolver+LegacyApi.swift */; }; - FD8BB4CC8DA0E560E39FA491 /* BindingBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = A367B4D6F7E5331620430ECF /* BindingBuilder.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -492,7 +458,6 @@ 0D8B3342E2AC3236F12072F5 /* RetrievalSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RetrievalSpec.swift; sourceTree = ""; }; 0DC67CB109091002AB433A46 /* SwinjectTests.xctest */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.cfbundle; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 0E0B580B43E1891812C97209 /* AnyBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnyBinding.swift; sourceTree = ""; }; - 0E7DC2C5AA87B18BD465EB77 /* Opaque.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Opaque.swift; sourceTree = ""; }; 10480F2154EAA0414D4C1F55 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */ = {isa = PBXFileReference; lastKnownFileType = text.yaml; path = .swiftlint.yml; sourceTree = ""; }; 118ABC654C4144496848AD74 /* CIrcularitySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CIrcularitySpec.swift; sourceTree = ""; }; @@ -504,9 +469,7 @@ 1D3C59E84B5FD0C13F487838 /* ScopesSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopesSpec.swift; sourceTree = ""; }; 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Behavior.swift; sourceTree = ""; }; 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Arguments.swift; sourceTree = ""; }; - 26EEC28683E4A26B3092E8BA /* BinderEnvironment.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = BinderEnvironment.swifttemplate; sourceTree = ""; }; 273FB7A6277E0841E1570990 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; - 2E0C3E4D518BC1FEF3EF8D33 /* BinderVariation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderVariation.swift; sourceTree = ""; }; 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; 34AFFAC41BA9D02A38BDB7A3 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; 351C4221896DDB8572BD6CB5 /* Person.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Person.swift; sourceTree = ""; }; @@ -514,7 +477,6 @@ 38615FC8EEB466C5C1EAD21C /* ServiceEntry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServiceEntry.swift; sourceTree = ""; }; 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Swinject+Builder.swift"; sourceTree = ""; }; 38BCCF3F950869BD1891F7A8 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 419FB96A1F4B72278B9A6665 /* InstanceBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceBuilder.swift; sourceTree = ""; }; 42490D1D0C395951243F5CFF /* Container.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.swift; sourceTree = ""; }; 424C647FF08FCB7C2A54E085 /* PropertyWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PropertyWrapper.swift; sourceTree = ""; }; 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmploymentAssembly.swift; sourceTree = ""; }; @@ -571,15 +533,12 @@ 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistryKey.swift; sourceTree = ""; }; A20C1319AF31EC7F8E6945FE /* SwinjectTests.xctest */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.cfbundle; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; A3586A4987B7C7C8122D674E /* SwinjectError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectError.swift; sourceTree = ""; }; - A367B4D6F7E5331620430ECF /* BindingBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingBuilder.swift; sourceTree = ""; }; A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Resolver.swift; sourceTree = ""; }; ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Circularity.swift; sourceTree = ""; }; ADA1541ABC1365DFD7E3377F /* Food.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Food.swift; sourceTree = ""; }; ADC44E9312C3B974AFD8F07B /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AssemblerSpec.swift; sourceTree = ""; }; B59A3946B59EB4D787CCE9F2 /* Container+Registration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Registration.swift"; sourceTree = ""; }; - B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinderEnvironment.swift; sourceTree = ""; }; - B92B8E618A08408404FB2A7A /* TypeBinder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeBinder.swift; sourceTree = ""; }; B9F626B9D3E547621787E4D7 /* Resolver+FunctionCall.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Resolver+FunctionCall.swift"; sourceTree = ""; }; BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StandardScopeRegistrySpec.swift; sourceTree = ""; }; BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "ServiceEntry+TypeForwarding.swifttemplate"; sourceTree = ""; }; @@ -587,14 +546,11 @@ C1E726A651C3AFE92C19608B /* SwinjectModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectModule.swift; sourceTree = ""; }; C3C516EFA0CA22D19F07B27E /* InjectionVariation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InjectionVariation.swift; sourceTree = ""; }; C765B92B00C0AC8625BB4AC9 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; - CC85CB215058F95C0BC190B1 /* Bridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bridge.swift; sourceTree = ""; }; CDA78290D6D60BD0B808571F /* Container+Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Logging.swift"; sourceTree = ""; }; CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; - D7D394F381E60F6E6E92E7DB /* SimpleBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleBinding.swift; sourceTree = ""; }; DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextSpec.swift; sourceTree = ""; }; E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; F290F6B1207A0557A528220B /* Assembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Assembly.swift; sourceTree = ""; }; - F2E291E30E191A1E202A013A /* ScopedBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopedBinding.swift; sourceTree = ""; }; F446D6BD4C44E16A1D608BFB /* Container+TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+TypeForwarding.swift"; sourceTree = ""; }; F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.TypeForwarding.swift; sourceTree = ""; }; FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+LegacyApi.swifttemplate"; sourceTree = ""; }; @@ -647,8 +603,6 @@ 07354387D49F6D7BBBA4F3AC /* Templates */ = { isa = PBXGroup; children = ( - 26EEC28683E4A26B3092E8BA /* BinderEnvironment.swifttemplate */, - 2E0C3E4D518BC1FEF3EF8D33 /* BinderVariation.swift */, 77B87F3D231153D200321C08 /* FactoryVariation.swift */, 77B87F3F231155B300321C08 /* Binding+Factory.swifttemplate */, CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */, @@ -700,16 +654,13 @@ 2D9982F0E5050BAE1832702E /* 3.0 API */ = { isa = PBXGroup; children = ( - 0E7DC2C5AA87B18BD465EB77 /* Opaque.swift */, - B843C72AD5C4094F7D6EBCF7 /* BinderEnvironment.swift */, - A367B4D6F7E5331620430ECF /* BindingBuilder.swift */, - 419FB96A1F4B72278B9A6665 /* InstanceBuilder.swift */, + 773C6DDB23111956007A40BF /* Binding.swift */, + 77ED80042311221600AC48F9 /* ValueRequest.swift */, + 77B87F3B23112DB100321C08 /* Binding+Api.swift */, + 77B87F41231157B200321C08 /* Binding+Factory.swift */, B9F626B9D3E547621787E4D7 /* Resolver+FunctionCall.swift */, 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */, - F2E291E30E191A1E202A013A /* ScopedBinding.swift */, - D7D394F381E60F6E6E92E7DB /* SimpleBinding.swift */, 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */, - B92B8E618A08408404FB2A7A /* TypeBinder.swift */, 667B13B528642272FC0794B6 /* UnboundScope.swift */, 57A7E35B2B22650208F904B8 /* Weak.swift */, ); @@ -728,7 +679,6 @@ 4F46C48FA15F512EAED5F67A /* Support */ = { isa = PBXGroup; children = ( - CC85CB215058F95C0BC190B1 /* Bridge.swift */, 5AB605ED0F735221D0EB1D5F /* Convenience.swift */, 722CAC1761180366DE75A4A6 /* TestModels.swift */, 1F06930A1A2C8BA94D6875BA /* Legacy */, @@ -764,17 +714,6 @@ path = watchOS; sourceTree = ""; }; - 773C6DDA23111910007A40BF /* 3.1 API */ = { - isa = PBXGroup; - children = ( - 773C6DDB23111956007A40BF /* Binding.swift */, - 77ED80042311221600AC48F9 /* ValueRequest.swift */, - 77B87F3B23112DB100321C08 /* Binding+Api.swift */, - 77B87F41231157B200321C08 /* Binding+Factory.swift */, - ); - path = "3.1 API"; - sourceTree = ""; - }; 80E97D8FD5574A96B6BC9EB9 /* Frameworks */ = { isa = PBXGroup; children = ( @@ -869,7 +808,6 @@ D026A6699A2A932511D29E14 /* Sources */ = { isa = PBXGroup; children = ( - 773C6DDA23111910007A40BF /* 3.1 API */, 5F7BC1C4169BB4382C6D3E1F /* Info.plist */, 74DE57FB3E8228904E6FE0D7 /* Swinject.h */, 5F6AA1259C61A4D472220C36 /* 2.0 API */, @@ -1199,7 +1137,6 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - BEFFC7B36FE5810169C81B97 /* BinderEnvironment.swifttemplate in Resources */, BFE22F9F2E88F177302E9D19 /* Container+Registration.swifttemplate in Resources */, 1C82BFD00FCC384DB3AE6A89 /* MatchableBoxes.swifttemplate in Resources */, 3EC8383BEAC339595CF7F927 /* Resolver+FunctionCallApi.swifttemplate in Resources */, @@ -1458,9 +1395,7 @@ 19EBB651BD06BD0C03C1ACB5 /* Assembler.swift in Sources */, F504C2ABEFCFFCAC8B858751 /* Assembly.swift in Sources */, 703F8B3AD111A6CFAFF66A49 /* Behavior.swift in Sources */, - ADCF273AF041E74DBEC2C13A /* BinderEnvironment.swift in Sources */, 658AEDC8D802A6788E959E0C /* AnyBinding.swift in Sources */, - B0B65F494A88CDEFE8EF79F6 /* BindingBuilder.swift in Sources */, 694C2C891D581371B2B051D7 /* Container+Logging.swift in Sources */, 77ED80062311221600AC48F9 /* ValueRequest.swift in Sources */, AAD8D0551B8A26A9B22AECEC /* Container+Registration.swift in Sources */, @@ -1469,11 +1404,9 @@ 8B5927517B567B1DFAB5B935 /* ContextTranslator.swift in Sources */, 77B87F492311580600321C08 /* Binding+Api.swift in Sources */, 1D17DBC27F25717BF7A87AF3 /* InstanceRequest.swift in Sources */, - 36D0B5EFA3B4AB4D464C9260 /* InstanceBuilder.swift in Sources */, A91EDAFBC3606EDFBD739899 /* InstanceWrapper.swift in Sources */, 98322F9371E1A8461BC614D1 /* Matchable.swift in Sources */, 3753FB83A1FB4B83891AA5C8 /* ObjectScope.swift in Sources */, - 7A956FAB419F74D7EB9CAD0B /* Opaque.swift in Sources */, 77B87F44231157E900321C08 /* Binding+Factory.swift in Sources */, 5393E5DE21B568A88498E454 /* PropertyWrapper.swift in Sources */, 3BD6055555A5C30DABDC8ED2 /* Reference.swift in Sources */, @@ -1485,17 +1418,14 @@ 68C95FCB0D345CA3BA24D320 /* Scope.swift in Sources */, BB571B9A78FC53231A18E18C /* ScopeRegistry.swift in Sources */, 593B93BA2EE3FE4418A1C579 /* ScopeRegistryKey.swift in Sources */, - 69EE97FE7F5AF3A227E7FE22 /* ScopedBinding.swift in Sources */, AD3E7135985F1046E35C39DE /* ServiceEntry+TypeForwarding.swift in Sources */, 93BCD12CEFB88BAD49BEA431 /* ServiceEntry.swift in Sources */, - 976E692202CF33EEE4C3A997 /* SimpleBinding.swift in Sources */, B9550BE2BA6FA5731BEC87FD /* Swinject+Builder.swift in Sources */, 33391EBA040E82DFB0A37015 /* Swinject.swift in Sources */, 3328937B7BBFA77FA3CD303E /* SwinjectContainer.swift in Sources */, 020DA1718FCC68D889FB5A5F /* SwinjectError.swift in Sources */, CF4EBB60C21F8C503BCD7A29 /* SwinjectModule.swift in Sources */, 0D5C4A278A16AB3A163148AF /* SwinjectTree.swift in Sources */, - AB864E029E996492ED4A3A52 /* TypeBinder.swift in Sources */, 49685AB40BEE856C62005C87 /* TypeDescriptor.swift in Sources */, 5BD767B85CFE5FADDFE0A7B5 /* UnboundScope.swift in Sources */, F88700BAAFFB47B1BD4D3BFA /* Weak.swift in Sources */, @@ -1506,7 +1436,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 44F458F61B21D78A91664160 /* BinderVariation.swift in Sources */, 7E3C3E6FD07F3BD76024770A /* InjectionVariation.swift in Sources */, 77B87F3E231153D200321C08 /* FactoryVariation.swift in Sources */, 70BAF056528B2B33B3A65E9D /* Utils.swift in Sources */, @@ -1522,7 +1451,6 @@ DD29D2E60DA979D61F32A39A /* BasicAssembly.swift in Sources */, 3129A37CDC1653C11800E24A /* BehaviorFakes.swift in Sources */, 9A2A6978519F2BBA97DA6EA6 /* BindingSpec.swift in Sources */, - 89E2997CB8B90368A15A91CE /* Bridge.swift in Sources */, E39152E9059357CF0C9B21AF /* CIrcularitySpec.swift in Sources */, BB64AE6DFE526629918211B7 /* Circularity.swift in Sources */, 68D828A3C583DDD28CFE882B /* ContainerSpec.Arguments.swift in Sources */, @@ -1564,7 +1492,6 @@ 401592294E5D528379BE1AB2 /* BasicAssembly.swift in Sources */, A3BFFED76688F149FBAF7C53 /* BehaviorFakes.swift in Sources */, BB77A5D81C58392964D07233 /* BindingSpec.swift in Sources */, - 13CDEC7A6C8E43B58D5CBE3D /* Bridge.swift in Sources */, 39AE6864444BC1CE491142E5 /* CIrcularitySpec.swift in Sources */, CDE8EA7EC1D8096F12BDD8C2 /* Circularity.swift in Sources */, 83464EDC08380F5CE2190F30 /* ContainerSpec.Arguments.swift in Sources */, @@ -1606,7 +1533,6 @@ 03122D1B2EA65C89ADC78EC7 /* BasicAssembly.swift in Sources */, 1CA5DF3F93203B226A6FA059 /* BehaviorFakes.swift in Sources */, CAA5241DAA201FBB5818C803 /* BindingSpec.swift in Sources */, - E4CE31B7B9616EFC93C69341 /* Bridge.swift in Sources */, ACA8E10AADBFC063A6F345D7 /* CIrcularitySpec.swift in Sources */, D3FD513CDD70AF674C453B83 /* Circularity.swift in Sources */, 8436D091ED844817C8CE3AF2 /* ContainerSpec.Arguments.swift in Sources */, @@ -1648,7 +1574,6 @@ 599C7F009F954CDA522244B3 /* BasicAssembly.swift in Sources */, 8E1E051646BBD6E38F4199C2 /* BehaviorFakes.swift in Sources */, 0207493E1CEE8456E91E3DAE /* BindingSpec.swift in Sources */, - 43A74237D8933572BAA0F3B4 /* Bridge.swift in Sources */, 6DD80811E5FD658CAFEEA647 /* CIrcularitySpec.swift in Sources */, 90C399A2AF93F0897169E413 /* Circularity.swift in Sources */, A70936B898139A6C5F83F616 /* ContainerSpec.Arguments.swift in Sources */, @@ -1688,9 +1613,7 @@ 5D5852F610358DFF7230C35C /* Assembler.swift in Sources */, 74E1FC692A27C56510363364 /* Assembly.swift in Sources */, FA805A162E989A22990B99AA /* Behavior.swift in Sources */, - 6FCCBA9D2E4C2A225CB1A152 /* BinderEnvironment.swift in Sources */, F9A4BF18B0085B7DCD3440EC /* AnyBinding.swift in Sources */, - 6CFE30E5595611778893D147 /* BindingBuilder.swift in Sources */, 6A03ABEED82EF31E8E6E297E /* Container+Logging.swift in Sources */, A5E4C79F89E1A8AB3A4D8D6E /* Container+Registration.swift in Sources */, BD9B57E26722C80B7EF990DB /* Container+TypeForwarding.swift in Sources */, @@ -1698,14 +1621,12 @@ DD5E3AF2B5FCE5E81EBDF606 /* ContextTranslator.swift in Sources */, 76FB9AFE299316E7F3F4C3BB /* InstanceRequest.swift in Sources */, 77B87F482311580600321C08 /* Binding+Api.swift in Sources */, - 157A967F9BAD0B8DAFAC2A36 /* InstanceBuilder.swift in Sources */, 57BFBA2077E70DC1C2FE796C /* InstanceWrapper.swift in Sources */, 293985649250DF270DC89135 /* Matchable.swift in Sources */, 77ED80072311221600AC48F9 /* ValueRequest.swift in Sources */, B4B66D7251BDDE25D6D7FB3C /* ObjectScope.swift in Sources */, 773BE491231124AD000AA1A9 /* Binding.swift in Sources */, 77B87F45231157EA00321C08 /* Binding+Factory.swift in Sources */, - 5365FDFB2DDA6491F3049654 /* Opaque.swift in Sources */, 6A967AE5710606998C2BE070 /* PropertyWrapper.swift in Sources */, B293894FEB67831DDA5F000E /* Reference.swift in Sources */, 8A4E9E736239F92F878C070C /* Resolver+FunctionCall.swift in Sources */, @@ -1715,17 +1636,14 @@ B84167AC8C6BEB57C4D0695A /* Scope.swift in Sources */, E7D1045D25FAB592401DCAF0 /* ScopeRegistry.swift in Sources */, 4347EE17D0C0ED574C899D85 /* ScopeRegistryKey.swift in Sources */, - B91523667CD2A31E889A4669 /* ScopedBinding.swift in Sources */, 5FCE2A2AE5DD0DBECA4A9953 /* ServiceEntry+TypeForwarding.swift in Sources */, D98BB7F59E98FC197D1C97A2 /* ServiceEntry.swift in Sources */, - 5F49839A5C17677861F5971B /* SimpleBinding.swift in Sources */, EFD2F695B86E74C77F46B7D1 /* Swinject+Builder.swift in Sources */, 63528D45A548DD58D748D54C /* Swinject.swift in Sources */, C8462BEE06316286B9CA85AC /* SwinjectContainer.swift in Sources */, 91E435894038C42335086FA8 /* SwinjectError.swift in Sources */, C637E97E193BB1DADDDC6C21 /* SwinjectModule.swift in Sources */, 0CE1126436F680F9684837E4 /* SwinjectTree.swift in Sources */, - 4B9811CF0604946CCF323ED2 /* TypeBinder.swift in Sources */, 9CEE20BD42795D5E5F39BF20 /* TypeDescriptor.swift in Sources */, 8B711CBE6A5B86DC2D6CABDC /* UnboundScope.swift in Sources */, FC339851D7EEE4D17178CC1F /* Weak.swift in Sources */, @@ -1739,9 +1657,7 @@ 290C9E9420A1EE30456476CB /* Assembler.swift in Sources */, 3099172980F9E9143C0A1C20 /* Assembly.swift in Sources */, 2CB057F2A16DA462E0517AAB /* Behavior.swift in Sources */, - 2DD6F290740EA69B3E73E0EA /* BinderEnvironment.swift in Sources */, D2BAE1CB997A4D052CB8EFC8 /* AnyBinding.swift in Sources */, - FD8BB4CC8DA0E560E39FA491 /* BindingBuilder.swift in Sources */, 1ED6BD68D92F4FE60978EF22 /* Container+Logging.swift in Sources */, 77ED80082311221600AC48F9 /* ValueRequest.swift in Sources */, CB0B308F3D3A831A28127462 /* Container+Registration.swift in Sources */, @@ -1750,11 +1666,9 @@ F06DEB671A4B85ABB0E96E51 /* ContextTranslator.swift in Sources */, 77B87F472311580500321C08 /* Binding+Api.swift in Sources */, 027015812E961322FE3D942B /* InstanceRequest.swift in Sources */, - C6E443EAD892B0B69DA61144 /* InstanceBuilder.swift in Sources */, 389C54E04DD794DA4F648571 /* InstanceWrapper.swift in Sources */, 87FEAEF562B99522083CB87D /* Matchable.swift in Sources */, 6DA49F84E2592B32F81F268B /* ObjectScope.swift in Sources */, - 6251955691663E4495DE310D /* Opaque.swift in Sources */, 77B87F46231157EA00321C08 /* Binding+Factory.swift in Sources */, 5F1647DCC0D437A782647372 /* PropertyWrapper.swift in Sources */, 2D020C6391A4F6A2118585B8 /* Reference.swift in Sources */, @@ -1766,17 +1680,14 @@ 2C352AAD1AC7D82A4A059046 /* Scope.swift in Sources */, 02556F149C9AAEF5CE353AC1 /* ScopeRegistry.swift in Sources */, 06F4CAB352B4F623FF7BD885 /* ScopeRegistryKey.swift in Sources */, - 7C745281CA1627BCC8A8A92A /* ScopedBinding.swift in Sources */, A75BAA10EC6F738EBC2C5BE8 /* ServiceEntry+TypeForwarding.swift in Sources */, 59FD1167CD4A913E04D3EAFD /* ServiceEntry.swift in Sources */, - EE3063E3D1582D3BB7CC43F0 /* SimpleBinding.swift in Sources */, DCB7C4BF24782862BE9DB135 /* Swinject+Builder.swift in Sources */, 75D74C8C25EDACF5A7A75A5C /* Swinject.swift in Sources */, 4D86550CC5C281A58B4A6F61 /* SwinjectContainer.swift in Sources */, 4DF3DC1CDD3C4948F9BDD3DF /* SwinjectError.swift in Sources */, 82299769BC637A14E7827DB0 /* SwinjectModule.swift in Sources */, 372F0061E762BF8FFF05457F /* SwinjectTree.swift in Sources */, - 9425887520AC2DBDCBACB252 /* TypeBinder.swift in Sources */, AC470B4322599B0A076DD3FF /* TypeDescriptor.swift in Sources */, D669A1E2657CC868027395D9 /* UnboundScope.swift in Sources */, 95E6DD9D94BE64420EEC1298 /* Weak.swift in Sources */, @@ -1790,9 +1701,7 @@ DC5B169FD525CC1C01518312 /* Assembler.swift in Sources */, BB8FDF4F2A0AF8C1DA615854 /* Assembly.swift in Sources */, F7979BE4BE1B1C7101D15E61 /* Behavior.swift in Sources */, - B5FF5DFE394B6B1BB930D88D /* BinderEnvironment.swift in Sources */, 3F8F5645D6D37FCEC1D89393 /* AnyBinding.swift in Sources */, - 2A6D2874ADB24B08DAE1EC04 /* BindingBuilder.swift in Sources */, 999AF7221D3F2E1F83C3ACB1 /* Container+Logging.swift in Sources */, 77ED80052311221600AC48F9 /* ValueRequest.swift in Sources */, 21285CED416F1317E993397A /* Container+Registration.swift in Sources */, @@ -1800,12 +1709,10 @@ 0622539110A7430776A307C7 /* Container.swift in Sources */, D1DF4740A9D86362B63104B8 /* ContextTranslator.swift in Sources */, 826D63FA91E370F0061768B0 /* InstanceRequest.swift in Sources */, - 16393BD60FDDD38B5A977C55 /* InstanceBuilder.swift in Sources */, 77B87F43231157E900321C08 /* Binding+Factory.swift in Sources */, 98ACB1A09194572A946CA90D /* InstanceWrapper.swift in Sources */, 5ED8A7D19F21FA686215F72C /* Matchable.swift in Sources */, B42331BF00B482369B908BB8 /* ObjectScope.swift in Sources */, - EB73B06547A273D2534528E3 /* Opaque.swift in Sources */, 14C8DA4FCCDFA87885038D38 /* PropertyWrapper.swift in Sources */, 0509EE8D41BF354EB91ACC80 /* Reference.swift in Sources */, 5A78C354D420D64CF8A787C1 /* Resolver+FunctionCall.swift in Sources */, @@ -1816,17 +1723,14 @@ 96EA0A5DF33F025EBE0B67D2 /* Scope.swift in Sources */, D861595482464ED95CF81922 /* ScopeRegistry.swift in Sources */, 920DE2CAB9895D10FAE48FBA /* ScopeRegistryKey.swift in Sources */, - 85CBEFBB558636EAC76E5F0C /* ScopedBinding.swift in Sources */, CEE763218A90832454A6E2DE /* ServiceEntry+TypeForwarding.swift in Sources */, 36A706F87ED2E88F3390C6C2 /* ServiceEntry.swift in Sources */, - 19E02C4326FB05E0630B56E3 /* SimpleBinding.swift in Sources */, 6C01E868DE44BD396D94858B /* Swinject+Builder.swift in Sources */, 4EC94A51037C79DE0C5C8CB1 /* Swinject.swift in Sources */, A6721BA534AD082E1E7C1D08 /* SwinjectContainer.swift in Sources */, 820307073A53AED47AC99B8D /* SwinjectError.swift in Sources */, 8E77B56EE7F90BF723600DDF /* SwinjectModule.swift in Sources */, 6922AE734E84B515C94D9480 /* SwinjectTree.swift in Sources */, - EF79F0B3D497215D4BBBC038 /* TypeBinder.swift in Sources */, E3EABE098DBFB561A20632E3 /* TypeDescriptor.swift in Sources */, 19F21849D1E173F5AC724281 /* UnboundScope.swift in Sources */, 77B87F3C23112DB100321C08 /* Binding+Api.swift in Sources */, diff --git a/Templates/BinderEnvironment.swifttemplate b/Templates/BinderEnvironment.swifttemplate deleted file mode 100644 index c374d91c..00000000 --- a/Templates/BinderEnvironment.swifttemplate +++ /dev/null @@ -1,12 +0,0 @@ -<%- include("SwiftCode") %> -// sourcery:inline:SomeBindingBuilders -extension ContextedEnvironment { -<%= BinderVariation.publicCases.filter { $0.isContexted && !$0.isScoped }.map { $0.render(true) }.joined(separator: "\n\n") %> -} - -extension ScopedEnvironment { -<%= BinderVariation.publicCases.filter { $0.isContexted && $0.isScoped }.map { $0.render(true) }.joined(separator: "\n\n") %> -} - -<%= BinderVariation.publicCases.filter { !$0.isContexted }.map { $0.render(false) }.joined(separator: "\n\n") %> -// sourcery:end diff --git a/Templates/BinderVariation.swift b/Templates/BinderVariation.swift deleted file mode 100644 index 295be62f..00000000 --- a/Templates/BinderVariation.swift +++ /dev/null @@ -1,155 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -struct BinderVariation { - let args: Int - let hasResolver: Bool - let hasContext: Bool - let isMatchable: Bool - let isScoped: Bool - let isContexted: Bool -} - -extension BinderVariation { - var argTypes: String { - return join((1 ..< args + 1).map { "Arg\($0)" }) - } - - var argTypesOrNil: String? { - return argTypes.isEmpty ? nil : argTypes - } - - var genericTypes: String { - return join("Type", argTypesOrNil) - } - - var builderInputTypes: String { - return join( - hasResolver ? "Resolver" : nil, - hasContext ? "Context" : nil, - argTypesOrNil - ) - } - - var params: String { - return join( - isScoped ? "ref: @escaping ReferenceMaker = strongRef" : nil, - "_ builder: @escaping (\(builderInputTypes)) throws -> Type" - ) - } - - var scopeType: String { - return isContexted ? "AScope" : "UnboundScope" - } - - var scopeVar: String { - return isContexted ? "scope" : ".root" - } - - var contextType: String { - return isContexted ? "Context" : "Any" - } - - var argReturnType: String { - switch args { - case 0: return "Void" - case 1: return isMatchable ? "MatchableBox1" : "Arg1" - default: return isMatchable ? "MatchableBox\(args)<\(argTypes)>" : "(\(argTypes))" - } - } - - var returnType: String { - return "SomeBindingBuilder" - } - - var actualReturnType: String { - if isScoped { - return "ScopedBinding.Builder" - } else { - return "SimpleBinding.Builder" - } - } - - var hashableArgTypes: String { - return join((1 ..< args + 1).map { "Arg\($0): Hashable" }) - } - - var constraints: String { - return isMatchable && args > 0 ? "where \(hashableArgTypes) " : "" - } - - var functionName: String { - switch (isScoped, args > 0) { - case (true, true): return "multiton" - case (true, false): return "singleton" - case (false, true): return "factory" - case (false, false): return "provider" - } - } - - var initVars: String { - return isScoped ? "(\(join(scopeVar, "ref")))" : "" - } - - var argVarsOrNil: String? { - switch args { - case 0: return nil - case 1: return isMatchable ? "a.arg1" : "a" - default: return join((1 ... args).map { isMatchable ? "a.arg\($0)" : "a.\($0 - 1)" }) - } - } - - var builderInputs: String { - return join( - hasResolver ? "r" : "_", - hasContext ? "c" : "_", - args > 0 ? "a" : "_" - ) - } - - var builderVars: String { - return join( - hasResolver ? "r" : nil, - hasContext ? "c" : nil, - argVarsOrNil - ) - } -} - -extension BinderVariation { - static let maxArgs = 5 - - static let allCases = (0 ... maxArgs) - .flatMap { t in [false, true].map { (t, $0) } } - .flatMap { t in [false, true].map { (t.0, t.1, $0) } } - .flatMap { t in [false, true].map { (t.0, t.1, t.2, $0) } } - .flatMap { t in [false, true].map { (t.0, t.1, t.2, t.3, $0) } } - .flatMap { t in [false, true].map { (t.0, t.1, t.2, t.3, t.4, $0) } } - .map(BinderVariation.init) - - static let sortedCases = allCases.sorted { [ - !$0.isScoped && $1.isScoped, - $0.args < $1.args, - !$0.isMatchable && $1.isMatchable && $0.args == $1.args, - ].contains(true) } - - static let publicCases = sortedCases - .filter { !($0.hasContext && !$0.isContexted) } - .filter { !($0.hasContext && !$0.hasResolver) } - .filter { !($0.args == 0 && !$0.isMatchable) } - .filter { !($0.args > 0 && !$0.hasResolver) } - .filter { !($0.args > 0 && $0.isContexted && !$0.hasContext) } - .filter { !($0.isScoped && !$0.isMatchable) } -} - -extension BinderVariation { - func render(_ indent: Bool) -> String { - let prefix = indent ? " " : "" - return """ - \(prefix)public func \(functionName)<\(genericTypes)>(\(params)) -> \(returnType) \(constraints){ - \(prefix) return \(actualReturnType)\(initVars) { \(builderInputs) in try builder(\(builderVars)) }.opaque - \(prefix)} - """ - } -} diff --git a/Templates/SwiftCode.swifttemplate b/Templates/SwiftCode.swifttemplate index a0a36506..c107d5d3 100644 --- a/Templates/SwiftCode.swifttemplate +++ b/Templates/SwiftCode.swifttemplate @@ -3,161 +3,6 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -struct BinderVariation { - let args: Int - let hasResolver: Bool - let hasContext: Bool - let isMatchable: Bool - let isScoped: Bool - let isContexted: Bool -} - -extension BinderVariation { - var argTypes: String { - return join((1 ..< args + 1).map { "Arg\($0)" }) - } - - var argTypesOrNil: String? { - return argTypes.isEmpty ? nil : argTypes - } - - var genericTypes: String { - return join("Type", argTypesOrNil) - } - - var builderInputTypes: String { - return join( - hasResolver ? "Resolver" : nil, - hasContext ? "Context" : nil, - argTypesOrNil - ) - } - - var params: String { - return join( - isScoped ? "ref: @escaping ReferenceMaker = strongRef" : nil, - "_ builder: @escaping (\(builderInputTypes)) throws -> Type" - ) - } - - var scopeType: String { - return isContexted ? "AScope" : "UnboundScope" - } - - var scopeVar: String { - return isContexted ? "scope" : ".root" - } - - var contextType: String { - return isContexted ? "Context" : "Any" - } - - var argReturnType: String { - switch args { - case 0: return "Void" - case 1: return isMatchable ? "MatchableBox1" : "Arg1" - default: return isMatchable ? "MatchableBox\(args)<\(argTypes)>" : "(\(argTypes))" - } - } - - var returnType: String { - return "SomeBindingBuilder" - } - - var actualReturnType: String { - if isScoped { - return "ScopedBinding.Builder" - } else { - return "SimpleBinding.Builder" - } - } - - var hashableArgTypes: String { - return join((1 ..< args + 1).map { "Arg\($0): Hashable" }) - } - - var constraints: String { - return isMatchable && args > 0 ? "where \(hashableArgTypes) " : "" - } - - var functionName: String { - switch (isScoped, args > 0) { - case (true, true): return "multiton" - case (true, false): return "singleton" - case (false, true): return "factory" - case (false, false): return "provider" - } - } - - var initVars: String { - return isScoped ? "(\(join(scopeVar, "ref")))" : "" - } - - var argVarsOrNil: String? { - switch args { - case 0: return nil - case 1: return isMatchable ? "a.arg1" : "a" - default: return join((1 ... args).map { isMatchable ? "a.arg\($0)" : "a.\($0 - 1)" }) - } - } - - var builderInputs: String { - return join( - hasResolver ? "r" : "_", - hasContext ? "c" : "_", - args > 0 ? "a" : "_" - ) - } - - var builderVars: String { - return join( - hasResolver ? "r" : nil, - hasContext ? "c" : nil, - argVarsOrNil - ) - } -} - -extension BinderVariation { - static let maxArgs = 5 - - static let allCases = (0 ... maxArgs) - .flatMap { t in [false, true].map { (t, $0) } } - .flatMap { t in [false, true].map { (t.0, t.1, $0) } } - .flatMap { t in [false, true].map { (t.0, t.1, t.2, $0) } } - .flatMap { t in [false, true].map { (t.0, t.1, t.2, t.3, $0) } } - .flatMap { t in [false, true].map { (t.0, t.1, t.2, t.3, t.4, $0) } } - .map(BinderVariation.init) - - static let sortedCases = allCases.sorted { [ - !$0.isScoped && $1.isScoped, - $0.args < $1.args, - !$0.isMatchable && $1.isMatchable && $0.args == $1.args, - ].contains(true) } - - static let publicCases = sortedCases - .filter { !($0.hasContext && !$0.isContexted) } - .filter { !($0.hasContext && !$0.hasResolver) } - .filter { !($0.args == 0 && !$0.isMatchable) } - .filter { !($0.args > 0 && !$0.hasResolver) } - .filter { !($0.args > 0 && $0.isContexted && !$0.hasContext) } - .filter { !($0.isScoped && !$0.isMatchable) } -} - -extension BinderVariation { - func render(_ indent: Bool) -> String { - let prefix = indent ? " " : "" - return """ - \(prefix)public func \(functionName)<\(genericTypes)>(\(params)) -> \(returnType) \(constraints){ - \(prefix) return \(actualReturnType)\(initVars) { \(builderInputs) in try builder(\(builderVars)) }.opaque - \(prefix)} - """ - } -} -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - struct FactoryVariation { let args: Int let hasResolver: Bool diff --git a/Tests/3.0 API/PropertyWrappersSpec.swift b/Tests/3.0 API/PropertyWrappersSpec.swift index ca63b50e..c40e209c 100644 --- a/Tests/3.0 API/PropertyWrappersSpec.swift +++ b/Tests/3.0 API/PropertyWrappersSpec.swift @@ -28,7 +28,7 @@ class PropertyWrappersSpec: QuickSpec { override func spec() { #if swift(>=5.1) } it("throws if provided type is bound with different arguments") { let swinject = Swinject { - bbind(Int.self) & 42 + register().constant(42) } expect { try swinject.instance(arg: "arg") as Wrapped }.to(throwError()) } diff --git a/Tests/Support/Bridge.swift b/Tests/Support/Bridge.swift deleted file mode 100644 index 8cb0be50..00000000 --- a/Tests/Support/Bridge.swift +++ /dev/null @@ -1,11 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -import func Swinject.bind -import struct Swinject.TypeBinder - -// Original Swinject `bind` function conflicts with QuickSpec's instance methods -func bbind(_: Type.Type, tagged tag: String? = nil, overrides: Bool = false) -> TypeBinder { - return bind(Type.self, tagged: tag, overrides: overrides) -} diff --git a/Tests/Unit Specs/SwinjectTreeBuilderSpec.swift b/Tests/Unit Specs/SwinjectTreeBuilderSpec.swift index a3abfacf..510f48e4 100644 --- a/Tests/Unit Specs/SwinjectTreeBuilderSpec.swift +++ b/Tests/Unit Specs/SwinjectTreeBuilderSpec.swift @@ -13,30 +13,30 @@ class SwinjectTreeBuilderSpec: QuickSpec { override func spec() { #if swift(>=5. expect(tree.bindings).to(beEmpty()) } it("builds closure with single entry") { - let tree = makeTree { bbind(Int.self).with(42) } + let tree = makeTree { register().constant(42) } expect(tree.bindings.count) == 1 } it("builds closure with multiple entries") { let tree = makeTree { - bbind(Int.self).with(42) - bbind(UInt.self).with(42) - bbind(Float.self).with(42) - bbind(Double.self).with(42) - bbind(Int32.self).with(42) + register().constant(42 as Int) + register().constant(42 as UInt) + register().constant(42 as Float) + register().constant(42 as Double) + register().constant(42 as Int32) } expect(tree.bindings.count) == 5 } it("builds closure with if statement") { let tree = makeTree { - if true { bbind(Int.self).with(42) } + if true { register().constant(42) } } expect(tree.bindings.count) == 1 } it("builds closure with nested if statement") { let tree = makeTree { if true { - bbind(Int.self).with(42) - if true { bbind(UInt.self).with(42) } + register().constant(42) + if true { register().constant(42 as UInt) } } } expect(tree.bindings.count) == 2 @@ -44,8 +44,8 @@ class SwinjectTreeBuilderSpec: QuickSpec { override func spec() { #if swift(>=5. it("builds closure with if else statement") { let tree = makeTree { if false {} else { - bbind(Int.self).with(42) - bbind(UInt.self).with(42) + register().constant(42) + register().constant(42 as UInt) } } expect(tree.bindings.count) == 2 @@ -54,9 +54,9 @@ class SwinjectTreeBuilderSpec: QuickSpec { override func spec() { #if swift(>=5. let tree = makeTree { include(Swinject.Module("1")) include(Swinject.Module("2")) - bbind(Int.self).with(42) - bbind(UInt.self).with(42) - bbind(Float.self).with(42) + register().constant(42) + register().constant(42 as UInt) + register().constant(42 as Float) } expect(tree.modules.count) == 2 expect(tree.bindings.count) == 3 From a5e5660725792f75693b8e3b5175b3b96f1ac991 Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Sat, 24 Aug 2019 15:15:28 +0200 Subject: [PATCH 224/239] Make matchboxes internal --- Sources/2.0 API/ServiceEntry.swift | 2 +- Sources/3.0 API/Binding+Api.swift | 36 ++++++++++++------- Sources/3.0 API/Binding+Factory.swift | 48 +++++++++++++------------- Sources/3.0 API/Binding.swift | 28 ++++++++------- Sources/Core/AnyBinding.swift | 3 +- Sources/Core/Matchable.swift | 11 +++--- Sources/Core/Swinject.swift | 2 +- Templates/FactoryVariation.swift | 10 +++--- Templates/MatchableBoxes.swifttemplate | 2 +- Templates/SwiftCode.swifttemplate | 10 +++--- 10 files changed, 82 insertions(+), 70 deletions(-) diff --git a/Sources/2.0 API/ServiceEntry.swift b/Sources/2.0 API/ServiceEntry.swift index a05f802e..c5fc96f1 100644 --- a/Sources/2.0 API/ServiceEntry.swift +++ b/Sources/2.0 API/ServiceEntry.swift @@ -72,7 +72,7 @@ public class ServiceEntry { extension ServiceEntry: AnyBinding { public var overrides: Bool { return false } - public func instance(arg: Any, resolver: Resolver) throws -> Any { + public func makeInstance(resolver: Resolver, arg: Any) throws -> Any { let context = try resolver.context(as: key.contextType) if let scope = scope { return getRegistry(scope: scope, context: context).instance( diff --git a/Sources/3.0 API/Binding+Api.swift b/Sources/3.0 API/Binding+Api.swift index acbc7489..301eb1e5 100644 --- a/Sources/3.0 API/Binding+Api.swift +++ b/Sources/3.0 API/Binding+Api.swift @@ -2,29 +2,39 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -public typealias AnyContext = Any -public typealias NoArgument = Void -public typealias NoScope = Void - -public func register(inContextOf _: Context.Type) -> Binding { - return Binding(products: [], dependencies: .none, factory: { _, _ in }, properties: .default, scope: ()) +public func register(inContextOf _: Context.Type) -> Binding { + return Binding( + products: [], + dependencies: .none, + factory: { _, _ in }, + properties: .default, + scope: nil, + argumentType: Void.self + ) } -public func register() -> Binding { +public func register() -> Binding { return register(inContextOf: Any.self) } -public func registerSingle(in scope: AScope) -> Binding { - return Binding(products: [], dependencies: .none, factory: { _, _ in }, properties: .default, scope: scope) +public func registerSingle(in scope: AScope) -> Binding { + return Binding( + products: [], + dependencies: .none, + factory: { _, _ in }, + properties: .default, + scope: scope, + argumentType: Void.self + ) } -public func registerSingle() -> Binding { - return registerSingle(in: .root) +public func registerSingle() -> Binding { + return registerSingle(in: UnboundScope.root) } public extension Binding where Instance == Void { - func constant(_ value: Value, tag: String? = nil) -> Binding { - return updatedFactory { _, _ in value }.updated { + func constant(_ value: Value, tag: String? = nil) -> Binding { + return updatedFactory { (_, _: Void) in value }.updated { $0.products = [tagged(Value.self, with: tag)] $0.dependencies = .none } diff --git a/Sources/3.0 API/Binding+Factory.swift b/Sources/3.0 API/Binding+Factory.swift index df767a52..daaf3d7c 100644 --- a/Sources/3.0 API/Binding+Factory.swift +++ b/Sources/3.0 API/Binding+Factory.swift @@ -7,85 +7,85 @@ // swiftlint:disable large_tuple // sourcery:inline:BindingFactoryApi public extension Binding { - func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping () throws -> NewInstance) -> Binding { - return updatedFactory { _, _ in try factory() }.updated { + func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping () throws -> NewInstance) -> Binding { + return updatedFactory { (_, _: Void) in try factory() }.updated { $0.products = [tagged(NewInstance.self, with: tag)] $0.dependencies = .undefined } } - func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver) throws -> NewInstance) -> Binding { - return updatedFactory { r, _ in try factory(r) }.updated { + func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver) throws -> NewInstance) -> Binding { + return updatedFactory { (r, _: Void) in try factory(r) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] $0.dependencies = .undefined } } - func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1) throws -> NewInstance) -> Binding { - return updatedFactory { r, a in try factory(r, a) }.updated { + func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1) throws -> NewInstance) -> Binding { + return updatedFactory { (r, a: Arg1) in try factory(r, a) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] $0.dependencies = .undefined } } - func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1) throws -> NewInstance) -> Binding> where Arg1: Hashable { - return updatedFactory { r, a in try factory(r, a.arg1) }.updated { + func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1) throws -> NewInstance) -> Binding where Arg1: Hashable { + return updatedFactory { (r, a: MatchableBox1) in try factory(r, a.arg1) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] $0.dependencies = .undefined } } - func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2) throws -> NewInstance) -> Binding { - return updatedFactory { r, a in try factory(r, a.0, a.1) }.updated { + func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2) throws -> NewInstance) -> Binding { + return updatedFactory { (r, a: (Arg1, Arg2)) in try factory(r, a.0, a.1) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] $0.dependencies = .undefined } } - func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2) throws -> NewInstance) -> Binding> where Arg1: Hashable, Arg2: Hashable { - return updatedFactory { r, a in try factory(r, a.arg1, a.arg2) }.updated { + func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2) throws -> NewInstance) -> Binding where Arg1: Hashable, Arg2: Hashable { + return updatedFactory { (r, a: MatchableBox2) in try factory(r, a.arg1, a.arg2) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] $0.dependencies = .undefined } } - func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2, Arg3) throws -> NewInstance) -> Binding { - return updatedFactory { r, a in try factory(r, a.0, a.1, a.2) }.updated { + func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2, Arg3) throws -> NewInstance) -> Binding { + return updatedFactory { (r, a: (Arg1, Arg2, Arg3)) in try factory(r, a.0, a.1, a.2) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] $0.dependencies = .undefined } } - func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2, Arg3) throws -> NewInstance) -> Binding> where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - return updatedFactory { r, a in try factory(r, a.arg1, a.arg2, a.arg3) }.updated { + func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2, Arg3) throws -> NewInstance) -> Binding where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + return updatedFactory { (r, a: MatchableBox3) in try factory(r, a.arg1, a.arg2, a.arg3) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] $0.dependencies = .undefined } } - func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2, Arg3, Arg4) throws -> NewInstance) -> Binding { - return updatedFactory { r, a in try factory(r, a.0, a.1, a.2, a.3) }.updated { + func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2, Arg3, Arg4) throws -> NewInstance) -> Binding { + return updatedFactory { (r, a: (Arg1, Arg2, Arg3, Arg4)) in try factory(r, a.0, a.1, a.2, a.3) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] $0.dependencies = .undefined } } - func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2, Arg3, Arg4) throws -> NewInstance) -> Binding> where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return updatedFactory { r, a in try factory(r, a.arg1, a.arg2, a.arg3, a.arg4) }.updated { + func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2, Arg3, Arg4) throws -> NewInstance) -> Binding where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + return updatedFactory { (r, a: MatchableBox4) in try factory(r, a.arg1, a.arg2, a.arg3, a.arg4) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] $0.dependencies = .undefined } } - func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> NewInstance) -> Binding { - return updatedFactory { r, a in try factory(r, a.0, a.1, a.2, a.3, a.4) }.updated { + func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> NewInstance) -> Binding { + return updatedFactory { (r, a: (Arg1, Arg2, Arg3, Arg4, Arg5)) in try factory(r, a.0, a.1, a.2, a.3, a.4) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] $0.dependencies = .undefined } } - func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> NewInstance) -> Binding> where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return updatedFactory { r, a in try factory(r, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) }.updated { + func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> NewInstance) -> Binding where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + return updatedFactory { (r, a: MatchableBox5) in try factory(r, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] $0.dependencies = .undefined } diff --git a/Sources/3.0 API/Binding.swift b/Sources/3.0 API/Binding.swift index d870e460..fc5486fe 100644 --- a/Sources/3.0 API/Binding.swift +++ b/Sources/3.0 API/Binding.swift @@ -16,28 +16,27 @@ enum BindingDependencies { static let none = BindingDependencies.requests([]) } -public struct Binding { +public struct Binding { var products: [TypeDescriptor] var dependencies: BindingDependencies - var factory: (ContextedResolver, Argument) throws -> Instance + var factory: (ContextedResolver, Any) throws -> Instance var properties: BindingProperties - var scope: AScope + let scope: AnyScope? + let argumentType: Any.Type } extension Binding { var keys: [BindingKey] { - return products.map { BindingKey(descriptor: $0, contextType: Context.self, argumentType: Argument.self) } + return products.map { BindingKey(descriptor: $0, contextType: Context.self, argumentType: argumentType) } } } extension Binding: AnyBinding { public var key: BindingKey { return keys.first! } // FIXME: enable multiple keys in AnyBinding public var overrides: Bool { return properties.overrides } -} -extension Binding { - public func instance(arg: Any, resolver: Resolver) throws -> Any { - if let scope = scope as? AnyScope { + public func makeInstance(resolver: Resolver, arg: Any) throws -> Any { + if let scope = scope { return try scopedInstance(resolver: resolver, scope: scope, arg: arg) } else { return try simpleInstance(resolver: resolver, arg: arg) @@ -53,7 +52,7 @@ extension Binding { } private func simpleInstance(resolver: Resolver, arg: Any) throws -> Any { - return try factory(resolver.contexted(), arg as! Argument) + return try factory(resolver.contexted(), arg) } } @@ -66,9 +65,14 @@ extension Binding { func updatedFactory( factory: @escaping (ContextedResolver, NewArgument) throws -> NewInstance - ) -> Binding { - return Binding( - products: products, dependencies: dependencies, factory: factory, properties: properties, scope: scope + ) -> Binding { + return Binding( + products: products, + dependencies: dependencies, + factory: { try factory($0, $1 as! NewArgument) }, + properties: properties, + scope: scope, + argumentType: NewArgument.self ) } } diff --git a/Sources/Core/AnyBinding.swift b/Sources/Core/AnyBinding.swift index 3f3425b9..cb7589f7 100644 --- a/Sources/Core/AnyBinding.swift +++ b/Sources/Core/AnyBinding.swift @@ -32,9 +32,8 @@ extension BindingKey { } } -// TODO: Can We make this internal? public protocol AnyBinding: SwinjectEntry { var key: BindingKey { get } var overrides: Bool { get } - func instance(arg: Any, resolver: Resolver) throws -> Any + func makeInstance(resolver: Resolver, arg: Any) throws -> Any } diff --git a/Sources/Core/Matchable.swift b/Sources/Core/Matchable.swift index 8bf0cfaa..335762c5 100644 --- a/Sources/Core/Matchable.swift +++ b/Sources/Core/Matchable.swift @@ -13,33 +13,32 @@ public extension Matchable where Self: Equatable { } } -// TODO: Can we make boxes internal? // swiftlint:disable line_length // swiftlint:disable large_tuple // sourcery:inline:MatchableBoxes -public struct MatchableBox1: Hashable, Matchable where Arg1: Hashable { +struct MatchableBox1: Hashable, Matchable where Arg1: Hashable { let arg1: Arg1 } -public struct MatchableBox2: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable { +struct MatchableBox2: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable { let arg1: Arg1 let arg2: Arg2 } -public struct MatchableBox3: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { +struct MatchableBox3: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { let arg1: Arg1 let arg2: Arg2 let arg3: Arg3 } -public struct MatchableBox4: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { +struct MatchableBox4: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { let arg1: Arg1 let arg2: Arg2 let arg3: Arg3 let arg4: Arg4 } -public struct MatchableBox5: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { +struct MatchableBox5: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { let arg1: Arg1 let arg2: Arg2 let arg3: Arg3 diff --git a/Sources/Core/Swinject.swift b/Sources/Core/Swinject.swift index e538543c..4b0445cb 100644 --- a/Sources/Core/Swinject.swift +++ b/Sources/Core/Swinject.swift @@ -78,7 +78,7 @@ extension Swinject { } private func makeInstance(from binding: AnyBinding, arg: Argument) throws -> Type { - return try binding.instance(arg: arg, resolver: self) as? Type ?? { throw SwinjectError() }() + return try binding.makeInstance(resolver: self, arg: arg) as? Type ?? { throw SwinjectError() }() } } diff --git a/Templates/FactoryVariation.swift b/Templates/FactoryVariation.swift index 16965e0f..0a2d805d 100644 --- a/Templates/FactoryVariation.swift +++ b/Templates/FactoryVariation.swift @@ -36,16 +36,16 @@ extension FactoryVariation { ) } - var argReturnType: String { + var argInputType: String { switch args { - case 0: return "NoArgument" + case 0: return "Void" case 1: return isMatchable ? "MatchableBox1" : "Arg1" default: return isMatchable ? "MatchableBox\(args)<\(argTypes)>" : "(\(argTypes))" } } var returnType: String { - return "Binding" + return "Binding" } var hashableArgTypes: String { @@ -67,7 +67,7 @@ extension FactoryVariation { var factoryInputs: String { return join( hasResolver ? "r" : "_", - args > 0 ? "a" : "_" + (args > 0 ? "a" : "_") + ": \(argInputType)" ) } @@ -101,7 +101,7 @@ extension FactoryVariation { func render() -> String { return """ func factory<\(genericTypes)>(\(params)) -> \(returnType) \(constraints){ - return updatedFactory { \(factoryInputs) in try factory(\(factoryVars)) }.updated { + return updatedFactory { (\(factoryInputs)) in try factory(\(factoryVars)) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] $0.dependencies = .undefined } diff --git a/Templates/MatchableBoxes.swifttemplate b/Templates/MatchableBoxes.swifttemplate index 95c82134..9156a5cf 100644 --- a/Templates/MatchableBoxes.swifttemplate +++ b/Templates/MatchableBoxes.swifttemplate @@ -5,7 +5,7 @@ let arg_hashables = (1...i).map { "Arg\($0): Hashable" }.joined(separator: ", ") let type_name = "MatchableBox\(i)<\(arg_types)>" -%> -public struct <%= type_name %>: Hashable, Matchable where <%= arg_hashables %> { +struct <%= type_name %>: Hashable, Matchable where <%= arg_hashables %> { <%= (1...i).map { "let arg\($0): Arg\($0)" }.joined(separator: "\n ") %> } diff --git a/Templates/SwiftCode.swifttemplate b/Templates/SwiftCode.swifttemplate index c107d5d3..15a2c6c6 100644 --- a/Templates/SwiftCode.swifttemplate +++ b/Templates/SwiftCode.swifttemplate @@ -37,16 +37,16 @@ extension FactoryVariation { ) } - var argReturnType: String { + var argInputType: String { switch args { - case 0: return "NoArgument" + case 0: return "Void" case 1: return isMatchable ? "MatchableBox1" : "Arg1" default: return isMatchable ? "MatchableBox\(args)<\(argTypes)>" : "(\(argTypes))" } } var returnType: String { - return "Binding" + return "Binding" } var hashableArgTypes: String { @@ -68,7 +68,7 @@ extension FactoryVariation { var factoryInputs: String { return join( hasResolver ? "r" : "_", - args > 0 ? "a" : "_" + (args > 0 ? "a" : "_") + ": \(argInputType)" ) } @@ -102,7 +102,7 @@ extension FactoryVariation { func render() -> String { return """ func factory<\(genericTypes)>(\(params)) -> \(returnType) \(constraints){ - return updatedFactory { \(factoryInputs) in try factory(\(factoryVars)) }.updated { + return updatedFactory { (\(factoryInputs)) in try factory(\(factoryVars)) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] $0.dependencies = .undefined } From f2042887d2028089cac926e1015179e4b6d9b2d7 Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Sat, 24 Aug 2019 15:31:17 +0200 Subject: [PATCH 225/239] Implement multiple type binding --- Sources/2.0 API/ServiceEntry.swift | 4 +++- Sources/3.0 API/Binding.swift | 7 ++----- Sources/Core/AnyBinding.swift | 2 +- Sources/Core/SwinjectContainer.swift | 16 +++++++++------- Tests/3.0 API/BindingSpec.swift | 11 ++++++++++- Tests/3.0 API/SingletonSpec.swift | 10 ++++++++++ 6 files changed, 35 insertions(+), 15 deletions(-) diff --git a/Sources/2.0 API/ServiceEntry.swift b/Sources/2.0 API/ServiceEntry.swift index c5fc96f1..84dc2225 100644 --- a/Sources/2.0 API/ServiceEntry.swift +++ b/Sources/2.0 API/ServiceEntry.swift @@ -95,13 +95,15 @@ extension ServiceEntry: AnyBinding { return scope.registry(for: context) } - public var key: BindingKey { + var key: BindingKey { return BindingKey( descriptor: tagged(Service.self, with: name), contextType: scope?.contextType ?? Any.self, argumentType: argumentType ) } + + public var keys: [BindingKey] { return [key] } } extension ServiceEntry: CustomStringConvertible { diff --git a/Sources/3.0 API/Binding.swift b/Sources/3.0 API/Binding.swift index fc5486fe..4fb129bf 100644 --- a/Sources/3.0 API/Binding.swift +++ b/Sources/3.0 API/Binding.swift @@ -25,14 +25,11 @@ public struct Binding { let argumentType: Any.Type } -extension Binding { - var keys: [BindingKey] { +extension Binding: AnyBinding { + public var keys: [BindingKey] { return products.map { BindingKey(descriptor: $0, contextType: Context.self, argumentType: argumentType) } } -} -extension Binding: AnyBinding { - public var key: BindingKey { return keys.first! } // FIXME: enable multiple keys in AnyBinding public var overrides: Bool { return properties.overrides } public func makeInstance(resolver: Resolver, arg: Any) throws -> Any { diff --git a/Sources/Core/AnyBinding.swift b/Sources/Core/AnyBinding.swift index cb7589f7..36d9483f 100644 --- a/Sources/Core/AnyBinding.swift +++ b/Sources/Core/AnyBinding.swift @@ -33,7 +33,7 @@ extension BindingKey { } public protocol AnyBinding: SwinjectEntry { - var key: BindingKey { get } + var keys: [BindingKey] { get } var overrides: Bool { get } func makeInstance(resolver: Resolver, arg: Any) throws -> Any } diff --git a/Sources/Core/SwinjectContainer.swift b/Sources/Core/SwinjectContainer.swift index 9a7d7920..3d10b28a 100644 --- a/Sources/Core/SwinjectContainer.swift +++ b/Sources/Core/SwinjectContainer.swift @@ -72,13 +72,15 @@ extension SwinjectContainer.Builder { canOverrideSilently: Bool ) -> [BindingEntry] { return tree.bindings - .map { BindingEntry( - binding: $0, - key: $0.key, - overrides: $0.overrides, - canOverride: canOverride ?? true, - canOverrideSilently: canOverrideSilently - ) } + .flatMap { binding in binding.keys.map { key in + BindingEntry( + binding: binding, + key: key, + overrides: binding.overrides, + canOverride: canOverride ?? true, + canOverrideSilently: canOverrideSilently + ) + } } + tree.modules.flatMap { collectBindingEntries( from: $0.module.tree, canOverride: canOverride ?? $0.canOverride, diff --git a/Tests/3.0 API/BindingSpec.swift b/Tests/3.0 API/BindingSpec.swift index 7ebc6ac1..eda7ff9e 100644 --- a/Tests/3.0 API/BindingSpec.swift +++ b/Tests/3.0 API/BindingSpec.swift @@ -36,7 +36,16 @@ class BindingSpec: QuickSpec { override func spec() { #if swift(>=5.1) } expect(try? swinject.instance(of: Mammal.self) is Human) == true } - // TODO: type forwarding + it("can bind an implementation to multiple types") { + let swinject = Swinject { + register().factory { Human() } + .alsoUse { $0 as Mammal } + .alsoUse({ $0 as AnyObject }, tag: "human") + } + expect { try swinject.instance(of: Human.self) }.notTo(throwError()) + expect { try swinject.instance(of: Mammal.self) }.notTo(throwError()) + expect { try swinject.instance(of: AnyObject.self, tagged: "human") }.notTo(throwError()) + } it("can use up to 5 arguments in factory binding") { let swinject = Swinject { register().factory { (_, a1: Int) in a1 } diff --git a/Tests/3.0 API/SingletonSpec.swift b/Tests/3.0 API/SingletonSpec.swift index 499ac9c4..e9e26c46 100644 --- a/Tests/3.0 API/SingletonSpec.swift +++ b/Tests/3.0 API/SingletonSpec.swift @@ -27,6 +27,16 @@ class SingletonSpec: QuickSpec { override func spec() { #if swift(>=5.1) let second = try? swinject.instance(of: Human.self) expect(first) === second } + it("injects the same instance for types bound to the same implementation") { + let swinject = Swinject { + registerSingle() + .factory { Human() } + .alsoUse { $0 as Mammal } + } + let human = try? swinject.instance() as Human + let mammal = try? swinject.instance() as Mammal + expect(human) === mammal + } it("does not reuse singleton instances for different tags") { let swinject = Swinject { registerSingle().factory(tag: "john") { Human() } From c903b4bce628e8380f57fc5fd2e5b262ff656176 Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Sat, 24 Aug 2019 16:46:09 +0200 Subject: [PATCH 226/239] Redesign injection API --- Sources/2.0 API/Container.swift | 18 +- Sources/3.0 API/InstanceRequest+APi.swift | 57 +++++ Sources/3.0 API/Resolver+FunctionCall.swift | 40 ++-- Sources/3.0 API/Resolver+Injection.swift | 221 ------------------ Sources/Core/Resolver.swift | 16 +- Swinject.xcodeproj/project.pbxproj | 36 +-- Templates/InjectionVariation.swift | 108 --------- Templates/InstanceRequest+Api.swifttemplate | 4 + Templates/InstanceRequestVariation.swift | 86 +++++++ .../Resolver+FunctionCallApi.swifttemplate | 2 +- Templates/Resolver+Injection.swifttemplate | 14 -- Templates/SwiftCode.swifttemplate | 194 +++++++-------- Tests/3.0 API/BindingSpec.swift | 33 ++- Tests/3.0 API/CIrcularitySpec.swift | 34 +-- Tests/3.0 API/ContextSpec.swift | 26 +-- Tests/3.0 API/InjectionSpec.swift | 90 +------ Tests/3.0 API/ModulesSpec.swift | 8 +- Tests/3.0 API/OptionalsSpec.swift | 20 +- Tests/3.0 API/OverrideSpec.swift | 12 +- Tests/3.0 API/PropertyWrappersSpec.swift | 18 +- Tests/3.0 API/RetrievalSpec.swift | 5 +- Tests/3.0 API/ScopesSpec.swift | 26 +-- Tests/3.0 API/SingletonSpec.swift | 34 +-- 23 files changed, 404 insertions(+), 698 deletions(-) create mode 100644 Sources/3.0 API/InstanceRequest+APi.swift delete mode 100644 Sources/3.0 API/Resolver+Injection.swift delete mode 100644 Templates/InjectionVariation.swift create mode 100644 Templates/InstanceRequest+Api.swifttemplate create mode 100644 Templates/InstanceRequestVariation.swift delete mode 100644 Templates/Resolver+Injection.swifttemplate diff --git a/Sources/2.0 API/Container.swift b/Sources/2.0 API/Container.swift index b7ccc902..407e077f 100644 --- a/Sources/2.0 API/Container.swift +++ b/Sources/2.0 API/Container.swift @@ -140,10 +140,10 @@ extension Container: CustomStringConvertible { } } -// MARK: Swinject Aware +// MARK: Resolver -extension Container: SwinjectAware { - public var swinject: Resolver { +extension Container: Resolver { + private var swinject: Resolver { return Swinject( tree: SwinjectTree(bindings: [], modules: [], translators: []), container: SwinjectContainer(bindings: allBindings, translators: []), @@ -156,4 +156,16 @@ extension Container: SwinjectAware { ) ) } + + public func resolve(_ request: InstanceRequest) throws -> Type { + return try swinject.resolve(request) + } + + public func on(_ context: Context) -> Resolver { + return swinject.on(context) + } + + public func context(as contextType: Any.Type) throws -> Any { + return try swinject.context(as: contextType) + } } diff --git a/Sources/3.0 API/InstanceRequest+APi.swift b/Sources/3.0 API/InstanceRequest+APi.swift new file mode 100644 index 00000000..ae09c5a6 --- /dev/null +++ b/Sources/3.0 API/InstanceRequest+APi.swift @@ -0,0 +1,57 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +public extension InstanceRequest { + func from(_ resolver: Resolver) throws -> Type { + return try resolver.resolve(self) + } +} + +// swiftlint:disable line_length +// sourcery:inline:InstanceRequestApi +public func instance(of _: Type.Type = Type.self, tagged tag: String? = nil) -> InstanceRequest { + return request(type: Type.self, tag: tag, arg: ()) +} + +public func instance(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1) -> InstanceRequest { + return request(type: Type.self, tag: tag, arg: box(arg1)) +} + +public func instance(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1) -> InstanceRequest where Arg1: Hashable { + return request(type: Type.self, tag: tag, arg: box(arg1)) +} + +public func instance(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2) -> InstanceRequest { + return request(type: Type.self, tag: tag, arg: box(arg1, arg2)) +} + +public func instance(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2) -> InstanceRequest where Arg1: Hashable, Arg2: Hashable { + return request(type: Type.self, tag: tag, arg: box(arg1, arg2)) +} + +public func instance(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> InstanceRequest { + return request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3)) +} + +public func instance(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> InstanceRequest where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + return request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3)) +} + +public func instance(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> InstanceRequest { + return request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, arg4)) +} + +public func instance(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> InstanceRequest where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + return request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, arg4)) +} + +public func instance(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> InstanceRequest { + return request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, arg4, arg5)) +} + +public func instance(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> InstanceRequest where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + return request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, arg4, arg5)) +} + +// sourcery:end diff --git a/Sources/3.0 API/Resolver+FunctionCall.swift b/Sources/3.0 API/Resolver+FunctionCall.swift index 2ff328c4..000a4abf 100644 --- a/Sources/3.0 API/Resolver+FunctionCall.swift +++ b/Sources/3.0 API/Resolver+FunctionCall.swift @@ -6,83 +6,83 @@ // sourcery:inline:ResolverFunctionCallApi public extension Resolver { func call1(_ function: (P1) -> Output) throws -> Output { - return try function(instance()) + return try function(resolve(instance())) } func call(_ function: (P1, P2) -> Output) throws -> Output { - return try function(instance(), instance()) + return try function(resolve(instance()), resolve(instance())) } func call(_ function: (P1, P2, P3) -> Output) throws -> Output { - return try function(instance(), instance(), instance()) + return try function(resolve(instance()), resolve(instance()), resolve(instance())) } func call(_ function: (P1, P2, P3, P4) -> Output) throws -> Output { - return try function(instance(), instance(), instance(), instance()) + return try function(resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance())) } func call(_ function: (P1, P2, P3, P4, P5) -> Output) throws -> Output { - return try function(instance(), instance(), instance(), instance(), instance()) + return try function(resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance())) } func call(_ function: (P1, P2, P3, P4, P5, P6) -> Output) throws -> Output { - return try function(instance(), instance(), instance(), instance(), instance(), instance()) + return try function(resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance())) } func call(_ function: (P1, P2, P3, P4, P5, P6, P7) -> Output) throws -> Output { - return try function(instance(), instance(), instance(), instance(), instance(), instance(), instance()) + return try function(resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance())) } func call(_ function: (P1, P2, P3, P4, P5, P6, P7, P8) -> Output) throws -> Output { - return try function(instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance()) + return try function(resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance())) } func call(_ function: (P1, P2, P3, P4, P5, P6, P7, P8, P9) -> Output) throws -> Output { - return try function(instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance()) + return try function(resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance())) } func call(_ function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10) -> Output) throws -> Output { - return try function(instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance()) + return try function(resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance())) } func call(_ function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11) -> Output) throws -> Output { - return try function(instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance()) + return try function(resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance())) } func call(_ function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12) -> Output) throws -> Output { - return try function(instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance()) + return try function(resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance())) } func call(_ function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13) -> Output) throws -> Output { - return try function(instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance()) + return try function(resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance())) } func call(_ function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14) -> Output) throws -> Output { - return try function(instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance()) + return try function(resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance())) } func call(_ function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15) -> Output) throws -> Output { - return try function(instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance()) + return try function(resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance())) } func call(_ function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16) -> Output) throws -> Output { - return try function(instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance()) + return try function(resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance())) } func call(_ function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17) -> Output) throws -> Output { - return try function(instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance()) + return try function(resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance())) } func call(_ function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18) -> Output) throws -> Output { - return try function(instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance()) + return try function(resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance())) } func call(_ function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19) -> Output) throws -> Output { - return try function(instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance()) + return try function(resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance())) } func call(_ function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20) -> Output) throws -> Output { - return try function(instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance()) + return try function(resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance())) } } diff --git a/Sources/3.0 API/Resolver+Injection.swift b/Sources/3.0 API/Resolver+Injection.swift deleted file mode 100644 index 7cdeafc0..00000000 --- a/Sources/3.0 API/Resolver+Injection.swift +++ /dev/null @@ -1,221 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -// swiftlint:disable line_length -// sourcery:inline:ResolverInjectionApi -public extension Resolver { - func instance(of _: Type.Type = Type.self, tagged tag: String? = nil) throws -> Type { - return try resolve(request(type: Type.self, tag: tag, arg: ())) - } - - func instance(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1) throws -> Type { - return try resolve(request(type: Type.self, tag: tag, arg: box(arg1))) - } - - func instance(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1) throws -> Type where Arg1: Hashable { - return try resolve(request(type: Type.self, tag: tag, arg: box(arg1))) - } - - func instance(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2) throws -> Type { - return try resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2))) - } - - func instance(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2) throws -> Type where Arg1: Hashable, Arg2: Hashable { - return try resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2))) - } - - func instance(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) throws -> Type { - return try resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3))) - } - - func instance(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - return try resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3))) - } - - func instance(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) throws -> Type { - return try resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, arg4))) - } - - func instance(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return try resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, arg4))) - } - - func instance(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) throws -> Type { - return try resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, arg4, arg5))) - } - - func instance(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return try resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, arg4, arg5))) - } -} - -public extension Resolver { - func provider(of _: Type.Type = Type.self, tagged tag: String? = nil) -> () throws -> Type { - return { try self.resolve(request(type: Type.self, tag: tag, arg: ())) } - } - - func provider(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1) -> () throws -> Type { - return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1))) } - } - - func provider(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1) -> () throws -> Type where Arg1: Hashable { - return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1))) } - } - - func provider(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2) -> () throws -> Type { - return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2))) } - } - - func provider(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2) -> () throws -> Type where Arg1: Hashable, Arg2: Hashable { - return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2))) } - } - - func provider(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> () throws -> Type { - return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3))) } - } - - func provider(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> () throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3))) } - } - - func provider(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> () throws -> Type { - return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, arg4))) } - } - - func provider(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> () throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, arg4))) } - } - - func provider(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> () throws -> Type { - return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, arg4, arg5))) } - } - - func provider(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> () throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, arg4, arg5))) } - } -} - -public extension Resolver { - func factory(of _: Type.Type = Type.self, tagged tag: String? = nil) -> (Arg1) throws -> Type { - return { try self.resolve(request(type: Type.self, tag: tag, arg: box($0))) } - } - - func factory(of _: Type.Type = Type.self, tagged tag: String? = nil) -> (Arg1) throws -> Type where Arg1: Hashable { - return { try self.resolve(request(type: Type.self, tag: tag, arg: box($0))) } - } - - func factory(of _: Type.Type = Type.self, tagged tag: String? = nil) -> (Arg1, Arg2) throws -> Type { - return { try self.resolve(request(type: Type.self, tag: tag, arg: box($0, $1))) } - } - - func factory(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1) -> (Arg2) throws -> Type { - return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, $0))) } - } - - func factory(of _: Type.Type = Type.self, tagged tag: String? = nil) -> (Arg1, Arg2) throws -> Type where Arg1: Hashable, Arg2: Hashable { - return { try self.resolve(request(type: Type.self, tag: tag, arg: box($0, $1))) } - } - - func factory(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1) -> (Arg2) throws -> Type where Arg1: Hashable, Arg2: Hashable { - return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, $0))) } - } - - func factory(of _: Type.Type = Type.self, tagged tag: String? = nil) -> (Arg1, Arg2, Arg3) throws -> Type { - return { try self.resolve(request(type: Type.self, tag: tag, arg: box($0, $1, $2))) } - } - - func factory(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1) -> (Arg2, Arg3) throws -> Type { - return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, $0, $1))) } - } - - func factory(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3) throws -> Type { - return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, $0))) } - } - - func factory(of _: Type.Type = Type.self, tagged tag: String? = nil) -> (Arg1, Arg2, Arg3) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - return { try self.resolve(request(type: Type.self, tag: tag, arg: box($0, $1, $2))) } - } - - func factory(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1) -> (Arg2, Arg3) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, $0, $1))) } - } - - func factory(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, $0))) } - } - - func factory(of _: Type.Type = Type.self, tagged tag: String? = nil) -> (Arg1, Arg2, Arg3, Arg4) throws -> Type { - return { try self.resolve(request(type: Type.self, tag: tag, arg: box($0, $1, $2, $3))) } - } - - func factory(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1) -> (Arg2, Arg3, Arg4) throws -> Type { - return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, $0, $1, $2))) } - } - - func factory(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3, Arg4) throws -> Type { - return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, $0, $1))) } - } - - func factory(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> (Arg4) throws -> Type { - return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, $0))) } - } - - func factory(of _: Type.Type = Type.self, tagged tag: String? = nil) -> (Arg1, Arg2, Arg3, Arg4) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return { try self.resolve(request(type: Type.self, tag: tag, arg: box($0, $1, $2, $3))) } - } - - func factory(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1) -> (Arg2, Arg3, Arg4) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, $0, $1, $2))) } - } - - func factory(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3, Arg4) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, $0, $1))) } - } - - func factory(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> (Arg4) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, $0))) } - } - - func factory(of _: Type.Type = Type.self, tagged tag: String? = nil) -> (Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type { - return { try self.resolve(request(type: Type.self, tag: tag, arg: box($0, $1, $2, $3, $4))) } - } - - func factory(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1) -> (Arg2, Arg3, Arg4, Arg5) throws -> Type { - return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, $0, $1, $2, $3))) } - } - - func factory(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3, Arg4, Arg5) throws -> Type { - return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, $0, $1, $2))) } - } - - func factory(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> (Arg4, Arg5) throws -> Type { - return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, $0, $1))) } - } - - func factory(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> (Arg5) throws -> Type { - return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, arg4, $0))) } - } - - func factory(of _: Type.Type = Type.self, tagged tag: String? = nil) -> (Arg1, Arg2, Arg3, Arg4, Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return { try self.resolve(request(type: Type.self, tag: tag, arg: box($0, $1, $2, $3, $4))) } - } - - func factory(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1) -> (Arg2, Arg3, Arg4, Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, $0, $1, $2, $3))) } - } - - func factory(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2) -> (Arg3, Arg4, Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, $0, $1, $2))) } - } - - func factory(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> (Arg4, Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, $0, $1))) } - } - - func factory(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> (Arg5) throws -> Type where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return { try self.resolve(request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, arg4, $0))) } - } -} - -// sourcery:end diff --git a/Sources/Core/Resolver.swift b/Sources/Core/Resolver.swift index 10a943f1..d108f03c 100644 --- a/Sources/Core/Resolver.swift +++ b/Sources/Core/Resolver.swift @@ -8,24 +8,10 @@ public protocol Resolver { func context(as contextType: Any.Type) throws -> Any // TODO: Ideally this should be internal } -public protocol SwinjectAware: Resolver { +public protocol SwinjectAware { var swinject: Resolver { get } } -public extension SwinjectAware { - func resolve(_ request: InstanceRequest) throws -> Type { - return try swinject.resolve(request) - } - - func on(_ context: Context) -> Resolver { - return swinject.on(context) - } - - func context(as contextType: Any.Type) throws -> Any { - return try swinject.context(as: contextType) - } -} - public struct ContextedResolver: Resolver { let actual: Resolver diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index bfb7a4d3..1fa48dfc 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -135,7 +135,6 @@ 708D400457552769A54A406B /* OverrideSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86C18DDD83715886DF7F1818 /* OverrideSpec.swift */; }; 708E1C453CBC76ED26FA2FCB /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; 70BAF056528B2B33B3A65E9D /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A006CC804F9AB8ACC121029 /* Utils.swift */; }; - 71895EBC0803EEE3BFCD7001 /* Resolver+Injection.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 01DEC4D20CE554C9DFBD0A8D /* Resolver+Injection.swifttemplate */; }; 72217E47D83C3CA6D97640B9 /* StandardScopeRegistrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */; }; 725EF35B0CC5E62791D5EA09 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 34AFFAC41BA9D02A38BDB7A3 /* Nimble.framework */; }; 72F09FC92FFB0F7C32D8E2A5 /* OptionalsSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50D6F2639990DD5BAD9578B0 /* OptionalsSpec.swift */; }; @@ -144,6 +143,12 @@ 751F545653B0F1E30341C312 /* OverrideSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86C18DDD83715886DF7F1818 /* OverrideSpec.swift */; }; 75D74C8C25EDACF5A7A75A5C /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; 76FB9AFE299316E7F3F4C3BB /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57F4D977AC4289A6145383C9 /* InstanceRequest.swift */; }; + 77316670231176B20002655B /* InstanceRequest+APi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7731666F231176B20002655B /* InstanceRequest+APi.swift */; }; + 77316671231176B40002655B /* InstanceRequest+APi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7731666F231176B20002655B /* InstanceRequest+APi.swift */; }; + 77316672231176B50002655B /* InstanceRequest+APi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7731666F231176B20002655B /* InstanceRequest+APi.swift */; }; + 77316673231176B50002655B /* InstanceRequest+APi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7731666F231176B20002655B /* InstanceRequest+APi.swift */; }; + 77316675231177580002655B /* InstanceRequestVariation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77316674231177580002655B /* InstanceRequestVariation.swift */; }; + 773166772311787D0002655B /* InstanceRequest+Api.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 773166762311787D0002655B /* InstanceRequest+Api.swifttemplate */; }; 773BE491231124AD000AA1A9 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773C6DDB23111956007A40BF /* Binding.swift */; }; 773C6DDC23111956007A40BF /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773C6DDB23111956007A40BF /* Binding.swift */; }; 773C6DDD23111956007A40BF /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773C6DDB23111956007A40BF /* Binding.swift */; }; @@ -167,7 +172,6 @@ 789BF74652A2424EB8F7EF47 /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 7A7032384E07DAD308D4F70A /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 8B9785AAE94A5447FA307242 /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 7D6F664091C70BABBFB61D53 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; - 7E3C3E6FD07F3BD76024770A /* InjectionVariation.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C516EFA0CA22D19F07B27E /* InjectionVariation.swift */; }; 8016512839FE61EC3127E489 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */; }; 811BA1018E9BF86A7DEB728F /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */; }; 818DF17D671EA1022CE59A2A /* InjectionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 670DB253ECD5CE1468A7F2E3 /* InjectionSpec.swift */; }; @@ -178,7 +182,6 @@ 832C9ABB8DCF5340D796F5F8 /* ContextSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */; }; 83464EDC08380F5CE2190F30 /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; 8436D091ED844817C8CE3AF2 /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; - 848227742D4ABA298D340485 /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; 86CBC40FDC90E2A2051386C5 /* ContextSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */; }; 87FEAEF562B99522083CB87D /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; 890CCD2800597F6FB7C6FD31 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; @@ -265,7 +268,6 @@ C22853F014054A6DCDF0CB6A /* OverrideSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86C18DDD83715886DF7F1818 /* OverrideSpec.swift */; }; C38A2EBF4D1904E7D6989989 /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADA1541ABC1365DFD7E3377F /* Food.swift */; }; C637E97E193BB1DADDDC6C21 /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1E726A651C3AFE92C19608B /* SwinjectModule.swift */; }; - C6D60E2AEC381998223145B2 /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; C76374CAFE7C2BCCE52F1BB1 /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 351C4221896DDB8572BD6CB5 /* Person.swift */; }; C8462BEE06316286B9CA85AC /* SwinjectContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8C4916168E81D76536892122 /* SwinjectContainer.swift */; }; C950785B81C6DB22F41FA3CE /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; @@ -275,7 +277,6 @@ CB0B308F3D3A831A28127462 /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59A3946B59EB4D787CCE9F2 /* Container+Registration.swift */; }; CB9E8D16D7A0620A1F7A32A3 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; CBBE28990E0EA82AD8D5E3AF /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; - CBE63031F33303F3E503CEF2 /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; CDE8EA7EC1D8096F12BDD8C2 /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96AEC72A42A227A50CF9845B /* Circularity.swift */; }; CE5AFED22F04B96713ED76D7 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ADC44E9312C3B974AFD8F07B /* Nimble.framework */; }; CEE763218A90832454A6E2DE /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */; }; @@ -294,7 +295,6 @@ D69ED6990417ED1E921ACFCA /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; D7915D8FCF67D0FFCC41E9D6 /* PropertyWrappersSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49B24254B9F0E48ED3713565 /* PropertyWrappersSpec.swift */; }; D861595482464ED95CF81922 /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; - D9084C826F7A798508CD66F5 /* Resolver+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */; }; D941D81F59900A52805D6B4A /* OptionalsSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50D6F2639990DD5BAD9578B0 /* OptionalsSpec.swift */; }; D98BB7F59E98FC197D1C97A2 /* ServiceEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38615FC8EEB466C5C1EAD21C /* ServiceEntry.swift */; }; D9C5E21A1B6F43FA4C9DAD3C /* Quick.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 683A1FB7D7F4E9508D57E936 /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -451,7 +451,6 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 01DEC4D20CE554C9DFBD0A8D /* Resolver+Injection.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+Injection.swifttemplate"; sourceTree = ""; }; 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.swift; sourceTree = ""; }; 09FC792715B1658721F76885 /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 0CA449690AE00F6300DE8ACA /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -491,7 +490,6 @@ 50D6F2639990DD5BAD9578B0 /* OptionalsSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OptionalsSpec.swift; sourceTree = ""; }; 57A7E35B2B22650208F904B8 /* Weak.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Weak.swift; sourceTree = ""; }; 57F4D977AC4289A6145383C9 /* InstanceRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRequest.swift; sourceTree = ""; }; - 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Resolver+Injection.swift"; sourceTree = ""; }; 59111BE319C59E4CD6CF68CD /* Assembler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Assembler.swift; sourceTree = ""; }; 5AB605ED0F735221D0EB1D5F /* Convenience.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Convenience.swift; sourceTree = ""; }; 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Matchable.swift; sourceTree = ""; }; @@ -511,6 +509,9 @@ 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.CustomStringConvertible.swift; sourceTree = ""; }; 74DE57FB3E8228904E6FE0D7 /* Swinject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Swinject.h; sourceTree = ""; }; 75BE3AE3E30DFE42A919D825 /* ModulesSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModulesSpec.swift; sourceTree = ""; }; + 7731666F231176B20002655B /* InstanceRequest+APi.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "InstanceRequest+APi.swift"; sourceTree = ""; }; + 77316674231177580002655B /* InstanceRequestVariation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRequestVariation.swift; sourceTree = ""; }; + 773166762311787D0002655B /* InstanceRequest+Api.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "InstanceRequest+Api.swifttemplate"; sourceTree = ""; }; 773C6DDB23111956007A40BF /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; 77B87F3B23112DB100321C08 /* Binding+Api.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Binding+Api.swift"; sourceTree = ""; }; 77B87F3D231153D200321C08 /* FactoryVariation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FactoryVariation.swift; sourceTree = ""; }; @@ -544,7 +545,6 @@ BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "ServiceEntry+TypeForwarding.swifttemplate"; sourceTree = ""; }; BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Behavior.swift; sourceTree = ""; }; C1E726A651C3AFE92C19608B /* SwinjectModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectModule.swift; sourceTree = ""; }; - C3C516EFA0CA22D19F07B27E /* InjectionVariation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InjectionVariation.swift; sourceTree = ""; }; C765B92B00C0AC8625BB4AC9 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; CDA78290D6D60BD0B808571F /* Container+Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Logging.swift"; sourceTree = ""; }; CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; @@ -606,10 +606,10 @@ 77B87F3D231153D200321C08 /* FactoryVariation.swift */, 77B87F3F231155B300321C08 /* Binding+Factory.swifttemplate */, CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */, - C3C516EFA0CA22D19F07B27E /* InjectionVariation.swift */, + 77316674231177580002655B /* InstanceRequestVariation.swift */, + 773166762311787D0002655B /* InstanceRequest+Api.swifttemplate */, 808C1063CA90CC593C7E0E9C /* MatchableBoxes.swifttemplate */, 176824B29DD1A0DAA5CBD241 /* Resolver+FunctionCallApi.swifttemplate */, - 01DEC4D20CE554C9DFBD0A8D /* Resolver+Injection.swifttemplate */, FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */, BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */, 90191C25A2D66E07C4E9CD73 /* SwiftCode.swifttemplate */, @@ -659,10 +659,10 @@ 77B87F3B23112DB100321C08 /* Binding+Api.swift */, 77B87F41231157B200321C08 /* Binding+Factory.swift */, B9F626B9D3E547621787E4D7 /* Resolver+FunctionCall.swift */, - 583B00ADF411CA422E1BE6FA /* Resolver+Injection.swift */, 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */, 667B13B528642272FC0794B6 /* UnboundScope.swift */, 57A7E35B2B22650208F904B8 /* Weak.swift */, + 7731666F231176B20002655B /* InstanceRequest+APi.swift */, ); path = "3.0 API"; sourceTree = ""; @@ -1140,7 +1140,7 @@ BFE22F9F2E88F177302E9D19 /* Container+Registration.swifttemplate in Resources */, 1C82BFD00FCC384DB3AE6A89 /* MatchableBoxes.swifttemplate in Resources */, 3EC8383BEAC339595CF7F927 /* Resolver+FunctionCallApi.swifttemplate in Resources */, - 71895EBC0803EEE3BFCD7001 /* Resolver+Injection.swifttemplate in Resources */, + 773166772311787D0002655B /* InstanceRequest+Api.swifttemplate in Resources */, F568382FB877060127790413 /* Resolver+LegacyApi.swifttemplate in Resources */, 77B87F40231155B300321C08 /* Binding+Factory.swifttemplate in Resources */, B7653A6427A5E284E9A1D6D3 /* ServiceEntry+TypeForwarding.swifttemplate in Resources */, @@ -1395,6 +1395,7 @@ 19EBB651BD06BD0C03C1ACB5 /* Assembler.swift in Sources */, F504C2ABEFCFFCAC8B858751 /* Assembly.swift in Sources */, 703F8B3AD111A6CFAFF66A49 /* Behavior.swift in Sources */, + 77316673231176B50002655B /* InstanceRequest+APi.swift in Sources */, 658AEDC8D802A6788E959E0C /* AnyBinding.swift in Sources */, 694C2C891D581371B2B051D7 /* Container+Logging.swift in Sources */, 77ED80062311221600AC48F9 /* ValueRequest.swift in Sources */, @@ -1411,7 +1412,6 @@ 5393E5DE21B568A88498E454 /* PropertyWrapper.swift in Sources */, 3BD6055555A5C30DABDC8ED2 /* Reference.swift in Sources */, A9112F7CF871475B94A077D7 /* Resolver+FunctionCall.swift in Sources */, - D9084C826F7A798508CD66F5 /* Resolver+Injection.swift in Sources */, D4936DC1A47A8C85325FB52E /* Resolver+LegacyApi.swift in Sources */, 8016512839FE61EC3127E489 /* Resolver.swift in Sources */, 773C6DDD23111956007A40BF /* Binding.swift in Sources */, @@ -1436,7 +1436,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 7E3C3E6FD07F3BD76024770A /* InjectionVariation.swift in Sources */, + 77316675231177580002655B /* InstanceRequestVariation.swift in Sources */, 77B87F3E231153D200321C08 /* FactoryVariation.swift in Sources */, 70BAF056528B2B33B3A65E9D /* Utils.swift in Sources */, ); @@ -1613,6 +1613,7 @@ 5D5852F610358DFF7230C35C /* Assembler.swift in Sources */, 74E1FC692A27C56510363364 /* Assembly.swift in Sources */, FA805A162E989A22990B99AA /* Behavior.swift in Sources */, + 77316672231176B50002655B /* InstanceRequest+APi.swift in Sources */, F9A4BF18B0085B7DCD3440EC /* AnyBinding.swift in Sources */, 6A03ABEED82EF31E8E6E297E /* Container+Logging.swift in Sources */, A5E4C79F89E1A8AB3A4D8D6E /* Container+Registration.swift in Sources */, @@ -1630,7 +1631,6 @@ 6A967AE5710606998C2BE070 /* PropertyWrapper.swift in Sources */, B293894FEB67831DDA5F000E /* Reference.swift in Sources */, 8A4E9E736239F92F878C070C /* Resolver+FunctionCall.swift in Sources */, - 848227742D4ABA298D340485 /* Resolver+Injection.swift in Sources */, E177D354B1F410129D921C69 /* Resolver+LegacyApi.swift in Sources */, 5D7E26A00B055803A50CD9C2 /* Resolver.swift in Sources */, B84167AC8C6BEB57C4D0695A /* Scope.swift in Sources */, @@ -1657,6 +1657,7 @@ 290C9E9420A1EE30456476CB /* Assembler.swift in Sources */, 3099172980F9E9143C0A1C20 /* Assembly.swift in Sources */, 2CB057F2A16DA462E0517AAB /* Behavior.swift in Sources */, + 77316671231176B40002655B /* InstanceRequest+APi.swift in Sources */, D2BAE1CB997A4D052CB8EFC8 /* AnyBinding.swift in Sources */, 1ED6BD68D92F4FE60978EF22 /* Container+Logging.swift in Sources */, 77ED80082311221600AC48F9 /* ValueRequest.swift in Sources */, @@ -1673,7 +1674,6 @@ 5F1647DCC0D437A782647372 /* PropertyWrapper.swift in Sources */, 2D020C6391A4F6A2118585B8 /* Reference.swift in Sources */, 1AC00BCB4DB26B078203DAD8 /* Resolver+FunctionCall.swift in Sources */, - C6D60E2AEC381998223145B2 /* Resolver+Injection.swift in Sources */, FD7B2663F2F931B78EB330EE /* Resolver+LegacyApi.swift in Sources */, 97C2EA47D7623AFD723AFE93 /* Resolver.swift in Sources */, 773C6DDE23111956007A40BF /* Binding.swift in Sources */, @@ -1701,6 +1701,7 @@ DC5B169FD525CC1C01518312 /* Assembler.swift in Sources */, BB8FDF4F2A0AF8C1DA615854 /* Assembly.swift in Sources */, F7979BE4BE1B1C7101D15E61 /* Behavior.swift in Sources */, + 77316670231176B20002655B /* InstanceRequest+APi.swift in Sources */, 3F8F5645D6D37FCEC1D89393 /* AnyBinding.swift in Sources */, 999AF7221D3F2E1F83C3ACB1 /* Container+Logging.swift in Sources */, 77ED80052311221600AC48F9 /* ValueRequest.swift in Sources */, @@ -1716,7 +1717,6 @@ 14C8DA4FCCDFA87885038D38 /* PropertyWrapper.swift in Sources */, 0509EE8D41BF354EB91ACC80 /* Reference.swift in Sources */, 5A78C354D420D64CF8A787C1 /* Resolver+FunctionCall.swift in Sources */, - CBE63031F33303F3E503CEF2 /* Resolver+Injection.swift in Sources */, 41C7340BFD2EB66359772733 /* Resolver+LegacyApi.swift in Sources */, BE94EF7BCF976A703F961389 /* Resolver.swift in Sources */, 773C6DDC23111956007A40BF /* Binding.swift in Sources */, diff --git a/Templates/InjectionVariation.swift b/Templates/InjectionVariation.swift deleted file mode 100644 index cdc20622..00000000 --- a/Templates/InjectionVariation.swift +++ /dev/null @@ -1,108 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -struct InjectionVariation { - let paramArgs: Int - let factoryArgs: Int - let isMatchable: Bool - let isDelayed: Bool -} - -extension InjectionVariation { - var args: Int { return paramArgs + factoryArgs } - - var genericTypes: String { - return join( - "Type", - args > 0 ? join((1 ... args).map { "Arg\($0)" }) : nil - ) - } - - var params: String { - return join( - "of _: Type.Type = Type.self", - "tagged tag: String? = nil", - paramArgs >= 1 ? "arg " + join(separator: ", _ ", (1 ... paramArgs).map { "arg\($0): Arg\($0)" }) : nil - ) - } - - var factoryInputs: String { - return join((1 ..< factoryArgs + 1).map { "Arg\($0 + paramArgs)" }) - } - - var constraints: String { - return join( - isMatchable && args > 0 ? join((1 ... args).map { "Arg\($0): Hashable" }) : nil - ) - } - - var whereClause: String? { - return constraints.isEmpty ? nil : "where " + constraints - } - - var requestParams: String { - let paramVars = (0 ..< paramArgs).map { "arg\($0 + 1)" } - let factoryVars = (0 ..< factoryArgs).map { "$\($0)" } - return join( - "type: Type.self", - "tag: tag", - args == 0 ? "arg: ()" : "arg: box(\(join(paramVars + factoryVars)))" - ) - } - - var functionName: String { - if !isDelayed { return "instance" } - else if factoryArgs == 0 { return "provider" } - else { return "factory" } - } - - var returnType: String { - if !isDelayed { - return "throws -> Type" - } else { - return "-> (\(factoryInputs)) throws -> Type" - } - } - - var returnDescription: String { - return join(separator: " ", returnType, whereClause) - } - - var returnStatement: String { - if isDelayed { - return "return { try self.resolve(request(\(requestParams))) }" - } else { - return "return try resolve(request(\(requestParams)))" - } - } -} - -extension InjectionVariation { - static let maxArgs = 5 - - static let allCases = (0 ... maxArgs) - .flatMap { t in (t ... maxArgs).map { (t, maxArgs - $0) } } - .flatMap { t in [false, true].map { (t.0, t.1, $0) } } - .flatMap { t in [false, true].map { (t.0, t.1, t.2, $0) } } - .map(InjectionVariation.init) - - static let sortedCases = allCases.sorted { [ - $0.args < $1.args, - !$0.isMatchable && $1.isMatchable && $0.args == $1.args, - ].contains(true) } - - static let publicCases = sortedCases - .filter { !($0.args == 0 && !$0.isMatchable) } - .filter { !($0.factoryArgs > 0 && !$0.isDelayed) } -} - -extension InjectionVariation { - func render() -> String { - return """ - func \(functionName)<\(genericTypes)>(\(params)) \(returnDescription) { - \(returnStatement) - } - """ - } -} diff --git a/Templates/InstanceRequest+Api.swifttemplate b/Templates/InstanceRequest+Api.swifttemplate new file mode 100644 index 00000000..f27abfd8 --- /dev/null +++ b/Templates/InstanceRequest+Api.swifttemplate @@ -0,0 +1,4 @@ +<%- include("SwiftCode") %> +// sourcery:inline:InstanceRequestApi +<%= InstanceRequestVariation.publicCases.map { $0.render() }.joined(separator: "\n\n") %> +// sourcery:end diff --git a/Templates/InstanceRequestVariation.swift b/Templates/InstanceRequestVariation.swift new file mode 100644 index 00000000..2456e53a --- /dev/null +++ b/Templates/InstanceRequestVariation.swift @@ -0,0 +1,86 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +struct InstanceRequestVariation { + let args: Int + let isMatchable: Bool +} + +extension InstanceRequestVariation { + var genericTypes: String { + return join( + "Type", + args > 0 ? join((1 ... args).map { "Arg\($0)" }) : nil + ) + } + + var params: String { + return join( + "of _: Type.Type = Type.self", + "tagged tag: String? = nil", + args >= 1 ? "arg " + join(separator: ", _ ", (1 ... args).map { "arg\($0): Arg\($0)" }) : nil + ) + } + + var constraints: String { + return join( + isMatchable && args > 0 ? join((1 ... args).map { "Arg\($0): Hashable" }) : nil + ) + } + + var whereClause: String? { + return constraints.isEmpty ? nil : "where " + constraints + } + + var requestParams: String { + let argVars = join((0 ..< args).map { "arg\($0 + 1)" }) + return join( + "type: Type.self", + "tag: tag", + args == 0 ? "arg: ()" : "arg: box(\(argVars))" + ) + } + + var functionName: String { + return "instance" + } + + var returnType: String { + return "InstanceRequest" + } + + var returnDescription: String { + return join(separator: " ", "->", returnType, whereClause) + } + + var returnStatement: String { + return "return request(\(requestParams))" + } +} + +extension InstanceRequestVariation { + static let maxArgs = 5 + + static let allCases = (0 ... maxArgs) + .flatMap { t in [false, true].map { (t, $0) } } + .map(InstanceRequestVariation.init) + + static let sortedCases = allCases.sorted { [ + $0.args < $1.args, + !$0.isMatchable && $1.isMatchable && $0.args == $1.args, + ].contains(true) } + + static let publicCases = sortedCases + .filter { !($0.args == 0 && !$0.isMatchable) } +} + +extension InstanceRequestVariation { + func render() -> String { + return """ + public func \(functionName)<\(genericTypes)>(\(params)) \(returnDescription) { + \(returnStatement) + } + """ + } +} diff --git a/Templates/Resolver+FunctionCallApi.swifttemplate b/Templates/Resolver+FunctionCallApi.swifttemplate index f13c0042..f6fd7854 100644 --- a/Templates/Resolver+FunctionCallApi.swifttemplate +++ b/Templates/Resolver+FunctionCallApi.swifttemplate @@ -3,7 +3,7 @@ public extension Resolver { <%_ for n in 1 ... maxParams { let paramTypes = (1 ... n).map { "P\($0)" }.joined(separator: ", ") - let instances = (1 ... n).map { _ in "instance()" }.joined(separator: ", ") + let instances = (1 ... n).map { _ in "resolve(instance())" }.joined(separator: ", ") let methodName = n == 1 ? "call1" : "call" -%> func <%= methodName %>>(_ function: (<%= paramTypes %>) -> Output) throws -> Output { diff --git a/Templates/Resolver+Injection.swifttemplate b/Templates/Resolver+Injection.swifttemplate deleted file mode 100644 index e2dc0ad5..00000000 --- a/Templates/Resolver+Injection.swifttemplate +++ /dev/null @@ -1,14 +0,0 @@ -<%- include("SwiftCode") %> -// sourcery:inline:ResolverInjectionApi -public extension Resolver { -<%= InjectionVariation.publicCases.filter { $0.functionName == "instance" }.map { $0.render() }.joined(separator: "\n\n") %> -} - -public extension Resolver { -<%= InjectionVariation.publicCases.filter { $0.functionName == "provider" }.map { $0.render() }.joined(separator: "\n\n") %> -} - -public extension Resolver { -<%= InjectionVariation.publicCases.filter { $0.functionName == "factory" }.map { $0.render() }.joined(separator: "\n\n") %> -} -// sourcery:end diff --git a/Templates/SwiftCode.swifttemplate b/Templates/SwiftCode.swifttemplate index 15a2c6c6..1b8453b7 100644 --- a/Templates/SwiftCode.swifttemplate +++ b/Templates/SwiftCode.swifttemplate @@ -3,6 +3,92 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // +struct InstanceRequestVariation { + let args: Int + let isMatchable: Bool +} + +extension InstanceRequestVariation { + var genericTypes: String { + return join( + "Type", + args > 0 ? join((1 ... args).map { "Arg\($0)" }) : nil + ) + } + + var params: String { + return join( + "of _: Type.Type = Type.self", + "tagged tag: String? = nil", + args >= 1 ? "arg " + join(separator: ", _ ", (1 ... args).map { "arg\($0): Arg\($0)" }) : nil + ) + } + + var constraints: String { + return join( + isMatchable && args > 0 ? join((1 ... args).map { "Arg\($0): Hashable" }) : nil + ) + } + + var whereClause: String? { + return constraints.isEmpty ? nil : "where " + constraints + } + + var requestParams: String { + let argVars = join((0 ..< args).map { "arg\($0 + 1)" }) + return join( + "type: Type.self", + "tag: tag", + args == 0 ? "arg: ()" : "arg: box(\(argVars))" + ) + } + + var functionName: String { + return "instance" + } + + var returnType: String { + return "InstanceRequest" + } + + var returnDescription: String { + return join(separator: " ", "->", returnType, whereClause) + } + + var returnStatement: String { + return "return request(\(requestParams))" + } +} + +extension InstanceRequestVariation { + static let maxArgs = 5 + + static let allCases = (0 ... maxArgs) + .flatMap { t in [false, true].map { (t, $0) } } + .map(InstanceRequestVariation.init) + + static let sortedCases = allCases.sorted { [ + $0.args < $1.args, + !$0.isMatchable && $1.isMatchable && $0.args == $1.args, + ].contains(true) } + + static let publicCases = sortedCases + .filter { !($0.args == 0 && !$0.isMatchable) } +} + +extension InstanceRequestVariation { + func render() -> String { + return """ + public func \(functionName)<\(genericTypes)>(\(params)) \(returnDescription) { + \(returnStatement) + } + """ + } +} +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + struct FactoryVariation { let args: Int let hasResolver: Bool @@ -114,114 +200,6 @@ extension FactoryVariation { // Copyright © 2019 Swinject Contributors. All rights reserved. // -struct InjectionVariation { - let paramArgs: Int - let factoryArgs: Int - let isMatchable: Bool - let isDelayed: Bool -} - -extension InjectionVariation { - var args: Int { return paramArgs + factoryArgs } - - var genericTypes: String { - return join( - "Type", - args > 0 ? join((1 ... args).map { "Arg\($0)" }) : nil - ) - } - - var params: String { - return join( - "of _: Type.Type = Type.self", - "tagged tag: String? = nil", - paramArgs >= 1 ? "arg " + join(separator: ", _ ", (1 ... paramArgs).map { "arg\($0): Arg\($0)" }) : nil - ) - } - - var factoryInputs: String { - return join((1 ..< factoryArgs + 1).map { "Arg\($0 + paramArgs)" }) - } - - var constraints: String { - return join( - isMatchable && args > 0 ? join((1 ... args).map { "Arg\($0): Hashable" }) : nil - ) - } - - var whereClause: String? { - return constraints.isEmpty ? nil : "where " + constraints - } - - var requestParams: String { - let paramVars = (0 ..< paramArgs).map { "arg\($0 + 1)" } - let factoryVars = (0 ..< factoryArgs).map { "$\($0)" } - return join( - "type: Type.self", - "tag: tag", - args == 0 ? "arg: ()" : "arg: box(\(join(paramVars + factoryVars)))" - ) - } - - var functionName: String { - if !isDelayed { return "instance" } - else if factoryArgs == 0 { return "provider" } - else { return "factory" } - } - - var returnType: String { - if !isDelayed { - return "throws -> Type" - } else { - return "-> (\(factoryInputs)) throws -> Type" - } - } - - var returnDescription: String { - return join(separator: " ", returnType, whereClause) - } - - var returnStatement: String { - if isDelayed { - return "return { try self.resolve(request(\(requestParams))) }" - } else { - return "return try resolve(request(\(requestParams)))" - } - } -} - -extension InjectionVariation { - static let maxArgs = 5 - - static let allCases = (0 ... maxArgs) - .flatMap { t in (t ... maxArgs).map { (t, maxArgs - $0) } } - .flatMap { t in [false, true].map { (t.0, t.1, $0) } } - .flatMap { t in [false, true].map { (t.0, t.1, t.2, $0) } } - .map(InjectionVariation.init) - - static let sortedCases = allCases.sorted { [ - $0.args < $1.args, - !$0.isMatchable && $1.isMatchable && $0.args == $1.args, - ].contains(true) } - - static let publicCases = sortedCases - .filter { !($0.args == 0 && !$0.isMatchable) } - .filter { !($0.factoryArgs > 0 && !$0.isDelayed) } -} - -extension InjectionVariation { - func render() -> String { - return """ - func \(functionName)<\(genericTypes)>(\(params)) \(returnDescription) { - \(returnStatement) - } - """ - } -} -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - func join(separator: String = ", ", _ strings: String? ...) -> String { return join(separator: separator, strings) } diff --git a/Tests/3.0 API/BindingSpec.swift b/Tests/3.0 API/BindingSpec.swift index eda7ff9e..8f9f2a6d 100644 --- a/Tests/3.0 API/BindingSpec.swift +++ b/Tests/3.0 API/BindingSpec.swift @@ -12,29 +12,29 @@ class BindingSpec: QuickSpec { override func spec() { #if swift(>=5.1) register().constant(42) register().constant(42 as Double) } - expect { try swinject.instance() as Int } == 42 - expect { try swinject.instance() as Double } == 42 + expect { try instance().from(swinject) as Int } == 42 + expect { try instance().from(swinject) as Double } == 42 } it("can bind the same type with different tags") { let swinject = Swinject { register().constant("Plain") register().constant("Tagged", tag: "Tag") } - expect { try swinject.instance(of: String.self) } == "Plain" - expect { try swinject.instance(of: String.self, tagged: "Tag") } == "Tagged" + expect { try instance(of: String.self).from(swinject) } == "Plain" + expect { try instance(of: String.self, tagged: "Tag").from(swinject) } == "Tagged" } it("throws if has no binding with given tag") { let swinject = Swinject { register().constant("Plain") register().constant("Tagged", tag: "Tag") } - expect { try swinject.instance(of: String.self, tagged: "WrongTag") }.to(throwError()) + expect { try instance(of: String.self, tagged: "WrongTag").from(swinject) }.to(throwError()) } it("can bind a protocol to it's implementation") { let swinject = Swinject { register().factory(for: Mammal.self) { Human() } } - expect(try? swinject.instance(of: Mammal.self) is Human) == true + expect(try? instance(of: Mammal.self).from(swinject) is Human) == true } it("can bind an implementation to multiple types") { let swinject = Swinject { @@ -42,9 +42,9 @@ class BindingSpec: QuickSpec { override func spec() { #if swift(>=5.1) .alsoUse { $0 as Mammal } .alsoUse({ $0 as AnyObject }, tag: "human") } - expect { try swinject.instance(of: Human.self) }.notTo(throwError()) - expect { try swinject.instance(of: Mammal.self) }.notTo(throwError()) - expect { try swinject.instance(of: AnyObject.self, tagged: "human") }.notTo(throwError()) + expect { try instance(of: Human.self).from(swinject) }.notTo(throwError()) + expect { try instance(of: Mammal.self).from(swinject) }.notTo(throwError()) + expect { try instance(of: AnyObject.self, tagged: "human").from(swinject) }.notTo(throwError()) } it("can use up to 5 arguments in factory binding") { let swinject = Swinject { @@ -54,18 +54,17 @@ class BindingSpec: QuickSpec { override func spec() { #if swift(>=5.1) register().factory { (_, a1: Int, a2: Int, a3: Int, a4: Int) in a1 + a2 + a3 + a4 } register().factory { (_, a1: Int, a2: Int, a3: Int, a4: Int, a5: Int) in a1 + a2 + a3 + a4 + a5 } } - expect { try swinject.instance(of: Int.self, arg: 1) } == 1 - expect { try swinject.instance(of: Int.self, arg: 1, 2) } == 3 - expect { try swinject.instance(of: Int.self, arg: 1, 2, 3) } == 6 - expect { try swinject.instance(of: Int.self, arg: 1, 2, 3, 4) } == 10 - expect { try swinject.instance(of: Int.self, arg: 1, 2, 3, 4, 5) } == 15 + expect { try instance(of: Int.self, arg: 1).from(swinject) } == 1 + expect { try instance(of: Int.self, arg: 1, 2).from(swinject) } == 3 + expect { try instance(of: Int.self, arg: 1, 2, 3).from(swinject) } == 6 + expect { try instance(of: Int.self, arg: 1, 2, 3, 4).from(swinject) } == 10 + expect { try instance(of: Int.self, arg: 1, 2, 3, 4, 5).from(swinject) } == 15 } it("does not invoke binding until instance is required") { var invoked = false - let swinject = Swinject { + _ = Swinject { register().factory(for: Int.self) { invoked = true; return 42 } } - _ = swinject.provider(of: Int.self) expect(invoked) == false } it("does not invoke unnecessary bindings") { @@ -74,7 +73,7 @@ class BindingSpec: QuickSpec { override func spec() { #if swift(>=5.1) register().factory(for: Int.self) { invoked = true; return 42 } register().constant(42, tag: "tag") } - _ = try? swinject.instance(of: Int.self, tagged: "tag") + _ = try? instance(of: Int.self, tagged: "tag").from(swinject) expect(invoked) == false } #endif diff --git a/Tests/3.0 API/CIrcularitySpec.swift b/Tests/3.0 API/CIrcularitySpec.swift index 57adf234..ddee9c59 100644 --- a/Tests/3.0 API/CIrcularitySpec.swift +++ b/Tests/3.0 API/CIrcularitySpec.swift @@ -14,26 +14,26 @@ class CircularitySpec: QuickSpec { override func spec() { #if swift(>=5.1) class Foo { init(_: Bar) {} } class Bar { init(_: Foo) {} } let swinject = Swinject { - register().factory { Foo(try $0.instance()) } - register().factory { Bar(try $0.instance()) } + register().factory { Foo(try instance().from($0)) } + register().factory { Bar(try instance().from($0)) } } - expect { try swinject.instance(of: Foo.self) }.to(throwError()) + expect { try instance(of: Foo.self).from(swinject) }.to(throwError()) } it("does not produce false circularity detections") { let swinject = Swinject { register().constant(21) - register().factory(for: Int.self, tag: "computed") { try $0.instance() + $0.instance() } + register().factory(for: Int.self, tag: "computed") { try instance().from($0) + instance().from($0) } } - expect { try swinject.instance(of: Int.self, tagged: "computed") } == 42 + expect { try instance(of: Int.self, tagged: "computed").from(swinject) } == 42 } it("can break circularity using Lazy wrapper") { class Foo { init(_: Bar) {} } class Bar { init(_: Lazy) {} } let swinject = Swinject { - register().factory { Foo(try $0.instance()) } - register().factory { Bar(try $0.instance()) } + register().factory { Foo(try instance().from($0)) } + register().factory { Bar(try instance().from($0)) } } - expect { try swinject.instance(of: Foo.self) }.notTo(throwError()) + expect { try instance(of: Foo.self).from(swinject) }.notTo(throwError()) } it("correctly injects dependencies if root is weak singleton") { class Foo { @@ -45,12 +45,12 @@ class CircularitySpec: QuickSpec { override func spec() { #if swift(>=5.1) init(_ foo: Lazy) { _foo = foo } } let swinject = Swinject { - register().factory { Bar(try $0.instance()) } + register().factory { Bar(try instance().from($0)) } registerSingle() - .factory { Foo(try $0.instance()) } + .factory { Foo(try instance().from($0)) } .withProperties { $0.reference = weakRef } } - let foo = try? swinject.instance(of: Foo.self) + let foo = try? instance(of: Foo.self).from(swinject) expect { foo?.bar.foo } === foo } it("correctly injects dependencies if using Lazy Weak wrapper") { @@ -63,12 +63,12 @@ class CircularitySpec: QuickSpec { override func spec() { #if swift(>=5.1) init(_ foo: Lazy>) { _foo = foo } } let swinject = Swinject { - register().factory { Bar(try $0.instance()) } + register().factory { Bar(try instance().from($0)) } registerSingle() - .factory { Foo(try $0.instance()) } + .factory { Foo(try instance().from($0)) } .withProperties { $0.reference = weakRef } } - let foo = try? swinject.instance(of: Foo.self) + let foo = try? instance(of: Foo.self).from(swinject) expect { foo?.bar.foo } === foo } it("can avoid reference cycles if using Lazy Weak wrapper and weak singleton") { @@ -81,12 +81,12 @@ class CircularitySpec: QuickSpec { override func spec() { #if swift(>=5.1) init(_ foo: Lazy>) { _foo = foo } } let swinject = Swinject { - register().factory { Bar(try $0.instance()) } + register().factory { Bar(try instance().from($0)) } registerSingle() - .factory { Foo(try $0.instance()) } + .factory { Foo(try instance().from($0)) } .withProperties { $0.reference = weakRef } } - var foo = try? swinject.instance(of: Foo.self) + var foo = try? instance(of: Foo.self).from(swinject) let bar = foo?.bar foo = nil diff --git a/Tests/3.0 API/ContextSpec.swift b/Tests/3.0 API/ContextSpec.swift index ed1b584a..49cc09f8 100644 --- a/Tests/3.0 API/ContextSpec.swift +++ b/Tests/3.0 API/ContextSpec.swift @@ -13,14 +13,14 @@ class ContextSpec: QuickSpec { override func spec() { #if swift(>=5.1) register(inContextOf: String.self).factory { try Int($0.context())! } register(inContextOf: String.self).factory { try Double($0.context())! + Double($1 as Int) } } - expect { try swinject.on("42").instance(of: Int.self) } == 42 - expect { try swinject.on("25").instance(of: Double.self, arg: 17) } == 42 + expect { try instance(of: Int.self).from(swinject.on("42")) } == 42 + expect { try instance(of: Double.self, arg: 17).from(swinject.on("25")) } == 42 } it("throws if injecting on the wrong context") { let swinject = Swinject { register(inContextOf: Double.self).factory { try Int($0.context()) } } - expect { try swinject.on("context").instance(of: Int.self) }.to(throwError()) + expect { try instance(of: Int.self).from(swinject.on("context")) }.to(throwError()) } it("does not invoke bindings on other contexts") { var invoked = false @@ -31,23 +31,23 @@ class ContextSpec: QuickSpec { override func spec() { #if swift(>=5.1) return 42 } } - _ = try? swinject.on("context").instance(of: Int.self) + _ = try? instance(of: Int.self).from(swinject.on("context")) expect(invoked) == false } it("can use binding without context in any context") { let swinject = Swinject { register().constant(42) } - expect { try swinject.on("context").instance() as Int } == 42 - expect { try swinject.on(Human()).instance() as Int } == 42 + expect { try instance().from(swinject.on("context")) as Int } == 42 + expect { try instance().from(swinject.on(Human())) as Int } == 42 } it("passes context to the dependencies") { let john = Human() let swinject = Swinject { register(inContextOf: String.self).factory { try $0.context() == "john" ? john : Human() } - register().factory { Pet(owner: try $0.instance()) } + register().factory { Pet(owner: try instance().from($0)) } } - let pet = try? swinject.on("john").instance(of: Pet.self) + let pet = try? instance(of: Pet.self).from(swinject.on("john")) expect(pet?.owner) === john } describe("translators") { @@ -57,7 +57,7 @@ class ContextSpec: QuickSpec { override func spec() { #if swift(>=5.1) register(inContextOf: Human.self).factory { try Pet(owner: $0.context()) } registerContextTranslator(from: String.self) { $0 == "john" ? john : Human() } } - let pet = try? swinject.on("john").instance(of: Pet.self) + let pet = try? instance(of: Pet.self).from(swinject.on("john")) expect(pet?.owner) === john } it("throws if translator has incorrect types") { @@ -66,7 +66,7 @@ class ContextSpec: QuickSpec { override func spec() { #if swift(>=5.1) registerContextTranslator(from: Float.self) { String($0) } registerContextTranslator(from: Double.self) { Int($0) } } - expect { try swinject.on(42.0).instance(of: Int.self) }.to(throwError()) + expect { try instance(of: Int.self).from(swinject.on(42)) }.to(throwError()) } it("throws if multiple bindings could be used with translated contexts") { let swinject = Swinject { @@ -75,7 +75,7 @@ class ContextSpec: QuickSpec { override func spec() { #if swift(>=5.1) registerContextTranslator(from: String.self) { Float($0)! } registerContextTranslator(from: String.self) { Double($0)! } } - expect { try swinject.on("42").instance(of: Int.self) }.to(throwError()) + expect { try instance(of: Int.self).from(swinject.on("42")) }.to(throwError()) } it("throws if has binding on given context and translator leading to other binding") { let swinject = Swinject { @@ -83,7 +83,7 @@ class ContextSpec: QuickSpec { override func spec() { #if swift(>=5.1) register(inContextOf: Double.self).factory { try Int($0.context()) } registerContextTranslator(from: String.self) { Double($0)! } } - expect { try swinject.on("42").instance(of: Int.self) }.to(throwError()) + expect { try instance(of: Int.self).from(swinject.on("42")) }.to(throwError()) } it("does not throw if multiple translators lead to the same binding") { let swinject = Swinject { @@ -91,7 +91,7 @@ class ContextSpec: QuickSpec { override func spec() { #if swift(>=5.1) registerContextTranslator(from: Double.self) { "\($0)" } registerContextTranslator(from: Double.self) { Float($0) } } - expect { try swinject.on(42.0).instance(of: Int.self) }.notTo(throwError()) + expect { try instance(of: Int.self).from(swinject.on(42)) }.notTo(throwError()) } } #endif diff --git a/Tests/3.0 API/InjectionSpec.swift b/Tests/3.0 API/InjectionSpec.swift index 9631b4a6..a2b9d3e0 100644 --- a/Tests/3.0 API/InjectionSpec.swift +++ b/Tests/3.0 API/InjectionSpec.swift @@ -10,101 +10,27 @@ class InjectionSpec: QuickSpec { override func spec() { #if swift(>=5.1) describe("instance") { it("throws if bound type has missing dependency") { let swinject = Swinject { - register().factory { Pet(owner: try $0.instance()) } + register().factory { Pet(owner: try instance().from($0)) } } - expect { try swinject.instance(of: Pet.self) }.to(throwError()) + expect { try instance(of: Pet.self).from(swinject) }.to(throwError()) } it("injects instance if all dependencies are bound") { let john = Human() let swinject = Swinject { - register().factory { Pet(owner: try $0.instance()) } + register().factory { Pet(owner: try instance().from($0)) } register().constant(john) } - expect { try swinject.instance(of: Pet.self).owner } === john + expect { try instance(of: Pet.self).from(swinject).owner } === john } it("throws if type's binding requires different arguments") { let swinject = Swinject { register().factory { (_, string: String) in Int(string)! } } - expect { try swinject.instance() as Int }.to(throwError()) - expect { try swinject.instance(arg: 42.0) as Int }.to(throwError()) - } - } - describe("provider") { - it("can inject instance provider") { - let swinject = Swinject { - register().constant(42) - } - let intProvider = swinject.provider(of: Int.self) - expect { try intProvider() } == 42 - } - it("throws if provided type is not bound") { - let swinject = Swinject {} - let intProvider = swinject.provider(of: Int.self) - expect { try intProvider() }.to(throwError()) - } - it("throws if provided type has missing dependency") { - let swinject = Swinject { - register().factory { Pet(owner: try $0.instance()) } - } - let petProvider = swinject.provider(of: Pet.self) - expect { try petProvider() }.to(throwError()) - } - it("throws if provided type's binding requires different arguments") { - let swinject = Swinject { - register().factory { (_, string: String) in Int(string)! } - } - expect { try swinject.provider(of: Int.self)() }.to(throwError()) - expect { try swinject.provider(of: Int.self, arg: 42.0)() }.to(throwError()) - } - } - describe("factory") { - it("can inject instance factory") { - let john = Human() - let swinject = Swinject { - register().factory { try Pet(name: $1, owner: $0.instance()) } - register().constant(john) - } - - let petFactory = swinject.factory() as (String) throws -> Pet - let pet = try? petFactory("mimi") - - expect(pet?.owner) === john - expect(pet?.name) == "mimi" - } - it("throws if created type is not bound") { - let swinject = Swinject {} - let petFactory = swinject.factory() as (String) throws -> Pet - expect { try petFactory("mimi") }.to(throwError()) - } - it("throws if created type has missing dependency") { - let swinject = Swinject { - register().factory { try Pet(name: $1, owner: $0.instance()) } - } - let petFactory = swinject.factory() as (String) throws -> Pet - expect { try petFactory("mimi") }.to(throwError()) - } - it("throws if created type's binding requires different arguments") { - let swinject = Swinject { - register().factory { try Pet(name: $1, owner: $0.instance()) } - register().factory { Human() } - } - let petFactory = swinject.factory() as (Int) throws -> Pet - expect { try petFactory(42) }.to(throwError()) - } - it("can curry factory arguments") { - let swinject = Swinject { - register().factory { - Int($1 as Int) + Int($2 as Double) + Int($3 as String)! - } - } - expect { try swinject.factory()(11, 14.0, "17") as Int } == 42 - expect { try swinject.factory(arg: 11)(14.0, "17") as Int } == 42 - expect { try swinject.factory(arg: 11, 14.0)("17") as Int } == 42 - expect { try swinject.provider(arg: 11, 14.0, "17")() as Int } == 42 - expect { try swinject.instance(arg: 11, 14.0, "17") as Int } == 42 + expect { try instance().from(swinject) as Int }.to(throwError()) + expect { try instance(arg: 42.0).from(swinject) as Int }.to(throwError()) } } + // TODO: Refactor describe("function call") { it("can inject parameter to the function") { func echo(int: Int) -> Int { @@ -133,7 +59,7 @@ class InjectionSpec: QuickSpec { override func spec() { #if swift(>=5.1) register().constant(john) register().factory { try $0.call(Pet.init) } } - let pet = try? swinject.instance(of: Pet.self) + let pet = try? instance(of: Pet.self).from(swinject) expect(pet?.name) == "mimi" expect(pet?.owner) === john } diff --git a/Tests/3.0 API/ModulesSpec.swift b/Tests/3.0 API/ModulesSpec.swift index 555788f7..34a8c314 100644 --- a/Tests/3.0 API/ModulesSpec.swift +++ b/Tests/3.0 API/ModulesSpec.swift @@ -18,8 +18,8 @@ class ModulesSpec: QuickSpec { override func spec() { #if swift(>=5.1) include(intModule) include(doubleModule) } - expect { try swinject.instance() as Int } == 42 - expect { try swinject.instance() as Double } == 42.0 + expect { try instance().from(swinject) as Int } == 42 + expect { try instance().from(swinject) as Double } == 42.0 } it("can handle module hierarchies") { let intModule = Swinject.Module("Int") { @@ -32,8 +32,8 @@ class ModulesSpec: QuickSpec { override func spec() { #if swift(>=5.1) let swinject = Swinject { include(numbersModule) } - expect { try swinject.instance() as Int } == 42 - expect { try swinject.instance() as Double } == 42.0 + expect { try instance().from(swinject) as Int } == 42 + expect { try instance().from(swinject) as Double } == 42.0 } it("does not allow modules with the same name") { let firstModule = Swinject.Module("name") diff --git a/Tests/3.0 API/OptionalsSpec.swift b/Tests/3.0 API/OptionalsSpec.swift index 542227aa..53d80637 100644 --- a/Tests/3.0 API/OptionalsSpec.swift +++ b/Tests/3.0 API/OptionalsSpec.swift @@ -11,49 +11,49 @@ class OptionalsSpec: QuickSpec { override func spec() { #if swift(>=5.1) let swinject = Swinject { register().constant(42) } - expect { try swinject.instance() as Int? } == 42 + expect { try instance().from(swinject) as Int? } == 42 } it("can use a binding of the injected type's optional") { let swinject = Swinject { register().constant(42 as Int?) } - expect { try swinject.instance() as Int } == 42 + expect { try instance().from(swinject) as Int } == 42 } it("throws if binding of the type's optional produces nil") { let swinject = Swinject { register().constant(nil as Int?) } - expect { try swinject.instance() as Int }.to(throwError()) + expect { try instance().from(swinject) as Int }.to(throwError()) } it("can use a binding for bound type's double optional") { let swinject = Swinject { register().constant(42) } - expect { try swinject.instance() as Int?? } == 42 + expect { try instance().from(swinject) as Int?? } == 42 } it("does not throw if injecting optional for an unbound type") { let swinject = Swinject {} - expect { try swinject.instance() as Int? }.notTo(throwError()) + expect { try instance().from(swinject) as Int? }.notTo(throwError()) } it("throws if has an incomplete binding for the optional") { let swinject = Swinject { - register().factory { Int(try $0.instance() as Double) } + register().factory { Int(try instance().from($0) as Double) } } - expect { try swinject.instance() as Int? }.to(throwError()) + expect { try instance().from(swinject) as Int? }.to(throwError()) } it("injects same singleton instance for type and it's optional") { let swinject = Swinject { registerSingle().factory { Human() } } - let direct = try? swinject.instance(of: Human.self) - let optional = try? swinject.instance(of: Human?.self) + let direct = try? instance(of: Human.self).from(swinject) + let optional = try? instance(of: Human?.self).from(swinject) expect(direct) === optional } it("injects instance on the optional of a binding's context") { let swinject = Swinject { register(inContextOf: String.self).factory { try Int($0.context())! } } - expect { try swinject.on("42" as String?).instance(of: Int.self) } == 42 + expect { try instance(of: Int.self).from(swinject.on("42" as String?)) } == 42 } #endif } } diff --git a/Tests/3.0 API/OverrideSpec.swift b/Tests/3.0 API/OverrideSpec.swift index e1bcc4fc..9b43769d 100644 --- a/Tests/3.0 API/OverrideSpec.swift +++ b/Tests/3.0 API/OverrideSpec.swift @@ -39,7 +39,7 @@ class OverrideSpec: QuickSpec { override func spec() { #if swift(>=5.1) register().constant(0) register().constant(42).withProperties { $0.overrides = true } } - expect { try swinject.instance(of: Int.self) } == 42 + expect { try instance(of: Int.self).from(swinject) } == 42 } it("uses the last overriding binding for the injection") { let swinject = Swinject { @@ -47,7 +47,7 @@ class OverrideSpec: QuickSpec { override func spec() { #if swift(>=5.1) register().constant(2).withProperties { $0.overrides = true } register().constant(3).withProperties { $0.overrides = true } } - expect { try swinject.instance(of: Int.self) } == 3 + expect { try instance(of: Int.self).from(swinject) } == 3 } it("must declare overriding binding after the overriden one") { expect { @@ -89,7 +89,7 @@ class OverrideSpec: QuickSpec { override func spec() { #if swift(>=5.1) include(firstModule) include(secondModule, allowToOverride: true) } - expect { try swinject.instance(of: Int.self) } == 42 + expect { try instance(of: Int.self).from(swinject) } == 42 } it("allows overriding bindings in the entire included module tree") { let firstModule = Swinject.Module("first") { @@ -105,7 +105,7 @@ class OverrideSpec: QuickSpec { override func spec() { #if swift(>=5.1) include(firstModule) include(thirdModule, allowToOverride: true) } - expect { try swinject.instance(of: Int.self) } == 42 + expect { try instance(of: Int.self).from(swinject) } == 42 } it("can allow silent overrides in a module") { let firstModule = Swinject.Module("first") { @@ -118,7 +118,7 @@ class OverrideSpec: QuickSpec { override func spec() { #if swift(>=5.1) include(firstModule) include(secondModule) } - expect { try swinject.instance(of: Int.self) } == 42 + expect { try instance(of: Int.self).from(swinject) } == 42 } it("does not apply silent override transitively") { let firstModule = Swinject.Module("first") { @@ -142,7 +142,7 @@ class OverrideSpec: QuickSpec { override func spec() { #if swift(>=5.1) register().constant(0) register().constant(42) } - expect { try swinject.instance(of: Int.self) } == 42 + expect { try instance(of: Int.self).from(swinject) } == 42 } #endif } } diff --git a/Tests/3.0 API/PropertyWrappersSpec.swift b/Tests/3.0 API/PropertyWrappersSpec.swift index c40e209c..90143069 100644 --- a/Tests/3.0 API/PropertyWrappersSpec.swift +++ b/Tests/3.0 API/PropertyWrappersSpec.swift @@ -19,44 +19,44 @@ class PropertyWrappersSpec: QuickSpec { override func spec() { #if swift(>=5.1) let swinject = Swinject { register().constant(42) } - let wrappedInt = try? swinject.instance() as Wrapped + let wrappedInt = try? instance().from(swinject) as Wrapped expect { wrappedInt?.wrappedValue } == 42 } it("throws if provided type is not bound") { let swinject = Swinject {} - expect { try swinject.instance() as Wrapped }.to(throwError()) + expect { try instance().from(swinject) as Wrapped }.to(throwError()) } it("throws if provided type is bound with different arguments") { let swinject = Swinject { register().constant(42) } - expect { try swinject.instance(arg: "arg") as Wrapped }.to(throwError()) + expect { try instance(arg: "arg").from(swinject) as Wrapped }.to(throwError()) } it("can inject lazy provider of bound type with arguments") { let swinject = Swinject { register().factory { Int($1 as String)! } } - let wrappedInt = try? swinject.instance(arg: "42") as Wrapped + let wrappedInt = try? instance(arg: "42").from(swinject) as Wrapped expect { wrappedInt?.wrappedValue } == 42 } it("throws if provided type is bound with different tag") { let swinject = Swinject { register().constant(42) } - expect { try swinject.instance(tagged: "tag") as Wrapped }.to(throwError()) + expect { try instance(tagged: "tag").from(swinject) as Wrapped }.to(throwError()) } it("can inject lazy provider of tagged bound type") { let swinject = Swinject { register().constant(42, tag: "tag") } - let wrappedInt = try? swinject.instance(tagged: "tag") as Wrapped + let wrappedInt = try? instance(tagged: "tag").from(swinject) as Wrapped expect { wrappedInt?.wrappedValue } == 42 } it("can inject nested property wrappers") { let swinject = Swinject { register().constant(42) } - let doubleWrappedInt = try? swinject.instance() as Wrapped> + let doubleWrappedInt = try? instance().from(swinject) as Wrapped> expect { doubleWrappedInt?.wrappedValue.wrappedValue } == 42 } it("can inject attributed properties") { @@ -65,9 +65,9 @@ class PropertyWrappersSpec: QuickSpec { override func spec() { #if swift(>=5.1) } let swinject = Swinject { register().constant(42) - register().factory { try IntHolder(int: $0.instance()) } + register().factory { try IntHolder(int: instance().from($0)) } } - expect { try swinject.instance(of: IntHolder.self).int } == 42 + expect { try instance(of: IntHolder.self).from(swinject).int } == 42 } } #endif diff --git a/Tests/3.0 API/RetrievalSpec.swift b/Tests/3.0 API/RetrievalSpec.swift index a0dfd72a..b0095c1a 100644 --- a/Tests/3.0 API/RetrievalSpec.swift +++ b/Tests/3.0 API/RetrievalSpec.swift @@ -8,16 +8,17 @@ import Swinject // swiftlint:disable force_try class RetrievalSpec: QuickSpec { override func spec() { #if swift(>=5.1) + // TODO: Better support it("can retrieve bound types") { struct IntHolder: SwinjectAware { let swinject: Resolver - lazy var int: Int = try! instance() + lazy var int: Int = try! instance().from(swinject) } let swinject = Swinject { register().factory { IntHolder(swinject: $0) } register().constant(42) } - var holder = try? swinject.instance() as IntHolder + var holder = try? instance().from(swinject) as IntHolder expect(holder?.int) == 42 } #endif diff --git a/Tests/3.0 API/ScopesSpec.swift b/Tests/3.0 API/ScopesSpec.swift index 014df3d2..26ccab19 100644 --- a/Tests/3.0 API/ScopesSpec.swift +++ b/Tests/3.0 API/ScopesSpec.swift @@ -12,8 +12,8 @@ class ScopesSpec: QuickSpec { override func spec() { #if swift(>=5.1) let swinject = Swinject { registerSingle(in: scope).factory { Human() } } - let first = try? swinject.instance(of: Human.self) - let second = try? swinject.instance(of: Human.self) + let first = try? instance(of: Human.self).from(swinject) + let second = try? instance(of: Human.self).from(swinject) expect(first) === second } it("can bind singleton on a scope with context") { @@ -22,8 +22,8 @@ class ScopesSpec: QuickSpec { override func spec() { #if swift(>=5.1) let swinject = Swinject { registerSingle(in: scope).factory { Human() } } - let first = try? swinject.on(session).instance(of: Human.self) - let second = try? swinject.on(session).instance(of: Human.self) + let first = try? instance(of: Human.self).from(swinject.on(session)) + let second = try? instance(of: Human.self).from(swinject.on(session)) expect(first) === second } it("throws if injecting scoped singleton without context") { @@ -31,15 +31,15 @@ class ScopesSpec: QuickSpec { override func spec() { #if swift(>=5.1) let swinject = Swinject { registerSingle(in: scope).factory { Human() } } - expect { try swinject.instance(of: Human.self) }.to(throwError()) + expect { try instance(of: Human.self).from(swinject) }.to(throwError()) } it("injects different intances on different contexts") { let scope = SessionScope() let swinject = Swinject { registerSingle(in: scope).factory { Human() } } - let first = try? swinject.on(Session()).instance(of: Human.self) - let second = try? swinject.on(Session()).instance(of: Human.self) + let first = try? instance(of: Human.self).from(swinject.on(Session())) + let second = try? instance(of: Human.self).from(swinject.on(Session())) expect(first) !== second } describe("closable") { @@ -49,9 +49,9 @@ class ScopesSpec: QuickSpec { override func spec() { #if swift(>=5.1) registerSingle(in: scope).factory { Human() } } - let first = try? swinject.instance(of: Human.self) + let first = try? instance(of: Human.self).from(swinject) scope.close() - let second = try? swinject.instance(of: Human.self) + let second = try? instance(of: Human.self).from(swinject) expect(first) !== second } @@ -60,7 +60,7 @@ class ScopesSpec: QuickSpec { override func spec() { #if swift(>=5.1) let swinject = Swinject { registerSingle(in: scope).factory { Door() } } - let door = try? swinject.instance() as Door + let door = try? instance().from(swinject) as Door scope.close() @@ -72,7 +72,7 @@ class ScopesSpec: QuickSpec { override func spec() { #if swift(>=5.1) let swinject = Swinject { registerSingle(in: scope).factory { Door() } } - let door = try? swinject.on(session!).instance(of: Door.self) + let door = try? instance(of: Door.self).from(swinject.on(session!)) session = nil @@ -84,11 +84,11 @@ class ScopesSpec: QuickSpec { override func spec() { #if swift(>=5.1) let swinject = Swinject { registerSingle(in: scope).factory { Human() } } - weak var instance = try? swinject.on(session!).instance(of: Human.self) + weak var weakInstance = try? instance(of: Human.self).from(swinject.on(session!)) session = nil - expect(instance).to(beNil()) + expect(weakInstance).to(beNil()) } } #endif diff --git a/Tests/3.0 API/SingletonSpec.swift b/Tests/3.0 API/SingletonSpec.swift index e9e26c46..d446d9a8 100644 --- a/Tests/3.0 API/SingletonSpec.swift +++ b/Tests/3.0 API/SingletonSpec.swift @@ -15,16 +15,16 @@ class SingletonSpec: QuickSpec { override func spec() { #if swift(>=5.1) let swinject = Swinject { register().factory { Human() } } - let first = try? swinject.instance(of: Human.self) - let second = try? swinject.instance(of: Human.self) + let first = try? instance(of: Human.self).from(swinject) + let second = try? instance(of: Human.self).from(swinject) expect(first) !== second } it("injects the same instance from a singleton binding") { let swinject = Swinject { registerSingle().factory { Human() } } - let first = try? swinject.instance(of: Human.self) - let second = try? swinject.instance(of: Human.self) + let first = try? instance(of: Human.self).from(swinject) + let second = try? instance(of: Human.self).from(swinject) expect(first) === second } it("injects the same instance for types bound to the same implementation") { @@ -33,8 +33,8 @@ class SingletonSpec: QuickSpec { override func spec() { #if swift(>=5.1) .factory { Human() } .alsoUse { $0 as Mammal } } - let human = try? swinject.instance() as Human - let mammal = try? swinject.instance() as Mammal + let human = try? instance().from(swinject) as Human + let mammal = try? instance().from(swinject) as Mammal expect(human) === mammal } it("does not reuse singleton instances for different tags") { @@ -42,26 +42,26 @@ class SingletonSpec: QuickSpec { override func spec() { #if swift(>=5.1) registerSingle().factory(tag: "john") { Human() } registerSingle().factory(tag: "rick") { Human() } } - let john = try? swinject.instance(of: Human.self, tagged: "john") - let rick = try? swinject.instance(of: Human.self, tagged: "rick") + let john = try? instance(of: Human.self, tagged: "john").from(swinject) + let rick = try? instance(of: Human.self, tagged: "rick").from(swinject) expect(john) !== rick } it("injects the same instance from multiton binding when using the same argument") { let swinject = Swinject { register().factory { Human() } - registerSingle().factory { Pet(name: $1, owner: try $0.instance()) } + registerSingle().factory { Pet(name: $1, owner: try instance().from($0)) } } - let first = try? swinject.instance(of: Pet.self, arg: "mimi") - let second = try? swinject.instance(of: Pet.self, arg: "mimi") + let first = try? instance(of: Pet.self, arg: "mimi").from(swinject) + let second = try? instance(of: Pet.self, arg: "mimi").from(swinject) expect(first) === second } it("injects a different instance from multiton binding when using a different argument") { let swinject = Swinject { register().factory { Human() } - registerSingle().factory { Pet(name: $1, owner: try $0.instance()) } + registerSingle().factory { Pet(name: $1, owner: try instance().from($0)) } } - let mimi = try? swinject.instance(of: Pet.self, arg: "mimi") - let riff = try? swinject.instance(of: Pet.self, arg: "riff") + let mimi = try? instance(of: Pet.self, arg: "mimi").from(swinject) + let riff = try? instance(of: Pet.self, arg: "riff").from(swinject) expect(mimi) !== riff } describe("weak reference") { @@ -71,7 +71,7 @@ class SingletonSpec: QuickSpec { override func spec() { #if swift(>=5.1) .factory { Human() } .withProperties { $0.reference = weakRef } } - weak var first = try? swinject.instance() as Human + weak var first = try? instance().from(swinject) as Human expect(first).to(beNil()) } it("injects the same instance while it is used") { @@ -80,8 +80,8 @@ class SingletonSpec: QuickSpec { override func spec() { #if swift(>=5.1) .factory { Human() } .withProperties { $0.reference = weakRef } } - let first = try? swinject.instance(of: Human.self) - let second = try? swinject.instance(of: Human.self) + let first = try? instance(of: Human.self).from(swinject) + let second = try? instance(of: Human.self).from(swinject) expect(first) === second } } From 11b56a6c1c18b97618fd5923cd76d22a76ca2ec8 Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Sat, 24 Aug 2019 17:15:20 +0200 Subject: [PATCH 227/239] Draft support for instance retrieval --- Sources/3.0 API/Retrieval.swift | 38 ++++++++++++++++++++++++++++++ Swinject.xcodeproj/project.pbxproj | 10 ++++++++ Tests/3.0 API/RetrievalSpec.swift | 17 ++++++++----- 3 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 Sources/3.0 API/Retrieval.swift diff --git a/Sources/3.0 API/Retrieval.swift b/Sources/3.0 API/Retrieval.swift new file mode 100644 index 00000000..09cf5393 --- /dev/null +++ b/Sources/3.0 API/Retrieval.swift @@ -0,0 +1,38 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +// swiftformat:disable unusedArguments indent +// swiftlint:disable force_try + +#if swift(>=5.1) +@propertyWrapper public struct Injected { + private var value: Value? + private let request: InstanceRequest + + public init(_ request: InstanceRequest) { + self.request = request + } + + public init() { + request = instance() + } + + public var wrappedValue: Value { fatalError() } + + public static subscript( + _enclosingInstance enclosing: EnclosingType, + wrapped wrappedKeyPath: KeyPath, + storage storageKeyPath: ReferenceWritableKeyPath + ) -> Value { + if let value = enclosing[keyPath: storageKeyPath].value { + return value + } else { + let request = enclosing[keyPath: storageKeyPath].request + let newValue = try! enclosing.swinject.resolve(request) + enclosing[keyPath: storageKeyPath].value = newValue + return newValue + } + } +} +#endif diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 1fa48dfc..1412ef89 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -149,6 +149,10 @@ 77316673231176B50002655B /* InstanceRequest+APi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7731666F231176B20002655B /* InstanceRequest+APi.swift */; }; 77316675231177580002655B /* InstanceRequestVariation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77316674231177580002655B /* InstanceRequestVariation.swift */; }; 773166772311787D0002655B /* InstanceRequest+Api.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 773166762311787D0002655B /* InstanceRequest+Api.swifttemplate */; }; + 773166792311854B0002655B /* Retrieval.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773166782311854B0002655B /* Retrieval.swift */; }; + 7731667A231187470002655B /* Retrieval.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773166782311854B0002655B /* Retrieval.swift */; }; + 7731667B231187480002655B /* Retrieval.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773166782311854B0002655B /* Retrieval.swift */; }; + 7731667C231187480002655B /* Retrieval.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773166782311854B0002655B /* Retrieval.swift */; }; 773BE491231124AD000AA1A9 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773C6DDB23111956007A40BF /* Binding.swift */; }; 773C6DDC23111956007A40BF /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773C6DDB23111956007A40BF /* Binding.swift */; }; 773C6DDD23111956007A40BF /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773C6DDB23111956007A40BF /* Binding.swift */; }; @@ -512,6 +516,7 @@ 7731666F231176B20002655B /* InstanceRequest+APi.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "InstanceRequest+APi.swift"; sourceTree = ""; }; 77316674231177580002655B /* InstanceRequestVariation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRequestVariation.swift; sourceTree = ""; }; 773166762311787D0002655B /* InstanceRequest+Api.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "InstanceRequest+Api.swifttemplate"; sourceTree = ""; }; + 773166782311854B0002655B /* Retrieval.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Retrieval.swift; sourceTree = ""; }; 773C6DDB23111956007A40BF /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; 77B87F3B23112DB100321C08 /* Binding+Api.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Binding+Api.swift"; sourceTree = ""; }; 77B87F3D231153D200321C08 /* FactoryVariation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FactoryVariation.swift; sourceTree = ""; }; @@ -663,6 +668,7 @@ 667B13B528642272FC0794B6 /* UnboundScope.swift */, 57A7E35B2B22650208F904B8 /* Weak.swift */, 7731666F231176B20002655B /* InstanceRequest+APi.swift */, + 773166782311854B0002655B /* Retrieval.swift */, ); path = "3.0 API"; sourceTree = ""; @@ -1402,6 +1408,7 @@ AAD8D0551B8A26A9B22AECEC /* Container+Registration.swift in Sources */, 996CCFE825834C7D3236E742 /* Container+TypeForwarding.swift in Sources */, B2FAD41F7726502822AF913B /* Container.swift in Sources */, + 7731667C231187480002655B /* Retrieval.swift in Sources */, 8B5927517B567B1DFAB5B935 /* ContextTranslator.swift in Sources */, 77B87F492311580600321C08 /* Binding+Api.swift in Sources */, 1D17DBC27F25717BF7A87AF3 /* InstanceRequest.swift in Sources */, @@ -1620,6 +1627,7 @@ BD9B57E26722C80B7EF990DB /* Container+TypeForwarding.swift in Sources */, DB74F17CDFF4886B9C38AD14 /* Container.swift in Sources */, DD5E3AF2B5FCE5E81EBDF606 /* ContextTranslator.swift in Sources */, + 7731667B231187480002655B /* Retrieval.swift in Sources */, 76FB9AFE299316E7F3F4C3BB /* InstanceRequest.swift in Sources */, 77B87F482311580600321C08 /* Binding+Api.swift in Sources */, 57BFBA2077E70DC1C2FE796C /* InstanceWrapper.swift in Sources */, @@ -1664,6 +1672,7 @@ CB0B308F3D3A831A28127462 /* Container+Registration.swift in Sources */, 283C77045DA55C2134EC9C48 /* Container+TypeForwarding.swift in Sources */, 58ABEE0321A3061048B65EA2 /* Container.swift in Sources */, + 7731667A231187470002655B /* Retrieval.swift in Sources */, F06DEB671A4B85ABB0E96E51 /* ContextTranslator.swift in Sources */, 77B87F472311580500321C08 /* Binding+Api.swift in Sources */, 027015812E961322FE3D942B /* InstanceRequest.swift in Sources */, @@ -1708,6 +1717,7 @@ 21285CED416F1317E993397A /* Container+Registration.swift in Sources */, 3A0B409E840B44B281DB3C54 /* Container+TypeForwarding.swift in Sources */, 0622539110A7430776A307C7 /* Container.swift in Sources */, + 773166792311854B0002655B /* Retrieval.swift in Sources */, D1DF4740A9D86362B63104B8 /* ContextTranslator.swift in Sources */, 826D63FA91E370F0061768B0 /* InstanceRequest.swift in Sources */, 77B87F43231157E900321C08 /* Binding+Factory.swift in Sources */, diff --git a/Tests/3.0 API/RetrievalSpec.swift b/Tests/3.0 API/RetrievalSpec.swift index b0095c1a..816717ec 100644 --- a/Tests/3.0 API/RetrievalSpec.swift +++ b/Tests/3.0 API/RetrievalSpec.swift @@ -5,21 +5,26 @@ import Nimble import Quick import Swinject -// swiftlint:disable force_try class RetrievalSpec: QuickSpec { override func spec() { #if swift(>=5.1) - // TODO: Better support it("can retrieve bound types") { - struct IntHolder: SwinjectAware { + class NumberHolder: SwinjectAware { + @Injected var int: Int + + @Injected(instance(tagged: "tag", arg: 42)) + var double: Double + let swinject: Resolver - lazy var int: Int = try! instance().from(swinject) + init(swinject: Resolver) { self.swinject = swinject } } let swinject = Swinject { - register().factory { IntHolder(swinject: $0) } + register().factory { NumberHolder(swinject: $0) } register().constant(42) + register().factory(tag: "tag") { Double($1 as Int) } } - var holder = try? instance().from(swinject) as IntHolder + let holder = try? instance(of: NumberHolder.self).from(swinject) expect(holder?.int) == 42 + expect(holder?.double) == 42 } #endif } } From 1367dce878623354e79d63a481d7f3817d19d2c4 Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Sat, 24 Aug 2019 17:35:22 +0200 Subject: [PATCH 228/239] Fix compilation on < 5.1 --- Sources/3.0 API/Binding+Api.swift | 10 +++++----- Sources/3.0 API/Binding.swift | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/3.0 API/Binding+Api.swift b/Sources/3.0 API/Binding+Api.swift index 301eb1e5..bf6c8857 100644 --- a/Sources/3.0 API/Binding+Api.swift +++ b/Sources/3.0 API/Binding+Api.swift @@ -42,25 +42,25 @@ public extension Binding where Instance == Void { } public extension Binding { - func toUse(_: (Instance) -> OtherInstance, tag: String?) -> Self { + func toUse(_: (Instance) -> OtherInstance, tag: String?) -> Binding { return updated { $0.products = [tagged(OtherInstance.self, with: tag)] } } - func toUse(_ typeCheck: (Instance) -> OtherInstance) -> Self { + func toUse(_ typeCheck: (Instance) -> OtherInstance) -> Binding { return toUse(typeCheck, tag: nil) } - func alsoUse(_: (Instance) -> OtherInstance, tag: String? = nil) -> Self { + func alsoUse(_: (Instance) -> OtherInstance, tag: String? = nil) -> Binding { return updated { $0.products.append(tagged(OtherInstance.self, with: tag)) } } - func alsoUse(_ typeCheck: (Instance) -> OtherInstance) -> Self { + func alsoUse(_ typeCheck: (Instance) -> OtherInstance) -> Binding { return alsoUse(typeCheck, tag: nil) } } public extension Binding { - func withProperties(_ update: (inout BindingProperties) -> Void) -> Self { + func withProperties(_ update: (inout BindingProperties) -> Void) -> Binding { return updated { update(&$0.properties) } } } diff --git a/Sources/3.0 API/Binding.swift b/Sources/3.0 API/Binding.swift index 4fb129bf..69e2cb36 100644 --- a/Sources/3.0 API/Binding.swift +++ b/Sources/3.0 API/Binding.swift @@ -54,7 +54,7 @@ extension Binding: AnyBinding { } extension Binding { - func updated(_ update: (inout Self) -> Void) -> Self { + func updated(_ update: (inout Binding) -> Void) -> Binding { var copy = self update(©) return copy From 2a9eddeaaf7b5db079d1d0e4d9e57ae4b08f81d9 Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Sat, 24 Aug 2019 17:45:33 +0200 Subject: [PATCH 229/239] Describe behavior for throwing initializers --- Tests/3.0 API/InjectionSpec.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Tests/3.0 API/InjectionSpec.swift b/Tests/3.0 API/InjectionSpec.swift index a2b9d3e0..c2b37b19 100644 --- a/Tests/3.0 API/InjectionSpec.swift +++ b/Tests/3.0 API/InjectionSpec.swift @@ -29,6 +29,12 @@ class InjectionSpec: QuickSpec { override func spec() { #if swift(>=5.1) expect { try instance().from(swinject) as Int }.to(throwError()) expect { try instance(arg: 42.0).from(swinject) as Int }.to(throwError()) } + it("rethrows error from the type's factory") { + let swinject = Swinject { + register().factory(for: Int.self) { throw TestError() } + } + expect { try instance(of: Int.self).from(swinject) }.to(throwError(errorType: TestError.self)) + } } // TODO: Refactor describe("function call") { From 00a196ce2cfdacafd18ca8313c06d220acc4686f Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Sun, 25 Aug 2019 10:32:43 +0200 Subject: [PATCH 230/239] Refactor argument handling --- Sources/2.0 API/Container+Registration.swift | 20 +- .../2.0 API/Container+TypeForwarding.swift | 4 +- Sources/2.0 API/Resolver+LegacyApi.swift | 20 +- Sources/2.0 API/ServiceEntry.swift | 30 +-- Sources/3.0 API/Binding+Api.swift | 7 +- Sources/3.0 API/Binding+Factory.swift | 37 ++- Sources/3.0 API/Binding.swift | 30 +-- Sources/3.0 API/InstanceRequest+APi.swift | 22 +- Sources/Core/AnyBinding.swift | 20 +- Sources/Core/Arguments.swift | 162 +++++++++++ Sources/Core/InstanceRequest.swift | 30 +-- Sources/Core/Matchable.swift | 77 +----- Sources/Core/PropertyWrapper.swift | 7 +- Sources/Core/ScopeRegistryKey.swift | 23 +- Sources/Core/Swinject.swift | 6 +- Sources/Core/SwinjectError.swift | 2 + Swinject.xcodeproj/project.pbxproj | 254 +++++++++--------- Templates/ArgumentVariations.swifttemplate | 19 ++ .../Container+Registration.swifttemplate | 8 +- Templates/FactoryVariation.swift | 16 +- Templates/InstanceRequestVariation.swift | 2 +- Templates/MatchableBoxes.swifttemplate | 29 -- Templates/Resolver+LegacyApi.swifttemplate | 6 +- Templates/SwiftCode.swifttemplate | 18 +- .../StandardScopeRegistrySpec.swift | 2 +- 25 files changed, 461 insertions(+), 390 deletions(-) create mode 100644 Sources/Core/Arguments.swift create mode 100644 Templates/ArgumentVariations.swifttemplate delete mode 100644 Templates/MatchableBoxes.swifttemplate diff --git a/Sources/2.0 API/Container+Registration.swift b/Sources/2.0 API/Container+Registration.swift index 7721be7d..d6c7b4cc 100644 --- a/Sources/2.0 API/Container+Registration.swift +++ b/Sources/2.0 API/Container+Registration.swift @@ -19,7 +19,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, _: Void) in factory(r) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef, argumentDescriptor: []) { r, _ in factory(r) } addEntry(entry, with: name) return entry } @@ -38,7 +38,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, a: Arg1) in factory(r, a) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef, argumentDescriptor: [Arg1.self]) { r, a in try! factory(r, a.arg(0)) } addEntry(entry, with: name) return entry } @@ -57,7 +57,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, a: (Arg1, Arg2)) in factory(r, a.0, a.1) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef, argumentDescriptor: [Arg1.self, Arg2.self]) { r, a in try! factory(r, a.arg(0), a.arg(1)) } addEntry(entry, with: name) return entry } @@ -76,7 +76,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, a: (Arg1, Arg2, Arg3)) in factory(r, a.0, a.1, a.2) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef, argumentDescriptor: [Arg1.self, Arg2.self, Arg3.self]) { r, a in try! factory(r, a.arg(0), a.arg(1), a.arg(2)) } addEntry(entry, with: name) return entry } @@ -95,7 +95,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, a: (Arg1, Arg2, Arg3, Arg4)) in factory(r, a.0, a.1, a.2, a.3) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef, argumentDescriptor: [Arg1.self, Arg2.self, Arg3.self, Arg4.self]) { r, a in try! factory(r, a.arg(0), a.arg(1), a.arg(2), a.arg(3)) } addEntry(entry, with: name) return entry } @@ -114,7 +114,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5)) in factory(r, a.0, a.1, a.2, a.3, a.4) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef, argumentDescriptor: [Arg1.self, Arg2.self, Arg3.self, Arg4.self, Arg5.self]) { r, a in try! factory(r, a.arg(0), a.arg(1), a.arg(2), a.arg(3), a.arg(4)) } addEntry(entry, with: name) return entry } @@ -133,7 +133,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef, argumentDescriptor: [Arg1.self, Arg2.self, Arg3.self, Arg4.self, Arg5.self, Arg6.self]) { r, a in try! factory(r, a.arg(0), a.arg(1), a.arg(2), a.arg(3), a.arg(4), a.arg(5)) } addEntry(entry, with: name) return entry } @@ -152,7 +152,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef, argumentDescriptor: [Arg1.self, Arg2.self, Arg3.self, Arg4.self, Arg5.self, Arg6.self, Arg7.self]) { r, a in try! factory(r, a.arg(0), a.arg(1), a.arg(2), a.arg(3), a.arg(4), a.arg(5), a.arg(6)) } addEntry(entry, with: name) return entry } @@ -171,7 +171,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6, a.7) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef, argumentDescriptor: [Arg1.self, Arg2.self, Arg3.self, Arg4.self, Arg5.self, Arg6.self, Arg7.self, Arg8.self]) { r, a in try! factory(r, a.arg(0), a.arg(1), a.arg(2), a.arg(3), a.arg(4), a.arg(5), a.arg(6), a.arg(7)) } addEntry(entry, with: name) return entry } @@ -190,7 +190,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, a: (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9)) in factory(r, a.0, a.1, a.2, a.3, a.4, a.5, a.6, a.7, a.8) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef, argumentDescriptor: [Arg1.self, Arg2.self, Arg3.self, Arg4.self, Arg5.self, Arg6.self, Arg7.self, Arg8.self, Arg9.self]) { r, a in try! factory(r, a.arg(0), a.arg(1), a.arg(2), a.arg(3), a.arg(4), a.arg(5), a.arg(6), a.arg(7), a.arg(8)) } addEntry(entry, with: name) return entry } diff --git a/Sources/2.0 API/Container+TypeForwarding.swift b/Sources/2.0 API/Container+TypeForwarding.swift index c331dd1e..e9581731 100644 --- a/Sources/2.0 API/Container+TypeForwarding.swift +++ b/Sources/2.0 API/Container+TypeForwarding.swift @@ -22,9 +22,9 @@ extension Container { addBinding( type: type, key: BindingKey( - descriptor: tagged(T.self, with: name), + type: tagged(T.self, with: name), contextType: service.key.contextType, - argumentType: service.key.argumentType + arguments: service.key.arguments ), name: name, entry: service diff --git a/Sources/2.0 API/Resolver+LegacyApi.swift b/Sources/2.0 API/Resolver+LegacyApi.swift index 309b29ac..eb6b0651 100644 --- a/Sources/2.0 API/Resolver+LegacyApi.swift +++ b/Sources/2.0 API/Resolver+LegacyApi.swift @@ -12,7 +12,7 @@ public extension Resolver { /// /// - Returns: The resolved service type instance, or nil if no service with the name is found. func resolve(_ serviceType: Service.Type, name: String? = nil) -> Service? { - return try? resolve(request(type: serviceType, tag: name, arg: ())) as Service + return try? resolve(request(type: serviceType, tag: name, arg: Arguments())) as Service } /// Retrieves the instance with the specified service type, 1 argument to the factory closure and registration name. @@ -25,7 +25,7 @@ public extension Resolver { /// - Returns: The resolved service type instance, or nil if no registration for the service type, /// 1 argument and name is found. func resolve(_ serviceType: Service.Type, name: String? = nil, argument: Arg1) -> Service? { - return try? resolve(request(type: serviceType, tag: name, arg: argument)) as Service + return try? resolve(request(type: serviceType, tag: name, arg: Arguments(argument))) as Service } /// Retrieves the instance with the specified service type, list of 2 arguments to the factory closure and registration name. @@ -38,7 +38,7 @@ public extension Resolver { /// - Returns: The resolved service type instance, or nil if no registration for the service type, /// list of 2 arguments and name is found. func resolve(_ serviceType: Service.Type, name: String? = nil, arguments arg1: Arg1, _ arg2: Arg2) -> Service? { - return try? resolve(request(type: serviceType, tag: name, arg: (arg1, arg2))) as Service + return try? resolve(request(type: serviceType, tag: name, arg: Arguments(arg1, arg2))) as Service } /// Retrieves the instance with the specified service type, list of 3 arguments to the factory closure and registration name. @@ -51,7 +51,7 @@ public extension Resolver { /// - Returns: The resolved service type instance, or nil if no registration for the service type, /// list of 3 arguments and name is found. func resolve(_ serviceType: Service.Type, name: String? = nil, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> Service? { - return try? resolve(request(type: serviceType, tag: name, arg: (arg1, arg2, arg3))) as Service + return try? resolve(request(type: serviceType, tag: name, arg: Arguments(arg1, arg2, arg3))) as Service } /// Retrieves the instance with the specified service type, list of 4 arguments to the factory closure and registration name. @@ -64,7 +64,7 @@ public extension Resolver { /// - Returns: The resolved service type instance, or nil if no registration for the service type, /// list of 4 arguments and name is found. func resolve(_ serviceType: Service.Type, name: String? = nil, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> Service? { - return try? resolve(request(type: serviceType, tag: name, arg: (arg1, arg2, arg3, arg4))) as Service + return try? resolve(request(type: serviceType, tag: name, arg: Arguments(arg1, arg2, arg3, arg4))) as Service } /// Retrieves the instance with the specified service type, list of 5 arguments to the factory closure and registration name. @@ -77,7 +77,7 @@ public extension Resolver { /// - Returns: The resolved service type instance, or nil if no registration for the service type, /// list of 5 arguments and name is found. func resolve(_ serviceType: Service.Type, name: String? = nil, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> Service? { - return try? resolve(request(type: serviceType, tag: name, arg: (arg1, arg2, arg3, arg4, arg5))) as Service + return try? resolve(request(type: serviceType, tag: name, arg: Arguments(arg1, arg2, arg3, arg4, arg5))) as Service } /// Retrieves the instance with the specified service type, list of 6 arguments to the factory closure and registration name. @@ -90,7 +90,7 @@ public extension Resolver { /// - Returns: The resolved service type instance, or nil if no registration for the service type, /// list of 6 arguments and name is found. func resolve(_ serviceType: Service.Type, name: String? = nil, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6) -> Service? { - return try? resolve(request(type: serviceType, tag: name, arg: (arg1, arg2, arg3, arg4, arg5, arg6))) as Service + return try? resolve(request(type: serviceType, tag: name, arg: Arguments(arg1, arg2, arg3, arg4, arg5, arg6))) as Service } /// Retrieves the instance with the specified service type, list of 7 arguments to the factory closure and registration name. @@ -103,7 +103,7 @@ public extension Resolver { /// - Returns: The resolved service type instance, or nil if no registration for the service type, /// list of 7 arguments and name is found. func resolve(_ serviceType: Service.Type, name: String? = nil, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7) -> Service? { - return try? resolve(request(type: serviceType, tag: name, arg: (arg1, arg2, arg3, arg4, arg5, arg6, arg7))) as Service + return try? resolve(request(type: serviceType, tag: name, arg: Arguments(arg1, arg2, arg3, arg4, arg5, arg6, arg7))) as Service } /// Retrieves the instance with the specified service type, list of 8 arguments to the factory closure and registration name. @@ -116,7 +116,7 @@ public extension Resolver { /// - Returns: The resolved service type instance, or nil if no registration for the service type, /// list of 8 arguments and name is found. func resolve(_ serviceType: Service.Type, name: String? = nil, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8) -> Service? { - return try? resolve(request(type: serviceType, tag: name, arg: (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8))) as Service + return try? resolve(request(type: serviceType, tag: name, arg: Arguments(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8))) as Service } /// Retrieves the instance with the specified service type, list of 9 arguments to the factory closure and registration name. @@ -129,7 +129,7 @@ public extension Resolver { /// - Returns: The resolved service type instance, or nil if no registration for the service type, /// list of 9 arguments and name is found. func resolve(_ serviceType: Service.Type, name: String? = nil, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8, _ arg9: Arg9) -> Service? { - return try? resolve(request(type: serviceType, tag: name, arg: (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9))) as Service + return try? resolve(request(type: serviceType, tag: name, arg: Arguments(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9))) as Service } } diff --git a/Sources/2.0 API/ServiceEntry.swift b/Sources/2.0 API/ServiceEntry.swift index 84dc2225..5587a5ce 100644 --- a/Sources/2.0 API/ServiceEntry.swift +++ b/Sources/2.0 API/ServiceEntry.swift @@ -6,27 +6,28 @@ /// As a returned instance from a `register` method of a `Container`, some configurations can be added. public class ServiceEntry { weak var container: Container? - let builder: (Resolver, Any, Any) -> Service - let argumentType: Any.Type + let builder: (Resolver, Arguments) -> Service + let argumentDescriptor: Arguments.Descriptor let name: String? var scope: AnyScope? var makeRef: ReferenceMaker var finalizers = [(Resolver, Service) -> Void]() var forwardedDescriptors = [TypeDescriptor]() - init( + init( container: Container, name: String?, scope: AnyScope?, makeRef: @escaping ReferenceMaker, - builder: @escaping (Resolver, Any, Argument) -> Service + argumentDescriptor: Arguments.Descriptor, + builder: @escaping (Resolver, Arguments) -> Service ) { self.container = container self.name = name self.scope = scope self.makeRef = makeRef - self.builder = { builder($0, $1, $2 as! Argument) } - argumentType = Argument.self + self.builder = builder + self.argumentDescriptor = argumentDescriptor } /// Specifies a custom scope & reference maker to use for the service. @@ -72,16 +73,16 @@ public class ServiceEntry { extension ServiceEntry: AnyBinding { public var overrides: Bool { return false } - public func makeInstance(resolver: Resolver, arg: Any) throws -> Any { + public func makeInstance(resolver: Resolver, arguments: Arguments) throws -> Any { let context = try resolver.context(as: key.contextType) if let scope = scope { return getRegistry(scope: scope, context: context).instance( - for: ScopeRegistryKey(descriptor: key.descriptor, argument: arg), - builder: { makeRef(builder(resolver, context, arg)) }, + for: ScopeRegistryKey(descriptor: key.type, arguments: arguments), + builder: { makeRef(builder(resolver, arguments)) }, finalizer: { instance in finalizers.forEach { $0(resolver, instance as! Service) } } ) } else { - return builder(resolver, context, arg) + return builder(resolver, arguments) } } @@ -97,9 +98,9 @@ extension ServiceEntry: AnyBinding { var key: BindingKey { return BindingKey( - descriptor: tagged(Service.self, with: name), + type: tagged(Service.self, with: name), contextType: scope?.contextType ?? Any.self, - argumentType: argumentType + arguments: argumentDescriptor ) } @@ -122,10 +123,7 @@ extension ServiceEntry: CustomStringConvertible { } private var argumentTypes: String? { - var result = "\(argumentType)" - if result.hasPrefix("("), result.hasSuffix(")") { - result = String(result.dropFirst().dropLast()) - } + let result = argumentDescriptor.types.map { "\($0)" }.joined(separator: ", ") return result.isEmpty ? nil : result } diff --git a/Sources/3.0 API/Binding+Api.swift b/Sources/3.0 API/Binding+Api.swift index bf6c8857..bbb97e3c 100644 --- a/Sources/3.0 API/Binding+Api.swift +++ b/Sources/3.0 API/Binding+Api.swift @@ -9,7 +9,7 @@ public func register(inContextOf _: Context.Type) -> Binding(in scope: AScope) -> Binding Binding { public extension Binding where Instance == Void { func constant(_ value: Value, tag: String? = nil) -> Binding { - return updatedFactory { (_, _: Void) in value }.updated { + return updatedFactory { _, _ in value }.updated { $0.products = [tagged(Value.self, with: tag)] $0.dependencies = .none + $0.arguments = [] } } } diff --git a/Sources/3.0 API/Binding+Factory.swift b/Sources/3.0 API/Binding+Factory.swift index daaf3d7c..0ec01987 100644 --- a/Sources/3.0 API/Binding+Factory.swift +++ b/Sources/3.0 API/Binding+Factory.swift @@ -4,90 +4,101 @@ // swiftlint:disable line_length // swiftlint:disable identifier_name -// swiftlint:disable large_tuple // sourcery:inline:BindingFactoryApi public extension Binding { func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping () throws -> NewInstance) -> Binding { - return updatedFactory { (_, _: Void) in try factory() }.updated { + return updatedFactory { _, _ in try factory() }.updated { $0.products = [tagged(NewInstance.self, with: tag)] $0.dependencies = .undefined + $0.arguments = [] } } func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver) throws -> NewInstance) -> Binding { - return updatedFactory { (r, _: Void) in try factory(r) }.updated { + return updatedFactory { r, _ in try factory(r) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] $0.dependencies = .undefined + $0.arguments = [] } } func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1) throws -> NewInstance) -> Binding { - return updatedFactory { (r, a: Arg1) in try factory(r, a) }.updated { + return updatedFactory { r, a in try factory(r, a.arg(0)) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] $0.dependencies = .undefined + $0.arguments = [Arg1.self] } } func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1) throws -> NewInstance) -> Binding where Arg1: Hashable { - return updatedFactory { (r, a: MatchableBox1) in try factory(r, a.arg1) }.updated { + return updatedFactory { r, a in try factory(r, a.arg(0)) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] $0.dependencies = .undefined + $0.arguments = [Arg1.self] } } func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2) throws -> NewInstance) -> Binding { - return updatedFactory { (r, a: (Arg1, Arg2)) in try factory(r, a.0, a.1) }.updated { + return updatedFactory { r, a in try factory(r, a.arg(0), a.arg(1)) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] $0.dependencies = .undefined + $0.arguments = [Arg1.self, Arg2.self] } } func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2) throws -> NewInstance) -> Binding where Arg1: Hashable, Arg2: Hashable { - return updatedFactory { (r, a: MatchableBox2) in try factory(r, a.arg1, a.arg2) }.updated { + return updatedFactory { r, a in try factory(r, a.arg(0), a.arg(1)) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] $0.dependencies = .undefined + $0.arguments = [Arg1.self, Arg2.self] } } func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2, Arg3) throws -> NewInstance) -> Binding { - return updatedFactory { (r, a: (Arg1, Arg2, Arg3)) in try factory(r, a.0, a.1, a.2) }.updated { + return updatedFactory { r, a in try factory(r, a.arg(0), a.arg(1), a.arg(2)) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] $0.dependencies = .undefined + $0.arguments = [Arg1.self, Arg2.self, Arg3.self] } } func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2, Arg3) throws -> NewInstance) -> Binding where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - return updatedFactory { (r, a: MatchableBox3) in try factory(r, a.arg1, a.arg2, a.arg3) }.updated { + return updatedFactory { r, a in try factory(r, a.arg(0), a.arg(1), a.arg(2)) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] $0.dependencies = .undefined + $0.arguments = [Arg1.self, Arg2.self, Arg3.self] } } func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2, Arg3, Arg4) throws -> NewInstance) -> Binding { - return updatedFactory { (r, a: (Arg1, Arg2, Arg3, Arg4)) in try factory(r, a.0, a.1, a.2, a.3) }.updated { + return updatedFactory { r, a in try factory(r, a.arg(0), a.arg(1), a.arg(2), a.arg(3)) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] $0.dependencies = .undefined + $0.arguments = [Arg1.self, Arg2.self, Arg3.self, Arg4.self] } } func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2, Arg3, Arg4) throws -> NewInstance) -> Binding where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return updatedFactory { (r, a: MatchableBox4) in try factory(r, a.arg1, a.arg2, a.arg3, a.arg4) }.updated { + return updatedFactory { r, a in try factory(r, a.arg(0), a.arg(1), a.arg(2), a.arg(3)) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] $0.dependencies = .undefined + $0.arguments = [Arg1.self, Arg2.self, Arg3.self, Arg4.self] } } func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> NewInstance) -> Binding { - return updatedFactory { (r, a: (Arg1, Arg2, Arg3, Arg4, Arg5)) in try factory(r, a.0, a.1, a.2, a.3, a.4) }.updated { + return updatedFactory { r, a in try factory(r, a.arg(0), a.arg(1), a.arg(2), a.arg(3), a.arg(4)) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] $0.dependencies = .undefined + $0.arguments = [Arg1.self, Arg2.self, Arg3.self, Arg4.self, Arg5.self] } } func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> NewInstance) -> Binding where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return updatedFactory { (r, a: MatchableBox5) in try factory(r, a.arg1, a.arg2, a.arg3, a.arg4, a.arg5) }.updated { + return updatedFactory { r, a in try factory(r, a.arg(0), a.arg(1), a.arg(2), a.arg(3), a.arg(4)) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] $0.dependencies = .undefined + $0.arguments = [Arg1.self, Arg2.self, Arg3.self, Arg4.self, Arg5.self] } } } diff --git a/Sources/3.0 API/Binding.swift b/Sources/3.0 API/Binding.swift index 69e2cb36..7d8cb033 100644 --- a/Sources/3.0 API/Binding.swift +++ b/Sources/3.0 API/Binding.swift @@ -19,37 +19,37 @@ enum BindingDependencies { public struct Binding { var products: [TypeDescriptor] var dependencies: BindingDependencies - var factory: (ContextedResolver, Any) throws -> Instance + var factory: (ContextedResolver, Arguments) throws -> Instance var properties: BindingProperties let scope: AnyScope? - let argumentType: Any.Type + var arguments: Arguments.Descriptor } extension Binding: AnyBinding { public var keys: [BindingKey] { - return products.map { BindingKey(descriptor: $0, contextType: Context.self, argumentType: argumentType) } + return products.map { BindingKey(type: $0, contextType: Context.self, arguments: arguments) } } public var overrides: Bool { return properties.overrides } - public func makeInstance(resolver: Resolver, arg: Any) throws -> Any { + public func makeInstance(resolver: Resolver, arguments: Arguments) throws -> Any { if let scope = scope { - return try scopedInstance(resolver: resolver, scope: scope, arg: arg) + return try scopedInstance(resolver: resolver, scope: scope, arguments: arguments) } else { - return try simpleInstance(resolver: resolver, arg: arg) + return try simpleInstance(resolver: resolver, arguments: arguments) } } - private func scopedInstance(resolver: Resolver, scope: AnyScope, arg: Any) throws -> Any { + private func scopedInstance(resolver: Resolver, scope: AnyScope, arguments: Arguments) throws -> Any { return try scope .registry(for: resolver.context(as: Context.self)) - .instance(for: ScopeRegistryKey(descriptor: products.first!, argument: arg)) { - try properties.reference(simpleInstance(resolver: resolver, arg: arg)) + .instance(for: ScopeRegistryKey(descriptor: products.first!, arguments: arguments)) { + try properties.reference(simpleInstance(resolver: resolver, arguments: arguments)) } } - private func simpleInstance(resolver: Resolver, arg: Any) throws -> Any { - return try factory(resolver.contexted(), arg) + private func simpleInstance(resolver: Resolver, arguments: Arguments) throws -> Any { + return try factory(resolver.contexted(), arguments) } } @@ -60,16 +60,16 @@ extension Binding { return copy } - func updatedFactory( - factory: @escaping (ContextedResolver, NewArgument) throws -> NewInstance + func updatedFactory( + factory: @escaping (ContextedResolver, Arguments) throws -> NewInstance ) -> Binding { return Binding( products: products, dependencies: dependencies, - factory: { try factory($0, $1 as! NewArgument) }, + factory: factory, properties: properties, scope: scope, - argumentType: NewArgument.self + arguments: arguments ) } } diff --git a/Sources/3.0 API/InstanceRequest+APi.swift b/Sources/3.0 API/InstanceRequest+APi.swift index ae09c5a6..18ec6948 100644 --- a/Sources/3.0 API/InstanceRequest+APi.swift +++ b/Sources/3.0 API/InstanceRequest+APi.swift @@ -11,47 +11,47 @@ public extension InstanceRequest { // swiftlint:disable line_length // sourcery:inline:InstanceRequestApi public func instance(of _: Type.Type = Type.self, tagged tag: String? = nil) -> InstanceRequest { - return request(type: Type.self, tag: tag, arg: ()) + return request(type: Type.self, tag: tag, arg: Arguments()) } public func instance(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1) -> InstanceRequest { - return request(type: Type.self, tag: tag, arg: box(arg1)) + return request(type: Type.self, tag: tag, arg: Arguments(arg1)) } public func instance(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1) -> InstanceRequest where Arg1: Hashable { - return request(type: Type.self, tag: tag, arg: box(arg1)) + return request(type: Type.self, tag: tag, arg: Arguments(arg1)) } public func instance(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2) -> InstanceRequest { - return request(type: Type.self, tag: tag, arg: box(arg1, arg2)) + return request(type: Type.self, tag: tag, arg: Arguments(arg1, arg2)) } public func instance(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2) -> InstanceRequest where Arg1: Hashable, Arg2: Hashable { - return request(type: Type.self, tag: tag, arg: box(arg1, arg2)) + return request(type: Type.self, tag: tag, arg: Arguments(arg1, arg2)) } public func instance(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> InstanceRequest { - return request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3)) + return request(type: Type.self, tag: tag, arg: Arguments(arg1, arg2, arg3)) } public func instance(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> InstanceRequest where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - return request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3)) + return request(type: Type.self, tag: tag, arg: Arguments(arg1, arg2, arg3)) } public func instance(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> InstanceRequest { - return request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, arg4)) + return request(type: Type.self, tag: tag, arg: Arguments(arg1, arg2, arg3, arg4)) } public func instance(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> InstanceRequest where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, arg4)) + return request(type: Type.self, tag: tag, arg: Arguments(arg1, arg2, arg3, arg4)) } public func instance(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> InstanceRequest { - return request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, arg4, arg5)) + return request(type: Type.self, tag: tag, arg: Arguments(arg1, arg2, arg3, arg4, arg5)) } public func instance(of _: Type.Type = Type.self, tagged tag: String? = nil, arg arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> InstanceRequest where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return request(type: Type.self, tag: tag, arg: box(arg1, arg2, arg3, arg4, arg5)) + return request(type: Type.self, tag: tag, arg: Arguments(arg1, arg2, arg3, arg4, arg5)) } // sourcery:end diff --git a/Sources/Core/AnyBinding.swift b/Sources/Core/AnyBinding.swift index 36d9483f..bb006363 100644 --- a/Sources/Core/AnyBinding.swift +++ b/Sources/Core/AnyBinding.swift @@ -3,26 +3,26 @@ // public struct BindingKey: Hashable { - let descriptor: TypeDescriptor + let type: TypeDescriptor let contextType: Any.Type - let argumentType: Any.Type + let arguments: Arguments.Descriptor - init(descriptor: TypeDescriptor, contextType: Any.Type, argumentType: Any.Type) { - self.descriptor = descriptor + init(type: TypeDescriptor, contextType: Any.Type, arguments: Arguments.Descriptor) { + self.type = type self.contextType = unwrapOptionals(contextType) - self.argumentType = argumentType + self.arguments = arguments } public func hash(into hasher: inout Hasher) { - descriptor.hash(into: &hasher) + type.hash(into: &hasher) ObjectIdentifier(contextType).hash(into: &hasher) - ObjectIdentifier(argumentType).hash(into: &hasher) + arguments.hash(into: &hasher) } public static func == (lhs: BindingKey, rhs: BindingKey) -> Bool { - return lhs.descriptor == rhs.descriptor + return lhs.type == rhs.type && lhs.contextType == rhs.contextType - && lhs.argumentType == rhs.argumentType + && lhs.arguments == rhs.arguments } } @@ -35,5 +35,5 @@ extension BindingKey { public protocol AnyBinding: SwinjectEntry { var keys: [BindingKey] { get } var overrides: Bool { get } - func makeInstance(resolver: Resolver, arg: Any) throws -> Any + func makeInstance(resolver: Resolver, arguments: Arguments) throws -> Any } diff --git a/Sources/Core/Arguments.swift b/Sources/Core/Arguments.swift new file mode 100644 index 00000000..c3e40086 --- /dev/null +++ b/Sources/Core/Arguments.swift @@ -0,0 +1,162 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +public struct Arguments { + struct Descriptor { + let types: [Any.Type] + } + + let values: [Any] + let descriptor: Descriptor + + func arg(_ index: Int) throws -> Type { + guard (0 ..< values.count).contains(index) else { throw MissingArgument() } + if let value = values[index] as? Type { + return value + } + if let box = values[index] as? AnyMatchBox, let value = box.anyValue as? Type { + return value + } + throw ArgumentMismatch() + } +} + +extension Arguments: Hashable { + public func hash(into hasher: inout Hasher) { + descriptor.hash(into: &hasher) + values.forEach { ($0 as? Matchable)?.hash(into: &hasher) } + } + + public static func == (lhs: Arguments, rhs: Arguments) -> Bool { + return lhs.descriptor == rhs.descriptor + && lhs.values.count == rhs.values.count + && !zip(lhs.values, rhs.values).map(areValuesEqual).contains(false) + } + + private static func areValuesEqual(_ lhs: Any, _ rhs: Any) -> Bool { + switch (lhs, rhs) { + case let (lhs as Matchable, _): return lhs.matches(rhs) + case let (_, rhs as Matchable): return rhs.matches(lhs) + default: return true + } + } +} + +extension Arguments.Descriptor: Hashable { + func hash(into hasher: inout Hasher) { + types.map { ObjectIdentifier($0) }.hash(into: &hasher) + } + + static func == (lhs: Arguments.Descriptor, rhs: Arguments.Descriptor) -> Bool { + return lhs.types.count == rhs.types.count + && zip(lhs.types, rhs.types).map { $0.0 == $0.1 }.allSatisfy { $0 == true } + } +} + +extension Arguments.Descriptor: ExpressibleByArrayLiteral { + init(arrayLiteral types: Any.Type ...) { + self.types = types + } +} + +extension Arguments { + init() { + values = [] + descriptor = [] + } + + // swiftlint:disable line_length + // sourcery:inline:ArgumentVariations + init(_ arg1: Arg1) { + values = [arg1] + descriptor = [Arg1.self] + } + + init(_ arg1: Arg1) where Arg1: Hashable { + values = [MatchBox(arg1)] + descriptor = [Arg1.self] + } + + init(_ arg1: Arg1, _ arg2: Arg2) { + values = [arg1, arg2] + descriptor = [Arg1.self, Arg2.self] + } + + init(_ arg1: Arg1, _ arg2: Arg2) where Arg1: Hashable, Arg2: Hashable { + values = [MatchBox(arg1), MatchBox(arg2)] + descriptor = [Arg1.self, Arg2.self] + } + + init(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) { + values = [arg1, arg2, arg3] + descriptor = [Arg1.self, Arg2.self, Arg3.self] + } + + init(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { + values = [MatchBox(arg1), MatchBox(arg2), MatchBox(arg3)] + descriptor = [Arg1.self, Arg2.self, Arg3.self] + } + + init(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) { + values = [arg1, arg2, arg3, arg4] + descriptor = [Arg1.self, Arg2.self, Arg3.self, Arg4.self] + } + + init(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { + values = [MatchBox(arg1), MatchBox(arg2), MatchBox(arg3), MatchBox(arg4)] + descriptor = [Arg1.self, Arg2.self, Arg3.self, Arg4.self] + } + + init(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) { + values = [arg1, arg2, arg3, arg4, arg5] + descriptor = [Arg1.self, Arg2.self, Arg3.self, Arg4.self, Arg5.self] + } + + init(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { + values = [MatchBox(arg1), MatchBox(arg2), MatchBox(arg3), MatchBox(arg4), MatchBox(arg5)] + descriptor = [Arg1.self, Arg2.self, Arg3.self, Arg4.self, Arg5.self] + } + + init(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6) { + values = [arg1, arg2, arg3, arg4, arg5, arg6] + descriptor = [Arg1.self, Arg2.self, Arg3.self, Arg4.self, Arg5.self, Arg6.self] + } + + init(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6) where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable, Arg6: Hashable { + values = [MatchBox(arg1), MatchBox(arg2), MatchBox(arg3), MatchBox(arg4), MatchBox(arg5), MatchBox(arg6)] + descriptor = [Arg1.self, Arg2.self, Arg3.self, Arg4.self, Arg5.self, Arg6.self] + } + + init(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7) { + values = [arg1, arg2, arg3, arg4, arg5, arg6, arg7] + descriptor = [Arg1.self, Arg2.self, Arg3.self, Arg4.self, Arg5.self, Arg6.self, Arg7.self] + } + + init(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7) where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable, Arg6: Hashable, Arg7: Hashable { + values = [MatchBox(arg1), MatchBox(arg2), MatchBox(arg3), MatchBox(arg4), MatchBox(arg5), MatchBox(arg6), MatchBox(arg7)] + descriptor = [Arg1.self, Arg2.self, Arg3.self, Arg4.self, Arg5.self, Arg6.self, Arg7.self] + } + + init(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8) { + values = [arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8] + descriptor = [Arg1.self, Arg2.self, Arg3.self, Arg4.self, Arg5.self, Arg6.self, Arg7.self, Arg8.self] + } + + init(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8) where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable, Arg6: Hashable, Arg7: Hashable, Arg8: Hashable { + values = [MatchBox(arg1), MatchBox(arg2), MatchBox(arg3), MatchBox(arg4), MatchBox(arg5), MatchBox(arg6), MatchBox(arg7), MatchBox(arg8)] + descriptor = [Arg1.self, Arg2.self, Arg3.self, Arg4.self, Arg5.self, Arg6.self, Arg7.self, Arg8.self] + } + + init(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8, _ arg9: Arg9) { + values = [arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9] + descriptor = [Arg1.self, Arg2.self, Arg3.self, Arg4.self, Arg5.self, Arg6.self, Arg7.self, Arg8.self, Arg9.self] + } + + init(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8, _ arg9: Arg9) where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable, Arg6: Hashable, Arg7: Hashable, Arg8: Hashable, Arg9: Hashable { + values = [MatchBox(arg1), MatchBox(arg2), MatchBox(arg3), MatchBox(arg4), MatchBox(arg5), MatchBox(arg6), MatchBox(arg7), MatchBox(arg8), MatchBox(arg9)] + descriptor = [Arg1.self, Arg2.self, Arg3.self, Arg4.self, Arg5.self, Arg6.self, Arg7.self, Arg8.self, Arg9.self] + } + + // sourcery:end +} diff --git a/Sources/Core/InstanceRequest.swift b/Sources/Core/InstanceRequest.swift index 5022f1b1..59fc9756 100644 --- a/Sources/Core/InstanceRequest.swift +++ b/Sources/Core/InstanceRequest.swift @@ -3,39 +3,25 @@ // protocol AnyInstanceRequest: Matchable { - var descriptor: TypeDescriptor { get } - var argument: Any { get } - var argumentType: Any.Type { get } + var type: TypeDescriptor { get } + var arguments: Arguments { get } } public struct InstanceRequest: AnyInstanceRequest, Hashable { - let descriptor: TypeDescriptor - let argument: Any - let argumentType: Any.Type - - public func hash(into hasher: inout Hasher) { - descriptor.hash(into: &hasher) - ObjectIdentifier(argumentType).hash(into: &hasher) - (argument as? Matchable)?.hash(into: &hasher) - } - - public static func == (lhs: InstanceRequest, rhs: InstanceRequest) -> Bool { - return lhs.descriptor == rhs.descriptor - && lhs.argumentType == rhs.argumentType - && areArgumentsEqual(lhs.argument, rhs.argument) - } + let type: TypeDescriptor + let arguments: Arguments } -func request( +func request( type: Type.Type = Type.self, tag: String?, - arg: Argument + arg: Arguments ) -> InstanceRequest { - return InstanceRequest(descriptor: tagged(type, with: tag), argument: arg, argumentType: Argument.self) + return InstanceRequest(type: tagged(type, with: tag), arguments: arg) } extension AnyInstanceRequest { func key(forContextType contextType: Any.Type) -> BindingKey { - return BindingKey(descriptor: descriptor, contextType: contextType, argumentType: argumentType) + return BindingKey(type: type, contextType: contextType, arguments: arguments.descriptor) } } diff --git a/Sources/Core/Matchable.swift b/Sources/Core/Matchable.swift index 335762c5..3954b580 100644 --- a/Sources/Core/Matchable.swift +++ b/Sources/Core/Matchable.swift @@ -13,77 +13,16 @@ public extension Matchable where Self: Equatable { } } -// swiftlint:disable line_length -// swiftlint:disable large_tuple -// sourcery:inline:MatchableBoxes -struct MatchableBox1: Hashable, Matchable where Arg1: Hashable { - let arg1: Arg1 +protocol AnyMatchBox: Matchable { + var anyValue: Any { get } } -struct MatchableBox2: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable { - let arg1: Arg1 - let arg2: Arg2 -} - -struct MatchableBox3: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - let arg1: Arg1 - let arg2: Arg2 - let arg3: Arg3 -} - -struct MatchableBox4: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - let arg1: Arg1 - let arg2: Arg2 - let arg3: Arg3 - let arg4: Arg4 -} - -struct MatchableBox5: Hashable, Matchable where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - let arg1: Arg1 - let arg2: Arg2 - let arg3: Arg3 - let arg4: Arg4 - let arg5: Arg5 -} - -func box(_ arg1: Arg1) -> Arg1 { - return arg1 -} - -func box(_ arg1: Arg1) -> MatchableBox1 where Arg1: Hashable { - return MatchableBox1(arg1: arg1) -} - -func box(_ arg1: Arg1, _ arg2: Arg2) -> (Arg1, Arg2) { - return (arg1, arg2) -} +struct MatchBox: Hashable, AnyMatchBox where Value: Hashable { + let value: Value -func box(_ arg1: Arg1, _ arg2: Arg2) -> MatchableBox2 where Arg1: Hashable, Arg2: Hashable { - return MatchableBox2(arg1: arg1, arg2: arg2) -} - -func box(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> (Arg1, Arg2, Arg3) { - return (arg1, arg2, arg3) -} - -func box(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> MatchableBox3 where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - return MatchableBox3(arg1: arg1, arg2: arg2, arg3: arg3) -} - -func box(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> (Arg1, Arg2, Arg3, Arg4) { - return (arg1, arg2, arg3, arg4) -} - -func box(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> MatchableBox4 where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return MatchableBox4(arg1: arg1, arg2: arg2, arg3: arg3, arg4: arg4) -} - -func box(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> (Arg1, Arg2, Arg3, Arg4, Arg5) { - return (arg1, arg2, arg3, arg4, arg5) -} + init(_ value: Value) { + self.value = value + } -func box(_ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> MatchableBox5 where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return MatchableBox5(arg1: arg1, arg2: arg2, arg3: arg3, arg4: arg4, arg5: arg5) + var anyValue: Any { return value } } - -// sourcery:end diff --git a/Sources/Core/PropertyWrapper.swift b/Sources/Core/PropertyWrapper.swift index c1dbc16d..ed8fd012 100644 --- a/Sources/Core/PropertyWrapper.swift +++ b/Sources/Core/PropertyWrapper.swift @@ -30,12 +30,11 @@ extension PropertyWrapper { extension AnyInstanceRequest { func replacingType(with _: Type.Type) -> InstanceRequest { return InstanceRequest( - descriptor: TypeDescriptor( - tag: descriptor.tag, + type: TypeDescriptor( + tag: type.tag, type: Type.self ), - argument: argument, - argumentType: argumentType + arguments: arguments ) } } diff --git a/Sources/Core/ScopeRegistryKey.swift b/Sources/Core/ScopeRegistryKey.swift index 0c23fc1d..4ce14f6b 100644 --- a/Sources/Core/ScopeRegistryKey.swift +++ b/Sources/Core/ScopeRegistryKey.swift @@ -2,26 +2,7 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -public struct ScopeRegistryKey { +public struct ScopeRegistryKey: Hashable { let descriptor: TypeDescriptor - let argument: Any -} - -extension ScopeRegistryKey: Hashable { - public static func == (lhs: ScopeRegistryKey, rhs: ScopeRegistryKey) -> Bool { - return lhs.descriptor == rhs.descriptor && areArgumentsEqual(lhs.argument, rhs.argument) - } - - public func hash(into hasher: inout Hasher) { - descriptor.hash(into: &hasher) - (argument as? Matchable)?.hash(into: &hasher) - } -} - -func areArgumentsEqual(_ lhs: Any, _ rhs: Any) -> Bool { - switch (lhs, rhs) { - case let (lhs as Matchable, _): return lhs.matches(rhs) - case let (_, rhs as Matchable): return rhs.matches(lhs) - default: return true - } + let arguments: Arguments } diff --git a/Sources/Core/Swinject.swift b/Sources/Core/Swinject.swift index 4b0445cb..63b74c9d 100644 --- a/Sources/Core/Swinject.swift +++ b/Sources/Core/Swinject.swift @@ -25,7 +25,7 @@ extension Swinject: Resolver { if let custom = resolve(request, asCustom: Type.self) { return custom } throw error } - return try tracking(request).makeInstance(from: binding, arg: request.argument) + return try tracking(request).makeInstance(from: binding, with: request.arguments) } public func on(_ context: Context) -> Resolver { @@ -77,8 +77,8 @@ extension Swinject { return bindings[0] } - private func makeInstance(from binding: AnyBinding, arg: Argument) throws -> Type { - return try binding.makeInstance(resolver: self, arg: arg) as? Type ?? { throw SwinjectError() }() + private func makeInstance(from binding: AnyBinding, with arguments: Arguments) throws -> Type { + return try binding.makeInstance(resolver: self, arguments: arguments) as? Type ?? { throw SwinjectError() }() } } diff --git a/Sources/Core/SwinjectError.swift b/Sources/Core/SwinjectError.swift index c56de058..cd8a2d4c 100644 --- a/Sources/Core/SwinjectError.swift +++ b/Sources/Core/SwinjectError.swift @@ -20,5 +20,7 @@ public class NothingToOverride: SwinjectError {} public class SilentOverrideNotAllowed: SwinjectError {} public class NoContextTranslator: SwinjectError {} public class CircularDependency: SwinjectError {} +public class MissingArgument: SwinjectError {} +public class ArgumentMismatch: SwinjectError {} // TODO: Debugging error description diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 1412ef89..8d66822c 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -7,27 +7,32 @@ objects = { /* Begin PBXBuildFile section */ + 000151E30A8F1EEAEA54B2EC /* Binding+Factory.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDAE85794B8BBB70A76A0016 /* Binding+Factory.swift */; }; 004B06007E4FDD8F44B7EC89 /* ModulesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75BE3AE3E30DFE42A919D825 /* ModulesSpec.swift */; }; 0068DAA4AA322F00AF53731F /* ScopesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D3C59E84B5FD0C13F487838 /* ScopesSpec.swift */; }; 0207493E1CEE8456E91E3DAE /* BindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E59A67F3548663368788B17 /* BindingSpec.swift */; }; 020DA1718FCC68D889FB5A5F /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3586A4987B7C7C8122D674E /* SwinjectError.swift */; }; 02410BD4FB357F4C6B521608 /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; 02556F149C9AAEF5CE353AC1 /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; - 027015812E961322FE3D942B /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57F4D977AC4289A6145383C9 /* InstanceRequest.swift */; }; 03122D1B2EA65C89ADC78EC7 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62682D6ED38742996624B041 /* BasicAssembly.swift */; }; 0509EE8D41BF354EB91ACC80 /* Reference.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73B4B777290FF5D38A8914CC /* Reference.swift */; }; 0622539110A7430776A307C7 /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42490D1D0C395951243F5CFF /* Container.swift */; }; 06363AE7650CA288BDF6CB73 /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 34AFFAC41BA9D02A38BDB7A3 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 06CD85528AABB15BDFBF3166 /* RetrievalSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D8B3342E2AC3236F12072F5 /* RetrievalSpec.swift */; }; + 06D09D88E514CCA11D101AFB /* Retrieval.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28D11412EEA912FD369E0D4B /* Retrieval.swift */; }; 06F4CAB352B4F623FF7BD885 /* ScopeRegistryKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */; }; 0720BEA814AD514378380ACB /* StandardScopeRegistrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */; }; 0781579818FC4A2CA1CD3CAE /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */; }; + 082EBD694ADF41DB4C53BD5A /* InstanceRequest+Api.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 076C2114835DCF003BE040B7 /* InstanceRequest+Api.swifttemplate */; }; 0B61DC733616A8ED4ED77FA7 /* StandardScopeRegistrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */; }; + 0CB78F196D83DC32125402D3 /* Binding+Factory.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDAE85794B8BBB70A76A0016 /* Binding+Factory.swift */; }; 0CD787EACEBFD1051D358E7D /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; 0CE1126436F680F9684837E4 /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; 0CE158916595980A7C8272D3 /* SingletonSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46F05CC591903E2B04B6D8ED /* SingletonSpec.swift */; }; 0D5C4A278A16AB3A163148AF /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; + 128913D570B4A8BBF40866BE /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; 14C8DA4FCCDFA87885038D38 /* PropertyWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 424C647FF08FCB7C2A54E085 /* PropertyWrapper.swift */; }; + 168224D6B76AF22325307EB6 /* AnyBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 020903EC58FDC4727852CAF4 /* AnyBinding.swift */; }; 180DB4397B4C05E26F819C85 /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADA1541ABC1365DFD7E3377F /* Food.swift */; }; 18AAA07DCD6FAB4A7D7E8B76 /* OverrideSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86C18DDD83715886DF7F1818 /* OverrideSpec.swift */; }; 19416C867F15E88394A0ABD1 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */; }; @@ -38,19 +43,21 @@ 1A68A8D05D9974002BF34CF8 /* RetrievalSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D8B3342E2AC3236F12072F5 /* RetrievalSpec.swift */; }; 1AC00BCB4DB26B078203DAD8 /* Resolver+FunctionCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F626B9D3E547621787E4D7 /* Resolver+FunctionCall.swift */; }; 1C62135FAE3D64DC7BFBF861 /* ContextSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */; }; - 1C82BFD00FCC384DB3AE6A89 /* MatchableBoxes.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 808C1063CA90CC593C7E0E9C /* MatchableBoxes.swifttemplate */; }; + 1C82BFD00FCC384DB3AE6A89 /* ArgumentVariations.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 808C1063CA90CC593C7E0E9C /* ArgumentVariations.swifttemplate */; }; 1CA5DF3F93203B226A6FA059 /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EA566CD336DB8343ADFAF9B /* BehaviorFakes.swift */; }; - 1D17DBC27F25717BF7A87AF3 /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57F4D977AC4289A6145383C9 /* InstanceRequest.swift */; }; 1ED6BD68D92F4FE60978EF22 /* Container+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDA78290D6D60BD0B808571F /* Container+Logging.swift */; }; + 1FB4AED93C9EEF9760913558 /* Binding+Factory.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = E8A39A3F1C11C85BF0D0A9B1 /* Binding+Factory.swifttemplate */; }; 21285CED416F1317E993397A /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59A3946B59EB4D787CCE9F2 /* Container+Registration.swift */; }; 233F3E25FF0B51A3E6611F58 /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; 2615FC1C92B7E381116B9E57 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; 26C4C6118D189E8813ABD5A2 /* Quick.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = C765B92B00C0AC8625BB4AC9 /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 27285F3D5FC1115A22B830F8 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96873D000ADA6FC81B346488 /* Binding.swift */; }; 283C77045DA55C2134EC9C48 /* Container+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F446D6BD4C44E16A1D608BFB /* Container+TypeForwarding.swift */; }; + 28E140284EE255E55B45E4CF /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96873D000ADA6FC81B346488 /* Binding.swift */; }; 290C9E9420A1EE30456476CB /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59111BE319C59E4CD6CF68CD /* Assembler.swift */; }; 293985649250DF270DC89135 /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; 2AA60B7E6EBA9EC6BE92D7CB /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; - 2B506344F37CE5F5C5C02C05 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; + 2B13DD3C7FA3288A959A0928 /* Binding+Api.swift in Sources */ = {isa = PBXBuildFile; fileRef = C603FD109D6B1496A21B2F8D /* Binding+Api.swift */; }; 2C352AAD1AC7D82A4A059046 /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; 2C3EB507FFA03D18B2909405 /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8B9785AAE94A5447FA307242 /* Swinject.framework */; }; 2CB057F2A16DA462E0517AAB /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; @@ -71,14 +78,15 @@ 389C54E04DD794DA4F648571 /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */; }; 39AE6864444BC1CE491142E5 /* CIrcularitySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 118ABC654C4144496848AD74 /* CIrcularitySpec.swift */; }; 3A0B409E840B44B281DB3C54 /* Container+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F446D6BD4C44E16A1D608BFB /* Container+TypeForwarding.swift */; }; + 3A6E6708B2EF95B9A6491213 /* InstanceRequestVariation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22F5FE25C34A0D7124528088 /* InstanceRequestVariation.swift */; }; + 3AB62DA4D297295283ABE1AE /* ValueRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B5EE429B22E5A993ABBC347 /* ValueRequest.swift */; }; 3BD6055555A5C30DABDC8ED2 /* Reference.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73B4B777290FF5D38A8914CC /* Reference.swift */; }; - 3BDB44DE92D2377334894804 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; 3C270A77DE4F1E6BC2F8E863 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; 3CEF021295AD9AF9BF26B71E /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; 3DEFB7CA42D9EFF0B4FBC0F4 /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 38BCCF3F950869BD1891F7A8 /* Swinject.framework */; }; 3EC8383BEAC339595CF7F927 /* Resolver+FunctionCallApi.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 176824B29DD1A0DAA5CBD241 /* Resolver+FunctionCallApi.swifttemplate */; }; - 3F8F5645D6D37FCEC1D89393 /* AnyBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B580B43E1891812C97209 /* AnyBinding.swift */; }; 401592294E5D528379BE1AB2 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62682D6ED38742996624B041 /* BasicAssembly.swift */; }; + 41BD3DC77CA877DB46844B18 /* Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDDA125B54235F76F7A34730 /* Arguments.swift */; }; 41C7340BFD2EB66359772733 /* Resolver+LegacyApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A784E2DEC7691D14DDBECD8 /* Resolver+LegacyApi.swift */; }; 42FE916C1593A9289E1A28BC /* InjectionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 670DB253ECD5CE1468A7F2E3 /* InjectionSpec.swift */; }; 4347EE17D0C0ED574C899D85 /* ScopeRegistryKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */; }; @@ -88,12 +96,15 @@ 4954CBB07E38E98752AC3347 /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; 49685AB40BEE856C62005C87 /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; 49D71F6CC12C12FE7B6A097A /* ContextSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */; }; + 4B9B0B0F61359DC8C25C36A5 /* Binding+Api.swift in Sources */ = {isa = PBXBuildFile; fileRef = C603FD109D6B1496A21B2F8D /* Binding+Api.swift */; }; 4D86550CC5C281A58B4A6F61 /* SwinjectContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8C4916168E81D76536892122 /* SwinjectContainer.swift */; }; 4DF3DC1CDD3C4948F9BDD3DF /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3586A4987B7C7C8122D674E /* SwinjectError.swift */; }; 4E4DC8CDD1BA51FB66A332C2 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */; }; 4EC94A51037C79DE0C5C8CB1 /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; 4EE5C1207C57C85A928FA89B /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 273FB7A6277E0841E1570990 /* Nimble.framework */; }; + 4FACFC5F59982A6EDA7F8E4D /* InstanceRequest+APi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 980BDFC415DEF2099DF9E89A /* InstanceRequest+APi.swift */; }; 5393E5DE21B568A88498E454 /* PropertyWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 424C647FF08FCB7C2A54E085 /* PropertyWrapper.swift */; }; + 53EBF7A46EF65F2A8DAADC7A /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; 546FF827DB6D42490D1CA439 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; 54956014A1774DF8357B69E6 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; 55CA3AA3F28B7CC221ABEC83 /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6D54F152C11C966ECFC55ECB /* Swinject.framework */; }; @@ -105,6 +116,7 @@ 593B93BA2EE3FE4418A1C579 /* ScopeRegistryKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */; }; 599C7F009F954CDA522244B3 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62682D6ED38742996624B041 /* BasicAssembly.swift */; }; 59FD1167CD4A913E04D3EAFD /* ServiceEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38615FC8EEB466C5C1EAD21C /* ServiceEntry.swift */; }; + 5A74DF28BBEBC4E494E67162 /* AnyBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 020903EC58FDC4727852CAF4 /* AnyBinding.swift */; }; 5A78C354D420D64CF8A787C1 /* Resolver+FunctionCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F626B9D3E547621787E4D7 /* Resolver+FunctionCall.swift */; }; 5BD767B85CFE5FADDFE0A7B5 /* UnboundScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 667B13B528642272FC0794B6 /* UnboundScope.swift */; }; 5C56C1E893D53B2311D27416 /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */; }; @@ -114,10 +126,13 @@ 5F1647DCC0D437A782647372 /* PropertyWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 424C647FF08FCB7C2A54E085 /* PropertyWrapper.swift */; }; 5FCE2A2AE5DD0DBECA4A9953 /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */; }; 6034CF5459D96497AF36E4B6 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; + 603BD4D9FBE1B2A5916967CA /* Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDDA125B54235F76F7A34730 /* Arguments.swift */; }; 628EBFBA0031B1FA2E29F583 /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 351C4221896DDB8572BD6CB5 /* Person.swift */; }; 63528D45A548DD58D748D54C /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; + 6405B24BE522A98AEB275E7D /* Retrieval.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28D11412EEA912FD369E0D4B /* Retrieval.swift */; }; 640F7A55D9A671FA112C8083 /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; - 658AEDC8D802A6788E959E0C /* AnyBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B580B43E1891812C97209 /* AnyBinding.swift */; }; + 64703514AB8130B7808F7180 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96873D000ADA6FC81B346488 /* Binding.swift */; }; + 67A273EEFC4769951013DCEA /* Binding+Factory.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDAE85794B8BBB70A76A0016 /* Binding+Factory.swift */; }; 68C95FCB0D345CA3BA24D320 /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; 68D828A3C583DDD28CFE882B /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; 6922AE734E84B515C94D9480 /* SwinjectTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */; }; @@ -127,6 +142,7 @@ 6A967AE5710606998C2BE070 /* PropertyWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 424C647FF08FCB7C2A54E085 /* PropertyWrapper.swift */; }; 6BB1E24C1CE55C9F6EA6CC28 /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C765B92B00C0AC8625BB4AC9 /* Quick.framework */; }; 6C01E868DE44BD396D94858B /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; + 6D10D2E438AA642300483BF1 /* Retrieval.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28D11412EEA912FD369E0D4B /* Retrieval.swift */; }; 6DA49F84E2592B32F81F268B /* ObjectScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BFF4BA99493C54260878C4 /* ObjectScope.swift */; }; 6DD80811E5FD658CAFEEA647 /* CIrcularitySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 118ABC654C4144496848AD74 /* CIrcularitySpec.swift */; }; 6F6FAD0EEF84580DD53BB755 /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1C58FC14EEA170B0DC079DE4 /* Quick.framework */; }; @@ -142,37 +158,19 @@ 74E1FC692A27C56510363364 /* Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = F290F6B1207A0557A528220B /* Assembly.swift */; }; 751F545653B0F1E30341C312 /* OverrideSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86C18DDD83715886DF7F1818 /* OverrideSpec.swift */; }; 75D74C8C25EDACF5A7A75A5C /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; - 76FB9AFE299316E7F3F4C3BB /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57F4D977AC4289A6145383C9 /* InstanceRequest.swift */; }; - 77316670231176B20002655B /* InstanceRequest+APi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7731666F231176B20002655B /* InstanceRequest+APi.swift */; }; - 77316671231176B40002655B /* InstanceRequest+APi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7731666F231176B20002655B /* InstanceRequest+APi.swift */; }; - 77316672231176B50002655B /* InstanceRequest+APi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7731666F231176B20002655B /* InstanceRequest+APi.swift */; }; - 77316673231176B50002655B /* InstanceRequest+APi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7731666F231176B20002655B /* InstanceRequest+APi.swift */; }; - 77316675231177580002655B /* InstanceRequestVariation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77316674231177580002655B /* InstanceRequestVariation.swift */; }; - 773166772311787D0002655B /* InstanceRequest+Api.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 773166762311787D0002655B /* InstanceRequest+Api.swifttemplate */; }; - 773166792311854B0002655B /* Retrieval.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773166782311854B0002655B /* Retrieval.swift */; }; - 7731667A231187470002655B /* Retrieval.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773166782311854B0002655B /* Retrieval.swift */; }; - 7731667B231187480002655B /* Retrieval.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773166782311854B0002655B /* Retrieval.swift */; }; - 7731667C231187480002655B /* Retrieval.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773166782311854B0002655B /* Retrieval.swift */; }; - 773BE491231124AD000AA1A9 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773C6DDB23111956007A40BF /* Binding.swift */; }; - 773C6DDC23111956007A40BF /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773C6DDB23111956007A40BF /* Binding.swift */; }; - 773C6DDD23111956007A40BF /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773C6DDB23111956007A40BF /* Binding.swift */; }; - 773C6DDE23111956007A40BF /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 773C6DDB23111956007A40BF /* Binding.swift */; }; 778D9AB6470D4280254AC140 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; - 77B87F3C23112DB100321C08 /* Binding+Api.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77B87F3B23112DB100321C08 /* Binding+Api.swift */; }; - 77B87F3E231153D200321C08 /* FactoryVariation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77B87F3D231153D200321C08 /* FactoryVariation.swift */; }; - 77B87F40231155B300321C08 /* Binding+Factory.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 77B87F3F231155B300321C08 /* Binding+Factory.swifttemplate */; }; - 77B87F43231157E900321C08 /* Binding+Factory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77B87F41231157B200321C08 /* Binding+Factory.swift */; }; - 77B87F44231157E900321C08 /* Binding+Factory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77B87F41231157B200321C08 /* Binding+Factory.swift */; }; - 77B87F45231157EA00321C08 /* Binding+Factory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77B87F41231157B200321C08 /* Binding+Factory.swift */; }; - 77B87F46231157EA00321C08 /* Binding+Factory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77B87F41231157B200321C08 /* Binding+Factory.swift */; }; - 77B87F472311580500321C08 /* Binding+Api.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77B87F3B23112DB100321C08 /* Binding+Api.swift */; }; - 77B87F482311580600321C08 /* Binding+Api.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77B87F3B23112DB100321C08 /* Binding+Api.swift */; }; - 77B87F492311580600321C08 /* Binding+Api.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77B87F3B23112DB100321C08 /* Binding+Api.swift */; }; 77BF219EAB4FC8475943CECC /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6D434EB4C13CF9D9FA6D80CB /* Swinject.framework */; }; - 77ED80052311221600AC48F9 /* ValueRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77ED80042311221600AC48F9 /* ValueRequest.swift */; }; - 77ED80062311221600AC48F9 /* ValueRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77ED80042311221600AC48F9 /* ValueRequest.swift */; }; - 77ED80072311221600AC48F9 /* ValueRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77ED80042311221600AC48F9 /* ValueRequest.swift */; }; - 77ED80082311221600AC48F9 /* ValueRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77ED80042311221600AC48F9 /* ValueRequest.swift */; }; + 77F957ED23127CB800FD392A /* LinuxConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 938425B216B78A06EC10504A /* LinuxConfig.swift */; }; + 77F957EE23127CB800FD392A /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; + 77F957EF23127CB800FD392A /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; + 77F957F023127CB800FD392A /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; + 77F957F123127CB800FD392A /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; + 77F957F223127CB800FD392A /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; + 77F957F323127CB800FD392A /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; + 77F957F423127CB800FD392A /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; + 77F957F523127CB800FD392A /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; + 77F957F623127CB800FD392A /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; + 77F957F723127CB800FD392A /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; 789BF74652A2424EB8F7EF47 /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 7A7032384E07DAD308D4F70A /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 8B9785AAE94A5447FA307242 /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 7D6F664091C70BABBFB61D53 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; @@ -181,12 +179,12 @@ 818DF17D671EA1022CE59A2A /* InjectionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 670DB253ECD5CE1468A7F2E3 /* InjectionSpec.swift */; }; 820307073A53AED47AC99B8D /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3586A4987B7C7C8122D674E /* SwinjectError.swift */; }; 82299769BC637A14E7827DB0 /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1E726A651C3AFE92C19608B /* SwinjectModule.swift */; }; - 826D63FA91E370F0061768B0 /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57F4D977AC4289A6145383C9 /* InstanceRequest.swift */; }; 829853126CDB7464599AFC85 /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; 832C9ABB8DCF5340D796F5F8 /* ContextSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */; }; - 83464EDC08380F5CE2190F30 /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; + 83CDF14784F813ABD8E00933 /* AnyBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 020903EC58FDC4727852CAF4 /* AnyBinding.swift */; }; 8436D091ED844817C8CE3AF2 /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; 86CBC40FDC90E2A2051386C5 /* ContextSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */; }; + 875D809B53B3A118AAF1348C /* Retrieval.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28D11412EEA912FD369E0D4B /* Retrieval.swift */; }; 87FEAEF562B99522083CB87D /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; 890CCD2800597F6FB7C6FD31 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; 8A4E9E736239F92F878C070C /* Resolver+FunctionCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F626B9D3E547621787E4D7 /* Resolver+FunctionCall.swift */; }; @@ -197,12 +195,12 @@ 90C399A2AF93F0897169E413 /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96AEC72A42A227A50CF9845B /* Circularity.swift */; }; 91E435894038C42335086FA8 /* SwinjectError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3586A4987B7C7C8122D674E /* SwinjectError.swift */; }; 920DE2CAB9895D10FAE48FBA /* ScopeRegistryKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */; }; + 921406E8219BBDAFE2BEEDD6 /* InstanceRequest+APi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 980BDFC415DEF2099DF9E89A /* InstanceRequest+APi.swift */; }; 934AFACA6BFF24AD3503F98D /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */; }; 93BCD12CEFB88BAD49BEA431 /* ServiceEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38615FC8EEB466C5C1EAD21C /* ServiceEntry.swift */; }; 95A6654089875BCC863FB53B /* InjectionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 670DB253ECD5CE1468A7F2E3 /* InjectionSpec.swift */; }; 95E6DD9D94BE64420EEC1298 /* Weak.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57A7E35B2B22650208F904B8 /* Weak.swift */; }; 96EA0A5DF33F025EBE0B67D2 /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; - 979518E078B187549E11DF48 /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; 97C2EA47D7623AFD723AFE93 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */; }; 980FED1DBC62B65597E2828B /* SingletonSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46F05CC591903E2B04B6D8ED /* SingletonSpec.swift */; }; 98322F9371E1A8461BC614D1 /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; @@ -212,16 +210,20 @@ 99C5D861B16FAFAD3F9E28C5 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */; }; 9A21ECA8F283E1E144CEC763 /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; 9A2A6978519F2BBA97DA6EA6 /* BindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E59A67F3548663368788B17 /* BindingSpec.swift */; }; + 9A8E74FAA81B2E5A1903371A /* AnyBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 020903EC58FDC4727852CAF4 /* AnyBinding.swift */; }; 9AA68475ABE3E7502F59216D /* PropertyWrappersSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49B24254B9F0E48ED3713565 /* PropertyWrappersSpec.swift */; }; 9CCAB8EE342CCC8D2FB187C1 /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */; }; 9CEE20BD42795D5E5F39BF20 /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; + 9DEAC620F2F00D0DDD3B5D3E /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; A1A2D0FA98038EACAC04E64C /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; A2D3B18BE38948A427B60BC5 /* LoadAwareAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61EE5DDBE705B47AFC9A6986 /* LoadAwareAssembly.swift */; }; + A2E179234F7C8526A1A9BF87 /* Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDDA125B54235F76F7A34730 /* Arguments.swift */; }; A308578B99D33C7E33632E85 /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; A3BFFED76688F149FBAF7C53 /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EA566CD336DB8343ADFAF9B /* BehaviorFakes.swift */; }; A453A5A7E0EC0FE161AA34D5 /* OptionalsSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50D6F2639990DD5BAD9578B0 /* OptionalsSpec.swift */; }; A53B5A8E2188F8C4A3F29C2E /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BC5108ED11A3A3084D864CC /* Animal.swift */; }; A59C6C434288333EDAF951C4 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */; }; + A5AD538F6D2C7CB0BE4EFF8C /* ValueRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B5EE429B22E5A993ABBC347 /* ValueRequest.swift */; }; A5E4C79F89E1A8AB3A4D8D6E /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59A3946B59EB4D787CCE9F2 /* Container+Registration.swift */; }; A6721BA534AD082E1E7C1D08 /* SwinjectContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8C4916168E81D76536892122 /* SwinjectContainer.swift */; }; A6EECC339FA54CA0BBFF4146 /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BC5108ED11A3A3084D864CC /* Animal.swift */; }; @@ -232,7 +234,6 @@ A882705E4199EF759E80B311 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; A9112F7CF871475B94A077D7 /* Resolver+FunctionCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F626B9D3E547621787E4D7 /* Resolver+FunctionCall.swift */; }; A91EDAFBC3606EDFBD739899 /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */; }; - A9A242086D1EDE408DC556D0 /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; AAC6F2F5EC2928943BF2BED1 /* PropertyWrappersSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49B24254B9F0E48ED3713565 /* PropertyWrappersSpec.swift */; }; AAD8D0551B8A26A9B22AECEC /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59A3946B59EB4D787CCE9F2 /* Container+Registration.swift */; }; AC470B4322599B0A076DD3FF /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; @@ -253,8 +254,8 @@ B65DE0B0562540CC8CEC48F3 /* SingletonSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46F05CC591903E2B04B6D8ED /* SingletonSpec.swift */; }; B7653A6427A5E284E9A1D6D3 /* ServiceEntry+TypeForwarding.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */; }; B84167AC8C6BEB57C4D0695A /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; + B90A5B58E1DF17A63B093BE5 /* Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDDA125B54235F76F7A34730 /* Arguments.swift */; }; B9550BE2BA6FA5731BEC87FD /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; - B96A6370D549AAC383360ABC /* LinuxConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 938425B216B78A06EC10504A /* LinuxConfig.swift */; }; BB571B9A78FC53231A18E18C /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; BB64AE6DFE526629918211B7 /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96AEC72A42A227A50CF9845B /* Circularity.swift */; }; BB77A5D81C58392964D07233 /* BindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E59A67F3548663368788B17 /* BindingSpec.swift */; }; @@ -263,6 +264,7 @@ BD08D3E155AFD841CFECA0AD /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BC5108ED11A3A3084D864CC /* Animal.swift */; }; BD9B57E26722C80B7EF990DB /* Container+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F446D6BD4C44E16A1D608BFB /* Container+TypeForwarding.swift */; }; BE3A8FAC5AC745EDCCD5A5FB /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 6D54F152C11C966ECFC55ECB /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + BE4601421B552E315C828F82 /* Binding+Api.swift in Sources */ = {isa = PBXBuildFile; fileRef = C603FD109D6B1496A21B2F8D /* Binding+Api.swift */; }; BE6C13A3492E3CFC08E231B0 /* Food.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADA1541ABC1365DFD7E3377F /* Food.swift */; }; BE94EF7BCF976A703F961389 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */; }; BEEFBE87EB17D56BA8D47358 /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 351C4221896DDB8572BD6CB5 /* Person.swift */; }; @@ -280,17 +282,17 @@ CAA5241DAA201FBB5818C803 /* BindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E59A67F3548663368788B17 /* BindingSpec.swift */; }; CB0B308F3D3A831A28127462 /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59A3946B59EB4D787CCE9F2 /* Container+Registration.swift */; }; CB9E8D16D7A0620A1F7A32A3 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; - CBBE28990E0EA82AD8D5E3AF /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; CDE8EA7EC1D8096F12BDD8C2 /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96AEC72A42A227A50CF9845B /* Circularity.swift */; }; + CDF8E0FFBFD4BB9E2758EBFE /* ValueRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B5EE429B22E5A993ABBC347 /* ValueRequest.swift */; }; CE5AFED22F04B96713ED76D7 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ADC44E9312C3B974AFD8F07B /* Nimble.framework */; }; + CECF5BD14BCDF5248771A06A /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; CEE763218A90832454A6E2DE /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */; }; CF4516872D3DA7118DB2B90B /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; CF4EBB60C21F8C503BCD7A29 /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1E726A651C3AFE92C19608B /* SwinjectModule.swift */; }; - CF9535A0DCAFF23F4D62F871 /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; + D06263E082BD076D53A297D6 /* Binding+Api.swift in Sources */ = {isa = PBXBuildFile; fileRef = C603FD109D6B1496A21B2F8D /* Binding+Api.swift */; }; D0D71F9C22A0EE82B6E4F61A /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 74DE57FB3E8228904E6FE0D7 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; D13208E63523A97A0B840283 /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BC5108ED11A3A3084D864CC /* Animal.swift */; }; D1DF4740A9D86362B63104B8 /* ContextTranslator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */; }; - D2BAE1CB997A4D052CB8EFC8 /* AnyBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B580B43E1891812C97209 /* AnyBinding.swift */; }; D3FB9F7B3F791A83FF86205C /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 273FB7A6277E0841E1570990 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; D3FD513CDD70AF674C453B83 /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96AEC72A42A227A50CF9845B /* Circularity.swift */; }; D4936DC1A47A8C85325FB52E /* Resolver+LegacyApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A784E2DEC7691D14DDBECD8 /* Resolver+LegacyApi.swift */; }; @@ -308,12 +310,10 @@ DCB7C4BF24782862BE9DB135 /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; DD29D2E60DA979D61F32A39A /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62682D6ED38742996624B041 /* BasicAssembly.swift */; }; DD5E3AF2B5FCE5E81EBDF606 /* ContextTranslator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */; }; - E01D0D443FBA4DB82A6EC298 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; E177D354B1F410129D921C69 /* Resolver+LegacyApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A784E2DEC7691D14DDBECD8 /* Resolver+LegacyApi.swift */; }; E227D08034E08AA0909BC043 /* RetrievalSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D8B3342E2AC3236F12072F5 /* RetrievalSpec.swift */; }; E39152E9059357CF0C9B21AF /* CIrcularitySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 118ABC654C4144496848AD74 /* CIrcularitySpec.swift */; }; E3EABE098DBFB561A20632E3 /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; - E5880DBBB91CC5F8F47FBF73 /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; E7D1045D25FAB592401DCAF0 /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; EA0D19F7DF0355C774B0F40B /* ScopesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D3C59E84B5FD0C13F487838 /* ScopesSpec.swift */; }; EB3420214A9E68A0247D0F2C /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 351C4221896DDB8572BD6CB5 /* Person.swift */; }; @@ -323,6 +323,7 @@ EE0D3637D2524AC1CD21780D /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 74DE57FB3E8228904E6FE0D7 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; EE35DF2D353E2C5110DA5C42 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; EEAD7E215908DF939ECCDCC9 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; + EEBB114E8A57F37E4F226482 /* InstanceRequest+APi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 980BDFC415DEF2099DF9E89A /* InstanceRequest+APi.swift */; }; EFD2F695B86E74C77F46B7D1 /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; F06DEB671A4B85ABB0E96E51 /* ContextTranslator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */; }; F1F3BA81462E2362374BD4C4 /* ModulesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75BE3AE3E30DFE42A919D825 /* ModulesSpec.swift */; }; @@ -333,11 +334,14 @@ F7979BE4BE1B1C7101D15E61 /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; F7CD04FB09FC7F18E9E001CF /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; F88700BAAFFB47B1BD4D3BFA /* Weak.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57A7E35B2B22650208F904B8 /* Weak.swift */; }; - F8EB47A631D482A0D7B621DE /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; - F9A4BF18B0085B7DCD3440EC /* AnyBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B580B43E1891812C97209 /* AnyBinding.swift */; }; + F9F9839490926ED7623ED4BE /* ValueRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B5EE429B22E5A993ABBC347 /* ValueRequest.swift */; }; FA805A162E989A22990B99AA /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; + FB3113365FAB20BE0A2DC2E7 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96873D000ADA6FC81B346488 /* Binding.swift */; }; + FB467C5FB6C6851FD1B6DB51 /* InstanceRequest+APi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 980BDFC415DEF2099DF9E89A /* InstanceRequest+APi.swift */; }; FC339851D7EEE4D17178CC1F /* Weak.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57A7E35B2B22650208F904B8 /* Weak.swift */; }; FD7B2663F2F931B78EB330EE /* Resolver+LegacyApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A784E2DEC7691D14DDBECD8 /* Resolver+LegacyApi.swift */; }; + FECBBFAB7336A166E1A46D95 /* Binding+Factory.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDAE85794B8BBB70A76A0016 /* Binding+Factory.swift */; }; + FEF6E60044D76ECC226411DD /* FactoryVariation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FBCA343BDC1493D29B286C2 /* FactoryVariation.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -455,12 +459,13 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 020903EC58FDC4727852CAF4 /* AnyBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnyBinding.swift; sourceTree = ""; }; 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.swift; sourceTree = ""; }; + 076C2114835DCF003BE040B7 /* InstanceRequest+Api.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "InstanceRequest+Api.swifttemplate"; sourceTree = ""; }; 09FC792715B1658721F76885 /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 0CA449690AE00F6300DE8ACA /* SwinjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 0D8B3342E2AC3236F12072F5 /* RetrievalSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RetrievalSpec.swift; sourceTree = ""; }; 0DC67CB109091002AB433A46 /* SwinjectTests.xctest */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.cfbundle; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - 0E0B580B43E1891812C97209 /* AnyBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnyBinding.swift; sourceTree = ""; }; 10480F2154EAA0414D4C1F55 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */ = {isa = PBXFileReference; lastKnownFileType = text.yaml; path = .swiftlint.yml; sourceTree = ""; }; 118ABC654C4144496848AD74 /* CIrcularitySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CIrcularitySpec.swift; sourceTree = ""; }; @@ -472,7 +477,9 @@ 1D3C59E84B5FD0C13F487838 /* ScopesSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopesSpec.swift; sourceTree = ""; }; 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Behavior.swift; sourceTree = ""; }; 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Arguments.swift; sourceTree = ""; }; + 22F5FE25C34A0D7124528088 /* InstanceRequestVariation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRequestVariation.swift; sourceTree = ""; }; 273FB7A6277E0841E1570990 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; + 28D11412EEA912FD369E0D4B /* Retrieval.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Retrieval.swift; sourceTree = ""; }; 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; 34AFFAC41BA9D02A38BDB7A3 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; 351C4221896DDB8572BD6CB5 /* Person.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Person.swift; sourceTree = ""; }; @@ -493,12 +500,12 @@ 5057BAB33984E3E33469452B /* Scope.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Scope.swift; sourceTree = ""; }; 50D6F2639990DD5BAD9578B0 /* OptionalsSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OptionalsSpec.swift; sourceTree = ""; }; 57A7E35B2B22650208F904B8 /* Weak.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Weak.swift; sourceTree = ""; }; - 57F4D977AC4289A6145383C9 /* InstanceRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRequest.swift; sourceTree = ""; }; 59111BE319C59E4CD6CF68CD /* Assembler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Assembler.swift; sourceTree = ""; }; 5AB605ED0F735221D0EB1D5F /* Convenience.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Convenience.swift; sourceTree = ""; }; 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Matchable.swift; sourceTree = ""; }; 5EA566CD336DB8343ADFAF9B /* BehaviorFakes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BehaviorFakes.swift; sourceTree = ""; }; 5F7BC1C4169BB4382C6D3E1F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 5FBCA343BDC1493D29B286C2 /* FactoryVariation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FactoryVariation.swift; sourceTree = ""; }; 61EE5DDBE705B47AFC9A6986 /* LoadAwareAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadAwareAssembly.swift; sourceTree = ""; }; 62682D6ED38742996624B041 /* BasicAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BasicAssembly.swift; sourceTree = ""; }; 667B13B528642272FC0794B6 /* UnboundScope.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnboundScope.swift; sourceTree = ""; }; @@ -513,20 +520,10 @@ 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.CustomStringConvertible.swift; sourceTree = ""; }; 74DE57FB3E8228904E6FE0D7 /* Swinject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Swinject.h; sourceTree = ""; }; 75BE3AE3E30DFE42A919D825 /* ModulesSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModulesSpec.swift; sourceTree = ""; }; - 7731666F231176B20002655B /* InstanceRequest+APi.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "InstanceRequest+APi.swift"; sourceTree = ""; }; - 77316674231177580002655B /* InstanceRequestVariation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRequestVariation.swift; sourceTree = ""; }; - 773166762311787D0002655B /* InstanceRequest+Api.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "InstanceRequest+Api.swifttemplate"; sourceTree = ""; }; - 773166782311854B0002655B /* Retrieval.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Retrieval.swift; sourceTree = ""; }; - 773C6DDB23111956007A40BF /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; - 77B87F3B23112DB100321C08 /* Binding+Api.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Binding+Api.swift"; sourceTree = ""; }; - 77B87F3D231153D200321C08 /* FactoryVariation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FactoryVariation.swift; sourceTree = ""; }; - 77B87F3F231155B300321C08 /* Binding+Factory.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Binding+Factory.swifttemplate"; sourceTree = ""; }; - 77B87F41231157B200321C08 /* Binding+Factory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Binding+Factory.swift"; sourceTree = ""; }; - 77ED80042311221600AC48F9 /* ValueRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ValueRequest.swift; sourceTree = ""; }; 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ServiceEntry+TypeForwarding.swift"; sourceTree = ""; }; 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextTranslator.swift; sourceTree = ""; }; 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistry.swift; sourceTree = ""; }; - 808C1063CA90CC593C7E0E9C /* MatchableBoxes.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = MatchableBoxes.swifttemplate; sourceTree = ""; }; + 808C1063CA90CC593C7E0E9C /* ArgumentVariations.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = ArgumentVariations.swifttemplate; sourceTree = ""; }; 823617F3B8A9192F56B13331 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; 86C18DDD83715886DF7F1818 /* OverrideSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OverrideSpec.swift; sourceTree = ""; }; 8B9785AAE94A5447FA307242 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -535,8 +532,11 @@ 90191C25A2D66E07C4E9CD73 /* SwiftCode.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = SwiftCode.swifttemplate; sourceTree = ""; }; 938425B216B78A06EC10504A /* LinuxConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinuxConfig.swift; sourceTree = ""; }; 9620155728133F451B31C0AD /* Swinject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Swinject.swift; sourceTree = ""; }; + 96873D000ADA6FC81B346488 /* Binding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Binding.swift; sourceTree = ""; }; 96AEC72A42A227A50CF9845B /* Circularity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Circularity.swift; sourceTree = ""; }; + 980BDFC415DEF2099DF9E89A /* InstanceRequest+APi.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "InstanceRequest+APi.swift"; sourceTree = ""; }; 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistryKey.swift; sourceTree = ""; }; + 9B5EE429B22E5A993ABBC347 /* ValueRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ValueRequest.swift; sourceTree = ""; }; A20C1319AF31EC7F8E6945FE /* SwinjectTests.xctest */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.cfbundle; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; A3586A4987B7C7C8122D674E /* SwinjectError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectError.swift; sourceTree = ""; }; A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Resolver.swift; sourceTree = ""; }; @@ -550,11 +550,16 @@ BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "ServiceEntry+TypeForwarding.swifttemplate"; sourceTree = ""; }; BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Behavior.swift; sourceTree = ""; }; C1E726A651C3AFE92C19608B /* SwinjectModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectModule.swift; sourceTree = ""; }; + C603FD109D6B1496A21B2F8D /* Binding+Api.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Binding+Api.swift"; sourceTree = ""; }; C765B92B00C0AC8625BB4AC9 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; CDA78290D6D60BD0B808571F /* Container+Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Logging.swift"; sourceTree = ""; }; CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Container+Registration.swifttemplate"; sourceTree = ""; }; DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextSpec.swift; sourceTree = ""; }; + DDAE85794B8BBB70A76A0016 /* Binding+Factory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Binding+Factory.swift"; sourceTree = ""; }; + DDDA125B54235F76F7A34730 /* Arguments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Arguments.swift; sourceTree = ""; }; + E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRequest.swift; sourceTree = ""; }; E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeDescriptor.swift; sourceTree = ""; }; + E8A39A3F1C11C85BF0D0A9B1 /* Binding+Factory.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Binding+Factory.swifttemplate"; sourceTree = ""; }; F290F6B1207A0557A528220B /* Assembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Assembly.swift; sourceTree = ""; }; F446D6BD4C44E16A1D608BFB /* Container+TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+TypeForwarding.swift"; sourceTree = ""; }; F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.TypeForwarding.swift; sourceTree = ""; }; @@ -608,12 +613,12 @@ 07354387D49F6D7BBBA4F3AC /* Templates */ = { isa = PBXGroup; children = ( - 77B87F3D231153D200321C08 /* FactoryVariation.swift */, - 77B87F3F231155B300321C08 /* Binding+Factory.swifttemplate */, + E8A39A3F1C11C85BF0D0A9B1 /* Binding+Factory.swifttemplate */, CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */, - 77316674231177580002655B /* InstanceRequestVariation.swift */, - 773166762311787D0002655B /* InstanceRequest+Api.swifttemplate */, - 808C1063CA90CC593C7E0E9C /* MatchableBoxes.swifttemplate */, + 5FBCA343BDC1493D29B286C2 /* FactoryVariation.swift */, + 076C2114835DCF003BE040B7 /* InstanceRequest+Api.swifttemplate */, + 22F5FE25C34A0D7124528088 /* InstanceRequestVariation.swift */, + 808C1063CA90CC593C7E0E9C /* ArgumentVariations.swifttemplate */, 176824B29DD1A0DAA5CBD241 /* Resolver+FunctionCallApi.swifttemplate */, FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */, BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */, @@ -659,16 +664,16 @@ 2D9982F0E5050BAE1832702E /* 3.0 API */ = { isa = PBXGroup; children = ( - 773C6DDB23111956007A40BF /* Binding.swift */, - 77ED80042311221600AC48F9 /* ValueRequest.swift */, - 77B87F3B23112DB100321C08 /* Binding+Api.swift */, - 77B87F41231157B200321C08 /* Binding+Factory.swift */, + 96873D000ADA6FC81B346488 /* Binding.swift */, + C603FD109D6B1496A21B2F8D /* Binding+Api.swift */, + DDAE85794B8BBB70A76A0016 /* Binding+Factory.swift */, + 980BDFC415DEF2099DF9E89A /* InstanceRequest+APi.swift */, B9F626B9D3E547621787E4D7 /* Resolver+FunctionCall.swift */, + 28D11412EEA912FD369E0D4B /* Retrieval.swift */, 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */, 667B13B528642272FC0794B6 /* UnboundScope.swift */, + 9B5EE429B22E5A993ABBC347 /* ValueRequest.swift */, 57A7E35B2B22650208F904B8 /* Weak.swift */, - 7731666F231176B20002655B /* InstanceRequest+APi.swift */, - 773166782311854B0002655B /* Retrieval.swift */, ); path = "3.0 API"; sourceTree = ""; @@ -843,9 +848,10 @@ FCA9C6262A4D071C8E7EEBD0 /* Core */ = { isa = PBXGroup; children = ( - 0E0B580B43E1891812C97209 /* AnyBinding.swift */, + 020903EC58FDC4727852CAF4 /* AnyBinding.swift */, + DDDA125B54235F76F7A34730 /* Arguments.swift */, 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */, - 57F4D977AC4289A6145383C9 /* InstanceRequest.swift */, + E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */, 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */, 424C647FF08FCB7C2A54E085 /* PropertyWrapper.swift */, 73B4B777290FF5D38A8914CC /* Reference.swift */, @@ -1143,12 +1149,12 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 1FB4AED93C9EEF9760913558 /* Binding+Factory.swifttemplate in Resources */, BFE22F9F2E88F177302E9D19 /* Container+Registration.swifttemplate in Resources */, - 1C82BFD00FCC384DB3AE6A89 /* MatchableBoxes.swifttemplate in Resources */, + 082EBD694ADF41DB4C53BD5A /* InstanceRequest+Api.swifttemplate in Resources */, + 1C82BFD00FCC384DB3AE6A89 /* ArgumentVariations.swifttemplate in Resources */, 3EC8383BEAC339595CF7F927 /* Resolver+FunctionCallApi.swifttemplate in Resources */, - 773166772311787D0002655B /* InstanceRequest+Api.swifttemplate in Resources */, F568382FB877060127790413 /* Resolver+LegacyApi.swifttemplate in Resources */, - 77B87F40231155B300321C08 /* Binding+Factory.swifttemplate in Resources */, B7653A6427A5E284E9A1D6D3 /* ServiceEntry+TypeForwarding.swifttemplate in Resources */, EBC64A1515C868E410C83451 /* SwiftCode.swifttemplate in Resources */, ); @@ -1398,30 +1404,30 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 5A74DF28BBEBC4E494E67162 /* AnyBinding.swift in Sources */, + B90A5B58E1DF17A63B093BE5 /* Arguments.swift in Sources */, 19EBB651BD06BD0C03C1ACB5 /* Assembler.swift in Sources */, F504C2ABEFCFFCAC8B858751 /* Assembly.swift in Sources */, 703F8B3AD111A6CFAFF66A49 /* Behavior.swift in Sources */, - 77316673231176B50002655B /* InstanceRequest+APi.swift in Sources */, - 658AEDC8D802A6788E959E0C /* AnyBinding.swift in Sources */, + D06263E082BD076D53A297D6 /* Binding+Api.swift in Sources */, + 0CB78F196D83DC32125402D3 /* Binding+Factory.swift in Sources */, + 28E140284EE255E55B45E4CF /* Binding.swift in Sources */, 694C2C891D581371B2B051D7 /* Container+Logging.swift in Sources */, - 77ED80062311221600AC48F9 /* ValueRequest.swift in Sources */, AAD8D0551B8A26A9B22AECEC /* Container+Registration.swift in Sources */, 996CCFE825834C7D3236E742 /* Container+TypeForwarding.swift in Sources */, B2FAD41F7726502822AF913B /* Container.swift in Sources */, - 7731667C231187480002655B /* Retrieval.swift in Sources */, 8B5927517B567B1DFAB5B935 /* ContextTranslator.swift in Sources */, - 77B87F492311580600321C08 /* Binding+Api.swift in Sources */, - 1D17DBC27F25717BF7A87AF3 /* InstanceRequest.swift in Sources */, + FB467C5FB6C6851FD1B6DB51 /* InstanceRequest+APi.swift in Sources */, + 53EBF7A46EF65F2A8DAADC7A /* InstanceRequest.swift in Sources */, A91EDAFBC3606EDFBD739899 /* InstanceWrapper.swift in Sources */, 98322F9371E1A8461BC614D1 /* Matchable.swift in Sources */, 3753FB83A1FB4B83891AA5C8 /* ObjectScope.swift in Sources */, - 77B87F44231157E900321C08 /* Binding+Factory.swift in Sources */, 5393E5DE21B568A88498E454 /* PropertyWrapper.swift in Sources */, 3BD6055555A5C30DABDC8ED2 /* Reference.swift in Sources */, A9112F7CF871475B94A077D7 /* Resolver+FunctionCall.swift in Sources */, D4936DC1A47A8C85325FB52E /* Resolver+LegacyApi.swift in Sources */, 8016512839FE61EC3127E489 /* Resolver.swift in Sources */, - 773C6DDD23111956007A40BF /* Binding.swift in Sources */, + 06D09D88E514CCA11D101AFB /* Retrieval.swift in Sources */, 68C95FCB0D345CA3BA24D320 /* Scope.swift in Sources */, BB571B9A78FC53231A18E18C /* ScopeRegistry.swift in Sources */, 593B93BA2EE3FE4418A1C579 /* ScopeRegistryKey.swift in Sources */, @@ -1435,6 +1441,7 @@ 0D5C4A278A16AB3A163148AF /* SwinjectTree.swift in Sources */, 49685AB40BEE856C62005C87 /* TypeDescriptor.swift in Sources */, 5BD767B85CFE5FADDFE0A7B5 /* UnboundScope.swift in Sources */, + F9F9839490926ED7623ED4BE /* ValueRequest.swift in Sources */, F88700BAAFFB47B1BD4D3BFA /* Weak.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1443,8 +1450,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 77316675231177580002655B /* InstanceRequestVariation.swift in Sources */, - 77B87F3E231153D200321C08 /* FactoryVariation.swift in Sources */, + FEF6E60044D76ECC226411DD /* FactoryVariation.swift in Sources */, + 3A6E6708B2EF95B9A6491213 /* InstanceRequestVariation.swift in Sources */, 70BAF056528B2B33B3A65E9D /* Utils.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1495,38 +1502,38 @@ buildActionMask = 2147483647; files = ( A6EECC339FA54CA0BBFF4146 /* Animal.swift in Sources */, - CBBE28990E0EA82AD8D5E3AF /* AssemblerSpec.swift in Sources */, + 77F957F123127CB800FD392A /* ContainerSpec.Circularity.swift in Sources */, 401592294E5D528379BE1AB2 /* BasicAssembly.swift in Sources */, + 77F957F023127CB800FD392A /* ContainerSpec.Behavior.swift in Sources */, + 77F957EE23127CB800FD392A /* AssemblerSpec.swift in Sources */, A3BFFED76688F149FBAF7C53 /* BehaviorFakes.swift in Sources */, + 77F957F323127CB800FD392A /* ContainerSpec.swift in Sources */, BB77A5D81C58392964D07233 /* BindingSpec.swift in Sources */, + 77F957F223127CB800FD392A /* ContainerSpec.CustomStringConvertible.swift in Sources */, 39AE6864444BC1CE491142E5 /* CIrcularitySpec.swift in Sources */, CDE8EA7EC1D8096F12BDD8C2 /* Circularity.swift in Sources */, - 83464EDC08380F5CE2190F30 /* ContainerSpec.Arguments.swift in Sources */, - F8EB47A631D482A0D7B621DE /* ContainerSpec.Behavior.swift in Sources */, - E5880DBBB91CC5F8F47FBF73 /* ContainerSpec.Circularity.swift in Sources */, - 2B506344F37CE5F5C5C02C05 /* ContainerSpec.CustomStringConvertible.swift in Sources */, - E01D0D443FBA4DB82A6EC298 /* ContainerSpec.TypeForwarding.swift in Sources */, - A9A242086D1EDE408DC556D0 /* ContainerSpec.swift in Sources */, 1C62135FAE3D64DC7BFBF861 /* ContextSpec.swift in Sources */, A882705E4199EF759E80B311 /* Convenience.swift in Sources */, 19416C867F15E88394A0ABD1 /* EmploymentAssembly.swift in Sources */, 590B861A863A056A0B7FA368 /* Food.swift in Sources */, 95A6654089875BCC863FB53B /* InjectionSpec.swift in Sources */, - 979518E078B187549E11DF48 /* LazySpec.swift in Sources */, - B96A6370D549AAC383360ABC /* LinuxConfig.swift in Sources */, 335CE53CEC2360DC86D58F07 /* LoadAwareAssembly.swift in Sources */, 004B06007E4FDD8F44B7EC89 /* ModulesSpec.swift in Sources */, D941D81F59900A52805D6B4A /* OptionalsSpec.swift in Sources */, 18AAA07DCD6FAB4A7D7E8B76 /* OverrideSpec.swift in Sources */, + 77F957F523127CB800FD392A /* LazySpec.swift in Sources */, EB3420214A9E68A0247D0F2C /* Person.swift in Sources */, 9AA68475ABE3E7502F59216D /* PropertyWrappersSpec.swift in Sources */, - CF9535A0DCAFF23F4D62F871 /* ProviderSpec.swift in Sources */, + 77F957EF23127CB800FD392A /* ContainerSpec.Arguments.swift in Sources */, 1A68A8D05D9974002BF34CF8 /* RetrievalSpec.swift in Sources */, + 77F957F623127CB800FD392A /* ProviderSpec.swift in Sources */, + 77F957F723127CB800FD392A /* SynchronizedResolverSpec.swift in Sources */, + 77F957F423127CB800FD392A /* ContainerSpec.TypeForwarding.swift in Sources */, + 77F957ED23127CB800FD392A /* LinuxConfig.swift in Sources */, 0068DAA4AA322F00AF53731F /* ScopesSpec.swift in Sources */, B65DE0B0562540CC8CEC48F3 /* SingletonSpec.swift in Sources */, C952D5869D87743297968E9A /* StandardScopeRegistrySpec.swift in Sources */, A308578B99D33C7E33632E85 /* SwinjectTreeBuilderSpec.swift in Sources */, - 3BDB44DE92D2377334894804 /* SynchronizedResolverSpec.swift in Sources */, 2615FC1C92B7E381116B9E57 /* TestModels.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1617,30 +1624,30 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 9A8E74FAA81B2E5A1903371A /* AnyBinding.swift in Sources */, + 603BD4D9FBE1B2A5916967CA /* Arguments.swift in Sources */, 5D5852F610358DFF7230C35C /* Assembler.swift in Sources */, 74E1FC692A27C56510363364 /* Assembly.swift in Sources */, FA805A162E989A22990B99AA /* Behavior.swift in Sources */, - 77316672231176B50002655B /* InstanceRequest+APi.swift in Sources */, - F9A4BF18B0085B7DCD3440EC /* AnyBinding.swift in Sources */, + 2B13DD3C7FA3288A959A0928 /* Binding+Api.swift in Sources */, + FECBBFAB7336A166E1A46D95 /* Binding+Factory.swift in Sources */, + 27285F3D5FC1115A22B830F8 /* Binding.swift in Sources */, 6A03ABEED82EF31E8E6E297E /* Container+Logging.swift in Sources */, A5E4C79F89E1A8AB3A4D8D6E /* Container+Registration.swift in Sources */, BD9B57E26722C80B7EF990DB /* Container+TypeForwarding.swift in Sources */, DB74F17CDFF4886B9C38AD14 /* Container.swift in Sources */, DD5E3AF2B5FCE5E81EBDF606 /* ContextTranslator.swift in Sources */, - 7731667B231187480002655B /* Retrieval.swift in Sources */, - 76FB9AFE299316E7F3F4C3BB /* InstanceRequest.swift in Sources */, - 77B87F482311580600321C08 /* Binding+Api.swift in Sources */, + 921406E8219BBDAFE2BEEDD6 /* InstanceRequest+APi.swift in Sources */, + 9DEAC620F2F00D0DDD3B5D3E /* InstanceRequest.swift in Sources */, 57BFBA2077E70DC1C2FE796C /* InstanceWrapper.swift in Sources */, 293985649250DF270DC89135 /* Matchable.swift in Sources */, - 77ED80072311221600AC48F9 /* ValueRequest.swift in Sources */, B4B66D7251BDDE25D6D7FB3C /* ObjectScope.swift in Sources */, - 773BE491231124AD000AA1A9 /* Binding.swift in Sources */, - 77B87F45231157EA00321C08 /* Binding+Factory.swift in Sources */, 6A967AE5710606998C2BE070 /* PropertyWrapper.swift in Sources */, B293894FEB67831DDA5F000E /* Reference.swift in Sources */, 8A4E9E736239F92F878C070C /* Resolver+FunctionCall.swift in Sources */, E177D354B1F410129D921C69 /* Resolver+LegacyApi.swift in Sources */, 5D7E26A00B055803A50CD9C2 /* Resolver.swift in Sources */, + 875D809B53B3A118AAF1348C /* Retrieval.swift in Sources */, B84167AC8C6BEB57C4D0695A /* Scope.swift in Sources */, E7D1045D25FAB592401DCAF0 /* ScopeRegistry.swift in Sources */, 4347EE17D0C0ED574C899D85 /* ScopeRegistryKey.swift in Sources */, @@ -1654,6 +1661,7 @@ 0CE1126436F680F9684837E4 /* SwinjectTree.swift in Sources */, 9CEE20BD42795D5E5F39BF20 /* TypeDescriptor.swift in Sources */, 8B711CBE6A5B86DC2D6CABDC /* UnboundScope.swift in Sources */, + A5AD538F6D2C7CB0BE4EFF8C /* ValueRequest.swift in Sources */, FC339851D7EEE4D17178CC1F /* Weak.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1662,30 +1670,30 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 168224D6B76AF22325307EB6 /* AnyBinding.swift in Sources */, + 41BD3DC77CA877DB46844B18 /* Arguments.swift in Sources */, 290C9E9420A1EE30456476CB /* Assembler.swift in Sources */, 3099172980F9E9143C0A1C20 /* Assembly.swift in Sources */, 2CB057F2A16DA462E0517AAB /* Behavior.swift in Sources */, - 77316671231176B40002655B /* InstanceRequest+APi.swift in Sources */, - D2BAE1CB997A4D052CB8EFC8 /* AnyBinding.swift in Sources */, + BE4601421B552E315C828F82 /* Binding+Api.swift in Sources */, + 000151E30A8F1EEAEA54B2EC /* Binding+Factory.swift in Sources */, + 64703514AB8130B7808F7180 /* Binding.swift in Sources */, 1ED6BD68D92F4FE60978EF22 /* Container+Logging.swift in Sources */, - 77ED80082311221600AC48F9 /* ValueRequest.swift in Sources */, CB0B308F3D3A831A28127462 /* Container+Registration.swift in Sources */, 283C77045DA55C2134EC9C48 /* Container+TypeForwarding.swift in Sources */, 58ABEE0321A3061048B65EA2 /* Container.swift in Sources */, - 7731667A231187470002655B /* Retrieval.swift in Sources */, F06DEB671A4B85ABB0E96E51 /* ContextTranslator.swift in Sources */, - 77B87F472311580500321C08 /* Binding+Api.swift in Sources */, - 027015812E961322FE3D942B /* InstanceRequest.swift in Sources */, + EEBB114E8A57F37E4F226482 /* InstanceRequest+APi.swift in Sources */, + CECF5BD14BCDF5248771A06A /* InstanceRequest.swift in Sources */, 389C54E04DD794DA4F648571 /* InstanceWrapper.swift in Sources */, 87FEAEF562B99522083CB87D /* Matchable.swift in Sources */, 6DA49F84E2592B32F81F268B /* ObjectScope.swift in Sources */, - 77B87F46231157EA00321C08 /* Binding+Factory.swift in Sources */, 5F1647DCC0D437A782647372 /* PropertyWrapper.swift in Sources */, 2D020C6391A4F6A2118585B8 /* Reference.swift in Sources */, 1AC00BCB4DB26B078203DAD8 /* Resolver+FunctionCall.swift in Sources */, FD7B2663F2F931B78EB330EE /* Resolver+LegacyApi.swift in Sources */, 97C2EA47D7623AFD723AFE93 /* Resolver.swift in Sources */, - 773C6DDE23111956007A40BF /* Binding.swift in Sources */, + 6405B24BE522A98AEB275E7D /* Retrieval.swift in Sources */, 2C352AAD1AC7D82A4A059046 /* Scope.swift in Sources */, 02556F149C9AAEF5CE353AC1 /* ScopeRegistry.swift in Sources */, 06F4CAB352B4F623FF7BD885 /* ScopeRegistryKey.swift in Sources */, @@ -1699,6 +1707,7 @@ 372F0061E762BF8FFF05457F /* SwinjectTree.swift in Sources */, AC470B4322599B0A076DD3FF /* TypeDescriptor.swift in Sources */, D669A1E2657CC868027395D9 /* UnboundScope.swift in Sources */, + CDF8E0FFBFD4BB9E2758EBFE /* ValueRequest.swift in Sources */, 95E6DD9D94BE64420EEC1298 /* Weak.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1707,20 +1716,21 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 83CDF14784F813ABD8E00933 /* AnyBinding.swift in Sources */, + A2E179234F7C8526A1A9BF87 /* Arguments.swift in Sources */, DC5B169FD525CC1C01518312 /* Assembler.swift in Sources */, BB8FDF4F2A0AF8C1DA615854 /* Assembly.swift in Sources */, F7979BE4BE1B1C7101D15E61 /* Behavior.swift in Sources */, - 77316670231176B20002655B /* InstanceRequest+APi.swift in Sources */, - 3F8F5645D6D37FCEC1D89393 /* AnyBinding.swift in Sources */, + 4B9B0B0F61359DC8C25C36A5 /* Binding+Api.swift in Sources */, + 67A273EEFC4769951013DCEA /* Binding+Factory.swift in Sources */, + FB3113365FAB20BE0A2DC2E7 /* Binding.swift in Sources */, 999AF7221D3F2E1F83C3ACB1 /* Container+Logging.swift in Sources */, - 77ED80052311221600AC48F9 /* ValueRequest.swift in Sources */, 21285CED416F1317E993397A /* Container+Registration.swift in Sources */, 3A0B409E840B44B281DB3C54 /* Container+TypeForwarding.swift in Sources */, 0622539110A7430776A307C7 /* Container.swift in Sources */, - 773166792311854B0002655B /* Retrieval.swift in Sources */, D1DF4740A9D86362B63104B8 /* ContextTranslator.swift in Sources */, - 826D63FA91E370F0061768B0 /* InstanceRequest.swift in Sources */, - 77B87F43231157E900321C08 /* Binding+Factory.swift in Sources */, + 4FACFC5F59982A6EDA7F8E4D /* InstanceRequest+APi.swift in Sources */, + 128913D570B4A8BBF40866BE /* InstanceRequest.swift in Sources */, 98ACB1A09194572A946CA90D /* InstanceWrapper.swift in Sources */, 5ED8A7D19F21FA686215F72C /* Matchable.swift in Sources */, B42331BF00B482369B908BB8 /* ObjectScope.swift in Sources */, @@ -1729,7 +1739,7 @@ 5A78C354D420D64CF8A787C1 /* Resolver+FunctionCall.swift in Sources */, 41C7340BFD2EB66359772733 /* Resolver+LegacyApi.swift in Sources */, BE94EF7BCF976A703F961389 /* Resolver.swift in Sources */, - 773C6DDC23111956007A40BF /* Binding.swift in Sources */, + 6D10D2E438AA642300483BF1 /* Retrieval.swift in Sources */, 96EA0A5DF33F025EBE0B67D2 /* Scope.swift in Sources */, D861595482464ED95CF81922 /* ScopeRegistry.swift in Sources */, 920DE2CAB9895D10FAE48FBA /* ScopeRegistryKey.swift in Sources */, @@ -1743,7 +1753,7 @@ 6922AE734E84B515C94D9480 /* SwinjectTree.swift in Sources */, E3EABE098DBFB561A20632E3 /* TypeDescriptor.swift in Sources */, 19F21849D1E173F5AC724281 /* UnboundScope.swift in Sources */, - 77B87F3C23112DB100321C08 /* Binding+Api.swift in Sources */, + 3AB62DA4D297295283ABE1AE /* ValueRequest.swift in Sources */, 581B08428C6AACAFC8017F8A /* Weak.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Templates/ArgumentVariations.swifttemplate b/Templates/ArgumentVariations.swifttemplate new file mode 100644 index 00000000..3dfc04e2 --- /dev/null +++ b/Templates/ArgumentVariations.swifttemplate @@ -0,0 +1,19 @@ +<% let arg_count = 9 %> +// sourcery:inline:ArgumentVariations +<%_ (1...arg_count).forEach { i in + let arg_types = (1...i).map { "Arg\($0)" }.joined(separator: ", ") + let arg_hashables = (1...i).map { "Arg\($0): Hashable" }.joined(separator: ", ") + let arg_params = (1...i).map { "_ arg\($0): Arg\($0)" }.joined(separator: ", ") +-%> +init<<%= arg_types %>>(<%= arg_params %>) { + values = [<%= (1...i).map { "arg\($0)" }.joined(separator: ", ") %>] + descriptor = [<%= (1...i).map { "Arg\($0).self" }.joined(separator: ", ") %>] +} + +init<<%= arg_types %>>(<%= arg_params %>) where <%= arg_hashables %> { + values = [<%= (1...i).map { "MatchBox(arg\($0))" }.joined(separator: ", ") %>] + descriptor = [<%= (1...i).map { "Arg\($0).self" }.joined(separator: ", ") %>] +} + +<%_ } -%> +// sourcery:end diff --git a/Templates/Container+Registration.swifttemplate b/Templates/Container+Registration.swifttemplate index 973c5101..f2c2c5b6 100644 --- a/Templates/Container+Registration.swifttemplate +++ b/Templates/Container+Registration.swifttemplate @@ -16,16 +16,16 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register(_: Service.Type, name: String? = nil, factory: @escaping (Resolver) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, _: Void) in factory(r) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef, argumentDescriptor: []) { r, _ in factory(r) } addEntry(entry, with: name) return entry } <%_ (1...arg_count).forEach { i in let arg_types = (1...i).map { "Arg\($0)" }.joined(separator: ", ") - let arg_closure_type = i == 1 ? "Arg1" : "(\(arg_types))" + let arg_descriptor_types = (1...i).map { "Arg\($0).self" }.joined(separator: ", ") let arg_description = i == 1 ? "\(i) argument" : "\(i) arguments" - let arg_vars = i == 1 ? "a" : (0.. /// Adds a registration for the specified service with the factory closure to specify how the service is resolved with dependencies. /// @@ -41,7 +41,7 @@ extension Container { /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register>(_: Service.Type, name: String? = nil, factory: @escaping (Resolver, <%= arg_types %>) -> Service) -> ServiceEntry { - let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef) { (r, _, a: <%= arg_closure_type %>) in factory(r, <%= arg_vars %>) } + let entry = ServiceEntry(container: self, name: name, scope: defaultScope, makeRef: defaultMakeRef, argumentDescriptor: [<%= arg_descriptor_types %>]) { r, a in try! factory(r, <%= arg_vars %>) } addEntry(entry, with: name) return entry }<%= i < arg_count ? "\n" : "" %> diff --git a/Templates/FactoryVariation.swift b/Templates/FactoryVariation.swift index 0a2d805d..dee76ad8 100644 --- a/Templates/FactoryVariation.swift +++ b/Templates/FactoryVariation.swift @@ -36,12 +36,8 @@ extension FactoryVariation { ) } - var argInputType: String { - switch args { - case 0: return "Void" - case 1: return isMatchable ? "MatchableBox1" : "Arg1" - default: return isMatchable ? "MatchableBox\(args)<\(argTypes)>" : "(\(argTypes))" - } + var argDescriptorTypes: String { + return join((1 ..< args + 1).map { "Arg\($0).self" }) } var returnType: String { @@ -59,15 +55,14 @@ extension FactoryVariation { var argVarsOrNil: String? { switch args { case 0: return nil - case 1: return isMatchable ? "a.arg1" : "a" - default: return join((1 ... args).map { isMatchable ? "a.arg\($0)" : "a.\($0 - 1)" }) + default: return join((0 ..< args).map { "a.arg(\($0))" }) } } var factoryInputs: String { return join( hasResolver ? "r" : "_", - (args > 0 ? "a" : "_") + ": \(argInputType)" + args > 0 ? "a" : "_" ) } @@ -101,9 +96,10 @@ extension FactoryVariation { func render() -> String { return """ func factory<\(genericTypes)>(\(params)) -> \(returnType) \(constraints){ - return updatedFactory { (\(factoryInputs)) in try factory(\(factoryVars)) }.updated { + return updatedFactory { \(factoryInputs) in try factory(\(factoryVars)) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] $0.dependencies = .undefined + $0.arguments = [\(argDescriptorTypes)] } } """ diff --git a/Templates/InstanceRequestVariation.swift b/Templates/InstanceRequestVariation.swift index 2456e53a..851831ff 100644 --- a/Templates/InstanceRequestVariation.swift +++ b/Templates/InstanceRequestVariation.swift @@ -38,7 +38,7 @@ extension InstanceRequestVariation { return join( "type: Type.self", "tag: tag", - args == 0 ? "arg: ()" : "arg: box(\(argVars))" + "arg: Arguments(\(argVars))" ) } diff --git a/Templates/MatchableBoxes.swifttemplate b/Templates/MatchableBoxes.swifttemplate deleted file mode 100644 index 9156a5cf..00000000 --- a/Templates/MatchableBoxes.swifttemplate +++ /dev/null @@ -1,29 +0,0 @@ -<% let arg_count = 5 %> -// sourcery:inline:MatchableBoxes -<%_ (1...arg_count).forEach { i in - let arg_types = (1...i).map { "Arg\($0)" }.joined(separator: ", ") - let arg_hashables = (1...i).map { "Arg\($0): Hashable" }.joined(separator: ", ") - let type_name = "MatchableBox\(i)<\(arg_types)>" --%> -struct <%= type_name %>: Hashable, Matchable where <%= arg_hashables %> { - <%= (1...i).map { "let arg\($0): Arg\($0)" }.joined(separator: "\n ") %> -} - -<%_ } -%> -<%_ (1...arg_count).forEach { i in - let arg_types = (1...i).map { "Arg\($0)" }.joined(separator: ", ") - let arg_hashables = (1...i).map { "Arg\($0): Hashable" }.joined(separator: ", ") - let arg_params = (1...i).map { "_ arg\($0): Arg\($0)" }.joined(separator: ", ") - let arg_call_params = (1...i).map { "arg\($0): arg\($0)" }.joined(separator: ", ") - let tuple_params = (1...i).map { "arg\($0)" }.joined(separator: ", ") --%> -func box<<%= arg_types %>>(<%= arg_params %>) -> <%= i == 1 ? arg_types : "(\(arg_types))" %> { - return <%= i == 1 ? tuple_params : "(\(tuple_params))" %> -} - -func box<<%= arg_types %>>(<%= arg_params %>) -> MatchableBox<%= i %><<%= arg_types %>> where <%= arg_hashables %> { - return MatchableBox<%= i %>(<%= arg_call_params %>) -} - -<%_ } -%> -// sourcery:end diff --git a/Templates/Resolver+LegacyApi.swifttemplate b/Templates/Resolver+LegacyApi.swifttemplate index c3779ac5..5ec3e0a4 100644 --- a/Templates/Resolver+LegacyApi.swifttemplate +++ b/Templates/Resolver+LegacyApi.swifttemplate @@ -9,7 +9,7 @@ public extension Resolver { /// /// - Returns: The resolved service type instance, or nil if no service with the name is found. func resolve(_ serviceType: Service.Type, name: String? = nil) -> Service? { - return try? resolve(request(type: serviceType, tag: name, arg: ())) as Service + return try? resolve(request(type: serviceType, tag: name, arg: Arguments())) as Service } <%_ (1...arg_count).forEach { i in @@ -17,7 +17,7 @@ public extension Resolver { let arg_param = i == 1 ? "argument: Arg1" : "arguments arg1: Arg1, " + (2...i).map{ "_ arg\($0): Arg\($0)" }.joined(separator: ", ") let arg_param_name = i == 1 ? "argument" : "arguments" let arg_param_description = i == 1 ? "\(i) argument" : "list of \(i) arguments" - let arg_vars = i == 1 ? "argument" : ("(" + (1...i).map { "arg\($0)" }.joined(separator: ", ") + ")") + let arg_vars = i == 1 ? "argument" : (1...i).map { "arg\($0)" }.joined(separator: ", ") -%> /// Retrieves the instance with the specified service type, <%= arg_param_description %> to the factory closure and registration name. /// @@ -29,7 +29,7 @@ public extension Resolver { /// - Returns: The resolved service type instance, or nil if no registration for the service type, /// <%= arg_param_description %> and name is found. func resolve>(_ serviceType: Service.Type, name: String? = nil, <%= arg_param %>) -> Service? { - return try? resolve(request(type: serviceType, tag: name, arg: <%= arg_vars %>)) as Service + return try? resolve(request(type: serviceType, tag: name, arg: Arguments(<%= arg_vars %>))) as Service }<%= i < arg_count ? "\n" : "" %> <%_ } -%> } diff --git a/Templates/SwiftCode.swifttemplate b/Templates/SwiftCode.swifttemplate index 1b8453b7..6231abde 100644 --- a/Templates/SwiftCode.swifttemplate +++ b/Templates/SwiftCode.swifttemplate @@ -39,7 +39,7 @@ extension InstanceRequestVariation { return join( "type: Type.self", "tag: tag", - args == 0 ? "arg: ()" : "arg: box(\(argVars))" + "arg: Arguments(\(argVars))" ) } @@ -123,12 +123,8 @@ extension FactoryVariation { ) } - var argInputType: String { - switch args { - case 0: return "Void" - case 1: return isMatchable ? "MatchableBox1" : "Arg1" - default: return isMatchable ? "MatchableBox\(args)<\(argTypes)>" : "(\(argTypes))" - } + var argDescriptorTypes: String { + return join((1 ..< args + 1).map { "Arg\($0).self" }) } var returnType: String { @@ -146,15 +142,14 @@ extension FactoryVariation { var argVarsOrNil: String? { switch args { case 0: return nil - case 1: return isMatchable ? "a.arg1" : "a" - default: return join((1 ... args).map { isMatchable ? "a.arg\($0)" : "a.\($0 - 1)" }) + default: return join((0 ..< args).map { "a.arg(\($0))" }) } } var factoryInputs: String { return join( hasResolver ? "r" : "_", - (args > 0 ? "a" : "_") + ": \(argInputType)" + args > 0 ? "a" : "_" ) } @@ -188,9 +183,10 @@ extension FactoryVariation { func render() -> String { return """ func factory<\(genericTypes)>(\(params)) -> \(returnType) \(constraints){ - return updatedFactory { (\(factoryInputs)) in try factory(\(factoryVars)) }.updated { + return updatedFactory { \(factoryInputs) in try factory(\(factoryVars)) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] $0.dependencies = .undefined + $0.arguments = [\(argDescriptorTypes)] } } """ diff --git a/Tests/Unit Specs/StandardScopeRegistrySpec.swift b/Tests/Unit Specs/StandardScopeRegistrySpec.swift index 3bac4fdf..5c0cdf41 100644 --- a/Tests/Unit Specs/StandardScopeRegistrySpec.swift +++ b/Tests/Unit Specs/StandardScopeRegistrySpec.swift @@ -9,7 +9,7 @@ import Quick class StandardScopeRegistrySpec: QuickSpec { override func spec() { var registry: StandardScopeRegistry! - let key = (1 ... 5).map { ScopeRegistryKey(descriptor: tagged(Int.self, with: "\($0)"), argument: ()) } + let key = (1 ... 5).map { ScopeRegistryKey(descriptor: tagged(Int.self, with: "\($0)"), arguments: Arguments()) } var doors = [Door]() beforeEach { doors = (1 ... 3).map { _ in Door() } From 1050c787c34b05f0ac1626e75ff6a4c42f0b9dc8 Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Sun, 25 Aug 2019 13:07:52 +0200 Subject: [PATCH 231/239] Define partial requests --- Sources/3.0 API/Binding.swift | 4 +- Sources/3.0 API/PartialRequest.swift | 63 +++++++++++++++++++++ Sources/3.0 API/ValueRequest.swift | 7 --- Sources/Core/Arguments.swift | 8 +-- Sources/Core/Resolver.swift | 1 + Swinject.xcodeproj/project.pbxproj | 82 ++++++++++++++++------------ 6 files changed, 116 insertions(+), 49 deletions(-) create mode 100644 Sources/3.0 API/PartialRequest.swift delete mode 100644 Sources/3.0 API/ValueRequest.swift diff --git a/Sources/3.0 API/Binding.swift b/Sources/3.0 API/Binding.swift index 7d8cb033..969f46a0 100644 --- a/Sources/3.0 API/Binding.swift +++ b/Sources/3.0 API/Binding.swift @@ -11,9 +11,9 @@ public struct BindingProperties { enum BindingDependencies { case undefined - case requests([ValueRequest]) + case list([PartialDependency]) - static let none = BindingDependencies.requests([]) + static let none = BindingDependencies.list([]) } public struct Binding { diff --git a/Sources/3.0 API/PartialRequest.swift b/Sources/3.0 API/PartialRequest.swift new file mode 100644 index 00000000..1a8d853f --- /dev/null +++ b/Sources/3.0 API/PartialRequest.swift @@ -0,0 +1,63 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +public enum PartialDependency { + case instance(TypeDescriptor, Arguments.Descriptor) + case argument(Any.Type) + case context(Any.Type) +} + +public protocol AnyPartialRequest { + var asDependency: PartialDependency { get } + func fulfill(with resolver: Resolver, and arguments: Arguments) throws -> Any +} + +protocol PartialRequest: AnyPartialRequest { + associatedtype Result + func fulfill(with resolver: Resolver, and arguments: Arguments) throws -> Result +} + +extension PartialRequest { + public func fulfill(with resolver: Resolver, and arguments: Arguments) throws -> Any { + return try fulfill(with: resolver, and: arguments) as Result + } +} + +public struct ContextRequest {} + +public struct ArgumentRequest { + let index: Int +} + +public func context(as _: Type.Type = Type.self) -> ContextRequest { + return ContextRequest() +} + +public func argument(_ index: Int, as _: Type.Type = Type.self) -> ArgumentRequest { + return ArgumentRequest(index: index) +} + +extension InstanceRequest: PartialRequest { + public var asDependency: PartialDependency { return .instance(type, arguments.descriptor) } + + func fulfill(with resolver: Resolver, and _: Arguments) throws -> Type { + return try resolver.resolve(self) + } +} + +extension ArgumentRequest: PartialRequest { + public var asDependency: PartialDependency { return .argument(Type.self) } + + func fulfill(with _: Resolver, and arguments: Arguments) throws -> Type { + return try arguments.arg(index) + } +} + +extension ContextRequest: PartialRequest { + public var asDependency: PartialDependency { return .context(Type.self) } + + func fulfill(with resolver: Resolver, and _: Arguments) throws -> Type { + return try resolver.contexted().context() + } +} diff --git a/Sources/3.0 API/ValueRequest.swift b/Sources/3.0 API/ValueRequest.swift deleted file mode 100644 index 6b050db7..00000000 --- a/Sources/3.0 API/ValueRequest.swift +++ /dev/null @@ -1,7 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -public protocol ValueRequest { - var descriptor: TypeDescriptor { get } -} diff --git a/Sources/Core/Arguments.swift b/Sources/Core/Arguments.swift index c3e40086..38e1c370 100644 --- a/Sources/Core/Arguments.swift +++ b/Sources/Core/Arguments.swift @@ -3,7 +3,7 @@ // public struct Arguments { - struct Descriptor { + public struct Descriptor { let types: [Any.Type] } @@ -44,18 +44,18 @@ extension Arguments: Hashable { } extension Arguments.Descriptor: Hashable { - func hash(into hasher: inout Hasher) { + public func hash(into hasher: inout Hasher) { types.map { ObjectIdentifier($0) }.hash(into: &hasher) } - static func == (lhs: Arguments.Descriptor, rhs: Arguments.Descriptor) -> Bool { + public static func == (lhs: Arguments.Descriptor, rhs: Arguments.Descriptor) -> Bool { return lhs.types.count == rhs.types.count && zip(lhs.types, rhs.types).map { $0.0 == $0.1 }.allSatisfy { $0 == true } } } extension Arguments.Descriptor: ExpressibleByArrayLiteral { - init(arrayLiteral types: Any.Type ...) { + public init(arrayLiteral types: Any.Type ...) { self.types = types } } diff --git a/Sources/Core/Resolver.swift b/Sources/Core/Resolver.swift index d108f03c..bb4dfa20 100644 --- a/Sources/Core/Resolver.swift +++ b/Sources/Core/Resolver.swift @@ -3,6 +3,7 @@ // public protocol Resolver { + // TODO: Can we absstract the input, and remove `InstanceRequest` from core? func resolve(_ request: InstanceRequest) throws -> Type func on(_ context: Context) -> Resolver func context(as contextType: Any.Type) throws -> Any // TODO: Ideally this should be internal diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 8d66822c..07add8fe 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -42,8 +42,8 @@ 1A40A26942A65246D7DD268E /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = ADC44E9312C3B974AFD8F07B /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 1A68A8D05D9974002BF34CF8 /* RetrievalSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D8B3342E2AC3236F12072F5 /* RetrievalSpec.swift */; }; 1AC00BCB4DB26B078203DAD8 /* Resolver+FunctionCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F626B9D3E547621787E4D7 /* Resolver+FunctionCall.swift */; }; + 1B03DC8F071E5395A3B38FCE /* ArgumentVariations.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 193B78CD40CD179E9DD99B64 /* ArgumentVariations.swifttemplate */; }; 1C62135FAE3D64DC7BFBF861 /* ContextSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */; }; - 1C82BFD00FCC384DB3AE6A89 /* ArgumentVariations.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 808C1063CA90CC593C7E0E9C /* ArgumentVariations.swifttemplate */; }; 1CA5DF3F93203B226A6FA059 /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EA566CD336DB8343ADFAF9B /* BehaviorFakes.swift */; }; 1ED6BD68D92F4FE60978EF22 /* Container+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDA78290D6D60BD0B808571F /* Container+Logging.swift */; }; 1FB4AED93C9EEF9760913558 /* Binding+Factory.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = E8A39A3F1C11C85BF0D0A9B1 /* Binding+Factory.swifttemplate */; }; @@ -58,6 +58,7 @@ 293985649250DF270DC89135 /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; 2AA60B7E6EBA9EC6BE92D7CB /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; 2B13DD3C7FA3288A959A0928 /* Binding+Api.swift in Sources */ = {isa = PBXBuildFile; fileRef = C603FD109D6B1496A21B2F8D /* Binding+Api.swift */; }; + 2B506344F37CE5F5C5C02C05 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; 2C352AAD1AC7D82A4A059046 /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; 2C3EB507FFA03D18B2909405 /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8B9785AAE94A5447FA307242 /* Swinject.framework */; }; 2CB057F2A16DA462E0517AAB /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; @@ -79,8 +80,9 @@ 39AE6864444BC1CE491142E5 /* CIrcularitySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 118ABC654C4144496848AD74 /* CIrcularitySpec.swift */; }; 3A0B409E840B44B281DB3C54 /* Container+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F446D6BD4C44E16A1D608BFB /* Container+TypeForwarding.swift */; }; 3A6E6708B2EF95B9A6491213 /* InstanceRequestVariation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22F5FE25C34A0D7124528088 /* InstanceRequestVariation.swift */; }; - 3AB62DA4D297295283ABE1AE /* ValueRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B5EE429B22E5A993ABBC347 /* ValueRequest.swift */; }; + 3AB62DA4D297295283ABE1AE /* PartialRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B5EE429B22E5A993ABBC347 /* PartialRequest.swift */; }; 3BD6055555A5C30DABDC8ED2 /* Reference.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73B4B777290FF5D38A8914CC /* Reference.swift */; }; + 3BDB44DE92D2377334894804 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; 3C270A77DE4F1E6BC2F8E863 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; 3CEF021295AD9AF9BF26B71E /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; 3DEFB7CA42D9EFF0B4FBC0F4 /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 38BCCF3F950869BD1891F7A8 /* Swinject.framework */; }; @@ -160,17 +162,10 @@ 75D74C8C25EDACF5A7A75A5C /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; 778D9AB6470D4280254AC140 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; 77BF219EAB4FC8475943CECC /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6D434EB4C13CF9D9FA6D80CB /* Swinject.framework */; }; - 77F957ED23127CB800FD392A /* LinuxConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 938425B216B78A06EC10504A /* LinuxConfig.swift */; }; - 77F957EE23127CB800FD392A /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; - 77F957EF23127CB800FD392A /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; - 77F957F023127CB800FD392A /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; - 77F957F123127CB800FD392A /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; - 77F957F223127CB800FD392A /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; - 77F957F323127CB800FD392A /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; - 77F957F423127CB800FD392A /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; - 77F957F523127CB800FD392A /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; - 77F957F623127CB800FD392A /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; - 77F957F723127CB800FD392A /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; + 77F957F9231298E400FD392A /* FunctionCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F957F8231298E400FD392A /* FunctionCall.swift */; }; + 77F957FA231298E400FD392A /* FunctionCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F957F8231298E400FD392A /* FunctionCall.swift */; }; + 77F957FB231298E400FD392A /* FunctionCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F957F8231298E400FD392A /* FunctionCall.swift */; }; + 77F957FC231298E400FD392A /* FunctionCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F957F8231298E400FD392A /* FunctionCall.swift */; }; 789BF74652A2424EB8F7EF47 /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 7A7032384E07DAD308D4F70A /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 8B9785AAE94A5447FA307242 /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 7D6F664091C70BABBFB61D53 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; @@ -181,6 +176,7 @@ 82299769BC637A14E7827DB0 /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1E726A651C3AFE92C19608B /* SwinjectModule.swift */; }; 829853126CDB7464599AFC85 /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; 832C9ABB8DCF5340D796F5F8 /* ContextSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */; }; + 83464EDC08380F5CE2190F30 /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; 83CDF14784F813ABD8E00933 /* AnyBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 020903EC58FDC4727852CAF4 /* AnyBinding.swift */; }; 8436D091ED844817C8CE3AF2 /* ContainerSpec.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AEDF723BDD949B59E6D1C5 /* ContainerSpec.Arguments.swift */; }; 86CBC40FDC90E2A2051386C5 /* ContextSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */; }; @@ -201,6 +197,7 @@ 95A6654089875BCC863FB53B /* InjectionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 670DB253ECD5CE1468A7F2E3 /* InjectionSpec.swift */; }; 95E6DD9D94BE64420EEC1298 /* Weak.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57A7E35B2B22650208F904B8 /* Weak.swift */; }; 96EA0A5DF33F025EBE0B67D2 /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; + 979518E078B187549E11DF48 /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13513FA012659ADE699A3608 /* LazySpec.swift */; }; 97C2EA47D7623AFD723AFE93 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */; }; 980FED1DBC62B65597E2828B /* SingletonSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46F05CC591903E2B04B6D8ED /* SingletonSpec.swift */; }; 98322F9371E1A8461BC614D1 /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; @@ -223,7 +220,7 @@ A453A5A7E0EC0FE161AA34D5 /* OptionalsSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50D6F2639990DD5BAD9578B0 /* OptionalsSpec.swift */; }; A53B5A8E2188F8C4A3F29C2E /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BC5108ED11A3A3084D864CC /* Animal.swift */; }; A59C6C434288333EDAF951C4 /* EmploymentAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 433BC87EE5B310B8B9F54156 /* EmploymentAssembly.swift */; }; - A5AD538F6D2C7CB0BE4EFF8C /* ValueRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B5EE429B22E5A993ABBC347 /* ValueRequest.swift */; }; + A5AD538F6D2C7CB0BE4EFF8C /* PartialRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B5EE429B22E5A993ABBC347 /* PartialRequest.swift */; }; A5E4C79F89E1A8AB3A4D8D6E /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59A3946B59EB4D787CCE9F2 /* Container+Registration.swift */; }; A6721BA534AD082E1E7C1D08 /* SwinjectContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8C4916168E81D76536892122 /* SwinjectContainer.swift */; }; A6EECC339FA54CA0BBFF4146 /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BC5108ED11A3A3084D864CC /* Animal.swift */; }; @@ -234,6 +231,7 @@ A882705E4199EF759E80B311 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; A9112F7CF871475B94A077D7 /* Resolver+FunctionCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F626B9D3E547621787E4D7 /* Resolver+FunctionCall.swift */; }; A91EDAFBC3606EDFBD739899 /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */; }; + A9A242086D1EDE408DC556D0 /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; AAC6F2F5EC2928943BF2BED1 /* PropertyWrappersSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49B24254B9F0E48ED3713565 /* PropertyWrappersSpec.swift */; }; AAD8D0551B8A26A9B22AECEC /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59A3946B59EB4D787CCE9F2 /* Container+Registration.swift */; }; AC470B4322599B0A076DD3FF /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; @@ -256,6 +254,7 @@ B84167AC8C6BEB57C4D0695A /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5057BAB33984E3E33469452B /* Scope.swift */; }; B90A5B58E1DF17A63B093BE5 /* Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDDA125B54235F76F7A34730 /* Arguments.swift */; }; B9550BE2BA6FA5731BEC87FD /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; + B96A6370D549AAC383360ABC /* LinuxConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 938425B216B78A06EC10504A /* LinuxConfig.swift */; }; BB571B9A78FC53231A18E18C /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; BB64AE6DFE526629918211B7 /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96AEC72A42A227A50CF9845B /* Circularity.swift */; }; BB77A5D81C58392964D07233 /* BindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E59A67F3548663368788B17 /* BindingSpec.swift */; }; @@ -282,13 +281,15 @@ CAA5241DAA201FBB5818C803 /* BindingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E59A67F3548663368788B17 /* BindingSpec.swift */; }; CB0B308F3D3A831A28127462 /* Container+Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59A3946B59EB4D787CCE9F2 /* Container+Registration.swift */; }; CB9E8D16D7A0620A1F7A32A3 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; + CBBE28990E0EA82AD8D5E3AF /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; CDE8EA7EC1D8096F12BDD8C2 /* Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96AEC72A42A227A50CF9845B /* Circularity.swift */; }; - CDF8E0FFBFD4BB9E2758EBFE /* ValueRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B5EE429B22E5A993ABBC347 /* ValueRequest.swift */; }; + CDF8E0FFBFD4BB9E2758EBFE /* PartialRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B5EE429B22E5A993ABBC347 /* PartialRequest.swift */; }; CE5AFED22F04B96713ED76D7 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ADC44E9312C3B974AFD8F07B /* Nimble.framework */; }; CECF5BD14BCDF5248771A06A /* InstanceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0874A043EAEE3C7CF1EA063 /* InstanceRequest.swift */; }; CEE763218A90832454A6E2DE /* ServiceEntry+TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */; }; CF4516872D3DA7118DB2B90B /* AssemblerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */; }; CF4EBB60C21F8C503BCD7A29 /* SwinjectModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1E726A651C3AFE92C19608B /* SwinjectModule.swift */; }; + CF9535A0DCAFF23F4D62F871 /* ProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 494AA2AA587975747596C157 /* ProviderSpec.swift */; }; D06263E082BD076D53A297D6 /* Binding+Api.swift in Sources */ = {isa = PBXBuildFile; fileRef = C603FD109D6B1496A21B2F8D /* Binding+Api.swift */; }; D0D71F9C22A0EE82B6E4F61A /* Swinject.h in Headers */ = {isa = PBXBuildFile; fileRef = 74DE57FB3E8228904E6FE0D7 /* Swinject.h */; settings = {ATTRIBUTES = (Public, ); }; }; D13208E63523A97A0B840283 /* Animal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BC5108ED11A3A3084D864CC /* Animal.swift */; }; @@ -310,10 +311,12 @@ DCB7C4BF24782862BE9DB135 /* Swinject+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */; }; DD29D2E60DA979D61F32A39A /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62682D6ED38742996624B041 /* BasicAssembly.swift */; }; DD5E3AF2B5FCE5E81EBDF606 /* ContextTranslator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */; }; + E01D0D443FBA4DB82A6EC298 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; E177D354B1F410129D921C69 /* Resolver+LegacyApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A784E2DEC7691D14DDBECD8 /* Resolver+LegacyApi.swift */; }; E227D08034E08AA0909BC043 /* RetrievalSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D8B3342E2AC3236F12072F5 /* RetrievalSpec.swift */; }; E39152E9059357CF0C9B21AF /* CIrcularitySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 118ABC654C4144496848AD74 /* CIrcularitySpec.swift */; }; E3EABE098DBFB561A20632E3 /* TypeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E2DEB50E8526344B904B3C /* TypeDescriptor.swift */; }; + E5880DBBB91CC5F8F47FBF73 /* ContainerSpec.Circularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB24A17D2ECAA4869AE1DD0 /* ContainerSpec.Circularity.swift */; }; E7D1045D25FAB592401DCAF0 /* ScopeRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */; }; EA0D19F7DF0355C774B0F40B /* ScopesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D3C59E84B5FD0C13F487838 /* ScopesSpec.swift */; }; EB3420214A9E68A0247D0F2C /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 351C4221896DDB8572BD6CB5 /* Person.swift */; }; @@ -334,7 +337,8 @@ F7979BE4BE1B1C7101D15E61 /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; F7CD04FB09FC7F18E9E001CF /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; F88700BAAFFB47B1BD4D3BFA /* Weak.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57A7E35B2B22650208F904B8 /* Weak.swift */; }; - F9F9839490926ED7623ED4BE /* ValueRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B5EE429B22E5A993ABBC347 /* ValueRequest.swift */; }; + F8EB47A631D482A0D7B621DE /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; + F9F9839490926ED7623ED4BE /* PartialRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B5EE429B22E5A993ABBC347 /* PartialRequest.swift */; }; FA805A162E989A22990B99AA /* Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ECCBCAAEAB77D77D1910B0 /* Behavior.swift */; }; FB3113365FAB20BE0A2DC2E7 /* Binding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96873D000ADA6FC81B346488 /* Binding.swift */; }; FB467C5FB6C6851FD1B6DB51 /* InstanceRequest+APi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 980BDFC415DEF2099DF9E89A /* InstanceRequest+APi.swift */; }; @@ -472,6 +476,7 @@ 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SynchronizedResolverSpec.swift; sourceTree = ""; }; 13513FA012659ADE699A3608 /* LazySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LazySpec.swift; sourceTree = ""; }; 176824B29DD1A0DAA5CBD241 /* Resolver+FunctionCallApi.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+FunctionCallApi.swifttemplate"; sourceTree = ""; }; + 193B78CD40CD179E9DD99B64 /* ArgumentVariations.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = ArgumentVariations.swifttemplate; sourceTree = ""; }; 1A006CC804F9AB8ACC121029 /* Utils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = ""; }; 1C58FC14EEA170B0DC079DE4 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; 1D3C59E84B5FD0C13F487838 /* ScopesSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopesSpec.swift; sourceTree = ""; }; @@ -520,10 +525,10 @@ 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.CustomStringConvertible.swift; sourceTree = ""; }; 74DE57FB3E8228904E6FE0D7 /* Swinject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Swinject.h; sourceTree = ""; }; 75BE3AE3E30DFE42A919D825 /* ModulesSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModulesSpec.swift; sourceTree = ""; }; + 77F957F8231298E400FD392A /* FunctionCall.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FunctionCall.swift; sourceTree = ""; }; 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ServiceEntry+TypeForwarding.swift"; sourceTree = ""; }; 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextTranslator.swift; sourceTree = ""; }; 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistry.swift; sourceTree = ""; }; - 808C1063CA90CC593C7E0E9C /* ArgumentVariations.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = ArgumentVariations.swifttemplate; sourceTree = ""; }; 823617F3B8A9192F56B13331 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; 86C18DDD83715886DF7F1818 /* OverrideSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OverrideSpec.swift; sourceTree = ""; }; 8B9785AAE94A5447FA307242 /* Swinject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swinject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -536,7 +541,7 @@ 96AEC72A42A227A50CF9845B /* Circularity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Circularity.swift; sourceTree = ""; }; 980BDFC415DEF2099DF9E89A /* InstanceRequest+APi.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "InstanceRequest+APi.swift"; sourceTree = ""; }; 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistryKey.swift; sourceTree = ""; }; - 9B5EE429B22E5A993ABBC347 /* ValueRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ValueRequest.swift; sourceTree = ""; }; + 9B5EE429B22E5A993ABBC347 /* PartialRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PartialRequest.swift; sourceTree = ""; }; A20C1319AF31EC7F8E6945FE /* SwinjectTests.xctest */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.cfbundle; path = SwinjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; A3586A4987B7C7C8122D674E /* SwinjectError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectError.swift; sourceTree = ""; }; A5583CF2602DDFB5E8A7D2DE /* Resolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Resolver.swift; sourceTree = ""; }; @@ -613,12 +618,12 @@ 07354387D49F6D7BBBA4F3AC /* Templates */ = { isa = PBXGroup; children = ( + 193B78CD40CD179E9DD99B64 /* ArgumentVariations.swifttemplate */, E8A39A3F1C11C85BF0D0A9B1 /* Binding+Factory.swifttemplate */, CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */, 5FBCA343BDC1493D29B286C2 /* FactoryVariation.swift */, 076C2114835DCF003BE040B7 /* InstanceRequest+Api.swifttemplate */, 22F5FE25C34A0D7124528088 /* InstanceRequestVariation.swift */, - 808C1063CA90CC593C7E0E9C /* ArgumentVariations.swifttemplate */, 176824B29DD1A0DAA5CBD241 /* Resolver+FunctionCallApi.swifttemplate */, FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */, BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */, @@ -672,7 +677,8 @@ 28D11412EEA912FD369E0D4B /* Retrieval.swift */, 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */, 667B13B528642272FC0794B6 /* UnboundScope.swift */, - 9B5EE429B22E5A993ABBC347 /* ValueRequest.swift */, + 9B5EE429B22E5A993ABBC347 /* PartialRequest.swift */, + 77F957F8231298E400FD392A /* FunctionCall.swift */, 57A7E35B2B22650208F904B8 /* Weak.swift */, ); path = "3.0 API"; @@ -1149,10 +1155,10 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 1B03DC8F071E5395A3B38FCE /* ArgumentVariations.swifttemplate in Resources */, 1FB4AED93C9EEF9760913558 /* Binding+Factory.swifttemplate in Resources */, BFE22F9F2E88F177302E9D19 /* Container+Registration.swifttemplate in Resources */, 082EBD694ADF41DB4C53BD5A /* InstanceRequest+Api.swifttemplate in Resources */, - 1C82BFD00FCC384DB3AE6A89 /* ArgumentVariations.swifttemplate in Resources */, 3EC8383BEAC339595CF7F927 /* Resolver+FunctionCallApi.swifttemplate in Resources */, F568382FB877060127790413 /* Resolver+LegacyApi.swifttemplate in Resources */, B7653A6427A5E284E9A1D6D3 /* ServiceEntry+TypeForwarding.swifttemplate in Resources */, @@ -1427,6 +1433,7 @@ A9112F7CF871475B94A077D7 /* Resolver+FunctionCall.swift in Sources */, D4936DC1A47A8C85325FB52E /* Resolver+LegacyApi.swift in Sources */, 8016512839FE61EC3127E489 /* Resolver.swift in Sources */, + 77F957FA231298E400FD392A /* FunctionCall.swift in Sources */, 06D09D88E514CCA11D101AFB /* Retrieval.swift in Sources */, 68C95FCB0D345CA3BA24D320 /* Scope.swift in Sources */, BB571B9A78FC53231A18E18C /* ScopeRegistry.swift in Sources */, @@ -1441,7 +1448,7 @@ 0D5C4A278A16AB3A163148AF /* SwinjectTree.swift in Sources */, 49685AB40BEE856C62005C87 /* TypeDescriptor.swift in Sources */, 5BD767B85CFE5FADDFE0A7B5 /* UnboundScope.swift in Sources */, - F9F9839490926ED7623ED4BE /* ValueRequest.swift in Sources */, + F9F9839490926ED7623ED4BE /* PartialRequest.swift in Sources */, F88700BAAFFB47B1BD4D3BFA /* Weak.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1502,38 +1509,38 @@ buildActionMask = 2147483647; files = ( A6EECC339FA54CA0BBFF4146 /* Animal.swift in Sources */, - 77F957F123127CB800FD392A /* ContainerSpec.Circularity.swift in Sources */, + CBBE28990E0EA82AD8D5E3AF /* AssemblerSpec.swift in Sources */, 401592294E5D528379BE1AB2 /* BasicAssembly.swift in Sources */, - 77F957F023127CB800FD392A /* ContainerSpec.Behavior.swift in Sources */, - 77F957EE23127CB800FD392A /* AssemblerSpec.swift in Sources */, A3BFFED76688F149FBAF7C53 /* BehaviorFakes.swift in Sources */, - 77F957F323127CB800FD392A /* ContainerSpec.swift in Sources */, BB77A5D81C58392964D07233 /* BindingSpec.swift in Sources */, - 77F957F223127CB800FD392A /* ContainerSpec.CustomStringConvertible.swift in Sources */, 39AE6864444BC1CE491142E5 /* CIrcularitySpec.swift in Sources */, CDE8EA7EC1D8096F12BDD8C2 /* Circularity.swift in Sources */, + 83464EDC08380F5CE2190F30 /* ContainerSpec.Arguments.swift in Sources */, + F8EB47A631D482A0D7B621DE /* ContainerSpec.Behavior.swift in Sources */, + E5880DBBB91CC5F8F47FBF73 /* ContainerSpec.Circularity.swift in Sources */, + 2B506344F37CE5F5C5C02C05 /* ContainerSpec.CustomStringConvertible.swift in Sources */, + E01D0D443FBA4DB82A6EC298 /* ContainerSpec.TypeForwarding.swift in Sources */, + A9A242086D1EDE408DC556D0 /* ContainerSpec.swift in Sources */, 1C62135FAE3D64DC7BFBF861 /* ContextSpec.swift in Sources */, A882705E4199EF759E80B311 /* Convenience.swift in Sources */, 19416C867F15E88394A0ABD1 /* EmploymentAssembly.swift in Sources */, 590B861A863A056A0B7FA368 /* Food.swift in Sources */, 95A6654089875BCC863FB53B /* InjectionSpec.swift in Sources */, + 979518E078B187549E11DF48 /* LazySpec.swift in Sources */, + B96A6370D549AAC383360ABC /* LinuxConfig.swift in Sources */, 335CE53CEC2360DC86D58F07 /* LoadAwareAssembly.swift in Sources */, 004B06007E4FDD8F44B7EC89 /* ModulesSpec.swift in Sources */, D941D81F59900A52805D6B4A /* OptionalsSpec.swift in Sources */, 18AAA07DCD6FAB4A7D7E8B76 /* OverrideSpec.swift in Sources */, - 77F957F523127CB800FD392A /* LazySpec.swift in Sources */, EB3420214A9E68A0247D0F2C /* Person.swift in Sources */, 9AA68475ABE3E7502F59216D /* PropertyWrappersSpec.swift in Sources */, - 77F957EF23127CB800FD392A /* ContainerSpec.Arguments.swift in Sources */, + CF9535A0DCAFF23F4D62F871 /* ProviderSpec.swift in Sources */, 1A68A8D05D9974002BF34CF8 /* RetrievalSpec.swift in Sources */, - 77F957F623127CB800FD392A /* ProviderSpec.swift in Sources */, - 77F957F723127CB800FD392A /* SynchronizedResolverSpec.swift in Sources */, - 77F957F423127CB800FD392A /* ContainerSpec.TypeForwarding.swift in Sources */, - 77F957ED23127CB800FD392A /* LinuxConfig.swift in Sources */, 0068DAA4AA322F00AF53731F /* ScopesSpec.swift in Sources */, B65DE0B0562540CC8CEC48F3 /* SingletonSpec.swift in Sources */, C952D5869D87743297968E9A /* StandardScopeRegistrySpec.swift in Sources */, A308578B99D33C7E33632E85 /* SwinjectTreeBuilderSpec.swift in Sources */, + 3BDB44DE92D2377334894804 /* SynchronizedResolverSpec.swift in Sources */, 2615FC1C92B7E381116B9E57 /* TestModels.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1647,6 +1654,7 @@ 8A4E9E736239F92F878C070C /* Resolver+FunctionCall.swift in Sources */, E177D354B1F410129D921C69 /* Resolver+LegacyApi.swift in Sources */, 5D7E26A00B055803A50CD9C2 /* Resolver.swift in Sources */, + 77F957FB231298E400FD392A /* FunctionCall.swift in Sources */, 875D809B53B3A118AAF1348C /* Retrieval.swift in Sources */, B84167AC8C6BEB57C4D0695A /* Scope.swift in Sources */, E7D1045D25FAB592401DCAF0 /* ScopeRegistry.swift in Sources */, @@ -1661,7 +1669,7 @@ 0CE1126436F680F9684837E4 /* SwinjectTree.swift in Sources */, 9CEE20BD42795D5E5F39BF20 /* TypeDescriptor.swift in Sources */, 8B711CBE6A5B86DC2D6CABDC /* UnboundScope.swift in Sources */, - A5AD538F6D2C7CB0BE4EFF8C /* ValueRequest.swift in Sources */, + A5AD538F6D2C7CB0BE4EFF8C /* PartialRequest.swift in Sources */, FC339851D7EEE4D17178CC1F /* Weak.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1693,6 +1701,7 @@ 1AC00BCB4DB26B078203DAD8 /* Resolver+FunctionCall.swift in Sources */, FD7B2663F2F931B78EB330EE /* Resolver+LegacyApi.swift in Sources */, 97C2EA47D7623AFD723AFE93 /* Resolver.swift in Sources */, + 77F957FC231298E400FD392A /* FunctionCall.swift in Sources */, 6405B24BE522A98AEB275E7D /* Retrieval.swift in Sources */, 2C352AAD1AC7D82A4A059046 /* Scope.swift in Sources */, 02556F149C9AAEF5CE353AC1 /* ScopeRegistry.swift in Sources */, @@ -1707,7 +1716,7 @@ 372F0061E762BF8FFF05457F /* SwinjectTree.swift in Sources */, AC470B4322599B0A076DD3FF /* TypeDescriptor.swift in Sources */, D669A1E2657CC868027395D9 /* UnboundScope.swift in Sources */, - CDF8E0FFBFD4BB9E2758EBFE /* ValueRequest.swift in Sources */, + CDF8E0FFBFD4BB9E2758EBFE /* PartialRequest.swift in Sources */, 95E6DD9D94BE64420EEC1298 /* Weak.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1739,6 +1748,7 @@ 5A78C354D420D64CF8A787C1 /* Resolver+FunctionCall.swift in Sources */, 41C7340BFD2EB66359772733 /* Resolver+LegacyApi.swift in Sources */, BE94EF7BCF976A703F961389 /* Resolver.swift in Sources */, + 77F957F9231298E400FD392A /* FunctionCall.swift in Sources */, 6D10D2E438AA642300483BF1 /* Retrieval.swift in Sources */, 96EA0A5DF33F025EBE0B67D2 /* Scope.swift in Sources */, D861595482464ED95CF81922 /* ScopeRegistry.swift in Sources */, @@ -1753,7 +1763,7 @@ 6922AE734E84B515C94D9480 /* SwinjectTree.swift in Sources */, E3EABE098DBFB561A20632E3 /* TypeDescriptor.swift in Sources */, 19F21849D1E173F5AC724281 /* UnboundScope.swift in Sources */, - 3AB62DA4D297295283ABE1AE /* ValueRequest.swift in Sources */, + 3AB62DA4D297295283ABE1AE /* PartialRequest.swift in Sources */, 581B08428C6AACAFC8017F8A /* Weak.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; From 21042204c37f84727fb31ff780f96aef84c49086 Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Sun, 25 Aug 2019 13:43:30 +0200 Subject: [PATCH 232/239] Implement declarative function call binding api --- Sources/3.0 API/Binding+Api.swift | 15 ++ Sources/3.0 API/FunctionCall.swift | 226 ++++++++++++++++++ Sources/3.0 API/PartialRequest.swift | 15 +- Sources/3.0 API/Resolver+FunctionCall.swift | 89 ------- Swinject.xcodeproj/project.pbxproj | 18 +- .../FunctionCallVariations.swifttemplate | 30 +++ .../Resolver+FunctionCallApi.swifttemplate | 14 -- Tests/3.0 API/InjectionSpec.swift | 46 ---- 8 files changed, 279 insertions(+), 174 deletions(-) create mode 100644 Sources/3.0 API/FunctionCall.swift delete mode 100644 Sources/3.0 API/Resolver+FunctionCall.swift create mode 100644 Templates/FunctionCallVariations.swifttemplate delete mode 100644 Templates/Resolver+FunctionCallApi.swifttemplate diff --git a/Sources/3.0 API/Binding+Api.swift b/Sources/3.0 API/Binding+Api.swift index bbb97e3c..641c8573 100644 --- a/Sources/3.0 API/Binding+Api.swift +++ b/Sources/3.0 API/Binding+Api.swift @@ -40,6 +40,21 @@ public extension Binding where Instance == Void { $0.arguments = [] } } + + func resultOf( + _ call: FunctionCall, + as _: NewInstance.Type = NewInstance.self, + tag: String? = nil + ) -> Binding { + return updatedFactory(factory: call.execute).updated { + // TODO: assert context type + $0.products = [tagged(NewInstance.self, with: tag)] + $0.dependencies = .list(call.inputs.map { $0.asDependency }) + $0.arguments = Arguments.Descriptor(types: call.inputs.compactMap { + if case let .argument(type) = $0.asDependency { return type } else { return nil } + }) + } + } } public extension Binding { diff --git a/Sources/3.0 API/FunctionCall.swift b/Sources/3.0 API/FunctionCall.swift new file mode 100644 index 00000000..eb2d272b --- /dev/null +++ b/Sources/3.0 API/FunctionCall.swift @@ -0,0 +1,226 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +public struct FunctionCall { + let inputs: [AnyPartialRequest] + let execute: (Resolver, Arguments) throws -> Result +} + +postfix operator ^ + +// swiftlint:disable line_length +// swiftlint:disable large_tuple +// swiftformat:disable spaceAroundOperators redundantParens +// sourcery:inline:FunctionCallVariations +public postfix func ^ (function: @escaping () throws -> Result) -> FunctionCall { + return function^() +} + +public postfix func ^ (function: @escaping (I1) throws -> Result) -> FunctionCall { + return function^(instance()) +} + +public postfix func ^ (function: @escaping (I1, I2) throws -> Result) -> FunctionCall { + return function^(instance(), instance()) +} + +public postfix func ^ (function: @escaping (I1, I2, I3) throws -> Result) -> FunctionCall { + return function^(instance(), instance(), instance()) +} + +public postfix func ^ (function: @escaping (I1, I2, I3, I4) throws -> Result) -> FunctionCall { + return function^(instance(), instance(), instance(), instance()) +} + +public postfix func ^ (function: @escaping (I1, I2, I3, I4, I5) throws -> Result) -> FunctionCall { + return function^(instance(), instance(), instance(), instance(), instance()) +} + +public postfix func ^ (function: @escaping (I1, I2, I3, I4, I5, I6) throws -> Result) -> FunctionCall { + return function^(instance(), instance(), instance(), instance(), instance(), instance()) +} + +public postfix func ^ (function: @escaping (I1, I2, I3, I4, I5, I6, I7) throws -> Result) -> FunctionCall { + return function^(instance(), instance(), instance(), instance(), instance(), instance(), instance()) +} + +public postfix func ^ (function: @escaping (I1, I2, I3, I4, I5, I6, I7, I8) throws -> Result) -> FunctionCall { + return function^(instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance()) +} + +public postfix func ^ (function: @escaping (I1, I2, I3, I4, I5, I6, I7, I8, I9) throws -> Result) -> FunctionCall { + return function^(instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance()) +} + +public postfix func ^ (function: @escaping (I1, I2, I3, I4, I5, I6, I7, I8, I9, I10) throws -> Result) -> FunctionCall { + return function^(instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance()) +} + +public postfix func ^ (function: @escaping (I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11) throws -> Result) -> FunctionCall { + return function^(instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance()) +} + +public postfix func ^ (function: @escaping (I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12) throws -> Result) -> FunctionCall { + return function^(instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance()) +} + +public postfix func ^ (function: @escaping (I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12, I13) throws -> Result) -> FunctionCall { + return function^(instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance()) +} + +public postfix func ^ (function: @escaping (I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12, I13, I14) throws -> Result) -> FunctionCall { + return function^(instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance()) +} + +public postfix func ^ (function: @escaping (I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12, I13, I14, I15) throws -> Result) -> FunctionCall { + return function^(instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance()) +} + +public postfix func ^ (function: @escaping (I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12, I13, I14, I15, I16) throws -> Result) -> FunctionCall { + return function^(instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance()) +} + +public postfix func ^ (function: @escaping (I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12, I13, I14, I15, I16, I17) throws -> Result) -> FunctionCall { + return function^(instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance()) +} + +public postfix func ^ (function: @escaping (I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12, I13, I14, I15, I16, I17, I18) throws -> Result) -> FunctionCall { + return function^(instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance()) +} + +public postfix func ^ (function: @escaping (I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12, I13, I14, I15, I16, I17, I18, I19) throws -> Result) -> FunctionCall { + return function^(instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance()) +} + +public postfix func ^ (function: @escaping (I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12, I13, I14, I15, I16, I17, I18, I19, I20) throws -> Result) -> FunctionCall { + return function^(instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance(), instance()) +} + +public func ^ (function: @escaping () throws -> Result, _: ()) -> FunctionCall { + return FunctionCall(inputs: []) { _, _ in + try function() + } +} + +public func ^ (function: @escaping (R1.Result) throws -> Result, inputs: (R1)) -> FunctionCall where R1: PartialRequest { + return FunctionCall(inputs: [inputs]) { + try function(inputs.fulfill(with: $0, and: $1)) + } +} + +public func ^ (function: @escaping (R1.Result, R2.Result) throws -> Result, inputs: (R1, R2)) -> FunctionCall where R1: PartialRequest, R2: PartialRequest { + return FunctionCall(inputs: [inputs.0, inputs.1]) { + try function(inputs.0.fulfill(with: $0, and: $1), inputs.1.fulfill(with: $0, and: $1)) + } +} + +public func ^ (function: @escaping (R1.Result, R2.Result, R3.Result) throws -> Result, inputs: (R1, R2, R3)) -> FunctionCall where R1: PartialRequest, R2: PartialRequest, R3: PartialRequest { + return FunctionCall(inputs: [inputs.0, inputs.1, inputs.2]) { + try function(inputs.0.fulfill(with: $0, and: $1), inputs.1.fulfill(with: $0, and: $1), inputs.2.fulfill(with: $0, and: $1)) + } +} + +public func ^ (function: @escaping (R1.Result, R2.Result, R3.Result, R4.Result) throws -> Result, inputs: (R1, R2, R3, R4)) -> FunctionCall where R1: PartialRequest, R2: PartialRequest, R3: PartialRequest, R4: PartialRequest { + return FunctionCall(inputs: [inputs.0, inputs.1, inputs.2, inputs.3]) { + try function(inputs.0.fulfill(with: $0, and: $1), inputs.1.fulfill(with: $0, and: $1), inputs.2.fulfill(with: $0, and: $1), inputs.3.fulfill(with: $0, and: $1)) + } +} + +public func ^ (function: @escaping (R1.Result, R2.Result, R3.Result, R4.Result, R5.Result) throws -> Result, inputs: (R1, R2, R3, R4, R5)) -> FunctionCall where R1: PartialRequest, R2: PartialRequest, R3: PartialRequest, R4: PartialRequest, R5: PartialRequest { + return FunctionCall(inputs: [inputs.0, inputs.1, inputs.2, inputs.3, inputs.4]) { + try function(inputs.0.fulfill(with: $0, and: $1), inputs.1.fulfill(with: $0, and: $1), inputs.2.fulfill(with: $0, and: $1), inputs.3.fulfill(with: $0, and: $1), inputs.4.fulfill(with: $0, and: $1)) + } +} + +public func ^ (function: @escaping (R1.Result, R2.Result, R3.Result, R4.Result, R5.Result, R6.Result) throws -> Result, inputs: (R1, R2, R3, R4, R5, R6)) -> FunctionCall where R1: PartialRequest, R2: PartialRequest, R3: PartialRequest, R4: PartialRequest, R5: PartialRequest, R6: PartialRequest { + return FunctionCall(inputs: [inputs.0, inputs.1, inputs.2, inputs.3, inputs.4, inputs.5]) { + try function(inputs.0.fulfill(with: $0, and: $1), inputs.1.fulfill(with: $0, and: $1), inputs.2.fulfill(with: $0, and: $1), inputs.3.fulfill(with: $0, and: $1), inputs.4.fulfill(with: $0, and: $1), inputs.5.fulfill(with: $0, and: $1)) + } +} + +public func ^ (function: @escaping (R1.Result, R2.Result, R3.Result, R4.Result, R5.Result, R6.Result, R7.Result) throws -> Result, inputs: (R1, R2, R3, R4, R5, R6, R7)) -> FunctionCall where R1: PartialRequest, R2: PartialRequest, R3: PartialRequest, R4: PartialRequest, R5: PartialRequest, R6: PartialRequest, R7: PartialRequest { + return FunctionCall(inputs: [inputs.0, inputs.1, inputs.2, inputs.3, inputs.4, inputs.5, inputs.6]) { + try function(inputs.0.fulfill(with: $0, and: $1), inputs.1.fulfill(with: $0, and: $1), inputs.2.fulfill(with: $0, and: $1), inputs.3.fulfill(with: $0, and: $1), inputs.4.fulfill(with: $0, and: $1), inputs.5.fulfill(with: $0, and: $1), inputs.6.fulfill(with: $0, and: $1)) + } +} + +public func ^ (function: @escaping (R1.Result, R2.Result, R3.Result, R4.Result, R5.Result, R6.Result, R7.Result, R8.Result) throws -> Result, inputs: (R1, R2, R3, R4, R5, R6, R7, R8)) -> FunctionCall where R1: PartialRequest, R2: PartialRequest, R3: PartialRequest, R4: PartialRequest, R5: PartialRequest, R6: PartialRequest, R7: PartialRequest, R8: PartialRequest { + return FunctionCall(inputs: [inputs.0, inputs.1, inputs.2, inputs.3, inputs.4, inputs.5, inputs.6, inputs.7]) { + try function(inputs.0.fulfill(with: $0, and: $1), inputs.1.fulfill(with: $0, and: $1), inputs.2.fulfill(with: $0, and: $1), inputs.3.fulfill(with: $0, and: $1), inputs.4.fulfill(with: $0, and: $1), inputs.5.fulfill(with: $0, and: $1), inputs.6.fulfill(with: $0, and: $1), inputs.7.fulfill(with: $0, and: $1)) + } +} + +public func ^ (function: @escaping (R1.Result, R2.Result, R3.Result, R4.Result, R5.Result, R6.Result, R7.Result, R8.Result, R9.Result) throws -> Result, inputs: (R1, R2, R3, R4, R5, R6, R7, R8, R9)) -> FunctionCall where R1: PartialRequest, R2: PartialRequest, R3: PartialRequest, R4: PartialRequest, R5: PartialRequest, R6: PartialRequest, R7: PartialRequest, R8: PartialRequest, R9: PartialRequest { + return FunctionCall(inputs: [inputs.0, inputs.1, inputs.2, inputs.3, inputs.4, inputs.5, inputs.6, inputs.7, inputs.8]) { + try function(inputs.0.fulfill(with: $0, and: $1), inputs.1.fulfill(with: $0, and: $1), inputs.2.fulfill(with: $0, and: $1), inputs.3.fulfill(with: $0, and: $1), inputs.4.fulfill(with: $0, and: $1), inputs.5.fulfill(with: $0, and: $1), inputs.6.fulfill(with: $0, and: $1), inputs.7.fulfill(with: $0, and: $1), inputs.8.fulfill(with: $0, and: $1)) + } +} + +public func ^ (function: @escaping (R1.Result, R2.Result, R3.Result, R4.Result, R5.Result, R6.Result, R7.Result, R8.Result, R9.Result, R10.Result) throws -> Result, inputs: (R1, R2, R3, R4, R5, R6, R7, R8, R9, R10)) -> FunctionCall where R1: PartialRequest, R2: PartialRequest, R3: PartialRequest, R4: PartialRequest, R5: PartialRequest, R6: PartialRequest, R7: PartialRequest, R8: PartialRequest, R9: PartialRequest, R10: PartialRequest { + return FunctionCall(inputs: [inputs.0, inputs.1, inputs.2, inputs.3, inputs.4, inputs.5, inputs.6, inputs.7, inputs.8, inputs.9]) { + try function(inputs.0.fulfill(with: $0, and: $1), inputs.1.fulfill(with: $0, and: $1), inputs.2.fulfill(with: $0, and: $1), inputs.3.fulfill(with: $0, and: $1), inputs.4.fulfill(with: $0, and: $1), inputs.5.fulfill(with: $0, and: $1), inputs.6.fulfill(with: $0, and: $1), inputs.7.fulfill(with: $0, and: $1), inputs.8.fulfill(with: $0, and: $1), inputs.9.fulfill(with: $0, and: $1)) + } +} + +public func ^ (function: @escaping (R1.Result, R2.Result, R3.Result, R4.Result, R5.Result, R6.Result, R7.Result, R8.Result, R9.Result, R10.Result, R11.Result) throws -> Result, inputs: (R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11)) -> FunctionCall where R1: PartialRequest, R2: PartialRequest, R3: PartialRequest, R4: PartialRequest, R5: PartialRequest, R6: PartialRequest, R7: PartialRequest, R8: PartialRequest, R9: PartialRequest, R10: PartialRequest, R11: PartialRequest { + return FunctionCall(inputs: [inputs.0, inputs.1, inputs.2, inputs.3, inputs.4, inputs.5, inputs.6, inputs.7, inputs.8, inputs.9, inputs.10]) { + try function(inputs.0.fulfill(with: $0, and: $1), inputs.1.fulfill(with: $0, and: $1), inputs.2.fulfill(with: $0, and: $1), inputs.3.fulfill(with: $0, and: $1), inputs.4.fulfill(with: $0, and: $1), inputs.5.fulfill(with: $0, and: $1), inputs.6.fulfill(with: $0, and: $1), inputs.7.fulfill(with: $0, and: $1), inputs.8.fulfill(with: $0, and: $1), inputs.9.fulfill(with: $0, and: $1), inputs.10.fulfill(with: $0, and: $1)) + } +} + +public func ^ (function: @escaping (R1.Result, R2.Result, R3.Result, R4.Result, R5.Result, R6.Result, R7.Result, R8.Result, R9.Result, R10.Result, R11.Result, R12.Result) throws -> Result, inputs: (R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12)) -> FunctionCall where R1: PartialRequest, R2: PartialRequest, R3: PartialRequest, R4: PartialRequest, R5: PartialRequest, R6: PartialRequest, R7: PartialRequest, R8: PartialRequest, R9: PartialRequest, R10: PartialRequest, R11: PartialRequest, R12: PartialRequest { + return FunctionCall(inputs: [inputs.0, inputs.1, inputs.2, inputs.3, inputs.4, inputs.5, inputs.6, inputs.7, inputs.8, inputs.9, inputs.10, inputs.11]) { + try function(inputs.0.fulfill(with: $0, and: $1), inputs.1.fulfill(with: $0, and: $1), inputs.2.fulfill(with: $0, and: $1), inputs.3.fulfill(with: $0, and: $1), inputs.4.fulfill(with: $0, and: $1), inputs.5.fulfill(with: $0, and: $1), inputs.6.fulfill(with: $0, and: $1), inputs.7.fulfill(with: $0, and: $1), inputs.8.fulfill(with: $0, and: $1), inputs.9.fulfill(with: $0, and: $1), inputs.10.fulfill(with: $0, and: $1), inputs.11.fulfill(with: $0, and: $1)) + } +} + +public func ^ (function: @escaping (R1.Result, R2.Result, R3.Result, R4.Result, R5.Result, R6.Result, R7.Result, R8.Result, R9.Result, R10.Result, R11.Result, R12.Result, R13.Result) throws -> Result, inputs: (R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, R13)) -> FunctionCall where R1: PartialRequest, R2: PartialRequest, R3: PartialRequest, R4: PartialRequest, R5: PartialRequest, R6: PartialRequest, R7: PartialRequest, R8: PartialRequest, R9: PartialRequest, R10: PartialRequest, R11: PartialRequest, R12: PartialRequest, R13: PartialRequest { + return FunctionCall(inputs: [inputs.0, inputs.1, inputs.2, inputs.3, inputs.4, inputs.5, inputs.6, inputs.7, inputs.8, inputs.9, inputs.10, inputs.11, inputs.12]) { + try function(inputs.0.fulfill(with: $0, and: $1), inputs.1.fulfill(with: $0, and: $1), inputs.2.fulfill(with: $0, and: $1), inputs.3.fulfill(with: $0, and: $1), inputs.4.fulfill(with: $0, and: $1), inputs.5.fulfill(with: $0, and: $1), inputs.6.fulfill(with: $0, and: $1), inputs.7.fulfill(with: $0, and: $1), inputs.8.fulfill(with: $0, and: $1), inputs.9.fulfill(with: $0, and: $1), inputs.10.fulfill(with: $0, and: $1), inputs.11.fulfill(with: $0, and: $1), inputs.12.fulfill(with: $0, and: $1)) + } +} + +public func ^ (function: @escaping (R1.Result, R2.Result, R3.Result, R4.Result, R5.Result, R6.Result, R7.Result, R8.Result, R9.Result, R10.Result, R11.Result, R12.Result, R13.Result, R14.Result) throws -> Result, inputs: (R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, R13, R14)) -> FunctionCall where R1: PartialRequest, R2: PartialRequest, R3: PartialRequest, R4: PartialRequest, R5: PartialRequest, R6: PartialRequest, R7: PartialRequest, R8: PartialRequest, R9: PartialRequest, R10: PartialRequest, R11: PartialRequest, R12: PartialRequest, R13: PartialRequest, R14: PartialRequest { + return FunctionCall(inputs: [inputs.0, inputs.1, inputs.2, inputs.3, inputs.4, inputs.5, inputs.6, inputs.7, inputs.8, inputs.9, inputs.10, inputs.11, inputs.12, inputs.13]) { + try function(inputs.0.fulfill(with: $0, and: $1), inputs.1.fulfill(with: $0, and: $1), inputs.2.fulfill(with: $0, and: $1), inputs.3.fulfill(with: $0, and: $1), inputs.4.fulfill(with: $0, and: $1), inputs.5.fulfill(with: $0, and: $1), inputs.6.fulfill(with: $0, and: $1), inputs.7.fulfill(with: $0, and: $1), inputs.8.fulfill(with: $0, and: $1), inputs.9.fulfill(with: $0, and: $1), inputs.10.fulfill(with: $0, and: $1), inputs.11.fulfill(with: $0, and: $1), inputs.12.fulfill(with: $0, and: $1), inputs.13.fulfill(with: $0, and: $1)) + } +} + +public func ^ (function: @escaping (R1.Result, R2.Result, R3.Result, R4.Result, R5.Result, R6.Result, R7.Result, R8.Result, R9.Result, R10.Result, R11.Result, R12.Result, R13.Result, R14.Result, R15.Result) throws -> Result, inputs: (R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, R13, R14, R15)) -> FunctionCall where R1: PartialRequest, R2: PartialRequest, R3: PartialRequest, R4: PartialRequest, R5: PartialRequest, R6: PartialRequest, R7: PartialRequest, R8: PartialRequest, R9: PartialRequest, R10: PartialRequest, R11: PartialRequest, R12: PartialRequest, R13: PartialRequest, R14: PartialRequest, R15: PartialRequest { + return FunctionCall(inputs: [inputs.0, inputs.1, inputs.2, inputs.3, inputs.4, inputs.5, inputs.6, inputs.7, inputs.8, inputs.9, inputs.10, inputs.11, inputs.12, inputs.13, inputs.14]) { + try function(inputs.0.fulfill(with: $0, and: $1), inputs.1.fulfill(with: $0, and: $1), inputs.2.fulfill(with: $0, and: $1), inputs.3.fulfill(with: $0, and: $1), inputs.4.fulfill(with: $0, and: $1), inputs.5.fulfill(with: $0, and: $1), inputs.6.fulfill(with: $0, and: $1), inputs.7.fulfill(with: $0, and: $1), inputs.8.fulfill(with: $0, and: $1), inputs.9.fulfill(with: $0, and: $1), inputs.10.fulfill(with: $0, and: $1), inputs.11.fulfill(with: $0, and: $1), inputs.12.fulfill(with: $0, and: $1), inputs.13.fulfill(with: $0, and: $1), inputs.14.fulfill(with: $0, and: $1)) + } +} + +public func ^ (function: @escaping (R1.Result, R2.Result, R3.Result, R4.Result, R5.Result, R6.Result, R7.Result, R8.Result, R9.Result, R10.Result, R11.Result, R12.Result, R13.Result, R14.Result, R15.Result, R16.Result) throws -> Result, inputs: (R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, R13, R14, R15, R16)) -> FunctionCall where R1: PartialRequest, R2: PartialRequest, R3: PartialRequest, R4: PartialRequest, R5: PartialRequest, R6: PartialRequest, R7: PartialRequest, R8: PartialRequest, R9: PartialRequest, R10: PartialRequest, R11: PartialRequest, R12: PartialRequest, R13: PartialRequest, R14: PartialRequest, R15: PartialRequest, R16: PartialRequest { + return FunctionCall(inputs: [inputs.0, inputs.1, inputs.2, inputs.3, inputs.4, inputs.5, inputs.6, inputs.7, inputs.8, inputs.9, inputs.10, inputs.11, inputs.12, inputs.13, inputs.14, inputs.15]) { + try function(inputs.0.fulfill(with: $0, and: $1), inputs.1.fulfill(with: $0, and: $1), inputs.2.fulfill(with: $0, and: $1), inputs.3.fulfill(with: $0, and: $1), inputs.4.fulfill(with: $0, and: $1), inputs.5.fulfill(with: $0, and: $1), inputs.6.fulfill(with: $0, and: $1), inputs.7.fulfill(with: $0, and: $1), inputs.8.fulfill(with: $0, and: $1), inputs.9.fulfill(with: $0, and: $1), inputs.10.fulfill(with: $0, and: $1), inputs.11.fulfill(with: $0, and: $1), inputs.12.fulfill(with: $0, and: $1), inputs.13.fulfill(with: $0, and: $1), inputs.14.fulfill(with: $0, and: $1), inputs.15.fulfill(with: $0, and: $1)) + } +} + +public func ^ (function: @escaping (R1.Result, R2.Result, R3.Result, R4.Result, R5.Result, R6.Result, R7.Result, R8.Result, R9.Result, R10.Result, R11.Result, R12.Result, R13.Result, R14.Result, R15.Result, R16.Result, R17.Result) throws -> Result, inputs: (R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, R13, R14, R15, R16, R17)) -> FunctionCall where R1: PartialRequest, R2: PartialRequest, R3: PartialRequest, R4: PartialRequest, R5: PartialRequest, R6: PartialRequest, R7: PartialRequest, R8: PartialRequest, R9: PartialRequest, R10: PartialRequest, R11: PartialRequest, R12: PartialRequest, R13: PartialRequest, R14: PartialRequest, R15: PartialRequest, R16: PartialRequest, R17: PartialRequest { + return FunctionCall(inputs: [inputs.0, inputs.1, inputs.2, inputs.3, inputs.4, inputs.5, inputs.6, inputs.7, inputs.8, inputs.9, inputs.10, inputs.11, inputs.12, inputs.13, inputs.14, inputs.15, inputs.16]) { + try function(inputs.0.fulfill(with: $0, and: $1), inputs.1.fulfill(with: $0, and: $1), inputs.2.fulfill(with: $0, and: $1), inputs.3.fulfill(with: $0, and: $1), inputs.4.fulfill(with: $0, and: $1), inputs.5.fulfill(with: $0, and: $1), inputs.6.fulfill(with: $0, and: $1), inputs.7.fulfill(with: $0, and: $1), inputs.8.fulfill(with: $0, and: $1), inputs.9.fulfill(with: $0, and: $1), inputs.10.fulfill(with: $0, and: $1), inputs.11.fulfill(with: $0, and: $1), inputs.12.fulfill(with: $0, and: $1), inputs.13.fulfill(with: $0, and: $1), inputs.14.fulfill(with: $0, and: $1), inputs.15.fulfill(with: $0, and: $1), inputs.16.fulfill(with: $0, and: $1)) + } +} + +public func ^ (function: @escaping (R1.Result, R2.Result, R3.Result, R4.Result, R5.Result, R6.Result, R7.Result, R8.Result, R9.Result, R10.Result, R11.Result, R12.Result, R13.Result, R14.Result, R15.Result, R16.Result, R17.Result, R18.Result) throws -> Result, inputs: (R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, R13, R14, R15, R16, R17, R18)) -> FunctionCall where R1: PartialRequest, R2: PartialRequest, R3: PartialRequest, R4: PartialRequest, R5: PartialRequest, R6: PartialRequest, R7: PartialRequest, R8: PartialRequest, R9: PartialRequest, R10: PartialRequest, R11: PartialRequest, R12: PartialRequest, R13: PartialRequest, R14: PartialRequest, R15: PartialRequest, R16: PartialRequest, R17: PartialRequest, R18: PartialRequest { + return FunctionCall(inputs: [inputs.0, inputs.1, inputs.2, inputs.3, inputs.4, inputs.5, inputs.6, inputs.7, inputs.8, inputs.9, inputs.10, inputs.11, inputs.12, inputs.13, inputs.14, inputs.15, inputs.16, inputs.17]) { + try function(inputs.0.fulfill(with: $0, and: $1), inputs.1.fulfill(with: $0, and: $1), inputs.2.fulfill(with: $0, and: $1), inputs.3.fulfill(with: $0, and: $1), inputs.4.fulfill(with: $0, and: $1), inputs.5.fulfill(with: $0, and: $1), inputs.6.fulfill(with: $0, and: $1), inputs.7.fulfill(with: $0, and: $1), inputs.8.fulfill(with: $0, and: $1), inputs.9.fulfill(with: $0, and: $1), inputs.10.fulfill(with: $0, and: $1), inputs.11.fulfill(with: $0, and: $1), inputs.12.fulfill(with: $0, and: $1), inputs.13.fulfill(with: $0, and: $1), inputs.14.fulfill(with: $0, and: $1), inputs.15.fulfill(with: $0, and: $1), inputs.16.fulfill(with: $0, and: $1), inputs.17.fulfill(with: $0, and: $1)) + } +} + +public func ^ (function: @escaping (R1.Result, R2.Result, R3.Result, R4.Result, R5.Result, R6.Result, R7.Result, R8.Result, R9.Result, R10.Result, R11.Result, R12.Result, R13.Result, R14.Result, R15.Result, R16.Result, R17.Result, R18.Result, R19.Result) throws -> Result, inputs: (R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, R13, R14, R15, R16, R17, R18, R19)) -> FunctionCall where R1: PartialRequest, R2: PartialRequest, R3: PartialRequest, R4: PartialRequest, R5: PartialRequest, R6: PartialRequest, R7: PartialRequest, R8: PartialRequest, R9: PartialRequest, R10: PartialRequest, R11: PartialRequest, R12: PartialRequest, R13: PartialRequest, R14: PartialRequest, R15: PartialRequest, R16: PartialRequest, R17: PartialRequest, R18: PartialRequest, R19: PartialRequest { + return FunctionCall(inputs: [inputs.0, inputs.1, inputs.2, inputs.3, inputs.4, inputs.5, inputs.6, inputs.7, inputs.8, inputs.9, inputs.10, inputs.11, inputs.12, inputs.13, inputs.14, inputs.15, inputs.16, inputs.17, inputs.18]) { + try function(inputs.0.fulfill(with: $0, and: $1), inputs.1.fulfill(with: $0, and: $1), inputs.2.fulfill(with: $0, and: $1), inputs.3.fulfill(with: $0, and: $1), inputs.4.fulfill(with: $0, and: $1), inputs.5.fulfill(with: $0, and: $1), inputs.6.fulfill(with: $0, and: $1), inputs.7.fulfill(with: $0, and: $1), inputs.8.fulfill(with: $0, and: $1), inputs.9.fulfill(with: $0, and: $1), inputs.10.fulfill(with: $0, and: $1), inputs.11.fulfill(with: $0, and: $1), inputs.12.fulfill(with: $0, and: $1), inputs.13.fulfill(with: $0, and: $1), inputs.14.fulfill(with: $0, and: $1), inputs.15.fulfill(with: $0, and: $1), inputs.16.fulfill(with: $0, and: $1), inputs.17.fulfill(with: $0, and: $1), inputs.18.fulfill(with: $0, and: $1)) + } +} + +public func ^ (function: @escaping (R1.Result, R2.Result, R3.Result, R4.Result, R5.Result, R6.Result, R7.Result, R8.Result, R9.Result, R10.Result, R11.Result, R12.Result, R13.Result, R14.Result, R15.Result, R16.Result, R17.Result, R18.Result, R19.Result, R20.Result) throws -> Result, inputs: (R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, R13, R14, R15, R16, R17, R18, R19, R20)) -> FunctionCall where R1: PartialRequest, R2: PartialRequest, R3: PartialRequest, R4: PartialRequest, R5: PartialRequest, R6: PartialRequest, R7: PartialRequest, R8: PartialRequest, R9: PartialRequest, R10: PartialRequest, R11: PartialRequest, R12: PartialRequest, R13: PartialRequest, R14: PartialRequest, R15: PartialRequest, R16: PartialRequest, R17: PartialRequest, R18: PartialRequest, R19: PartialRequest, R20: PartialRequest { + return FunctionCall(inputs: [inputs.0, inputs.1, inputs.2, inputs.3, inputs.4, inputs.5, inputs.6, inputs.7, inputs.8, inputs.9, inputs.10, inputs.11, inputs.12, inputs.13, inputs.14, inputs.15, inputs.16, inputs.17, inputs.18, inputs.19]) { + try function(inputs.0.fulfill(with: $0, and: $1), inputs.1.fulfill(with: $0, and: $1), inputs.2.fulfill(with: $0, and: $1), inputs.3.fulfill(with: $0, and: $1), inputs.4.fulfill(with: $0, and: $1), inputs.5.fulfill(with: $0, and: $1), inputs.6.fulfill(with: $0, and: $1), inputs.7.fulfill(with: $0, and: $1), inputs.8.fulfill(with: $0, and: $1), inputs.9.fulfill(with: $0, and: $1), inputs.10.fulfill(with: $0, and: $1), inputs.11.fulfill(with: $0, and: $1), inputs.12.fulfill(with: $0, and: $1), inputs.13.fulfill(with: $0, and: $1), inputs.14.fulfill(with: $0, and: $1), inputs.15.fulfill(with: $0, and: $1), inputs.16.fulfill(with: $0, and: $1), inputs.17.fulfill(with: $0, and: $1), inputs.18.fulfill(with: $0, and: $1), inputs.19.fulfill(with: $0, and: $1)) + } +} + +// sourcery:end diff --git a/Sources/3.0 API/PartialRequest.swift b/Sources/3.0 API/PartialRequest.swift index 1a8d853f..03e637f3 100644 --- a/Sources/3.0 API/PartialRequest.swift +++ b/Sources/3.0 API/PartialRequest.swift @@ -10,20 +10,13 @@ public enum PartialDependency { public protocol AnyPartialRequest { var asDependency: PartialDependency { get } - func fulfill(with resolver: Resolver, and arguments: Arguments) throws -> Any } -protocol PartialRequest: AnyPartialRequest { +public protocol PartialRequest: AnyPartialRequest { associatedtype Result func fulfill(with resolver: Resolver, and arguments: Arguments) throws -> Result } -extension PartialRequest { - public func fulfill(with resolver: Resolver, and arguments: Arguments) throws -> Any { - return try fulfill(with: resolver, and: arguments) as Result - } -} - public struct ContextRequest {} public struct ArgumentRequest { @@ -41,7 +34,7 @@ public func argument(_ index: Int, as _: Type.Type = Type.self) -> Argumen extension InstanceRequest: PartialRequest { public var asDependency: PartialDependency { return .instance(type, arguments.descriptor) } - func fulfill(with resolver: Resolver, and _: Arguments) throws -> Type { + public func fulfill(with resolver: Resolver, and _: Arguments) throws -> Type { return try resolver.resolve(self) } } @@ -49,7 +42,7 @@ extension InstanceRequest: PartialRequest { extension ArgumentRequest: PartialRequest { public var asDependency: PartialDependency { return .argument(Type.self) } - func fulfill(with _: Resolver, and arguments: Arguments) throws -> Type { + public func fulfill(with _: Resolver, and arguments: Arguments) throws -> Type { return try arguments.arg(index) } } @@ -57,7 +50,7 @@ extension ArgumentRequest: PartialRequest { extension ContextRequest: PartialRequest { public var asDependency: PartialDependency { return .context(Type.self) } - func fulfill(with resolver: Resolver, and _: Arguments) throws -> Type { + public func fulfill(with resolver: Resolver, and _: Arguments) throws -> Type { return try resolver.contexted().context() } } diff --git a/Sources/3.0 API/Resolver+FunctionCall.swift b/Sources/3.0 API/Resolver+FunctionCall.swift deleted file mode 100644 index 000a4abf..00000000 --- a/Sources/3.0 API/Resolver+FunctionCall.swift +++ /dev/null @@ -1,89 +0,0 @@ -// -// Copyright © 2019 Swinject Contributors. All rights reserved. -// - -// swiftlint:disable line_length -// sourcery:inline:ResolverFunctionCallApi -public extension Resolver { - func call1(_ function: (P1) -> Output) throws -> Output { - return try function(resolve(instance())) - } - - func call(_ function: (P1, P2) -> Output) throws -> Output { - return try function(resolve(instance()), resolve(instance())) - } - - func call(_ function: (P1, P2, P3) -> Output) throws -> Output { - return try function(resolve(instance()), resolve(instance()), resolve(instance())) - } - - func call(_ function: (P1, P2, P3, P4) -> Output) throws -> Output { - return try function(resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance())) - } - - func call(_ function: (P1, P2, P3, P4, P5) -> Output) throws -> Output { - return try function(resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance())) - } - - func call(_ function: (P1, P2, P3, P4, P5, P6) -> Output) throws -> Output { - return try function(resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance())) - } - - func call(_ function: (P1, P2, P3, P4, P5, P6, P7) -> Output) throws -> Output { - return try function(resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance())) - } - - func call(_ function: (P1, P2, P3, P4, P5, P6, P7, P8) -> Output) throws -> Output { - return try function(resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance())) - } - - func call(_ function: (P1, P2, P3, P4, P5, P6, P7, P8, P9) -> Output) throws -> Output { - return try function(resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance())) - } - - func call(_ function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10) -> Output) throws -> Output { - return try function(resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance())) - } - - func call(_ function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11) -> Output) throws -> Output { - return try function(resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance())) - } - - func call(_ function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12) -> Output) throws -> Output { - return try function(resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance())) - } - - func call(_ function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13) -> Output) throws -> Output { - return try function(resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance())) - } - - func call(_ function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14) -> Output) throws -> Output { - return try function(resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance())) - } - - func call(_ function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15) -> Output) throws -> Output { - return try function(resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance())) - } - - func call(_ function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16) -> Output) throws -> Output { - return try function(resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance())) - } - - func call(_ function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17) -> Output) throws -> Output { - return try function(resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance())) - } - - func call(_ function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18) -> Output) throws -> Output { - return try function(resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance())) - } - - func call(_ function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19) -> Output) throws -> Output { - return try function(resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance())) - } - - func call(_ function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20) -> Output) throws -> Output { - return try function(resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance()), resolve(instance())) - } -} - -// sourcery:end diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 07add8fe..03718275 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -41,7 +41,6 @@ 19F21849D1E173F5AC724281 /* UnboundScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 667B13B528642272FC0794B6 /* UnboundScope.swift */; }; 1A40A26942A65246D7DD268E /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = ADC44E9312C3B974AFD8F07B /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 1A68A8D05D9974002BF34CF8 /* RetrievalSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D8B3342E2AC3236F12072F5 /* RetrievalSpec.swift */; }; - 1AC00BCB4DB26B078203DAD8 /* Resolver+FunctionCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F626B9D3E547621787E4D7 /* Resolver+FunctionCall.swift */; }; 1B03DC8F071E5395A3B38FCE /* ArgumentVariations.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 193B78CD40CD179E9DD99B64 /* ArgumentVariations.swifttemplate */; }; 1C62135FAE3D64DC7BFBF861 /* ContextSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD2E1DF87A61DDC9110D91B2 /* ContextSpec.swift */; }; 1CA5DF3F93203B226A6FA059 /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EA566CD336DB8343ADFAF9B /* BehaviorFakes.swift */; }; @@ -86,7 +85,6 @@ 3C270A77DE4F1E6BC2F8E863 /* ContainerSpec.TypeForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86EE3DDCF0BD65D4EDEA615 /* ContainerSpec.TypeForwarding.swift */; }; 3CEF021295AD9AF9BF26B71E /* SwinjectTreeBuilderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CABCE76AA0EF1BD720F65E0 /* SwinjectTreeBuilderSpec.swift */; }; 3DEFB7CA42D9EFF0B4FBC0F4 /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 38BCCF3F950869BD1891F7A8 /* Swinject.framework */; }; - 3EC8383BEAC339595CF7F927 /* Resolver+FunctionCallApi.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 176824B29DD1A0DAA5CBD241 /* Resolver+FunctionCallApi.swifttemplate */; }; 401592294E5D528379BE1AB2 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62682D6ED38742996624B041 /* BasicAssembly.swift */; }; 41BD3DC77CA877DB46844B18 /* Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDDA125B54235F76F7A34730 /* Arguments.swift */; }; 41C7340BFD2EB66359772733 /* Resolver+LegacyApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A784E2DEC7691D14DDBECD8 /* Resolver+LegacyApi.swift */; }; @@ -119,7 +117,6 @@ 599C7F009F954CDA522244B3 /* BasicAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62682D6ED38742996624B041 /* BasicAssembly.swift */; }; 59FD1167CD4A913E04D3EAFD /* ServiceEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38615FC8EEB466C5C1EAD21C /* ServiceEntry.swift */; }; 5A74DF28BBEBC4E494E67162 /* AnyBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 020903EC58FDC4727852CAF4 /* AnyBinding.swift */; }; - 5A78C354D420D64CF8A787C1 /* Resolver+FunctionCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F626B9D3E547621787E4D7 /* Resolver+FunctionCall.swift */; }; 5BD767B85CFE5FADDFE0A7B5 /* UnboundScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 667B13B528642272FC0794B6 /* UnboundScope.swift */; }; 5C56C1E893D53B2311D27416 /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 10E8C7E53982E88175FD04A7 /* .swiftlint.yml */; }; 5D5852F610358DFF7230C35C /* Assembler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59111BE319C59E4CD6CF68CD /* Assembler.swift */; }; @@ -166,6 +163,7 @@ 77F957FA231298E400FD392A /* FunctionCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F957F8231298E400FD392A /* FunctionCall.swift */; }; 77F957FB231298E400FD392A /* FunctionCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F957F8231298E400FD392A /* FunctionCall.swift */; }; 77F957FC231298E400FD392A /* FunctionCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F957F8231298E400FD392A /* FunctionCall.swift */; }; + 77F957FE2312A4C600FD392A /* FunctionCallVariations.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 77F957FD2312A4C600FD392A /* FunctionCallVariations.swifttemplate */; }; 789BF74652A2424EB8F7EF47 /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 7A7032384E07DAD308D4F70A /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 8B9785AAE94A5447FA307242 /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 7D6F664091C70BABBFB61D53 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; @@ -183,7 +181,6 @@ 875D809B53B3A118AAF1348C /* Retrieval.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28D11412EEA912FD369E0D4B /* Retrieval.swift */; }; 87FEAEF562B99522083CB87D /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2DC5DE630207F56B6CD9EF /* Matchable.swift */; }; 890CCD2800597F6FB7C6FD31 /* SynchronizedResolverSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */; }; - 8A4E9E736239F92F878C070C /* Resolver+FunctionCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F626B9D3E547621787E4D7 /* Resolver+FunctionCall.swift */; }; 8B5927517B567B1DFAB5B935 /* ContextTranslator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */; }; 8B711CBE6A5B86DC2D6CABDC /* UnboundScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 667B13B528642272FC0794B6 /* UnboundScope.swift */; }; 8E1E051646BBD6E38F4199C2 /* BehaviorFakes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EA566CD336DB8343ADFAF9B /* BehaviorFakes.swift */; }; @@ -229,7 +226,6 @@ A7DD08A60F12EC078BBE086F /* ContainerSpec.Behavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */; }; A834D948AB86794CA3304B98 /* LinuxConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 938425B216B78A06EC10504A /* LinuxConfig.swift */; }; A882705E4199EF759E80B311 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB605ED0F735221D0EB1D5F /* Convenience.swift */; }; - A9112F7CF871475B94A077D7 /* Resolver+FunctionCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9F626B9D3E547621787E4D7 /* Resolver+FunctionCall.swift */; }; A91EDAFBC3606EDFBD739899 /* InstanceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AA3031083A039CCD929CD12 /* InstanceWrapper.swift */; }; A9A242086D1EDE408DC556D0 /* ContainerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B0E1B8963622CA872FA45B /* ContainerSpec.swift */; }; AAC6F2F5EC2928943BF2BED1 /* PropertyWrappersSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49B24254B9F0E48ED3713565 /* PropertyWrappersSpec.swift */; }; @@ -475,7 +471,6 @@ 118ABC654C4144496848AD74 /* CIrcularitySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CIrcularitySpec.swift; sourceTree = ""; }; 11BC689CB98FD2079AC0B410 /* SynchronizedResolverSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SynchronizedResolverSpec.swift; sourceTree = ""; }; 13513FA012659ADE699A3608 /* LazySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LazySpec.swift; sourceTree = ""; }; - 176824B29DD1A0DAA5CBD241 /* Resolver+FunctionCallApi.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Resolver+FunctionCallApi.swifttemplate"; sourceTree = ""; }; 193B78CD40CD179E9DD99B64 /* ArgumentVariations.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = ArgumentVariations.swifttemplate; sourceTree = ""; }; 1A006CC804F9AB8ACC121029 /* Utils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = ""; }; 1C58FC14EEA170B0DC079DE4 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; @@ -526,6 +521,7 @@ 74DE57FB3E8228904E6FE0D7 /* Swinject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Swinject.h; sourceTree = ""; }; 75BE3AE3E30DFE42A919D825 /* ModulesSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModulesSpec.swift; sourceTree = ""; }; 77F957F8231298E400FD392A /* FunctionCall.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FunctionCall.swift; sourceTree = ""; }; + 77F957FD2312A4C600FD392A /* FunctionCallVariations.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = FunctionCallVariations.swifttemplate; sourceTree = ""; }; 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ServiceEntry+TypeForwarding.swift"; sourceTree = ""; }; 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextTranslator.swift; sourceTree = ""; }; 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistry.swift; sourceTree = ""; }; @@ -550,7 +546,6 @@ ADC44E9312C3B974AFD8F07B /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; B0C926D1E315E596E450D7D6 /* AssemblerSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AssemblerSpec.swift; sourceTree = ""; }; B59A3946B59EB4D787CCE9F2 /* Container+Registration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Registration.swift"; sourceTree = ""; }; - B9F626B9D3E547621787E4D7 /* Resolver+FunctionCall.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Resolver+FunctionCall.swift"; sourceTree = ""; }; BAF68BC7EEE11B52D4D6FB94 /* StandardScopeRegistrySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StandardScopeRegistrySpec.swift; sourceTree = ""; }; BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = "ServiceEntry+TypeForwarding.swifttemplate"; sourceTree = ""; }; BEFFEE7870660D8AB209459D /* ContainerSpec.Behavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.Behavior.swift; sourceTree = ""; }; @@ -621,10 +616,10 @@ 193B78CD40CD179E9DD99B64 /* ArgumentVariations.swifttemplate */, E8A39A3F1C11C85BF0D0A9B1 /* Binding+Factory.swifttemplate */, CDF0639C00CFE55484D487CE /* Container+Registration.swifttemplate */, + 77F957FD2312A4C600FD392A /* FunctionCallVariations.swifttemplate */, 5FBCA343BDC1493D29B286C2 /* FactoryVariation.swift */, 076C2114835DCF003BE040B7 /* InstanceRequest+Api.swifttemplate */, 22F5FE25C34A0D7124528088 /* InstanceRequestVariation.swift */, - 176824B29DD1A0DAA5CBD241 /* Resolver+FunctionCallApi.swifttemplate */, FE0EA1AA356CC46F4AB8AA3F /* Resolver+LegacyApi.swifttemplate */, BD6E47826E8E3D3744E91ADC /* ServiceEntry+TypeForwarding.swifttemplate */, 90191C25A2D66E07C4E9CD73 /* SwiftCode.swifttemplate */, @@ -673,7 +668,6 @@ C603FD109D6B1496A21B2F8D /* Binding+Api.swift */, DDAE85794B8BBB70A76A0016 /* Binding+Factory.swift */, 980BDFC415DEF2099DF9E89A /* InstanceRequest+APi.swift */, - B9F626B9D3E547621787E4D7 /* Resolver+FunctionCall.swift */, 28D11412EEA912FD369E0D4B /* Retrieval.swift */, 3874152C14D0A7F8C5151779 /* Swinject+Builder.swift */, 667B13B528642272FC0794B6 /* UnboundScope.swift */, @@ -1159,9 +1153,9 @@ 1FB4AED93C9EEF9760913558 /* Binding+Factory.swifttemplate in Resources */, BFE22F9F2E88F177302E9D19 /* Container+Registration.swifttemplate in Resources */, 082EBD694ADF41DB4C53BD5A /* InstanceRequest+Api.swifttemplate in Resources */, - 3EC8383BEAC339595CF7F927 /* Resolver+FunctionCallApi.swifttemplate in Resources */, F568382FB877060127790413 /* Resolver+LegacyApi.swifttemplate in Resources */, B7653A6427A5E284E9A1D6D3 /* ServiceEntry+TypeForwarding.swifttemplate in Resources */, + 77F957FE2312A4C600FD392A /* FunctionCallVariations.swifttemplate in Resources */, EBC64A1515C868E410C83451 /* SwiftCode.swifttemplate in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1430,7 +1424,6 @@ 3753FB83A1FB4B83891AA5C8 /* ObjectScope.swift in Sources */, 5393E5DE21B568A88498E454 /* PropertyWrapper.swift in Sources */, 3BD6055555A5C30DABDC8ED2 /* Reference.swift in Sources */, - A9112F7CF871475B94A077D7 /* Resolver+FunctionCall.swift in Sources */, D4936DC1A47A8C85325FB52E /* Resolver+LegacyApi.swift in Sources */, 8016512839FE61EC3127E489 /* Resolver.swift in Sources */, 77F957FA231298E400FD392A /* FunctionCall.swift in Sources */, @@ -1651,7 +1644,6 @@ B4B66D7251BDDE25D6D7FB3C /* ObjectScope.swift in Sources */, 6A967AE5710606998C2BE070 /* PropertyWrapper.swift in Sources */, B293894FEB67831DDA5F000E /* Reference.swift in Sources */, - 8A4E9E736239F92F878C070C /* Resolver+FunctionCall.swift in Sources */, E177D354B1F410129D921C69 /* Resolver+LegacyApi.swift in Sources */, 5D7E26A00B055803A50CD9C2 /* Resolver.swift in Sources */, 77F957FB231298E400FD392A /* FunctionCall.swift in Sources */, @@ -1698,7 +1690,6 @@ 6DA49F84E2592B32F81F268B /* ObjectScope.swift in Sources */, 5F1647DCC0D437A782647372 /* PropertyWrapper.swift in Sources */, 2D020C6391A4F6A2118585B8 /* Reference.swift in Sources */, - 1AC00BCB4DB26B078203DAD8 /* Resolver+FunctionCall.swift in Sources */, FD7B2663F2F931B78EB330EE /* Resolver+LegacyApi.swift in Sources */, 97C2EA47D7623AFD723AFE93 /* Resolver.swift in Sources */, 77F957FC231298E400FD392A /* FunctionCall.swift in Sources */, @@ -1745,7 +1736,6 @@ B42331BF00B482369B908BB8 /* ObjectScope.swift in Sources */, 14C8DA4FCCDFA87885038D38 /* PropertyWrapper.swift in Sources */, 0509EE8D41BF354EB91ACC80 /* Reference.swift in Sources */, - 5A78C354D420D64CF8A787C1 /* Resolver+FunctionCall.swift in Sources */, 41C7340BFD2EB66359772733 /* Resolver+LegacyApi.swift in Sources */, BE94EF7BCF976A703F961389 /* Resolver.swift in Sources */, 77F957F9231298E400FD392A /* FunctionCall.swift in Sources */, diff --git a/Templates/FunctionCallVariations.swifttemplate b/Templates/FunctionCallVariations.swifttemplate new file mode 100644 index 00000000..1b081d72 --- /dev/null +++ b/Templates/FunctionCallVariations.swifttemplate @@ -0,0 +1,30 @@ +<% let maxParams = 20 %> +// sourcery:inline:FunctionCallVariations +<%_ for n in 0 ... maxParams { + let inputTypes = (0 ..< n).map { "I\($0+1)" }.joined(separator: ", ") + let genericParams = n == 0 ? "Result" : "Result, \(inputTypes)" + let requests = (0 ..< n).map { _ in "instance()" }.joined(separator: ", ") +-%> +public postfix func ^ <<%= genericParams %>>(function: @escaping (<%= inputTypes %>) throws -> Result) -> FunctionCall { + return function^(<%= requests %>) +} + +<%_ } -%> +<%_ for n in 0 ... maxParams { + let requestTypes = (0 ..< n).map { "R\($0+1)" }.joined(separator: ", ") + let genericParams = n == 0 ? "Result" : "Result, \(requestTypes)" + let inputTypes = (0 ..< n).map { "R\($0+1).Result" }.joined(separator: ", ") + let constraints = (0 ..< n).map { "R\($0+1): PartialRequest" }.joined(separator: ", ") + let whereClause = n == 0 ? "" : " where \(constraints)" + let requestVars = n == 1 ? "inputs" : (0 ..< n).map { "inputs.\($0)" }.joined(separator: ", ") + let inputVars = n == 1 ? "inputs.fulfill(with: $0, and: $1)" : (0 ..< n).map { "inputs.\($0).fulfill(with: $0, and: $1)" }.joined(separator: ", ") + let executionInputs = n == 0 ? " _, _ in" : "" + let inputsParam = n == 0 ? "_" : "inputs" +-%> +public func ^ <<%= genericParams %>>(function: @escaping (<%= inputTypes %>) throws -> Result, <%= inputsParam %>: (<%= requestTypes %>)) -> FunctionCall<%= whereClause %> { + return FunctionCall(inputs: [<%= requestVars %>]) {<%= executionInputs %> + try function(<%= inputVars %>) + } +}<%= n < maxParams ? "\n" : "" %> +<%_ } -%> +// sourcery:end diff --git a/Templates/Resolver+FunctionCallApi.swifttemplate b/Templates/Resolver+FunctionCallApi.swifttemplate deleted file mode 100644 index f6fd7854..00000000 --- a/Templates/Resolver+FunctionCallApi.swifttemplate +++ /dev/null @@ -1,14 +0,0 @@ -<% let maxParams = 20 %> -// sourcery:inline:ResolverFunctionCallApi -public extension Resolver { -<%_ for n in 1 ... maxParams { - let paramTypes = (1 ... n).map { "P\($0)" }.joined(separator: ", ") - let instances = (1 ... n).map { _ in "resolve(instance())" }.joined(separator: ", ") - let methodName = n == 1 ? "call1" : "call" --%> - func <%= methodName %>>(_ function: (<%= paramTypes %>) -> Output) throws -> Output { - return try function(<%= instances %>) - }<%= n < maxParams ? "\n" : "" %> -<%_ } -%> -} -// sourcery:end diff --git a/Tests/3.0 API/InjectionSpec.swift b/Tests/3.0 API/InjectionSpec.swift index c2b37b19..6cc661c9 100644 --- a/Tests/3.0 API/InjectionSpec.swift +++ b/Tests/3.0 API/InjectionSpec.swift @@ -36,51 +36,5 @@ class InjectionSpec: QuickSpec { override func spec() { #if swift(>=5.1) expect { try instance(of: Int.self).from(swinject) }.to(throwError(errorType: TestError.self)) } } - // TODO: Refactor - describe("function call") { - it("can inject parameter to the function") { - func echo(int: Int) -> Int { - return int - } - let swinject = Swinject { - register().constant(42) - } - expect { try swinject.call1(echo) } == 42 - } - it("can inject multiple parameters to the function") { - func sum(int: Int, double: Double, string: String) -> Int { - return int + Int(double) + Int(string)! - } - let swinject = Swinject { - register().constant(17) - register().constant(14.0) - register().constant("11") - } - expect { try swinject.call(sum) } == 42 - } - it("can call initializer when declaring bindings") { - let john = Human() - let swinject = Swinject { - register().constant("mimi") - register().constant(john) - register().factory { try $0.call(Pet.init) } - } - let pet = try? instance(of: Pet.self).from(swinject) - expect(pet?.name) == "mimi" - expect(pet?.owner) === john - } - it("can be used for property injection") { - let swinject = Swinject { - register().constant(42) - register().constant(124 as Double) - register().constant("john") - } - let john = Human() - try? swinject.call(john.injectProperties) - expect(john.age) == 42 - expect(john.height) == 124 - expect(john.name) == "john" - } - } #endif } } From b97b7c9c7ec26e728a1b797066dfd8b23991ba9e Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Sun, 25 Aug 2019 14:10:01 +0200 Subject: [PATCH 233/239] Describe function call usage --- Sources/3.0 API/FunctionCall.swift | 4 -- Swinject.xcodeproj/project.pbxproj | 10 ++++ .../FunctionCallVariations.swifttemplate | 1 + Tests/3.0 API/DependencyCheckSpec.swift | 58 +++++++++++++++++++ Tests/LinuxConfig.swift | 1 + 5 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 Tests/3.0 API/DependencyCheckSpec.swift diff --git a/Sources/3.0 API/FunctionCall.swift b/Sources/3.0 API/FunctionCall.swift index eb2d272b..4b3f4040 100644 --- a/Sources/3.0 API/FunctionCall.swift +++ b/Sources/3.0 API/FunctionCall.swift @@ -17,10 +17,6 @@ public postfix func ^ (function: @escaping () throws -> Result) -> Funct return function^() } -public postfix func ^ (function: @escaping (I1) throws -> Result) -> FunctionCall { - return function^(instance()) -} - public postfix func ^ (function: @escaping (I1, I2) throws -> Result) -> FunctionCall { return function^(instance(), instance()) } diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 03718275..b205da76 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -164,6 +164,10 @@ 77F957FB231298E400FD392A /* FunctionCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F957F8231298E400FD392A /* FunctionCall.swift */; }; 77F957FC231298E400FD392A /* FunctionCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F957F8231298E400FD392A /* FunctionCall.swift */; }; 77F957FE2312A4C600FD392A /* FunctionCallVariations.swifttemplate in Resources */ = {isa = PBXBuildFile; fileRef = 77F957FD2312A4C600FD392A /* FunctionCallVariations.swifttemplate */; }; + 77F958002312ACFF00FD392A /* DependencyCheckSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F957FF2312ACFF00FD392A /* DependencyCheckSpec.swift */; }; + 77F958012312ACFF00FD392A /* DependencyCheckSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F957FF2312ACFF00FD392A /* DependencyCheckSpec.swift */; }; + 77F958022312ACFF00FD392A /* DependencyCheckSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F957FF2312ACFF00FD392A /* DependencyCheckSpec.swift */; }; + 77F958032312ACFF00FD392A /* DependencyCheckSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F957FF2312ACFF00FD392A /* DependencyCheckSpec.swift */; }; 789BF74652A2424EB8F7EF47 /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 7A7032384E07DAD308D4F70A /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 8B9785AAE94A5447FA307242 /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 7D6F664091C70BABBFB61D53 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; @@ -522,6 +526,7 @@ 75BE3AE3E30DFE42A919D825 /* ModulesSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModulesSpec.swift; sourceTree = ""; }; 77F957F8231298E400FD392A /* FunctionCall.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FunctionCall.swift; sourceTree = ""; }; 77F957FD2312A4C600FD392A /* FunctionCallVariations.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = FunctionCallVariations.swifttemplate; sourceTree = ""; }; + 77F957FF2312ACFF00FD392A /* DependencyCheckSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DependencyCheckSpec.swift; sourceTree = ""; }; 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ServiceEntry+TypeForwarding.swift"; sourceTree = ""; }; 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextTranslator.swift; sourceTree = ""; }; 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistry.swift; sourceTree = ""; }; @@ -772,6 +777,7 @@ 0D8B3342E2AC3236F12072F5 /* RetrievalSpec.swift */, 1D3C59E84B5FD0C13F487838 /* ScopesSpec.swift */, 46F05CC591903E2B04B6D8ED /* SingletonSpec.swift */, + 77F957FF2312ACFF00FD392A /* DependencyCheckSpec.swift */, ); path = "3.0 API"; sourceTree = ""; @@ -1484,6 +1490,7 @@ F1F3BA81462E2362374BD4C4 /* ModulesSpec.swift in Sources */, 72F09FC92FFB0F7C32D8E2A5 /* OptionalsSpec.swift in Sources */, 751F545653B0F1E30341C312 /* OverrideSpec.swift in Sources */, + 77F958002312ACFF00FD392A /* DependencyCheckSpec.swift in Sources */, 628EBFBA0031B1FA2E29F583 /* Person.swift in Sources */, 45F1654C204C7A2C87397BCD /* PropertyWrappersSpec.swift in Sources */, 708E1C453CBC76ED26FA2FCB /* ProviderSpec.swift in Sources */, @@ -1525,6 +1532,7 @@ 004B06007E4FDD8F44B7EC89 /* ModulesSpec.swift in Sources */, D941D81F59900A52805D6B4A /* OptionalsSpec.swift in Sources */, 18AAA07DCD6FAB4A7D7E8B76 /* OverrideSpec.swift in Sources */, + 77F958012312ACFF00FD392A /* DependencyCheckSpec.swift in Sources */, EB3420214A9E68A0247D0F2C /* Person.swift in Sources */, 9AA68475ABE3E7502F59216D /* PropertyWrappersSpec.swift in Sources */, CF9535A0DCAFF23F4D62F871 /* ProviderSpec.swift in Sources */, @@ -1566,6 +1574,7 @@ D9F132E4A6F6BC2BDD5DFCAA /* ModulesSpec.swift in Sources */, A453A5A7E0EC0FE161AA34D5 /* OptionalsSpec.swift in Sources */, C22853F014054A6DCDF0CB6A /* OverrideSpec.swift in Sources */, + 77F958032312ACFF00FD392A /* DependencyCheckSpec.swift in Sources */, C76374CAFE7C2BCCE52F1BB1 /* Person.swift in Sources */, D7915D8FCF67D0FFCC41E9D6 /* PropertyWrappersSpec.swift in Sources */, 4954CBB07E38E98752AC3347 /* ProviderSpec.swift in Sources */, @@ -1607,6 +1616,7 @@ 55F2E72EA8C3564130F66946 /* ModulesSpec.swift in Sources */, F6EEF5F7B57DC0E44EF569A4 /* OptionalsSpec.swift in Sources */, 708D400457552769A54A406B /* OverrideSpec.swift in Sources */, + 77F958022312ACFF00FD392A /* DependencyCheckSpec.swift in Sources */, BEEFBE87EB17D56BA8D47358 /* Person.swift in Sources */, AAC6F2F5EC2928943BF2BED1 /* PropertyWrappersSpec.swift in Sources */, 48F40377D116C6B1B786C329 /* ProviderSpec.swift in Sources */, diff --git a/Templates/FunctionCallVariations.swifttemplate b/Templates/FunctionCallVariations.swifttemplate index 1b081d72..c9161b68 100644 --- a/Templates/FunctionCallVariations.swifttemplate +++ b/Templates/FunctionCallVariations.swifttemplate @@ -1,6 +1,7 @@ <% let maxParams = 20 %> // sourcery:inline:FunctionCallVariations <%_ for n in 0 ... maxParams { + if n == 1 { continue } let inputTypes = (0 ..< n).map { "I\($0+1)" }.joined(separator: ", ") let genericParams = n == 0 ? "Result" : "Result, \(inputTypes)" let requests = (0 ..< n).map { _ in "instance()" }.joined(separator: ", ") diff --git a/Tests/3.0 API/DependencyCheckSpec.swift b/Tests/3.0 API/DependencyCheckSpec.swift new file mode 100644 index 00000000..2e1c59ff --- /dev/null +++ b/Tests/3.0 API/DependencyCheckSpec.swift @@ -0,0 +1,58 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +import Nimble +import Quick +import Swinject + +// swiftformat:disable spaceAroundOperators +class DependencyCheckSpec: QuickSpec { override func spec() { #if swift(>=5.1) + describe("checked binding") { + let john = Human() + it("can declaratively specify binding's factory") { + let swinject = Swinject { + register().constant("mimi") + register().constant(john) + register().resultOf(Pet.init^) + } + let pet = try? instance(of: Pet.self).from(swinject) + expect(pet?.name) == "mimi" + expect(pet?.owner) === john + } + it("can declare specific input requests") { + let swinject = Swinject { + register().constant("mimi", tag: "name") + register().factory { $1 == "john" ? john : Human() } + register().resultOf( + Pet.init^(name: instance(tagged: "name"), owner: instance(arg: "john")) + ) + } + let pet = try? instance(of: Pet.self).from(swinject) + expect(pet?.name) == "mimi" + expect(pet?.owner) === john + } + it("can require arguments as function inputs") { + let swinject = Swinject { + register().resultOf( + Pet.init^(name: argument(0), owner: argument(1)) + ) + } + let pet = try? instance(of: Pet.self, arg: "mimi", john).from(swinject) + expect(pet?.name) == "mimi" + expect(pet?.owner) === john + } + it("can require context as function input") { + let swinject = Swinject { + register().constant("mimi") + register(inContextOf: Human.self).resultOf( + Pet.init^(name: instance(), owner: context()) + ) + } + let pet = try? instance(of: Pet.self).from(swinject.on(john)) + expect(pet?.name) == "mimi" + expect(pet?.owner) === john + } + } + #endif +} } diff --git a/Tests/LinuxConfig.swift b/Tests/LinuxConfig.swift index bdc04e96..2f5e53b3 100644 --- a/Tests/LinuxConfig.swift +++ b/Tests/LinuxConfig.swift @@ -26,6 +26,7 @@ let allSpecs: [QuickSpec.Type] = [ OptionalsSpec.self, RetrievalSpec.self, PropertyWrappersSpec.self, + DependencyCheckSpec.self, // Unit Specs StandardScopeRegistrySpec.self, SwinjectTreeBuilderSpec.self, From a8f309a90736a501fb8ef2ed62ec6a8ce0f0f247 Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Sun, 25 Aug 2019 15:32:45 +0200 Subject: [PATCH 234/239] Check binding dependencies when constructing container --- Sources/2.0 API/ServiceEntry.swift | 1 + Sources/3.0 API/Binding+Api.swift | 8 +++---- Sources/3.0 API/Binding+Factory.swift | 24 ++++++++++---------- Sources/3.0 API/Binding.swift | 9 +------- Sources/3.0 API/PartialRequest.swift | 14 ++++-------- Sources/Core/AnyBinding.swift | 7 ++++++ Sources/Core/SwinjectContainer.swift | 19 ++++++++++++---- Sources/Core/SwinjectError.swift | 1 + Templates/FactoryVariation.swift | 2 +- Templates/SwiftCode.swifttemplate | 2 +- Tests/3.0 API/DependencyCheckSpec.swift | 29 ++++++++++++++++++++++++- 11 files changed, 75 insertions(+), 41 deletions(-) diff --git a/Sources/2.0 API/ServiceEntry.swift b/Sources/2.0 API/ServiceEntry.swift index 5587a5ce..4ee6b9fe 100644 --- a/Sources/2.0 API/ServiceEntry.swift +++ b/Sources/2.0 API/ServiceEntry.swift @@ -72,6 +72,7 @@ public class ServiceEntry { extension ServiceEntry: AnyBinding { public var overrides: Bool { return false } + public var dependencies: [BindingDependency] { return [] } public func makeInstance(resolver: Resolver, arguments: Arguments) throws -> Any { let context = try resolver.context(as: key.contextType) diff --git a/Sources/3.0 API/Binding+Api.swift b/Sources/3.0 API/Binding+Api.swift index 641c8573..def7c96d 100644 --- a/Sources/3.0 API/Binding+Api.swift +++ b/Sources/3.0 API/Binding+Api.swift @@ -5,7 +5,7 @@ public func register(inContextOf _: Context.Type) -> Binding { return Binding( products: [], - dependencies: .none, + dependencies: [], factory: { _, _ in }, properties: .default, scope: nil, @@ -20,7 +20,7 @@ public func register() -> Binding { public func registerSingle(in scope: AScope) -> Binding { return Binding( products: [], - dependencies: .none, + dependencies: [], factory: { _, _ in }, properties: .default, scope: scope, @@ -36,7 +36,7 @@ public extension Binding where Instance == Void { func constant(_ value: Value, tag: String? = nil) -> Binding { return updatedFactory { _, _ in value }.updated { $0.products = [tagged(Value.self, with: tag)] - $0.dependencies = .none + $0.dependencies = [] $0.arguments = [] } } @@ -49,7 +49,7 @@ public extension Binding where Instance == Void { return updatedFactory(factory: call.execute).updated { // TODO: assert context type $0.products = [tagged(NewInstance.self, with: tag)] - $0.dependencies = .list(call.inputs.map { $0.asDependency }) + $0.dependencies = call.inputs.map { $0.asDependency } $0.arguments = Arguments.Descriptor(types: call.inputs.compactMap { if case let .argument(type) = $0.asDependency { return type } else { return nil } }) diff --git a/Sources/3.0 API/Binding+Factory.swift b/Sources/3.0 API/Binding+Factory.swift index 0ec01987..e9f268d6 100644 --- a/Sources/3.0 API/Binding+Factory.swift +++ b/Sources/3.0 API/Binding+Factory.swift @@ -9,7 +9,7 @@ public extension Binding { func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping () throws -> NewInstance) -> Binding { return updatedFactory { _, _ in try factory() }.updated { $0.products = [tagged(NewInstance.self, with: tag)] - $0.dependencies = .undefined + $0.dependencies = [] $0.arguments = [] } } @@ -17,7 +17,7 @@ public extension Binding { func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver) throws -> NewInstance) -> Binding { return updatedFactory { r, _ in try factory(r) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] - $0.dependencies = .undefined + $0.dependencies = [] $0.arguments = [] } } @@ -25,7 +25,7 @@ public extension Binding { func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1) throws -> NewInstance) -> Binding { return updatedFactory { r, a in try factory(r, a.arg(0)) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] - $0.dependencies = .undefined + $0.dependencies = [] $0.arguments = [Arg1.self] } } @@ -33,7 +33,7 @@ public extension Binding { func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1) throws -> NewInstance) -> Binding where Arg1: Hashable { return updatedFactory { r, a in try factory(r, a.arg(0)) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] - $0.dependencies = .undefined + $0.dependencies = [] $0.arguments = [Arg1.self] } } @@ -41,7 +41,7 @@ public extension Binding { func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2) throws -> NewInstance) -> Binding { return updatedFactory { r, a in try factory(r, a.arg(0), a.arg(1)) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] - $0.dependencies = .undefined + $0.dependencies = [] $0.arguments = [Arg1.self, Arg2.self] } } @@ -49,7 +49,7 @@ public extension Binding { func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2) throws -> NewInstance) -> Binding where Arg1: Hashable, Arg2: Hashable { return updatedFactory { r, a in try factory(r, a.arg(0), a.arg(1)) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] - $0.dependencies = .undefined + $0.dependencies = [] $0.arguments = [Arg1.self, Arg2.self] } } @@ -57,7 +57,7 @@ public extension Binding { func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2, Arg3) throws -> NewInstance) -> Binding { return updatedFactory { r, a in try factory(r, a.arg(0), a.arg(1), a.arg(2)) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] - $0.dependencies = .undefined + $0.dependencies = [] $0.arguments = [Arg1.self, Arg2.self, Arg3.self] } } @@ -65,7 +65,7 @@ public extension Binding { func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2, Arg3) throws -> NewInstance) -> Binding where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { return updatedFactory { r, a in try factory(r, a.arg(0), a.arg(1), a.arg(2)) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] - $0.dependencies = .undefined + $0.dependencies = [] $0.arguments = [Arg1.self, Arg2.self, Arg3.self] } } @@ -73,7 +73,7 @@ public extension Binding { func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2, Arg3, Arg4) throws -> NewInstance) -> Binding { return updatedFactory { r, a in try factory(r, a.arg(0), a.arg(1), a.arg(2), a.arg(3)) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] - $0.dependencies = .undefined + $0.dependencies = [] $0.arguments = [Arg1.self, Arg2.self, Arg3.self, Arg4.self] } } @@ -81,7 +81,7 @@ public extension Binding { func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2, Arg3, Arg4) throws -> NewInstance) -> Binding where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { return updatedFactory { r, a in try factory(r, a.arg(0), a.arg(1), a.arg(2), a.arg(3)) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] - $0.dependencies = .undefined + $0.dependencies = [] $0.arguments = [Arg1.self, Arg2.self, Arg3.self, Arg4.self] } } @@ -89,7 +89,7 @@ public extension Binding { func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> NewInstance) -> Binding { return updatedFactory { r, a in try factory(r, a.arg(0), a.arg(1), a.arg(2), a.arg(3), a.arg(4)) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] - $0.dependencies = .undefined + $0.dependencies = [] $0.arguments = [Arg1.self, Arg2.self, Arg3.self, Arg4.self, Arg5.self] } } @@ -97,7 +97,7 @@ public extension Binding { func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> NewInstance) -> Binding where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { return updatedFactory { r, a in try factory(r, a.arg(0), a.arg(1), a.arg(2), a.arg(3), a.arg(4)) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] - $0.dependencies = .undefined + $0.dependencies = [] $0.arguments = [Arg1.self, Arg2.self, Arg3.self, Arg4.self, Arg5.self] } } diff --git a/Sources/3.0 API/Binding.swift b/Sources/3.0 API/Binding.swift index 969f46a0..acd5213b 100644 --- a/Sources/3.0 API/Binding.swift +++ b/Sources/3.0 API/Binding.swift @@ -9,16 +9,9 @@ public struct BindingProperties { static let `default` = BindingProperties(overrides: false, reference: strongRef) } -enum BindingDependencies { - case undefined - case list([PartialDependency]) - - static let none = BindingDependencies.list([]) -} - public struct Binding { var products: [TypeDescriptor] - var dependencies: BindingDependencies + public var dependencies: [BindingDependency] var factory: (ContextedResolver, Arguments) throws -> Instance var properties: BindingProperties let scope: AnyScope? diff --git a/Sources/3.0 API/PartialRequest.swift b/Sources/3.0 API/PartialRequest.swift index 03e637f3..a7cf1493 100644 --- a/Sources/3.0 API/PartialRequest.swift +++ b/Sources/3.0 API/PartialRequest.swift @@ -2,14 +2,8 @@ // Copyright © 2019 Swinject Contributors. All rights reserved. // -public enum PartialDependency { - case instance(TypeDescriptor, Arguments.Descriptor) - case argument(Any.Type) - case context(Any.Type) -} - public protocol AnyPartialRequest { - var asDependency: PartialDependency { get } + var asDependency: BindingDependency { get } } public protocol PartialRequest: AnyPartialRequest { @@ -32,7 +26,7 @@ public func argument(_ index: Int, as _: Type.Type = Type.self) -> Argumen } extension InstanceRequest: PartialRequest { - public var asDependency: PartialDependency { return .instance(type, arguments.descriptor) } + public var asDependency: BindingDependency { return .instance(type, arguments.descriptor) } public func fulfill(with resolver: Resolver, and _: Arguments) throws -> Type { return try resolver.resolve(self) @@ -40,7 +34,7 @@ extension InstanceRequest: PartialRequest { } extension ArgumentRequest: PartialRequest { - public var asDependency: PartialDependency { return .argument(Type.self) } + public var asDependency: BindingDependency { return .argument(Type.self) } public func fulfill(with _: Resolver, and arguments: Arguments) throws -> Type { return try arguments.arg(index) @@ -48,7 +42,7 @@ extension ArgumentRequest: PartialRequest { } extension ContextRequest: PartialRequest { - public var asDependency: PartialDependency { return .context(Type.self) } + public var asDependency: BindingDependency { return .context(Type.self) } public func fulfill(with resolver: Resolver, and _: Arguments) throws -> Type { return try resolver.contexted().context() diff --git a/Sources/Core/AnyBinding.swift b/Sources/Core/AnyBinding.swift index bb006363..91d2764b 100644 --- a/Sources/Core/AnyBinding.swift +++ b/Sources/Core/AnyBinding.swift @@ -32,8 +32,15 @@ extension BindingKey { } } +public enum BindingDependency { + case instance(TypeDescriptor, Arguments.Descriptor) + case argument(Any.Type) + case context(Any.Type) +} + public protocol AnyBinding: SwinjectEntry { var keys: [BindingKey] { get } var overrides: Bool { get } + var dependencies: [BindingDependency] { get } func makeInstance(resolver: Resolver, arguments: Arguments) throws -> Any } diff --git a/Sources/Core/SwinjectContainer.swift b/Sources/Core/SwinjectContainer.swift index 3d10b28a..55f77b3f 100644 --- a/Sources/Core/SwinjectContainer.swift +++ b/Sources/Core/SwinjectContainer.swift @@ -19,10 +19,9 @@ extension SwinjectContainer.Builder { private func makeContainerOrThrow() throws -> SwinjectContainer { try checkDuplicitModules() - return try SwinjectContainer( - bindings: collectBindings(), - translators: tree.translators - ) + let bindings = try collectBindings() + try checkDependencies(for: bindings) + return SwinjectContainer(bindings: bindings, translators: tree.translators) } } @@ -37,6 +36,18 @@ extension SwinjectContainer.Builder { } } +extension SwinjectContainer.Builder { + func checkDependencies(for bindings: [BindingKey: AnyBinding]) throws { + try bindings.values.flatMap { $0.dependencies }.forEach { + if case let .instance(type, arguments) = $0 { + if !bindings.keys.contains(where: { $0.type == type && $0.arguments == arguments }) { + throw MissingDependency() + } + } + } + } +} + extension SwinjectContainer.Builder { private struct BindingEntry { let binding: AnyBinding diff --git a/Sources/Core/SwinjectError.swift b/Sources/Core/SwinjectError.swift index cd8a2d4c..2a194984 100644 --- a/Sources/Core/SwinjectError.swift +++ b/Sources/Core/SwinjectError.swift @@ -22,5 +22,6 @@ public class NoContextTranslator: SwinjectError {} public class CircularDependency: SwinjectError {} public class MissingArgument: SwinjectError {} public class ArgumentMismatch: SwinjectError {} +public class MissingDependency: SwinjectError {} // TODO: Debugging error description diff --git a/Templates/FactoryVariation.swift b/Templates/FactoryVariation.swift index dee76ad8..97a1e546 100644 --- a/Templates/FactoryVariation.swift +++ b/Templates/FactoryVariation.swift @@ -98,7 +98,7 @@ extension FactoryVariation { func factory<\(genericTypes)>(\(params)) -> \(returnType) \(constraints){ return updatedFactory { \(factoryInputs) in try factory(\(factoryVars)) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] - $0.dependencies = .undefined + $0.dependencies = [] $0.arguments = [\(argDescriptorTypes)] } } diff --git a/Templates/SwiftCode.swifttemplate b/Templates/SwiftCode.swifttemplate index 6231abde..2bce5eb1 100644 --- a/Templates/SwiftCode.swifttemplate +++ b/Templates/SwiftCode.swifttemplate @@ -185,7 +185,7 @@ extension FactoryVariation { func factory<\(genericTypes)>(\(params)) -> \(returnType) \(constraints){ return updatedFactory { \(factoryInputs) in try factory(\(factoryVars)) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] - $0.dependencies = .undefined + $0.dependencies = [] $0.arguments = [\(argDescriptorTypes)] } } diff --git a/Tests/3.0 API/DependencyCheckSpec.swift b/Tests/3.0 API/DependencyCheckSpec.swift index 2e1c59ff..93d52ad7 100644 --- a/Tests/3.0 API/DependencyCheckSpec.swift +++ b/Tests/3.0 API/DependencyCheckSpec.swift @@ -8,8 +8,8 @@ import Swinject // swiftformat:disable spaceAroundOperators class DependencyCheckSpec: QuickSpec { override func spec() { #if swift(>=5.1) + let john = Human() describe("checked binding") { - let john = Human() it("can declaratively specify binding's factory") { let swinject = Swinject { register().constant("mimi") @@ -54,5 +54,32 @@ class DependencyCheckSpec: QuickSpec { override func spec() { #if swift(>=5.1) expect(pet?.owner) === john } } + describe("dependency check") { + it("fails if checked binding has missing dependency") { + expect { + _ = Swinject { + register().resultOf(Pet.init^) + } + }.to(throwAssertion()) + } + it("fails if checked binding's dependency is registerd with wrong tag") { + expect { + _ = Swinject { + register().constant(john) + register().constant("mimi", tag: "name") + register().resultOf(Pet.init^) + } + }.to(throwAssertion()) + } + it("fails if checked binding's dependency is registerd with wrong arguments") { + expect { + _ = Swinject { + register().factory { $1 == "john" ? john : Human() } + register().constant("mimi") + register().resultOf(Pet.init^) + } + }.to(throwAssertion()) + } + } #endif } } From 13f2c643859885c31071e7f108e054a8866b58c7 Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Sun, 25 Aug 2019 16:25:36 +0200 Subject: [PATCH 235/239] Implement support for declarative property injection --- Sources/3.0 API/Binding+Api.swift | 18 +++++++-- Sources/3.0 API/Binding.swift | 2 +- Sources/3.0 API/InjectionRequest.swift | 19 +++++++++ Sources/3.0 API/PartialRequest.swift | 6 +++ Sources/Core/Arguments.swift | 2 +- Swinject.xcodeproj/project.pbxproj | 10 +++++ Tests/3.0 API/DependencyCheckSpec.swift | 53 ++++++++++++++++++++++++- 7 files changed, 104 insertions(+), 6 deletions(-) create mode 100644 Sources/3.0 API/InjectionRequest.swift diff --git a/Sources/3.0 API/Binding+Api.swift b/Sources/3.0 API/Binding+Api.swift index def7c96d..890a0c94 100644 --- a/Sources/3.0 API/Binding+Api.swift +++ b/Sources/3.0 API/Binding+Api.swift @@ -50,9 +50,21 @@ public extension Binding where Instance == Void { // TODO: assert context type $0.products = [tagged(NewInstance.self, with: tag)] $0.dependencies = call.inputs.map { $0.asDependency } - $0.arguments = Arguments.Descriptor(types: call.inputs.compactMap { - if case let .argument(type) = $0.asDependency { return type } else { return nil } - }) + $0.arguments.types = call.inputs.compactMap { $0.asArgumentDependency } + } + } +} + +public extension Binding { + func injectedBy(_ injections: InjectionRequest ...) -> Binding { + return updated { + $0.factory = { resolver, arguments in + var instance = try self.factory(resolver, arguments) + try injections.forEach { try $0.execute(resolver, arguments, &instance) } + return instance + } + $0.dependencies += injections.flatMap { $0.inputs }.map { $0.asDependency } + $0.arguments.types += injections.flatMap { $0.inputs }.compactMap { $0.asArgumentDependency } } } } diff --git a/Sources/3.0 API/Binding.swift b/Sources/3.0 API/Binding.swift index acd5213b..294c9d4d 100644 --- a/Sources/3.0 API/Binding.swift +++ b/Sources/3.0 API/Binding.swift @@ -14,7 +14,7 @@ public struct Binding { public var dependencies: [BindingDependency] var factory: (ContextedResolver, Arguments) throws -> Instance var properties: BindingProperties - let scope: AnyScope? + var scope: AnyScope? var arguments: Arguments.Descriptor } diff --git a/Sources/3.0 API/InjectionRequest.swift b/Sources/3.0 API/InjectionRequest.swift new file mode 100644 index 00000000..1c180a82 --- /dev/null +++ b/Sources/3.0 API/InjectionRequest.swift @@ -0,0 +1,19 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +public struct InjectionRequest { + let inputs: [AnyPartialRequest] + let execute: (Resolver, Arguments, inout Instance) throws -> Void +} + +infix operator <-: AssignmentPrecedence + +public func <- ( + target: WritableKeyPath, + request: Request +) -> InjectionRequest where Request: PartialRequest, Request.Result == Property { + return InjectionRequest(inputs: [request]) { + $2[keyPath: target] = try request.fulfill(with: $0, and: $1) + } +} diff --git a/Sources/3.0 API/PartialRequest.swift b/Sources/3.0 API/PartialRequest.swift index a7cf1493..fa5b4939 100644 --- a/Sources/3.0 API/PartialRequest.swift +++ b/Sources/3.0 API/PartialRequest.swift @@ -6,6 +6,12 @@ public protocol AnyPartialRequest { var asDependency: BindingDependency { get } } +extension AnyPartialRequest { + var asArgumentDependency: Any.Type? { + if case let .argument(type) = asDependency { return type } else { return nil } + } +} + public protocol PartialRequest: AnyPartialRequest { associatedtype Result func fulfill(with resolver: Resolver, and arguments: Arguments) throws -> Result diff --git a/Sources/Core/Arguments.swift b/Sources/Core/Arguments.swift index 38e1c370..0f4246c4 100644 --- a/Sources/Core/Arguments.swift +++ b/Sources/Core/Arguments.swift @@ -4,7 +4,7 @@ public struct Arguments { public struct Descriptor { - let types: [Any.Type] + var types: [Any.Type] } let values: [Any] diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index b205da76..539aa8db 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -168,6 +168,10 @@ 77F958012312ACFF00FD392A /* DependencyCheckSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F957FF2312ACFF00FD392A /* DependencyCheckSpec.swift */; }; 77F958022312ACFF00FD392A /* DependencyCheckSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F957FF2312ACFF00FD392A /* DependencyCheckSpec.swift */; }; 77F958032312ACFF00FD392A /* DependencyCheckSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F957FF2312ACFF00FD392A /* DependencyCheckSpec.swift */; }; + 77F958052312C82600FD392A /* InjectionRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F958042312C82600FD392A /* InjectionRequest.swift */; }; + 77F958062312C82600FD392A /* InjectionRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F958042312C82600FD392A /* InjectionRequest.swift */; }; + 77F958072312C82600FD392A /* InjectionRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F958042312C82600FD392A /* InjectionRequest.swift */; }; + 77F958082312C82600FD392A /* InjectionRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F958042312C82600FD392A /* InjectionRequest.swift */; }; 789BF74652A2424EB8F7EF47 /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 7A7032384E07DAD308D4F70A /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 8B9785AAE94A5447FA307242 /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 7D6F664091C70BABBFB61D53 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; @@ -527,6 +531,7 @@ 77F957F8231298E400FD392A /* FunctionCall.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FunctionCall.swift; sourceTree = ""; }; 77F957FD2312A4C600FD392A /* FunctionCallVariations.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = FunctionCallVariations.swifttemplate; sourceTree = ""; }; 77F957FF2312ACFF00FD392A /* DependencyCheckSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DependencyCheckSpec.swift; sourceTree = ""; }; + 77F958042312C82600FD392A /* InjectionRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InjectionRequest.swift; sourceTree = ""; }; 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ServiceEntry+TypeForwarding.swift"; sourceTree = ""; }; 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextTranslator.swift; sourceTree = ""; }; 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistry.swift; sourceTree = ""; }; @@ -678,6 +683,7 @@ 667B13B528642272FC0794B6 /* UnboundScope.swift */, 9B5EE429B22E5A993ABBC347 /* PartialRequest.swift */, 77F957F8231298E400FD392A /* FunctionCall.swift */, + 77F958042312C82600FD392A /* InjectionRequest.swift */, 57A7E35B2B22650208F904B8 /* Weak.swift */, ); path = "3.0 API"; @@ -1423,6 +1429,7 @@ 996CCFE825834C7D3236E742 /* Container+TypeForwarding.swift in Sources */, B2FAD41F7726502822AF913B /* Container.swift in Sources */, 8B5927517B567B1DFAB5B935 /* ContextTranslator.swift in Sources */, + 77F958062312C82600FD392A /* InjectionRequest.swift in Sources */, FB467C5FB6C6851FD1B6DB51 /* InstanceRequest+APi.swift in Sources */, 53EBF7A46EF65F2A8DAADC7A /* InstanceRequest.swift in Sources */, A91EDAFBC3606EDFBD739899 /* InstanceWrapper.swift in Sources */, @@ -1647,6 +1654,7 @@ BD9B57E26722C80B7EF990DB /* Container+TypeForwarding.swift in Sources */, DB74F17CDFF4886B9C38AD14 /* Container.swift in Sources */, DD5E3AF2B5FCE5E81EBDF606 /* ContextTranslator.swift in Sources */, + 77F958072312C82600FD392A /* InjectionRequest.swift in Sources */, 921406E8219BBDAFE2BEEDD6 /* InstanceRequest+APi.swift in Sources */, 9DEAC620F2F00D0DDD3B5D3E /* InstanceRequest.swift in Sources */, 57BFBA2077E70DC1C2FE796C /* InstanceWrapper.swift in Sources */, @@ -1693,6 +1701,7 @@ 283C77045DA55C2134EC9C48 /* Container+TypeForwarding.swift in Sources */, 58ABEE0321A3061048B65EA2 /* Container.swift in Sources */, F06DEB671A4B85ABB0E96E51 /* ContextTranslator.swift in Sources */, + 77F958082312C82600FD392A /* InjectionRequest.swift in Sources */, EEBB114E8A57F37E4F226482 /* InstanceRequest+APi.swift in Sources */, CECF5BD14BCDF5248771A06A /* InstanceRequest.swift in Sources */, 389C54E04DD794DA4F648571 /* InstanceWrapper.swift in Sources */, @@ -1739,6 +1748,7 @@ 3A0B409E840B44B281DB3C54 /* Container+TypeForwarding.swift in Sources */, 0622539110A7430776A307C7 /* Container.swift in Sources */, D1DF4740A9D86362B63104B8 /* ContextTranslator.swift in Sources */, + 77F958052312C82600FD392A /* InjectionRequest.swift in Sources */, 4FACFC5F59982A6EDA7F8E4D /* InstanceRequest+APi.swift in Sources */, 128913D570B4A8BBF40866BE /* InstanceRequest.swift in Sources */, 98ACB1A09194572A946CA90D /* InstanceWrapper.swift in Sources */, diff --git a/Tests/3.0 API/DependencyCheckSpec.swift b/Tests/3.0 API/DependencyCheckSpec.swift index 93d52ad7..bff76ec5 100644 --- a/Tests/3.0 API/DependencyCheckSpec.swift +++ b/Tests/3.0 API/DependencyCheckSpec.swift @@ -9,7 +9,7 @@ import Swinject // swiftformat:disable spaceAroundOperators class DependencyCheckSpec: QuickSpec { override func spec() { #if swift(>=5.1) let john = Human() - describe("checked binding") { + describe("checked factory") { it("can declaratively specify binding's factory") { let swinject = Swinject { register().constant("mimi") @@ -54,6 +54,50 @@ class DependencyCheckSpec: QuickSpec { override func spec() { #if swift(>=5.1) expect(pet?.owner) === john } } + describe("checked property injection") { + it("can specify property injection in binding declaration") { + let swinject = Swinject { + register().constant("john") + register().constant(42, tag: "age") + register() + .resultOf(Human.init^) + .injectedBy( + \.name <- instance(), + \.age <- instance(tagged: "age") + ) + } + let human = try? instance(of: Human.self).from(swinject) + expect(human?.name) == "john" + expect(human?.age) == 42 + } + it("can use arguments for property injection") { + let swinject = Swinject { + register() + .resultOf(Human.init^) + .injectedBy( + \.name <- argument(0), + \.age <- argument(1) + ) + } + let human = try? instance(of: Human.self, arg: "john", 42).from(swinject) + expect(human?.name) == "john" + expect(human?.age) == 42 + } + it("can use context for property injection") { + let swinject = Swinject { + register().constant(42) + register(inContextOf: String.self) + .resultOf(Human.init^) + .injectedBy( + \.name <- context(), + \.age <- instance() + ) + } + let human = try? instance(of: Human.self).from(swinject.on("john")) + expect(human?.name) == "john" + expect(human?.age) == 42 + } + } describe("dependency check") { it("fails if checked binding has missing dependency") { expect { @@ -80,6 +124,13 @@ class DependencyCheckSpec: QuickSpec { override func spec() { #if swift(>=5.1) } }.to(throwAssertion()) } + it("fails if checked binding has missing property injection dependency") { + expect { + _ = Swinject { + register().resultOf(Human.init^).injectedBy(\.name <- instance()) + } + }.to(throwAssertion()) + } } #endif } } From 78f629287f65594646d2c0499da34a42b9e06720 Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Sun, 25 Aug 2019 22:51:56 +0200 Subject: [PATCH 236/239] Add basic support for using modules in assembler --- Sources/3.0 API/Module+Assembly.swift | 16 ++++ Swinject.xcodeproj/project.pbxproj | 28 +++++++ Tests/3.0 API/InteroperabilitySpec.swift | 101 +++++++++++++++++++++++ Tests/3.0 API/ScopesSpec.swift | 10 --- Tests/LinuxConfig.swift | 1 + Tests/Support/TestModels.swift | 10 +++ 6 files changed, 156 insertions(+), 10 deletions(-) create mode 100644 Sources/3.0 API/Module+Assembly.swift create mode 100644 Tests/3.0 API/InteroperabilitySpec.swift diff --git a/Sources/3.0 API/Module+Assembly.swift b/Sources/3.0 API/Module+Assembly.swift new file mode 100644 index 00000000..13a1edc3 --- /dev/null +++ b/Sources/3.0 API/Module+Assembly.swift @@ -0,0 +1,16 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +extension Swinject.Module: Assembly { + public func assemble(container: Container) { + for binding in tree.bindings { + for key in binding.keys { + container.bindings[key] = binding + } + } + for inclusion in tree.modules { + inclusion.module.assemble(container: container) + } + } +} diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index 539aa8db..f897ec56 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -172,6 +172,14 @@ 77F958062312C82600FD392A /* InjectionRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F958042312C82600FD392A /* InjectionRequest.swift */; }; 77F958072312C82600FD392A /* InjectionRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F958042312C82600FD392A /* InjectionRequest.swift */; }; 77F958082312C82600FD392A /* InjectionRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F958042312C82600FD392A /* InjectionRequest.swift */; }; + 77F9580F231317AA00FD392A /* InteroperabilitySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F9580A2313175D00FD392A /* InteroperabilitySpec.swift */; }; + 77F95810231317AA00FD392A /* InteroperabilitySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F9580A2313175D00FD392A /* InteroperabilitySpec.swift */; }; + 77F95811231317AB00FD392A /* InteroperabilitySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F9580A2313175D00FD392A /* InteroperabilitySpec.swift */; }; + 77F95812231317AB00FD392A /* InteroperabilitySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F9580A2313175D00FD392A /* InteroperabilitySpec.swift */; }; + 77F95815231318EA00FD392A /* Module+Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F95814231318EA00FD392A /* Module+Assembly.swift */; }; + 77F95816231318EA00FD392A /* Module+Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F95814231318EA00FD392A /* Module+Assembly.swift */; }; + 77F95817231318EA00FD392A /* Module+Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F95814231318EA00FD392A /* Module+Assembly.swift */; }; + 77F95818231318EA00FD392A /* Module+Assembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F95814231318EA00FD392A /* Module+Assembly.swift */; }; 789BF74652A2424EB8F7EF47 /* Nimble.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 30EDBFDB23A7FB3DA7758DD0 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 7A7032384E07DAD308D4F70A /* Swinject.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 8B9785AAE94A5447FA307242 /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 7D6F664091C70BABBFB61D53 /* ContainerSpec.CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */; }; @@ -532,6 +540,8 @@ 77F957FD2312A4C600FD392A /* FunctionCallVariations.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = FunctionCallVariations.swifttemplate; sourceTree = ""; }; 77F957FF2312ACFF00FD392A /* DependencyCheckSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DependencyCheckSpec.swift; sourceTree = ""; }; 77F958042312C82600FD392A /* InjectionRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InjectionRequest.swift; sourceTree = ""; }; + 77F9580A2313175D00FD392A /* InteroperabilitySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InteroperabilitySpec.swift; sourceTree = ""; }; + 77F95814231318EA00FD392A /* Module+Assembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Module+Assembly.swift"; sourceTree = ""; }; 78F0D8665C3D7F020BDA1ACB /* ServiceEntry+TypeForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ServiceEntry+TypeForwarding.swift"; sourceTree = ""; }; 7C83EC4390A34D207245D9C9 /* ContextTranslator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextTranslator.swift; sourceTree = ""; }; 7DB3B73B11CA8650972E1175 /* ScopeRegistry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeRegistry.swift; sourceTree = ""; }; @@ -684,6 +694,7 @@ 9B5EE429B22E5A993ABBC347 /* PartialRequest.swift */, 77F957F8231298E400FD392A /* FunctionCall.swift */, 77F958042312C82600FD392A /* InjectionRequest.swift */, + 77F95814231318EA00FD392A /* Module+Assembly.swift */, 57A7E35B2B22650208F904B8 /* Weak.swift */, ); path = "3.0 API"; @@ -736,6 +747,13 @@ path = watchOS; sourceTree = ""; }; + 77F958092313172900FD392A /* Interop */ = { + isa = PBXGroup; + children = ( + ); + path = Interop; + sourceTree = ""; + }; 80E97D8FD5574A96B6BC9EB9 /* Frameworks */ = { isa = PBXGroup; children = ( @@ -784,6 +802,7 @@ 1D3C59E84B5FD0C13F487838 /* ScopesSpec.swift */, 46F05CC591903E2B04B6D8ED /* SingletonSpec.swift */, 77F957FF2312ACFF00FD392A /* DependencyCheckSpec.swift */, + 77F9580A2313175D00FD392A /* InteroperabilitySpec.swift */, ); path = "3.0 API"; sourceTree = ""; @@ -810,6 +829,7 @@ 938425B216B78A06EC10504A /* LinuxConfig.swift */, F64B4AFEC15ABABB3014A636 /* 2.0 API */, 9A6E5EB655CFE64BBCF5DED1 /* 3.0 API */, + 77F958092313172900FD392A /* Interop */, 4F46C48FA15F512EAED5F67A /* Support */, 0A05322134E988A4593B5122 /* Unit Specs */, ); @@ -1428,6 +1448,7 @@ AAD8D0551B8A26A9B22AECEC /* Container+Registration.swift in Sources */, 996CCFE825834C7D3236E742 /* Container+TypeForwarding.swift in Sources */, B2FAD41F7726502822AF913B /* Container.swift in Sources */, + 77F95816231318EA00FD392A /* Module+Assembly.swift in Sources */, 8B5927517B567B1DFAB5B935 /* ContextTranslator.swift in Sources */, 77F958062312C82600FD392A /* InjectionRequest.swift in Sources */, FB467C5FB6C6851FD1B6DB51 /* InstanceRequest+APi.swift in Sources */, @@ -1503,6 +1524,7 @@ 708E1C453CBC76ED26FA2FCB /* ProviderSpec.swift in Sources */, E227D08034E08AA0909BC043 /* RetrievalSpec.swift in Sources */, 33B86F2D33219879731CDDF0 /* ScopesSpec.swift in Sources */, + 77F9580F231317AA00FD392A /* InteroperabilitySpec.swift in Sources */, 30D247E8083858C233B92908 /* SingletonSpec.swift in Sources */, 72217E47D83C3CA6D97640B9 /* StandardScopeRegistrySpec.swift in Sources */, 640F7A55D9A671FA112C8083 /* SwinjectTreeBuilderSpec.swift in Sources */, @@ -1545,6 +1567,7 @@ CF9535A0DCAFF23F4D62F871 /* ProviderSpec.swift in Sources */, 1A68A8D05D9974002BF34CF8 /* RetrievalSpec.swift in Sources */, 0068DAA4AA322F00AF53731F /* ScopesSpec.swift in Sources */, + 77F95810231317AA00FD392A /* InteroperabilitySpec.swift in Sources */, B65DE0B0562540CC8CEC48F3 /* SingletonSpec.swift in Sources */, C952D5869D87743297968E9A /* StandardScopeRegistrySpec.swift in Sources */, A308578B99D33C7E33632E85 /* SwinjectTreeBuilderSpec.swift in Sources */, @@ -1587,6 +1610,7 @@ 4954CBB07E38E98752AC3347 /* ProviderSpec.swift in Sources */, 2F664F8534CA1D92ED2F81E2 /* RetrievalSpec.swift in Sources */, 31729A1E5F50EF30FDD427AD /* ScopesSpec.swift in Sources */, + 77F95812231317AB00FD392A /* InteroperabilitySpec.swift in Sources */, 0CE158916595980A7C8272D3 /* SingletonSpec.swift in Sources */, 0720BEA814AD514378380ACB /* StandardScopeRegistrySpec.swift in Sources */, 3CEF021295AD9AF9BF26B71E /* SwinjectTreeBuilderSpec.swift in Sources */, @@ -1629,6 +1653,7 @@ 48F40377D116C6B1B786C329 /* ProviderSpec.swift in Sources */, 06CD85528AABB15BDFBF3166 /* RetrievalSpec.swift in Sources */, EA0D19F7DF0355C774B0F40B /* ScopesSpec.swift in Sources */, + 77F95811231317AB00FD392A /* InteroperabilitySpec.swift in Sources */, 980FED1DBC62B65597E2828B /* SingletonSpec.swift in Sources */, 0B61DC733616A8ED4ED77FA7 /* StandardScopeRegistrySpec.swift in Sources */, 233F3E25FF0B51A3E6611F58 /* SwinjectTreeBuilderSpec.swift in Sources */, @@ -1653,6 +1678,7 @@ A5E4C79F89E1A8AB3A4D8D6E /* Container+Registration.swift in Sources */, BD9B57E26722C80B7EF990DB /* Container+TypeForwarding.swift in Sources */, DB74F17CDFF4886B9C38AD14 /* Container.swift in Sources */, + 77F95817231318EA00FD392A /* Module+Assembly.swift in Sources */, DD5E3AF2B5FCE5E81EBDF606 /* ContextTranslator.swift in Sources */, 77F958072312C82600FD392A /* InjectionRequest.swift in Sources */, 921406E8219BBDAFE2BEEDD6 /* InstanceRequest+APi.swift in Sources */, @@ -1700,6 +1726,7 @@ CB0B308F3D3A831A28127462 /* Container+Registration.swift in Sources */, 283C77045DA55C2134EC9C48 /* Container+TypeForwarding.swift in Sources */, 58ABEE0321A3061048B65EA2 /* Container.swift in Sources */, + 77F95818231318EA00FD392A /* Module+Assembly.swift in Sources */, F06DEB671A4B85ABB0E96E51 /* ContextTranslator.swift in Sources */, 77F958082312C82600FD392A /* InjectionRequest.swift in Sources */, EEBB114E8A57F37E4F226482 /* InstanceRequest+APi.swift in Sources */, @@ -1747,6 +1774,7 @@ 21285CED416F1317E993397A /* Container+Registration.swift in Sources */, 3A0B409E840B44B281DB3C54 /* Container+TypeForwarding.swift in Sources */, 0622539110A7430776A307C7 /* Container.swift in Sources */, + 77F95815231318EA00FD392A /* Module+Assembly.swift in Sources */, D1DF4740A9D86362B63104B8 /* ContextTranslator.swift in Sources */, 77F958052312C82600FD392A /* InjectionRequest.swift in Sources */, 4FACFC5F59982A6EDA7F8E4D /* InstanceRequest+APi.swift in Sources */, diff --git a/Tests/3.0 API/InteroperabilitySpec.swift b/Tests/3.0 API/InteroperabilitySpec.swift new file mode 100644 index 00000000..30a93cac --- /dev/null +++ b/Tests/3.0 API/InteroperabilitySpec.swift @@ -0,0 +1,101 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +import Nimble +import Quick +import Swinject +@testable import class Swinject.UnboundScope + +class InteroperabilitySpec: QuickSpec { override func spec() { #if swift(>=5.1) + it("can resolve module bindings from assembler") { + let module = Swinject.Module("") { + register().constant(42) + } + let assembler = Assembler([module]) + expect(assembler.resolver.resolve(Int.self)) == 42 + } + it("can use module bindings from other assemblies") { + let module = Swinject.Module("") { + register().constant(42) + } + struct OtherAssembly: Assembly { + func assemble(container: Container) { + container.register(Double.self) { Double($0.resolve(Int.self)!) } + } + } + let assembler = Assembler([module, OtherAssembly()]) + expect(assembler.resolver.resolve(Double.self)) == 42 + } + it("can use assembly bindings in module") { + let module = Swinject.Module("") { + register().resultOf(Double.init ^ instance(of: Int.self)) + } + struct OtherAssembly: Assembly { + func assemble(container: Container) { + container.register(Int.self) { _ in 42 } + } + } + let assembler = Assembler([module, OtherAssembly()]) + expect(assembler.resolver.resolve(Double.self)) == 42 + } + it("can use 3.0 injection api with container") { + let container = Container { + $0.register(Int.self) { _ in 42 } + } + expect { try instance(of: Int.self).from(container) } == 42 + } + describe("singletons") { + beforeEach { + UnboundScope.root.close() + } + struct Dependencies: Assembly { + func assemble(container: Container) { + container.register(String.self) { _ in "mimi" } + container.register(Human.self) { _ in Human() } + } + } + it("can use unscoped singletons") { + let module = Swinject.Module("") { + registerSingle().resultOf(Pet.init^) + } + let assembler = Assembler([module, Dependencies()]) + + let first = try? instance(of: Pet.self).from(assembler.resolver) + let second = try? instance(of: Pet.self).from(assembler.resolver) + + expect(first) === second + } + it("can use singletons in scope without context") { + let scope = UnboundScope() + let module = Swinject.Module("") { + registerSingle(in: scope).resultOf(Pet.init^) + } + let assembler = Assembler([module, Dependencies()]) + + let first = try? instance(of: Pet.self).from(assembler.resolver) + let second = try? instance(of: Pet.self).from(assembler.resolver) + + expect(first) === second + } + it("cannot use scopes with context if dependencies are defined in assembly") { + let sessionScope = SessionScope() + let session = Session() + let module = Swinject.Module("") { + registerSingle(in: sessionScope).resultOf(Pet.init^) + } + let assembler = Assembler([module, Dependencies()]) + + expect { try instance(of: Pet.self).from(assembler.resolver.on(session)) }.to(throwError()) + } + it("cannot use contexts if dependencies are defined in assembly") { + let module = Swinject.Module("") { + register(inContextOf: String.self).resultOf(Pet.init^) + } + let assembler = Assembler([module, Dependencies()]) + + expect { try instance(of: Pet.self).from(assembler.resolver.on("context")) }.to(throwError()) + } + } + #endif +} } diff --git a/Tests/3.0 API/ScopesSpec.swift b/Tests/3.0 API/ScopesSpec.swift index 26ccab19..e9a19cc0 100644 --- a/Tests/3.0 API/ScopesSpec.swift +++ b/Tests/3.0 API/ScopesSpec.swift @@ -93,13 +93,3 @@ class ScopesSpec: QuickSpec { override func spec() { #if swift(>=5.1) } #endif } } - -class Session { - let registry = StandardScopeRegistry() -} - -struct SessionScope: Scope { - func registry(for session: Session) -> ScopeRegistry { - return session.registry - } -} diff --git a/Tests/LinuxConfig.swift b/Tests/LinuxConfig.swift index 2f5e53b3..9d3058cc 100644 --- a/Tests/LinuxConfig.swift +++ b/Tests/LinuxConfig.swift @@ -27,6 +27,7 @@ let allSpecs: [QuickSpec.Type] = [ RetrievalSpec.self, PropertyWrappersSpec.self, DependencyCheckSpec.self, + InteroperabilitySpec.self, // Unit Specs StandardScopeRegistrySpec.self, SwinjectTreeBuilderSpec.self, diff --git a/Tests/Support/TestModels.swift b/Tests/Support/TestModels.swift index 5b822666..3e1dfb6e 100644 --- a/Tests/Support/TestModels.swift +++ b/Tests/Support/TestModels.swift @@ -40,3 +40,13 @@ class Door: Closable { whenClosed() } } + +class Session { + let registry = StandardScopeRegistry() +} + +struct SessionScope: Scope { + func registry(for session: Session) -> ScopeRegistry { + return session.registry + } +} From 25f9073317e194b728540f3ff5efb2e91dd59c44 Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Sun, 25 Aug 2019 17:16:37 +0200 Subject: [PATCH 237/239] Remove matchable overloads from binding factory api --- Sources/3.0 API/Binding+Factory.swift | 40 --------------------------- Templates/FactoryVariation.swift | 10 +------ Templates/SwiftCode.swifttemplate | 10 +------ 3 files changed, 2 insertions(+), 58 deletions(-) diff --git a/Sources/3.0 API/Binding+Factory.swift b/Sources/3.0 API/Binding+Factory.swift index e9f268d6..9202983d 100644 --- a/Sources/3.0 API/Binding+Factory.swift +++ b/Sources/3.0 API/Binding+Factory.swift @@ -30,14 +30,6 @@ public extension Binding { } } - func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1) throws -> NewInstance) -> Binding where Arg1: Hashable { - return updatedFactory { r, a in try factory(r, a.arg(0)) }.updated { - $0.products = [tagged(NewInstance.self, with: tag)] - $0.dependencies = [] - $0.arguments = [Arg1.self] - } - } - func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2) throws -> NewInstance) -> Binding { return updatedFactory { r, a in try factory(r, a.arg(0), a.arg(1)) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] @@ -46,14 +38,6 @@ public extension Binding { } } - func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2) throws -> NewInstance) -> Binding where Arg1: Hashable, Arg2: Hashable { - return updatedFactory { r, a in try factory(r, a.arg(0), a.arg(1)) }.updated { - $0.products = [tagged(NewInstance.self, with: tag)] - $0.dependencies = [] - $0.arguments = [Arg1.self, Arg2.self] - } - } - func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2, Arg3) throws -> NewInstance) -> Binding { return updatedFactory { r, a in try factory(r, a.arg(0), a.arg(1), a.arg(2)) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] @@ -62,14 +46,6 @@ public extension Binding { } } - func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2, Arg3) throws -> NewInstance) -> Binding where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable { - return updatedFactory { r, a in try factory(r, a.arg(0), a.arg(1), a.arg(2)) }.updated { - $0.products = [tagged(NewInstance.self, with: tag)] - $0.dependencies = [] - $0.arguments = [Arg1.self, Arg2.self, Arg3.self] - } - } - func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2, Arg3, Arg4) throws -> NewInstance) -> Binding { return updatedFactory { r, a in try factory(r, a.arg(0), a.arg(1), a.arg(2), a.arg(3)) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] @@ -78,14 +54,6 @@ public extension Binding { } } - func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2, Arg3, Arg4) throws -> NewInstance) -> Binding where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable { - return updatedFactory { r, a in try factory(r, a.arg(0), a.arg(1), a.arg(2), a.arg(3)) }.updated { - $0.products = [tagged(NewInstance.self, with: tag)] - $0.dependencies = [] - $0.arguments = [Arg1.self, Arg2.self, Arg3.self, Arg4.self] - } - } - func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> NewInstance) -> Binding { return updatedFactory { r, a in try factory(r, a.arg(0), a.arg(1), a.arg(2), a.arg(3), a.arg(4)) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] @@ -93,14 +61,6 @@ public extension Binding { $0.arguments = [Arg1.self, Arg2.self, Arg3.self, Arg4.self, Arg5.self] } } - - func factory(for _: NewInstance.Type = NewInstance.self, tag: String? = nil, factory: @escaping (ContextedResolver, Arg1, Arg2, Arg3, Arg4, Arg5) throws -> NewInstance) -> Binding where Arg1: Hashable, Arg2: Hashable, Arg3: Hashable, Arg4: Hashable, Arg5: Hashable { - return updatedFactory { r, a in try factory(r, a.arg(0), a.arg(1), a.arg(2), a.arg(3), a.arg(4)) }.updated { - $0.products = [tagged(NewInstance.self, with: tag)] - $0.dependencies = [] - $0.arguments = [Arg1.self, Arg2.self, Arg3.self, Arg4.self, Arg5.self] - } - } } // sourcery:end diff --git a/Templates/FactoryVariation.swift b/Templates/FactoryVariation.swift index 97a1e546..76a0a5d7 100644 --- a/Templates/FactoryVariation.swift +++ b/Templates/FactoryVariation.swift @@ -5,7 +5,6 @@ struct FactoryVariation { let args: Int let hasResolver: Bool - let isMatchable: Bool } extension FactoryVariation { @@ -48,10 +47,6 @@ extension FactoryVariation { return join((1 ..< args + 1).map { "Arg\($0): Hashable" }) } - var constraints: String { - return isMatchable && args > 0 ? "where \(hashableArgTypes) " : "" - } - var argVarsOrNil: String? { switch args { case 0: return nil @@ -79,23 +74,20 @@ extension FactoryVariation { static let allCases = (0 ... maxArgs) .flatMap { t in [false, true].map { (t, $0) } } - .flatMap { t in [false, true].map { (t.0, t.1, $0) } } .map(FactoryVariation.init) static let sortedCases = allCases.sorted { [ $0.args < $1.args, - !$0.isMatchable && $1.isMatchable && $0.args == $1.args, ].contains(true) } static let publicCases = sortedCases - .filter { !($0.args == 0 && !$0.isMatchable) } .filter { !($0.args > 0 && !$0.hasResolver) } } extension FactoryVariation { func render() -> String { return """ - func factory<\(genericTypes)>(\(params)) -> \(returnType) \(constraints){ + func factory<\(genericTypes)>(\(params)) -> \(returnType) { return updatedFactory { \(factoryInputs) in try factory(\(factoryVars)) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] $0.dependencies = [] diff --git a/Templates/SwiftCode.swifttemplate b/Templates/SwiftCode.swifttemplate index 2bce5eb1..901a04b4 100644 --- a/Templates/SwiftCode.swifttemplate +++ b/Templates/SwiftCode.swifttemplate @@ -92,7 +92,6 @@ extension InstanceRequestVariation { struct FactoryVariation { let args: Int let hasResolver: Bool - let isMatchable: Bool } extension FactoryVariation { @@ -135,10 +134,6 @@ extension FactoryVariation { return join((1 ..< args + 1).map { "Arg\($0): Hashable" }) } - var constraints: String { - return isMatchable && args > 0 ? "where \(hashableArgTypes) " : "" - } - var argVarsOrNil: String? { switch args { case 0: return nil @@ -166,23 +161,20 @@ extension FactoryVariation { static let allCases = (0 ... maxArgs) .flatMap { t in [false, true].map { (t, $0) } } - .flatMap { t in [false, true].map { (t.0, t.1, $0) } } .map(FactoryVariation.init) static let sortedCases = allCases.sorted { [ $0.args < $1.args, - !$0.isMatchable && $1.isMatchable && $0.args == $1.args, ].contains(true) } static let publicCases = sortedCases - .filter { !($0.args == 0 && !$0.isMatchable) } .filter { !($0.args > 0 && !$0.hasResolver) } } extension FactoryVariation { func render() -> String { return """ - func factory<\(genericTypes)>(\(params)) -> \(returnType) \(constraints){ + func factory<\(genericTypes)>(\(params)) -> \(returnType) { return updatedFactory { \(factoryInputs) in try factory(\(factoryVars)) }.updated { $0.products = [tagged(NewInstance.self, with: tag)] $0.dependencies = [] From 42c57d6d09a3ba8093f3d961ed2d669ee2f6bad2 Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Thu, 29 Aug 2019 11:20:04 +0200 Subject: [PATCH 238/239] Refine dependency checking --- Sources/3.0 API/PartialRequest.swift | 2 +- Sources/Core/AnyBinding.swift | 2 +- Sources/Core/InstanceRequest.swift | 15 ++- Sources/Core/PropertyWrapper.swift | 26 +++-- Sources/Core/Swinject.swift | 33 +----- Sources/Core/SwinjectContainer+Builder.swift | 95 ++++++++++++++++ Sources/Core/SwinjectContainer.swift | 110 +++++-------------- Sources/Core/TypeDescriptor.swift | 13 ++- Swinject.xcodeproj/project.pbxproj | 10 ++ Tests/3.0 API/DependencyCheckSpec.swift | 31 ++++++ 10 files changed, 209 insertions(+), 128 deletions(-) create mode 100644 Sources/Core/SwinjectContainer+Builder.swift diff --git a/Sources/3.0 API/PartialRequest.swift b/Sources/3.0 API/PartialRequest.swift index fa5b4939..76f5012c 100644 --- a/Sources/3.0 API/PartialRequest.swift +++ b/Sources/3.0 API/PartialRequest.swift @@ -32,7 +32,7 @@ public func argument(_ index: Int, as _: Type.Type = Type.self) -> Argumen } extension InstanceRequest: PartialRequest { - public var asDependency: BindingDependency { return .instance(type, arguments.descriptor) } + public var asDependency: BindingDependency { return .instance(descriptor) } public func fulfill(with resolver: Resolver, and _: Arguments) throws -> Type { return try resolver.resolve(self) diff --git a/Sources/Core/AnyBinding.swift b/Sources/Core/AnyBinding.swift index 91d2764b..4bbbe238 100644 --- a/Sources/Core/AnyBinding.swift +++ b/Sources/Core/AnyBinding.swift @@ -33,7 +33,7 @@ extension BindingKey { } public enum BindingDependency { - case instance(TypeDescriptor, Arguments.Descriptor) + case instance(InstanceRequestDescriptor) case argument(Any.Type) case context(Any.Type) } diff --git a/Sources/Core/InstanceRequest.swift b/Sources/Core/InstanceRequest.swift index 59fc9756..8bb6b8d3 100644 --- a/Sources/Core/InstanceRequest.swift +++ b/Sources/Core/InstanceRequest.swift @@ -20,8 +20,19 @@ func request( return InstanceRequest(type: tagged(type, with: tag), arguments: arg) } +public struct InstanceRequestDescriptor { + let type: TypeDescriptor + let arguments: Arguments.Descriptor +} + extension AnyInstanceRequest { - func key(forContextType contextType: Any.Type) -> BindingKey { - return BindingKey(type: type, contextType: contextType, arguments: arguments.descriptor) + var descriptor: InstanceRequestDescriptor { + return .init(type: type, arguments: arguments.descriptor) + } +} + +extension InstanceRequestDescriptor { + func key(on contextType: Any.Type) -> BindingKey { + return BindingKey(type: type, contextType: contextType, arguments: arguments) } } diff --git a/Sources/Core/PropertyWrapper.swift b/Sources/Core/PropertyWrapper.swift index ed8fd012..ebc4c825 100644 --- a/Sources/Core/PropertyWrapper.swift +++ b/Sources/Core/PropertyWrapper.swift @@ -4,7 +4,7 @@ protocol CustomResolvable { init(resolver: Resolver, request: AnyInstanceRequest) - static func requiredRequest(for request: AnyInstanceRequest) -> AnyInstanceRequest? + static func requiredRequest(for request: InstanceRequestDescriptor) -> InstanceRequestDescriptor? } protocol PropertyWrapper: CustomResolvable { @@ -18,22 +18,24 @@ extension PropertyWrapper { self.init(wrappedValue: try! resolver.resolve(request.replacingType(with: Value.self))) } - static func requiredRequest(for request: AnyInstanceRequest) -> AnyInstanceRequest? { - if let wrapper = Value.self as? CustomResolvable.Type { - return wrapper.requiredRequest(for: request) - } else { - return request.replacingType(with: Value.self) - } + static func requiredRequest(for request: InstanceRequestDescriptor) -> InstanceRequestDescriptor? { + return request.replacingType(with: Value.self) } } extension AnyInstanceRequest { func replacingType(with _: Type.Type) -> InstanceRequest { return InstanceRequest( - type: TypeDescriptor( - tag: type.tag, - type: Type.self - ), + type: TypeDescriptor(tag: type.tag, type: Type.self), + arguments: arguments + ) + } +} + +extension InstanceRequestDescriptor { + func replacingType(with _: Type.Type) -> InstanceRequestDescriptor { + return InstanceRequestDescriptor( + type: TypeDescriptor(tag: type.tag, type: Type.self), arguments: arguments ) } @@ -44,7 +46,7 @@ extension Optional: CustomResolvable { self = try? resolver.resolve(request.replacingType(with: Wrapped.self)) as Wrapped } - static func requiredRequest(for _: AnyInstanceRequest) -> AnyInstanceRequest? { + static func requiredRequest(for _: InstanceRequestDescriptor) -> InstanceRequestDescriptor? { return nil } } diff --git a/Sources/Core/Swinject.swift b/Sources/Core/Swinject.swift index 63b74c9d..0c3307ff 100644 --- a/Sources/Core/Swinject.swift +++ b/Sources/Core/Swinject.swift @@ -20,9 +20,9 @@ extension Swinject: Resolver { public func resolve(_ request: InstanceRequest) throws -> Type { let binding: AnyBinding do { - binding = try findBinding(for: request) + binding = try container.findBinding(for: request.descriptor, on: contextType) } catch let error as NoBinding { - if let custom = resolve(request, asCustom: Type.self) { return custom } + if let custom = customResolve(request) { return custom } throw error } return try tracking(request).makeInstance(from: binding, with: request.arguments) @@ -33,7 +33,7 @@ extension Swinject: Resolver { } public func context(as resultType: Any.Type) throws -> Any { - return try allTranslators + return try container.allTranslators(on: contextType) .filter { $0.sourceType == contextType && $0.targetType == resultType } .compactMap { try $0.translate(anyContext) } .first ?? { throw NoContextTranslator() }() @@ -41,9 +41,9 @@ extension Swinject: Resolver { } extension Swinject { - private func resolve(_ request: InstanceRequest, asCustom _: Type.Type) -> Type? { + private func customResolve(_ request: InstanceRequest) -> Type? { guard let custom = Type.self as? CustomResolvable.Type else { return nil } - if let request = custom.requiredRequest(for: request), !hasBinding(for: request) { return nil } + guard container.hasBinding(for: request.descriptor, on: contextType) else { return nil } // TODO: We should reset tracking only for "delayed" custom resolutions return custom.init(resolver: with(stack: []), request: request) as? Type } @@ -54,29 +54,6 @@ extension Swinject { return with(stack: stack + [request]) } - private func translatableKeys(for request: AnyInstanceRequest) -> [BindingKey] { - return allTranslators.map { request.key(forContextType: $0.targetType) } - } - - private var allTranslators: [AnyContextTranslator] { - return container.translators.filter { $0.sourceType == contextType } + defaultTranslators - } - - private var defaultTranslators: [AnyContextTranslator] { - return [IdentityTranslator(for: contextType), ToAnyTranslator(for: contextType)] - } - - private func hasBinding(for request: AnyInstanceRequest) -> Bool { - return (try? findBinding(for: request)) != nil - } - - private func findBinding(for request: AnyInstanceRequest) throws -> AnyBinding { - let bindings = translatableKeys(for: request).compactMap { container.bindings[$0] } - if bindings.isEmpty { throw NoBinding() } - if bindings.count > 1 { throw MultipleBindings() } - return bindings[0] - } - private func makeInstance(from binding: AnyBinding, with arguments: Arguments) throws -> Type { return try binding.makeInstance(resolver: self, arguments: arguments) as? Type ?? { throw SwinjectError() }() } diff --git a/Sources/Core/SwinjectContainer+Builder.swift b/Sources/Core/SwinjectContainer+Builder.swift new file mode 100644 index 00000000..e6439fb2 --- /dev/null +++ b/Sources/Core/SwinjectContainer+Builder.swift @@ -0,0 +1,95 @@ +// +// Copyright © 2019 Swinject Contributors. All rights reserved. +// + +extension SwinjectContainer { + struct Builder { + let tree: SwinjectTree + let properties: Swinject.Properties + } +} + +extension SwinjectContainer.Builder { + func makeContainer() -> SwinjectContainer { + do { return try makeContainerOrThrow() } catch { fatalError("\(error)") } + } + + private func makeContainerOrThrow() throws -> SwinjectContainer { + try checkDuplicitModules() + let container = SwinjectContainer( + bindings: try collectBindings(), + translators: tree.translators + ) + try container.checkDependencies() + return container + } +} + +extension SwinjectContainer.Builder { + private func checkDuplicitModules() throws { + let names = collectModules(from: tree).map { $0.name } + if names.containsDuplicates { throw DuplicateModules() } + } + + private func collectModules(from tree: SwinjectTree) -> [Swinject.Module] { + return tree.modules.map { $0.module } + tree.modules.flatMap { collectModules(from: $0.module.tree) } + } +} + +extension SwinjectContainer.Builder { + private struct BindingEntry { + let binding: AnyBinding + let key: BindingKey + let overrides: Bool + let canOverride: Bool + let canOverrideSilently: Bool + } + + private func collectBindings() throws -> [BindingKey: AnyBinding] { + return try collectBindingEntries(from: tree, canOverrideSilently: properties.allowsSilentOverride) + .reduce(into: [BindingKey: AnyBinding]()) { dict, entry in + try checkOverrideRules(for: entry, beingAddedTo: dict) + dict[entry.key] = entry.binding + } + } + + private func checkOverrideRules(for entry: BindingEntry, beingAddedTo dict: [BindingKey: AnyBinding]) throws { + if !entry.canOverride, entry.overrides { + throw OverrideNotAllowed() + } + if dict[entry.key] == nil, entry.overrides { + throw NothingToOverride() + } + if dict[entry.key] != nil, !entry.overrides, !entry.canOverrideSilently { + throw SilentOverrideNotAllowed() + } + } + + private func collectBindingEntries( + from tree: SwinjectTree, + canOverride: Bool? = nil, + canOverrideSilently: Bool + ) -> [BindingEntry] { + return tree.bindings + .flatMap { binding in binding.keys.map { key in + BindingEntry( + binding: binding, + key: key, + overrides: binding.overrides, + canOverride: canOverride ?? true, + canOverrideSilently: canOverrideSilently + ) + } } + + tree.modules.flatMap { collectBindingEntries( + from: $0.module.tree, + canOverride: canOverride ?? $0.canOverride, + canOverrideSilently: $0.module.allowsSilentOverride + ) } + } +} + +private extension Array where Element: Hashable { + var containsDuplicates: Bool { + return count != Set(self).count + } +} diff --git a/Sources/Core/SwinjectContainer.swift b/Sources/Core/SwinjectContainer.swift index 55f77b3f..2b7c35fd 100644 --- a/Sources/Core/SwinjectContainer.swift +++ b/Sources/Core/SwinjectContainer.swift @@ -5,103 +5,51 @@ struct SwinjectContainer { let bindings: [BindingKey: AnyBinding] let translators: [AnyContextTranslator] - - struct Builder { - let tree: SwinjectTree - let properties: Swinject.Properties - } -} - -extension SwinjectContainer.Builder { - func makeContainer() -> SwinjectContainer { - do { return try makeContainerOrThrow() } catch { fatalError("\(error)") } - } - - private func makeContainerOrThrow() throws -> SwinjectContainer { - try checkDuplicitModules() - let bindings = try collectBindings() - try checkDependencies(for: bindings) - return SwinjectContainer(bindings: bindings, translators: tree.translators) - } } -extension SwinjectContainer.Builder { - private func checkDuplicitModules() throws { - let names = collectModules(from: tree).map { $0.name } - if names.containsDuplicates { throw DuplicateModules() } - } - - private func collectModules(from tree: SwinjectTree) -> [Swinject.Module] { - return tree.modules.map { $0.module } + tree.modules.flatMap { collectModules(from: $0.module.tree) } +extension SwinjectContainer { + func checkDependencies() throws { + try bindings.values + .flatMap { $0.dependencies } + .compactMap { $0.asInstanceRequest } + .forEach { + if !hasBinding(for: $0, on: Any.self) { throw MissingDependency() } + } } } -extension SwinjectContainer.Builder { - func checkDependencies(for bindings: [BindingKey: AnyBinding]) throws { - try bindings.values.flatMap { $0.dependencies }.forEach { - if case let .instance(type, arguments) = $0 { - if !bindings.keys.contains(where: { $0.type == type && $0.arguments == arguments }) { - throw MissingDependency() - } - } +extension SwinjectContainer { + func hasBinding(for request: InstanceRequestDescriptor, on contextType: Any.Type) -> Bool { + if let custom = request.type.type as? CustomResolvable.Type { + return custom.requiredRequest(for: request).map { hasBinding(for: $0, on: contextType) } ?? true + } else { + return (try? findBinding(for: request, on: contextType)) != nil } } -} -extension SwinjectContainer.Builder { - private struct BindingEntry { - let binding: AnyBinding - let key: BindingKey - let overrides: Bool - let canOverride: Bool - let canOverrideSilently: Bool + func findBinding(for request: InstanceRequestDescriptor, on contextType: Any.Type) throws -> AnyBinding { + let bindings = translatableKeys(for: request, on: contextType).compactMap { self.bindings[$0] } + if bindings.isEmpty { throw NoBinding() } + if bindings.count > 1 { throw MultipleBindings() } + return bindings[0] } - private func collectBindings() throws -> [BindingKey: AnyBinding] { - return try collectBindingEntries(from: tree, canOverrideSilently: properties.allowsSilentOverride) - .reduce(into: [BindingKey: AnyBinding]()) { dict, entry in - try checkOverrideRules(for: entry, beingAddedTo: dict) - dict[entry.key] = entry.binding - } + func allTranslators(on contextType: Any.Type) -> [AnyContextTranslator] { + return translators.filter { $0.sourceType == contextType } + defaultTranslators(on: contextType) } - private func checkOverrideRules(for entry: BindingEntry, beingAddedTo dict: [BindingKey: AnyBinding]) throws { - if !entry.canOverride, entry.overrides { - throw OverrideNotAllowed() - } - if dict[entry.key] == nil, entry.overrides { - throw NothingToOverride() - } - if dict[entry.key] != nil, !entry.overrides, !entry.canOverrideSilently { - throw SilentOverrideNotAllowed() - } + private func defaultTranslators(on contextType: Any.Type) -> [AnyContextTranslator] { + return [IdentityTranslator(for: contextType)] + + (contextType == Any.self ? [] : [ToAnyTranslator(for: contextType)]) } - private func collectBindingEntries( - from tree: SwinjectTree, - canOverride: Bool? = nil, - canOverrideSilently: Bool - ) -> [BindingEntry] { - return tree.bindings - .flatMap { binding in binding.keys.map { key in - BindingEntry( - binding: binding, - key: key, - overrides: binding.overrides, - canOverride: canOverride ?? true, - canOverrideSilently: canOverrideSilently - ) - } } - + tree.modules.flatMap { collectBindingEntries( - from: $0.module.tree, - canOverride: canOverride ?? $0.canOverride, - canOverrideSilently: $0.module.allowsSilentOverride - ) } + private func translatableKeys(for request: InstanceRequestDescriptor, on contextType: Any.Type) -> [BindingKey] { + return allTranslators(on: contextType).map { request.key(on: $0.targetType) } } } -private extension Array where Element: Hashable { - var containsDuplicates: Bool { - return count != Set(self).count +private extension BindingDependency { + var asInstanceRequest: InstanceRequestDescriptor? { + if case let .instance(descriptor) = self { return descriptor } else { return nil } } } diff --git a/Sources/Core/TypeDescriptor.swift b/Sources/Core/TypeDescriptor.swift index 4a389195..cf06e098 100644 --- a/Sources/Core/TypeDescriptor.swift +++ b/Sources/Core/TypeDescriptor.swift @@ -5,19 +5,26 @@ public struct TypeDescriptor: Hashable { let tag: String? let type: Any.Type + private let unwrappedType: Any.Type + + init(tag: String?, type: Any.Type) { + self.tag = tag + self.type = type + unwrappedType = unwrapOptionals(type) + } public func hash(into hasher: inout Hasher) { - ObjectIdentifier(type).hash(into: &hasher) + ObjectIdentifier(unwrappedType).hash(into: &hasher) tag.hash(into: &hasher) } public static func == (lhs: TypeDescriptor, rhs: TypeDescriptor) -> Bool { - return lhs.type == rhs.type && lhs.tag == rhs.tag + return lhs.unwrappedType == rhs.unwrappedType && lhs.tag == rhs.tag } } func tagged(_: Type.Type, with tag: String?) -> TypeDescriptor { - return TypeDescriptor(tag: tag, type: unwrapOptionals(Type.self)) + return TypeDescriptor(tag: tag, type: Type.self) } func unwrapOptionals(_ type: Any.Type) -> Any.Type { diff --git a/Swinject.xcodeproj/project.pbxproj b/Swinject.xcodeproj/project.pbxproj index f897ec56..cecb2d24 100644 --- a/Swinject.xcodeproj/project.pbxproj +++ b/Swinject.xcodeproj/project.pbxproj @@ -158,6 +158,10 @@ 751F545653B0F1E30341C312 /* OverrideSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86C18DDD83715886DF7F1818 /* OverrideSpec.swift */; }; 75D74C8C25EDACF5A7A75A5C /* Swinject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9620155728133F451B31C0AD /* Swinject.swift */; }; 778D9AB6470D4280254AC140 /* TestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722CAC1761180366DE75A4A6 /* TestModels.swift */; }; + 77B60C7D2317C42700F6CCE3 /* SwinjectContainer+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77B60C7C2317C42700F6CCE3 /* SwinjectContainer+Builder.swift */; }; + 77B60C7E2317C42700F6CCE3 /* SwinjectContainer+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77B60C7C2317C42700F6CCE3 /* SwinjectContainer+Builder.swift */; }; + 77B60C7F2317C42700F6CCE3 /* SwinjectContainer+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77B60C7C2317C42700F6CCE3 /* SwinjectContainer+Builder.swift */; }; + 77B60C802317C42700F6CCE3 /* SwinjectContainer+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77B60C7C2317C42700F6CCE3 /* SwinjectContainer+Builder.swift */; }; 77BF219EAB4FC8475943CECC /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6D434EB4C13CF9D9FA6D80CB /* Swinject.framework */; }; 77F957F9231298E400FD392A /* FunctionCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F957F8231298E400FD392A /* FunctionCall.swift */; }; 77F957FA231298E400FD392A /* FunctionCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F957F8231298E400FD392A /* FunctionCall.swift */; }; @@ -536,6 +540,7 @@ 74118B5030E790B24C0F44AF /* ContainerSpec.CustomStringConvertible.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerSpec.CustomStringConvertible.swift; sourceTree = ""; }; 74DE57FB3E8228904E6FE0D7 /* Swinject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Swinject.h; sourceTree = ""; }; 75BE3AE3E30DFE42A919D825 /* ModulesSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModulesSpec.swift; sourceTree = ""; }; + 77B60C7C2317C42700F6CCE3 /* SwinjectContainer+Builder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SwinjectContainer+Builder.swift"; sourceTree = ""; }; 77F957F8231298E400FD392A /* FunctionCall.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FunctionCall.swift; sourceTree = ""; }; 77F957FD2312A4C600FD392A /* FunctionCallVariations.swifttemplate */ = {isa = PBXFileReference; lastKnownFileType = text; path = FunctionCallVariations.swifttemplate; sourceTree = ""; }; 77F957FF2312ACFF00FD392A /* DependencyCheckSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DependencyCheckSpec.swift; sourceTree = ""; }; @@ -893,6 +898,7 @@ 98A8DD30D81D1A4223A5EBC9 /* ScopeRegistryKey.swift */, 9620155728133F451B31C0AD /* Swinject.swift */, 8C4916168E81D76536892122 /* SwinjectContainer.swift */, + 77B60C7C2317C42700F6CCE3 /* SwinjectContainer+Builder.swift */, A3586A4987B7C7C8122D674E /* SwinjectError.swift */, C1E726A651C3AFE92C19608B /* SwinjectModule.swift */, 47018AC89CBE8254E17C4639 /* SwinjectTree.swift */, @@ -1462,6 +1468,7 @@ 8016512839FE61EC3127E489 /* Resolver.swift in Sources */, 77F957FA231298E400FD392A /* FunctionCall.swift in Sources */, 06D09D88E514CCA11D101AFB /* Retrieval.swift in Sources */, + 77B60C7E2317C42700F6CCE3 /* SwinjectContainer+Builder.swift in Sources */, 68C95FCB0D345CA3BA24D320 /* Scope.swift in Sources */, BB571B9A78FC53231A18E18C /* ScopeRegistry.swift in Sources */, 593B93BA2EE3FE4418A1C579 /* ScopeRegistryKey.swift in Sources */, @@ -1692,6 +1699,7 @@ 5D7E26A00B055803A50CD9C2 /* Resolver.swift in Sources */, 77F957FB231298E400FD392A /* FunctionCall.swift in Sources */, 875D809B53B3A118AAF1348C /* Retrieval.swift in Sources */, + 77B60C7F2317C42700F6CCE3 /* SwinjectContainer+Builder.swift in Sources */, B84167AC8C6BEB57C4D0695A /* Scope.swift in Sources */, E7D1045D25FAB592401DCAF0 /* ScopeRegistry.swift in Sources */, 4347EE17D0C0ED574C899D85 /* ScopeRegistryKey.swift in Sources */, @@ -1740,6 +1748,7 @@ 97C2EA47D7623AFD723AFE93 /* Resolver.swift in Sources */, 77F957FC231298E400FD392A /* FunctionCall.swift in Sources */, 6405B24BE522A98AEB275E7D /* Retrieval.swift in Sources */, + 77B60C802317C42700F6CCE3 /* SwinjectContainer+Builder.swift in Sources */, 2C352AAD1AC7D82A4A059046 /* Scope.swift in Sources */, 02556F149C9AAEF5CE353AC1 /* ScopeRegistry.swift in Sources */, 06F4CAB352B4F623FF7BD885 /* ScopeRegistryKey.swift in Sources */, @@ -1788,6 +1797,7 @@ BE94EF7BCF976A703F961389 /* Resolver.swift in Sources */, 77F957F9231298E400FD392A /* FunctionCall.swift in Sources */, 6D10D2E438AA642300483BF1 /* Retrieval.swift in Sources */, + 77B60C7D2317C42700F6CCE3 /* SwinjectContainer+Builder.swift in Sources */, 96EA0A5DF33F025EBE0B67D2 /* Scope.swift in Sources */, D861595482464ED95CF81922 /* ScopeRegistry.swift in Sources */, 920DE2CAB9895D10FAE48FBA /* ScopeRegistryKey.swift in Sources */, diff --git a/Tests/3.0 API/DependencyCheckSpec.swift b/Tests/3.0 API/DependencyCheckSpec.swift index bff76ec5..d78b03e9 100644 --- a/Tests/3.0 API/DependencyCheckSpec.swift +++ b/Tests/3.0 API/DependencyCheckSpec.swift @@ -131,6 +131,37 @@ class DependencyCheckSpec: QuickSpec { override func spec() { #if swift(>=5.1) } }.to(throwAssertion()) } + it("does not fail if checked binding has optional dependency") { + struct Checked { + let optional: Int? + } + expect { + _ = Swinject { + register().resultOf(Checked.init^instance()) + } + }.notTo(throwAssertion()) + } + it("does not fail if checked binding has custom resolvable dependency") { + struct Checked { + let lazy: Lazy + } + expect { + _ = Swinject { + register().constant(42) + register().resultOf(Checked.init^instance()) + } + }.notTo(throwAssertion()) + } + it("fails if checked binding has custom resolvable with missing dependency") { + struct Checked { + let lazy: Lazy + } + expect { + _ = Swinject { + register().resultOf(Checked.init^instance()) + } + }.to(throwAssertion()) + } } #endif } } From 4c5fda41c35ef914338a6c3dbe5ff4f61800c964 Mon Sep 17 00:00:00 2001 From: Jakub Vano Date: Thu, 29 Aug 2019 11:49:12 +0200 Subject: [PATCH 239/239] Reset request tracking only for delayed custom resolutions --- Sources/2.0 API/InstanceWrapper.swift | 16 ++++++------ Sources/3.0 API/Weak.swift | 8 +++--- Sources/Core/PropertyWrapper.swift | 31 +++++++++++++++++++++--- Sources/Core/Swinject.swift | 6 +++-- Tests/3.0 API/PropertyWrappersSpec.swift | 4 +-- 5 files changed, 47 insertions(+), 18 deletions(-) diff --git a/Sources/2.0 API/InstanceWrapper.swift b/Sources/2.0 API/InstanceWrapper.swift index d636801b..b2d0bb02 100644 --- a/Sources/2.0 API/InstanceWrapper.swift +++ b/Sources/2.0 API/InstanceWrapper.swift @@ -6,7 +6,7 @@ /// `Lazy` does not need to be explicitly registered into the `Container` - resolution will work /// as long as there is a registration for the `Type`. #if swift(>=5.1) - @propertyWrapper public enum Lazy: PropertyWrapper { + @propertyWrapper public enum Lazy { case uninitialized(() -> Value) case initialized(Value) @@ -16,7 +16,7 @@ } #else - public enum Lazy: PropertyWrapper { + public enum Lazy { case uninitialized(() -> Value) case initialized(Value) } @@ -40,8 +40,10 @@ public extension Lazy { self = .initialized(newValue) } } +} - init(wrappedValue: @autoclosure @escaping () -> Value) { +extension Lazy: DelayedPropertyWrapper { + public init(wrappedValue: @autoclosure @escaping () -> Value) { self = .uninitialized(wrappedValue) } } @@ -50,7 +52,7 @@ public extension Lazy { /// `Provider` does not need to be explicitly registered into the `Container` - resolution will work /// as long as there is a registration for the `Type`. #if swift(>=5.1) - @propertyWrapper public struct Provider: PropertyWrapper { + @propertyWrapper public struct Provider { private let provider: () -> Type public var wrappedValue: Type { @@ -59,7 +61,7 @@ public extension Lazy { } #else - public struct Provider: PropertyWrapper { + public struct Provider { private let provider: () -> Type } #endif @@ -72,8 +74,8 @@ public extension Provider { } } -extension Provider { - init(wrappedValue: @autoclosure @escaping () -> Type) { +extension Provider: DelayedPropertyWrapper { + public init(wrappedValue: @autoclosure @escaping () -> Type) { provider = wrappedValue } diff --git a/Sources/3.0 API/Weak.swift b/Sources/3.0 API/Weak.swift index 5e191cd3..9e6eb8d5 100644 --- a/Sources/3.0 API/Weak.swift +++ b/Sources/3.0 API/Weak.swift @@ -6,8 +6,8 @@ @propertyWrapper public struct Weak: PropertyWrapper where Value: AnyObject { public weak var wrappedValue: Value? - public init(wrappedValue: @autoclosure () -> Value?) { - self.wrappedValue = wrappedValue() + public init(wrappedValue: Value?) { + self.wrappedValue = wrappedValue } } @@ -15,8 +15,8 @@ public struct Weak: PropertyWrapper where Value: AnyObject { public weak var wrappedValue: Value? - public init(wrappedValue: @autoclosure () -> Value?) { - self.wrappedValue = wrappedValue() + public init(wrappedValue: Value?) { + self.wrappedValue = wrappedValue } } #endif diff --git a/Sources/Core/PropertyWrapper.swift b/Sources/Core/PropertyWrapper.swift index ebc4c825..e7210eaf 100644 --- a/Sources/Core/PropertyWrapper.swift +++ b/Sources/Core/PropertyWrapper.swift @@ -5,22 +5,45 @@ protocol CustomResolvable { init(resolver: Resolver, request: AnyInstanceRequest) static func requiredRequest(for request: InstanceRequestDescriptor) -> InstanceRequestDescriptor? + static var delaysResolution: Bool { get } } -protocol PropertyWrapper: CustomResolvable { +protocol AnyPropertyWrapper: CustomResolvable { + associatedtype Value +} + +protocol PropertyWrapper: AnyPropertyWrapper { + associatedtype Value + init(wrappedValue: Value) +} + +protocol DelayedPropertyWrapper: AnyPropertyWrapper { associatedtype Value init(wrappedValue: @autoclosure @escaping () -> Value) } +extension AnyPropertyWrapper { + static func requiredRequest(for request: InstanceRequestDescriptor) -> InstanceRequestDescriptor? { + return request.replacingType(with: Value.self) + } +} + extension PropertyWrapper { init(resolver: Resolver, request: AnyInstanceRequest) { // swiftlint:disable:next force_try self.init(wrappedValue: try! resolver.resolve(request.replacingType(with: Value.self))) } - static func requiredRequest(for request: InstanceRequestDescriptor) -> InstanceRequestDescriptor? { - return request.replacingType(with: Value.self) + static var delaysResolution: Bool { return false } +} + +extension DelayedPropertyWrapper { + init(resolver: Resolver, request: AnyInstanceRequest) { + // swiftlint:disable:next force_try + self.init(wrappedValue: try! resolver.resolve(request.replacingType(with: Value.self))) } + + static var delaysResolution: Bool { return true } } extension AnyInstanceRequest { @@ -49,4 +72,6 @@ extension Optional: CustomResolvable { static func requiredRequest(for _: InstanceRequestDescriptor) -> InstanceRequestDescriptor? { return nil } + + static var delaysResolution: Bool { return false } } diff --git a/Sources/Core/Swinject.swift b/Sources/Core/Swinject.swift index 0c3307ff..06dafd3e 100644 --- a/Sources/Core/Swinject.swift +++ b/Sources/Core/Swinject.swift @@ -44,8 +44,10 @@ extension Swinject { private func customResolve(_ request: InstanceRequest) -> Type? { guard let custom = Type.self as? CustomResolvable.Type else { return nil } guard container.hasBinding(for: request.descriptor, on: contextType) else { return nil } - // TODO: We should reset tracking only for "delayed" custom resolutions - return custom.init(resolver: with(stack: []), request: request) as? Type + return custom.init( + resolver: custom.delaysResolution ? with(stack: []) : self, + request: request + ) as? Type } private func tracking(_ request: AnyInstanceRequest) throws -> Swinject { diff --git a/Tests/3.0 API/PropertyWrappersSpec.swift b/Tests/3.0 API/PropertyWrappersSpec.swift index 90143069..068679d0 100644 --- a/Tests/3.0 API/PropertyWrappersSpec.swift +++ b/Tests/3.0 API/PropertyWrappersSpec.swift @@ -11,8 +11,8 @@ class PropertyWrappersSpec: QuickSpec { override func spec() { #if swift(>=5.1) @propertyWrapper struct Wrapped: PropertyWrapper { var wrappedValue: Value - public init(wrappedValue: @autoclosure () -> Value) { - self.wrappedValue = wrappedValue() + public init(wrappedValue: Value) { + self.wrappedValue = wrappedValue } } it("can inject wrapped provider of a bound type") {