public IActionResult GetUsingMethodInjection([FromServices] IMyService myService) { if (myService == null) { throw new ArgumentNullException(nameof(myService)); } myService.Execute(); return(Ok("Success!")); }
protected override async Task ExecuteAsync(CancellationToken cancellationToken) { using (var scope = _serviceScopeFactory.CreateScope()) { IMyService myScopedService = scope.ServiceProvider.GetRequiredService <IMyService>(); while (!cancellationToken.IsCancellationRequested) { await myScopedService.Execute(); await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken); } } }
public async Task Handle(MyMessage message, int retryCount) { try { Console.WriteLine("Consumed " + message.Id); throw new Exception("Errour"); var id = await _myService.Execute(message); } catch (Exception ex) { _messageBus.RetryPublish(new MyMessage() { Content = "Nouveau " + DateTime.Now.ToShortDateString(), Id = message.Id }, retryCount); } }
public async Task Handle(MyMessage message, int retryCount) { throw new Exception("Errour"); var id = await _myService.Execute(message); }
public IActionResult GetUsingConstructorInjection() { _myService.Execute(); return(Ok("Success!")); }
protected override void ExecuteJob(JobExecutionContext context) { myService = ObjectFactory.GetInstance<IMyService>(); myService.Execute(); }