Lifestyles
Lifestyle controls in what scope instances are reused,and when to release them(that is do all the necessary clean up steps and then let it go for the Garbage Collector to destroy). Lifestyle控制实例在什么作用域(scope)内被重用,在什么时候被释放(清理的必要步骤,清理之后被GC回收) 常见的生命方式??Standard Lifestyle :the common ones?Singleton(default style)在第一次请求时创建,后续请求重复使用。显示调用释放(container.Release(instance))不起作用。只有当容器释放时才会释放singleton的实例 什么样的类设置为单例呢?
Transient每次程序需要时都会创建新的实例 trannsient实例需要释放。 如果是这样获取实例(container.Resolve<MyTransientComponent>()) 需要调用container.Release(myTransientInstance) 释放它 Transient components may be tracked by the container 用完之后如果不是放GC不会回收 不常见的生命方式the less common ones?Scopeusing Castle.MicroKernel.Lifestyle; using (Container.BeginScope()) //extension method } // releases the instance the scope is bound to the?CallContext. 注意在多线程情况下子操作应该在scope范围内完成,否则出现空引用错误。 Custom ScopeImplementing custom scope Bound(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |