Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need a way to know when all dependencies are resolved #56

Closed
sebastian-zarzycki-apzumi opened this issue Mar 10, 2016 · 14 comments · Fixed by #57
Closed

Need a way to know when all dependencies are resolved #56

sebastian-zarzycki-apzumi opened this issue Mar 10, 2016 · 14 comments · Fixed by #57

Comments

@sebastian-zarzycki-apzumi

Most solid IoC containers provide some form of notification after the object that has some dependencies, has the dependencies resolved.

If I set up my dependencies like so:

container = DependencyContainer { container in
  container.register(.Singleton) { LoginService() }
  container.register(.Singleton) { LoginModel() } .resolveDependencies { container, entity in
     entity.loginService = try! container.resolve() as LoginService
  }
}

I need a way to determine within Login Model when loginService is resolved in, because I might need to instantly operate on it for some reason. I cannot do this in initializer, because loginService isn't injected yet. In theory, I could call a method within the resolveDependencies block, but that doesn't feel like an elegant solution. Does Dip provide/could provide something like this?

@ilyapuchka
Copy link
Collaborator

Hi, @sebastian-zarzycki-es . Sure, you can do it right away inside resolveDependencies.
If you mean a callback after all dependencies were resolved (equal to calling your method at the end of resolveDependencies) it will be very trivial to implement such a protocol, like DipResolvable (or something) and have such callbacks. Fell free to make a PR 😉

@sebastian-zarzycki-apzumi
Copy link
Author

I wish I could help, but while I'm no stranger to DI/IoC concepts, I'm coming from different environments (mainly Flex and AngularJS) and I don't feel proficient enough in Swift at the moment, to contribute. But yes, I was thinking about such protocol, like you've described. I'd greatly appreciate such addition. From my evaluation, Dip is the best DI solution for Swift there is on the market atm (I didn't like Swinject or Typhoon that much).

@ilyapuchka
Copy link
Collaborator

Ok, will add it in the next version 🙇

@sebastian-zarzycki-apzumi
Copy link
Author

Awesome!

@ilyapuchka
Copy link
Collaborator

@sebastian-zarzycki-es this feature is released with 4.3.0 - check out =)

@sebastian-zarzycki-apzumi
Copy link
Author

Great stuff, thanks!

@sebastian-zarzycki-apzumi
Copy link
Author

Hmm, @ilyapuchka , seems like I cannot pull 4.3.0 from cocoa pods if I have DipUI listed in pods as well. Apparently DipUI still targets 4.1.0, which prevents pods from getting 4.3.0. I know it's not the right place to ask as it's unrelated, but can someone look into this?

@ilyapuchka
Copy link
Collaborator

@sebastian-zarzycki-es Thanks for noticing! Will fix Dip-UI pod spec and update it.

@sebastian-zarzycki-apzumi
Copy link
Author

For some reason, it doesn't work for me. I've updated it from pods now, it says it's 4.3.0 and I can see the public protocol declared in code, but if I use it, it says the protocol cannot be found (even if I use import Dip). Not sure why.

@ilyapuchka ilyapuchka reopened this Mar 20, 2016
@ilyapuchka
Copy link
Collaborator

Have you tried to deep clean project? Shift+Cmd+Alt+K and Shift+Cmd+K.

@sebastian-zarzycki-apzumi
Copy link
Author

That actually worked, thanks! I didn't know about this. One last think I've noticed is that DipUI got it's version reverted from 0.0.2 (as it was before in cocoapods) to 0.0.1 - was that intentional?

@ilyapuchka
Copy link
Collaborator

No, in fact it was bumped to 0.1.0

@sebastian-zarzycki-apzumi
Copy link
Author

Ah, got it. Ok, I guess we can finally close this now :)

@ilyapuchka
Copy link
Collaborator

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants