c# - WebApi attribute routing defined on interface -
i'm trying convert wcf/rest service project mvc/webapi. service layer implemented multiple times wrapper different end systems, , implementations observe common contract defined in interface (icontract
). wcf, defined [webinvoke]
, [operationcontract]
attributes on each of methods exposed web service methods. in webapi, can simplified attribute routing defined on controller. however, keep route attributes defined on interface, implementations behave similarly.
here's sample of old interface:
[servicecontract] public interface icontract { [webinvoke(uritemplate = "version", method = "get", requestformat = webmessageformat.json, responseformat = webmessageformat.json, bodystyle = webmessagebodystyle.bare)] [operationcontract] string getversion(); }
here's hoping working:
public interface icontract { [route("version")] [httpget] string getversion(); }
i consider creating abstract base class, other stackoverflow question makes me think there isn't suitable replacement [webinvoke(uritemplate)]
using webapi attribute routing. case, or can point me similar, supported technique?
thanks
you cannot decorate interface route
attribute. because web api works within own framework... inspects objects of type apicontroller
in order determine route. interrogates custom controller's methods' attributes in order create routing. not custom icontract
interface, not care such routing.
even if change code-base of web api read , process route
attributes interfaces, how work? interface contract , not contain functionality. so, if saw route "version"
, controller implementation/instance map to? first 1 arbitrarily finds can assigned icontract
? last one? of them? , if of them, how execute n controller methods @ once?
i believe need evaluate understanding of attribute routing. tells web api framework use method on controller route. not abstract interface because not able determine deriving class execute.
Comments
Post a Comment