"Lifetime scopes are respected" 是什么意思?
What does "Lifetime scopes are respected" means?
我正在阅读 Autofac 官方文档中的 Implicit Relationship Types 部分,但我不太理解这一行。
Lifetime scopes are respected using this relationship type.
谁能帮我解释一下'respected'到底是什么意思?
'respected' 表示当您使用动态实例化时,Autofac 不会覆盖您的注册。
这在接下来的两行中详细说明:
If you register an object as InstancePerDependency()
and call the Func<B>
multiple times, you’ll get a new instance each time. However, if you register an object as SingleInstance()
and call the Func<B>
to resolve the object more than once, you will get the same object instance every time.
转自提问者的评论:
I understand the detailed explanations in the next 2 lines and i have wrote demos for that, but what's the connection to lifetime scope? Can I understand that lifetime scope is important, and will influence the instantiation?
与生命周期范围的联系:
当你依赖注入一个对象时,我给你一个新对象还是单例?
为什么生命周期范围很重要并且会影响实例化:
对象是否具有不应在别处访问的实例属性?如果我给你一个新对象,它应该是在应用程序的剩余生命周期中存在的单例吗?
我正在阅读 Autofac 官方文档中的 Implicit Relationship Types 部分,但我不太理解这一行。
Lifetime scopes are respected using this relationship type.
谁能帮我解释一下'respected'到底是什么意思?
'respected' 表示当您使用动态实例化时,Autofac 不会覆盖您的注册。
这在接下来的两行中详细说明:
If you register an object as
InstancePerDependency()
and call theFunc<B>
multiple times, you’ll get a new instance each time. However, if you register an object asSingleInstance()
and call theFunc<B>
to resolve the object more than once, you will get the same object instance every time.
转自提问者的评论:
I understand the detailed explanations in the next 2 lines and i have wrote demos for that, but what's the connection to lifetime scope? Can I understand that lifetime scope is important, and will influence the instantiation?
与生命周期范围的联系:
当你依赖注入一个对象时,我给你一个新对象还是单例?
为什么生命周期范围很重要并且会影响实例化:
对象是否具有不应在别处访问的实例属性?如果我给你一个新对象,它应该是在应用程序的剩余生命周期中存在的单例吗?