Esempio n. 1
0
        /// <summary>
        /// Adds a delegate that configures the application.
        /// </summary>
        public static ICommandLineHostBuilder Configure(this ICommandLineHostBuilder builder, Action <IApplicationBuilder> configureApp)
        {
            if (configureApp == null)
            {
                throw new ArgumentNullException(nameof(configureApp));
            }

            return(builder.UseSetting(HostDefaults.ApplicationNameKey, configureApp.Method.DeclaringType.Assembly.GetName().Name)
                   .ConfigureServices(services =>
            {
                var startupDescriptor = services.SingleOrDefault(s => s.ImplementationType.IsDelegateStartupType());
                if (startupDescriptor != null)
                {
                    services.Remove(startupDescriptor);
                }

                services.AddSingleton <IStartup>(new DelegateStartup <IServiceCollection>
                {
                    ConfigureApp = configureApp
                });
            }));
        }
Esempio n. 2
0
 /// <summary>
 /// Specifies the startup class to use to configure an application.
 /// </summary>
 public static ICommandLineHostBuilder UseStartup <TStartup>(this ICommandLineHostBuilder builder) where TStartup : class, IStartup
 {
     return(builder.UseSetting(HostDefaults.ApplicationNameKey, typeof(TStartup).Assembly.GetName().Name)
            .ConfigureServices(services => services.AddSingleton <IStartup, TStartup>()));
 }