private FunctionHostBuilder CreateBuilderFromConfiguration( ICommandRegistry commandRegistry, IFunctionAppConfiguration configuration) { FunctionHostBuilder builder = new FunctionHostBuilder(ServiceCollection, commandRegistry, true); configuration.Build(builder); DefaultMediatorSettings.SetDefaultsIfRequired(builder); RegisterCommandHandlersForCommandsWithNoAssociatedHandler(builder, commandRegistry); IMediatorResultTypeExtractor extractor = (IMediatorResultTypeExtractor)Activator.CreateInstance(builder.Options.MediatorResultTypeExtractor); new PostBuildPatcher(extractor).Patch(builder, ""); return(builder); }
public bool Compile() { string newAssemblyNamespace = $"{_configurationSourceAssembly.GetName().Name.Replace("-", "_")}.Functions"; IFunctionCompilerMetadata functionCompilerMetadata = null; IFunctionAppConfiguration configuration = null; FunctionAppHostBuilder appHostBuilder = null; IFunctionAppHost appHost = ConfigurationLocator.FindFunctionAppHost(_configurationSourceAssembly); if (appHost != null) { appHostBuilder = new FunctionAppHostBuilder(); appHost.Build(appHostBuilder); if (appHostBuilder.FunctionAppConfiguration != null) { configuration = (IFunctionAppConfiguration)Activator.CreateInstance(appHostBuilder.FunctionAppConfiguration); } } if (configuration == null) { configuration = ConfigurationLocator.FindConfiguration(_configurationSourceAssembly); } if (configuration == null) { functionCompilerMetadata = ConfigurationLocator.FindCompilerMetadata(_configurationSourceAssembly); if (functionCompilerMetadata == null) { _compilerLog.Error($"The assembly {_configurationSourceAssembly.GetName().Name} does not contain a public class implementing the IFunctionAppConfiguration interface"); return(false); } } else { FunctionHostBuilder builder = new FunctionHostBuilder(_serviceCollection, _commandRegistry, false); if (appHostBuilder != null) { builder.Options = appHostBuilder.Options; } configuration.Build(builder); DefaultMediatorSettings.SetDefaultsIfRequired(builder); if (!ValidateCommandTypes(builder)) { return(false); } IMediatorResultTypeExtractor extractor = CreateMediatorResultTypeExtractor(builder.Options.MediatorResultTypeExtractor); if (extractor == null) { return(false); } new PostBuildPatcher(extractor).Patch(builder, newAssemblyNamespace); if (!VerifyCommandAndResponseTypes(builder)) { return(false); } if (!VerifyOutputBindings(builder)) { return(false); } functionCompilerMetadata = new FunctionCompilerMetadata { FunctionDefinitions = builder.FunctionDefinitions, OpenApiConfiguration = builder.OpenApiConfiguration, OutputAuthoredSourceFolder = builder.Options.OutputSourceTo, CompilerOptions = builder.Options }; } PostBuildPatcher.EnsureFunctionsHaveUniqueNames(functionCompilerMetadata.FunctionDefinitions); IReadOnlyCollection <string> externalAssemblies = GetExternalAssemblyLocations(functionCompilerMetadata.FunctionDefinitions); ITargetCompiler targetCompiler = functionCompilerMetadata.CompilerOptions.HttpTarget == CompileTargetEnum.AzureFunctions ? (ITargetCompiler) new AzureFunctionsCompiler(_compilerLog) : new AspNetCoreCompiler(_compilerLog); return(targetCompiler.CompileAssets(functionCompilerMetadata, newAssemblyNamespace, configuration, externalAssemblies, _outputBinaryFolder)); }