How to execute a command from a constructor

Oct 21, 2010 at 2:54 PM

I'm sure this is simple to do, but I cannot work it out.  Complete Caliburn newbie..

I want to execute a command from within a constructor.  For example call the following:

        public IEnumerable<IResult> ExecuteSearch()
        {
            var search = new FindData
            {
                SearchAll = false
            }.AsResult();

            yield return Show.Busy();
            yield return search;

            var resultCount = search.Response.Count();

            if (resultCount == 0)
                SearchResults = _noResults;
            else 
                SearchResults = _results.With(search.Response);

            yield return Show.NotBusy();
        }

Oct 21, 2010 at 4:00 PM

Why not just execute this before calling the constructor and then passing in the SearchResults to the constructor.

Oct 21, 2010 at 4:06 PM

What I'm trying to do is:

- Have my ShellViewModel conductor that receives AuthenticateViewModel in the constructor.

- AuthenticateViewModel is activated on initialisation.  AuthenticateViewModel is constructed with success & failure screens.

- On activation of AuthenticateViewModel, I want it to call my coroutine to Authenticate user automatically.

- If no error is thrown, then transition is made to the success screen, otherwise the failure screen.

Oct 21, 2010 at 4:43 PM

Try Coroutine.Execute(ExecuteSearch().GetEnumerator());

 

 

Oct 21, 2010 at 4:48 PM

Perfect!  Thank you.