private static void CallTheServiceSynchronously() { IRequestDispatcher requestDispatcher = null; try { // NOTE: i'm using Agatha's IOC wrapper here directly... you could just as well resolve the IRequestDispatcher component // through _your_ container Console.WriteLine("Calling the service synchronously..."); requestDispatcher = IoC.Container.Resolve <IRequestDispatcher>(); Console.WriteLine("requesting a hello world... (synchronously)"); requestDispatcher.Add(new HelloWorldRequest()); Console.WriteLine("asking the server to reverse this string... (synchronously)"); requestDispatcher.Add(new ReverseStringRequest { StringToReverse = "asking the server to reverse this string" }); Console.WriteLine(requestDispatcher.Get <HelloWorldResponse>().Message); Console.WriteLine(requestDispatcher.Get <ReverseStringResponse>().ReversedString); Console.WriteLine("Sending HelloWorldCommand"); requestDispatcher.Send(new HelloWorldCommand()); } finally { // not really necessary in this silly example, but it's recommended to release each RequestDispatcher instance once you're // done with it if (requestDispatcher != null) { IoC.Container.Release(requestDispatcher); } } }
public static Request <T> Add <T>(this IRequestDispatcher dispatcher, Func <T> func, CancellationToken cancellationToken) { var request = new FuncRequest <T>(func, cancellationToken); dispatcher.Add(request); return(request); }
public static Request <T> Add <T>(this IRequestDispatcher dispatcher, Func <T> func) { var request = new FuncRequest <T>(func); dispatcher.Add(request); return(request); }
public static Request Add(this IRequestDispatcher dispatcher, Action action, CancellationToken cancellationToken) { var request = new ActionRequest(action, cancellationToken); dispatcher.Add(request); return(request); }
/// <summary> /// 检查添加到处置队列内; /// </summary> void TryAddDispatcherQueue() { if (!InQueue) { isCompleted = false; requestDispatcher.Add(this); InQueue = true; } }