[英]Instance of a class in Create method of JobBuilder in quartz.net
The default create method of JobBuilder is JobBuilder的默认创建方法是
IJobDetail paymentJob = JobBuilder.Create<Hello>().WithIdentity(jobName, groupName).Build();
I checked the overloads but there is no overload in which we can have an instance of a class inside. 我检查了重载但是没有重载我们可以在里面有一个类的实例。 the create method.
创建方法。 Something like this
像这样的东西
IJobDetail paymentJob = JobBuilder.Create<new Hello()>().WithIdentity(jobName, groupName).Build();
but this gives an error 但这会给出错误
Operator < cannot be applied to the 'method group' or 'Hello'
运算符<无法应用于'方法组'或'Hello'
The reason i need this is: 我需要这个的原因是:
public abstract class Hello:IJob
{
public abstract void Execute(IJobExecutionContext context);
}
public Hello1: Hello
{
public void Execute(IJobExecutionContext context)
{
//implementation
}
}
public Hello2: Hello
{
public void Execute(IJobExecutionContext context)
{
//implementation
}
}
public static HelloFactory
{
public Hello GetHelloType(HelloEnum enum)
{
Hello job = new Hello();
switch(enum)
{
case HelloEnum.Type1: job = new Hello1();
case HelloEnum.Type2: job = new Hello2();
}
}
}
Just change your HelloFactory to return a Type object instead of a Hello object: 只需更改HelloFactory即可返回Type对象而不是Hello对象:
public static class HelloFactory
{
public Type GetHelloType(HelloEnum theEnum)
{
Type type;
switch (theEnum)
{
case HelloEnum.Type1:
type = typeof(Hello1);
break;
case HelloEnum.Type2: job = typeof(Hello2);
break;
}
}
}
Alternatively, implement your own JobFactory. 或者,实现自己的JobFactory。 Here's an exmaple on how to implement one: http://jayvilalta.com/blog/2012/07/23/creating-a-custom-quartz-net-jobfactory/
以下是如何实施一个例子: http : //jayvilalta.com/blog/2012/07/23/creating-a-custom-quartz-net-jobfactory/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.