/// <summary> /// Removes the singleton items of a specific type. /// </summary> /// <param name="contextSectionName">Name of the context section to consider.</param> /// <param name="persistenceLevel">The persistence level to consider.</param> public void RemoveItems( string contextSectionName = null, PersistenceLevels persistenceLevel = PersistenceLevels.Singleton) { if ((persistenceLevel == PersistenceLevels.Any) || (persistenceLevel == PersistenceLevels.Singleton)) { var items = SingletonItems.Keys.Where(p => (string.IsNullOrEmpty(contextSectionName)) || (p?.ToString().ToLower().StartsWith(contextSectionName.ToLower() + "$") == true)); foreach (string key in items) { SingletonItems.Remove(key); } } if ((persistenceLevel == PersistenceLevels.Any) || (persistenceLevel == PersistenceLevels.Scoped)) { var items = ScopedItems.Keys.Where(p => (string.IsNullOrEmpty(contextSectionName)) || (p?.ToString().ToLower().StartsWith(contextSectionName.ToLower() + "$") == true)); foreach (string key in items) { ScopedItems.Remove(key); } } if ((persistenceLevel == PersistenceLevels.Any) || (persistenceLevel == PersistenceLevels.Transient)) { var items = TransientItems.Keys.Where(p => (string.IsNullOrEmpty(contextSectionName)) || (p?.ToString().ToLower().StartsWith(contextSectionName.ToLower() + "$") == true)); foreach (string key in items) { TransientItems.Remove(key); } } }
/// <summary> /// Adds a new singleton item to this instance. /// </summary> /// <param name="name">Name of the item to add.</param> /// <param name="item">The item to consider.</param> /// <param name="contextSectionName">Name of the context section to consider.</param> public void AddSingletonItem( string name, object item, string contextSectionName = null) { string itemName = BdoDataContext.GetItemUniqueName(name, contextSectionName); SingletonItems.Remove(itemName); SingletonItems.Add(itemName, item); }