Exemplo n.º 1
0
 /// <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);
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Adds a new scoped 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 AddScopedItem(
            string name,
            object item,
            string contextSectionName = null)
        {
            string itemName = BdoDataContext.GetItemUniqueName(name, contextSectionName);

            ScopedItems.Remove(itemName);
            ScopedItems.Add(name, item);
        }