-
Notifications
You must be signed in to change notification settings - Fork 2
Modularizing Assemblies
In a complex app a single assembly file can become complicated or unwieldy. They can be modularized where we group components together in some logical fashion.
This can be done as follows:
class ApplicationAssembly: PilgrimAssembly, ControllerProvider {
var config: ApplicationConfig { ConfigProvider.shared }
let daemons = AssemblyHolder.shared(DaemonAssembly.self)
let services = AssemblyHolder.shared(ServiceAssembly.self)
let repos = AssemblyHolder.shared(RepositoryAssembly.self)
}
Now the top-level application assembly can pull in components from the lower level assemblies. In general it is recommended to layer as follows:
A good rule of thumb is for abstraction to layered, with higher levels having visibility of the layers below, however you can define circular dependencies (lower layer can refer to higher level components). It might be necessary to mark one side as lazy, like this:
class ServiceAssembly: PilgrimAssembly {
var config: ApplicationConfig { ConfigProvider.shared }
lazy var assembly = AssemblyHolder.shared(ApplicationAssembly.self)
}
Something still not clear? How about posting a question on StackOverflow.
Get started in two minutes.
Get familiar with Pilgrim.
Become a Pilgrim expert.
For contributors or curious folks.