Open pwil301 opened 9 years ago
It is not so obvious that CSLA is a good choice for your use case. But here is some ideas.
You will typically not use the "state" machine in CSLA objects (like Insert/Update).
What is the shape of your objects? Do they have the same properties and children no matter which datasource or are they different?
In terms of rules, you might look into RuleSets: ie: The possibility of having different sets of Rules to apply to the object. Just be aware that each RuleSet must be a complete set and all rules must be registered during the first call to AddBusinessRules().
For Save you could use Save(forceUpdate = true) and the add all the logic to check for existing => insert or update - all within the Update method.
So you could load the object from one datasource (ie: DataPortal_Fetch) and Save it to another datasource (in DataPortal_Update).
Thanks jonnybee.
The objects are identical regardless of data source/sink.
Good idea on the Fetch/Update split. I'll give it a whirl!
G'day. Need some best practice guidance for CSLA objects that read and write from/to multiple stores. We're working a system that synchronizes a large volume of records between two different endpoints. The data is streamed from the source into a local cache, validated and altered as required by rules, and then streamed back out to a sink. For each record in the source, the destination is first queried for a match. If found, the match is updated in the destination. If not, it is created. Deletes are handled separately.
This results in having an object that fetches from the source, but also must fetch from the destination before ultimately writing to the destination. I'm looking for design best practices regarding how to use two different connection configurations within the same object.
For example, a given object needs to have configuration data to tell it to read from one repository or another. What's the best way to inject that logic? Should I have the Person object in another assembly and a controller object that passes it the appropriate connection information it will need? I feel the business rules are going to get hazy as some rules only apply for a given connection. Should I create two different objects and handle then generate instances of the destination object in the processing code of the source object? I just need pointed in the right direction.