Ejemplo n.º 1
0
 public IActionResult GetUsingMethodInjection([FromServices] IMyService myService)
 {
     if (myService == null)
     {
         throw new ArgumentNullException(nameof(myService));
     }
     myService.Execute();
     return(Ok("Success!"));
 }
Ejemplo n.º 2
0
    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);
            }
        }
    }
Ejemplo n.º 3
0
 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);
     }
 }
Ejemplo n.º 4
0
 public async Task Handle(MyMessage message, int retryCount)
 {
     throw new Exception("Errour");
     var id = await _myService.Execute(message);
 }
Ejemplo n.º 5
0
 public IActionResult GetUsingConstructorInjection()
 {
     _myService.Execute();
     return(Ok("Success!"));
 }
 protected override void ExecuteJob(JobExecutionContext context)
 {
     myService = ObjectFactory.GetInstance<IMyService>();
     myService.Execute();
 }