两者之间有什么区别。后者是新的选择吗?我想我以前没见过。
该文件说后者将处理IDisposables,但IIRC也是InstancePerLifetimeScope的行为?
答案 0 :(得分:2)
OwnedByLifetimeScope
和InstancePerLifetimeScope
设置了注册的不同属性。如果你看一下源代码,你会看到:
... OwnedByLifetimeScope()
{
RegistrationData.Ownership = InstanceOwnership.OwnedByLifetimeScope;
return this;
}
和
... InstancePerLifetimeScope()
{
RegistrationData.Sharing = InstanceSharing.Shared;
RegistrationData.Lifetime = new CurrentScopeLifetime();
return this;
}
对于OwnedByLifetimeScope
,这实际上是默认值,因此显式设置它通常是无操作,除非其他一些代码明确地将其更改为ExternallyOwned
。