##// END OF EJS Templates
improved typings
improved typings

File last commit:

r7:58282d42a47b default
r7:58282d42a47b default
Show More
container.ts
86 lines | 2.0 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
improved typings
r7 import { 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;
}
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});
const mmap = <X extends DepsMap<Services, string>>(m: X) => {};
const refs: Refs<Services> = {name: "bar", default: undefined};
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({
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 container builder
r5 declare const container: Container<object>;
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"];
m.resolve("container").resolve("container");