Reputation: 599
I have mainAssembly
:
final class ApplicationAssembly {
var assembler: Assembler
init(with assemblies: [Assembly]) {
self.assembler = Assembler(assemblies)
}
}
With two module for example:
var applicationAssembly = ApplicationAssembly(with: [ProfileAssembly(), StoriesAssembly()])
window?.rootViewController = applicationAssembly.assembler.resolver.resolve(ProfileViewController.self)
Here is ProfileAssembly
:
import Swinject
class ProfileAssembly: Assembly {
func assemble(container: Container) {
container.register(ProfileInteractorInput.self) { (r, presenter: ProfilePresenter) in
let interactor = ProfileInteractor()
interactor.output = presenter
return interactor
}
container.register(ProfilePresenterInput.self){ (r, viewController: ProfileViewController) in
let presenter = ProfilePresenter()
presenter.output = viewController
presenter.interactor = r.resolve(ProfileInteractorInput.self, argument: presenter)
presenter.router = r.resolve(ProfileRouterInput.self, argument: viewController)
return presenter
}
container.register(ProfileRouterInput.self) { (r, viewController: ProfileViewController) in
let router = ProfileRouter()
router.viewController = viewController
return router
}
container.register(ProfileViewController.self) { r in
let viewController = ProfileViewController()
viewController.presenter = r.resolve(ProfilePresenterInput.self, argument: viewController)
return viewController
}
}
}
Everything works fine, however i don't know how to configure my router to navigate to another module:
protocol ProfileRouterInput: class {
func openStories()
}
class ProfileRouter: ProfileRouterInput {
weak var viewController: UIViewController?
func openStories() {
}
}
Before Swinject I've used wireframes where I had something like build()
function to return specific VC. But since my assemblies are in the main Assembler container, should I have a direct access from any routers in my app to the main assembler?
Upvotes: 1
Views: 594