c# - Must Inject the Specifications on Business Layer? -


i'm trying learn somethings dependency injection , specification pattern.

if have scenario: have 3 methods , have different validation rules. rules validated specifications. so... class must receive on constructor these specifications this?

public postservice(irepositorio rep, ispecificationsave ss, specificationget g, ispecificationdelete sd) {    // things... } 

but if correct, when add new method, need change de constructor receive more 1 specification?

or, using dependency inject, better, in case, create instance of specification on method how's use specification that:

public void dosomething(myobject object) {      specification<myobject> specification = new specification<myobject>();      // things... } 

i know question simple 1 of you, i'm trying learn kinds of patterns yet.

you can use these specifications in each validator them adding 1 one in class, using specitication pattern, follow:

public class class1 : iclass1 {     private list<ispecification> contents;     private list<ispecification> specializations;      public list getcontents() {         return contents;     }      public set getfeatures() {          return specifications;           }      public class1() {         features = new list<ispecification>(){//put specializations belongs class here};         specialications = new list<ispecification>();     }         public boolean validator1() {         foreach(ispecification spec in this.specializations) {             if (!spec.getspecification().issatisfiedby(this))                 return false;         }         return true;     } }  public class specification1 : ispecification {   private object requiredfeature;    public specification1(object feature) {      requiredfeature = feature;   }    public boolean issatisfiedby(iclass class) {      return class.getfeatures().contains(requiredfeature);     } } 

then, can add specifications in application by:

iclass1 class = new class1(); class.getfeatures().add(new specialization1(// feature)); class.getfeatures().add(new specialization2(// feature)); class.getfeatures().add(new specialization3(// feature)); 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -