コード例 #1
0
 /// <summary>
 /// Injects multiple instances of <typeparamref name="T"/> for this instance builder, one per item in the source sequence, via the factory function passed to this method.
 /// </summary>
 /// <typeparam name="TSource">The type of items in the source sequence.</typeparam>
 /// <typeparam name="T">The type of instance to create.</typeparam>
 /// <param name="builder">The instance builder.</param>
 /// <param name="source">The source sequence.</param>
 /// <param name="function">The factory function that transforms a source sequence item to an instance of <typeparamref name="T"/>.</param>
 public static InstanceBuilder WithMany <TSource, T>(this IInstanceBuilder builder, IEnumerable <TSource> source, Func <InstanceBuilder, TSource, T> function)
 {
     _ = builder ?? throw new ArgumentNullException(nameof(builder));
     _ = source ?? throw new ArgumentNullException(nameof(source));
     _ = function ?? throw new ArgumentNullException(nameof(function));
     return(builder.With(source.Select(x => function(builder.Copy(), x)).ToList()));
 }
コード例 #2
0
 /// <summary>
 /// Injects multiple instances of <typeparamref name="T"/> for this instance builder, one per factory function passed to this method.
 /// </summary>
 /// <typeparam name="T">The type of instance to create.</typeparam>
 /// <param name="builder">The instance builder.</param>
 /// <param name="factoryFunctions">A series of factory functions.</param>
 public static InstanceBuilder WithMany <T>(this IInstanceBuilder builder, params Func <InstanceBuilder, T>[] factoryFunctions)
 {
     _ = builder ?? throw new ArgumentNullException(nameof(builder));
     _ = factoryFunctions ?? throw new ArgumentNullException(nameof(factoryFunctions));
     return(builder.With(factoryFunctions.Select(factoryFunction => factoryFunction(builder.Copy())).ToList()));
 }
コード例 #3
0
 /// <summary>
 /// Injects a single instance of <typeparamref name="T"/> for this instance builder, using the factory function passed to this method.
 /// </summary>
 /// <typeparam name="T">The type of instance to create.</typeparam>
 /// <param name="builder">The instance builder.</param>
 /// <param name="factoryFunction">A factory function.</param>
 public static InstanceBuilder With <T>(this IInstanceBuilder builder, Func <InstanceBuilder, T> factoryFunction)
 {
     _ = builder ?? throw new ArgumentNullException(nameof(builder));
     _ = factoryFunction ?? throw new ArgumentNullException(nameof(factoryFunction));
     return(builder.With(factoryFunction(builder.Copy()) !));
 }