C# Lazy property gets initialized on constructor

282 views Asked by At

I have lazy command in my view model:

private ICommand _testCommand;
public ICommand TestCommand => _testCommand ?? (_testCommand = new Command(Test));

and for some reason it gets called and initialized on constructor. This is constructor:

public TestViewModel(IMediator mediator, IDispatcherService dispatcherService, IGroupService groupService)
{
    _mediator = mediator;
    _dispatcherService = dispatcherService;
    _groupService = groupService;
}

Command is not bound in UI and it is not called from anywhere except unit tests in which this problem happens when view model is constructed that is before property gets called.

I tried putting break point on property and when it entered break point in Call Stack it showed that last one to call this property is [External Code] and before that is constructor.

Does anyone know what is actually happening here?

0

There are 0 answers