|
|
Examples of Data Access Layer working with CSLA framework?
-
02-28-2007, 3:49 AM |
-
RichardETVS
-
-
-
Joined on 02-20-2007
-
-
Posts 61
-
Points 1,115
-
|
Examples of Data Access Layer working with CSLA framework?
In the CSLA; the business objects have the responsibility to access the database. I would like to have a separate access layer, so I could change of database without modifying the BO. I could implement a simple data layer, an object with method who’ll get object to save, update, etc. as parameters, like MyDataAccesObjectLayer.Save(aCustomer).
But how that could work? In order to save aCustomer, MyDataAccesObjectLayer should know the private property of aCustomer? OR THE DataLayer object could in a propriety of the object to save; so it would have access to its members?
Do you know any example or framework that does that?
Cordially
Richard
Richard
|
|
-
02-28-2007, 4:22 AM |
-
Jimbo
-
-
-
Joined on 11-28-2006
-
Melbourne, Australia
-
Posts 107
-
Points 1,675
-
|
Re: Examples of Data Access Layer working with CSLA framework?
Yes you can do this, but it discards the use of "Mobile Objects"
and the goodies of the proxies that csla data portal provides.
We do this in a number of applications that need to support legacy COM+
etc server architectures ( although gradually migrating to remoting and
System Transactions instead) .
You can bypass csla DataPortal simply by overridiing Save() in
BusinessBase etc and pointing your updates to your own dataportal
service (tcp preferred).
Rocky does not go into the details of a tcp remoting service - but I
can tell you that it really rocks compared with using Soap and IIS etc.
jimbo
|
|
-
02-28-2007, 4:47 AM |
-
Jimbo
-
-
-
Joined on 11-28-2006
-
Melbourne, Australia
-
Posts 107
-
Points 1,675
-
|
Re: Examples of Data Access Layer working with CSLA framework?
I should add that in these scenarios we are using simple old fashioned
DTO's and parameterized calls that do not have any reference to the
BO's on the server.
|
|
-
02-28-2007, 4:48 AM |
-
RichardETVS
-
-
-
Joined on 02-20-2007
-
-
Posts 61
-
Points 1,115
-
|
Re: Examples of Data Access Layer working with CSLA framework?
Thanks for the answer. My idea was not to bypass the data portal. The BO would have their dataPortal methods, but instead of implementing them, they would use an access data layer.
By example, in a BO, DataPotal_Fetch(), instead of doing some SQL, would call the data access layer. Like this, we would keep the benefits of the CSLA framework.
Richard
|
|
-
02-28-2007, 6:24 AM |
-
Jimbo
-
-
-
Joined on 11-28-2006
-
Melbourne, Australia
-
Posts 107
-
Points 1,675
-
|
Re: Examples of Data Access Layer working with CSLA framework?
csla does not dictate the data access or provider that is to be used (
although it is ms sql centric by default) . You can use whatever data
access provider (MySql, Oracle, XML, CSV, Excell, Access etc ) you wish
to code for in each of your DataPortal_Fetch, Insert, Update etc
methods. Clearly you would also have to replace datareaders etc as
appropriate for loading datarows or otherwise provide suitable adaptors
for the type of rowsets that you get..
If you wanted to be able to use alternate or switchable sources than
perhaps it would require switchable cases in each method dependent on
the provider. This suggestion of course is not ideal as it would blow
out the code base in the objects and any future provider changes would
similarly require rebuilding.
How to have a universal persistence layer without provider customisation is beyond me at this point
|
|
-
02-28-2007, 3:42 PM |
-
02-28-2007, 4:33 PM |
-
malloc1024
-
-
-
Joined on 05-15-2006
-
-
Posts 147
-
Points 2,320
-
|
Re: Examples of Data Access Layer working with CSLA framework?
Another alternative you might want to consider involves the Separated
Interface pattern(Fowler). You could create an
explicit interface for each BO and place them in a separate assembly. Each BO would implement its own explicit interface
and pass that to the DAL. The key is to
use explicit interfaces and not implicit interfaces. Explicit interfaces allow you to access private
properties when you cast to the interface.
This allows you to load and save objects from the DAL. Any code that does not have a reference to
the explicit interfaces assembly will not have access to
the private properties. This allows you
to hide private properties from the presentation layer while exposing them to
the DAL.
|
|
-
03-01-2007, 4:23 AM |
-
RichardETVS
-
-
-
Joined on 02-20-2007
-
-
Posts 61
-
Points 1,115
-
|
Re: Examples of Data Access Layer working with CSLA framework?
Thanks for the links, Rocky.
First time I heard of Separated Interface pattern ;) . And I do not know the difference between explicit and implicit interfaces. I’ll invoke my all knowing god, Google!
Edit: well, I found things on explicit interfaces, like:
The class member IControl.Paint is only available through the IControl interface, and ISurface.Paint is only available through ISurface. Both method implementations are separate, and neither is available directly on the class. For example:
SampleClass obj = new SampleClass(); //obj.Paint(); // Compiler error.
IControl c = (IControl)obj; c.Paint(); // Calls IControl.Paint on SampleClass.
ISurface s = (ISurface)obj; s.Paint(); // Calls ISurface.Paint on SampleClass.
So the idea is to implement a public interface to expose private properties, and as this public interface is not available in the UI, the private properties stay hidden for the UI developer? That seems really interesting.
Richard
|
|
-
03-02-2007, 11:28 AM |
-
ajj3085
-
-
-
Joined on 05-05-2006
-
Vermont
-
Posts 2,523
-
Points 38,460
-
|
Re: Examples of Data Access Layer working with CSLA framework?
RichardETVS:So the idea is to implement a public interface to expose private properties, and as this public interface is not available in the UI, the private properties stay hidden for the UI developer? That seems really interesting.
Not quite; you want an internal interface, not a public interface. If you make the interface public, then the explicit implementation of the interface will be visable as well. If the interface is internal and you implement it explicity, then only classes internal to the assembly can see the private bits, but your UI code will still not be able to see it.
|
|
-
03-06-2007, 4:25 AM |
-
RichardETVS
-
-
-
Joined on 02-20-2007
-
-
Posts 61
-
Points 1,115
-
|
Re: Examples of Data Access Layer working with CSLA framework?
ajj3085:Not quite; you want an internal interface, not a public interface.
Well, I do not get it, then. When I read “You could create an explicit interface for each BO and place them in a separate assembly”, it seems to me that I can’t use internal scope.
Richard
|
|
-
03-06-2007, 7:21 AM |
-
ajj3085
-
-
-
Joined on 05-05-2006
-
Vermont
-
Posts 2,523
-
Points 38,460
-
|
Re: Examples of Data Access Layer working with CSLA framework?
That's correct, I'm not sure where malloc was going with his idea of seperate assemblies.. but if you put the interfaces in a seperate assembly, that assembly needs to be seen by any other assembly that uses your BO. That ends up defeating what you want to do, which is keeping the implementation of the interface on your BO private.
|
|
-
03-06-2007, 11:58 AM |
-
RichardETVS
-
-
-
Joined on 02-20-2007
-
-
Posts 61
-
Points 1,115
-
|
Re: Examples of Data Access Layer working with CSLA framework?
But f the interface assembly is referenced only the BO assembly and the DAL assembly, and the implementation of the interface are explicit, it seems to me that the encapsulation is preserved, because only the DAL will have access to the private fields of the BO.
Richard
|
|
-
03-06-2007, 12:50 PM |
-
ajj3085
-
-
-
Joined on 05-05-2006
-
Vermont
-
Posts 2,523
-
Points 38,460
-
|
Re: Examples of Data Access Layer working with CSLA framework?
I'm sure that anything which references your BO assembly will also have to reference the interface assembly, and thus could use that interface to modify the property values bypassing the normal Csla properties (i.e., the rules wouldn't run, etc.).
The only way to truely prevent this is to keep the interfaces internal to the BO assembly. You would then need some kind of mapper which takes the DAL object and sets properties via the interface.
Attached is a sample application which illustrates the problem.
|
|
-
03-06-2007, 1:05 PM |
-
malloc1024
-
-
-
Joined on 05-15-2006
-
-
Posts 147
-
Points 2,320
-
|
Re: Examples of Data Access Layer working with CSLA framework?
It works in VB.NET but it appears that is doesn’t work quite
as well in C#. I just tested it in C#
and it appears the presentation layer needs to have a reference to the separated
interfaces assembly. This is not the case
for VB.NET. The presentation layer doesn’t
need to have a reference to the separated interfaces assembly in VB.NET. I am not sure why it works in VB.NET and not
in C#. Anyway, even if the presentation
layer had a reference to the separated interfaces, it would not be able to
access the hidden properties of an object unless it was casted to its separated
interface. However, this does not work
as well.
|
|
-
03-06-2007, 1:12 PM |
-
malloc1024
-
-
-
Joined on 05-15-2006
-
-
Posts 147
-
Points 2,320
-
|
Re: Examples of Data Access Layer working with CSLA framework?
You could keep the interface internal to the BO assembly and
use the InternalsVisibleTo attribute to expose it to the data layer.
|
|
Page 1 of 2 (22 items)
1
Please contact Magenic for your .NET consulting and CSLA .NET mentoring needs. |
Please consider making a donation to help support the ongoing development of CSLA .NET. Why donate?
|
|
|