private void BindCore(Type key, object value) { if (this.bindings == null) { lock (this.created) { if (this.bindings == null) { this.bindings = ConcurrentDictionaryPool <Type, object> .Borrow(); } } } this.bindings.AddOrUpdate( key, t => value, (type, o) => throw new InvalidOperationException($"{type.PrettyName()} already has a binding to {(o as Type)?.PrettyName() ?? o}")); }
/// <inheritdoc/> public void Dispose() { if (this.created == null) { return; } var local = this.created; this.created = null; foreach (var kvp in local) { (kvp.Value as IDisposable)?.Dispose(); } ConcurrentDictionaryPool <Type, object> .Return(local); ConcurrentDictionaryPool <Type, object> .Return(this.bindings); }