mirror of
https://github.com/pese-git/cherrypick.git
synced 2026-01-23 21:13:35 +00:00
implemented toFactory8 method
This commit is contained in:
@@ -149,8 +149,16 @@ class ResolvingContext<T> extends Resolver {
|
||||
*/
|
||||
ResolvingContext<T> toFactory8<T1, T2, T3, T4, T5, T6, T7, T8>(
|
||||
T Function(T1, T2, T3, T4, T5, T6, T7, T8) factory) {
|
||||
// TODO: implement toFactory8
|
||||
throw UnimplementedError();
|
||||
Resolver<T> resolver = FactoryResolver<T>(() => factory(
|
||||
_container.resolve<T1>(),
|
||||
_container.resolve<T2>(),
|
||||
_container.resolve<T3>(),
|
||||
_container.resolve<T4>(),
|
||||
_container.resolve<T5>(),
|
||||
_container.resolve<T6>(),
|
||||
_container.resolve<T7>(),
|
||||
_container.resolve<T8>()));
|
||||
return toResolver(resolver);
|
||||
}
|
||||
|
||||
void _verify() {
|
||||
|
||||
@@ -273,6 +273,37 @@ void main() {
|
||||
expect(container.resolve<DependOnABCDEFG>().f, f);
|
||||
expect(container.resolve<DependOnABCDEFG>().g, g);
|
||||
});
|
||||
|
||||
test("Bind to the factory resolves with 8 value", () {
|
||||
final container = DiContainer();
|
||||
final a = AA();
|
||||
final b = BB();
|
||||
final c = CC();
|
||||
final d = DD();
|
||||
final e = EE();
|
||||
final f = FF();
|
||||
final g = GG();
|
||||
final h = HH();
|
||||
container.bind<A>().toValue(a);
|
||||
container.bind<B>().toValue(b);
|
||||
container.bind<C>().toValue(c);
|
||||
container.bind<D>().toValue(d);
|
||||
container.bind<E>().toValue(e);
|
||||
container.bind<F>().toValue(f);
|
||||
container.bind<G>().toValue(g);
|
||||
container.bind<H>().toValue(h);
|
||||
container.bind<DependOnABCDEFGH>().toFactory8<A, B, C, D, E, F, G, H>(
|
||||
(a, b, c, d, e, f, g, h) => DependOnABCDEFGH(a, b, c, d, e, f, g, h));
|
||||
|
||||
expect(container.resolve<DependOnABCDEFGH>().a, a);
|
||||
expect(container.resolve<DependOnABCDEFGH>().b, b);
|
||||
expect(container.resolve<DependOnABCDEFGH>().c, c);
|
||||
expect(container.resolve<DependOnABCDEFGH>().d, d);
|
||||
expect(container.resolve<DependOnABCDEFGH>().e, e);
|
||||
expect(container.resolve<DependOnABCDEFGH>().f, f);
|
||||
expect(container.resolve<DependOnABCDEFGH>().g, g);
|
||||
expect(container.resolve<DependOnABCDEFGH>().h, h);
|
||||
});
|
||||
}
|
||||
|
||||
ResolverMock<T> _makeResolver<T>(T expectedValue) {
|
||||
@@ -311,6 +342,10 @@ abstract class G {}
|
||||
|
||||
class GG implements G {}
|
||||
|
||||
abstract class H {}
|
||||
|
||||
class HH implements H {}
|
||||
|
||||
class DependOnA {
|
||||
final A a;
|
||||
|
||||
@@ -389,3 +424,25 @@ class DependOnABCDEFG {
|
||||
f != null &&
|
||||
g != null);
|
||||
}
|
||||
|
||||
class DependOnABCDEFGH {
|
||||
final A a;
|
||||
final B b;
|
||||
final C c;
|
||||
final D d;
|
||||
final E e;
|
||||
final F f;
|
||||
final G g;
|
||||
final H h;
|
||||
|
||||
DependOnABCDEFGH(
|
||||
this.a, this.b, this.c, this.d, this.e, this.f, this.g, this.h)
|
||||
: assert(a != null &&
|
||||
b != null &&
|
||||
c != null &&
|
||||
d != null &&
|
||||
e != null &&
|
||||
f != null &&
|
||||
g != null &&
|
||||
h != null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user