0001    //
0002    //  Assembler.swift
0003    //  Swinject
0004    //
0005    //  Created by mike.owens on 12/9/15.
0006    //  Copyright © 2015 Swinject Contributors. All rights reserved.
0007    //
0008    
0009    
0010    /// The `Assembler` provides a means to build a container via `AssemblyType` instances.
0011    public class Assembler
Assembler.swift:33
    public init(parentAssembler: Assembler?) {
Assembler.swift:59
    public init(assemblies: [AssemblyType], parentAssembler: Assembler?, propertyLoaders: [PropertyLoaderType]? = nil) throws {
{ 0012 0013 /// the container that each assembly will build its `Service` definitions into 0014 private let container
Assembler.swift:18
        return container
Assembler.swift:26
        self.container = container!
Assembler.swift:34
        container = Container(parent: parentAssembler?.container)
Assembler.swift:34
        container = Container(parent: parentAssembler?.container)
Assembler.swift:44
        self.container = container!
Assembler.swift:47
                try self.container.applyPropertyLoader(propertyLoader)
Assembler.swift:60
        container = Container(parent: parentAssembler?.container)
Assembler.swift:60
        container = Container(parent: parentAssembler?.container)
Assembler.swift:63
                try self.container.applyPropertyLoader(propertyLoader)
Assembler.swift:102
        try self.container.applyPropertyLoader(propertyLoader)
Assembler.swift:110
            assembly.assemble(self.container)
: Container 0015 0016 /// expose the container as a resolver so `Service` registration only happens within an assembly 0017 public var resolver
Assembler.swift:115
            assembly.loaded(self.resolver)
: ResolverType { 0018 return container 0019 } 0020 0021 /// Will create an empty `Assembler` 0022 /// 0023 /// - parameter container: the baseline container 0024 /// 0025 public init(container: Container? = Container()) { 0026 self.container = container! 0027 } 0028 0029 /// Will create an empty `Assembler` 0030 /// 0031 /// - parameter parentAssembler: the baseline assembler 0032 /// 0033 public init(parentAssembler: Assembler?) { 0034 container = Container(parent: parentAssembler?.container) 0035 } 0036 0037 /// Will create a new `Assembler` with the given `AssemblyType` instances to build a `Container` 0038 /// 0039 /// - parameter assemblies: the list of assemblies to build the container from 0040 /// - parameter propertyLoaders: a list of property loaders to apply to the container 0041 /// - parameter container: the baseline container 0042 /// 0043 public init(assemblies: [AssemblyType], propertyLoaders: [PropertyLoaderType]? = nil, container: Container? = Container()) throws { 0044 self.container = container! 0045 if let propertyLoaders = propertyLoaders { 0046 for propertyLoader in propertyLoaders { 0047 try self.container.applyPropertyLoader(propertyLoader) 0048 } 0049 } 0050 runAssemblies(assemblies) 0051 } 0052 0053 /// Will create a new `Assembler` with the given `AssemblyType` instances to build a `Container` 0054 /// 0055 /// - parameter assemblies: the list of assemblies to build the container from 0056 /// - parameter parentAssembler: the baseline assembler 0057 /// - parameter propertyLoaders: a list of property loaders to apply to the container 0058 /// 0059 public init(assemblies: [AssemblyType], parentAssembler: Assembler?, propertyLoaders: [PropertyLoaderType]? = nil) throws { 0060 container = Container(parent: parentAssembler?.container) 0061 if let propertyLoaders = propertyLoaders { 0062 for propertyLoader in propertyLoaders { 0063 try self.container.applyPropertyLoader(propertyLoader) 0064 } 0065 } 0066 runAssemblies(assemblies) 0067 } 0068 0069 /// Will apply the assembly to the container. This is useful if you want to lazy load an assembly into the assembler's 0070 /// container. 0071 /// 0072 /// If this assembly type is load aware, the loaded hook will be invoked right after the container has assembled 0073 /// since after each call to `addAssembly` the container is fully loaded in its current state. If you wish to 0074 /// lazy load several assemblies that have interdependencies between each other use `appyAssemblies` 0075 /// 0076 /// - parameter assembly: the assembly to apply to the container 0077 /// 0078 public func applyAssembly(assembly: AssemblyType) { 0079 runAssemblies([assembly]) 0080 } 0081 0082 /// Will apply the assemblies to the container. This is useful if you want to lazy load several assemblies into the assembler's 0083 /// container 0084 /// 0085 /// If this assembly type is load aware, the loaded hook will be invoked right after the container has assembled 0086 /// since after each call to `addAssembly` the container is fully loaded in its current state. 0087 /// 0088 /// - parameter assemblies: the assemblies to apply to the container 0089 /// 0090 public func applyAssemblies(assemblies: [AssemblyType]) { 0091 runAssemblies(assemblies) 0092 } 0093 0094 /// Will apply a property loader to the container. This is useful if you want to lazy load your assemblies or build 0095 /// your assembler manually 0096 /// 0097 /// - parameter propertyLoader: the property loader to apply to the assembler's container 0098 /// 0099 /// - throws: PropertyLoaderError 0100 /// 0101 public func applyPropertyLoader(propertyLoader: PropertyLoaderType) throws { 0102 try self.container.applyPropertyLoader(propertyLoader) 0103 } 0104 0105 // MARK: Private 0106 0107 private func runAssemblies
Assembler.swift:50
        runAssemblies(assemblies)
Assembler.swift:66
        runAssemblies(assemblies)
Assembler.swift:79
        runAssemblies([assembly])
Assembler.swift:91
        runAssemblies(assemblies)
(assemblies: [AssemblyType]) { 0108 // build the container from each assembly 0109 for assembly in assemblies { 0110 assembly.assemble(self.container) 0111 } 0112 0113 // inform all of the assemblies that the container is loaded 0114 for assembly in assemblies { 0115 assembly.loaded(self.resolver) 0116 } 0117 } 0118 } 0119