Skip to content

How to Implement DI get_it with other package in a project #133

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

Closed
wisnuwiry opened this issue Nov 30, 2020 · 6 comments
Closed

How to Implement DI get_it with other package in a project #133

wisnuwiry opened this issue Nov 30, 2020 · 6 comments

Comments

@wisnuwiry
Copy link

I have a study case, I want to make an app with a modular project with the package, in the item module. But I don't know about Implementing Dependency Injection in the module.

Thanks..

@escamoteur
Copy link
Collaborator

if you reference get_it in all your packages they will share the same instance as default.

@wisnuwiry
Copy link
Author

Are there samples that I can study? @escamoteur

@escamoteur
Copy link
Collaborator

Can you elaborate what is not clear to you?

@wisnuwiry
Copy link
Author

My Project App Structures:

├── lib
│   ├── ...
│   └── ...dart
│
├── module1
├── module2

In my project in each module, for example, in the example, there are module1 and module2, and in each module is a package.

In each package contains all the Data, State Management and UI.

I'm confused about where the DI implementation is put?

Do I put it in lib / .. di.dart?

Or is the DI (Service Locator) placed in each item module?

I want to apply this in the best practice.

@escamoteur
Copy link
Collaborator

if your modules are packages, you have two options:

  1. register all objects from all modules at a central place in lib\di.dart for instance. this makes dealing with dependencies often the easiest.

  2. give each package an init function that will register all types from that packae and you call these init functions at some place in your main project. For this you don't have to do anything special with get_it. After all init functions are called all objects are in the same global get_it instance.

@wisnuwiry
Copy link
Author

Thanks @escamoteur

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

No branches or pull requests

2 participants