2
public class ConsoleRegistry : Registry
{
    public ConsoleRegistry()
    {
        Scan(scan =>
        {
            scan.TheCallingAssembly();
            scan.WithDefaultConventions();
        });

        For<IJobFactory>().Use<StructureMapJobFactory>();

        For<ISchedulerFactory>().Use(ctx => new StdSchedulerFactory());
        /*For<IScheduler>().Use(async delegate (IContext ctx)
        {
            var scheduler = await ctx.GetInstance<ISchedulerFactory>().GetScheduler();
            scheduler.JobFactory = ctx.GetInstance<IJobFactory>();
            return scheduler;
        });*/

        ForSingletonOf<IScheduler>().Use(ctx =>
        {
            IScheduler scheduler = ctx.GetInstance<ISchedulerFactory>().GetScheduler().Result;
            scheduler.JobFactory = ctx.GetInstance<IJobFactory>();
            return scheduler;
        });
    }

最后有什么问题 ForSingletonOf<IScheduler>()...

我收到此错误

错误 CS0832 表达式树可能不包含赋值运算符

4

1 回答 1

1

这听起来像是库实现中的某个错误。由于该项目是“日落”的,你不太可能得到修复,所以尝试通过引入一个辅助方法来解决它:

private static IScheduler MakeScheduler(IContext ctx) {
    ... // the code from your lambda goes here
}
...
ForSingletonOf<IScheduler>().Use(ctx => MakeScheduler(ctx));
于 2018-07-28T21:46:27.233 回答