/// <summary> /// Adds an entity initializer to this context. /// </summary> /// <param name="initializer">The initializer to add.</param> /// <exception cref="ArgumentNullException"></exception> protected void AddEntityInitializer(IntelligentEntityInitializer initializer) { if (initializer is null) { throw new ArgumentNullException(nameof(initializer)); } var t = GetType(); lock (EntityInitializers) { if (!EntityInitializers.ContainsKey(t)) { EntityInitializers[t] = new List <IntelligentEntityInitializer>(); } EntityInitializers[t].Add(initializer); } }
/// <summary> /// Adds an entity initializer to the context type. /// </summary> /// <param name="initializer">The initializer to add.</param> /// <typeparam name="TContext">The context type to add the initializer to.</typeparam> /// <exception cref="ArgumentNullException"></exception> public static void AddEntityInitializer <TContext>(IntelligentEntityInitializer initializer) where TContext : IntelligentDbContext { if (initializer is null) { throw new ArgumentNullException(nameof(initializer)); } var t = typeof(TContext); lock (EntityInitializers) { if (!EntityInitializers.ContainsKey(t)) { EntityInitializers[t] = new List <IntelligentEntityInitializer>(); } EntityInitializers[t].Add(initializer); } }