Closed njall1 closed 7 years ago
Move rootAssembly to Application delegate class. It will fix the most of problems.
I checked this way and it has not helped.
import Dip
class AppDelegate: UIResponder, UIApplicationDelegate, AppDelegateInput {
var window: UIWindow?
var serviceLocator: ServiceLocator?
var output: AppDelegateOutput?
var moduleInput: RootModuleInput?
// let container: DependencyContainer = rootAssembly
let container = DependencyContainer { (container) in
unowned let container = container
container.register(.weakSingleton) { RootPresenter() }
.implements(AnyObject.self,
RootModuleInput.self,
AppDelegateOutput.self,
RootInteractorOutput.self)
.resolvingProperties { container, presenter in
presenter.delegate = UIApplication.shared.delegate as! AppDelegate
presenter.router = try! container.resolve()
presenter.interactor = try! container.resolve()
presenter.deeplinkHandler = try! container.resolve()
presenter.shortcutHandler = try! container.resolve()
}
...
Can you please state the problem more clear? What is expected, what is actual behaviour?
Expected: If you register a class with the scope: weakSingleton, there must be one instance of this class in memory.
Actual behaviour: I've registered class with scope: weakSingleton
let container = DependencyContainer { (container) in
unowned let container = container
container.register(.weakSingleton) { RootPresenter() }
.implements(AnyObject.self,
RootModuleInput.self,
AppDelegateOutput.self,
RootInteractorOutput.self)
.resolvingProperties { container, presenter in
presenter.delegate = UIApplication.shared.delegate as! AppDelegate
presenter.router = try! container.resolve()
presenter.interactor = try! container.resolve()
presenter.deeplinkHandler = try! container.resolve()
presenter.shortcutHandler = try! container.resolve()
}
...
But in memory app has 5 instances of this class.
Please provide any solution!
@njall1 unfortunately I can not understand what the issue can be from your code snippets. If you can submit a failing test this will really help.
Registering classes have memory issue:
or
or
I've fixed issue by this way:
or
Also issue actual for scopes : shared, singleton, eagerSingleton, weakSingleton.
Please provide any solution, because for me very important registering classes not protocols.