├── .gitignore ├── .pubignore ├── .vscode └── settings.json ├── CHANGELOG.md ├── LICENSE ├── README.md ├── analysis_options.yaml ├── doc └── api │ ├── __404error.html │ ├── auto_injector │ ├── AutoInjector-class.html │ ├── AutoInjector │ │ ├── AutoInjector.html │ │ ├── add.html │ │ ├── addInjector.html │ │ ├── addInstance.html │ │ ├── addLazySingleton.html │ │ ├── addSingleton.html │ │ ├── bindLength.html │ │ ├── call.html │ │ ├── commit.html │ │ ├── disposeSingleton.html │ │ ├── disposeSingletonsByTag.html │ │ ├── get.html │ │ ├── getNotifier.html │ │ ├── hasTag.html │ │ ├── isAdded.html │ │ ├── isInstantiateSingleton.html │ │ ├── on.html │ │ ├── removeAll.html │ │ ├── removeByTag.html │ │ ├── replaceInstance.html │ │ ├── tryGet.html │ │ └── uncommit.html │ ├── AutoInjectorException-class.html │ ├── AutoInjectorException │ │ ├── AutoInjectorException.html │ │ ├── message.html │ │ ├── stackTrace.html │ │ └── toString.html │ ├── NamedParam-class.html │ ├── NamedParam │ │ ├── NamedParam.html │ │ ├── isRequired.html │ │ ├── named.html │ │ └── setValue.html │ ├── Param-class.html │ ├── Param │ │ ├── Param.html │ │ ├── className.html │ │ ├── isNullable.html │ │ ├── setValue.html │ │ └── value.html │ ├── ParamTransform.html │ ├── PositionalParam-class.html │ ├── PositionalParam │ │ ├── PositionalParam.html │ │ └── setValue.html │ ├── UnregisteredInstance-class.html │ ├── UnregisteredInstance │ │ ├── UnregisteredInstance.html │ │ └── classNames.html │ ├── auto_injector-library.html │ └── changeParam.html │ ├── categories.json │ ├── index.html │ ├── index.json │ ├── search.html │ └── static-assets │ ├── docs.dart.js │ ├── docs.dart.js.map │ ├── favicon.png │ ├── github.css │ ├── highlight.pack.js │ ├── play_button.svg │ ├── readme.md │ ├── search.png │ └── styles.css ├── example └── auto_injector_example.dart ├── lib ├── auto_injector.dart └── src │ ├── auto_injector_base.dart │ ├── bind.dart │ ├── exceptions │ └── exceptions.dart │ ├── layers_graph.dart │ └── param.dart ├── pubspec.yaml ├── readme_assets └── logo-auto-injection.png └── test └── src ├── auto_injector_base_test.dart ├── auto_injector_with_key_test.dart ├── exceptions └── exceptions_test.dart └── nested_injectors_test.dart /.gitignore: -------------------------------------------------------------------------------- 1 | # Files and directories created by pub. 2 | .dart_tool/ 3 | .packages 4 | 5 | # Conventional directory for build outputs. 6 | build/ 7 | 8 | # Omit committing pubspec.lock for library packages; see 9 | # https://dart.dev/guides/libraries/private-files#pubspeclock. 10 | pubspec.lock 11 | 12 | coverage/ -------------------------------------------------------------------------------- /.pubignore: -------------------------------------------------------------------------------- 1 | # Files and directories created by pub. 2 | .dart_tool/ 3 | .packages 4 | 5 | # Conventional directory for build outputs. 6 | build/ 7 | 8 | # Omit committing pubspec.lock for library packages; see 9 | # https://dart.dev/guides/libraries/private-files#pubspeclock. 10 | pubspec.lock 11 | 12 | coverage/ 13 | doc/ 14 | readme_assets/ 15 | test/ -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "dart.flutterSdkPath": "/Users/jacob/.puro/envs/stable/flutter", 3 | "dart.sdkPath": "/Users/jacob/.puro/envs/stable/flutter/bin/cache/dart-sdk" 4 | } -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 2.1.0 2 | - Add: `addBind` for complex registration. 3 | 4 | ## 2.0.5 5 | - Fix: replaceInstance now dont throw errors. 6 | 7 | ## 2.0.4 8 | - Fix: Instance callback on dispose (@thalissonmt) 9 | 10 | ## 2.0.3 11 | - pump encrypt version 12 | 13 | ## 2.0.2 (2023-09-01) 14 | - fix: Remove `fake_reflection` 15 | - fix: dispose callback 16 | 17 | ## 2.0.0 (2023-08-24) 18 | 19 | - fix: replace with others tags 20 | - fix: Custom split to generics datas in many levels (thanks @luanbatistadev) 21 | - add: Multi Injector (thanks @davidsdearaujo). 22 | - add: Get and register instances by name (thanks toshi @toshiossada). 23 | 24 | ## 1.1.1 (2023-08-05) 25 | 26 | - fix: allow add same bind with tag diff 27 | 28 | ## 1.1.0+4 (2023-07-31) 29 | 30 | - add: BindConfig 31 | - chore: Update Exceptions 32 | 33 | ## 1.0.5+2 (2023-07-30) 34 | 35 | - fix: filter injectable params 36 | - chore: Separed Injector interface 37 | 38 | ## 1.0.4 (2023-06-29) 39 | 40 | - fix: Internal call dispose. 41 | 42 | ## 1.0.3 (2023-06-03) 43 | 44 | - fix: disposeSingletonsByTag error 45 | 46 | ## 1.0.2+2 (2023-03-08) 47 | 48 | - Fix: dart doc & readme 49 | 50 | ## 1.0.2+1 (2023-03-07) 51 | 52 | - Added: documentation with dart doc 53 | - Readme updated 54 | 55 | ## 1.0.2 (2023-02-11) 56 | 57 | - fix: Resolver class name with Object 58 | 59 | ## 1.0.1 (2023-01-31) 60 | 61 | - fix: param with named and positional params 62 | 63 | ## 1.0.0 (2023-01-30) 64 | 65 | - Initial version. 66 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | License Copyright: Flutterando. 3 | License License: Flutterando. 4 | License Contact: Flutterando. 5 | 6 | Begin license text. 7 | Copyright 2023 8 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 9 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 10 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 11 | End license text. -------------------------------------------------------------------------------- /analysis_options.yaml: -------------------------------------------------------------------------------- 1 | # This file configures the static analysis results for your project (errors, 2 | # warnings, and lints). 3 | # 4 | # This enables the 'recommended' set of lints from `package:lints`. 5 | # This set helps identify many issues that may lead to problems when running 6 | # or consuming Dart code, and enforces writing Dart using a single, idiomatic 7 | # style and format. 8 | # 9 | # If you want a smaller set of lints you can change this to specify 10 | # 'package:lints/core.yaml'. These are just the most critical lints 11 | # (the recommended set includes the core lints). 12 | # The core lints are also what is used by pub.dev for scoring packages. 13 | 14 | include: package:flutterando_analysis/dart_package.yaml 15 | 16 | # Uncomment the following section to specify additional rules. 17 | 18 | linter: 19 | rules: 20 | cascade_invocations: false 21 | avoid_print: false 22 | 23 | # analyzer: 24 | # exclude: 25 | # - path/to/excluded/files/** 26 | 27 | # For more information about the core and recommended set of lints, see 28 | # https://dart.dev/go/core-lints 29 | 30 | # For additional information about configuring this file, see 31 | # https://dart.dev/guides/language/analysis-options 32 | -------------------------------------------------------------------------------- /doc/api/__404error.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | auto_injector - Dart API docs 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 |
30 | menu 31 | 34 |
auto_injector
35 | 38 |
39 | 45 |
46 |
47 |
48 | 49 |
50 |

404: Something's gone wrong :-(

51 | 52 |
53 |

You've tried to visit a page that doesn't exist. Luckily this site 54 | has other pages.

55 |

If you were looking for something specific, try searching: 56 |

59 |

60 | 61 |
62 |
63 | 64 | 83 | 84 | 86 | 87 |
88 | 89 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /doc/api/auto_injector/AutoInjector/bindLength.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | bindLength property - AutoInjector class - auto_injector library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
bindLength
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

bindLength property 54 | Null safety 55 |

56 | 57 | 58 | 59 |
60 | 61 |
62 | 63 |
64 |
    65 |
  1. @visibleForTesting
  2. 66 |
67 |
68 | int 69 | bindLength 70 | 71 | 72 |
73 | 74 | 75 |
76 |

Only test

77 |
78 | 79 | 80 |
81 |

Implementation

82 |
@visibleForTesting
 83 | int get bindLength;
84 |
85 | 86 |
87 | 88 | 89 |
90 | 91 | 153 | 154 | 156 | 157 |
158 | 159 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | -------------------------------------------------------------------------------- /doc/api/auto_injector/AutoInjector/commit.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | commit method - AutoInjector class - auto_injector library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
commit
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

commit abstract method 54 | Null safety 55 |

56 | 57 |
58 | 59 | 60 | void 61 | commit() 62 | 63 | 64 | 65 |
66 | 67 |
68 |

Informs the container that the additions 69 | are finished and the injector is ready to be used.
70 | This command starts the singletons.

71 |
72 | 73 | 74 | 75 |
76 |

Implementation

77 |
void commit();
78 |
79 | 80 | 81 |
82 | 83 | 145 | 146 | 148 | 149 |
150 | 151 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | -------------------------------------------------------------------------------- /doc/api/auto_injector/AutoInjector/getNotifier.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | getNotifier method - AutoInjector class - auto_injector library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
getNotifier
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

getNotifier<T> abstract method 54 | Null safety 55 |

56 | 57 |
58 | 59 | 60 | dynamic 61 | getNotifier<T>() 62 | 63 | 64 | 65 |
66 | 67 |
68 |

Request an notifier propertie by Type

69 |
70 | 71 | 72 | 73 |
74 |

Implementation

75 |
dynamic getNotifier<T>();
76 |
77 | 78 | 79 |
80 | 81 | 143 | 144 | 146 | 147 |
148 | 149 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | -------------------------------------------------------------------------------- /doc/api/auto_injector/AutoInjector/isAdded.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | isAdded method - AutoInjector class - auto_injector library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
isAdded
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

isAdded<T> abstract method 54 | Null safety 55 |

56 | 57 |
58 | 59 | 60 | bool 61 | isAdded<T>() 62 | 63 | 64 | 65 |
66 | 67 |
68 |

Checks if the instance record exists.

69 |
70 | 71 | 72 | 73 |
74 |

Implementation

75 |
bool isAdded<T>();
76 |
77 | 78 | 79 |
80 | 81 | 143 | 144 | 146 | 147 |
148 | 149 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | -------------------------------------------------------------------------------- /doc/api/auto_injector/AutoInjector/on.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | on property - AutoInjector class - auto_injector library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
on
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

on property 54 | Null safety 55 |

56 | 57 |
58 | 59 | (void Function(AutoInjector injector)?) 60 | on 61 |
final
62 | 63 |
64 | 65 |
66 |

Helps with instance registration

67 |
68 | 69 | 70 |
71 |

Implementation

72 |
final void Function(AutoInjector injector)? on;
73 |
74 | 75 | 76 |
77 | 78 | 140 | 141 | 143 | 144 |
145 | 146 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | -------------------------------------------------------------------------------- /doc/api/auto_injector/AutoInjector/removeAll.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | removeAll method - AutoInjector class - auto_injector library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
removeAll
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

removeAll abstract method 54 | Null safety 55 |

56 | 57 |
58 | 59 | 60 | void 61 | removeAll() 62 | 63 | 64 | 65 |
66 | 67 |
68 |

Remove all regiters

69 |
70 | 71 | 72 | 73 |
74 |

Implementation

75 |
void removeAll();
76 |
77 | 78 | 79 |
80 | 81 | 143 | 144 | 146 | 147 |
148 | 149 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | -------------------------------------------------------------------------------- /doc/api/auto_injector/AutoInjector/removeByTag.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | removeByTag method - AutoInjector class - auto_injector library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
removeByTag
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

removeByTag abstract method 54 | Null safety 55 |

56 | 57 |
58 | 59 | 60 | void 61 | removeByTag(
  1. String tag
  2. 62 |
) 63 | 64 | 65 | 66 |
67 | 68 |
69 |

Removes registers by tag.

70 |
71 | 72 | 73 | 74 |
75 |

Implementation

76 |
void removeByTag(String tag);
77 |
78 | 79 | 80 |
81 | 82 | 144 | 145 | 147 | 148 |
149 | 150 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | -------------------------------------------------------------------------------- /doc/api/auto_injector/AutoInjector/uncommit.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | uncommit method - AutoInjector class - auto_injector library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
uncommit
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

uncommit abstract method 54 | Null safety 55 |

56 | 57 |
58 | 59 | 60 | void 61 | uncommit() 62 | 63 | 64 | 65 |
66 | 67 |
68 |

remove commit

69 |
70 | 71 | 72 | 73 |
74 |

Implementation

75 |
void uncommit();
76 |
77 | 78 | 79 |
80 | 81 | 143 | 144 | 146 | 147 |
148 | 149 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | -------------------------------------------------------------------------------- /doc/api/auto_injector/AutoInjectorException/AutoInjectorException.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | AutoInjectorException constructor - AutoInjectorException - auto_injector library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
AutoInjectorException
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

AutoInjectorException constructor 54 | Null safety 55 |

56 | 57 |
58 | const 59 | AutoInjectorException(
  1. String message,
  2. 60 |
  3. [StackTrace? stackTrace]
  4. 61 |
) 62 |
63 | 64 | 65 |
66 |

AutoInjecton Exception with ToString auto configurated

67 |
68 | 69 | 70 | 71 |
72 |

Implementation

73 |
const AutoInjectorException(this.message, [this.stackTrace]);
74 |
75 | 76 | 77 |
78 | 79 | 122 | 123 | 125 | 126 |
127 | 128 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /doc/api/auto_injector/AutoInjectorException/message.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | message property - AutoInjectorException class - auto_injector library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
message
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

message property 54 | Null safety 55 |

56 | 57 |
58 | 59 | String 60 | message 61 |
final
62 | 63 |
64 | 65 |
66 |

message of exception

67 |
68 | 69 | 70 |
71 |

Implementation

72 |
final String message;
73 |
74 | 75 | 76 |
77 | 78 | 121 | 122 | 124 | 125 |
126 | 127 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /doc/api/auto_injector/AutoInjectorException/stackTrace.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | stackTrace property - AutoInjectorException class - auto_injector library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
stackTrace
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

stackTrace property 54 | Null safety 55 |

56 | 57 |
58 | 59 | StackTrace? 60 | stackTrace 61 |
final
62 | 63 |
64 | 65 |
66 |

traces of exception

67 |
68 | 69 | 70 |
71 |

Implementation

72 |
final StackTrace? stackTrace;
73 |
74 | 75 | 76 |
77 | 78 | 121 | 122 | 124 | 125 |
126 | 127 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /doc/api/auto_injector/AutoInjectorException/toString.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | toString method - AutoInjectorException class - auto_injector library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
toString
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

toString method 54 | Null safety 55 |

56 | 57 |
58 | 59 |
60 |
    61 |
  1. @override
  2. 62 |
63 |
64 | 65 | String 66 | toString() 67 | 68 |
override
69 | 70 |
71 | 72 |
73 |

A string representation of this object.

74 |

Some classes have a default textual representation, 75 | often paired with a static parse function (like int.parse). 76 | These classes will provide the textual representation as 77 | their string representation.

78 |

Other classes have no meaningful textual representation 79 | that a program will care about. 80 | Such classes will typically override toString to provide 81 | useful information when inspecting the object, 82 | mainly for debugging or logging.

83 |
84 | 85 | 86 | 87 |
88 |

Implementation

89 |
@override
 90 | String toString() {
 91 |   var message = '$_typeName: ${this.message}';
 92 |   if (stackTrace != null) {
 93 |     message = '$message\n$stackTrace';
 94 |   }
 95 | 
 96 |   return message;
 97 | }
98 |
99 | 100 | 101 |
102 | 103 | 146 | 147 | 149 | 150 |
151 | 152 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | -------------------------------------------------------------------------------- /doc/api/auto_injector/NamedParam/NamedParam.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | NamedParam constructor - NamedParam - auto_injector library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
NamedParam
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

NamedParam constructor 54 | Null safety 55 |

56 | 57 |
58 | 59 | NamedParam(
  1. {required String className,
  2. 60 |
  3. dynamic value,
  4. 61 |
  5. required Symbol named,
  6. 62 |
  7. bool isNullable = false,
  8. 63 |
  9. bool isRequired = false}
  10. 64 |
) 65 |
66 | 67 | 68 | 69 | 70 | 71 |
72 |

Implementation

73 |
NamedParam({
 74 |   required super.className,
 75 |   super.value,
 76 |   required this.named,
 77 |   super.isNullable = false,
 78 |   this.isRequired = false,
 79 | });
80 |
81 | 82 | 83 |
84 | 85 | 132 | 133 | 135 | 136 |
137 | 138 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | -------------------------------------------------------------------------------- /doc/api/auto_injector/NamedParam/isRequired.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | isRequired property - NamedParam class - auto_injector library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
isRequired
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

isRequired property 54 | Null safety 55 |

56 | 57 |
58 | 59 | bool 60 | isRequired 61 |
final
62 | 63 |
64 | 65 | 66 | 67 |
68 |

Implementation

69 |
final bool isRequired;
70 |
71 | 72 | 73 |
74 | 75 | 122 | 123 | 125 | 126 |
127 | 128 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /doc/api/auto_injector/NamedParam/named.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | named property - NamedParam class - auto_injector library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
named
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

named property 54 | Null safety 55 |

56 | 57 |
58 | 59 | Symbol 60 | named 61 |
final
62 | 63 |
64 | 65 | 66 | 67 |
68 |

Implementation

69 |
final Symbol named;
70 |
71 | 72 | 73 |
74 | 75 | 122 | 123 | 125 | 126 |
127 | 128 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /doc/api/auto_injector/NamedParam/setValue.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | setValue method - NamedParam class - auto_injector library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
setValue
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

setValue method 54 | Null safety 55 |

56 | 57 |
58 | 59 |
60 |
    61 |
  1. @override
  2. 62 |
63 |
64 | 65 | NamedParam 66 | setValue(
  1. dynamic value
  2. 67 |
) 68 | 69 |
override
70 | 71 |
72 | 73 |
74 |

return a new instance of Param with value

75 |
76 | 77 | 78 | 79 |
80 |

Implementation

81 |
@override
 82 | NamedParam setValue(dynamic value) {
 83 |   return NamedParam(
 84 |     named: named,
 85 |     className: className,
 86 |     isNullable: isNullable,
 87 |     isRequired: isNullable,
 88 |     value: value,
 89 |   );
 90 | }
91 |
92 | 93 | 94 |
95 | 96 | 143 | 144 | 146 | 147 |
148 | 149 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | -------------------------------------------------------------------------------- /doc/api/auto_injector/Param/Param.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Param constructor - Param - auto_injector library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
Param
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

Param constructor 54 | Null safety 55 |

56 | 57 |
58 | 59 | Param(
  1. {required String className,
  2. 60 |
  3. bool isNullable = false,
  4. 61 |
  5. dynamic value}
  6. 62 |
) 63 |
64 | 65 | 66 | 67 | 68 | 69 |
70 |

Implementation

71 |
Param({
 72 |   required this.className,
 73 |   this.isNullable = false,
 74 |   this.value,
 75 | });
76 |
77 | 78 | 79 |
80 | 81 | 126 | 127 | 129 | 130 |
131 | 132 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | -------------------------------------------------------------------------------- /doc/api/auto_injector/Param/className.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | className property - Param class - auto_injector library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
className
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

className property 54 | Null safety 55 |

56 | 57 |
58 | 59 | String 60 | className 61 |
final
62 | 63 |
64 | 65 | 66 | 67 |
68 |

Implementation

69 |
final String className;
70 |
71 | 72 | 73 |
74 | 75 | 120 | 121 | 123 | 124 |
125 | 126 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | -------------------------------------------------------------------------------- /doc/api/auto_injector/Param/isNullable.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | isNullable property - Param class - auto_injector library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
isNullable
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

isNullable property 54 | Null safety 55 |

56 | 57 |
58 | 59 | bool 60 | isNullable 61 |
final
62 | 63 |
64 | 65 | 66 | 67 |
68 |

Implementation

69 |
final bool isNullable;
70 |
71 | 72 | 73 |
74 | 75 | 120 | 121 | 123 | 124 |
125 | 126 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | -------------------------------------------------------------------------------- /doc/api/auto_injector/Param/setValue.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | setValue method - Param class - auto_injector library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
setValue
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

setValue abstract method 54 | Null safety 55 |

56 | 57 |
58 | 59 | 60 | Param 61 | setValue(
  1. dynamic value
  2. 62 |
) 63 | 64 | 65 | 66 |
67 | 68 |
69 |

return a new instance of Param with value

70 |
71 | 72 | 73 | 74 |
75 |

Implementation

76 |
Param setValue(dynamic value);
77 |
78 | 79 | 80 |
81 | 82 | 127 | 128 | 130 | 131 |
132 | 133 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /doc/api/auto_injector/Param/value.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | value property - Param class - auto_injector library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
value
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

value property 54 | Null safety 55 |

56 | 57 |
58 | 59 | dynamic 60 | value 61 |
final
62 | 63 |
64 | 65 |
66 |

instance of param

67 |
68 | 69 | 70 |
71 |

Implementation

72 |
final dynamic value;
73 |
74 | 75 | 76 |
77 | 78 | 123 | 124 | 126 | 127 |
128 | 129 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | -------------------------------------------------------------------------------- /doc/api/auto_injector/ParamTransform.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | ParamTransform typedef - auto_injector library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 35 |
ParamTransform
36 | 39 |
40 | 46 |
47 |
48 |
49 | 50 |
51 |
52 |

ParamTransform typedef 53 | Null safety 54 | 55 |

56 | 57 |
58 | ParamTransform = 59 | Param? Function(Param param) 60 | 61 |
62 | 63 | 64 | 65 | 66 |
67 |

Implementation

68 |
typedef ParamTransform = Param? Function(Param param);
69 |
70 | 71 | 72 |
73 | 74 | 113 | 114 | 116 | 117 |
118 | 119 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | -------------------------------------------------------------------------------- /doc/api/auto_injector/PositionalParam/PositionalParam.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | PositionalParam constructor - PositionalParam - auto_injector library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
PositionalParam
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

PositionalParam constructor 54 | Null safety 55 |

56 | 57 |
58 | 59 | PositionalParam(
  1. {required String className,
  2. 60 |
  3. dynamic value,
  4. 61 |
  5. bool isNullable = false}
  6. 62 |
) 63 |
64 | 65 | 66 | 67 | 68 | 69 |
70 |

Implementation

71 |
PositionalParam({
 72 |   required super.className,
 73 |   super.value,
 74 |   super.isNullable = false,
 75 | });
76 |
77 | 78 | 79 |
80 | 81 | 126 | 127 | 129 | 130 |
131 | 132 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | -------------------------------------------------------------------------------- /doc/api/auto_injector/PositionalParam/setValue.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | setValue method - PositionalParam class - auto_injector library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
setValue
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

setValue method 54 | Null safety 55 |

56 | 57 |
58 | 59 |
60 |
    61 |
  1. @override
  2. 62 |
63 |
64 | 65 | PositionalParam 66 | setValue(
  1. dynamic value
  2. 67 |
) 68 | 69 |
override
70 | 71 |
72 | 73 |
74 |

return a new instance of Param with value

75 |
76 | 77 | 78 | 79 |
80 |

Implementation

81 |
@override
 82 | PositionalParam setValue(dynamic value) {
 83 |   return PositionalParam(
 84 |     className: className,
 85 |     isNullable: isNullable,
 86 |     value: value,
 87 |   );
 88 | }
89 |
90 | 91 | 92 |
93 | 94 | 139 | 140 | 142 | 143 |
144 | 145 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | -------------------------------------------------------------------------------- /doc/api/auto_injector/UnregisteredInstance/UnregisteredInstance.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | UnregisteredInstance constructor - UnregisteredInstance - auto_injector library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
UnregisteredInstance
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

UnregisteredInstance constructor 54 | Null safety 55 |

56 | 57 |
58 | 59 | UnregisteredInstance(
  1. List<String> classNames,
  2. 60 |
  3. [String message = '',
  4. 61 |
  5. StackTrace? stackTrace]
  6. 62 |
) 63 |
64 | 65 | 66 |
67 |

AutoInjecton Exception for Unregistered instance. 68 |
69 | Store all parent classNames 70 | message: message of exception
71 | stackTrace: traces of exception 72 | classNames: all parent class names

73 |
74 | 75 | 76 | 77 |
78 |

Implementation

79 |
UnregisteredInstance(this.classNames, [super.message = '', super.stackTrace]);
80 |
81 | 82 | 83 |
84 | 85 | 129 | 130 | 132 | 133 |
134 | 135 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | -------------------------------------------------------------------------------- /doc/api/auto_injector/UnregisteredInstance/classNames.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | classNames property - UnregisteredInstance class - auto_injector library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
classNames
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

classNames property 54 | Null safety 55 |

56 | 57 |
58 | 59 | List<String> 60 | classNames 61 |
final
62 | 63 |
64 | 65 |
66 |

all parent class names;

67 |
68 | 69 | 70 |
71 |

Implementation

72 |
final List<String> classNames;
73 |
74 | 75 | 76 |
77 | 78 | 122 | 123 | 125 | 126 |
127 | 128 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /doc/api/auto_injector/changeParam.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | changeParam function - auto_injector library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 35 |
changeParam
36 | 39 |
40 | 46 |
47 |
48 |
49 | 50 |
51 |
52 |

changeParam<T> function 53 | Null safety 54 | 55 |

56 | 57 |
58 | 59 | 60 | ParamTransform 61 | changeParam<T>(
  1. T newValue
  2. 62 |
) 63 | 64 | 65 | 66 |
67 | 68 | 69 | 70 | 71 |
72 |

Implementation

73 |
ParamTransform changeParam<T>(T newValue) {
 74 |   return (param) {
 75 |     if (T.toString() == param.className) {
 76 |       return param.setValue(newValue);
 77 |     }
 78 |     return null;
 79 |   };
 80 | }
81 |
82 | 83 | 84 |
85 | 86 | 125 | 126 | 128 | 129 |
130 | 131 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | -------------------------------------------------------------------------------- /doc/api/categories.json: -------------------------------------------------------------------------------- 1 | [] 2 | -------------------------------------------------------------------------------- /doc/api/search.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | auto_injector - Dart API docs 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 |
30 | menu 31 | 35 |
auto_injector
36 | 39 |
40 | 46 |
47 |
48 |
49 | 50 |
51 |
52 | 53 | 73 | 74 | 76 | 77 |
78 | 79 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /doc/api/static-assets/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/auto_injector/45719fbe86aae201d2feae0c3f462b0f875a2de6/doc/api/static-assets/favicon.png -------------------------------------------------------------------------------- /doc/api/static-assets/github.css: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | github.com style (c) Vasily Polovnyov 4 | 5 | */ 6 | 7 | .hljs { 8 | display: block; 9 | overflow-x: auto; 10 | padding: 0.5em; 11 | color: #333; 12 | background: #f8f8f8; 13 | } 14 | 15 | .hljs-comment, 16 | .hljs-quote { 17 | color: #998; 18 | font-style: italic; 19 | } 20 | 21 | .hljs-keyword, 22 | .hljs-selector-tag, 23 | .hljs-subst { 24 | color: #333; 25 | font-weight: bold; 26 | } 27 | 28 | .hljs-number, 29 | .hljs-literal, 30 | .hljs-variable, 31 | .hljs-template-variable, 32 | .hljs-tag .hljs-attr { 33 | color: #008080; 34 | } 35 | 36 | .hljs-string, 37 | .hljs-doctag { 38 | color: #d14; 39 | } 40 | 41 | .hljs-title, 42 | .hljs-section, 43 | .hljs-selector-id { 44 | color: #900; 45 | font-weight: bold; 46 | } 47 | 48 | .hljs-subst { 49 | font-weight: normal; 50 | } 51 | 52 | .hljs-type, 53 | .hljs-class .hljs-title { 54 | color: #458; 55 | font-weight: bold; 56 | } 57 | 58 | .hljs-tag, 59 | .hljs-name, 60 | .hljs-attribute { 61 | color: #000080; 62 | font-weight: normal; 63 | } 64 | 65 | .hljs-regexp, 66 | .hljs-link { 67 | color: #009926; 68 | } 69 | 70 | .hljs-symbol, 71 | .hljs-bullet { 72 | color: #990073; 73 | } 74 | 75 | .hljs-built_in, 76 | .hljs-builtin-name { 77 | color: #0086b3; 78 | } 79 | 80 | .hljs-meta { 81 | color: #999; 82 | font-weight: bold; 83 | } 84 | 85 | .hljs-deletion { 86 | background: #fdd; 87 | } 88 | 89 | .hljs-addition { 90 | background: #dfd; 91 | } 92 | 93 | .hljs-emphasis { 94 | font-style: italic; 95 | } 96 | 97 | .hljs-strong { 98 | font-weight: bold; 99 | } 100 | -------------------------------------------------------------------------------- /doc/api/static-assets/play_button.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /doc/api/static-assets/readme.md: -------------------------------------------------------------------------------- 1 | # highlight.js 2 | 3 | Generated from https://highlightjs.org/download/ on 2021-07-13 4 | 5 | **Included languages:** 6 | 7 | * bash 8 | * c 9 | * css 10 | * dart 11 | * diff 12 | * html, xml 13 | * java 14 | * javascript 15 | * json 16 | * kotlin 17 | * markdown 18 | * objective-c 19 | * plaintext 20 | * shell 21 | * swift 22 | * yaml 23 | -------------------------------------------------------------------------------- /doc/api/static-assets/search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/auto_injector/45719fbe86aae201d2feae0c3f462b0f875a2de6/doc/api/static-assets/search.png -------------------------------------------------------------------------------- /example/auto_injector_example.dart: -------------------------------------------------------------------------------- 1 | import 'package:auto_injector/auto_injector.dart'; 2 | 3 | final homeModule = AutoInjector( 4 | paramTransforms: [ 5 | (param) { 6 | return param; 7 | } 8 | ], 9 | on: (i) { 10 | i.addInjector(productModule); 11 | i.addInjector(userModule); 12 | i.commit(); 13 | }, 14 | ); 15 | 16 | final productModule = AutoInjector( 17 | on: (i) { 18 | i.addInstance(1); 19 | }, 20 | ); 21 | 22 | final userModule = AutoInjector( 23 | on: (i) { 24 | i.addInstance(true); 25 | }, 26 | ); 27 | 28 | void main() { 29 | print(homeModule.get()); 30 | print(homeModule.get()); 31 | } 32 | -------------------------------------------------------------------------------- /lib/auto_injector.dart: -------------------------------------------------------------------------------- 1 | /// Support for doing something awesome. 2 | /// 3 | /// More dartdocs go here. 4 | library auto_injector; 5 | 6 | export 'src/auto_injector_base.dart' hide AutoInjectorImpl, VoidCallback; 7 | export 'src/bind.dart'; 8 | export 'src/exceptions/exceptions.dart'; 9 | export 'src/param.dart'; 10 | -------------------------------------------------------------------------------- /lib/src/bind.dart: -------------------------------------------------------------------------------- 1 | // ignore_for_file: public_member_api_docs 2 | 3 | import 'package:auto_injector/auto_injector.dart'; 4 | 5 | enum BindType { 6 | instance, 7 | factory, 8 | singleton, 9 | lazySingleton; 10 | 11 | bool get isSingleton { 12 | return this == BindType.singleton || this == BindType.lazySingleton; 13 | } 14 | } 15 | 16 | class BindConfig { 17 | final DisposeCallback? onDispose; 18 | final NotifierCallback? notifier; 19 | BindConfig({ 20 | this.onDispose, 21 | this.notifier, 22 | }); 23 | } 24 | 25 | typedef DisposeCallback = void Function(T value); 26 | typedef NotifierCallback = dynamic Function(T value); 27 | 28 | class Bind { 29 | final Function constructor; 30 | final BindType type; 31 | final List params; 32 | final String? className; 33 | final T? instance; 34 | final BindConfig? config; 35 | final String? key; 36 | 37 | bool get hasInstance => instance != null; 38 | 39 | factory Bind({ 40 | required Function constructor, 41 | required BindType type, 42 | BindConfig? config, 43 | T? instance, 44 | String? key, 45 | }) { 46 | final constructorString = constructor.runtimeType.toString(); 47 | final className = _resolveClassName(constructorString); 48 | final params = _extractParams(constructorString); 49 | 50 | return Bind._( 51 | constructor: constructor, 52 | className: (key != null) ? null : className, 53 | params: params, 54 | type: type, 55 | config: config, 56 | instance: instance, 57 | key: key, 58 | ); 59 | } 60 | 61 | factory Bind.withClassName({ 62 | required Function constructor, 63 | required BindType type, 64 | required String className, 65 | BindConfig? config, 66 | String? key, 67 | }) { 68 | final constructorString = constructor.runtimeType.toString(); 69 | final params = _extractParams(constructorString); 70 | 71 | return Bind._( 72 | constructor: constructor, 73 | className: className, 74 | params: params, 75 | type: type, 76 | config: config, 77 | key: key, 78 | ); 79 | } 80 | 81 | factory Bind.empty(String className) { 82 | return Bind._( 83 | constructor: () => null, 84 | className: className, 85 | params: [], 86 | type: BindType.factory, 87 | ); 88 | } 89 | 90 | void callDispose() { 91 | final instance = this.instance; 92 | if (instance != null) { 93 | config?.onDispose?.call(instance); 94 | } 95 | } 96 | 97 | dynamic getNotifier() { 98 | if (instance != null && config?.notifier != null) { 99 | return Function.apply(config!.notifier!, [instance]); 100 | } 101 | } 102 | 103 | Bind._({ 104 | required this.constructor, 105 | required this.type, 106 | required this.params, 107 | this.className, 108 | this.config, 109 | this.instance, 110 | this.key, 111 | }); 112 | 113 | Bind withoutInstance() { 114 | return Bind._( 115 | constructor: constructor, 116 | type: type, 117 | params: params, 118 | className: className, 119 | config: config, 120 | key: key, 121 | ); 122 | } 123 | 124 | Bind withInstance(T instance) { 125 | return Bind._( 126 | constructor: constructor, 127 | type: type, 128 | params: params, 129 | className: className, 130 | instance: instance, 131 | config: config, 132 | key: key, 133 | ); 134 | } 135 | 136 | static List _customSplit(String input) { 137 | final parts = []; 138 | var currentPart = ''; 139 | var angleBracketCount = 0; 140 | 141 | for (final char in input.runes) { 142 | final charStr = String.fromCharCode(char); 143 | 144 | if (charStr == ',' && angleBracketCount == 0) { 145 | parts.add(currentPart.trim()); 146 | currentPart = ''; 147 | } else { 148 | currentPart += charStr; 149 | 150 | if (charStr == '<') { 151 | angleBracketCount++; 152 | } else if (charStr == '>') { 153 | angleBracketCount--; 154 | } 155 | } 156 | } 157 | 158 | if (currentPart.isNotEmpty && currentPart != ' ') { 159 | parts.add(currentPart.trim()); 160 | } 161 | 162 | return parts; 163 | } 164 | 165 | static List _extractParams(String constructorString) { 166 | final params = []; 167 | 168 | if (constructorString.startsWith('() => ')) { 169 | return params; 170 | } 171 | 172 | final allArgsRegex = RegExp(r'\((.+)\) => .+'); 173 | 174 | final allArgsMatch = allArgsRegex.firstMatch(constructorString); 175 | 176 | var allArgs = allArgsMatch!.group(1)!; 177 | 178 | final hasNamedParams = RegExp(r'\{(.+)\}'); 179 | final namedParams = hasNamedParams.firstMatch(allArgs); 180 | 181 | if (namedParams != null) { 182 | final named = namedParams.group(1)!; 183 | allArgs = allArgs.replaceAll('{$named}', ''); 184 | 185 | final paramsText = _customSplit(named); 186 | 187 | for (final paramText in paramsText) { 188 | final anatomicParamText = paramText.split(' '); 189 | 190 | final type = anatomicParamText[anatomicParamText.length - 2]; 191 | final named = Symbol(anatomicParamText.last); 192 | 193 | final param = NamedParam( 194 | isRequired: anatomicParamText.contains('required'), 195 | named: named, 196 | isNullable: type.endsWith('?'), 197 | className: type.replaceFirst('?', ''), 198 | ); 199 | 200 | params.add(param); 201 | } 202 | } 203 | 204 | if (allArgs.isNotEmpty) { 205 | final paramList = _customSplit(allArgs); 206 | final allParam = paramList // 207 | .map((e) => e.trim()) 208 | .where((e) => e.isNotEmpty) 209 | .map((e) { 210 | return PositionalParam( 211 | className: e.replaceFirst('?', ''), 212 | isNullable: e.endsWith('?'), 213 | isRequired: true, 214 | ); 215 | }).toList(); 216 | 217 | params.addAll(allParam); 218 | } 219 | 220 | return params; 221 | } 222 | 223 | static String _resolveClassName(String constructorString) { 224 | final typeName = T.toString(); 225 | final isDynamicOrObjectType = ['dynamic', 'Object'].contains(typeName); 226 | if (!isDynamicOrObjectType) return typeName; 227 | 228 | final className = constructorString.split(' => ').last; 229 | return className; 230 | } 231 | } 232 | -------------------------------------------------------------------------------- /lib/src/exceptions/exceptions.dart: -------------------------------------------------------------------------------- 1 | /// AutoInjection Exception with ToString auto configured 2 | ///
3 | /// [message] : message of exception
4 | /// [stackTrace] : traces of exception 5 | class AutoInjectorException implements Exception { 6 | /// message of exception 7 | final String message; 8 | 9 | /// traces of exception 10 | final StackTrace? stackTrace; 11 | 12 | /// AutoInjection Exception with ToString auto configured 13 | AutoInjectorException(this.message, [this.stackTrace]); 14 | 15 | // ignore: no_runtimetype_tostring 16 | late final String _typeName = '$runtimeType'; 17 | 18 | @override 19 | String toString() { 20 | var message = '$_typeName: ${this.message}'; 21 | if (stackTrace != null) { 22 | message = '$message\n$stackTrace'; 23 | } 24 | 25 | return message; 26 | } 27 | } 28 | 29 | /// AutoInjection Exception for Unregistered instance. 30 | ///
31 | /// Store all parent classNames 32 | /// [message] : message of exception
33 | /// [stackTrace] : traces of exception
34 | /// [classNames] : all parent class names 35 | class UnregisteredInstance extends AutoInjectorException { 36 | /// all parent class names; 37 | final List classNames; 38 | 39 | /// AutoInjection Exception for Unregistered instance. 40 | ///
41 | /// Store all parent classNames 42 | /// [message] : message of exception
43 | /// [stackTrace] : traces of exception
44 | /// [classNames] : all parent class names 45 | UnregisteredInstance(this.classNames, [super.message = '', super.stackTrace]); 46 | 47 | @override 48 | String toString() { 49 | var message = '$_typeName: ${this.message}\n${classNames.join(' => ')}'; 50 | if (stackTrace != null) { 51 | message = '$message\n$stackTrace'; 52 | } 53 | 54 | return message; 55 | } 56 | 57 | /// instance with stackTrace prints 58 | UnregisteredInstance withExceptionTrace() { 59 | final trace = classNames.join('->'); 60 | var message = this.message; 61 | if (classNames.length > 1) { 62 | message = '$message\nTrace: $trace'; 63 | } 64 | return UnregisteredInstance(classNames, message); 65 | } 66 | } 67 | 68 | /// AutoInjection Exception for Unregistered instance. 69 | ///
70 | /// Store all parent classNames 71 | /// [message] : message of exception
72 | /// [stackTrace] : traces of exception
73 | class UnregisteredInstanceByKey extends AutoInjectorException { 74 | /// all parent class names; 75 | final List keys; 76 | 77 | /// AutoInjection Exception for Unregistered instance. 78 | ///
79 | /// Store all parent classNames 80 | /// [message] : message of exception
81 | /// [stackTrace] : traces of exception
82 | /// [keys] : all parent keys 83 | UnregisteredInstanceByKey(this.keys, [super.message = '', super.stackTrace]); 84 | 85 | @override 86 | String toString() { 87 | var message = '$_typeName: ${this.message}\n${keys.join(' => ')}'; 88 | if (stackTrace != null) { 89 | message = '$message\n$stackTrace'; 90 | } 91 | 92 | return message; 93 | } 94 | } 95 | 96 | /// AutoInjecton Exception for Injector Already Commited. 97 | ///
98 | /// Store all parent classNames 99 | /// [message] : message of exception
100 | /// [stackTrace] : traces of exception
101 | /// [injectorTag] : tag of the current injector 102 | class InjectorAlreadyCommited extends AutoInjectorException { 103 | /// all parent class names; 104 | final String injectorTag; 105 | 106 | /// AutoInjecton Exception for Injector Already Commited. 107 | ///
108 | /// Store all parent classNames 109 | /// [message] : message of exception
110 | /// [stackTrace] : traces of exception
111 | /// [injectorTag] : tag of the current injector 112 | InjectorAlreadyCommited( 113 | this.injectorTag, [ 114 | super.message = '', 115 | super.stackTrace, 116 | ]); 117 | 118 | @override 119 | String toString() { 120 | var message = '$_typeName: ${this.message}' 121 | '\nAutoInjector(tag: $injectorTag)'; 122 | if (stackTrace != null) { 123 | message = '$message\n$stackTrace'; 124 | } 125 | 126 | return message; 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /lib/src/layers_graph.dart: -------------------------------------------------------------------------------- 1 | // ignore_for_file: public_member_api_docs, omit_local_variable_types 2 | 3 | part of 'auto_injector_base.dart'; 4 | 5 | class LayersGraph { 6 | final LinkedHashMap> adjacencyList; 7 | 8 | LayersGraph() 9 | : adjacencyList = LinkedHashMap( 10 | equals: (injector1, injector2) => injector1._tag == injector2._tag, 11 | hashCode: (injector) => injector._tag.hashCode, 12 | isValidKey: (key) => key is AutoInjectorImpl && key._tag.isNotEmpty, 13 | ); 14 | 15 | /// Fills the [adjacencyList] with this [injector] and its children tree. 16 | void initialize(AutoInjectorImpl injector) { 17 | _addInjector(injector); 18 | for (final innerInjector in injector.injectorsList) { 19 | _addEdge(injector, innerInjector); 20 | initialize(innerInjector); 21 | _removeWhenDispose( 22 | innerInjector: innerInjector, 23 | parentInjector: injector, 24 | ); 25 | } 26 | } 27 | 28 | /// Listen the [innerInjector] to remove it from this [LayersGraph]. 29 | void _removeWhenDispose({ 30 | required AutoInjectorImpl parentInjector, 31 | required AutoInjectorImpl innerInjector, 32 | }) { 33 | innerInjector.addDisposeListener(() { 34 | // Remove the adjacents of [innerInjector] on [adjacencyList] 35 | adjacencyList.remove(innerInjector); 36 | 37 | // Remove [innerInjector] from [parentInjector] on [adjacencyList] 38 | adjacencyList[parentInjector]?.remove(innerInjector); 39 | }); 40 | } 41 | 42 | /// Starts the [adjacencyList] for this [injector].

43 | /// **NOTE:** This function doesn't fill the [adjacencyList]. It only creates 44 | /// an empty adjacency list to this injector 45 | void _addInjector(AutoInjectorImpl injector) { 46 | adjacencyList[injector] = []; 47 | } 48 | 49 | void _addEdge(AutoInjectorImpl source, AutoInjectorImpl target) { 50 | adjacencyList[source]?.add(target); 51 | } 52 | 53 | /// Returns a MapEntry. The value is the found [Bind] and the key 54 | /// is the [AutoInjectorImpl] that have this bind. 55 | ///

**NOTE: Algorithm based on BFS (breadth-first search)** 56 | MapEntry? getBindByClassName( 57 | AutoInjectorImpl startInjector, { 58 | required String className, 59 | }) { 60 | final injector = getFirstInjectorWhere(startInjector, (currentInjector) { 61 | for (final Bind bind in currentInjector.binds) { 62 | if (bind.className == className) return true; 63 | } 64 | return false; 65 | }); 66 | if (injector == null) return null; 67 | final bind = 68 | injector.binds.firstWhere((bind) => bind.className == className); 69 | return MapEntry(injector, bind); 70 | } 71 | 72 | /// Returns a MapEntry. The value is the found [Bind] and the key 73 | /// is the [AutoInjectorImpl] that have this bind. 74 | ///

**NOTE: Algorithm based on BFS (breadth-first search)** 75 | MapEntry? getBindByKey( 76 | AutoInjectorImpl startInjector, { 77 | required String bindKey, 78 | }) { 79 | final injector = getFirstInjectorWhere(startInjector, (currentInjector) { 80 | for (final Bind bind in currentInjector.binds) { 81 | if (bind.key == bindKey) return true; 82 | } 83 | return false; 84 | }); 85 | if (injector == null) return null; 86 | final bind = injector.binds.firstWhere((bind) => bind.key == bindKey); 87 | return MapEntry(injector, bind); 88 | } 89 | 90 | /// Execute [callback] in all the injectors. 91 | ///

**NOTE: Algorithm based on BFS (breadth-first search)** 92 | void executeInAllInjectors( 93 | AutoInjectorImpl startInjector, 94 | T Function(AutoInjectorImpl) callback, 95 | ) { 96 | final visited = {}; 97 | final queue = Queue(); 98 | queue.add(startInjector); 99 | 100 | while (queue.isNotEmpty) { 101 | final currentInjector = queue.removeFirst(); 102 | callback(currentInjector); 103 | 104 | if (adjacencyList[currentInjector] == null) continue; 105 | 106 | for (final adjacentInjector in adjacencyList[currentInjector]!) { 107 | if (!visited.contains(adjacentInjector)) { 108 | visited.add(adjacentInjector); 109 | queue.add(adjacentInjector); 110 | } 111 | } 112 | } 113 | } 114 | 115 | /// Returns the first injector that pass in the [validation]. 116 | ///

**NOTE: Algorithm based on BFS (breadth-first search)** 117 | AutoInjectorImpl? getFirstInjectorWhere( 118 | AutoInjectorImpl startInjector, 119 | bool Function(AutoInjectorImpl) validation, 120 | ) { 121 | final visited = {}; 122 | final queue = Queue(); 123 | queue.add(startInjector); 124 | 125 | while (queue.isNotEmpty) { 126 | final currentInjector = queue.removeFirst(); 127 | if (validation(currentInjector)) { 128 | return currentInjector; 129 | } 130 | 131 | if (adjacencyList[currentInjector] == null) continue; 132 | 133 | for (final adjacentInjector in adjacencyList[currentInjector]!) { 134 | if (!visited.contains(adjacentInjector)) { 135 | visited.add(adjacentInjector); 136 | queue.add(adjacentInjector); 137 | } 138 | } 139 | } 140 | return null; 141 | } 142 | 143 | void reset() { 144 | adjacencyList.clear(); 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /lib/src/param.dart: -------------------------------------------------------------------------------- 1 | // ignore_for_file: public_member_api_docs 2 | 3 | import 'package:meta/meta.dart'; 4 | 5 | typedef ParamTransform = Param? Function(Param param); 6 | 7 | ParamTransform changeParam(T newValue) { 8 | return (param) { 9 | if (T.toString() == param.className) { 10 | return param.setValue(newValue); 11 | } 12 | return null; 13 | }; 14 | } 15 | 16 | @sealed 17 | abstract class Param { 18 | final String className; 19 | final bool isNullable; 20 | final bool isRequired; 21 | 22 | bool get injectableParam => !isNullable && isRequired; 23 | 24 | /// instance of param 25 | final dynamic value; 26 | 27 | Param({ 28 | required this.className, 29 | this.isNullable = false, 30 | this.value, 31 | this.isRequired = true, 32 | }); 33 | 34 | /// return a new instance of Param with value 35 | Param setValue(dynamic value); 36 | } 37 | 38 | @sealed 39 | class NamedParam extends Param { 40 | final Symbol named; 41 | 42 | NamedParam({ 43 | required super.className, 44 | super.value, 45 | required this.named, 46 | super.isNullable = false, 47 | bool isRequired = false, 48 | }) : super(isRequired: isRequired); 49 | 50 | @override 51 | NamedParam setValue(dynamic value) { 52 | return NamedParam( 53 | named: named, 54 | className: className, 55 | isNullable: isNullable, 56 | isRequired: isNullable, 57 | value: value, 58 | ); 59 | } 60 | } 61 | 62 | @sealed 63 | class PositionalParam extends Param { 64 | PositionalParam({ 65 | required super.className, 66 | required super.isRequired, 67 | super.value, 68 | super.isNullable = false, 69 | }); 70 | 71 | @override 72 | PositionalParam setValue(dynamic value) { 73 | return PositionalParam( 74 | className: className, 75 | isNullable: isNullable, 76 | value: value, 77 | isRequired: isRequired, 78 | ); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: auto_injector 2 | description: Automatic Dependency Injection System, but without build_runner :) 3 | version: 2.1.0 4 | repository: https://github.com/Flutterando/auto_injector 5 | 6 | environment: 7 | sdk: ">=3.0.0 <4.0.0" 8 | 9 | dependencies: 10 | meta: ">=1.11.0 <2.0.0" 11 | uuid: ^4.2.1 12 | 13 | dev_dependencies: 14 | flutterando_analysis: ^0.0.2 15 | test: ^1.16.0 16 | watcher: ^1.1.0 17 | -------------------------------------------------------------------------------- /readme_assets/logo-auto-injection.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/auto_injector/45719fbe86aae201d2feae0c3f462b0f875a2de6/readme_assets/logo-auto-injection.png -------------------------------------------------------------------------------- /test/src/exceptions/exceptions_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:auto_injector/auto_injector.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | void main() { 5 | test('errors message', () async { 6 | final error = AutoInjectorException('Test', StackTrace.empty); 7 | expect(error.toString(), 'AutoInjectorException: Test\n'); 8 | }); 9 | } 10 | --------------------------------------------------------------------------------