ขออภัยฉันเพิ่งเรียนรู้ Autofac
ฉันมีปัญหาในการทำความเข้าใจ Lifetime scope
ใน Autofac
โปรดช่วยตรวจสอบด้านล่าง
สมมติว่าเรามีรหัสด้านล่าง
using(var scope = container.BeginLifetimeScope())
{
// Resolve services from a scope that is a child
// of the root container.
var service = scope.Resolve<IService>();
// You can also create nested scopes...
using(var unitOfWorkScope = scope.BeginLifetimeScope())
{
var anotherService = unitOfWorkScope.Resolve<IOther>();
}
}
ตามเอกสาร ก> ใส่ Lifetime scopes are disposable and they track component disposal
.
หมายความว่า service
ใช้แล้วทิ้งและ GC สามารถรีไซเคิลได้หลังจากระบุคำสั่ง using(var scope = container.BeginLifetimeScope())
เสร็จแล้วใช่หรือไม่
และมันจะเป็นเช่นนั้นกับ anotherService
ในขอบเขตที่ซ้อนกันหรือไม่ ?
ฉันจะเป็นพยานด้วยการทดลองบางอย่างได้อย่างไร?
ขอบคุณ.