Skip to content

Commit

Permalink
- HotFix for Postpone singleton initialisation to respect environment…
Browse files Browse the repository at this point in the history
… filters
  • Loading branch information
Milad-Akarie committed Mar 12, 2024
1 parent 05d8f0a commit 9f96df0
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
4 changes: 4 additions & 0 deletions injectable/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# ChangeLog
## [2.3.4]
- HotFix for Postpone singleton initialisation to respect environment filters
## [2.3.3] (skip)
- Fix Postpone singleton initialisation to respect environment filters by @lrampazzo
## [2.3.2]
- Add option to pass instance callback function to the init function by @Adam-Langley
## [2.3.1]
Expand Down
18 changes: 12 additions & 6 deletions injectable/lib/src/get_it_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@ class GetItHelper {
late final EnvironmentFilter _environmentFilter;

/// creates a new instance of GetItHelper
GetItHelper(this.getIt, [String? environment, EnvironmentFilter? environmentFilter])
GetItHelper(this.getIt,
[String? environment, EnvironmentFilter? environmentFilter])
: assert(environmentFilter == null || environment == null) {
// register current EnvironmentsFilter as lazy singleton
if (!getIt.isRegistered<EnvironmentFilter>(instanceName: kEnvironmentsFilterName)) {
if (!getIt.isRegistered<EnvironmentFilter>(
instanceName: kEnvironmentsFilterName)) {
_environmentFilter = environmentFilter ?? NoEnvOrContains(environment);
getIt.registerLazySingleton<EnvironmentFilter>(
() => _environmentFilter,
instanceName: kEnvironmentsFilterName,
);
} else {
_environmentFilter = getIt<EnvironmentFilter>(instanceName: kEnvironmentsFilterName);
_environmentFilter =
getIt<EnvironmentFilter>(instanceName: kEnvironmentsFilterName);
}

// register current Environments as lazy singleton
Expand Down Expand Up @@ -213,7 +216,7 @@ class GetItHelper {
if (preResolve) {
return factoryFunc().then(
(instance) => getIt.registerSingleton(
() => instance,
instance,
instanceName: instanceName,
signalsReady: signalsReady,
),
Expand Down Expand Up @@ -255,7 +258,8 @@ class GetItHelper {
/// a helper method to push a new scope and init it's dependencies
/// asynchronously inside of [GetIt]
Future<GetIt> initScopeAsync(String name,
{required Future<void> Function(GetItHelper gh) init, ScopeDisposeFunc? dispose}) {
{required Future<void> Function(GetItHelper gh) init,
ScopeDisposeFunc? dispose}) {
final completer = Completer<GetIt>();
getIt.pushNewScope(
scopeName: name,
Expand All @@ -270,7 +274,9 @@ class GetItHelper {

/// a helper method to push a new scope and init it's dependencies
/// inside of [GetIt]
GetIt initScope(String name, {required void Function(GetItHelper gh) init, ScopeDisposeFunc? dispose}) {
GetIt initScope(String name,
{required void Function(GetItHelper gh) init,
ScopeDisposeFunc? dispose}) {
getIt.pushNewScope(
scopeName: name,
init: (_) => init(this),
Expand Down
2 changes: 1 addition & 1 deletion injectable/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: injectable
description: Injectable is a convenient code generator for get_it. Inspired by Angular DI, Guice DI and inject.dart.
version: 2.3.2
version: 2.3.4
homepage: https://github.com/Milad-Akarie/injectable

environment:
Expand Down
9 changes: 4 additions & 5 deletions injectable_generator/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,10 @@ packages:
injectable:
dependency: "direct main"
description:
name: injectable
sha256: cd3c422e13270c81f64ab73c80406b2b2ed563fe59d0ff2093eb7eee63d0bbeb
url: "https://pub.dev"
source: hosted
version: "2.3.2"
path: "../injectable"
relative: true
source: path
version: "2.3.3"
io:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion injectable_generator/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies:
code_builder: ^4.4.0
dart_style: ^2.0.3
injectable:
^2.3.2
^2.3.4
# path: ../injectable
collection: ^1.17.1
recase: ^4.1.0
Expand Down

0 comments on commit 9f96df0

Please sign in to comment.