मेरी परियोजना में, बिजनेस लॉजिक सभी एप्लिकेशन सर्विस में, डोमेन सेवा केवल कुछ इकाई है, जो मुझे बता सकता है या मुझे यह दिखाने के लिए एक उदाहरण दे सकता है कि डोमेन-ड्राइव-डिज़ाइन में डोमेन सेवा में व्यवसाय तर्क कैसे जोड़ें? बहुत धन्यवाद!डोमेन-संचालित-डिज़ाइन में डोमेन सेवा में व्यवसाय तर्क कैसे जोड़ें?
अद्यतन
मैं एक साधारण solutation लिखते हैं, इस solutation एक वोट प्रणाली है, solutation मुख्य हिस्सा है:
Vote.Application.Service.VoteService.cs:
namespace Vote.Application.Service
{
public class VoteService
{
private IVoteRepository _voteRepository;
private IArticleRepository _articleRepository;
public VoteService(IVoteRepository voteRepository,IArticleRepository articleRepository)
{
_voteRepository = voteRepository;
_articleRepository = articleRepository;
}
public bool AddVote(int articleId, string ip)
{
var article = _articleRepository.Single(articleId);
if (article == null)
{
throw new Exception("this article not exist!");
}
else
{
article.VoteCount++;
}
if (IsRepeat(ip, articleId))
return false;
if (IsOvertakeTodayVoteCountLimit(ip))
return false;
_voteRepository.Add(new VoteRecord()
{
ArticleID = articleId,
IP = ip,
VoteTime = DateTime.Now
});
try
{
_voteRepository.UnitOfWork.Commit();
return true;
}
catch (Exception ex)
{
throw ex;
}
}
private bool IsRepeat(string ip, int articleId)
{
//An IP per article up to cast 1 votes
//todo
return false;
}
private bool IsOvertakeTodayVoteCountLimit(string ip)
{
//An IP per day up to cast 10 votes
//todo
return false;
}
}
}
वोट.डोमेन.कंट्रैक्ट.वोटोट रिपोजिटरी.cs:
namespace Vote.Domain.Contract
{
public interface IVoteRepository
: IRepository<VoteRecord>
{
void Add(VoteRecord model);
}
}
Vote.Domain.Contract.IArticleRepository.cs:
namespace Vote.Domain.Contract
{
public interface IArticleRepository
: IRepository<Article>
{
void Add(VoteRecord model);
Article Single(int articleId);
}
}
Vote.Domain.Entities.VoteRecord:
namespace Vote.Domain.Entities
{
public class VoteRecord
{
public int ID { get; set; }
public DateTime VoteTime { get; set; }
public int ArticleID { get; set; }
public string IP { get; set; }
}
}
Vote.Domain.Entities.Article:
namespace Vote.Domain.Entities
{
public class Article
{
public int ID { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public int VoteCount { get; set; }
}
}
मैं व्यवसाय लॉग को स्थानांतरित करना चाहता हूं in.s.service में डोमेन.service (वर्तमान में इस परियोजना नहीं), कौन मेरी मदद कर सकता है? कैसे करना उचित है? बहुत धन्यवाद!
क्या आप अपने डोमेन ऑब्जेक्ट्स के कुछ उदाहरण प्रदान कर सकते हैं? – casablanca
@ कैसाब्लांका मैंने अपना प्रश्न अपडेट किया है – artwl
आईपी का क्या अर्थ है? क्या अनुच्छेद और वोटरेकॉर्ड के बीच कोई संबंध है? कृपया कक्षा –