/// <summary> /// Initialises a new instance of the <see cref="BlueprintApiBuilder" /> class with the given /// <see cref="IServiceCollection" /> in to which all DI registrations will be made. /// </summary> /// <param name="services">The service collection to configure.</param> public BlueprintApiBuilder(IServiceCollection services) { this.Services = services; this._options = new BlueprintApiOptions(); this._pipelineBuilder = new PipelineBuilder(this); this._operationScanner = new OperationScanner(); this._executionScanner = new ExecutorScanner(); if (BlueprintEnvironment.IsPrecompiling) { // The default strategy is to build to a DLL to the temp folder this.Compilation(c => c.UseFileCompileStrategy(Path.GetDirectoryName(typeof(BlueprintApiBuilder).Assembly.Location))); } else { // The default strategy is to build to a DLL to the temp folder this.Compilation(c => c.UseFileCompileStrategy(Path.Combine(Path.GetTempPath(), "Blueprint.Compiler"))); } }
internal void FindAndRegister( OperationScanner operationScanner, IServiceCollection services, List <ApiOperationDescriptor> operations) { var problems = new List <string>(); foreach (var operation in operations) { foreach (var scanner in this._scanners) { var handlers = scanner.FindHandlers(services, operation.OperationType, operationScanner.ScannedAssemblies); foreach (var handler in handlers) { // Not ideal using exceptions here, done to avoid duplicating the exception messaging around multiple operations try { operation.RegisterHandler(handler); } catch (Exception e) { problems.Add(e.Message); } } } if (operation.Handlers.Count == 0) { problems.Add($"Could not find any handlers for the operation {operation}"); } } if (problems.Any()) { throw new InvalidOperationException($"Problems were found during handler scanning:\n\n{string.Join("\n", problems)}"); } }