I'd like to see the CSLA creator's views of this hybrid of Factory and Encapsulated design to implement swappable DAL.
In this case, I have a BusinessObjects dll. In it, I have the Library and DAL namespace. Library contains all the sub name spaces for the actual CSLA Business Objects. They will implement the "Encapsulated Invocation" Model as detailed by the "Using CSLA 4 Data Access" book, BUT in this case the invocation is "Coding to Interface" instead of "Coding to Implementation"
Because there is a clear dependency between the DAL having to accept Business Objects as parameters and usually returning a DTO, the interfaces defining the contract for the DAL must be in the same assembly as the Library classes. If not, there would be a circular dependency that could only be broken by using exclusively DTO's for passing the data between assemblies. In this case the Library would be dependent on the DTO assembly and the DAL interfaces assembly.
The DAL interface will provide a DALLoader which reads the assembly config file to determine what assembly to create an instance in for a static field in the DAL namespace. This field / property can be reset and if the DAL instance is accessed again, the Loader will once again read the config file and create a new instance. I am also considering allowing the DALLoader to be specified by the config file or be set by application.
I have something working at the moment but it is directly against a SQL database and I have not made a DAL.Mock assembly yet...
I'm curious if those who are experts here have points or criticism on this idea. I'm not sure it can be incorporated in CSLA because it is executed within the DataPortal_xyz methods either in the Business Objects or the Object Factories. It can be used on either side Client/Server so it just seems too specific to the DAL design, but I'd like to share the idea once it gets tested and comments given to improve on it...
Thanks very much !
You may want to look at the trunk\Samples\MEFSamples\Repository sample i CslaContrib for an alternate version of how you can embed DI techniques inside the business base classes. Just select download to get all the source code on this page:
The sample use MEF for DI but could easily be modified to use any DI container. This is based on working code in some of our applications. There is also another sample that shows ObjectFactory pattern with MEF.
Copyright (c) Marimer LLC