Exemplo n.º 1
0
        /// <summary>
        /// Uses the rocket Surgery.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="startupInstance">The startup instance.</param>
        /// <param name="environment">The environment.</param>
        /// <param name="action">The action.</param>
        /// <returns>IWebJobsBuilder.</returns>
        public static IWebJobsBuilder UseRocketSurgery(
            this IWebJobsBuilder builder,
            [NotNull] object startupInstance,
            [NotNull] IRocketEnvironment environment,
            [NotNull] Action <IRocketFunctionHostBuilder> action
            )
        {
            if (startupInstance == null)
            {
                throw new ArgumentNullException(nameof(startupInstance));
            }

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

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

            var internalBuilder = GetOrCreateBuilder(builder, startupInstance, environment);

            action(internalBuilder);
            internalBuilder.Compose();
            return(builder);
        }
        /// <summary>
        /// Checks if the current host environment name is <see cref="EnvironmentName.Production" />.
        /// </summary>
        /// <param name="hostEnvironment">An instance of <see cref="IRocketEnvironment" />.</param>
        /// <returns><c>true</c> if the specified host environment is production; otherwise, <c>false</c>.</returns>
        /// <exception cref="ArgumentNullException">hostEnvironment</exception>
        public static bool IsProduction([NotNull] this IRocketEnvironment hostEnvironment)
        {
            if (hostEnvironment == null)
            {
                throw new ArgumentNullException(nameof(hostEnvironment));
            }

            return(hostEnvironment.IsEnvironment(RocketEnvironments.Production));
        }
Exemplo n.º 3
0
 /// <summary>
 /// Withes the specified environment.
 /// </summary>
 /// <param name="environment">The environment.</param>
 /// <returns>RocketFunctionHostBuilder.</returns>
 internal RocketFunctionHostBuilder With(IRocketEnvironment environment) => new RocketFunctionHostBuilder(
     Builder,
     FunctionsAssembly,
     _startupInstance,
     environment,
     Scanner,
     AssemblyCandidateFinder,
     AssemblyProvider,
     DiagnosticSource,
     ServiceProperties
     );
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConfigurationBuilder" /> class.
 /// </summary>
 /// <param name="scanner">The scanner.</param>
 /// <param name="environment">The environment.</param>
 /// <param name="configuration">The configuration.</param>
 /// <param name="builder">The builder.</param>
 /// <param name="diagnosticSource">The diagnostic source.</param>
 /// <param name="properties">The properties.</param>
 /// <exception cref="ArgumentNullException">
 /// scanner
 /// or
 /// builder
 /// or
 /// configuration
 /// or
 /// diagnosticSource
 /// </exception>
 public ConfigurationBuilder(
     IConventionScanner scanner,
     IRocketEnvironment environment,
     IConfiguration configuration,
     IMsftConfigurationBuilder builder,
     ILogger diagnosticSource,
     IDictionary <object, object?> properties
     ) : base(scanner, properties)
 {
     ApplicationConfigurationBuilder = builder ?? throw new ArgumentNullException(nameof(builder));
     Environment   = environment;
     Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
     Logger        = diagnosticSource ?? throw new ArgumentNullException(nameof(diagnosticSource));
 }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConventionTestHost" /> class.
 /// </summary>
 /// <param name="scanner">The scanner.</param>
 /// <param name="assemblyCandidateFinder">The assembly candidate finder.</param>
 /// <param name="assemblyProvider">The assembly provider.</param>
 /// <param name="diagnosticSource">The diagnostic source.</param>
 /// <param name="serviceProperties">The service properties.</param>
 /// <param name="loggerFactory">The logger factory.</param>
 /// <param name="environment">The environment.</param>
 internal ConventionTestHost(
     IConventionScanner scanner,
     IAssemblyCandidateFinder assemblyCandidateFinder,
     IAssemblyProvider assemblyProvider,
     DiagnosticSource diagnosticSource,
     IServiceProviderDictionary serviceProperties,
     ILoggerFactory loggerFactory,
     IRocketEnvironment environment
     ) : base(scanner, assemblyCandidateFinder, assemblyProvider, diagnosticSource, serviceProperties)
 {
     serviceProperties.Set(HostType.UnitTestHost);
     _loggerFactory = loggerFactory;
     _environment   = environment;
     _logger        = ServiceProperties.Get <ILogger>();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="MetricsBuilder" /> class.
 /// </summary>
 /// <param name="scanner">The scanner.</param>
 /// <param name="assemblyProvider">The assembly provider.</param>
 /// <param name="assemblyCandidateFinder">The assembly candidate finder.</param>
 /// <param name="appMetricsBuilder">The metrics builder.</param>
 /// <param name="environment">The environment.</param>
 /// <param name="configuration">The configuration.</param>
 /// <param name="diagnosticSource">The diagnostic source.</param>
 /// <param name="properties">The properties.</param>
 /// <exception cref="ArgumentNullException">
 /// environment
 /// or
 /// metricsBuilder
 /// or
 /// configuration
 /// or
 /// diagnosticSource
 /// </exception>
 public MetricsBuilder(
     IConventionScanner scanner,
     IAssemblyProvider assemblyProvider,
     IAssemblyCandidateFinder assemblyCandidateFinder,
     IAppMetricsBuilder appMetricsBuilder,
     IRocketEnvironment environment,
     IConfiguration configuration,
     ILogger diagnosticSource,
     IDictionary <object, object?> properties
     ) : base(scanner, assemblyProvider, assemblyCandidateFinder, properties)
 {
     Environment       = environment ?? throw new ArgumentNullException(nameof(environment));
     AppMetricsBuilder = appMetricsBuilder ?? throw new ArgumentNullException(nameof(appMetricsBuilder));
     Configuration     = configuration ?? throw new ArgumentNullException(nameof(configuration));
     Logger            = diagnosticSource ?? throw new ArgumentNullException(nameof(diagnosticSource));
 }
Exemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LoggingBuilder" /> class.
 /// </summary>
 /// <param name="scanner">The scanner.</param>
 /// <param name="assemblyProvider">The assembly provider.</param>
 /// <param name="assemblyCandidateFinder">The assembly candidate finder.</param>
 /// <param name="services">The services.</param>
 /// <param name="environment">The environment.</param>
 /// <param name="configuration">The configuration.</param>
 /// <param name="diagnosticSource">The diagnostic source.</param>
 /// <param name="properties">The properties.</param>
 /// <exception cref="ArgumentNullException">
 /// environment
 /// or
 /// services
 /// or
 /// configuration
 /// or
 /// diagnosticSource
 /// </exception>
 public LoggingBuilder(
     IConventionScanner scanner,
     IAssemblyProvider assemblyProvider,
     IAssemblyCandidateFinder assemblyCandidateFinder,
     IServiceCollection services,
     IRocketEnvironment environment,
     IConfiguration configuration,
     ILogger diagnosticSource,
     IDictionary <object, object?> properties
     ) : base(scanner, assemblyProvider, assemblyCandidateFinder, properties)
 {
     Environment   = environment ?? throw new ArgumentNullException(nameof(environment));
     Services      = services ?? throw new ArgumentNullException(nameof(services));
     Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
     Logger        = diagnosticSource ?? throw new ArgumentNullException(nameof(diagnosticSource));
 }
        /// <summary>
        /// Compares the current host environment name against the specified value.
        /// </summary>
        /// <param name="hostEnvironment">An instance of <see cref="IRocketEnvironment" />.</param>
        /// <param name="environmentName">Environment name to validate against.</param>
        /// <returns><c>true</c> if the specified environment name is environment; otherwise, <c>false</c>.</returns>
        /// <exception cref="ArgumentNullException">hostEnvironment</exception>
        public static bool IsEnvironment(
            [NotNull] this IRocketEnvironment hostEnvironment,
            [NotNull] string environmentName
            )
        {
            if (hostEnvironment == null)
            {
                throw new ArgumentNullException(nameof(hostEnvironment));
            }

            return(string.Equals(
                       hostEnvironment.EnvironmentName,
                       environmentName,
                       StringComparison.OrdinalIgnoreCase
                       ));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Uses the environment.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="environment">The environment.</param>
        /// <returns>IRocketFunctionHostBuilder.</returns>
        public static IRocketFunctionHostBuilder UseEnvironment(
            [NotNull] this IRocketFunctionHostBuilder builder,
            [NotNull] IRocketEnvironment environment
            )
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

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

            return(Swap(builder, GetOrCreateBuilder(builder, builder.FunctionsAssembly, null).With(environment)));
        }
Exemplo n.º 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RocketFunctionHostBuilder"/> class.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="functionsAssembly">The functions assembly.</param>
 /// <param name="startupInstance">The startup instance.</param>
 /// <param name="environment">The environment.</param>
 /// <param name="scanner">The scanner.</param>
 /// <param name="assemblyCandidateFinder">The assembly candidate finder.</param>
 /// <param name="assemblyProvider">The assembly provider.</param>
 /// <param name="diagnosticSource">The diagnostic source.</param>
 /// <param name="serviceProviderDictionary">The service provider dictionary of values</param>
 public RocketFunctionHostBuilder(
     IWebJobsBuilder builder,
     Assembly functionsAssembly,
     object startupInstance,
     IRocketEnvironment environment,
     IConventionScanner scanner,
     IAssemblyCandidateFinder assemblyCandidateFinder,
     IAssemblyProvider assemblyProvider,
     DiagnosticSource diagnosticSource,
     IServiceProviderDictionary serviceProviderDictionary) : base(scanner, assemblyCandidateFinder, assemblyProvider, diagnosticSource, serviceProviderDictionary)
 {
     _startupInstance  = startupInstance;
     _environment      = environment ?? CreateEnvironment();
     _logger           = new DiagnosticLogger(DiagnosticSource);
     Builder           = builder;
     FunctionsAssembly = functionsAssembly;
 }
Exemplo n.º 11
0
        /// <summary>
        /// Launches the with.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="startupInstance">The startup instance.</param>
        /// <param name="func">The function.</param>
        /// <param name="environment">The environment.</param>
        /// <param name="action">The action.</param>
        /// <returns>IWebJobsBuilder.</returns>
        /// <exception cref="Exception">Something bad happened...</exception>
        public static IWebJobsBuilder LaunchWith(
            this IWebJobsBuilder builder,
            [NotNull] object startupInstance,
            [NotNull] Func <IWebJobsBuilder, object, IRocketFunctionHostBuilder> func,
            [NotNull] IRocketEnvironment environment,
            [NotNull] Action <IRocketFunctionHostBuilder> action
            )
        {
            if (startupInstance == null)
            {
                throw new ArgumentNullException(nameof(startupInstance));
            }

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

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

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

            var b = func(builder, startupInstance);

            b.UseEnvironment(environment);
            action(b);
            if (!Builders.TryGetValue(builder, out var conventionalBuilder))
            {
                throw new Exception("Something bad happened...");
            }

            conventionalBuilder.Compose();
            return(builder);
        }
Exemplo n.º 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ServicesBuilder" /> class.
 /// </summary>
 /// <param name="scanner">The scanner.</param>
 /// <param name="assemblyProvider">The assembly provider.</param>
 /// <param name="assemblyCandidateFinder">The assembly candidate finder.</param>
 /// <param name="services">The services.</param>
 /// <param name="configuration">The configuration.</param>
 /// <param name="environment">The environment.</param>
 /// <param name="diagnosticSource">The diagnostic source.</param>
 /// <param name="properties">The properties.</param>
 /// <exception cref="ArgumentNullException">
 /// environment
 /// or
 /// diagnosticSource
 /// or
 /// configuration
 /// or
 /// services
 /// </exception>
 public ServicesBuilder(
     IConventionScanner scanner,
     IAssemblyProvider assemblyProvider,
     IAssemblyCandidateFinder assemblyCandidateFinder,
     IServiceCollection services,
     IConfiguration configuration,
     IRocketEnvironment environment,
     ILogger diagnosticSource,
     IDictionary <object, object?> properties
     )
     : base(scanner, assemblyProvider, assemblyCandidateFinder, properties)
 {
     Environment            = environment ?? throw new ArgumentNullException(nameof(environment));
     Configuration          = configuration ?? throw new ArgumentNullException(nameof(configuration));
     Services               = services ?? throw new ArgumentNullException(nameof(services));
     Logger                 = diagnosticSource ?? throw new ArgumentNullException(nameof(diagnosticSource));
     _onBuild               = new ServiceProviderObservable(Logger);
     ServiceProviderOptions = new ServiceProviderOptions
     {
         ValidateScopes = environment.IsDevelopment()
     };
 }
Exemplo n.º 13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AutofacBuilder" /> class.
        /// </summary>
        /// <param name="environment">The environment.</param>
        /// <param name="configuration">The configuration.</param>
        /// <param name="scanner">The scanner.</param>
        /// <param name="assemblyProvider">The assembly provider.</param>
        /// <param name="assemblyCandidateFinder">The assembly candidate finder.</param>
        /// <param name="services">The services.</param>
        /// <param name="containerBuilder">The container builder.</param>
        /// <param name="diagnosticSource">The diagnostic source</param>
        /// <param name="properties">The properties</param>
        /// <exception cref="ArgumentNullException">
        /// environment
        /// or
        /// containerBuilder
        /// or
        /// configuration
        /// or
        /// services
        /// </exception>
        public AutofacBuilder(
            IRocketEnvironment environment,
            IConfiguration configuration,
            IConventionScanner scanner,
            IAssemblyProvider assemblyProvider,
            IAssemblyCandidateFinder assemblyCandidateFinder,
            IServiceCollection services,
            ContainerBuilder containerBuilder,
            ILogger diagnosticSource,
            IDictionary <object, object?> properties
            )
            : base(scanner, assemblyProvider, assemblyCandidateFinder, properties)
        {
            Environment       = environment ?? throw new ArgumentNullException(nameof(environment));
            _containerBuilder = containerBuilder ?? throw new ArgumentNullException(nameof(containerBuilder));
            Configuration     = configuration ?? throw new ArgumentNullException(nameof(configuration));
            Services          = services ?? throw new ArgumentNullException(nameof(services));
            Logger            = diagnosticSource ?? throw new ArgumentNullException(nameof(diagnosticSource));

            _containerObservable    = new GenericObservableObservable <IContainer>(Logger);
            _serviceProviderOnBuild = new GenericObservableObservable <IServiceProvider>(Logger);
        }
Exemplo n.º 14
0
 /// <summary>
 /// Uses the environment.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="environment">The environment.</param>
 /// <returns>IRocketFunctionHostBuilder.</returns>
 public static IRocketFunctionHostBuilder UseEnvironment(this IRocketFunctionHostBuilder builder, IRocketEnvironment environment)
 {
     return(Swap(builder, GetOrCreateBuilder(builder, builder.FunctionsAssembly, null).With(environment)));
 }
Exemplo n.º 15
0
 /// <summary>
 /// Gets the or create builder.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="startupInstance">The startup instance.</param>
 /// <param name="environment">The environment.</param>
 /// <returns>RocketFunctionHostBuilder.</returns>
 internal static RocketFunctionHostBuilder GetOrCreateBuilder(IRocketFunctionHostBuilder builder, object startupInstance, IRocketEnvironment environment)
 {
     return(GetOrCreateBuilder(builder.Builder, startupInstance, environment));
 }
Exemplo n.º 16
0
        /// <summary>
        /// Gets the or create builder.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="startupInstance">The startup instance.</param>
        /// <param name="environment">The environment.</param>
        /// <returns>RocketFunctionHostBuilder.</returns>
        internal static RocketFunctionHostBuilder GetOrCreateBuilder(IWebJobsBuilder builder, object startupInstance, IRocketEnvironment environment)
        {
            if (!Builders.TryGetValue(builder, out var conventionalBuilder))
            {
                var diagnosticSource  = new DiagnosticListener("Rocket.Surgery.Hosting");
                var functionsAssembly = startupInstance.GetType().Assembly;

                var location = Path.GetDirectoryName(functionsAssembly.Location);
                DependencyContext dependencyContext = null;
                while (dependencyContext == null && !string.IsNullOrEmpty(location))
                {
                    var depsFilePath = Path.Combine(location, functionsAssembly.GetName().Name + ".deps.json");
                    if (File.Exists(depsFilePath))
                    {
                        using (var stream = File.Open(depsFilePath, FileMode.Open, FileAccess.Read))
                        {
                            dependencyContext = new DependencyContextJsonReader().Read(stream);
                            break;
                        }
                    }
                    location = Path.GetDirectoryName(location);
                }
                var logger = new DiagnosticLogger(diagnosticSource);
                var assemblyCandidateFinder = new DependencyContextAssemblyCandidateFinder(dependencyContext, logger);
                var assemblyProvider        = new DependencyContextAssemblyProvider(dependencyContext, logger);
                var properties = new ServiceProviderDictionary();
                var scanner    = new SimpleConventionScanner(assemblyCandidateFinder, properties, logger);
                conventionalBuilder = new RocketFunctionHostBuilder(builder, functionsAssembly, startupInstance, environment, scanner, assemblyCandidateFinder, assemblyProvider, diagnosticSource, properties);
                Builders.Add(builder, conventionalBuilder);
            }

            return(conventionalBuilder);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Uses the rocket booster.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="startupInstance">The startup instance.</param>
        /// <param name="func">The function.</param>
        /// <param name="environment">The environment.</param>
        /// <param name="action">The action.</param>
        /// <returns>IWebJobsBuilder.</returns>
        /// <exception cref="Exception">Something bad happened...</exception>
        public static IWebJobsBuilder UseRocketBooster(this IWebJobsBuilder builder, object startupInstance, Func <IWebJobsBuilder, object, IRocketFunctionHostBuilder> func, IRocketEnvironment environment, Action <IRocketFunctionHostBuilder> action)
        {
            var b = func(builder, startupInstance);

            b.UseEnvironment(environment);
            action(b);
            if (!Builders.TryGetValue(builder, out var conventionalBuilder))
            {
                throw new Exception("Something bad happened...");
            }
            conventionalBuilder.Compose();
            return(builder);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Uses the rocket Surgery.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="startupInstance">The startup instance.</param>
        /// <param name="environment">The environment.</param>
        /// <param name="action">The action.</param>
        /// <returns>IWebJobsBuilder.</returns>
        public static IWebJobsBuilder UseRocketSurgery(this IWebJobsBuilder builder, object startupInstance, IRocketEnvironment environment, Action <IRocketFunctionHostBuilder> action)
        {
            var internalBuilder = GetOrCreateBuilder(builder, startupInstance, environment);

            action(internalBuilder);
            internalBuilder.Compose();
            return(builder);
        }