c# - Is it possible to make a method inside an interface that takes list of method from that interface as parameter? -
edit:
i decided to:
- add savechanges() method repository, , make saving changes optional.
- use transactionscope , savechanges in controller methods
the above should work , simple implement - may not best approach, , not direct answer question have do.
original question:
i use following repository pattern interface in project:
public interface irepository<t> { keyvaluepair<bool, exception> create(t entitytoadd); keyvaluepair<bool, exception> create(list<t> entitylisttoadd); keyvaluepair<bool, exception> createorupdate(t entity); keyvaluepair<t, exception> get(int entityid); keyvaluepair<bool, exception> update(t entitytoupdate); keyvaluepair<bool, exception> update(list<t> entitylisttoupdate); keyvaluepair<bool, exception> delete(int entityid); keyvaluepair<bool, exception> delete(list<int> entityids); keyvaluepair<list<t>, exception> getfiltered(expression<func<t, bool>> filter); keyvaluepair<list<t>, exception> getfiltered<torderby>(expression<func<t, bool>> filter, expression<func<t,torderby>> order); keyvaluepair<t, exception> getfilteredsingle(expression<func<t, bool>> filter); keyvaluepair<bool, exception> updatecustomproperty<valuetype>(expression<func<t, bool>> filter, expression<func<t,valuetype>> property, valuetype value); }
problem designed method call context.savechanges() @ end of successful operation, , need more complex (create objects in 2 different tables in same method), , can cause trash data if - example - first entity created second not.
i add method repository, takes list of methods (from repository) parameter - thus, cold execute them 1 one , call savechanges() if calls succeed.
how can this? tried messing funct<> since needs fixed amount of function variables work, doesn't seem suitable job.
thanks in advance.
best regards.
i think distributing responsibility between different types.
concept may this:
public interface idbsave {} //generic interface public class table1saver : idbsave {} //class saves in table1 public class table2saver : idbsave {} //class saves in table2 //business process requires save in these 2 tables var twotablesbusinessprocess = new list<idbsave> {new table1saver(), new table2saver()}; //execute save in calling chanin of business process , if //succeed, confirm commit. if(twotablesbusinessprocess.all(save=>save.savetable())) context.savechanges();
i assume here every type derives idbsave
interface implements bool savetable(..)
method, returns true
if save suceed , false
otherwise.
Comments
Post a Comment