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 6905359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:10:26+00:00 2026-05-27T08:10:26+00:00

Let’s say you’re implementing your own version of stackoverflow (once again, yes) You have

  • 0

Let’s say you’re implementing your own version of stackoverflow (once again, yes)

You have a service that provides all the required functionality like this:

class Question { ... } // EF entity
class Answer { ... } // EF entity

interface IStackoverflowService
{
    void PostQuestion(Question question);
    void PostAnswer(Answer answer);
    void UpdateQuestion(Question question);
    ...
}

That seems to be pretty simple and generally I believe it’s a good idea. The only thing that I don’t like here is that client code (ASP.NET MVC controllers) has direct access to Questions and Answers. Pretend we have some tough BL related with posting questions and answers. It’s good idea to have this logic concentrated in a “single place” – on a service layer. In case your client code has access to Questions, it’s possible that someday somebody will decide to add “just a little bit of logic” to one of your controllers which is basically bad idea.

I’m thinking about defining a number of DTOs which will be the part of service interface, so the client code will only be able to work with these DTOs that contain “just the right amount of details”.

Let’s say your question entity is defined like this:

interface Question
{
    int Id { get; set; }
    User Poster { get; set; }
    DateTime Posted { get; set; }
    DateTime? Edited { get; set; }
    string Title { get; set; }
    string Text { get; set; }
    IQueryable<Answer> Answers { get; set; }
    ...
}

When posting the question, the request should only contain Title, Text and Poster. So, I’ll define a PostQuestionDTO:

class PostQuestionDTO
{
    User Poster { get; set; }
    string Title { get; set; }
    string Text { get; set; }
}

When somebody opens the page to check the question, there’s a little bit more details like Posted and Edited:

class QuestionDetailsDTO
{
    User Poster { get; set; }
    string Title { get; set; }
    string Text { get; set; }
    DateTime Posted { get; set; }
    DateTime? Edited { get; set; }
}

And so on. Is it a good practice or do you think it’s overengineering? What are the common approaches here?

  • 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-27T08:10:27+00:00Added an answer on May 27, 2026 at 8:10 am

    I’ve recently implemented pretty much exactly what you’re talking about, using a lot of Ninject and AutoMapper. My logical structure is like this:

        MyCompany.Data // Data layer namespace containing EF EDMX file / Codefirst / ADO.Net, whatever you want.
        class User { } // EF Entity
    
    MyCompany.Business // Business layer namespace containing business level factory interfaces and classes that expose their own business objects (some are directly mapped to the DB, most are not). All members expose POCO objects
    
    class NewUser { } // POCO class RegisteredUser { } // POCO interface IAccountFactory {
        void AddUser(NewUser user);
        RegisteredUser GetUser(int id); } // factory interface class AccountFactory : IAccountFactory // Service provider
    
    MyCompany.MVC // Presentation layer containing controllers and views. Controllers expose POCO objects from the business layer to the Views.
    

    I don’t think it’s overkill at all – yes, it takes a little longer to write, but AutoMapper basically removes most of the donkey work for you.

    A colleague of mine is very keen on Inversion of Control, which apparently solves this problem… though I’m not completely sold on it yet 🙂

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

Sidebar

Related Questions

Let's say that we have an ARGB color: Color argb = Color.FromARGB(127, 69, 12,
Let's say I have a simple Login servlet that checks the passed name and
Let's say I have some text as follows: do this, do that, then this,
Let's say, I have a .NET 2 installed. Can I programmatically install version 4
Let's say that I have a binary that I am building, and I include
Let's say that I have classes like this: public class Parent { public int
Let's say I'm creating an OpenGL game in C++ that will have many objects
Let's say that I have a set of relations that looks like this: relations
Let's say I'm building a data access layer for an application. Typically I have
Let's say you have a class called Customer, which contains the following fields: UserName

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.