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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:20:14+00:00 2026-05-26T20:20:14+00:00

I would like to know what is the best practice in designing the constructors

  • 0

I would like to know what is the best practice in designing the constructors of DTO objects.

say i have a Dto object like this:

class CustomerDto
{
    public string Name { get; set; }
    public string Surname { get; set; }
    public string Phone { get; set; }
    ...
}

There are several ways to construct the object:

I could declare a constructor:

public CustomerDto(string name, string surname, string phone, ...)
{
    this.Name = name;
    this.Surname = surname;
    this.Phone = phone;
    ...
}

When you see this constructor and immediately conclude a SRP (Single responsibility) violation?

Even though these attributes are all related.

One could also argue there is no need to validate the properties as this is a DTO and has NO behavior, and the behavior should rather be on the domain object that this maps from.

In C# we can also more elegantly construct this object:

var dto = new CustomerDto ()
{
    Name = "Some name",
    Surname = "Some surname"
}

Or use a fluent builder or a framework such as NBuilder.

There is also the usage of Auto mapping frameworks like Automapper. The problem is also using an Ioc container the ctor becomes complex, as well as the risk in swapping arguments for example, you pass in name where surname is or vice versa, the validation could miss this more easy then explicit mapping as above.

Please help convince me which is the better way.

  • 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-26T20:20:14+00:00Added an answer on May 26, 2026 at 8:20 pm

    Value types as in your examples aren’t dependencies. A dependency provides a functionality (or configuration) to the consumer. In your case they are just normal values that are assigned to your DTO. As long as the data belongs together you do not violate SRP even if you assign a lot of values in the constructor. The single responsibility in this case is to hold the data.

    Also DTO’s shouldn’t be created by a IoC container and have no real dependencies. You should create them manually, by your persistency framework or using auto mapping.

    If assigning the values using a constructor or properties is better depends on the usage. If they are required the constructor variant is better. If they are optional the property way is better.

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

Sidebar

Related Questions

I would like to know what the best practice for populating a business object
I would like to know what would be the best practice to perform this:
I'm new to objective-c and would like to know the best practice for importing
I would like to know what is the best practice between using bind tag
I would like to know the best practice about raising an exception without arguments.
I would like to know witch is the best practice to test if void
I would like to know the best practice to deploy a website. What I
I would like to know what are the best practice programming tasks in relation
I'd like to know some best practice when designing c++ classes. To put it
I would like to know what's the best practice for setting up the distribution

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.