Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6174311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:43:55+00:00 2026-05-23T23:43:55+00:00

I am trying some DDD and I will try to describe in most simple

  • 0

I am trying some DDD and I will try to describe in most simple manner what I have done.

Core project
The core project contains Entities, VO and domain services. For example I have User entity and UserRelation entity. I think we all know what is the User entity. The UserRelation contains information about how users are connected to each other like follow and connect(bidirectional follow). Because of that I have UserDomainService with stateless methods like Follow(user,user) and Connect(user, user).

public class User
{
    public string Name { get; set; }
    public string Username { get; set; }

    public void ChangeUsername(stirng newUsername)
    {
        ApplyEvent(new UserUsernameChanged(newUsername));
    }
}

public class UserRelation
{
    ctor(User1, User2, isBidirectional)
    public User User1 { get; set; }
    public User User2 { get; set; }
    public bool IsBidirectional { get; set; }
}

public class UserDomainService
{
    public UserRelation Follow(User user1, User user2)
    { 
        return new UserRelation(user1,user2,false);
    }
}

Repository Project

I am using NHibernate so I decided to not create such a project. Instead I am using NHibernate directly. For example, in my UI I get a user object from the DB, change it and then call session.Save(user).

The problem

If I want to do operation like follow I do this:

  • Get some info from DB
  • Call the Follow(user1, user2) from the service
  • Save the UserRelation object to the DB
    In the end the application code becomes a bit complex. Imagine if we want to use this code in 2-3 places and at some point we have to refactor it.

My solution
My solution is to create a ApplicationService project which will do the dirty work and force the consumer to use ApplicationService instead of using Entitties and Domain services directly

public class UserApplicationService
{
    ctor(UserDomainService userDomainService){}

    User GetUser(Guid id)
    {
        return NhibernateSession.Get(id)
    }

    public void Follow(Guid user1Id, Guid user2Id)
    {
        var u1 = GetUser(user1Id);
        var u2 = GetUser(user2Id);
        var userRelation = _userDomainService.Follow(u1,u2);
        NhibernateSession.Save(userRelation);
    }

    public void ChangeUsername(Guid user, string newUsername)
    {
        user.ChangeUsername(newUsername);
        NhibernateSession.Save(user);
    }
}

Is this application service good or bad? As you can see the new service act also as a repository so we can create a UserRepository class but lets skip that for now. What bothers me is the parameters in the two methods. They accept Guids and the service retrieves users from the DB. The other option is to pass directly User object. The ChangeUsername method is like the one from User entity + persistence.

Well, what do you think about this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T23:43:56+00:00Added an answer on May 23, 2026 at 11:43 pm

    I personally don’t see anything wrong, in fact this is how the company I work with has done it, as long as you abstract out the data access from that service it could be part of the business layer as a mediator between the data layer and the ui layer, it saves you from repeating yourself and making sure that any rules outlined for a certain operation fires.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying some programs in the C Language and come across to
I am trying to study some aspects of ddd with the domain of a
We are trying CQRS and DDD and event sourcing. Let's say I have a
I am trying some SQL code but I get an error when I try
I'm trying to get to light. In DDD approach we have Presentation Layer(UI), Application
I'm trying to write reusable components for my most common dev scenarios: I have
I have several concerns when trying to do DDD development with EF 4.2 (or
I'm trying to use DDD in my current project (c#, mvc, nhibernate, castle) and
I'm trying to apply some DDD-like patterns to the code I write to use
I'm really new to DDD and trying to grasp some of the concepts. Could

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.