BusinessBase or CommandBase...

BusinessBase or CommandBase...

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


JeffreyYoung posted on Thursday, March 26, 2015

I have a situation have not encountered in 7 years of CSLA development. I'm not sure why it's not come up until now but I have a need for a Calculation Object that Executes remotely and returns the data back.

Basically I have what amounts to a BB that I need to call Execute on. It is a large calculator for loans that has dozens of fields. Once filled in, we need to call Execute or Process or Whatever and have it go out to a Web Service and compute a result set and fill in the results on the BB. the CRUD operation of BB.Save() does not seem to fit.

But the Execute of Command does not seem to be rich enough... Unless I'm doing it wrong.

What I'd like is this...

MyBBOrCommandObj obj = MyBBOrCommandObj.Create();

obj.Properties = ...

obj = obj.Execute();

What would be the correct way of doing this? Can I do what I'm proposing now?

P.S. This is all in 4.5.601.

 

ajj3085 replied on Thursday, March 26, 2015

If your BB also has rules that must be enforced before doing the calc BB is just fine for this.  You could create an Execute method that just calls Save if the verb is bothering you, but there's nothing wrong with using BB for this.

JonnyBee replied on Friday, March 27, 2015

Hi,

If you want to separate the logic you could also create a CommandObject that just holds the BusinessObject (maybe a Clone) and call Execute on the CommandObject. Upon return you must then map the results to the original BB object.

This CO would easily also contain text messages back to the user.

Or just call DataPortal.Execute on the BB object and add code in DataPortal_Execute.

JeffreyYoung replied on Friday, March 27, 2015

JonnyBee

Or just call DataPortal.Execute on the BB object and add code in DataPortal_Execute.

Is this possible? I didn't think a BB had .Execute(). I thought all it had was .Save(). 

We were trying to avoid the interim objects and mapping the data twice.

 

 

ajj3085 replied on Friday, March 27, 2015

Jeffrey Young
Is this possible? I didn't think a BB had .Execute(). I thought all it had was .Save(). 

We were trying to avoid the interim objects and mapping the data twice.

BB doesn't have Execute, but you could add an Execute method yourself like this:

public void Execute() { DataPortal.Execute(this); }

And then implement DataPortal_Execute in your BB. I believe Johnny is suggesting this will work, since Csla at the end of the day doesn't care about what the type is it will just try to call the expected DataPortal_XYZ method via reflection.

The nice thing about Johnnys approach is that you don't need to have both DataPortal_Insert and _Update (or always going back to Old or New status).

Copyright (c) Marimer LLC