Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3938672
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:12:41+00:00 2026-05-20T00:12:41+00:00

Does anyone have any experience integrating autofac and Quartz.Net ? If so, where is

  • 0

Does anyone have any experience integrating autofac and Quartz.Net? If so, where is it best to control lifetime management — the IJobFactory, within the Execute of the IJob, or through event listeners?


Right now, I’m using a custom autofac IJobFactory to create the IJob instances, but I don’t have an easy way to plug in to a ILifetimeScope in the IJobFactory to ensure any expensive resources that are injected in the IJob are cleaned up. The job factory just creates an instance of a job and returns it. Here are my current ideas (hopefully there are better ones…)

  • It looks like most AutoFac integrations somehow wrap a ILifetimeScope around the unit of work they create. The obvious brute force way seems to be to pass an ILifetimeScope into the IJob and have the Execute method create a child ILifetimeScope and instantiate any dependencies there. This seems a little too close to a service locator pattern, which in turn seems to go against the spirit of autofac, but it might be the most obvious way to ensure proper handling of a scope.

  • I could plug into some of the Quartz events to handle the different phases of the Job execution stack, and handle lifetime management there. That would probably be a lot more work, but possibly worth it if it gets cleaner separation of concerns.

  • Ensure that an IJob is a simple wrapper around an IServiceComponent type, which would do all the work, and request it as Owned<T>, or Func<Owned<T>>. I like how this seems to vibe more with autofac, but I don’t like that its not strictly enforceable for all implementors of IJob.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T00:12:42+00:00Added an answer on May 20, 2026 at 12:12 am

    Without knowing too much about Quartz.Net and IJobs, I’ll venture a suggestion still.

    Consider the following Job wrapper:

    public class JobWrapper<T>: IJob where T:IJob
    {
        private Func<Owned<T>> _jobFactory;
    
        public JobWrapper(Func<Owned<T>> jobFactory)
        {
            _jobFactory = jobFactory;
        }
    
    
        void IJob.Execute()
        {
            using (var ownedJob = _jobFactory())
            {
                var theJob = ownedJob.Value;
                theJob.Execute();
            }
        }
    }
    

    Given the following registrations:

    builder.RegisterGeneric(typeof(JobWrapper<>));
    builder.RegisterType<SomeJob>();
    

    A job factory could now resolve this wrapper:

    var job = _container.Resolve<JobWrapper<SomeJob>>();
    

    Note: a lifetime scope will be created as part of the ownedJob instance, which in this case is of type Owned<SomeJob>. Any dependencies required by SomeJob that is InstancePerLifetimeScope or InstancePerDependency will be created and destroyed along with the Owned instance.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone have any experience creating a skin engine for asp.net MVC? I know
Does anyone have any experience integrating the Papyrus toolkit in an iPhone / iPad
Does anyone have any experience of using SproutCore together with ASP.NET MVC? For what
Does anyone have any experience querying FlexLM? (At a minimum) I need to be
Does anyone have any experience using PHP to send an sms via skype I
Does anyone have any experience with the following fluent config error? faultString = An
Does anyone have any experience with doing mail merge from Java on a word
Does anyone have any experience of storing data in JavaScript across all mobile platforms
Does anyone have any experience with this sort of thing? I'm talking about applets
Does anyone have any good advice or experience on how to create an engine

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.