##// END OF EJS Templates
working on typings
working on typings

File last commit:

r8:80cb5668e4a7 default
r8:80cb5668e4a7 default
Show More
container.ts
99 lines | 2.3 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";
import { ConfigurableKeys, ContainerProvided, ContainerServices, DepsMap, Refs, Resolver } 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
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>;
const foo = resolver("foo", {lazy: true});
cin
working on typings
r8 const mmap = <X extends DepsMap<Services>>(m: X) => {};
declare const refs: Refs<Services>;
cin
improved typings
r7
cin
working on typings
r8 if (refs && refs.name === "foo") {
refs.default;
}
declare const x: ContainerServices<Services>;
x.container.resolve("container");
cin
improved typings
r7
mmap({
fooz: {name: "foo", lazy: false, default: undefined },
ooz: "bar"
});
cin
working on fluent configuration
r1 interface SharedServices {
foo: Foo;
bar?: Bar;
baz: Bar;
}
const config = fluent()
.declare<Services>()
.declare<ServicesB>()
.register({
cin
working on typings
r8 zoo: it => {},
cin
working on fluent configuration
r1 bar: it => it
cin
Removed ContextResolver, added DescriptoBuilder.wants(...), dependencies are declared statically
r4 .lifetime("context") // тип активации, время жизни
.wants({
zoo: "zoo", // зависимость
cin
improved typings
r7 bar: "bar",
cin
Removed ContextResolver, added DescriptoBuilder.wants(...), dependencies are declared statically
r4
cin
improved typings
r7 $zoo: { name: "foo", lazy: true, } // отложенная активация,
cin
Removed ContextResolver, added DescriptoBuilder.wants(...), dependencies are declared statically
r4 //фабричный метод
})
cin
improved typings
r7 .wants({
zoom: "bar"
})
.factory(({ $zoo, zoo }) => // фабрика получает объект с именованными зависимостями
cin
Removed ContextResolver, added DescriptoBuilder.wants(...), dependencies are declared statically
r4 // удобно для деструктурирования
cin
improved typings
r7 new Bar($zoo) // создается экземпляр сервиса
cin
Removed ContextResolver, added DescriptoBuilder.wants(...), dependencies are declared statically
r4 ),
foo: it => it.factory(() => new Foo()),
cin
working on fluent configuration
r1 baz: it => it.value(new Foo())
})
cin
code comments
r2 .done({});
cin
working on fluent configuration
r1
cin
working on typings
r8 declare const container: ContainerBuilder<{}>;
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");
declare const m :ContainerServices<{foo: Foo}>["container"];
cin
working on typings
r8 m.resolve("container").resolve("container").resolve("foo");