public async Task <bool> HandleAsync(JobContextMessage jobContextMessage, CancellationToken cancellationToken) { var fundingServiceContext = new FundingServiceContext(jobContextMessage); try { using (var childLifeTimeScope = _lifetimeScope.BeginLifetimeScope()) { // Get logger ExecutionContext executionContext = (ExecutionContext)childLifeTimeScope.Resolve <IExecutionContext>(); executionContext.JobId = jobContextMessage.JobId.ToString(); _logger.LogDebug("Started Funding Calc Service"); var preFundingSfOrchestrationService = childLifeTimeScope.Resolve <IFundingOrchestrationService>(); // Call logic asynchronously, and return on initial context (no .ConfigureAwait(false)) await preFundingSfOrchestrationService.ExecuteAsync(fundingServiceContext, cancellationToken); _logger.LogDebug("Completed Funding Calc Service"); } ServiceEventSource.Current.ServiceMessage(_context, "Completed Funding Calc Service"); return(true); } catch (OutOfMemoryException oom) { Environment.FailFast("Funding Service Out Of Memory", oom); throw; } catch (Exception ex) { ServiceEventSource.Current.ServiceMessage(_context, "Exception-{0}", ex.ToString()); throw; } }
public async Task <IDesktopContext> ExecuteAsync(IDesktopContext desktopContext, CancellationToken cancellationToken) { // Create context var fundingServiceContext = new FundingServiceContext(desktopContext); using (var cacheLifetimeScope = _lifeTimeScope.BeginLifetimeScope()) { var refereceData = await cacheLifetimeScope.Resolve <IFileProviderService <ReferenceDataRoot> >().ProvideAsync(fundingServiceContext, cancellationToken); var externalDataCache = BuildExternalDataCache(cacheLifetimeScope.Resolve <IExternalDataCachePopulationService>().PopulateAsync(refereceData, cancellationToken)); using (var orchestratorLifetimeScope = cacheLifetimeScope.BeginLifetimeScope(c => c.RegisterInstance(externalDataCache).As <IExternalDataCache>())) { // resolve Orchestrator var orchestrator = orchestratorLifetimeScope.Resolve <IFundingOrchestrationService>(); await orchestrator.ExecuteAsync(fundingServiceContext, cancellationToken); } } return(desktopContext); }