Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I'm building a web API with entity framework. I have some questions about the business validation.

My solution contains several project. One for my entities and Dto (Data Transfert Object). One for my DbContext with code first and the repository. One for my API. One for my business services. I already implemented classic validation in my entities with DataAnnotations. What about the business rules? Business rules are all these rules I must check that force me to go to the database or do different kind of loop in the system.

My Business layer must implement all these rule. I cannot create these rules in my entities or DTO because I need to reference my database or other systems.

At this moment my business services are some kind of CRUD class that do all the job to create, map my entities. Where should I implement the validation?

What I have tried:

I already tried to implement IValidatableObject

public class ItemService : Service, ICrudService<item>, IValidatableObject
{

}


But my business class is not an entity. It seems not logic to use this IValidatableObject on a business class.
Posted
Updated 1-Nov-16 18:40pm

1 solution

I think I will use extension methods to create all my validations rules to lure the system

C#
public static class ItemBusinessRules
    {
        public static Notification ValidateDescription(this Item item, ItemService itemService)
        {
            return (item.Description.CompareTo(itemService.GenerateDescription(item)) != 0)
        }
    }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900