सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।
AutoInjector एक हल्का, बिल्ड-रनर-मुक्त डेपेंडेंसी इंजेक्शन सिस्टम है जो फ्लटर एप्लिकेशन के लिए है। यह रनटाइम पर सेवाओं, रिपॉजिटरीज़ और अन्य क्लासेज़ को स्वचालित रूप से रजिस्टर और समाधान करके डेपेंडेंसी के प्रबंधन को सरल बनाता है। सरलता और उपयोग में आसानी के लिए डिज़ाइन किया गया है, जिससे बिल्ड_रनर जैसे कोड जनरेशन टूल्स की आवश्यकता नहीं होती है, जिससे सेटअप तेज़ और आसान हो जाता है। अतिरिक्त बिल्ड स्टेप्स के बिना डेपेंडेंसी इंजेक्शन को हैंडल करने के लिए न्यूनतम, कुशल तरीके की तलाश में डेवलपर्स के लिए उपयुक्त है।
उपयोग
सरल एप्लिकेशन राज्य प्रबंधन
त्वरित प्रोटोटाइपिंग
छोटे से मध्यम आकार के Flutter प्रोजेक्ट
निर्भरता सेटअप में बॉयलरप्लेट को कम करना
build_runner की जटिलता से बचें
मुख्य विशेषताएँ
build_runner की आवश्यकता नहीं है
स्वचालित सेवा पंजीकरण
न्यूनतम कॉन्फ़िगरेशन
रनटाइम निर्भरता समाधान
सभी फ्लटर प्लेटफॉर्म को समर्थन करता है
इनके लिए उपयुक्त
शून्य बिल्ड सेटअप चाहने वाले विकासकर्ता
तत्काल समय सीमा वाले प्रोजेक्ट्स
संकलन-समय इंजेक्शन के बजाय रनटाइम इंजेक्शन प्राथमिकता देने वाली टीमें
निर्भरता इंजेक्शन अवधारणाओं को सीखें
हल्का निर्भरता प्रबंधन
विचार योग्य बातें
बहुत बड़े पैमाने के एप्लिकेशन के लिए आदर्श नहीं है जिसमें जटिल निर्भरता वृक्ष हो
build_runner-आधारित समाधानों की तुलना में सीमित उन्नत विशेषताएँ
अत्यधिक सेवा पंजीकरण के साथ संभावित प्रदर्शन प्रभाव
मूल README
संबंधित सोर्स रिपॉज़िटरी के मूल README का स्नैपशॉट। नवीनतम सामग्री के लिए रिपॉज़िटरी देखें।
Auto Injector - Automatic Dependency injection system without build_runner.
Auto Injector is a Dart package that was created to make the developer's life easier, making the method of how to do dependency injection simpler and more practical.
Just create the class that will be injected and declare it within some of the available "add" methods and that's it, you already have your dependency injection ready to use.
This project is distributed under the MIT License. See LICENSE.txt for more information.
// fetchfinal controller = autoInjector.get<Controller>();
print(controller); // Instance of 'Controller'.// or use calleble function (withless .get())final datasource = autoInjector<Datasource>();
print(datasource); // Instance of 'Datasource'.
// use tryGet that returns null if exception.final datasource = autoInjector.tryGet<Datasource>() ?? Datasource();
print(datasource); // Instance of 'Datasource'.
Get instance and transform params.
This can be used for example to replace an instance with a mock in tests.
final datasource = autoInjector.get<Datasource>(transform: changeParam(DataSourceMock()));
print(datasource); // Instance of 'Datasource'.
Dispose Singleton
Singletons can be terminated on request using the disposeSingleton method returning
the instance for executing the dispose routine.
final deadInstance = autoInjector.disposeSingleton<MyController>();
deadInstance.close();
Modularization
For projects with multiple scopes, try uniting the instances by naming them Module or Container.
With this, you can register specific instances for each module.
It is also possible to remove all singletons from a specific tag using the method
disposeSingletonsByTag which reports each instance removed via an anonymous function:
There is the possibility to listen and transform all the parameters that are being analyzed
when there is an instance request (AutoInject.get()). Add transformers on the main instance:
If there is a need to configure the dispose and notifier of the bind,
use the BindConfig<T> property.
This is very useful if you want to automate class disposes like BLoC or Triple Store:
final injector = AutoInjector();
final config = BindConfig<Bloc>(
onDispose: (bloc) => bloc.close(),
onNotifier: (bloc) => bloc.stream,
);
injector.addSingleton(ProductBloc.new, config: config);
Right now this package has concluded all his intended features. If you have any suggestions or find something to report, see below how to contribute to it.
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the appropriate tag.
Don't forget to give the project a star! Thanks again!
Fork the Project
Create your Feature Branch (git checkout -b feature/AmazingFeature)
Commit your Changes (git commit -m 'Add some AmazingFeature')
Push to the Branch (git push origin feature/AmazingFeature)