Support cycles?
tom-sherman opened this issue · comments
Not sure if this is sound as preventing cycles seems like a noble goal, many environments get by without cycles. But maybe there are use cases where cycles are needed, where they are unavoidable?
Could be supported in the form of a higher-order-factory (like singleton
)
const container = createContainer().register(
"cyclicSubGraph",
cycle({
a: func(a, 'b'),
b: func(b, 'a'),
})
);
const { a, b } = container.resolve('cyclicSubGraph');
If this feature is valuable something like the above would allow cycles to be explicit, local, and opt-in.
I would not go for that. Cycles are almost always a very bad symptom of architectural problems. The only acceptable case that comes to my mind are "ORM entities", but they are not really loaded via IoC containers anyway.