开发者

How to setup a schedueler factory with Ninject and Quartz:

I am using Quartz and Ninject and I would love to be able to GetScheduler's automatically binded(similar to how you can bind sessions automatically with ninje开发者_开发问答ct and nihbernate).

// construct a scheduler factory
ISchedulerFactory schedFact = new StdSchedulerFactory();

// get a scheduler
IScheduler sched = schedFact.GetScheduler();

What I would like to do is this

public class MyService
{
   private readonly IScheduler sched;

   public MyService(IScheduler sched)
   {
       this.sched = sched;
   }

   public void Test()
    {
         sched.Start();
         // go on.
     }
}

So when I call MySerivce it should see the IScheduler and get from the factored a scheduler and pass it in.

This was the only thing I could find on it and it seems to be more advanced then what I want and is in a windows service setting where I am using asp.net mvc 3.

Edit

This is what I come up so far but still crashes

public class QuartzSchedulerFactoryProvider : Provider<ISchedulerFactory>
    {
        protected override ISchedulerFactory CreateInstance(IContext context)
        {
            var schedulerFactory = new StdSchedulerFactory();
            return schedulerFactory;
        }
    }

    public class NhibernateSessionFactoryProvider : Provider<ISessionFactory>
    {   
        protected override ISessionFactory CreateInstance(IContext context)
        {
            var sessionFactory = new NhibernateSessionFactory();
            return sessionFactory.GetSessionFactory();
        }
    }

     public class QuartzModule : NinjectModule
    {
        public override void Load()
        {
            Bind<ISchedulerFactory>().ToProvider<QuartzSchedulerFactoryProvider>().InSingletonScope();
            Bind<IScheduler>().ToMethod(context => context.Kernel.Get<ISchedulerFactory>().GetScheduler()).InRequestScope();
        }
    }



        protected IKernel CreateKernel()
        {
            var modules = new INinjectModule[]
                              {
                                 new QuartzModule()
                              };

            return new StandardKernel(modules);
        }

Could not load file or assembly 'Common.Logging, Version=1.2.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e' or one of its dependencies. The system cannot find the file specified. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'Common.Logging, Version=1.2.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e' or one of its dependencies. The system cannot find the file specified.

Source Error:

Line 13: protected override ISchedulerFactory CreateInstance(IContext context) Line 14: { Line 15: var schedulerFactory = new StdSchedulerFactory(); Line 16:

return schedulerFactory; Line 17:

}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜