public async Task <ILotteryCalculator> GetLotteryCalculatorAsync(string orderId) { IOrderingApplicationService orderingApplicationService = _iocResolver.GetRequiredService <IOrderingApplicationService>(); var lotteryMerchanteOrder = await orderingApplicationService.FindOrderAsync(orderId); ObjectFactory objectFactory = _objectFactories.GetOrAdd(lotteryMerchanteOrder.LotteryId, (lotteryId) => { if (_lotteryCalculatorImplementationTypes.TryGetValue(lotteryId, out Type implementationType)) { ObjectFactory factory = ActivatorUtilities.CreateFactory(implementationType, new Type[] { typeof(LotteryMerchanteOrder) }); return(factory); } throw new KeyNotFoundException($"Lottery {nameof(lotteryId)} not implementation ILotteryCalculator"); }); ILotteryCalculator lotteryCalculator = objectFactory.Invoke(_iocResolver, new[] { lotteryMerchanteOrder }) as ILotteryCalculator; return(lotteryCalculator); }
public async Task <bool> RunAsync(AwardingScheduleArgs args) { IUnitOfWorkManager unitOfWorkManager = _iocResolver.GetRequiredService <IUnitOfWorkManager>(); using (var uow = unitOfWorkManager.Begin()) { ILotteryCalculator lotteryCalculator = await _lotteryCalculatorFactory.GetLotteryCalculatorAsync(args.LdpOrderId); Handle handle = await lotteryCalculator.CalculateAsync(); _logger.LogInformation("Execute Awarding Scheduler: {0}-{1}-{2}", args.LdpMerchanerId, args.LdpOrderId, handle); uow.Complete(); switch (handle) { case Handle.Winner: await _dispatchQueryingMessageService.PublishAsync(args.LdpOrderId, args.LdpMerchanerId, args.LvpOrderId, args.LvpMerchanerId, args.LotteryId, QueryingTypes.Awarding); return(true); case Handle.Losing: await _lotteryNoticingMessagePublisher.PublishAsync($"LotteryOrdering.Awarded.{args.LvpMerchanerId}", new NoticeMessage <LotteryAwarded>(args.LdpOrderId, args.LdpMerchanerId, new LotteryAwarded { LvpOrderId = args.LvpOrderId, LvpMerchanerId = args.LvpMerchanerId, BonusAmount = 0, AftertaxBonusAmount = 0, AwardingType = LotteryAwardingTypes.Loseing, })); return(true); case Handle.Waiting: return(false); } return(false); } }