Run job with object properties


#1

Hello, Im trying to schdule recurring job and the method it is use is a method of custom class I created. the method itself access properties of the class instance but in runtime all the properties is not initialized. I understood that is something with IOC Containers and DI but I can’t get it work with Autofac framework.

there is any tutorial for this? my class not use interface.


#2

If you want the data to be available on the class you need to pass it in as parameters to the method, or you need the class to have the values hard-coded into the class.


#3

But in this way I miss all the concept of classes, and the values can’t be hard coded because they different from one instance to another.


#4

If you really need all that data on your classes, you should create a separate class just for a job, that job should have a single method lets say Perform(param1, param2, param3)

Pass that method all the data you need to build up the class you need and new up the class in the job or in a service method called by the job.

That is how you should approach using hangfire.