Skip to content

Commit

Permalink
updgrade and get with type
Browse files Browse the repository at this point in the history
  • Loading branch information
lohanidamodar committed Feb 29, 2024
1 parent 62df3ad commit 85d9f06
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 7 additions & 3 deletions lib/src/di.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ class DI {
return resources;
}

dynamic g(String name, {bool fresh = false}) => get(name, fresh: fresh);
dynamic g<T>(String name, {bool fresh = false}) => get<T>(name, fresh: fresh);

dynamic get(String name, {bool fresh = false}) {
dynamic get<T>(String name, {bool fresh = false}) {
if (_resources[name] == null ||
fresh ||
(_resourceCallbacks[name]?.reset ?? true)) {
Expand All @@ -44,7 +44,11 @@ class DI {
);
}
_resourceCallbacks[name] = _resourceCallbacks[name]!.copyWith(reset: false);
return _resources[name];
final resource = _resources[name];
if (resource is T) {
return resource;
}
throw Exception('Resource type doesn\'t match');
}

void reset() {
Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ version: 0.0.2
repository: https://github.com/utopia-dart/utopia_di

environment:
sdk: '>=2.19.2 <3.0.0'
sdk: '>=2.19.2 <4.0.0'

dev_dependencies:
lints: ^2.1.1
test: ^1.24.6
lints: ^3.0.0
test: ^1.25.2

0 comments on commit 85d9f06

Please sign in to comment.