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

Hangfire Dependency injection issue #1363


User avatar
0
gunpal5 created

Hello,

I am trying to setup Hangfire on my production environment. I have setup it according to this article: <a class="postlink" href="http://docs.hangfire.io/en/latest/deployment-to-production/making-aspnet-app-always-running.html">http://docs.hangfire.io/en/latest/deplo ... nning.html</a>

but i am getting this issue.

Failed An exception occurred during processing of a background job. 


System.MissingMethodException

No parameterless constructor defined for this object.
System.MissingMethodException: No parameterless constructor defined for this object.
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.Activator.CreateInstance(Type type)
   at Hangfire.JobActivator.SimpleJobActivatorScope.Resolve(Type type)
   at Hangfire.Server.CoreBackgroundJobPerformer.Perform(PerformContext context)
   at Hangfire.Server.BackgroundJobPerformer.<>c__DisplayClass8_0.<PerformJobWithFilters>b__0()
   at Hangfire.Server.BackgroundJobPerformer.InvokePerformFilter(IServerFilter filter, PerformingContext preContext, Func`1 continuation)
   at Hangfire.Server.BackgroundJobPerformer.PerformJobWithFilters(PerformContext context, IEnumerable`1 filters)
   at Hangfire.Server.BackgroundJobPerformer.Perform(PerformContext context)
   at Hangfire.Server.Worker.PerformJob(BackgroundProcessContext context, IStorageConnection connection, String jobId)

My background Job class is as follows:

private IBizMovMailer _bizMovMailer;
        private ISmsSender _smsSender;
        private IAppNotifier _appNotifier;
        private IRepository<VideoProject, long> _videoProjectRepository;
        private UserManager _userManager;
        public BizMovNotificationJob(IBizMovMailer bizMovMailer, ISmsSender smsSender, IAppNotifier appNotifier, IRepository<VideoProject, long> videoProjectRepository, UserManager userManager)
        {
            _bizMovMailer = bizMovMailer;
            _smsSender = smsSender;
            _appNotifier = appNotifier;
            _videoProjectRepository = videoProjectRepository;
            _userManager = userManager;

            this.LocalizationSourceName = BizMovConsts.LocalizationSourceName;
        }

        public override void Execute(BizMovNotificationJobArgs args)
        {..
...
}
}

I have tried to add AbpBootrapper in the ApplicationPreload of Hangfire, like this:

public class ApplicationPreload : System.Web.Hosting.IProcessHostPreloadClient
    {
        public void Preload(string[] parameters)
        {
            var bootstrapper = new AbpBootstrapper();


            bootstrapper.IocManager.IocContainer
                .AddFacility<LoggingFacility>(f => f.UseLog4Net()
                    .WithConfig("log4net.config")
                );

            bootstrapper.Initialize();
            HangfireBootstrapper.abpBootstrapper = bootstrapper;
            HangfireBootstrapper.Instance.Start();

        }
    }

but I am still getting the mentioned issue.

Any suggestion on this will be helpful.

Thanks, Gunpal Jain


2 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    I don't suggest this approach. Because in that way you initialize ABP twice. Also, read this one: <a class="postlink" href="https://msdn.microsoft.com/en-us/library/system.web.hosting.iprocesshostpreloadclient(v=vs.110">https://msdn.microsoft.com/en-us/librar ... t(v=vs.110</a>).aspx#Anchor_2

    This interface is intended primarily for use by WCF applications that are non-HTTP applications. ASP.NET developers who want to preload ASP.NET Web applications should use the simulated HTTP requests in IIS 7.0 combined with the Application_Start method in the Global.asax file.

    I suggest you to make fake requests to your application in order to keep it alive. Either make requests internally, or using another tool.

    And initialize hangfire with Abp.HangFire package as described in our document: <a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Hangfire-Integration">http://www.aspnetboilerplate.com/Pages/ ... ntegration</a>

  • User Avatar
    0
    gunpal5 created

    Hi, I will try to use your approach.

    Thank You.