ASP.NET MVC 中的数据服务反射提供程序
我有一个现有的模型,其中的类可以从磁盘上的多个文件中读取模型。我在当前的 ASP.NET MVC 项目中使用它,并从磁盘读取正确的文件,处理读取的类需要 version URL 参数和 Request.PhysicalApplicationPath 参数。当我在 ASP.NET MVC 控制器中并且具有 Request 对象和传入参数形成 URL 时,这很容易。
然而,当我想要使用数据服务类来公开我的模型时,我首先需要能够将相同的 URL 参数和 Request 对象发送到类以读取模型。我不明白当我在 svc 文件中时我应该如何访问 URL 参数和 Request 对象,或者我应该如何使用我必须的 get 属性将它们获取到“上下文”对象读我的模型?
更新: 我想要类似下面的内容,其中“23456”将是版本号,我可以将其转发到从磁盘读取模型的类,其余的是我传递给 DataService 的查询以实现它的魔力。
http://MySite/23456/MyService/Category(1)/Products?$top=2&$orderby=name
所以基本上 - 是否可以同时使用 MVC 进行路由和参数控制等,然后将其余查询传递给 DataService 以获得询问基于 URL 的问题的完全灵活性?
I have a existing model with classes that reads the model from a number of files from disk. I use this in a current ASP.NET MVC project and to read the correct files from disk the classes handling the read needs a version URL parameter and a Request.PhysicalApplicationPath parameter. This is easy when I'm in a ASP.NET MVC controller and have the Request object and the incoming parameters form the URL.
When I then however want to use a Data Service class to expose my model I first need to be able to send the same URL parameter and the Request object to the classes for reading the model. I don't get how I should be able to access the URL parameters and the Request object when I'm in my svc file or how I should be able to get these to the "context" object with the get property that I have to read my model?
Update:
I would like to have something like the below where "23456" would then be the version number that I can forward to my classes that reads the model from disk and the rest is queries I pass on to the DataService to do it's magic.
http://MySite/23456/MyService/Category(1)/Products?$top=2&$orderby=name
So basically - is it possible to both use MVC for routing and parameter control etc and then pass the rest of the query to DataService to get the full flexibility of asking URL based questions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您是在问如何向底层服务(在本例中为数据服务)提供控制器中可用的一些特定于上下文的数据。
通常,更简单、最直接的方法是让控制器负责提取上下文特定的数据并将其作为标准方法参数转发到服务。
您当前的情况是否存在某些问题导致您无法获取控制器中的版本和 Url 数据并将它们传递到服务层?
I think you are asking how to provide some context-specific data that is available in your controller to an underlying service (a data service in this case).
Typically, the easier and most straightforward way to do that is to make it the responsibility of the controller to pull out context-specific data and forward it along to the service as standard method parameters.
Is there something about your current situation that prevents you from grabbing the Version and Url data in the controller and passing them down to the service tier?