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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:02:06+00:00 2026-05-15T10:02:06+00:00

When I worked on asp.net mvc web site project, I investigated different approaches for

  • 0

When I worked on asp.net mvc web site project, I investigated different approaches for validation. Some of them were DataAnotation validation and Validation Block. They use attributes for setting up rules for validation. Like this:

[Required]
public string Name {get;set;}

I was confused how this approach combines with SRP (single responsibilty principle) from OOP world. Also I don’t like any business logic in business objects, I prefer “poor business objects” model, but when I decorate my business objects with validation attributes for real requirements, they become ugly (Has a lot of attributes / with localization logic and so on).

Idea with attributes realy simple, but in my opinion the validation decoration should be separated from object. I’m not sure is the approach to separate validation rules to xml files or to another objects, maybe it is a solution.

Another bad side of AOP – problems with unit testin such code. When I decorated some controller actions with custom attributes for example to import/export TempData between actions or initialize some required services I can’t to write proper unit test for testing this actions.

Do you think that attributes don’t break srp or you just disregard this and think that it’s simplest , is not worst way ?

P.S. I read some likes articles and discussions and I just want to put things in proper order.

P.P.S. sorry for my “fluent” english :=)

EDIT
I think that ‘breaking rules’ and ugly will be in such scenario:
In case when validation has some business rules – for example users must have unique email in system, you should to validate user input throw all youe layers in app, so when you write your custom attribute to check this data, business object will be connected with your data layer throw attribute.

  • 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-15T10:02:06+00:00Added an answer on May 15, 2026 at 10:02 am

    AOP by itself doesn’t break any SOLID rule, especially SRP.

    If you use UI validation attributes inside business object, then it definitely breaks SRP. But if you use such attributes in special UI classes, which is intended to be interface between UI and BL, then everything satisfies SRP.

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

Sidebar

Related Questions

I'm using Linq2Sql for my asp.net mvc project and so far it has worked
can i have some general advice on converting a classic asp site to asp.net?
I have the following JQuery code that worked perfect in C#/Asp.net 2.0 to call
I'm just starting with ASP.NET MVC and I was trying the Authentication with this
I am working with the new ASP.NET MVC areas and mixing it with themes.
I'm trying to access a simple ASP.NET MVC route, but it's erroring with: The
My ASP.NET MVC 2 application runs under built-in local NETWORK SERVICE account. I want
I am an asp.net web application developer and I always have used Enterprise Library
In my ASP.Net MVC View, I have a menu. The menu consists of a
Hopefully someone can help, I've been playing with ASP.NET MVC 2 for a learning

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.