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