Implement a Save method for my object

后端 未结 3 840
时光取名叫无心
时光取名叫无心 2021-01-16 16:11

I\'m trying to improve my application\'s design, So instead of calling the DataAccess layer from the presentation layer. I\'ll try to implement a save method from my object

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-16 17:05

    You should avoid mixing the domain model with the persistence logic. The examples given above would make a tight coupling solution. In order to achieve the .SaveObject() you can make extension methods in the BL that would do the job.

    BL.*

    public static class ObjectPersistanceExtensions{
    
           public static SaveObejct(this IBaseEntity obj){
    
                IObjectDal _dal = AvailableSerices.Obtain>();
                _dal.AddObject(obj);
                _dal.Commit();
           }
    }
    

    So in this way you can still add functionaries to the domain objects without coupling the logic in the domain objects.

提交回复
热议问题