/// <summary> /// Registers an item with a specified name. /// </summary> /// <typeparam name="TOption">The type of options used.</typeparam> /// <typeparam name="TItem">The type of item produced.</typeparam> /// <param name="builder">The IFactoryItemBuilder.</param> /// <param name="name">The name of the item.</param> /// <param name="item">The item to add.</param> /// <returns>The updated IFactoryItemBuilder.</returns> public static IFactoryItemBuilder <TOption, TItem> AddItem <TOption, TItem>(this IFactoryItemBuilder <TOption, TItem> builder, string name, TItem item) where TOption : class { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } builder.Services.Configure <GenericFactoryOptions <TOption, TItem> >(o => { o.PrefabricatedItems[name] = item; }); return(builder); }
/// <summary> /// Configures a new item in the factory. /// </summary> /// <typeparam name="TOption">The type of options used.</typeparam> /// <typeparam name="TItem">The type of item produced.</typeparam> /// <param name="builder">The IFactoryItemBuilder.</param> /// <param name="configureOptions">Method for configuring the default item options.</param> /// <returns>The updated IFactoryItemBuilder.</returns> public static IFactoryItemBuilder <TOption, TItem> Configure <TOption, TItem>(this IFactoryItemBuilder <TOption, TItem> builder, Action <TOption> configureOptions) where TOption : class { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } builder.Services.Configure <TOption>(configureOptions); return(builder); }