This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
What's the best practice for bubbling up errors from my repository class? Does LightSpeed has any standard exception or result class that I could use? |
|
|
Depends on the kind of errors you're talking about. Validation errors are associated with each entity. Other errors are reported using exceptions: typically LightSpeedException for errors in the LightSpeed model or mapping, and the database-specific exception class (e.g. SqlException) for database errors. (But others can occur e.g. ArgumentException or ArgumentNullException.) I'd expect most production errors to be validation errors or database exceptions, as any mapping, configuration or argument exceptions should have been knocked on the head during development. |
|
|
Thanks Ivan, what about a business rule error? Or... Should I do my business rules validation outside of my repository class? |
|
|
If you ask three developers this question, you will get eighteen different answers. My understanding, for what it's worth, is that the repository's job is meant to be basically handling persistence, and that business rules are therefore external to the repository. On the other hand, since some basic data validation is already happening within the repository (via LightSpeed validation when you do a SaveChanges), I guess you could argue that the repository is already doing *some* rule validation and it would be better to put it all in one place. See? Even asking one developer, you get two different answers. In any case, if you do do business rule validation within the repository then this is independent of anything that LightSpeed is doing and you'll have to handle exceptions or error reporting according to how you've built your rules validator. |
|
|
Thanks! Where to perform the business rule validation is indeed a difficult topic. I suppose I was hoping you guys would have more of those convention bits and pieces lying around for us to think about :-) As a sidenote, there are heaps of useful LightSpeed and general design convention stuff sprinkles all over the web and this forum. Only if they could be collated into a easier searchable archive... |
|