AutoInjector는 Flutter 애플리케이션을 위한 가벼우면서 빌드 러너가 필요 없는 의존성 주입 시스템입니다. 실행 시점에 서비스, 리포지토리 및 기타 클래스를 자동으로 등록하고 해결함으로써 의존성 관리를 단순화합니다. 간단함과 사용 편의성을 고려해 설계되었으며, build_runner 같은 코드 생성 도구의 필요성을 제거하여 설정이 더 빠르고 간편합니다. 추가 빌드 단계 없이 최소한의 비용으로 효율적인 의존성 주입을 원하는 개발자에게 이상적입니다.
사용 사례
간단한 앱 상태 관리
빠른 프로토타이핑
작은에서 중간 규모의 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)