Base solution for your next web application

Activities of "nicolas33"

Question

Hi all...

I have some issues using Hangfire when I need to access Database. I've read here that I maybe shouldn't use HangFire to call Application Service but I don't see how I could do what I want to do another way.

Actually I have in my Startup.cs from my Web project :

[...]

app.UseHangfireDashboard();
app.UseHangfireServer();

RecurrentJobs recurrentJobs = new RecurrentJobs(IocManager.Instance);
RecurringJob.AddOrUpdate(() => recurrentJobs.LaunchJobsRecurrentFiveMinutes(), "0,5,10,15,20,25,30,35,40,45,50,55 * * * *");

[...]

In the RecurrentJobs.cs file, I have this call, which try to call a method in the ApplicationService ("AjouterMessageSysteme") :

[...]

        [UnitOfWork]
        public void LaunchJobsRecurrentFiveMinutes()
        {
            [...]
                using (var messageService = _iocResolver.ResolveAsDisposable<MessageAppService>())
                {
                    var source = LocalizationHelper.Manager.GetSource("MyProject");

                    foreach (var concoursId in retourMajQualif.ListeIdConcoursQualifMaj)
                    {
                        messageService.Object.AjouterMessageSysteme(
                        new AjouterMessageInput
                        {
                            ConcoursId = concoursId,
                            Contenu = source.GetString("finQualifications")
                        });
                    }
                }

            [...]
            }
        }

[...]

In the MessageAppService.cs I have this code :

[...]

        public AjouterMessageOutput AjouterMessageSysteme(AjouterMessageInput input)
        {
            var concours = _concoursRepository.GetAllWithParticipants().Where(c => c.Id == input.ConcoursId).FirstOrDefault();

            foreach (var part in concours.ListeParticipants)
            {
                _messageRepository.Insert(new Message
                {
                    ConcoursId = input.ConcoursId,
                    Contenu = input.Contenu,
                    DestinataireId = part.UserId,
                    EnvoyeurId = 0
                });
            }

            return new AjouterMessageOutput();
        }

[...]

The issue is when I call the method " _concoursRepository.GetAllWithParticipants()", which call a GetAll() with some includes. The object "concours " is always disposed before it can be used. I guess it's because the whole process isn't a "Unit Of Work", but I don't know how I can declare it beside the annotation on method in the class "RecurrentJobs". I succesfully could call a procedure from database, but I can't get data. Of course, if the method of the application service is called from a controller, it works perfectly.

Is there a way I can do this, or ABP/HangFire isn't designed to work like this ?

I apologize for my approximative english, thanx in advance for any help.

Showing 1 to 1 of 1 entries