|
1 | | -using ServiceStack.CacheAccess; |
2 | | -using ServiceStack.Common; |
3 | | -using ServiceStack.Northwind.ServiceModel.Operations; |
4 | | -using ServiceStack.ServiceHost; |
5 | | -using ServiceStack.ServiceInterface; |
6 | | - |
7 | | -namespace ServiceStack.Northwind.ServiceInterface |
8 | | -{ |
9 | | - /// <summary> |
10 | | - /// Create your ServiceStack rest-ful web service implementation. |
11 | | - /// </summary> |
12 | | - public class CachedCustomersService : RestServiceBase<CachedCustomers> |
13 | | - { |
14 | | - /// <summary> |
15 | | - /// Gets or sets the cache client. The built-in IoC used with ServiceStack autowires this property. |
16 | | - /// </summary> |
17 | | - public ICacheClient CacheClient { get; set; } |
18 | | - |
19 | | - public override object OnGet(CachedCustomers request) |
20 | | - { |
21 | | - //Manually create the Unified Resource Name "urn:customers". |
22 | | - return base.RequestContext.ToOptimizedResultUsingCache( |
23 | | - this.CacheClient, "urn:customers", () => |
24 | | - { |
25 | | - //Resolve the service in order to get the customers. |
26 | | - var service = this.ResolveService<CustomersService>(); |
27 | | - return (CustomersResponse)service.Get(new Customers()); |
28 | | - }); |
29 | | - } |
30 | | - } |
31 | | - |
32 | | - /// <summary> |
33 | | - /// Create your ServiceStack rest-ful web service implementation. |
34 | | - /// </summary> |
35 | | - public class CachedCustomerDetailsService : RestServiceBase<CachedCustomerDetails> |
36 | | - { |
37 | | - /// <summary> |
38 | | - /// Gets or sets the cache client. The built-in IoC used with ServiceStack autowires this property. |
39 | | - /// </summary> |
40 | | - public ICacheClient CacheClient { get; set; } |
41 | | - |
42 | | - public override object OnGet(CachedCustomerDetails request) |
43 | | - { |
44 | | - //Create the Unified Resource Name "urn:customerdetails:{id}". |
45 | | - var cacheKey = UrnId.Create<CustomerDetails>(request.Id); |
46 | | - return base.RequestContext.ToOptimizedResultUsingCache( |
47 | | - this.CacheClient, cacheKey, () => |
48 | | - { |
49 | | - return (CustomerDetailsResponse)this.ResolveService<CustomerDetailsService>() |
50 | | - .Get(new CustomerDetails { Id = request.Id }); |
51 | | - }); |
52 | | - } |
53 | | - } |
54 | | - |
55 | | - /// <summary> |
56 | | - /// Create your ServiceStack rest-ful web service implementation. |
57 | | - /// </summary> |
58 | | - public class CachedOrdersService : RestServiceBase<CachedOrders> |
59 | | - { |
60 | | - /// <summary> |
61 | | - /// Gets or sets the cache client. The built-in IoC used with ServiceStack autowires this property. |
62 | | - /// </summary> |
63 | | - public ICacheClient CacheClient { get; set; } |
64 | | - |
65 | | - public override object OnGet(CachedOrders request) |
66 | | - { |
67 | | - var cacheKey = UrnId.Create<Orders>(request.CustomerId ?? "all", request.Page.GetValueOrDefault(0).ToString()); |
68 | | - return base.RequestContext.ToOptimizedResultUsingCache(this.CacheClient, cacheKey, () => |
69 | | - { |
70 | | - return (OrdersResponse)this.ResolveService<OrdersService>() |
71 | | - .Get(new Orders { CustomerId = request.CustomerId, Page = request.Page }); |
72 | | - }); |
73 | | - } |
74 | | - } |
75 | | - |
76 | | -} |
| 1 | +using ServiceStack.CacheAccess; |
| 2 | +using ServiceStack.Common; |
| 3 | +using ServiceStack.Northwind.ServiceModel.Operations; |
| 4 | +using ServiceStack.ServiceHost; |
| 5 | +using ServiceStack.ServiceInterface; |
| 6 | + |
| 7 | +namespace ServiceStack.Northwind.ServiceInterface |
| 8 | +{ |
| 9 | + /// <summary> |
| 10 | + /// Create your ServiceStack RESTful web service implementation. |
| 11 | + /// </summary> |
| 12 | + public class CachedCustomersService : RestServiceBase<CachedCustomers> |
| 13 | + { |
| 14 | + /// <summary> |
| 15 | + /// Gets or sets the cache client. The built-in IoC used with ServiceStack auto wires this property. |
| 16 | + /// </summary> |
| 17 | + public ICacheClient CacheClient { get; set; } |
| 18 | + |
| 19 | + public override object OnGet(CachedCustomers request) |
| 20 | + { |
| 21 | + //Manually create the Unified Resource Name "urn:customers". |
| 22 | + return base.RequestContext.ToOptimizedResultUsingCache( |
| 23 | + this.CacheClient, "urn:customers", () => |
| 24 | + { |
| 25 | + //Resolve the service in order to get the customers. |
| 26 | + var service = this.ResolveService<CustomersService>(); |
| 27 | + return (CustomersResponse)service.Get(new Customers()); |
| 28 | + }); |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + /// <summary> |
| 33 | + /// Create your ServiceStack RESTful web service implementation. |
| 34 | + /// </summary> |
| 35 | + public class CachedCustomerDetailsService : RestServiceBase<CachedCustomerDetails> |
| 36 | + { |
| 37 | + /// <summary> |
| 38 | + /// Gets or sets the cache client. The built-in IoC used with ServiceStack auto wires this property. |
| 39 | + /// </summary> |
| 40 | + public ICacheClient CacheClient { get; set; } |
| 41 | + |
| 42 | + public override object OnGet(CachedCustomerDetails request) |
| 43 | + { |
| 44 | + //Create the Unified Resource Name "urn:customerdetails:{id}". |
| 45 | + var cacheKey = UrnId.Create<CustomerDetails>(request.Id); |
| 46 | + return base.RequestContext.ToOptimizedResultUsingCache( |
| 47 | + this.CacheClient, cacheKey, () => |
| 48 | + { |
| 49 | + return (CustomerDetailsResponse)this.ResolveService<CustomerDetailsService>() |
| 50 | + .Get(new CustomerDetails { Id = request.Id }); |
| 51 | + }); |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + /// <summary> |
| 56 | + /// Create your ServiceStack RESTful web service implementation. |
| 57 | + /// </summary> |
| 58 | + public class CachedOrdersService : RestServiceBase<CachedOrders> |
| 59 | + { |
| 60 | + /// <summary> |
| 61 | + /// Gets or sets the cache client. The built-in IoC used with ServiceStack auto wires this property. |
| 62 | + /// </summary> |
| 63 | + public ICacheClient CacheClient { get; set; } |
| 64 | + |
| 65 | + public override object OnGet(CachedOrders request) |
| 66 | + { |
| 67 | + var cacheKey = UrnId.Create<Orders>(request.CustomerId ?? "all", request.Page.GetValueOrDefault(0).ToString()); |
| 68 | + return base.RequestContext.ToOptimizedResultUsingCache(this.CacheClient, cacheKey, () => |
| 69 | + { |
| 70 | + return (OrdersResponse)this.ResolveService<OrdersService>() |
| 71 | + .Get(new Orders { CustomerId = request.CustomerId, Page = request.Page }); |
| 72 | + }); |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | +} |
0 commit comments