Copied to clipboard

Flag this post as spam?

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


  • Thomas 319 posts 606 karma points c-trib
    May 11, 2022 @ 12:26
    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 319 posts 606 karma points c-trib
    May 11, 2022 @ 12:42
    Thomas
    0

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

    enter image description here

  • Frans Lammers 57 posts 400 karma points c-trib
    May 16, 2022 @ 13:13
    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

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies