我正在我的应用程序中使用hangfire进行入队作业。
我的入队职务陈述如下:
string jobId = BackgroundJob.Enqueue(() =>
strategy.get(typeof(_service.Engine.Summary), cpdata));
当这会成功排队我的工作但是在状态表中收到错误消息,如
" FailedAt":" 2018-03-21T13:14:46.0172303Z"," ExceptionType": " System.MissingMethodException"," ExceptionMessage":"否 为此对象定义的无参数构造函数。",
" ExceptionDetails":" System.MissingMethodException:无参数 为此对象定义的构造函数。\ r \ n at System.RuntimeTypeHandle.CreateInstance(RuntimeType类型,布尔值 publicOnly,Boolean noCheck,Boolean& canBeCached, RuntimeMethodHandleInternal&安培; ctor,布尔& bNeedSecurityCheck个)\ r \ n
在System.RuntimeType.CreateInstanceSlow(Boolean publicOnly,Boolean skipCheckThis,Boolean fillCache,StackCrawlMark& stackMark)\ r \ n at System.Activator.CreateInstance(Type type,Boolean nonPublic)\ r \ n at System.Activator.CreateInstance(Type type)\ r \ n at Hangfire.JobActivator.SimpleJobActivatorScope.Resolve(Type type)\ r \ n
在Hangfire.Server.CoreBackgroundJobPerformer.Perform(PerformContext 上下文)\ r \ n at Hangfire.Server.BackgroundJobPerformer<> c__DisplayClass8_0.b__0(个)\ r \ n 在 Hangfire.Server.BackgroundJobPerformer.InvokePerformFilter(IServerFilter filter,PerformingContext preContext,Func 1 continuation)\ r \ n at Hangfire.Server.BackgroundJobPerformer.PerformJobWithFilters(PerformContext 上下文,IEnumerable`1过滤器)\ r \ n at Hangfire.Server.BackgroundJobPerformer.Perform(PerformContext 上下文)\ r \ n at Hangfire.Server.Worker.PerformJob(BackgroundProcessContext context, IStorageConnection连接,String jobId)"
这个DI问题会造成这种类型的错误吗?
我使用此链接的引用
在Enqueue中使用了调用方法Factory method with DI and IOC
例如,
var strategy = new CarStrategy(new ICarFactory[] {
new Car1Factory(dep1, dep2, dep3),
new Car2Factory(dep4, dep5, dep6),
new Car3Factory(dep7, dep8, dep9)
});
我的代码就是这样,
var strategy = new Strategy(new ICP[] {
new _Services.Engine.Detail.Detail(),
new _1Services.Engine.Summary.Summary(),
});
var CP = PrepareCPModelForEngine(c);
string jobId = BackgroundJob.Enqueue(() =>
strategy.get(typeof(_Services.Engine.Summary.Summary), cp));