Example #1
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);
        }
 /// <summary>
 /// Swaps the specified builder.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="newRocketFunctionBuilder">The new rocket function builder.</param>
 /// <returns>RocketFunctionHostBuilder.</returns>
 internal static RocketFunctionHostBuilder Swap(
     IRocketFunctionHostBuilder builder,
     RocketFunctionHostBuilder newRocketFunctionBuilder
     )
 {
     Builders.Remove(builder.Builder);
     Builders.Add(builder.Builder, newRocketFunctionBuilder);
     return(newRocketFunctionBuilder);
 }