diff --git a/Scripts/gencode b/Scripts/gencode index e989c98..46f6a64 100755 --- a/Scripts/gencode +++ b/Scripts/gencode @@ -1,10 +1,10 @@ #!/bin/sh -# This script is similar to Swinject's gencode script. +# This script is based on Swinject's gencode script. # It generates high-arity overloads of generic functions using the file templates listed below. # The generated files are checked in since they are not dynamic and don't change often. -files="Sources/Knit/ServiceCollection/Container+ServiceCollection" +files="Sources/Knit/ServiceCollection/Container+ServiceCollection Sources/Swinject/Container.Arguments Sources/Swinject/Resolver Sources/Swinject/ServiceEntry.TypeForwarding" for file in $files; do echo "Generating code to $file.swift" diff --git a/Sources/Swinject/Container.Arguments.erb b/Sources/Swinject/Container.Arguments.erb index 74bc0bd..e4b5d51 100644 --- a/Sources/Swinject/Container.Arguments.erb +++ b/Sources/Swinject/Container.Arguments.erb @@ -1,7 +1,4 @@ // -// Container.Arguments.swift -// Swinject -// // Created by Yoichi Tagaya on 8/18/15. // Copyright © 2015 Swinject Contributors. All rights reserved. // @@ -11,7 +8,7 @@ // // 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. +// Instead, modify Container.Arguments.erb and run `Scripts/gencode` at the project root directory to generate the code. // <% arg_count = 9 %> @@ -19,6 +16,7 @@ import Foundation // MARK: - Registration with Arguments + extension Container { <% (1..arg_count).each do |i| %> <% arg_types = (1..i).map { |n| "Arg#{n}" }.join(", ") %> @@ -39,8 +37,8 @@ extension Container { public func register>( _ serviceType: Service.Type, name: String? = nil, - factory: @escaping (Resolver, <%= arg_types %>) -> Service) -> ServiceEntry - { + factory: @escaping (Resolver, <%= arg_types %>) -> Service + ) -> ServiceEntry { return _register(serviceType, factory: factory, name: name) } @@ -48,6 +46,7 @@ extension Container { } // MARK: - Resolver with Arguments + extension Container { <% (1..arg_count).each do |i| %> <% arg_types = (1..i).map { |n| "Arg#{n}" }.join(", ") %> diff --git a/Sources/Swinject/Container.Arguments.swift b/Sources/Swinject/Container.Arguments.swift index 6c5554f..a27e470 100644 --- a/Sources/Swinject/Container.Arguments.swift +++ b/Sources/Swinject/Container.Arguments.swift @@ -1,5 +1,6 @@ // -// Copyright © 2019 Swinject Contributors. All rights reserved. +// Created by Yoichi Tagaya on 8/18/15. +// Copyright © 2015 Swinject Contributors. All rights reserved. // // @@ -7,9 +8,10 @@ // // 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. +// Instead, modify Container.Arguments.erb and run `Scripts/gencode` at the project root directory to generate the code. // + import Foundation // MARK: - Registration with Arguments @@ -22,11 +24,11 @@ extension Container { /// - 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, + /// 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. + /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register( _ serviceType: Service.Type, @@ -43,11 +45,11 @@ extension Container { /// - 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, + /// 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. + /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register( _ serviceType: Service.Type, @@ -64,11 +66,11 @@ extension Container { /// - 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, + /// 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. + /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register( _ serviceType: Service.Type, @@ -85,11 +87,11 @@ extension Container { /// - 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, + /// 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. + /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register( _ serviceType: Service.Type, @@ -106,11 +108,11 @@ extension Container { /// - 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, + /// 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. + /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register( _ serviceType: Service.Type, @@ -127,11 +129,11 @@ extension Container { /// - 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, + /// 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. + /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register( _ serviceType: Service.Type, @@ -148,11 +150,11 @@ extension Container { /// - 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, + /// 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. + /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register( _ serviceType: Service.Type, @@ -169,11 +171,11 @@ extension Container { /// - 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, + /// 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. + /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register( _ serviceType: Service.Type, @@ -190,11 +192,11 @@ extension Container { /// - 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, + /// 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. + /// - Returns: A registered `ServiceEntry` to configure more settings with method chaining. @discardableResult public func register( _ serviceType: Service.Type, @@ -203,6 +205,7 @@ extension Container { ) -> ServiceEntry { return _register(serviceType, factory: factory, name: name) } + } // MARK: - Resolver with Arguments @@ -215,11 +218,11 @@ extension Container { /// - 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``. + /// and 1 argument is found in the `Container`. public func resolve( _ serviceType: Service.Type, - argument: Arg1 - ) -> Service? { + argument: Arg1) -> Service? + { return resolve(serviceType, name: nil, argument: argument) } @@ -231,12 +234,12 @@ extension Container { /// - 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``. + /// 1 argument and name is found in the `Container`. public func resolve( - _: Service.Type, + _ serviceType: Service.Type, name: String?, - argument: Arg1 - ) -> Service? { + argument: Arg1) -> Service? + { typealias FactoryType = ((Resolver, Arg1)) -> Any return _resolve(name: name) { (factory: FactoryType) in factory((self, argument)) } } @@ -248,11 +251,11 @@ extension Container { /// - 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``. + /// and list of 2 arguments is found in the `Container`. public func resolve( _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2 - ) -> Service? { + arguments arg1: Arg1, _ arg2: Arg2) -> Service? + { return resolve(serviceType, name: nil, arguments: arg1, arg2) } @@ -264,12 +267,12 @@ extension Container { /// - 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``. + /// list of 2 arguments and name is found in the `Container`. public func resolve( - _: Service.Type, + _ serviceType: Service.Type, name: String?, - arguments arg1: Arg1, _ arg2: Arg2 - ) -> Service? { + arguments arg1: Arg1, _ arg2: Arg2) -> Service? + { typealias FactoryType = ((Resolver, Arg1, Arg2)) -> Any return _resolve(name: name) { (factory: FactoryType) in factory((self, arg1, arg2)) } } @@ -281,11 +284,11 @@ extension Container { /// - 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``. + /// and list of 3 arguments is found in the `Container`. public func resolve( _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3 - ) -> Service? { + arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> Service? + { return resolve(serviceType, name: nil, arguments: arg1, arg2, arg3) } @@ -297,12 +300,12 @@ extension Container { /// - 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``. + /// list of 3 arguments and name is found in the `Container`. public func resolve( - _: Service.Type, + _ serviceType: Service.Type, name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3 - ) -> Service? { + 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)) } } @@ -314,11 +317,11 @@ extension Container { /// - 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``. + /// 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? { + arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> Service? + { return resolve(serviceType, name: nil, arguments: arg1, arg2, arg3, arg4) } @@ -330,12 +333,12 @@ extension Container { /// - 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``. + /// list of 4 arguments and name is found in the `Container`. public func resolve( - _: Service.Type, + _ serviceType: Service.Type, name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4 - ) -> Service? { + 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)) } } @@ -347,11 +350,11 @@ extension Container { /// - 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``. + /// 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? { + arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5) -> Service? + { return resolve(serviceType, name: nil, arguments: arg1, arg2, arg3, arg4, arg5) } @@ -363,12 +366,12 @@ extension Container { /// - 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``. + /// list of 5 arguments and name is found in the `Container`. public func resolve( - _: Service.Type, + _ serviceType: Service.Type, name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5 - ) -> Service? { + 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)) } } @@ -380,11 +383,11 @@ extension Container { /// - 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``. + /// 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? { + 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) } @@ -396,12 +399,12 @@ extension Container { /// - 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``. + /// list of 6 arguments and name is found in the `Container`. public func resolve( - _: Service.Type, + _ serviceType: Service.Type, name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6 - ) -> Service? { + 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)) } } @@ -413,11 +416,11 @@ extension Container { /// - 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``. + /// 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? { + 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) } @@ -429,12 +432,12 @@ extension Container { /// - 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``. + /// list of 7 arguments and name is found in the `Container`. public func resolve( - _: Service.Type, + _ serviceType: Service.Type, name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7 - ) -> Service? { + 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)) } } @@ -446,11 +449,11 @@ extension Container { /// - 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``. + /// 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? { + 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) } @@ -462,12 +465,12 @@ extension Container { /// - 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``. + /// list of 8 arguments and name is found in the `Container`. public func resolve( - _: Service.Type, + _ serviceType: Service.Type, name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8 - ) -> Service? { + 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)) } } @@ -479,11 +482,11 @@ extension Container { /// - 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``. + /// 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? { + 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) } @@ -495,13 +498,14 @@ extension Container { /// - 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``. + /// list of 9 arguments and name is found in the `Container`. public func resolve( - _: Service.Type, + _ 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? { + 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/Swinject/Resolver.erb b/Sources/Swinject/Resolver.erb index 0eeb036..49cbe43 100644 --- a/Sources/Swinject/Resolver.erb +++ b/Sources/Swinject/Resolver.erb @@ -1,9 +1,6 @@ // -// Resolver.swift -// Swinject -// // Created by Yoichi Tagaya on 8/18/15. -// Copyright (c) 2015 Swinject Contributors. All rights reserved. +// Copyright © 2019 Swinject Contributors. All rights reserved. // // @@ -11,7 +8,7 @@ // // 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. +// Instead, modify Resolver.erb and run `Scripts/gencode` at the project root directory to generate the code. // <% arg_count = 9 %> diff --git a/Sources/Swinject/Resolver.swift b/Sources/Swinject/Resolver.swift index 8bc5558..4d60790 100644 --- a/Sources/Swinject/Resolver.swift +++ b/Sources/Swinject/Resolver.swift @@ -1,4 +1,5 @@ // +// Created by Yoichi Tagaya on 8/18/15. // Copyright © 2019 Swinject Contributors. All rights reserved. // @@ -6,10 +7,11 @@ // 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. +// Do NOT modify Container.Arguments.swift directly. +// Instead, modify Resolver.erb and run `Scripts/gencode` at the project root directory to generate the code. // + public protocol Resolver { /// Retrieves the instance with the specified service type. /// @@ -37,8 +39,7 @@ public protocol Resolver { /// and 1 argument is found. func resolve( _ serviceType: Service.Type, - argument: Arg1 - ) -> Service? + argument: Arg1) -> Service? /// Retrieves the instance with the specified service type, 1 argument to the factory closure and registration name. /// @@ -52,8 +53,7 @@ public protocol Resolver { func resolve( _ serviceType: Service.Type, name: String?, - argument: Arg1 - ) -> Service? + argument: Arg1) -> Service? /// Retrieves the instance with the specified service type and list of 2 arguments to the factory closure. /// @@ -65,8 +65,7 @@ public protocol Resolver { /// and list of 2 arguments is found. func resolve( _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2 - ) -> Service? + 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. /// @@ -80,8 +79,7 @@ public protocol Resolver { func resolve( _ serviceType: Service.Type, name: String?, - arguments arg1: Arg1, _ arg2: Arg2 - ) -> Service? + arguments arg1: Arg1, _ arg2: Arg2) -> Service? /// Retrieves the instance with the specified service type and list of 3 arguments to the factory closure. /// @@ -93,8 +91,7 @@ public protocol Resolver { /// and list of 3 arguments is found. func resolve( _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3 - ) -> Service? + 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. /// @@ -108,8 +105,7 @@ public protocol Resolver { func resolve( _ serviceType: Service.Type, name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3 - ) -> Service? + 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. /// @@ -121,8 +117,7 @@ public protocol Resolver { /// and list of 4 arguments is found. func resolve( _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4 - ) -> Service? + 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. /// @@ -136,8 +131,7 @@ public protocol Resolver { func resolve( _ serviceType: Service.Type, name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4 - ) -> Service? + 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. /// @@ -149,8 +143,7 @@ public protocol Resolver { /// and list of 5 arguments is found. func resolve( _ serviceType: Service.Type, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5 - ) -> Service? + 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. /// @@ -164,8 +157,7 @@ public protocol Resolver { func resolve( _ serviceType: Service.Type, name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5 - ) -> Service? + 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. /// @@ -177,8 +169,7 @@ public protocol Resolver { /// 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? + 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. /// @@ -192,8 +183,7 @@ public protocol Resolver { func resolve( _ serviceType: Service.Type, name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6 - ) -> Service? + 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. /// @@ -205,8 +195,7 @@ public protocol Resolver { /// 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? + 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. /// @@ -220,8 +209,7 @@ public protocol Resolver { func resolve( _ serviceType: Service.Type, name: String?, - arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7 - ) -> Service? + 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. /// @@ -233,8 +221,7 @@ public protocol Resolver { /// 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? + 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. /// @@ -248,8 +235,7 @@ public protocol Resolver { 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? + 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. /// @@ -261,8 +247,7 @@ public protocol Resolver { /// 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? + 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. /// @@ -276,6 +261,7 @@ public protocol Resolver { 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? + arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8, _ arg9: Arg9) -> Service? + + } diff --git a/Sources/Swinject/ServiceEntry.TypeForwarding.erb b/Sources/Swinject/ServiceEntry.TypeForwarding.erb index 6ea8169..d95a7f4 100644 --- a/Sources/Swinject/ServiceEntry.TypeForwarding.erb +++ b/Sources/Swinject/ServiceEntry.TypeForwarding.erb @@ -1,9 +1,6 @@ // -// ServiceEntry.TypeForwarding.swift -// Swinject-iOS -// // Created by Jakub Vaňo on 16/02/2018. -// Copyright © 2018 Swinject Contributors. All rights reserved. +// Copyright © 2019 Swinject Contributors. All rights reserved. // // @@ -11,7 +8,7 @@ // // 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. +// Instead, modify ServiceEntry.TypeForwarding.erb and run `Scripts/gencode` at the project root directory to generate the code. // <% type_count = 9 %> @@ -40,8 +37,8 @@ extension ServiceEntry { @discardableResult public func implements<<%= types %>>(<%= params %>) -> ServiceEntry { return self<% (1..i).each do |k| %>.implements(type<%= k %>)<% end %> - + } - + <% end %> } diff --git a/Sources/Swinject/ServiceEntry.TypeForwarding.swift b/Sources/Swinject/ServiceEntry.TypeForwarding.swift index 82297b6..faf6019 100644 --- a/Sources/Swinject/ServiceEntry.TypeForwarding.swift +++ b/Sources/Swinject/ServiceEntry.TypeForwarding.swift @@ -1,4 +1,5 @@ // +// Created by Jakub Vaňo on 16/02/2018. // Copyright © 2019 Swinject Contributors. All rights reserved. // @@ -7,9 +8,10 @@ // // 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. +// Instead, modify ServiceEntry.TypeForwarding.erb and run `Scripts/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 @@ -30,7 +32,7 @@ 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, @@ -40,7 +42,7 @@ 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, @@ -50,7 +52,7 @@ 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, @@ -60,7 +62,7 @@ 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, @@ -70,7 +72,7 @@ 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, @@ -80,7 +82,7 @@ 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, @@ -90,7 +92,7 @@ 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, @@ -100,6 +102,7 @@ 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) } + }