square / mortar

A simple library that makes it easy to pair thin views with dedicated controllers, isolated from most of the vagaries of the Activity life cycle.
Apache License 2.0
2.16k stars 156 forks source link

fix(MortarScope) use application context in MortarScope#getScope() #141

Closed DmitriyZaitsev closed 9 years ago

DmitriyZaitsev commented 9 years ago

Hi! I suggest to use application context in MortarScope.getScope(). In our activities we call MortarScope.findChild(context) and MortarScope.buildChild(context). Every time we must pass the getApplicationContext() as a parameter. I found that if developer forgets about it and accidentally passes this (current Activity instance), he'll get the StackOverflowException because of recursive function call. To avoid this I propose my solution that ensures we'll always have correct context for getting system service by name.

almozavr commented 9 years ago

Isn't it breaking service-to-context-binding and sometimes (I'm looking at Dagger) those service hierarchy?

ApplicationContext -> RootComponent as 'DaggerService'
  ActivityContext -> ActivityComponent extends RootComponent as 'DaggerService'
    ViewContext -> ViewComponent extends ActivityComponent as 'DaggerService'
DmitriyZaitsev commented 9 years ago

Really, it breaks. Sorry, I was wrong. Need to close this pull request.