Created
July 18, 2014 16:10
-
-
Save stevejay/14bd13d0aae8a16f6b26 to your computer and use it in GitHub Desktop.
StructureMapJobFactory for Quartz.Net
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Globalization; | |
using Common.Logging; | |
using Quartz; | |
using Quartz.Spi; | |
using StructureMap; | |
using LogManager = Common.Logging.LogManager; | |
namespace Scheduler | |
{ | |
public class StructureMapJobFactory : IJobFactory | |
{ | |
private static readonly ILog Log = LogManager.GetCurrentClassLogger(); | |
public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler) | |
{ | |
var jobDetail = bundle.JobDetail; | |
var jobType = jobDetail.JobType; | |
try | |
{ | |
if (Log.IsDebugEnabled) | |
{ | |
Log.Debug(string.Format(CultureInfo.InvariantCulture, "Producing instance of Job '{0}', class={1}", jobDetail.Key, jobType.FullName)); | |
} | |
return (IJob)ObjectFactory.Container.GetInstance(jobType); | |
} | |
catch (Exception e) | |
{ | |
var se = new SchedulerException(string.Format(CultureInfo.InvariantCulture, "Problem instantiating class '{0}'", jobDetail.JobType.FullName), e); | |
throw se; | |
} | |
} | |
public void ReturnJob(IJob job) | |
{ | |
// ReSharper disable once SuspiciousTypeConversion.Global | |
var disposable = job as IDisposable; | |
if (disposable != null) | |
{ | |
disposable.Dispose(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment