Created
May 28, 2014 18:31
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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