Пример #1
0
 /// <summary>
 /// Configures the default service provider
 /// </summary>
 /// <param name="applicationBuilder">The <see cref="IConsoleBuilder"/> to configure.</param>
 /// <param name="configure">A callback used to configure the <see cref="ServiceProviderOptions"/> for the default <see cref="IServiceProvider"/>.</param>
 /// <returns>The <see cref="IConsoleBuilder"/>.</returns>
 public static IConsoleBuilder UseDefaultServiceProvider(this IConsoleBuilder applicationBuilder, Action <ConsoleBuilderContext, ServiceProviderOptions> configure)
 {
     return(applicationBuilder.ConfigureServices((context, services) =>
     {
         var options = new ServiceProviderOptions();
         configure(context, options);
         services.Replace(ServiceDescriptor.Singleton <IServiceProviderFactory <IServiceCollection> >(new DefaultServiceProviderFactory(options)));
     }));
 }
Пример #2
0
 /// <summary>
 /// Adds a delegate for configuring the provided <see cref="ILoggingBuilder"/>. This may be called multiple times.
 /// </summary>
 /// <param name="applicationBuilder">The <see cref="IConsoleBuilder" /> to configure.</param>
 /// <param name="configureLogging">The delegate that configures the <see cref="ILoggingBuilder"/>.</param>
 /// <returns>The <see cref="IConsoleBuilder"/>.</returns>
 public static IConsoleBuilder ConfigureLogging(this IConsoleBuilder applicationBuilder, Action <ILoggingBuilder> configureLogging)
 {
     return(applicationBuilder.ConfigureServices(collection => collection.AddLogging(configureLogging)));
 }
Пример #3
0
 /// <summary>
 /// Adds a delegate for configuring the provided <see cref="LoggerFactory"/>. This may be called multiple times.
 /// </summary>
 /// <param name="applicationBuilder">The <see cref="IConsoleBuilder" /> to configure.</param>
 /// <param name="configureLogging">The delegate that configures the <see cref="LoggerFactory"/>.</param>
 /// <returns>The <see cref="IConsoleBuilder"/>.</returns>
 public static IConsoleBuilder ConfigureLogging(this IConsoleBuilder applicationBuilder, Action <ConsoleBuilderContext, ILoggingBuilder> configureLogging)
 {
     return(applicationBuilder.ConfigureServices((context, collection) => collection.AddLogging(builder => configureLogging(context, builder))));
 }
Пример #4
0
 /// <summary>
 /// Run this <see cref="IExecutable"/> when the console application starts.
 /// </summary>
 /// <typeparam name="TExecutable">The type of executable.</typeparam>
 /// <param name="applicationBuilder">The <see cref="IConsoleBuilder"/>.</param>
 /// <returns>The <see cref="IConsole"/>.</returns>
 /// <remarks>This can be called multiple times.</remarks>
 public static IConsoleBuilder Execute <TExecutable>(this IConsoleBuilder applicationBuilder)
     where TExecutable : class, IExecutable
 {
     return(applicationBuilder.ConfigureServices(services => services.TryAddEnumerable(ServiceDescriptor.Singleton <IExecutable, TExecutable>())));
 }