c# - 生命周期范围是否包含对非一次性组件的引用?
问题描述
我的问题与这个问题有关Autofac 如何处理非一次性组件。医生说:
像 Autofac 这样的跟踪容器保存对它们创建的一次性组件的引用
但它并没有说 Autofac 是否持有对他们创建的非一次性组件的引用
让我们看一个具体的例子:
public class A { } // doesn't implement IDisposable
static void Main() {
var builder = new ContainerBuilder();
IContainer container = builder.Build();
using (var childScope1 = container.BeginLifetimeScope(b => { b.RegisterType<A>().InstancePerDependency(); })) {
A a = childScope1.Resolve<A>();
... // do other stuff that doesn't involve a, and let's say generation 0 has filled its budget here
...
...
}
}
我的问题是:
childScope1 是否持有对 instance 的引用a
,因此a
在 childScope1 被处置之前不会被 GC
或者
childScope1 不包含对实例的引用,a
因为A
它是非一次性类,所以a
可能在using
块完成之前被 GCed?
解决方案
推荐阅读
- sql - 进行分组后,有没有办法在不同行的同一列中查看同一列结果?
- javascript - javascript中数组的逻辑或
- ansible - 目标目录的 Ansible fetch 模块问题
- c# - 如何通过表达式模拟ToString方法?#
- amazon-web-services - AWS Lambda 是否对初始化代码所花费的时间收费?
- windows - Windows Media 编码器不保存 MF_MT_MPEG_SEQUENCE_HEADER
- html - Mozilla Firefox 未从本地计算机加载图像
- acumatica - 报告设计中的数字到单词
- javascript - 样式问题和访问孩子
- android - 在片段中遇到问题,活动运作良好