This repository has been archived by the owner on Jan 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathApplicationAssembly.swift
135 lines (98 loc) · 4.88 KB
/
ApplicationAssembly.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
////////////////////////////////////////////////////////////////////////////////
//
// TYPHOON FRAMEWORK
// Copyright 2013, Typhoon Framework Contributors
// All Rights Reserved.
//
// NOTICE: The authors permit you to use, modify, and distribute this file
// in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////
public class ApplicationAssembly: TyphoonAssembly {
//-------------------------------------------------------------------------------------------
// MARK: - Bootstrapping
//-------------------------------------------------------------------------------------------
/*
* These are modules - assemblies collaborate to provie components to this one. At runtime you
* can instantiate Typhoon with any assembly tha satisfies the module interface.
*/
public var coreComponents: CoreComponents!
public var themeAssembly: ThemeAssembly!
/*
* This is the definition for our AppDelegate. Typhoon will inject the specified properties
* at application startup.
*/
public dynamic func appDelegate() -> AnyObject {
return TyphoonDefinition.withClass(AppDelegate.self) {
definition in
definition!.injectProperty("cityDao", with: self.coreComponents.cityDao())
definition!.injectProperty("rootViewController", with: self.rootViewController())
} as AnyObject
}
/*
* A config definition, referencing properties that will be loaded from a plist.
*/
public dynamic func config() -> AnyObject {
return TyphoonDefinition.configDefinition(withName: "Configuration.plist")
}
//-------------------------------------------------------------------------------------------
// MARK: - Main Assembly
//-------------------------------------------------------------------------------------------
public dynamic func rootViewController() -> AnyObject {
return TyphoonDefinition.withClass(RootViewController.self) {
definition in
definition!.useInitializer("initWithMainContentViewController:assembly:") {
initializer in
initializer!.injectParameter(with: self.weatherReportController())
initializer!.injectParameter(with: self)
}
definition!.scope = TyphoonScope.singleton
} as AnyObject
}
public dynamic func citiesListController() -> AnyObject {
return TyphoonDefinition.withClass(CitiesListViewController.self) {
definition in
definition!.useInitializer("initWithCityDao:theme:") {
initializer in
initializer!.injectParameter(with: self.coreComponents.cityDao())
initializer!.injectParameter(with: self.themeAssembly.currentTheme())
}
definition!.injectProperty("assembly")
} as AnyObject
}
public dynamic func weatherReportController() -> AnyObject {
return TyphoonDefinition.withClass(WeatherReportViewController.self) {
definition in
definition!.useInitializer("initWithView:weatherClient:weatherReportDao:cityDao:assembly:") {
initializer in
initializer!.injectParameter(with: self.weatherReportView())
initializer!.injectParameter(with: self.coreComponents.weatherClient())
initializer!.injectParameter(with: self.coreComponents.weatherReportDao())
initializer!.injectParameter(with: self.coreComponents.cityDao())
initializer!.injectParameter(with: self)
}
} as AnyObject
}
public dynamic func weatherReportView() -> AnyObject {
return TyphoonDefinition.withClass(WeatherReportView.self) {
definition in
definition!.injectProperty("theme", with: self.themeAssembly.currentTheme())
} as AnyObject
}
public dynamic func addCityViewController() -> AnyObject {
return TyphoonDefinition.withClass(AddCityViewController.self) {
definition in
// TODO: Seems sub-class MUST override this initializer otherwise it can't be
// TODO: invoked in RELEASE configuration. Bug?
definition!.useInitializer("initWithNibName:bundle:") {
initializer in
initializer!.injectParameter(with: "AddCity")
initializer!.injectParameter(with: Bundle.main)
}
definition!.injectProperty("cityDao", with: self.coreComponents.cityDao())
definition!.injectProperty("weatherClient", with: self.coreComponents.weatherClient())
definition!.injectProperty("theme", with: self.themeAssembly.currentTheme())
definition!.injectProperty("rootViewController", with: self.rootViewController())
} as AnyObject
}
}