Quartz .net does not work when I inject dependency

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

MetChul

Thread Starter
Joined
Mar 11, 2016
Messages
1
I am using Quartz .net v2.3.3.0 and Castle Windsor v3.3.0.0.

I have a job which is dependent on a Service

public class DemoJob : IJob
{
private readonly IService _Service;

public DemoJob(IService Service)
{
_Service = Service;
}
public void Execute(IJobExecutionContext context)
{
_Service.CallRepoMethod();
}
}


This is the service class which is in different project

public class Service: IService
{

public void CallRepoMethod()
{
Repo();
}
}
Everything works fine till now.

But as soon as I inject dependency in service class the job is not executed.

public class Service: IService
{
private readonly IRepository _repository;

Service(IRepository repository)
{
_repository = repository;
}
public void CallRepoMethod()
{
_repository.Repo();
}
}
IRepository is implemented by a simple Repository class with a single method.
Repository class is in different project and IService,Service and IRepository are in same project.

I don't get any error message but the job does not get executed. If i remove dependency from the Service class then everything works fine and jobs execute.


Here is how I have registered the dependencies

internal class CastleWindsorContainer : IContainer
{
public static WindsorContainer Container { get; private set; }

public CastleWindsorContainer()
{
Container = new WindsorContainer();
}

public void Register()
{

Container.Register(Component.For<IRepository>().ImplementedBy<Repository>().LifestyleTransient());

public Object Resolve(Type controllerType)
{
return Container.Resolve(controllerType);
}

public void Release(IController controller)
{
Container.Release(controller);
}


public void RegisterJobs(IJobFactory jobFactory)
{
Container.Register(Component.For<IJobFactory>().Instance(jobFactory).LifestyleTransient());
Container.Register(Component.For<IQuartzInitializer>().ImplementedBy<JobsConfig>().LifestyleTransient());
Container.Register(Component.For<IService>().ImplementedBy<Service>().LifestyleTransient());
Container.Register(Component.For<DemoJob>().ImplementedBy<DemoJob>().LifestyleTransient()

);
Container.Resolve<IQuartzInitializer>().RegisterJobs();
}

}


code in Global.asax


var container = new CastleWindsorContainer();

IJobFactory jobFactory = new WindsorJobFactory(container);

container.Register();
container.RegisterJobs(jobFactory);

I am not able to figure out what's wrong. I searched for the solution and found many links but it didn't help because all of them show only one level of dependency. What if the dependent class is dependent on another class?

You can find my demo project here: http://github.com/MieChul/QuartzWindsor

Some links I checked
http://bugsquash.blogspot.in/2009/03/windsor-facility-for-quartznet.html

Thank You


 
Joined
Apr 6, 2016
Messages
1
Hi MetChul,

I see two options.
- Reduce your dependencies to a proven/dependable working state
- Pinpoint the component triggering your issue

For the latter, I would suggest a try catch design for your functions to write to the console or perhaps to a log if you're deploying on another server. Any feedback to narrow down your scenarios.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Members online

Top