CommandBase should be the same as BusinessBase... Only different :) #3248
-
I've been struggling with two issues. One is writing code that is self-documenting, the second is business objects with different behavior for Fetches, Inserts, etc. I want to create a project that looks like: Message (folder) That layout describes what can be done without even having to look at code. I like it from a self-documenting perspective. The usage would be something like:
But I can't. I have at least 1 business rule, content is required. So... I can't use a command object. Instead I have to do one of several things.
So... I propose Csla either changes the CommandBase so it has the functionality of the BusinessBase OR Drop CommandBase and have BusinessBase support [Execute]. Just a thought. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
I have asked a similar question in the past about using BusinessBase as 'Command' object (When we have business rules involved) and @rockfordlhotka has confirmed he has done it in his projects as well. |
Beta Was this translation helpful? Give feedback.
-
Keep in mind that the primary purpose of The data portal does treat What I do in this sort of situation is to use a [Serializable]
public class UserInput : BusinessBase<UserInput>
{
// implement properties and rules
// don't implement any data portal operation methods
}
[Serializable]
public class MyCommand : CommandBase<MyCommand>
{
public static readonly PropertyInfo<UserInput> InputProperty = RegisterProperty<string>(c => c.Input);
public UserInput Input
{
get { return GetProperty(InputProperty); }
set { SetProperty(InputProperty, value); }
}
[Create]
[RunLocal]
private void Create()
{ }
[Execute]
private void Execute()
{
// execute the command based on info in Input
}
} |
Beta Was this translation helpful? Give feedback.
Keep in mind that the primary purpose of
BusinessBase
is to help you create a class that includes the full rules engine.The data portal does treat
CommandBase
types differently from other types in terms of theExecuteAsync
method. Looking back, perhaps that wasn't the best design decision, but there's a (I think) reasonable solution.What I do in this sort of situation is to use a
BusinessBase
subclass to collect and validate user input, then have aCommandBase
subclass that contains the editable object to execute the command. Something like this: