Dependency Injection and Specification Pattern

Asked

Viewed 58 times

1

Good night.

Can anyone give me a help to understand this issue of Specification Pattern and Dependency Injection?

For example:

In my service layer I need to check if the user has filled in some information and if this information is within the expected system conditions (e.g.: in a blog, the user fills the title and the title has between three and sixty characters?).

It might well do something in the method to verify this rule, but there could be several rules and it would be an extensive and ugly method for it. In addition to breaking SOLID rules.

Okay, I can implement a basic Specification Patter for that. But, the service object (e.g., Blogs.Postservice) would have to receive as a parameter the Repository and the Specifications, right?

But if I have a query method, one to save, one to delete... the service object will have to receive a Specification for each situation (since the rules are different for each situation)? I mean, you’d have to have a builder like:

public PostService(IRepositorio rep, ISpecificationSave ss, SpecificationGet g, ISpecificationDelete sd) { 
      // do things... 
}

I hope the question is not too abstract... I want to understand how I can relate these two techniques without making too much mess...

Thank you for your guidance.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.