private ILifetime GetLifetime(TypeDescriptor typeDescriptor) { if (Lifetime == null) { return(null); } if (!typeDescriptor.IsConstructedGenericType()) { return(Lifetime); } var lifetimeKey = new LifetimeKey(typeDescriptor.GetGenericTypeArguments()); ILifetime lifetime; lock (_lockObject) { if (!_lifetimes.TryGetValue(lifetimeKey, out lifetime)) { lifetime = Lifetime.Create(); _lifetimes.Add(lifetimeKey, lifetime); } } return(lifetime); }
public ILifetime GetLifetime([NotNull] Type type) { if (Lifetime == default(ILifetime)) { return(default(ILifetime)); } var hasLifetimes = _lifetimes.Count != 0; if (!hasLifetimes && !Keys.Any(key => key.Type.Descriptor().IsGenericTypeDefinition())) { return(Lifetime); } var lifetimeKey = new LifetimeKey(type.Descriptor().GetGenericTypeArguments()); if (!hasLifetimes) { _lifetimes = _lifetimes.Set(lifetimeKey, Lifetime); return(Lifetime); } var lifetime = _lifetimes.Get(lifetimeKey); if (lifetime != default(ILifetime)) { return(lifetime); } lifetime = Lifetime.CreateLifetime(); _lifetimes = _lifetimes.Set(lifetimeKey, lifetime); return(lifetime); }
private bool Equals(LifetimeKey other) => CoreExtensions.SequenceEqual(_genericTypes, other._genericTypes);