Closed ss-carlo closed 1 year ago
did you try the docs? what the problem with them?
https://github.com/eXpandFramework/Reactive.XAF/tree/master/src/Modules/JobScheduler.Hangfire
there are also tests that pass
The docs just specified that I should use dependency injection to get object instances. The problem is that the constructor with the needed dependency is not being invoked when I trigger the hangfire job from the Blazor application.
is it decorated? did you try running the tests and not work as well there? do u have a sample
The code is just as basic as the sample in the docs. Here is the code for the JobProvider class. I have also attached a sample project containing this source.
`using DevExpress.ExpressApp.Blazor; using Xpand.XAF.Modules.JobScheduler.Hangfire;
namespace HfSample.Blazor.Server.Hangfire { [JobProvider] public class SampleJob { public BlazorApplication Application;
public SampleJob()
{
Console.WriteLine("Default constructor");
}
public SampleJob(BlazorApplication application)
{
Application = application;
}
public void PerformOperation1()
{
Console.WriteLine(string.Format("PerformOperation1 app={0}", Application != null));
}
public void PerformOperation2()
{
Console.WriteLine(string.Format("PerformOperation2 app={0}", Application != null));
}
}
}`
is it decorated
the link i send above uses the ActivatorUtilitiesConstructor
attribute in the ctor, can u try it
the docs look outdate passing the BlazorAPp in the ctor is not supported anymore here is a test job from the link i posted above
please try this and let me know
public class TestJob {
public static readonly Subject<TestJob> Jobs=new();
public PerformContext Context { get; protected set; }
public TestJob() { }
public IServiceProvider Provider { get; }
[ActivatorUtilitiesConstructor]
protected TestJob(IServiceProvider provider) => Provider = provider;
[AutomaticRetry(Attempts = 0)][JobProvider]
public void FailMethodNoRetry() => throw new NotImplementedException();
[AutomaticRetry(Attempts = 1,DelaysInSeconds = new[] {1})][JobProvider]
public void FailMethodRetry() => throw new NotImplementedException();
[JobProvider]
public void Test() => Jobs.OnNext(this);
[JobProvider]
public void TestJobId(PerformContext context) {
Context = context;
Jobs.OnNext(this);
}
}
}
similarly from the TestApplication u can try this https://github.com/eXpandFramework/Reactive.XAF/blob/master/src/Tests/EasyTests/TestApplication/TestApplication.Module.Blazor/JobScheduler/Job.cs
Thanks, it worked with the ActivatorUtilitiesConstructor attribute!
this is a DI attribute and not expand and I suggest you consult with Hangfire docs as it operates independent of XAF or eXpand as you can see there are more attributes u can use e.g. for Retry etc
I tried to copy the JobProvider class in the sample video but only the empty constructor is being used when the job is triggered from my blazor application. Are there additional steps to do to make dependency injection work?