Only Application Scope
See original GitHub issueI’m newbie in DI, and decide to start learning it with toothpick. I try to refactor my sample application and add DI. My data repository is application singleton. Then I use it inside fragment, I inject it in fragment’s onCreate:
public class MyFragment extends BaseFragment {
........
@Inject
MyRepository repository;
.........
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
Toothpick.inject(this, ((App)getActivity().getApplication()).getAppScope());
super.onCreate(savedInstanceState);
}
App.java
public class App extends Application {
private Scope appScope;
@Override
public void onCreate() {
super.onCreate();
initToothpick();
}
private void initToothpick() {
appScope = Toothpick.openScope(this);
appScope.installModules(new SmoothieApplicationModule(this, Preference.NAME), new MyApplicationModule());
Toothpick.inject(this, appScope);
}
public Scope getAppScope() {
return appScope;
}
}
Is it fine?
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Application scope - ServiceNow Docs
Application scoping protects applications by identifying and restricting access to application files and data.
Read more >Scopes - Auth0
When an app requests permission to access a resource through an authorization server , it uses the scope parameter to specify what access...
Read more >Overview of permissions and consent in the Microsoft identity ...
App -only access uses app roles instead of delegated scopes. When granted through consent, app roles may also be called applications permissions.
Read more >Application Scopes - Box Support
These scopes will largely apply when creating a "Custom Application" type with only minor differences between the different Authentication ...
Read more >Excel Application Scope - UiPath Documentation Portal
UiPath.Excel.Activities.ExcelApplicationScope Opens an Excel workbook and provides a scope for Excel Activities. When the execution of this activity ends, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You don’t have a fragment scope, you use the activity scope in the fragment. Which is what you have to do, and the activity closes it properly already.
I close the issue. Please use stack overflow for any new question. feel free to ping us here if no one answers.
Thank you, I refactored scopes as you recommends.
As I understand Activity and ViewModel now fine. App and activity used as scopes and scopes is closing. ViewModel has own scope independent of activity.
But should I close fragment scope? Now it is something like this: