为什么在
处会出现stackoverflow异常 var serviceHost = container.Resolve<IServiceHost>();
class Program
{
static void Main(string[] args)
{
RunProgram().GetAwaiter().GetResult();
}
private static async Task RunProgram()
{
var container = new UnityContainer();
container.RegisterSingleton<ISchedulerFactory, Quartz.Impl.StdSchedulerFactory>();
container.RegisterSingleton<IServiceHost,ServiceHost>();
var serviceHost = container.Resolve<IServiceHost>();
await serviceHost.Start();
Console.Read();
}
}
public class Download : IJob
{
public Task Execute(IJobExecutionContext context)
{
return Task.Run(() => Console.WriteLine("Downloading..."));
}
}
public class ServiceHost : IServiceHost
{
public ISchedulerFactory SchedulerFactory { get; set; }
public ServiceHost(ISchedulerFactory schedulerFactory)
{
SchedulerFactory = schedulerFactory;
}
public async Task Start()
{
....
}
}
但是,如果我创建StdSchedulerFactory的子类并注册/解决该问题,那么它将起作用
public class CustomSchedulerFactory : StdSchedulerFactory
{
}
class Program
{
static void Main(string[] args)
{
RunProgram().GetAwaiter().GetResult();
}
private static async Task RunProgram()
{
var container = new UnityContainer();
container.RegisterSingleton<ISchedulerFactory, CustomSchedulerFactory>();
container.RegisterSingleton<IServiceHost,ServiceHost>();
var serviceHost = container.Resolve<IServiceHost>();
await serviceHost.Start();
Console.Read();
}
}