我尝试使用Quartz和Autofac Autofac.Extras.Quartz库。但是我的代码崩溃了 它很简单但崩溃了:
sqrt()
,例外:
using Autofac;
using Autofac.Extras.Quartz;
using Quartz;
using System;
namespace Test1_netCore
{
class Program
{
static void Main(string[] args)
{
var builder = new ContainerBuilder();
builder.RegisterModule(new QuartzAutofacFactoryModule());
var container = builder.Build();
IScheduler scheduler = container.Resolve<IScheduler>(); //crashes here
//
}
}
}
然而,当我解决Autofac.Core.DependencyResolutionException: 'An error occurred during the activation of a particular registration.
See the inner exception for details. Registration: Activator = IScheduler (DelegateActivator),
Services = [Quartz.IScheduler],
Lifetime = Autofac.Core.Lifetime.RootScopeLifetime,
Sharing = Shared,
Ownership = OwnedByLifetimeScope'
Inner Exception
MissingMethodException: Method not found: "Quartz.IScheduler Quartz.ISchedulerFactory.GetScheduler()".
并从中获取容器
ISchedulerFactory
会发生什么?我想我强烈误解了一些事情。
答案 0 :(得分:1)
我弄明白:Autofac.Extras.Quartz和Quartz程序集不兼容。 Autofac.Extras.Quartz(3.3.0)调用ISchedulerFactory方法getScheduler()就像这样
builder.Register(c => c.Resolve<ISchedulerFactory>().GetScheduler())
但是在Quarts 3.0.0-alpha3中这个方法的签名是
Task<IScheduler> GetScheduler(CancellationToken cancellationToken = default(CancellationToken));
但是,在我的问题中,我可以在第二个代码示例中使用版本和方法,只需手动解析ISchedulerFactory
然后getSchduler()
。
(我真的需要这个版本的包装,因为我项目中的其他依赖项)