##// END OF EJS Templates
sync
sync

File last commit:

r13:dc3d64c43573 default
r15:3985e8405319 tip default
Show More
container.ts
106 lines | 2.5 KiB | video/mp2t | TypeScriptLexer
/ src / test / ts / t / container.ts
cin
working on fluent configuration
r1 /* eslint max-classes-per-file: ["error", 20] */
import { describe, it } from "mocha";
cin
Removed ContextResolver, added DescriptoBuilder.wants(...), dependencies are declared statically
r4 import { Container } from "../Container";
cin
working on typings
r8 import { ContainerBuilder } from "../ContainerBuilder";
cin
WIP service descriptors
r13 import { ContainerServices, DepsMap, IContainerBuilder, Refs, Resolver, ServiceLocator } from "../interfaces";
cin
working on fluent configuration
r1 import { fluent } from "../traits";
class Foo {
foo = "foo";
}
class Bar {
bar = "bar";
cin
Removed ContextResolver, added DescriptoBuilder.wants(...), dependencies are declared statically
r4 constructor(foo?: () => Foo) { }
cin
working on fluent configuration
r1 }
interface Services {
foo: Foo;
bar?: Bar;
baz: Foo;
cin
working on typings
r8
cin
almost woking typings
r9 box?: Foo;
//container: string;
cin
working on fluent configuration
r1 }
interface ServicesB {
// will give errors
// baz: Bar;
baz: Foo;
zoo?: Foo;
}
cin
improved typings
r7 declare const resolver: Resolver<Services>;
cin
almost woking typings
r9 const foo = resolver("foo", { lazy: true, default: null });
cin
improved typings
r7
cin
almost woking typings
r9 const mmap = <X extends DepsMap<Services>>(m: X) => { };
cin
working on typings
r8
declare const refs: Refs<Services>;
cin
improved typings
r7
cin
working on typings
r8 if (refs && refs.name === "foo") {
refs.default;
}
cin
WIP service descriptors
r13 declare const x: ServiceLocator<ContainerServices<Services>>;
cin
working on typings
r8
cin
WIP service descriptors
r13 x.resolve("container").resolve("container");
cin
working on typings
r8
cin
improved typings
r7
mmap({
cin
almost woking typings
r9 fooz: { name: "foo", lazy: false, default: undefined },
ooz: "bar"
cin
improved typings
r7 });
cin
working on fluent configuration
r1 interface SharedServices {
foo: Foo;
bar?: Bar;
baz: Bar;
}
cin
almost woking typings
r9 const config = fluent<Services>()
cin
working on fluent configuration
r1 .declare<ServicesB>()
.register({
cin
almost woking typings
r9 zoo: it => it.value(new Foo()),
cin
working on fluent configuration
r1 bar: it => it
cin
Removed ContextResolver, added DescriptoBuilder.wants(...), dependencies are declared statically
r4 .lifetime("context") // тип активации, время жизни
.wants({
cin
almost woking typings
r9 self: "container",
childContainer: "childContainer",
cin
improved typings
r7 bar: "bar",
cin
almost woking typings
r9 foo$: { name: "foo", lazy: true } // отложенная активация, фабричный метод
cin
Removed ContextResolver, added DescriptoBuilder.wants(...), dependencies are declared statically
r4 })
cin
almost woking typings
r9 .override({ // переопределение сервиса
box: it => it.factory(() => new Foo())
cin
improved typings
r7 })
cin
almost woking typings
r9 .factory(({ foo$, bar, self, childContainer }) => // фабрика получает объект с именованными зависимостями
new Bar(foo$) // создается экземпляр сервиса
cin
Removed ContextResolver, added DescriptoBuilder.wants(...), dependencies are declared statically
r4 ),
foo: it => it.factory(() => new Foo()),
cin
almost woking typings
r9 baz: it => it.value(new Foo()),
//box: it => it.factory(() => new Foo())
cin
working on fluent configuration
r1 })
cin
almost woking typings
r9 .done();
declare const container: IContainerBuilder<ContainerServices<Services>, keyof Services>;
cin
working on fluent configuration
r1
cin
almost woking typings
r9 const v = container.build().resolve("foo");
if (v) {
// noop
}
cin
Working on container builder
r5 const c2 = config.configure(container);
cin
working on fluent configuration
r1
cin
Working on container builder
r5 c2.resolve("foo");
cin
almost woking typings
r9 declare const m: ContainerServices<{ foo?: Foo }>["container"];
cin
Working on container builder
r5
cin
working on typings
r8 m.resolve("container").resolve("container").resolve("foo");