Created
November 4, 2015 20:15
-
-
Save rudism/8913d8b830ed1a28ca3d to your computer and use it in GitHub Desktop.
This file contains 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
namespace testattr | |
{ | |
using System; | |
using Funq; | |
using ServiceStack; | |
using ServiceStack.Web; | |
using ServiceStack.Text; | |
class AppHost : AppSelfHostBase | |
{ | |
public AppHost() : base("AttributeTest", typeof(AppHost).Assembly) { } | |
public override void Configure(Container container) { } | |
} | |
[AttributeUsage(AttributeTargets.Method, Inherited = true, AllowMultiple = false)] | |
class TestAttribute : RequestFilterAttribute | |
{ | |
public override void Execute(IRequest req, IResponse res, object requestDto) | |
{ | |
throw new Exception("attribute was executed"); | |
} | |
} | |
[Route("/test/without/attribute")] | |
class TestWithout : IReturnVoid { } | |
[Route("/test/with/attribute")] | |
class TestWith : IReturnVoid { } | |
class TestService : Service | |
{ | |
public void Get(TestWithout request) | |
{ | |
using(var svc = base.ResolveService<TestService>()) | |
{ | |
svc.Get(new TestWith()); | |
} | |
} | |
[Test] | |
public void Get(TestWith request) | |
{ | |
} | |
} | |
class MainClass | |
{ | |
public static void Main (string[] args) | |
{ | |
new AppHost().Init().Start("http://localhost:9090/"); | |
"Started apphost on port 9090".Print(); | |
using(var client = new JsonServiceClient("http://localhost:9090")) | |
{ | |
"Calling /test/without/attribute...".Print(); | |
client.Get<IReturnVoid>("/test/without/attribute"); | |
"Calling /test/with/attribute...".Print(); | |
client.Get<IReturnVoid>("/test/with/attribute"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: