Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

BackgroundJob - Transient or Singleton? #7938


User avatar
0
OriAssurant created

Hi Abp Zero Support,

Is there any particular reason for BackgroundJob to be Transient in the document? Is there any downside if I make it Singleton?

public class TestJob : BackgroundJob<int>, ITransientDependency
{
    public override void Execute(int number)
    {
        Logger.Debug(number.ToString());
    }
}

https://aspnetboilerplate.com/Pages/Documents/Background-Jobs-And-Workers

Thank you, R


4 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    Implementing ITransientDependency is the simplest way.

    For the lifetimes of the dependency injection service, please refer to: https://medium.com/volosoft/asp-net-core-dependency-injection-best-practices-tips-tricks-c6e9c67f9d96

  • User Avatar
    0
    OriAssurant created

    Thank you for the response maliming. Do you mean it's not using ISingletonDependency because ISingletonDependency is more error prone, like concurrency conflicts and memory lead, for a background job?

  • User Avatar
    0
    maliming created
    Support Team

    Yes

  • User Avatar
    0
    ismcagdas created
    Support Team

    This issue is closed because it has not had recent activity for a long time.