Skip to content

Instantly share code, notes, and snippets.

View scottmcarthur's full-sized avatar

Scott McArthur scottmcarthur

  • Edinburgh, United Kingdom
View GitHub Profile
@scottmcarthur
scottmcarthur / program.cs
Created February 13, 2014 15:17
How to use a RequestBinder in ServiceStack (v4) to convert a complex JSON object into a request.
using System;
using System.Linq;
using ServiceStack.Text;
using System.Collections.Generic;
using System.Runtime.Serialization;
using ServiceStack;
using ServiceStack.Web;
using System.Net;
namespace JsonTest
@scottmcarthur
scottmcarthur / program.cs
Created February 9, 2014 13:09
Transparent Encoded Complex Ids in Request/Response DTO in ServiceStack v4. (With support for string[])
using System;
using ServiceStack;
using System.Text;
using ServiceStack.Web;
using System.Collections.Generic;
namespace ComplexIdTest
{
class MainClass
{
@scottmcarthur
scottmcarthur / program.cs
Created February 9, 2014 12:23
Transparent encoding/decoding Id properties in ServiceStack v4
using System;
using ServiceStack;
using System.Text;
using ServiceStack.Web;
namespace ComplexIdTest
{
class MainClass
{
public static void Main()
@scottmcarthur
scottmcarthur / program.cs
Last active August 29, 2015 13:55
ServiceStack IoC Lifetime Test (v3)
using System;
using ServiceStack.ServiceInterface;
using ServiceStack.ServiceHost;
using ServiceStack.WebHost.Endpoints;
using Funq;
namespace Testv3
{
class MainClass
{
@scottmcarthur
scottmcarthur / program.cs
Created February 1, 2014 09:26
ServiceStack IoC injection example (v4)
using System;
using ServiceStack;
namespace Tests.Recipe
{
class MainClass
{
public static void Main()
{
// Very basic console host
@scottmcarthur
scottmcarthur / Program.cs
Last active August 29, 2015 13:55
Demo of ServiceStack Form Post Collection Data
using System;
using ServiceStack;
namespace Tests.Recipe
{
class MainClass
{
public static void Main()
{
// Very basic console host
@scottmcarthur
scottmcarthur / CheckDatabaseModel.cs
Last active January 4, 2016 08:38
How to automatically detect database model changes in ServiceStack.OrmLite, and have the database update automatically.
public void CheckDatabaseModel(Type modelType)
{
// Get the referenced model version
string modelVersion = Assembly.GetAssembly(modelType).GetName().Version.ToString();
// Determine the last model version number from the configuration
var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var lastModelVersion = config.AppSettings.Settings["DatabaseModelVersion"];
// Determine if the model has changed
@scottmcarthur
scottmcarthur / Program.cs
Created January 23, 2014 12:00
Basic Authentication, Multiple repositories - ServiceStack v4
using System;
using System.Linq;
using ServiceStack;
using ServiceStack.Auth;
using ServiceStack.Web;
using System.Net;
using System.Text;
using System.Collections.Generic;
namespace Testv4
@scottmcarthur
scottmcarthur / Program.cs
Last active January 4, 2016 02:39
Deferred Validation Example. This example uses a custom validator plugin that is a substitute for the ServiceStack standard ValidationFeature plugin. When a custom attribute of `MyRoleAttribute` is applied to the request DTO, then the validation will not be run, allowing the MyRoleAttribute to run the validation checks once it has completed. Req…
using System;
using System.Linq;
using ServiceStack.ServiceInterface;
using ServiceStack.ServiceHost;
using ServiceStack.WebHost.Endpoints;
using ServiceStack.Common.Web;
using ServiceStack.Logging;
using ServiceStack.FluentValidation.Results;
using ServiceStack.Text;
using ServiceStack.ServiceInterface.Validation;
@scottmcarthur
scottmcarthur / ServiceStackApp.cs
Created January 13, 2014 12:51
ServiceStack Upload with Multipart. (Working)
using System;
using ServiceStack;
namespace Testv4
{
class MainClass
{
public static void Main()
{
var appHost = new AppHost(500);