Skip to content

The name localWorkerA does not exist in the current context #152

Description

@scott-xu

Describe the bug
The bracket is not correct.

To Reproduce

Bind().To(ctx => new Func<WorkerType, IWorker>(workerType =>
            {
                switch (workerType)
                {
                    case WorkerType.A:
                            ctx.Inject(out WorkerA workerA);
                            return workerA;
                    case WorkerType.B:
                            ctx.Inject(out WorkerB workerB);
                            return workerB;
                    default:
                            return null;
                }
            }))

Generated:

switch (workerType)
{
	case WorkerType.A:
	{
		global::My.WorkerA localWorkerA = new global::My.WorkerA());
	}
		return localWorkerA;
	case WorkerType.B:
	{
		global::My.WorkerB localWorkerB = new global::My.WorkerB());
	}
		return localWorkerB;
	default:
		return null;
}

Expected behavior
Should be able to compile

Additional context
A workaround is to add bracket in setup code:

Bind().To(ctx => new Func<WorkerType, IWorker>(workerType =>
            {
                switch (workerType)
                {
                    case WorkerType.A:
                            {
                                ctx.Inject(out WorkerA workerA);
                                return workerA;
                            }
                    case WorkerType.B:
                            {
                                ctx.Inject(out WorkerB workerB);
                                return workerB;
                            }
                    default:
                            return null;
                }
            }))

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions