##// END OF EJS Templates
Removed ContextResolver, added DescriptoBuilder.wants(...), dependencies are declared statically
Removed ContextResolver, added DescriptoBuilder.wants(...), dependencies are declared statically

File last commit:

r4:d9e74143f779 default
r4:d9e74143f779 default
Show More
container.ts
64 lines | 1.4 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 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;
}
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", // зависимость
zoo$: { name: "zoo", lazy: true } // отложенная активация,
//фабричный метод
})
.factory(({ zoo$ }) => // фабрика получает объект с именованными зависимостями
// удобно для деструктурирования
new Bar(zoo$) // создается экземпляр сервиса
),
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
Removed ContextResolver, added DescriptoBuilder.wants(...), dependencies are declared statically
r4 declare const container: Container<Record<string, never>>;
cin
working on fluent configuration
r1 const c2 = config.apply(container);
cin
Removed ContextResolver, added DescriptoBuilder.wants(...), dependencies are declared statically
r4 c2.resolve("foo");