Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Thomas 267 posts 548 karma points c-trib
    16 days ago
    Thomas
    0

    Umbraco 9 Hangfire Inject Service to Composer

    Hi

    I'm a little stuck here trying to get Hangfire calling a service.

    How do I inject til RitzauService correctly ?

    I'm using cultivhangfire package

    enter image description here

  • Thomas 267 posts 548 karma points c-trib
    16 days ago
    Thomas
    0

    Just thought I Had it.. But this didn't work..

    enter image description here

  • Frans Lammers 39 posts 322 karma points c-trib
    1 week ago
    Frans Lammers
    0

    Hi Thomas,

    I am not sure if I understand correctly what you are trying to do, but this is the way I implemented a custom service to be used by Hangfire:

        public class HangfireTasksComposer : IComposer
    {
    
        public void Compose(IUmbracoBuilder builder)
        {
            builder.Services.AddScoped<IRitzauService, RitzauService>();
            RecurringJob.AddOrUpdate<IRitzauService>(x => x.SyncRitzau(null), Cron.Daily()); 
        }
    
    }
    
    public interface IRitzauService
    {
        void TaskToPerform(PerformContext context);
    }
    
    public class RitzauService : IRitzauService
    {
    
    
        public void SyncRitzau(PerformContext context)
        {
            // Perform the task
        }
    }
    

    I hope this is any help.

    regards, Frans

Please Sign in or register to post replies

Write your reply to:

Draft