Skip to content

Instantly share code, notes, and snippets.

@gabrielfuller
Created January 26, 2012 12:14
Show Gist options
  • Save gabrielfuller/1682520 to your computer and use it in GitHub Desktop.
Save gabrielfuller/1682520 to your computer and use it in GitHub Desktop.
Quartz.net Integration with Windsor Castle and Asp.net MVC 3
protected virtual void InitializeServiceLocator()
{
var container = new WindsorContainer(new XmlInterpreter());
container.AddFacility("quartznet", new QuartzFacility());
//Get All Controller Instances in Assembly and Add to IWindsorContainer
ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(container));
var controllerTypes = (from t in Assembly.GetAssembly(typeof (BaseController)).GetExportedTypes()
where typeof (IController).IsAssignableFrom(t)
select t).ToArray();
container.RegisterControllers(controllerTypes);
// Register HttpContext(Base) and HttpRequest(Base) so it automagically can be injected using IoC
container.AddFacility<FactorySupportFacility>();
container.Register(Component.For<HttpRequestBase>().LifeStyle.PerWebRequest
.UsingFactoryMethod(() => new HttpRequestWrapper(HttpContext.Current.Request)));
container.Register(Component.For<HttpContextBase>().LifeStyle.PerWebRequest
.UsingFactoryMethod(() => new HttpContextWrapper(HttpContext.Current)));
var facility = new QuartzFacility();
ComponentRegistrar.AddComponentsTo(container);
ServiceLocator.SetLocatorProvider(() => new WindsorServiceLocator(container));
}
<?xml version="1.0" encoding="utf-8" ?>
<quartz xmlns="http://quartznet.sourceforge.net/JobSchedulingData"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="1.0"
overwrite-existing-jobs="true">
<job>
<job-detail>
<name>hello-world</name>
<job-type>SampleApp.SampleJob, SampleApp</job-type>
<durable>true</durable>
</job-detail>
</job>
</quartz>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment