Skip to content

Commit 5c2dc43

Browse files
committed
Update Northwind to latest SS
1 parent d7b06d6 commit 5c2dc43

26 files changed

+398
-946
lines changed
Lines changed: 49 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,49 @@
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-
}
1+
using ServiceStack.Common;
2+
using ServiceStack.Northwind.ServiceModel.Operations;
3+
using ServiceStack.ServiceHost;
4+
5+
namespace ServiceStack.Northwind.ServiceInterface
6+
{
7+
/// <summary>
8+
/// Create your ServiceStack RESTful web service implementation.
9+
/// </summary>
10+
public class CachedCustomersService : ServiceStack.ServiceInterface.Service
11+
{
12+
public object Get(CachedCustomers request)
13+
{
14+
//Manually create the Unified Resource Name "urn:customers".
15+
return base.RequestContext.ToOptimizedResultUsingCache(base.Cache, "urn:customers", () =>
16+
{
17+
//Resolve the service in order to get the customers.
18+
using (var service = this.ResolveService<CustomersService>())
19+
return service.Get(new Customers());
20+
});
21+
}
22+
23+
public object Get(CachedCustomerDetails request)
24+
{
25+
//Create the Unified Resource Name "urn:customerdetails:{id}".
26+
var cacheKey = UrnId.Create<CustomerDetails>(request.Id);
27+
return base.RequestContext.ToOptimizedResultUsingCache(base.Cache, cacheKey, () =>
28+
{
29+
using (var service = this.ResolveService<CustomerDetailsService>())
30+
{
31+
return service.Get(new CustomerDetails { Id = request.Id });
32+
}
33+
});
34+
}
35+
36+
public object Get(CachedOrders request)
37+
{
38+
var cacheKey = UrnId.Create<Orders>(request.CustomerId ?? "all", request.Page.GetValueOrDefault(0).ToString());
39+
return base.RequestContext.ToOptimizedResultUsingCache(this.Cache, cacheKey, () =>
40+
{
41+
using(var service = this.ResolveService<OrdersService>())
42+
{
43+
return service.Get(new Orders { CustomerId = request.CustomerId, Page = request.Page });
44+
}
45+
});
46+
}
47+
}
48+
49+
}
Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,32 @@
1-
using System;
2-
using System.Net;
3-
using ServiceStack.Common.Web;
4-
using ServiceStack.Northwind.ServiceModel.Operations;
5-
using ServiceStack.Northwind.ServiceModel.Types;
6-
using ServiceStack.OrmLite;
7-
using ServiceStack.ServiceInterface;
8-
9-
namespace ServiceStack.Northwind.ServiceInterface
10-
{
11-
/// <summary>
12-
/// Create your ServiceStack RESTful web service implementation.
13-
/// </summary>
14-
public class CustomerDetailsService : RestServiceBase<CustomerDetails>
15-
{
16-
/// <summary>
17-
/// Gets or sets the database factory. The built-in IoC used with ServiceStack auto wires this property.
18-
/// </summary>
19-
public IDbConnectionFactory DbFactory { get; set; }
20-
21-
public override object OnGet(CustomerDetails request)
22-
{
23-
var customer = DbFactory.Run(dbCmd => dbCmd.GetByIdOrDefault<Customer>(request.Id));
24-
if (customer == null)
25-
throw new HttpError(HttpStatusCode.NotFound, new ArgumentException("Customer does not exist: " + request.Id));
26-
27-
var ordersService = base.ResolveService<OrdersService>();
28-
var ordersResponse = (OrdersResponse)ordersService.Get(new Orders { CustomerId = customer.Id });
29-
30-
return new CustomerDetailsResponse
31-
{
32-
Customer = customer,
33-
CustomerOrders = ordersResponse.Results,
34-
};
35-
}
36-
}
37-
}
1+
using System;
2+
using System.Net;
3+
using ServiceStack.Common.Web;
4+
using ServiceStack.Northwind.ServiceModel.Operations;
5+
using ServiceStack.Northwind.ServiceModel.Types;
6+
using ServiceStack.OrmLite;
7+
8+
namespace ServiceStack.Northwind.ServiceInterface
9+
{
10+
/// <summary>
11+
/// Create your ServiceStack RESTful web service implementation.
12+
/// </summary>
13+
public class CustomerDetailsService : ServiceStack.ServiceInterface.Service
14+
{
15+
public CustomerDetailsResponse Get(CustomerDetails request)
16+
{
17+
var customer = Db.IdOrDefault<Customer>(request.Id);
18+
if (customer == null)
19+
throw new HttpError(HttpStatusCode.NotFound, new ArgumentException("Customer does not exist: " + request.Id));
20+
21+
using (var ordersService = base.ResolveService<OrdersService>())
22+
{
23+
var ordersResponse = ordersService.Get(new Orders { CustomerId = customer.Id });
24+
25+
return new CustomerDetailsResponse {
26+
Customer = customer,
27+
CustomerOrders = ordersResponse.Results,
28+
};
29+
}
30+
}
31+
}
32+
}
Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
1-
using ServiceStack.Northwind.ServiceModel.Operations;
2-
using ServiceStack.Northwind.ServiceModel.Types;
3-
using ServiceStack.OrmLite;
4-
using ServiceStack.ServiceInterface;
5-
6-
namespace ServiceStack.Northwind.ServiceInterface
7-
{
8-
/// <summary>
9-
/// Create your ServiceStack RESTful web service implementation.
10-
/// </summary>
11-
public class CustomersService : RestServiceBase<Customers>
12-
{
13-
/// <summary>
14-
/// Gets or sets the database factory. The built-in IoC used with ServiceStack auto wires this property.
15-
/// </summary>
16-
public IDbConnectionFactory DbFactory { get; set; }
17-
18-
public override object OnGet(Customers request)
19-
{
20-
return new CustomersResponse { Customers = DbFactory.Run(dbCmd => dbCmd.Select<Customer>()) };
21-
}
22-
}
23-
}
1+
using ServiceStack.Northwind.ServiceModel.Operations;
2+
using ServiceStack.Northwind.ServiceModel.Types;
3+
using ServiceStack.OrmLite;
4+
5+
namespace ServiceStack.Northwind.ServiceInterface
6+
{
7+
/// <summary>
8+
/// Create your ServiceStack RESTful web service implementation.
9+
/// </summary>
10+
public class CustomersService : ServiceStack.ServiceInterface.Service
11+
{
12+
public CustomersResponse Get(Customers request)
13+
{
14+
return new CustomersResponse { Customers = base.Db.Select<Customer>() };
15+
}
16+
}
17+
}
Lines changed: 38 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,38 @@
1-
using System.Linq;
2-
using ServiceStack.Common.Extensions;
3-
using ServiceStack.Northwind.ServiceModel.Operations;
4-
using ServiceStack.Northwind.ServiceModel.Types;
5-
using ServiceStack.OrmLite;
6-
using ServiceStack.ServiceInterface;
7-
8-
namespace ServiceStack.Northwind.ServiceInterface
9-
{
10-
/// <summary>
11-
/// Create your ServiceStack RESTful web service implementation.
12-
/// </summary>
13-
public class OrdersService : RestServiceBase<Orders>
14-
{
15-
private const int PageCount = 20;
16-
17-
/// <summary>
18-
/// Gets or sets the database factory. The built-in IoC used with ServiceStack auto wires this property.
19-
/// </summary>
20-
public IDbConnectionFactory DbFactory { get; set; }
21-
22-
public override object OnGet(Orders request)
23-
{
24-
using (var dbConn = DbFactory.OpenDbConnection())
25-
{
26-
var orders = request.CustomerId.IsNullOrEmpty()
27-
? dbConn.Select<Order>("ORDER BY OrderDate DESC LIMIT {0}, {1}", (request.Page.GetValueOrDefault(1) - 1) * PageCount, PageCount)
28-
: dbConn.Select<Order>("CustomerId = {0}", request.CustomerId);
29-
30-
if (orders.Count == 0) { return new OrdersResponse(); }
31-
32-
var orderDetails = dbConn.Select<OrderDetail>(
33-
"OrderId IN ({0})", new SqlInValues(orders.ConvertAll(x => x.Id)));
34-
35-
var orderDetailsLookup = orderDetails.ToLookup(o => o.OrderId);
36-
37-
var customerOrders = orders.ConvertAll(o =>
38-
new CustomerOrder
39-
{
40-
Order = o,
41-
OrderDetails = orderDetailsLookup[o.Id].ToList()
42-
});
43-
44-
return new OrdersResponse { Results = customerOrders };
45-
}
46-
}
47-
}
48-
}
1+
using System.Linq;
2+
using ServiceStack.Common.Extensions;
3+
using ServiceStack.Northwind.ServiceModel.Operations;
4+
using ServiceStack.Northwind.ServiceModel.Types;
5+
using ServiceStack.OrmLite;
6+
7+
namespace ServiceStack.Northwind.ServiceInterface
8+
{
9+
/// <summary>
10+
/// Create your ServiceStack RESTful web service implementation.
11+
/// </summary>
12+
public class OrdersService : ServiceStack.ServiceInterface.Service
13+
{
14+
private const int PageCount = 20;
15+
16+
public OrdersResponse Get(Orders request)
17+
{
18+
var orders = request.CustomerId.IsNullOrEmpty()
19+
? Db.Select<Order>("ORDER BY OrderDate DESC LIMIT {0}, {1}", (request.Page.GetValueOrDefault(1) - 1) * PageCount, PageCount)
20+
: Db.Select<Order>("CustomerId = {0}", request.CustomerId);
21+
22+
if (orders.Count == 0) { return new OrdersResponse(); }
23+
24+
var orderDetails = Db.Select<OrderDetail>(
25+
"OrderId IN ({0})", new SqlInValues(orders.ConvertAll(x => x.Id)));
26+
27+
var orderDetailsLookup = orderDetails.ToLookup(o => o.OrderId);
28+
29+
var customerOrders = orders.ConvertAll(o =>
30+
new CustomerOrder {
31+
Order = o,
32+
OrderDetails = orderDetailsLookup[o.Id].ToList()
33+
});
34+
35+
return new OrdersResponse { Results = customerOrders };
36+
}
37+
}
38+
}

src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceInterface/ServiceStack.Northwind.ServiceInterface.csproj

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,31 +54,28 @@
5454
</PropertyGroup>
5555
<ItemGroup>
5656
<Reference Include="ServiceStack">
57-
<HintPath>..\..\packages\ServiceStack.3.9.11\lib\net35\ServiceStack.dll</HintPath>
57+
<HintPath>..\packages\ServiceStack.3.9.32\lib\net35\ServiceStack.dll</HintPath>
5858
</Reference>
5959
<Reference Include="ServiceStack.Common">
60-
<HintPath>..\..\packages\ServiceStack.Common.3.9.11\lib\net35\ServiceStack.Common.dll</HintPath>
60+
<HintPath>..\packages\ServiceStack.Common.3.9.32\lib\net35\ServiceStack.Common.dll</HintPath>
6161
</Reference>
6262
<Reference Include="ServiceStack.Interfaces">
63-
<HintPath>..\..\packages\ServiceStack.Common.3.9.11\lib\net35\ServiceStack.Interfaces.dll</HintPath>
63+
<HintPath>..\packages\ServiceStack.Common.3.9.32\lib\net35\ServiceStack.Interfaces.dll</HintPath>
6464
</Reference>
6565
<Reference Include="ServiceStack.OrmLite">
66-
<HintPath>..\..\packages\ServiceStack.OrmLite.SqlServer.3.9.9\lib\ServiceStack.OrmLite.dll</HintPath>
67-
</Reference>
68-
<Reference Include="ServiceStack.OrmLite.SqliteNET">
69-
<HintPath>..\..\packages\ServiceStack.OrmLite.Sqlite32.3.9.9\lib\net35\ServiceStack.OrmLite.SqliteNET.dll</HintPath>
66+
<HintPath>..\packages\ServiceStack.OrmLite.SqlServer.3.9.32\lib\ServiceStack.OrmLite.dll</HintPath>
7067
</Reference>
7168
<Reference Include="ServiceStack.OrmLite.SqlServer">
72-
<HintPath>..\..\packages\ServiceStack.OrmLite.SqlServer.3.9.9\lib\ServiceStack.OrmLite.SqlServer.dll</HintPath>
69+
<HintPath>..\packages\ServiceStack.OrmLite.SqlServer.3.9.32\lib\ServiceStack.OrmLite.SqlServer.dll</HintPath>
7370
</Reference>
7471
<Reference Include="ServiceStack.Redis">
75-
<HintPath>..\..\packages\ServiceStack.Redis.3.9.11\lib\net35\ServiceStack.Redis.dll</HintPath>
72+
<HintPath>..\packages\ServiceStack.Redis.3.9.32\lib\net35\ServiceStack.Redis.dll</HintPath>
7673
</Reference>
7774
<Reference Include="ServiceStack.ServiceInterface">
78-
<HintPath>..\..\packages\ServiceStack.3.9.11\lib\net35\ServiceStack.ServiceInterface.dll</HintPath>
75+
<HintPath>..\packages\ServiceStack.3.9.32\lib\net35\ServiceStack.ServiceInterface.dll</HintPath>
7976
</Reference>
8077
<Reference Include="ServiceStack.Text">
81-
<HintPath>..\..\packages\ServiceStack.Text.3.9.11\lib\net35\ServiceStack.Text.dll</HintPath>
78+
<HintPath>..\packages\ServiceStack.Text.3.9.32\lib\net35\ServiceStack.Text.dll</HintPath>
8279
</Reference>
8380
<Reference Include="System" />
8481
<Reference Include="System.Core">
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="ServiceStack" version="3.9.11" targetFramework="net35" />
4+
<package id="ServiceStack" version="3.9.32" targetFramework="net35" />
45
<package id="ServiceStack.Common" version="3.9.11" targetFramework="net35" />
6+
<package id="ServiceStack.Common" version="3.9.32" targetFramework="net35" />
57
<package id="ServiceStack.OrmLite.Sqlite32" version="3.9.9" targetFramework="net35" />
68
<package id="ServiceStack.OrmLite.SqlServer" version="3.9.9" targetFramework="net35" />
9+
<package id="ServiceStack.OrmLite.SqlServer" version="3.9.32" targetFramework="net35" />
710
<package id="ServiceStack.Redis" version="3.9.11" targetFramework="net35" />
11+
<package id="ServiceStack.Redis" version="3.9.32" targetFramework="net35" />
812
<package id="ServiceStack.Text" version="3.9.11" targetFramework="net35" />
13+
<package id="ServiceStack.Text" version="3.9.32" targetFramework="net35" />
914
</packages>

src/ServiceStack.Northwind/ServiceStack.Northwind.ServiceModel/Operations/CachedOperations.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Runtime.Serialization;
21
using ServiceStack.ServiceHost;
32

43
namespace ServiceStack.Northwind.ServiceModel.Operations

0 commit comments

Comments
 (0)