/// <summary>
 /// Uses the assemblies.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="assemblies">The assemblies.</param>
 /// <param name="diagnosticSource">The diagnostic source.</param>
 /// <returns>IRocketHostBuilder.</returns>
 public static IRocketHostBuilder UseAssemblies(
     this IRocketHostBuilder builder,
     IEnumerable <Assembly> assemblies,
     DiagnosticSource diagnosticSource = null)
 {
     return(RocketBooster.ForAssemblies(assemblies, diagnosticSource)(builder.Builder));
 }
 /// <summary>
 /// Uses the application domain.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="appDomain">The application domain.</param>
 /// <param name="diagnosticSource">The diagnostic source.</param>
 /// <returns>IRocketHostBuilder.</returns>
 public static IRocketHostBuilder UseAppDomain(
     this IRocketHostBuilder builder,
     AppDomain appDomain,
     DiagnosticSource diagnosticSource = null)
 {
     return(RocketBooster.ForAppDomain(appDomain, diagnosticSource)(builder.Builder));
 }
 /// <summary>
 /// Uses the dependency context.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="dependencyContext">The dependency context.</param>
 /// <param name="diagnosticSource">The diagnostic source.</param>
 /// <returns>IRocketHostBuilder.</returns>
 public static IRocketHostBuilder UseDependencyContext(
     this IRocketHostBuilder builder,
     DependencyContext dependencyContext,
     DiagnosticSource diagnosticSource = null)
 {
     return(RocketBooster.ForDependencyContext(dependencyContext, diagnosticSource)(builder.Builder));
 }
        /// <summary>
        /// Uses the diagnostic logging.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="action">The action.</param>
        /// <returns>IRocketHostBuilder.</returns>
        public static IRocketHostBuilder UseDiagnosticLogging(
            [NotNull] this IRocketHostBuilder builder,
            [NotNull] Action <ILoggingBuilder> action
            )
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }

            (builder.DiagnosticSource is DiagnosticListener listener
                ? listener
                : new DiagnosticListener("DiagnosticLogger")).SubscribeWithAdapter(
                new DiagnosticListenerLoggingAdapter(
                    new ServiceCollection()
                    .AddLogging(action)
                    .BuildServiceProvider()
                    .GetRequiredService <ILoggerFactory>()
                    .CreateLogger("DiagnosticLogger")
                    )
                );
            return(builder);
        }
        /// <summary>
        /// Uses the autofac.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="containerBuilder">The container builder.</param>
        /// <returns>IRocketHostBuilder.</returns>
        public static IRocketHostBuilder UseAutofac(
            [NotNull] this IRocketHostBuilder builder,
            ContainerBuilder?containerBuilder = null
            )
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.Builder.ConfigureServices(
                (context, services) =>
            {
                builder.Builder.UseServiceProviderFactory(
                    new ServicesBuilderServiceProviderFactory(
                        collection =>
                        new AutofacBuilder(
                            context.HostingEnvironment.Convert(),
                            context.Configuration,
                            builder.Get <IConventionScanner>(),
                            builder.Get <IAssemblyProvider>(),
                            builder.Get <IAssemblyCandidateFinder>(),
                            collection,
                            containerBuilder ?? new ContainerBuilder(),
                            builder.Get <ILogger>(),
                            builder.ServiceProperties
                            )
                        )
                    );
            }
                );
            return(builder);
        }
 /// <summary>
 /// Uses the command line.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="configureOptions">The configure options.</param>
 /// <returns>IRocketHostBuilder.</returns>
 public static IRocketHostBuilder UseCommandLine(this IRocketHostBuilder builder, Action <ConsoleLifetimeOptions> configureOptions)
 {
     builder.Builder.Properties[typeof(CommandLineHostedService)] = true;
     builder.Builder
     .UseConsoleLifetime()
     .ConfigureServices(services => services.Configure(configureOptions));
     return(GetOrCreateBuilder(builder));
 }
 /// <summary>
 /// Uses the diagnostic logging.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="action">The action.</param>
 /// <returns>IRocketHostBuilder.</returns>
 public static IRocketHostBuilder UseDiagnosticLogging(this IRocketHostBuilder builder, Action <ILoggingBuilder> action)
 {
     DiagnosticListenerExtensions.SubscribeWithAdapter(
         builder.DiagnosticSource is DiagnosticListener listener ? listener : new DiagnosticListener("DiagnosticLogger"),
         new DiagnosticListenerLoggingAdapter(
             new ServiceCollection()
             .AddLogging(action)
             .BuildServiceProvider()
             .GetRequiredService <ILoggerFactory>()
             .CreateLogger("DiagnosticLogger")
             )
         );
     return(builder);
 }
        /// <summary>
        /// Uses the scanner.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="scanner">The scanner.</param>
        /// <returns>IRocketHostBuilder.</returns>
        public static IRocketHostBuilder UseScanner(
            [NotNull] this IRocketHostBuilder builder,
            [NotNull] IConventionScanner scanner
            )
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (scanner == null)
            {
                throw new ArgumentNullException(nameof(scanner));
            }

            return(Swap(builder, GetOrCreateBuilder(builder).With(scanner)));
        }
        /// <summary>
        /// Uses the diagnostic source.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="diagnosticSource">The diagnostic source.</param>
        /// <returns>IRocketHostBuilder.</returns>
        public static IRocketHostBuilder UseDiagnosticSource(
            [NotNull] this IRocketHostBuilder builder,
            [NotNull] DiagnosticSource diagnosticSource
            )
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (diagnosticSource == null)
            {
                throw new ArgumentNullException(nameof(diagnosticSource));
            }

            return(Swap(builder, GetOrCreateBuilder(builder).With(diagnosticSource)));
        }
Esempio n. 10
0
        /// <summary>
        /// Uses the assembly provider.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="assemblyProvider">The assembly provider.</param>
        /// <returns>IRocketHostBuilder.</returns>
        public static IRocketHostBuilder UseAssemblyProvider(
            [NotNull] this IRocketHostBuilder builder,
            [NotNull] IAssemblyProvider assemblyProvider
            )
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (assemblyProvider == null)
            {
                throw new ArgumentNullException(nameof(assemblyProvider));
            }

            return(Swap(builder, GetOrCreateBuilder(builder).With(assemblyProvider)));
        }
Esempio n. 11
0
        /// <summary>
        /// Uses the assemblies.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="assemblies">The assemblies.</param>
        /// <param name="diagnosticSource">The diagnostic source.</param>
        /// <returns>IRocketHostBuilder.</returns>
        public static IRocketHostBuilder UseAssemblies(
            [NotNull] this IRocketHostBuilder builder,
            [NotNull] IEnumerable <Assembly> assemblies,
            DiagnosticSource?diagnosticSource = null
            )
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (assemblies == null)
            {
                throw new ArgumentNullException(nameof(assemblies));
            }

            return(RocketBooster.ForAssemblies(assemblies, diagnosticSource)(builder.Builder));
        }
Esempio n. 12
0
        /// <summary>
        /// Uses the application domain.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="appDomain">The application domain.</param>
        /// <param name="diagnosticSource">The diagnostic source.</param>
        /// <returns>IRocketHostBuilder.</returns>
        public static IRocketHostBuilder UseAppDomain(
            [NotNull] this IRocketHostBuilder builder,
            [NotNull] AppDomain appDomain,
            DiagnosticSource?diagnosticSource = null
            )
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (appDomain == null)
            {
                throw new ArgumentNullException(nameof(appDomain));
            }

            return(RocketBooster.ForAppDomain(appDomain, diagnosticSource)(builder.Builder));
        }
Esempio n. 13
0
        /// <summary>
        /// Uses the dependency context.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="dependencyContext">The dependency context.</param>
        /// <param name="diagnosticSource">The diagnostic source.</param>
        /// <returns>IRocketHostBuilder.</returns>
        public static IRocketHostBuilder UseDependencyContext(
            [NotNull] this IRocketHostBuilder builder,
            [NotNull] DependencyContext dependencyContext,
            DiagnosticSource?diagnosticSource = null
            )
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (dependencyContext == null)
            {
                throw new ArgumentNullException(nameof(dependencyContext));
            }

            return(RocketBooster.ForDependencyContext(dependencyContext, diagnosticSource)(builder.Builder));
        }
Esempio n. 14
0
        /// <summary>
        /// Uses the command line.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="configureOptions">The configure options.</param>
        /// <returns>IRocketHostBuilder.</returns>
        public static IRocketHostBuilder UseCommandLine(
            [NotNull] this IRocketHostBuilder builder,
            [NotNull] Action <ConsoleLifetimeOptions> configureOptions
            )
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (configureOptions == null)
            {
                throw new ArgumentNullException(nameof(configureOptions));
            }

            builder.Builder.Properties[typeof(CommandLineHostedService)] = true;
            builder.Builder
            .UseConsoleLifetime()
            .ConfigureServices(services => services.Configure(configureOptions));
            return(GetOrCreateBuilder(builder));
        }
 /// <summary>
 /// Uses the autofac.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="containerBuilder">The container builder.</param>
 /// <returns>IRocketHostBuilder.</returns>
 public static IRocketHostBuilder UseAutofac(this IRocketHostBuilder builder, ContainerBuilder containerBuilder = null)
 {
     builder.Builder.ConfigureServices((context, services) =>
     {
         var conventionalBuilder = RocketHostExtensions.GetOrCreateBuilder(builder);
         builder.Builder.UseServiceProviderFactory(
             new ServicesBuilderServiceProviderFactory(collection =>
                                                       new AutofacBuilder(
                                                           context.HostingEnvironment.Convert(),
                                                           context.Configuration,
                                                           conventionalBuilder.Scanner,
                                                           conventionalBuilder.AssemblyProvider,
                                                           conventionalBuilder.AssemblyCandidateFinder,
                                                           collection,
                                                           containerBuilder ?? new ContainerBuilder(),
                                                           conventionalBuilder.DiagnosticSource,
                                                           conventionalBuilder.Properties
                                                           )
                                                       )
             );
     });
     return(RocketHostExtensions.GetOrCreateBuilder(builder));
 }
Esempio n. 16
0
 /// <summary>
 /// Swaps the specified builder.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="newRocketBuilder">The new rocket builder.</param>
 /// <returns>RocketHostBuilder.</returns>
 internal static RocketHostBuilder Swap(IRocketHostBuilder builder, RocketHostBuilder newRocketBuilder)
 {
     Builders.Remove(builder.Builder);
     Builders.Add(builder.Builder, newRocketBuilder);
     return(newRocketBuilder);
 }
Esempio n. 17
0
 /// <summary>
 /// Gets the or create builder.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <returns>RocketHostBuilder.</returns>
 internal static RocketHostBuilder GetOrCreateBuilder(IRocketHostBuilder builder)
 => GetOrCreateBuilder(builder.Builder);
Esempio n. 18
0
 /// <summary>
 /// Uses the command line.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <returns>IRocketHostBuilder.</returns>
 public static IRocketHostBuilder UseCommandLine(this IRocketHostBuilder builder)
 => builder.UseCommandLine(x => x.SuppressStatusMessages = true);
 /// <summary>
 /// Uses the diagnostic source.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="diagnosticSource">The diagnostic source.</param>
 /// <returns>IRocketHostBuilder.</returns>
 public static IRocketHostBuilder UseDiagnosticSource(this IRocketHostBuilder builder, DiagnosticSource diagnosticSource)
 {
     return(Swap(builder, GetOrCreateBuilder(builder).With(diagnosticSource)));
 }
 public HostingConventionContext(
     IRocketHostBuilder builder,
     ILogger logger
     ) : base(logger, builder.ServiceProperties) => _builder = builder;
 /// <summary>
 /// Uses the assembly provider.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="assemblyProvider">The assembly provider.</param>
 /// <returns>IRocketHostBuilder.</returns>
 public static IRocketHostBuilder UseAssemblyProvider(this IRocketHostBuilder builder, IAssemblyProvider assemblyProvider)
 {
     return(Swap(builder, GetOrCreateBuilder(builder).With(assemblyProvider)));
 }
 /// <summary>
 /// Uses the scanner.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="scanner">The scanner.</param>
 /// <returns>IRocketHostBuilder.</returns>
 public static IRocketHostBuilder UseScanner(this IRocketHostBuilder builder, IConventionScanner scanner)
 {
     return(Swap(builder, GetOrCreateBuilder(builder).With(scanner)));
 }
 /// <summary>
 /// Gets the or create builder.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <returns>RocketHostBuilder.</returns>
 internal static RocketHostBuilder GetOrCreateBuilder(IRocketHostBuilder builder)
 {
     return(GetOrCreateBuilder(builder.Builder));
 }