ssteenkiste / nettiers

Automatically exported from code.google.com/p/nettiers
1 stars 0 forks source link

Adding validation rules at service layer #37

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I have modified NetTiers scripts in order to minimise my work. It would be
handy if these could be incorporated into standard NetTiers, so I thought
I'd put it up here to see if anyone thinks it is worthwhile.

Firstly, the issue I wanted to deal with:
Basically, my database has lots of validation rules. Most of these are
written at the service layer, as they involve checking details in other
records (so they cant go into the entity layer). This creates one minor
problem - these rules are not loaded by default when I retrieve records
from the database.  This means I am forever writting get overrides to
ensure data is retrieved with the rules in tact.

My solution:
I modified the nettiers scripts so they generate the following code.
In the ServiceBaseCore.generated.cs file, two new methods were created -
both called AddCustomRules (one for single entities, one for a list of
entities)

In all of the Service files (for each entity), all of the Get, Find, etc
methods have been modified so that they call AddCustomRules to everything
before returning it:
list = AddCustomRules(list);

By itself, this code does nothing (The generated AddCustomRules dont do
much on their own). But if I create an override for the AddCustomRules in a
service file (adding validation rules), these validation rules are
automatically added to all retreivals of the records/entities.

Now I look at this, and I'm thinking a few things:
1) The problem I'm trying to overcome cant be that unique - most databases
have complicated rules at the service layer.
2) My solution was not particularly difficult - before this I had zero
knowledge of CodeSmith script writing, and I wrote this in an afternoon.

This leads me to suspect that there could be another, more elegant way of
acheiving what I'm after.

So, my questions are:
1) Would my changes be appreciated within NetTiers?
2) If there is a more elegant solution for what I'm trying to do already in
NetTiers, what is it?

What version of .netTiers and CodeSmith are you using? - 2.2 711

Thanks.

Original issue reported on code.google.com by shanon.m...@gmail.com on 1 Jun 2008 at 5:50

GoogleCodeExporter commented 9 years ago
Hello Shannon,
What I did for my convenience is to add on the constructor of the entity a new 
method
where you can add the validation rules for each entity. This way, by modifying 
the
template of the entities.generated.cs, you can create the validation rules for 
string
required, regex, minlenght, maxlenght, etc according to the column involved. 
You can
iterate through the property AllowDBNull for each column to verify if it is a
required field or if you have to assign a minimum or maximum lenght to the 
specific
field (same process as in the entity.aspx template for the maxlength on 
textboxes).
Then, once you create an instance of an entity, all of the validation rules 
will be
added to the new entity and just by checking Entity.Validate() you will have 
every
broken rule (if broken) at a blink of an eye.
Hope this few lines helped you develop a suitable solution for your needs, I 
did it
this way and now it is working as expected. I am now working on extending the
properties for the columns to add custom validation from the very begining (like
regex for specific fields), when you select the properties for nettiers.cst.  :)

Regards,
DiegoGravi

Original comment by diegogr...@gmail.com on 21 Aug 2008 at 12:20

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Shanon - I would be keen to see what yoe have done to the templates. I am 
needign to 
do something similar, and it would be very handy to see how you did it. Would 
it be 
possible to get a copy of your changes?

Cheers

Paul Smith
psmith@pcug.org.au

Original comment by s...@pcug.org.au on 4 Nov 2008 at 11:43

GoogleCodeExporter commented 9 years ago
Paul,

I'm happy to share my changes, but I'm unsure of the best way to do this. My 
changes 
are based on what I think is v2.2.0.711 ( a tad old now).

Original comment by shanon.m...@gmail.com on 5 Nov 2008 at 1:00

GoogleCodeExporter commented 9 years ago
Shanon,

Create a patch.
Upgrade to rev 715 and then reapply your patch as the folder was moved. 
From there all you have to do is hit the update button and update to the latest 
revision.

Original comment by bniemyjski on 8 Dec 2008 at 6:09

GoogleCodeExporter commented 9 years ago
Shanon,

If you submit your patch, I will upgrade it to the latest version.

Original comment by bniemyjski on 3 Feb 2009 at 2:40

GoogleCodeExporter commented 9 years ago
OK then. What is the best tool to use to make a patch? I usually use araxis for 
my 
comparing/merging needs, but it doesnt seem to have any kind of make patch 
option...

Original comment by shanon.m...@gmail.com on 3 Feb 2009 at 3:23

GoogleCodeExporter commented 9 years ago
I would pull down the same revision via svn and then drag your files over. From 
here
right click in the root directory and make a patch via svn.

-Blake

Original comment by bniemyjski on 3 Feb 2009 at 3:56

GoogleCodeExporter commented 9 years ago

Original comment by bniemyjski on 25 May 2009 at 3:18

GoogleCodeExporter commented 9 years ago

Original comment by bniemyjski on 25 May 2009 at 3:30

GoogleCodeExporter commented 9 years ago
I too would like to see this enhancement.  Validation rules on a subset or 
superset of 
entities is a very important feature.  I found myself needing this and realized 
the 
solution I came up with was no where near optimal.  IS there some guidance on 
this 
though, I can see the need for entities to validate themselves for data rules, 
but for 
business rules aggregates and set validation seems a no brainer for the service 
tier in 
this model.  Am I wrong?

Original comment by EAI.Fr...@gmail.com on 26 Jan 2010 at 6:44

GoogleCodeExporter commented 9 years ago
I'M working just right now in a project that requires execute business rules in 
the entities. The problem here is that modules in my project correspond to one 
specific entity (i.e: PurchaseEntity -> Purchases Module). This modules are 
generated at run time based in one specific interface in the assembly. Now, I 
need to load the custom rules or business rules to be validated when the entity 
require it (at Save time for say something). This business rules I'm thinking 
placed into separate assembly with Processor class or maybe one XML file that 
contains the assembly and the type to be instantiated at run time... this is my 
approach.

Regards
César F. Qüeb Montejo
MJJ  Brilliant, Inc

Original comment by cesar.q...@gmail.com on 2 Feb 2012 at 5:16