I have ModuleA
which defines the following class:
open class StatisticsManager<DealOptions> where DealOptions: Hashable {
open func update(dealOptions: DealOptions) {
fatalError("Implement in a derived class")
}
// Some other public methods which does not need to be overwritten in a derived class
}
In the same module I have other generic classes (most of them are UIViewControllers) which work with StatisticsManager
. For example:
public class StatisticsViewController<DealOptions: Hashable> : UIViewController {
private var statisticsManager: StatisticsManager<DealOptions>!
public static func create(statisticsManager: StatisticsManager<DealOptions>) -> StatisticsViewController<DealOptions> {
let viewController = StatisticsViewController<DealOptions>()
viewController.statisticsManager = statisticsManager
return viewController
}
// Some methods working with statisticsManager
}
So here I use explicit dependency injection to pass the statisticsManager
to the view controller itself. However this is very tedious because I have a bunch of such generic classes and passing them as arguments of each create
method is not convenient.
How I can create (or use) simple dependency injection framework where I can register all my dependencies and use them here instead of providing them as arguments?
I have tried Factory framework but I do not know how can register generic class as dependency.
1