Using objectfactory on the client side dataportal

Using objectfactory on the client side dataportal

Old forum URL:

Saman posted on Monday, June 06, 2011

Hello every body

with special thanks to dear rocky for his amazing framework

as im new to CSLA Frame work i created the training project to learn how to apply the pattern of this frame work.

first at all i created the library as a project tracker library with some different business objects

then i decide to using objectfactory to separate the business and data layer with more clarity

for example i have "Personnel" object that has some property and i used the factory attribute to declare the personnelfactory object.

in the factoryobject class i have implement the fetch method by using some criteria from my data access layer

the problem is here that i get confusing when i want dataportal factory object runs locally

in the other word what configuration i have to set in the config file.

am i should implementing the wcf or other remoting services to use my data access layer?

with the best regard

JonnyBee replied on Monday, June 06, 2011

What type of client are you using?

I'll assume WPF or WindowsForms here:

If you have a ObjectFactory where you want:

You should use the [RunLocal] attribute on the ObjectFactory.Create method (just like DataPortal_Create method).

    public object Create() 
      return ...;

    public object Fetch(string criteria)

       // create instance and fetch data

Your DataPortal (assuming you are using N-Tier configuration by DataPortal) should point to the server and use [RunLocal] on those methods that should run locallly.

You could even create a separate "object factory assembly" and ship with the client that ONLY contains the methods with [RunLocal] attribute.

In Silverlight you should handle this in your code. You must use the DataPortalProxyMode to specify local.


    public static void BeginNewCustomer(
      DataPortal.ProxyModes proxyMode,
      EventHandler<DataPortalResult<CustomerEdit>> callback)
      var dp = new DataPortal<CustomerEdit>(DataPortal.ProxyModes.LocalOnly);
      dp.CreateCompleted += callback;
    public static void BeginGetCustomer(
      DataPortal.ProxyModes proxyMode,
      EventHandler<DataPortalResult<CustomerEdit>> callback)
      var dp = new DataPortal<CustomerEdit>();
      dp.FetchCompleted += callback;

RockfordLhotka replied on Monday, June 06, 2011

This is also covered in detail in the Using CSLA 4: Data Access ebook from

Saman replied on Monday, June 06, 2011

Dear Rocky

thanks a lot

as i am from Iran unfortunately i have no access to any payment way there for i can't buy your great book

can you suggest me what can i do please ?

i can buy a hosting service for youWink


Saman replied on Monday, June 06, 2011

thanks a lot Jonny

i was wrong with object factory attribute define in my business object .

it was too hard for me as dataportal was'nt throw any exception during this wrong !!

the fetch message was not routed from bo to my objectfactory and thus there was nothing happened after calling fetch method

thank you again

Copyright (c) Marimer LLC