public static IConfigurationBuilder AddModels <TModel>(this IConfigurationBuilder builder, IEnumerable <TModel> models, Action <Models.ModelConfigurationSource <TModel> > configureSource = null) where TModel : Zongsoft.Data.IModel { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } var source = new Models.ModelConfigurationSource <TModel>() { Models = models }; configureSource?.Invoke(source); return(builder.Add(source)); }
public ModelConfigurationProvider(ModelConfigurationSource <TModel> source) { _source = source ?? throw new ArgumentNullException(nameof(source)); _reloadToken = new ConfigurationReloadToken(); this.Data = new Dictionary <string, TModel>(StringComparer.OrdinalIgnoreCase); if (source.Models != null) { foreach (var model in source.Models) { if (model.TryGetValue(source.Mapping.Key, out var key) && key != null) { this.Data.Add(key.ToString(), model); } } } }