Quantcast
Channel: Developer to developer
Viewing all articles
Browse latest Browse all 9076

Scheduled job not running with dependency injection for my custom service injected

$
0
0

Hi,

I am facing an issue with scheduled job, that its not able to start automatically. I am getting below error:

UnableToStartException has been thrown by the target of an invocation. [Activation error occurred while trying to get instance of type ILogisticProductsService, key ""]

I have a sercvice injected into scheduled job constructor. The job works fine if I manually trigger the job. 

code snipest:

public class AgrodeskSendLogisticProductsJob : ScheduledJobBase
    {
        private readonly ILogisticProductsService _logisticProductsService;
        public AgrodeskSendLogisticProductsJob()
        {
            _logisticProductsService = ServiceLocator.Current.GetInstance<ILogisticProductsService>();
        }
        public AgrodeskSendLogisticProductsJob(ILogisticProductsService logisticProductsService)
        {
            _logisticProductsService = logisticProductsService;
        }
        private static IUserImpersonation UserImpersonation
        {
            get { return ServiceLocator.Current.GetInstance<IUserImpersonation>(); }
        }
        public override string Execute()
        {
            PrincipalInfo.CurrentPrincipal = UserImpersonation.CreatePrincipal("saam.farmer@lm2.com");
            _logisticProductsService.SendProducts();
            return "OK";
        }
    }

The dependancies are resolved in dependancy resolver.

 container.For<ILogisticProductsService>().Use<LogisticProductsService>();

anyone could you help whats wrong with this approach?


Viewing all articles
Browse latest Browse all 9076

Trending Articles