c# - Service layer - returning validation & functional results -
i'd know best practice or suggestions returning validation results service layer going used in asp.net mvc.
option 1
public ienumberable<validationresult> foo(int userid, out videoid) { var validationresults = new list<validationresult>(); // validation logic goes here... videoid = _videoservice.addvideo(); return validationresults; }
option 2
public serviceresult foo(int userid) { var validationresults = new list<validationresult>(); var serviceresult = new serviceresult(); // validation logic goes here... serviceresult.returnobject = _videoservice.addvideo(); serviceresult.validationresults = validationresults; return serviceresult; } public class serviceresult { public ienumberable<validationresult> validationresults { get; set; } public object returnobject { get; set; } }
i doing option 1 because think boxing , un-boxing in option 2 pain point. ideas?
if return object
service layer, have cast returnobject
appropriate type/value in client code. therefore, type checking defferred runtime leads invalidcastexceptions if not careful. more importantly inelegant solution pollute code , therefore reduce understandability of code.
if want have 1 type use generics:
public class serviceresult<t> { public ienumberable<validationresult> validationresults { get; set; } public t resultobject { get;set; } }
if not solution, define result type type each service method.
public class resultbase { public ienumerable<validationresult> validationresults { get; set; } } public class registerresult : resultbase { public video video{get;set;} }
Comments
Post a Comment