• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Willian199 / dart_ddi / 16251761257

13 Jul 2025 05:38PM UTC coverage: 84.744% (+1.7%) from 83.056%
16251761257

push

github

web-flow
Feature/rework custom scopes (#26)

* This version brings a major rework to be able to use Custom Scopes.
* Now you can create your own Scopes.
* Added support to Zoned instances with
`DDI.instance.runInZone("zone_name", () => factory)`.

* Break changes:
* Removed the `Session Scope` and correlated methods. Use `Application`
instead.
* Now the `YourClazz.new.builder.asApplication()` shortcut registers
directly into ddi. You no longer need to call `.register()`.
* Now the custom factory requires to specify the Scope Factory and the
builder.

531 of 548 new or added lines in 16 files covered. (96.9%)

10 existing lines in 1 file now uncovered.

661 of 780 relevant lines covered (84.74%)

12.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

23.14
/lib/src/extension/function_extension.dart
1
import 'dart:async';
2

3
import 'package:dart_ddi/dart_ddi.dart';
4

5
/// Extensions to easily create [CustomBuilder]s for functions with different numbers of parameters.
6
///
7
/// These extensions allow you to convert a function (sync or async) with up to 10 parameters into a [CustomBuilder],
8
/// which is used by the DDI system to register factories with parameterized constructors or async creation.
9
///
10
/// Example:
11
/// ```dart
12
/// // For a function with no parameters
13
/// MyService.new.builder.asApplication();
14
///
15
/// // For a function with one parameter
16
/// ((String name) => MyService(name)).builder.asApplication();
17
///
18
/// // For an async function
19
/// (() async => await MyService.create()).builder.asApplication();
20
/// ```
21

22
/// Extension for functions with 0 parameters (sync)
23
extension P0<BeanT extends Object> on BeanT Function() {
24
  /// Returns an empty list, as there are no parameters.
25
  List<Type> get parameters => [];
66✔
26

27
  /// Returns the return type of the function.
28
  Type get returnType => BeanT;
33✔
29

30
  /// Converts this function into a [CustomBuilder].
31
  CustomBuilder<BeanT> get builder => CustomBuilder<BeanT>(
66✔
32
        producer: this,
33
        parametersType: parameters,
33✔
34
        returnType: returnType,
33✔
35
        isFuture: this is Future<Object> Function(),
33✔
36
      );
37
}
38

39
/// Extension for functions with 0 parameters (async)
40
extension PF0<BeanT extends Object> on Future<BeanT> Function() {
41
  /// Returns an empty list, as there are no parameters.
42
  List<Type> get parameters => [];
18✔
43

44
  /// Returns the return type of the function.
45
  Type get returnType => BeanT;
9✔
46

47
  /// Converts this async function into a [CustomBuilder].
48
  CustomBuilder<BeanT> get builder => CustomBuilder<BeanT>(
18✔
49
        producer: this,
50
        parametersType: parameters,
9✔
51
        returnType: returnType,
9✔
52
        isFuture: true,
53
      );
54
}
55

56
/// Extension for functions with 1 parameter (sync)
57
extension P1<BeanT extends Object, A> on BeanT Function(A) {
58
  /// Returns a list with the type of the parameter.
59
  List<Type> get parameters => [A];
14✔
60

61
  /// Returns the return type of the function.
62
  Type get returnType => BeanT;
7✔
63

64
  /// Converts this function into a [CustomBuilder].
65
  CustomBuilder<BeanT> get builder => CustomBuilder<BeanT>(
14✔
66
        producer: this,
67
        parametersType: parameters,
7✔
68
        returnType: returnType,
7✔
69
        isFuture: this is Future<Object> Function(A),
7✔
70
      );
71
}
72

73
/// Extension for functions with 1 parameter (async)
74
extension PF1<BeanT extends Object, A> on Future<BeanT> Function(A) {
75
  /// Returns a list with the type of the parameter.
76
  List<Type> get parameters => [A];
8✔
77

78
  /// Returns the return type of the function.
79
  Type get returnType => BeanT;
4✔
80

81
  /// Converts this async function into a [CustomBuilder].
82
  CustomBuilder<BeanT> get builder => CustomBuilder<BeanT>(
8✔
83
        producer: this,
84
        parametersType: parameters,
4✔
85
        returnType: returnType,
4✔
86
        isFuture: true,
87
      );
88
}
89

90
/// Extension for functions with 2 parameters (sync)
91
extension P2<BeanT extends Object, A, B> on BeanT Function(A, B) {
92
  /// Returns a list with the types of the parameters.
93
  List<Type> get parameters => [A, B];
×
94

95
  /// Returns the return type of the function.
96
  Type get returnType => BeanT;
×
97

98
  /// Converts this function into a [CustomBuilder].
UNCOV
99
  CustomBuilder<BeanT> get builder => CustomBuilder<BeanT>(
×
100
        producer: this,
101
        parametersType: parameters,
×
102
        returnType: returnType,
×
103
        isFuture: this is Future<Object> Function(A, B),
×
104
      );
105
}
106

107
/// Extension for functions with 2 parameters (async)
108
extension PF2<BeanT extends Object, A, B> on Future<BeanT> Function(A, B) {
109
  /// Returns a list with the types of the parameters.
110
  List<Type> get parameters => [A, B];
×
111

112
  /// Returns the return type of the function.
113
  Type get returnType => BeanT;
×
114

115
  /// Converts this async function into a [CustomBuilder].
UNCOV
116
  CustomBuilder<BeanT> get builder => CustomBuilder<BeanT>(
×
117
        producer: this,
118
        parametersType: parameters,
×
119
        returnType: returnType,
×
120
        isFuture: true,
121
      );
122
}
123

124
/// Extension for functions with 3 parameters (sync)
125
extension P3<BeanT extends Object, A, B, C> on BeanT Function(A, B, C) {
126
  /// Returns a list with the types of the parameters.
127
  List<Type> get parameters => [A, B, C];
14✔
128

129
  /// Returns the return type of the function.
130
  Type get returnType => BeanT;
7✔
131

132
  /// Converts this function into a [CustomBuilder].
133
  CustomBuilder<BeanT> get builder => CustomBuilder<BeanT>(
14✔
134
        producer: this,
135
        parametersType: parameters,
7✔
136
        returnType: returnType,
7✔
137
        isFuture: this is Future<Object> Function(A, B, C),
7✔
138
      );
139
}
140

141
/// Extension for functions with 3 parameters (async)
142
extension PF3<BeanT extends Object, A, B, C> on Future<BeanT> Function(
143
    A, B, C) {
144
  /// Returns a list with the types of the parameters.
145
  List<Type> get parameters => [A, B, C];
×
146

147
  /// Returns the return type of the function.
148
  Type get returnType => BeanT;
×
149

150
  /// Converts this async function into a [CustomBuilder].
UNCOV
151
  CustomBuilder<BeanT> get builder => CustomBuilder<BeanT>(
×
152
        producer: this,
153
        parametersType: parameters,
×
154
        returnType: returnType,
×
155
        isFuture: true,
156
      );
157
}
158

159
/// Extension for functions with 4 parameters (sync)
160
extension P4<BeanT extends Object, A, B, C, D> on BeanT Function(A, B, C, D) {
161
  /// Returns a list with the types of the parameters.
162
  List<Type> get parameters => [A, B, C, D];
×
163

164
  /// Returns the return type of the function.
165
  Type get returnType => BeanT;
×
166

167
  /// Converts this function into a [CustomBuilder].
UNCOV
168
  CustomBuilder<BeanT> get builder => CustomBuilder<BeanT>(
×
169
        producer: this,
170
        parametersType: parameters,
×
171
        returnType: returnType,
×
172
        isFuture: this is Future<Object> Function(A, B, C, D),
×
173
      );
174
}
175

176
/// Extension for functions with 4 parameters (async)
177
extension PF4<BeanT extends Object, A, B, C, D> on Future<BeanT> Function(
178
    A, B, C, D) {
179
  /// Returns a list with the types of the parameters.
180
  List<Type> get parameters => [A, B, C, D];
×
181

182
  /// Returns the return type of the function.
183
  Type get returnType => BeanT;
×
184

185
  /// Converts this async function into a [CustomBuilder].
UNCOV
186
  CustomBuilder<BeanT> get builder => CustomBuilder<BeanT>(
×
187
        producer: this,
188
        parametersType: parameters,
×
189
        returnType: returnType,
×
190
        isFuture: true,
191
      );
192
}
193

194
/// Extension for functions with 5 parameters (sync)
195
extension P5<BeanT extends Object, A, B, C, D, E> on BeanT Function(
196
    A, B, C, D, E) {
197
  /// Returns a list with the types of the parameters.
198
  List<Type> get parameters => [A, B, C, D, E];
×
199

200
  /// Returns the return type of the function.
201
  Type get returnType => BeanT;
×
202

203
  /// Converts this function into a [CustomBuilder].
UNCOV
204
  CustomBuilder<BeanT> get builder => CustomBuilder<BeanT>(
×
205
        producer: this,
206
        parametersType: parameters,
×
207
        returnType: returnType,
×
208
        isFuture: this is Future<Object> Function(A, B, C, D, E),
×
209
      );
210
}
211

212
/// Extension for functions with 5 parameters (async)
213
extension PF5<BeanT extends Object, A, B, C, D, E> on Future<BeanT> Function(
214
    A, B, C, D, E) {
215
  /// Returns a list with the types of the parameters.
216
  List<Type> get parameters => [A, B, C, D, E];
×
217

218
  /// Returns the return type of the function.
219
  Type get returnType => BeanT;
×
220

221
  /// Converts this async function into a [CustomBuilder].
UNCOV
222
  CustomBuilder<BeanT> get builder => CustomBuilder<BeanT>(
×
223
        producer: this,
224
        parametersType: parameters,
×
225
        returnType: returnType,
×
226
        isFuture: true,
227
      );
228
}
229

230
/// Extension for functions with 6 parameters (sync)
231
extension P6<BeanT extends Object, A, B, C, D, E, F> on BeanT Function(
232
    A, B, C, D, E, F) {
233
  /// Returns a list with the types of the parameters.
234
  List<Type> get parameters => [A, B, C, D, E, F];
×
235

236
  /// Returns the return type of the function.
237
  Type get returnType => BeanT;
×
238

239
  /// Converts this function into a [CustomBuilder].
UNCOV
240
  CustomBuilder<BeanT> get builder => CustomBuilder<BeanT>(
×
241
        producer: this,
242
        parametersType: parameters,
×
243
        returnType: returnType,
×
244
        isFuture: this is Future<Object> Function(A, B, C, D, E, F),
×
245
      );
246
}
247

248
/// Extension for functions with 6 parameters (async)
249
extension PF6<BeanT extends Object, A, B, C, D, E, F> on BeanT Function(
250
    A, B, C, D, E, F) {
251
  /// Returns a list with the types of the parameters.
252
  List<Type> get parameters => [A, B, C, D, E, F];
×
253

254
  /// Returns the return type of the function.
255
  Type get returnType => BeanT;
×
256

257
  /// Converts this async function into a [CustomBuilder].
UNCOV
258
  CustomBuilder<BeanT> get builder => CustomBuilder<BeanT>(
×
259
        producer: this,
260
        parametersType: parameters,
×
261
        returnType: returnType,
×
262
        isFuture: true,
263
      );
264
}
265

266
/// Extension for functions with 7 parameters (sync)
267
extension P7<BeanT extends Object, A, B, C, D, E, F, G> on BeanT Function(
268
    A, B, C, D, E, F, G) {
269
  /// Returns a list with the types of the parameters.
270
  List<Type> get parameters => [A, B, C, D, E, F, G];
×
271

272
  /// Returns the return type of the function.
273
  Type get returnType => BeanT;
×
274

275
  /// Converts this function into a [CustomBuilder].
UNCOV
276
  CustomBuilder<BeanT> get builder => CustomBuilder<BeanT>(
×
277
        producer: this,
278
        parametersType: parameters,
×
279
        returnType: returnType,
×
280
        isFuture: this is Future<Object> Function(A, B, C, D, E, F, G),
×
281
      );
282
}
283

284
extension PF7<BeanT extends Object, A, B, C, D, E, F, G> on Future<BeanT>
285
    Function(A, B, C, D, E, F, G) {
286
  List<Type> get parameters => [A, B, C, D, E, F, G];
×
287
  Type get returnType => BeanT;
×
288
  CustomBuilder<BeanT> get builder => CustomBuilder<BeanT>(
×
289
        producer: this,
290
        parametersType: parameters,
×
291
        returnType: returnType,
×
292
        isFuture: true,
293
      );
294
}
295

296
extension P8<BeanT extends Object, A, B, C, D, E, F, G, H> on BeanT Function(
297
    A, B, C, D, E, F, G, H) {
298
  List<Type> get parameters => [A, B, C, D, E, F, G, H];
×
299
  Type get returnType => BeanT;
×
300
  CustomBuilder<BeanT> get builder => CustomBuilder<BeanT>(
×
301
        producer: this,
302
        parametersType: parameters,
×
303
        returnType: returnType,
×
304
        isFuture: this is Future<Object> Function(A, B, C, D, E, F, G, H),
×
305
      );
306
}
307

308
extension PF8<BeanT extends Object, A, B, C, D, E, F, G, H> on Future<BeanT>
309
    Function(A, B, C, D, E, F, G, H) {
310
  List<Type> get parameters => [A, B, C, D, E, F, G, H];
×
311
  Type get returnType => BeanT;
×
312
  CustomBuilder<BeanT> get builder => CustomBuilder<BeanT>(
×
313
        producer: this,
314
        parametersType: parameters,
×
315
        returnType: returnType,
×
316
        isFuture: true,
317
      );
318
}
319

320
extension P9<BeanT extends Object, A, B, C, D, E, F, G, H, I> on BeanT Function(
321
    A, B, C, D, E, F, G, H, I) {
322
  List<Type> get parameters => [A, B, C, D, E, F, G, H, I];
×
323
  Type get returnType => BeanT;
×
324
  CustomBuilder<BeanT> get builder => CustomBuilder<BeanT>(
×
325
        producer: this,
326
        parametersType: parameters,
×
327
        returnType: returnType,
×
328
        isFuture: this is Future<Object> Function(A, B, C, D, E, F, G, H, I),
×
329
      );
330
}
331

332
extension PF9<BeanT extends Object, A, B, C, D, E, F, G, H, I> on Future<BeanT>
333
    Function(A, B, C, D, E, F, G, H, I) {
334
  List<Type> get parameters => [A, B, C, D, E, F, G, H, I];
×
335
  Type get returnType => BeanT;
×
336
  CustomBuilder<BeanT> get builder => CustomBuilder<BeanT>(
×
337
        producer: this,
338
        parametersType: parameters,
×
339
        returnType: returnType,
×
340
        isFuture: true,
341
      );
342
}
343

344
extension P10<BeanT extends Object, A, B, C, D, E, F, G, H, I, J> on BeanT
345
    Function(A, B, C, D, E, F, G, H, I, J) {
346
  List<Type> get parameters => [A, B, C, D, E, F, G, H, I, J];
×
347
  Type get returnType => BeanT;
×
348
  CustomBuilder<BeanT> get builder => CustomBuilder<BeanT>(
×
349
        producer: this,
350
        parametersType: parameters,
×
351
        returnType: returnType,
×
352
        isFuture: this is Future<Object> Function(A, B, C, D, E, F, G, H, I, J),
×
353
      );
354
}
355

356
extension PF10<BeanT extends Object, A, B, C, D, E, F, G, H, I, J>
357
    on Future<BeanT> Function(A, B, C, D, E, F, G, H, I, J) {
358
  List<Type> get parameters => [A, B, C, D, E, F, G, H, I, J];
×
359
  Type get returnType => BeanT;
×
360
  CustomBuilder<BeanT> get builder => CustomBuilder<BeanT>(
×
361
        producer: this,
362
        parametersType: parameters,
×
363
        returnType: returnType,
×
364
        isFuture: true,
365
      );
366
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc