快照与Castle Windsor儿童容器(Snapshots with Castle Windsor child containers)
在阅读关于由NServiceBus 3支持子容器的页面( http://docs.particular.net/nservicebus/containers/child-containers )之后,我期望在Castle Windsor中父容器中的瞬态组件像单例一样儿童容器 。 但是,每次从子容器中获取这些父组件的依赖关系都会被实例化。
有没有办法在Castle Windsor实现父容器快照的这种行为? 换句话说,容器中的组件瞬态,如果从子容器中解析出来,则是单件。
After reading the page (http://docs.particular.net/nservicebus/containers/child-containers) regarding support for child containers by NServiceBus 3, I was expecting that in Castle Windsor transient components in the parent container behave like singletons for the child container. However dependencies of those parent components from the child containers are instantiated every time.
Is there a way to achieve this behavior of parent container snapshots in Castle Windsor? In other words, transient for component in the container, singleton if resolved from a child container.
原文:https://stackoverflow.com/questions/10450345
最满意答案
1)我希望使序列延迟不起作用,因为print会在打印之前评估实现它。 而是尝试
doseq
或(map print my-seq)
以较小的块打印它。2)是的将它包装在vec中会给你你想要的东西:)尽管用一个
into
包装你的reduce会让它一直保持向量。 即:((reduce into [] [[1] [2] [3]] )
- >[1 2 3]
(into out-log (sorted-map cmp-val (vector lnam fnam)))))
1) i expect that making the sequence lazy not to help because print will evaluate realize it before printing it. instead try
doseq
or(map print my-seq)
to print it in smaller chunks.2) yes wrapping it in vec will give you what you want :) though wrapping your reduce with an
into
would keep it a vector the whole time. ie:(reduce into [] [[1] [2] [3]] )
-->[1 2 3]
(into out-log (sorted-map cmp-val (vector lnam fnam)))))
相关问答
更多-
为什么减少这个懒惰的序列会减慢这个Clojure程序的速度20倍?(Why does reducing this lazy sequence slow down this Clojure program 20x?)[2022-06-25]
执行时间的差异是懒惰的结果。 在sum-of-even-fibonaccis-below-2你只产生一个懒惰的斐波那契数seq,它没有被实现(只有在sum-of-even-fibonaccis-below-2创建一个惰性序列,但不会评估所有内容)。 所以实际上你的第二time表达式不会返回一个值列表,而是一个懒惰的seq,只有当你要求它们时才会产生它的元素。 要强制实现惰性序列,可以使用dorun如果你不需要保存它作为一个值,或者如果你想获得已实现的seq(小心inifinite seqs),可以使用dor ... -
Clojure懒惰序列使用(Clojure lazy sequence usage)[2024-02-20]
一个lazy-seq调用在第一次被访问时就执行一次,然后在以后再次调用时缓存并返回相同的结果。 如果要使用它来构建长(或甚至无限)序列,则需要在返回的序列中递归地嵌套其他延迟序列调用。 这是关于我能想到的最简单的情况: (defn ints-from [n] (cons n (lazy-seq (ints-from (inc n))))) (take 10 (ints-from 7)) => (7 8 9 10 11 12 13 14 15 16) Any(ints - from n)调用产生一个以 ... -
所有你需要的 因为seq有类型LazySeq并不意味着它有待评估。 懒惰的seqs缓存他们的结果,所以你需要做的是步行懒惰seq一次(作为doall),以强制它,所以使它不懒惰。 seq不强制整个集合被评估。 doall is all you need. Just because the seq has type LazySeq doesn't mean it has pending evaluation. Lazy seqs cache their results, so all you need to ...
-
在惰性序列内部是否实现惰性序列的差异发生(Differences in whether realization of a lazy sequence inside of a lazy sequence occurs)[2022-07-21]
“当你嵌入一个表达式,强迫实现一个懒惰序列进入没有实现的外层懒序列时,会发生什么?” 如果迫使实现内部序列的表达式是在外部序列的未实现部分中,则什么也不是。 “ 答案:这似乎取决于你如何创建外部惰性序列,如果外部序列来自map,内部序列就会实现,如果外部序列来迭代,它就不是。 ” 不,它只取决于你的强迫表达是否在未实现的部分。 无论是map还是iterate都不会意识到任何尚未实现的东西。 “描述下面发生的事情” 您需要考虑评估规则。 你的例子的行为主要是渴望与懒惰评估(Clojure渴望)的结果,并且只与 ... -
memoize确实适用于序列,你只需要比较苹果和苹果。 memoize在先前使用的哈希映射中查找参数,因此您最终会比较序列。 比较长序列需要很长时间,无论它们是否为向量: user> (def x (vec (range 1000000))) ;; => #'user/x user> (def y (vec (range 1000000))) ;; => #'user/y user> (time (= x y)) "Elapsed time: 64.351274 msecs" ;; => true user ...
-
map做你需要的一切。 它保留了您应用它的序列的“懒惰”。 (map f old-lazy-sequence) => [new-lazy-sequence] 无限范围的示例: (take 5 (map (partial * 2) (range))) => (0 2 4 6 8) map does everything you need. It preserves the "laziness" of sequences that you apply it to. (map f old ...
-
当然,这是因为根据定义,为了颠倒序列,你必须知道另一端是什么,才能返回将成为颠倒集合中第一项的东西。 因此,序列必须是有限的,你必须对它进行评估才能使用最终的结果。 附录: 作为一个无限序列,倒序并不合理(尽管公平地说,无限序列并不总是懒惰的先决条件)。 如果您要反转某个集合,那么您已经将其加载到内存中; 它不需要计算。 Surely it's because by definition, in order to reverse a sequence, you have to know what's at ...
-
如何将一个减少实现的序列转换回惰性向量序列(How To Turn a Reduce-Realized Sequence Back Into Lazy Vector Sequence)[2023-08-04]
1)我希望使序列延迟不起作用,因为print会在打印之前评估实现它。 而是尝试doseq或(map print my-seq)以较小的块打印它。 2)是的将它包装在vec中会给你你想要的东西:)尽管用一个into包装你的reduce会让它一直保持向量。 即:( (reduce into [] [[1] [2] [3]] ) - > [1 2 3] (into out-log (sorted-map cmp-val (vector lnam fnam))))) 1) i expect that maki ... -
你想要的是: (def word_string (apply str (interpose " " word_list))) 看看str的文档: 如果没有args,则返回空字符串。 使用一个arg x,返回 x.toString()。 (str nil)返回空字符串。 超过 一个arg返回args的str值的连接。 所以你在序列上调用.toString ,生成该表示而不是将str作为参数应用于序列的元素。 顺便说一句,做你想做的事情更习惯的方式是: (clojure.string/join " " wor ...
-
什么时候懒惰序列的不同元素在clojure中实现?(When are the different elements of a lazy sequence realized in clojure?)[2021-11-23]
Clojure的序列是懒惰的,但为了提高效率,一次实现了32个结果的块。 =>(def lz-seq (map #(do (println (str "fn call " %)) (identity %)) (range 100))) =>(first lz-seq) fn call 0 fn call 1 ... fn call 31 0 一旦你首先越过32边界,就会发生同样的事情 =>(nth lz-seq 33) fn call 0 fn call 1 ... fn call 63 33 对于需 ...