Search code examples
c#asp.net-mvcdomain-driven-designcode-first

can we call interface method in my domain in domain driven design c# code first mvc


I have this structure in my sub context in my DDD (Sub domain).

enter image description here

Now I want to use my interfaces in my domain. For example, here is my news Entity:

 public  class News
 {
     public Guid Id { set; get; }
     public string Subject { set; get; }
     public string Content { set; get; }
     public DateTime SubmitDatetime { set; get; }
     public DateTime ModifiedDateTime { set; get; }
     public string PublisherName { set; get; }
     public string PictureAddress { set; get; }
     public string TypeOfNews { set; get; }//etelaeie ya khabar
     public HttpPostedFile ImageFile { get; set; } 
 }

Suppose I want to add, for example, a news item to my database. My main question is how can I add a news item to my database? Should I call my repository inside the news class and create a method inside the news class to do that?


Solution

  • Typically, the Application Service (in CMSManagement.Application project) is the one that will

    • create a News
    • call the Repository to add the News to it
    • conclude the business transaction, effectively persisting the News to the DB (often by means of a Unit of Work)