/// <summary> /// Retrieves an object instance by key. If the key hasn't been encountered before, a new instance will be created. /// </summary> /// <param name="key">The key used to look up the instance. If the key is encountered for the first time, a new instance will be created.</param> /// <returns>An existing or new instance matching the key.</returns> public T GetObject(TKey key) { T obj; if (_objects.TryGetValue(key, out obj)) { return(obj); } // No or dead repository for the given key. Create a new one. obj = Create(); _objects.Add(key, obj); return(obj); }