Created
October 20, 2014 12:26
-
-
Save phillip-haydon/d491df603c5b1a0caa5c to your computer and use it in GitHub Desktop.
Sample Simple Authentication Process Calling
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
namespace SimpleAuthenticationProcessCallSample | |
{ | |
using System; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Hello World"); | |
var app = new WebAppService(); | |
INancyProccessor nancyProcessor = new TestNancyProcessor(); | |
IMvcProccessor mvcProcessor = new TestMvcProccessor(); | |
INancyModule module = new TestModule(); | |
IMvcController controller = new TestController(); | |
var result1 = app.DoSomething<INancyProccessor, INancyModule, dynamic>(nancyProcessor, module); | |
var result2 = app.DoSomething<IMvcProccessor, IMvcController, IActionResult>(mvcProcessor, controller); | |
Console.WriteLine("Result from Nancy: " + result1); | |
Console.WriteLine("Result from MVC: " + result2.Data); | |
Console.ReadKey(); | |
} | |
} | |
public interface IData | |
{ | |
} | |
public interface IActionResult | |
{ | |
string Data { get; } | |
} | |
public interface INancyModule | |
{ | |
} | |
public interface IMvcController | |
{ | |
} | |
public interface IMvcProccessor | |
{ | |
IActionResult Process(IMvcController controller, IData data); | |
} | |
public interface INancyProccessor | |
{ | |
dynamic Process(INancyModule module, IData data); | |
} | |
public class WebAppService | |
{ | |
public TResult DoSomething<T, TY, TResult>(T objectToInvokeOn, TY moduleOrController) | |
{ | |
IData data = new Data(); | |
var type = typeof (T); | |
var method = type.GetMethod("Process"); | |
return (TResult)method.Invoke(objectToInvokeOn, new object[] {moduleOrController, data}); | |
} | |
} | |
public class Data : IData | |
{ | |
} | |
public class ActionResult : IActionResult | |
{ | |
public string Data { get { return "lame mvc shit..."; } } | |
} | |
public class TestModule : INancyModule | |
{ | |
} | |
public class TestController : IMvcController | |
{ | |
} | |
public class TestNancyProcessor : INancyProccessor | |
{ | |
public dynamic Process(INancyModule module, IData data) | |
{ | |
return "rawrrrr"; | |
} | |
} | |
public class TestMvcProccessor : IMvcProccessor | |
{ | |
public IActionResult Process(IMvcController controller, IData data) | |
{ | |
return new ActionResult(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment