Custom Data Portal Proxy

Custom Data Portal Proxy

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


Jason Berkan posted on Tuesday, July 29, 2008

I have a couple of CSLA classes that must be run remotely.  My project also includes a number of other CSLA classes that must be run locally.  While I could add the RunLocal attribute to all the local class methods, there are far more of them than remote classes, and some of the local classes exist in a class library I am not in control of, so I would love to create a way to tag the classes that should be run remotely.

I have started down that path by creating a custom data portal proxy class and a custom attribute which I've added to the remote classes.  My data portal proxy class looks for this attribute and calls the regular RemotingProxy or LocalProxy as necessary.

However, I have run into a problem with the IsServerRemote method, as I have no way of determining the object type in order to return true or false.  The DataPortal functions know that information, but it doesn't look like I can pass it along without modifying the CSLA code.

Am I working on the correct solution to my problem?  Is there a way for IsServerRemote to return the correct value?

Jason

RockfordLhotka replied on Tuesday, July 29, 2008

That's a tough problem, and I don't have a good solution offhand.

If you can see a way I could refactor the data portal client code to better help you, I am certainly willing to consider suggestions.

It isn't something I have time to research right now though, as the 2008 book and CSLA Light and 3.5.1 are more than consuming my available time.

Jason Berkan replied on Tuesday, July 29, 2008

Thanks for the response.  I'm afraid I don't know enough about the framework to suggest any refactoring - is it possible to pass the objectType into the constructor for the IDataPortalProxy?

I had thought having some classes run remotely while others run locally would have been something commonly implemented, but I guess I was mistaken.  Does anyone have any other options for implementing partial remoting?  I have the remoting classes in a separate class library.

Currently I have come up with the following two options:

1. Change the remote code to a full fledged web service.

2. Create a custom version of the CSLA framework.

Jason

RockfordLhotka replied on Tuesday, July 29, 2008

Maybe I don't completely understand what you want. In 3.5 and earlier you can't create an instance of the DataPortal object, and the proxy object is cached. So your custom proxy is cached by the data portal.

In other words, the DataPortal methods call your proxy instance over and over again.

Your proxy must know whether (on a per-call basis) it is calling the local or a remote proxy?

So you should be able to alter your IsServerRemote property value accordingly? You should be able to delegate the call to the last proxy you used - to the LocalProxy or WcfProxy (or whatever) and just return the value provided by that underlying proxy.

Jason Berkan replied on Tuesday, July 29, 2008

(I'm using CSLA 2.0 - forgot to mention that.)  In simple terms, I have class A, which must run remotely and class B, which must run locally.  If I put the remoting entries in my web.config, both class A and class B run remotely, causing the DataPortal_Fetch on class B to fail.  The simple solution is to add RunLocal to class B, but I also have class C (which exists in a DLL written by someone else) that must also run locally.  Changing class C is a bit more difficult.

So, I was looking for a way to tag class A as a remote class and have the framework know that it should be run remotely, while all the other classes should run locally.  Various searches through this forum lead me to the custom proxy, though I missed the fact that it is cached.

I thought of returning the last proxy used through IsServerRemote, but that doesn't work because IsServerRemote is queried when creating the DataPortalContext, which occurs before any data access, meaning that it will return the wrong value whenever you call a local object and then a remote object (or vice versa).

Jason

Copyright (c) Marimer LLC