ServiceStack AutoQuery MVC controller

biddrafter

I'm experimenting with ServiceStack in MVC, using standard server side controllers creating view models. There are no jquery calls (or any direct calls) to any of the services registered at /api. Since SS lets us resolve services directly using:

using (var dr = HostContext.ResolveService<DataReportService>(base.HttpContext))

I haven't been calling the services using JsonServiceClient. Instead I've been resolving the services and calling their methods directly.

var dataReport = new DataReport
{
   IsArchived = false,
   ReportDate = DateTime.Now,
   ReportType = Model.ReportType
};
var drId = dr.Post(dataReport);

However, I have not been able to find a way to do this with the new AutoQuery feature. I know it creates a service automatically for any class that descends from QueryBase but I have had no luck resolving it. If I try to resolve the name used at run time then I won't compile (obviously). If I try something like this

using (var dr = HostContext.ResolveService<AutoQueryServiceBase>(base.HttpContext))

then it won't work either, because that is just a base class and not the actual registered instance. I know I could do this from JsonServiceClient but I'd really like to experiment with the direct call approach. Creating my own service that wraps any AutoQuery would work but seems like it defeats the purpose of the automatic creation. Still, I don't see any other way to proceed. Would love to hear any ideas.

Scott

Rather than using the ResolveService<T> method to get the service and call the executing method yourself, you can use HostContext.ServiceController.Execute method which allows you pass in the request DTO which will execute on the action method.

var dataReport = new DataReport
{
   IsArchived = false,
   ReportDate = DateTime.Now,
   ReportType = Model.ReportType
};
var drId = HostContext.ServiceController.Execute(dataReport);

I hope this helps.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Error calling ServiceStack service with mvc4 Controller

From Dev

ServiceStack - Validation not firing in MVC Action

From Dev

MVC with a front controller confusion

From Dev

Resolving ServiceStack Services in MVC Controllers

From Dev

MVC4 and ServiceStack session in Redis

From Dev

Local parameters in MVC controller

From Dev

MVC: Instantiate Controller In Router?

From Dev

Using ServiceStack Funq Dependency Injection in MVC

From Dev

ServiceStack AutoQuery MVC controller

From Dev

Using servicestack MVC integration causes: Cannot call action method 'T TryResolve[T]()' on controller

From Dev

Use of controller in MVC

From Dev

HttpContext is null for MVC controller

From Dev

MVC Controller Parameter is null

From Dev

ServiceStack - Autoquery & OrmLiteCacheClient

From Dev

Using ServiceStack Autoquery With Value Types that don't implement IConvertible

From Dev

Asynchronous MVC controller and HttpTaskAsyncHandler

From Dev

Can you disable count (Total) for ServiceStack AutoQuery?

From Dev

ServiceStack AutoQuery and [Authenticate] Attribute

From Dev

IdentityServer3 with ServiceStack and MVC Client

From Dev

Servicestack: restrict MVC action by role

From Dev

ServiceStack - Validation not firing in MVC Action

From Dev

MVC4 and ServiceStack session in Redis

From Dev

MVC4 + ServiceStack +....Glimpse?

From Dev

ServiceStack AutoQuery - Simplify with Generic and Custom Attributes

From Dev

ServiceStack AutoQuery, Multiple IJoin

From Dev

Using servicestack MVC integration causes: Cannot call action method 'T TryResolve[T]()' on controller

From Dev

ServiceStack AutoQuery MaxLimit

From Dev

Servicestack: restrict MVC action by role

From Dev

ServiceStack - Autoquery & Swapping Client Templates

Related Related

  1. 1

    Error calling ServiceStack service with mvc4 Controller

  2. 2

    ServiceStack - Validation not firing in MVC Action

  3. 3

    MVC with a front controller confusion

  4. 4

    Resolving ServiceStack Services in MVC Controllers

  5. 5

    MVC4 and ServiceStack session in Redis

  6. 6

    Local parameters in MVC controller

  7. 7

    MVC: Instantiate Controller In Router?

  8. 8

    Using ServiceStack Funq Dependency Injection in MVC

  9. 9

    ServiceStack AutoQuery MVC controller

  10. 10

    Using servicestack MVC integration causes: Cannot call action method 'T TryResolve[T]()' on controller

  11. 11

    Use of controller in MVC

  12. 12

    HttpContext is null for MVC controller

  13. 13

    MVC Controller Parameter is null

  14. 14

    ServiceStack - Autoquery & OrmLiteCacheClient

  15. 15

    Using ServiceStack Autoquery With Value Types that don't implement IConvertible

  16. 16

    Asynchronous MVC controller and HttpTaskAsyncHandler

  17. 17

    Can you disable count (Total) for ServiceStack AutoQuery?

  18. 18

    ServiceStack AutoQuery and [Authenticate] Attribute

  19. 19

    IdentityServer3 with ServiceStack and MVC Client

  20. 20

    Servicestack: restrict MVC action by role

  21. 21

    ServiceStack - Validation not firing in MVC Action

  22. 22

    MVC4 and ServiceStack session in Redis

  23. 23

    MVC4 + ServiceStack +....Glimpse?

  24. 24

    ServiceStack AutoQuery - Simplify with Generic and Custom Attributes

  25. 25

    ServiceStack AutoQuery, Multiple IJoin

  26. 26

    Using servicestack MVC integration causes: Cannot call action method 'T TryResolve[T]()' on controller

  27. 27

    ServiceStack AutoQuery MaxLimit

  28. 28

    Servicestack: restrict MVC action by role

  29. 29

    ServiceStack - Autoquery & Swapping Client Templates

HotTag

Archive