public async Task HandleAsync <TCommand>(TCommand command) { Ensure.NotNull(command, "command"); Type commandType = command.GetType(); RouteDefinition route; if (routeTable.TryGet(commandType, out route)) { using (HttpClient httpClient = httpAdapter.PrepareHttpClient(route)) { // Prepare content and send request. ObjectContent objectContent = httpAdapter.PrepareObjectContent(command, route); HttpResponseMessage response = await httpAdapter.Execute(httpClient, objectContent, route); //TODO: Process HTTP status errors. return; } } throw Ensure.Exception.InvalidOperation("Unnable to preces command without registered URL route, command type is '{0}'.", commandType.FullName); }
public async Task <TOutput> QueryAsync <TOutput>(IQuery <TOutput> query) { Ensure.NotNull(query, "query"); Type queryType = query.GetType(); RouteDefinition route; if (routeTable.TryGet(queryType, out route)) { using (HttpClient httpClient = httpAdapter.PrepareHttpClient(route)) { // Prepare content and send request. ObjectContent objectContent = httpAdapter.PrepareObjectContent(query, route); HttpResponseMessage response = await httpAdapter.Execute(httpClient, objectContent, route); // Parse output. TOutput output = await response.Content.ReadAsAsync <TOutput>(); return(output); } } throw Ensure.Exception.InvalidOperation("Unnable to preces query without registered URL route, query type is '{0}'.", queryType.FullName); }