Skip to content

Instantly share code, notes, and snippets.

@scottmcarthur
Created May 28, 2014 18:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottmcarthur/ce07158eb803b8b8fb66 to your computer and use it in GitHub Desktop.
Save scottmcarthur/ce07158eb803b8b8fb66 to your computer and use it in GitHub Desktop.
ServiceStack v4 Funq container test, reuse scope request (http://localhost:9000/Test?Hello=World)
using System;
using Funq;
using ServiceStack;
namespace V4
{
class MainClass
{
public static void Main()
{
// Simple Self-Hosted Console App
var appHost = new AppHost(500);
appHost.Init();
appHost.Start("http://*:9000/");
Console.ReadKey();
}
}
public class AppHost : AppHostHttpListenerPoolBase
{
public AppHost(int poolSize) : base("Test Service", poolSize, typeof(TestService).Assembly)
{
}
public override void Configure(Container container)
{
container.RegisterAutoWiredAs<FakeAgent, IAgent>().ReusedWithin(ReuseScope.Request);
}
}
[Route("/Test", "GET")]
public class TestRequest
{
public string Hello { get; set; }
}
public interface IAgent
{
object Process(TestRequest request);
}
public class FakeAgent : IAgent
{
public object Process(TestRequest request)
{
return request.Hello;
}
}
public class TestService : Service {
readonly IAgent _agent;
public TestService(IAgent agent) {
_agent = agent;
}
public object Get(TestRequest request) {
return _agent.Process(request);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment