Business Layer Objects

Posts   
 
    
ueberbill
User
Posts: 1
Joined: 06-Oct-2008
# Posted on: 06-Oct-2008 20:12:44   

I need advice- our project manager has declared that our view layer (we're using a sort of MVP-type model) will not ever reference the DAL - all access to data will come through the Business Layer, which references our LLBLGen-generated DAL.

The issue here is how to create business objects that do not require the view to reference the DAL project (which to clarify is just the LLBLGen project). This means that I can't have my BL inherit from LLBLGen entities because in order to get the entity fields you have to reference the LLBLGen piece and that has been verboten.

So is there a way to create business layer objects that work with LLBLGen without either (A) inheriting from LLBLGen (or inheriting in some way I'm not aware of that allows us not to have to reference the DAL in the view layer) or (B) without creating entire objects that have to translate from view-based, LLBLGen-free fields to LLBLGEN entity objects. I'm trying to avoid B as it seems like a lot of work for not all that much gain- if I have a person table in the database I'd have an LLBLGen person entity with Name, Address, etc, THEN I'd have a BL object that would have to be handwritten with the same fields plus the smarts to create and save an LLBLGen object when necessary. Am I making sense?

jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 06-Oct-2008 22:27:58   

you will need some form of translation. 1. create DTOs specific to each screen, have your Presenters map the domain (LLBL Entity) to the dto.


class SomeEntityToSomeDto : IMapper<SomeEntity, SomeDto>
{
         public SomeDto MapFrom(SomeEntity item)
         {
                return new SomeDto(properties of item);
         }
}

interface IMapper<Input, Output>
{
       Output MapFrom(Input item);
}

  1. roll your own adapter.

class MyEntity
{
        private LLBLGeneratedEntity entity;

        public MyEntity(LLBLGeneratedEntity entity)
        {
                this.entity = entity;
        }

        //expose the desired properties of entity.
}

  1. check out the DataAccessAdapter 2 class templates.
MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 14-Oct-2008 22:22:29   

Are your client side layers allowed to use LLBLGen entities, or is the restriction that LLBLGen can only be used on the business (server side) layer ?

If the former, then using the Adapter pattern allows all references to the DBSpecific project (essentially the DAL) to be kept on the business layer, with client side only needing to reference the DBGeneric project.

If it is the latter, then yes, you will have to buld some form of translation between the LLBLGen objects and your own client side object model. From experience this is a lot of work, and you end up recreating a whole load of functionality (Entity collections, Save fields, etc etc) that come for free with the LLBLGen entities.

Matt

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 15-Oct-2008 10:25:13   

If you want to use dto's you can generate them though. Some DTO templates are available in threads on this forum, which generate DTO's for you with fill code for entities so it's not that much work anymore wink

Frans Bouma | Lead developer LLBLGen Pro