Skip to content

Modularizing Assemblies

Jasper Blues edited this page Jun 22, 2021 · 3 revisions

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)

}

Quick Start!

Get started in two minutes.

Main Track

Get familiar with Pilgrim.

Advanced Topics

Become a Pilgrim expert.

Under the Hood

For contributors or curious folks.

Clone this wiki locally