Datalayer for local and webservice access RRS feed

  • Question

  • I have a business layer wich uses custom business objects. This BL uses the DAL to fill thes objects using a datareader returned by the DAL. Now the DAL also needs be capable of accesing data using webservices (depends on working online or offline). When retrieving data using webservices I can't use the datareader as a return type (And I don't want to Smile) But since the BL has no knowledge of the application working online or offline I use polymorphism and a factory to create DAL classes. The thing is I can't have the offline dataclass returning a datareader since the online class uses webservices that don't support datareaders. An other option is to let the DAL return Businessobjects so I can use custom serializition on the objects and pass these to the webservice and vice versa,  but then the DAL needs to know about the BL (wich would cause a circular reference Smile) How can i possibly solve this problem? Thank!

    Thursday, October 4, 2007 10:20 AM

All replies

  • Hi Mark

    You said the BL layer uses the DAL to fill these objects using a datareader..  By returning the datareader from the dal your letting details leak through your DAL into your BL layer. The DAL should be a layer of abstraction over the database, I would give a business object to the DAL to persist and expect a properly hydrated business object out when I called a load method.

    Put the DAL in the same project as the business classes and seperate them logically using namespaces instead of projects. This will allow you to pass and receive business objects to/from your DAL and then get them from either on or offline.



    Thursday, October 4, 2007 7:19 PM
  • Hi, thanks for your reply. Hmm in the same project? is that a wise thing to do? it would solve the circular reference issue.
    What about the return values from the webservices? custom serialized business objects? or arrays? or somethign else? Smile
    any recommendations?

    Friday, October 5, 2007 7:53 AM

  • You generally don't deploy your DAL anywhere else independantly of the BL so having a seperate assembly doesn't give you much.

    I would pass xml serializable data transfer objects to and return from the webservices and map these to and from the business objects in the service layer between the domain model and the websevice that you serve up form your factory.

    This gives you the same abstraction layer as you have for your dal and allows you to unit test the mappings to and from rather than trying to unit test the web service calls.


    Saturday, October 6, 2007 8:09 PM
  • Hi thanks again, these data transafer objects would be cutom objects that just wrap the data for transport? I am thinking of using the business objects for this task as they are very lightweight.
    Thursday, October 11, 2007 1:26 PM

    Definitley sounds like you need to be introduced to the magic of code generation, so why waste time doing it all yourself when there are tools out there that can get the code out in seconds, and they have a very active community behind them.

    A tool I've been using for years is NETTiers. Take a look at it, and at the pattern it implements to create the data layer, it should help you clear things up.

    Monday, October 15, 2007 9:27 PM