开发者

What is most common solution to resolve data mapper for a domain object

开发者 https://www.devze.com 2023-03-15 05:27 出处:网络
G\'day, I\'ve tried to do a search on a subject but couldn\'t find anything, at least yet. I have a 3 domain objects that implement interface IEntity. I\'d like to build a generic data mapper layer t

G'day, I've tried to do a search on a subject but couldn't find anything, at least yet.

I have a 3 domain objects that implement interface IEntity. I'd like to build a generic data mapper layer to do Create, Update, Delete operations on IEntity. Probl开发者_运维百科em is that each concrete entity is saved in its own table so it seems I need to have 3 concrete mappers to deal with that. However client doesn't know anything about concrete objects - it only knows about IEntity abstration. And obviously I don't want concrete objects to know anything about mappers.

So it seems that there should be a way for client to get mapper of the right type. Would service locator pattern be used in cases like that?

Something like:

public IEntityDataMapper GetMapper(IEntity entity)

Some other ways to accomplish this goal? Is it by any chance the sign of my domain model being somewhat faulty in the first place?

Example of what I'm trying to accomplish: (client code)

IEntityMapper mapper; 
IEntity abstractEntity; 

mapper.Update(abstractEntity);

Logic behind Update for every entity may be very different.


I'm not sure I understand exactly what you are looking for but it sounds like a case for Automapper.

http://automapper.codeplex.com/

p.s. I assume you are using .Net... but I guess you never specified...


I'm not really clear on what you want to do, either -> but are you familiar with the concept of ORMs, for example NHibernate, are you trying to map those entites to a relational database? You can have abstractions like those with simple NHibernate session:

IEntity someEntity = new Customer("John", "Doe");
session.Save(someEntity);

provided that you map the entity to the database...

0

精彩评论

暂无评论...
验证码 换一张
取 消