using System.Collections.Generic;
using System.Threading.Tasks;
public static void Main()
Console.WriteLine("Hello World");
public class TestController : Controller
#warning If you want, implement and register an IHttpControllerActivator to inject the IAPI implementation and remove this constructor if you want to have DI all the way up your stack
public TestController() : this(new TestAPI(new UserDataService("http://10.8.200.1/test/"), new MenuService("http://10.8.200.1/menu/"), new UserItemsService("http://10.8.200.1/items/"))) {}
public TestController(ITestAPI api) { this.api = api; }
public ActionResult Index(string id)
return View(this.api.GetTestModel(id));
public interface ITestAPI
TestModel GetTestModel(string id);
public class TestAPI : ITestAPI
private IUserDataService userDataService;
private IMenuService menuService;
private IUserItemsService userItemsService;
public TestAPI(IUserDataService userDataService, IMenuService menuService, IUserItemsService userItemsService)
this.userDataService = userDataService;
this.menuService = menuService;
this.userItemsService = userItemsService;
public TestModel GetTestModel(string id)
var testModel = new TestModel();
testModel.UserData = this.userDataService.GetUserData(id);
testModel.MenuList = this.menuService.GetMenus(id);
testModel.UserItems = this.userItemsService.GetUserItems(id);
public interface IUserDataService { UserData GetUserData(string id); }
public interface IMenuService { List<Menu> GetMenus(string id); }
public interface IUserItemsService { List<UserItem> GetUserItems(string id); }
public abstract class BaseHttpServiceClient<TEntity, TPrimaryKey> where TEntity : class
private string remoteUri;
protected BaseHttpServiceClient(string remoteUri) { this.remoteUri = remoteUri; }
protected virtual TEntity GetRemoteItem(TPrimaryKey id)
using (HttpClient httpClient = new HttpClient())
string requestUri = this.remoteUri + id.ToString();
HttpRequestMessage testRequest = new HttpRequestMessage(HttpMethod.Get, requestUri);
HttpResponseMessage response = httpClient.SendAsync(testRequest).Result;
if (response.IsSuccessStatusCode)
var jsonData = response.Content.ReadAsStringAsync().Result;
testData = JsonConvert.DeserializeObject<TEntity>(jsonData);
public class UserDataService : BaseHttpServiceClient<UserData, string>, IUserDataService
public UserDataService(string remoteUri) : base(remoteUri) {}
public UserData GetUserData(string id) { return this.GetRemoteItem(id); }
public class MenuService : BaseHttpServiceClient<List<Menu>, string>, IMenuService
public MenuService(string remoteUri) : base(remoteUri) {}
public List<Menu> GetMenus(string id) { return this.GetRemoteItem(id); }
public class UserItemsService : BaseHttpServiceClient<List<UserItem>, string>, IUserItemsService
public UserItemsService(string remoteUri) : base(remoteUri) {}
public List<UserItem> GetUserItems(string id) { return this.GetRemoteItem(id); }
public string Name{get;set;}
public string PublisherId{get;set;}
public string AccountType{get;set;}
public UserData UserData {get;set;}
public List<Menu> MenuList {get;set;}
public List<UserItem> UserItems {get;set;}
public ActionResult View(object model) { throw new NotImplementedException(); }
public class ActionResult {}
public class HttpClient : IDisposable
public Task<HttpResponseMessage> SendAsync(HttpRequestMessage request) { throw new NotImplementedException(); }
public Task<String> ReadAsStringAsync() { throw new NotImplementedException(); }
public class HttpResponseMessage
public bool IsSuccessStatusCode { get { throw new NotImplementedException(); } }
public HttpContent Content { get { throw new NotImplementedException(); } }
public class HttpRequestMessage
public HttpRequestMessage(HttpMethod method, string requestUri) {}
public static T DeserializeObject<T>(string jsonData){ throw new NotImplementedException(); }