Injecting a controller into another controller

184 Views Asked by At

I have a controller that receives an event with some data. As a part of the processing this s new data it needs to modify a collection in another controller. Is it a bad idea to inject a controller into another controller to modify this collection?

2

There are 2 best solutions below

0
On

I'm not too familiar with Swiz, however in other frameworks if you needed to have another 'controller' do something after a result, it would dispatch an event that the second controller is listening for giving it the data it needs.

8
On

I don't really understand what you mean by "a collection in another controller", but IMHO your collection should be in the model. Your first controller modifies the collection in the model which dispatches an event caught by the second controller.