WP7 and Factory Methods

WP7 and Factory Methods

Old forum URL: forums.lhotka.net/forums/t/10643.aspx

Atopper posted on Friday, August 26, 2011

I’m experimenting with WP7 and using a ReadOnlyListBase with the factory methods. Does this work on the WP7 Platform? I keep getting an ArgumentException when the factory method is called. This may be a silly question, I apologize, I’m new to 4.1 and have not been using CSLA since the .Net 2.0 versions.

I have read the books and look through all the examples I could find. If someone has a good example or could direct me to a posting, it would be much appreciated. I'm looking forward to the WP7 book, I hope a draft version is on it's way this fall.



JonnyBee replied on Saturday, August 27, 2011

In WP7 running in local mode the factory methods get a Callback function as last parameter. I believe that is missing in your code and hence you get an ArgumentException.

If you look at the WindowsPhone\cs\SimpleApp in Csla samples download you can add a CustomerFactory like this:

Add object factory attribute to CustomerEdit

  public class CustomerEdit : BusinessBase<CustomerEdit>

And add this class
  public class CustomerEditFactory : Csla.Server.ObjectFactory
    public void Create(Csla.DataPortalClient.FactoryProxy<Library.CustomerEdit>.CompletedHandler callback)
        var obj = (CustomerEdit)Activator.CreateInstance(typeof(CustomerEdit));
        using (BypassPropertyChecks(obj))
          obj.Status = "Created " + ApplicationContext.ExecutionLocation.ToString();
        callback.Invoke(obj, null);
      catch (Exception ex)
        callback.Invoke(null, ex);
    public void Fetch(SingleCriteria<CustomerEditint> criteria, 
Csla.DataPortalClient.FactoryProxy<Library.CustomerEdit>.CompletedHandler callback)     {       try       {         var obj = (CustomerEdit)Activator.CreateInstance(typeof(CustomerEdit));         using (BypassPropertyChecks(obj))         {           obj.Id = criteria.Value;           obj.Name = "Test " + criteria.Value;           obj.Status = "Retrieved " + ApplicationContext.ExecutionLocation.ToString();         }         MarkOld(obj);         callback.Invoke(obj, null);       }       catch (Exception ex)       {         callback.Invoke(null, ex);       }     }     public void Update(CustomerEdit obj,
Csla.DataPortalClient.FactoryProxy<Library.CustomerEdit>.CompletedHandler callback)     {       try       {         // call something to save the object         MarkOld(obj);         callback.Invoke(obj, null);       }       catch (Exception ex)       {         callback.Invoke(null, ex);       }     }   }

Atopper replied on Sunday, August 28, 2011

That clears things up. The world has changed in the last 5 years! Thank you very much.


Copyright (c) Marimer LLC