Separation of problems - DAO, DTO and BO

So I have DAO, DTO and BO. The result is the following code:

// Instantiate a new user repository.
UserRepository rep = new UserRepository();

// Retrieve user by ID (returns DTO) and convert to business object.
User user = rep.GetById(32).ToBusiness<User>();

// Perform business logic.
user.ResetPassword();
user.OtherBusinessLogic("test");
user.FirstName = "Bob";

// Convert business object back to a DTO to save to the database.
rep.Save(user.ToDataTransfer<Data.DTO.User>());

So, I am trying to separate the problems, but I want to get rid of the "converts" in this code. The "converters" are actually located at the business logic level (the DTO layer does not know anything about the business logic layer) as an extension object. The DTO itself, obviously, only stores data and does not have any business logic. UserRepository calls the DAO, and at the end GetById uses AutoMapper to map from the DAO to the DTO. "Converts" (ToBusiness and ToDataTransfer) performs exactly as they say.

My colleague thought that I might need a repository for the business, but he thought it might be a little awkward. Any thoughts?

+5
3

, Business Service. , Business Service, , , , DAL DTO. DTO , DAL - ( -).

, :

DAL → ( DTO) → ( BO)

, - , . :

// UserService uses UserRepository internally + any additional business logic.
var service = new UserService();
var user = service.GetById(32);

user.ResetPassword();
user.OtherBusinessLogic("test");
user.FirstName = "Bob";

service.Save(user);
+3

ToBusiness<User>() ToDataTransfer<Data.DTO.User>().

. ( - ).

A UserRepository User .

UserRepository User .

, , :

UserRepository rep = new UserRepository();

User user = rep.GetById(32);

// Do Work Here

rep.Save(user);
+8

, , DTO BO, DTO, BO. BO DTO, DAL .

+1

All Articles