Closed jerviscui closed 3 years ago
Discuss: https://github.com/pamidur/aspect-injector/pull/154#discussion_r653425093
I think the PropertyName used for dictionary key is enough.
LazyAspect
is Scope.PerInstance
and LazyAspect_backFields
is a instance field,Hi @jerviscui, I've seen your update, it looks good to me,I'll make sure to properly review and merge it ASAP once return from vacation at the end of the next week!
All looks good! Before I merge, last question, do we still need
[Aspect(Scope.PerInstance)]
since we don't use an instance anywhere I think we might simplify and speedup things usingScope.Global
Hi, @pamidur
This question, I think the Scope.Global
will make private readonly Dictionary<string, object> _backFields
a single instance.
And, objects cached in _backFields
will also become a singleton.
I think Scope.Global
will destroy objects lifetime when used for a scoped lifetime dependency service.
example:
class MyClass
{
private readonly IServiceProvider _serviceProvider;
public MyClass(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
}
private static Service _service;
public Service Service => _service ??= _serviceProvider.GetService<Service>();
}
Service
is registered by Transient or Scope, _service
make it a Singletone lifetime.[Aspect(Scope.PerInstance)]
can used for Single and Scope lifetime components. Use careful for Transient components.
Published here https://www.nuget.org/packages/Aspects.Lazy/
Fixes #152 Duplicate of #154
Should I continue to submit
Lazy
?Sorry, I don't know how to modify a PR. I create a new PR. 😂