Skip to content

Instantly share code, notes, and snippets.

@TimHeckel
Created April 6, 2012 22:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TimHeckel/2323392 to your computer and use it in GitHub Desktop.
Save TimHeckel/2323392 to your computer and use it in GitHub Desktop.
Possible implementation of dynamic hubs
//Define contracts something like this:
public interface ISlateApplicationProvider : IHubDescriptorProvider, IMethodDescriptorProvider
{
IList<AppHub> Apps { get; set; }
}
protected class AppHub
{
public string Name { get; set; }
public HubDescriptor Descriptor { get; set; }
public IEnumerable<MethodDescriptor> Methods { get; set; }
}
//And then implement something like this:
public class SlateApplicationProvider : ISlateApplicationProvider
{
private List<AppHub> _apps;
public List<AppHub> Apps
{
get
{
//need to populate my app list from my database and then probably cache it here...
_apps.Add(new AppHub() { Name = "Slate", Descriptor = new HubDescriptor() { Name = "Slate", Type = typeof(IHub) }, Methods = new List<MethodDescriptor>() });
return _apps;
}
set
{
_apps = value;
}
}
public IList<HubDescriptor> GetHubs()
{
return Apps.Select(h => h.Descriptor).ToList();
}
public bool TryGetHub(string hubName, out HubDescriptor descriptor)
{
descriptor = Apps.First(h => h.Name == hubName).Descriptor;
return true;
}
public IEnumerable<MethodDescriptor> GetMethods(HubDescriptor hub)
{
return Apps.First(h => h.Name == hub.Name).Methods;
}
public bool TryGetMethod(HubDescriptor hub, string method, out MethodDescriptor descriptor, params Newtonsoft.Json.Linq.JToken[] parameters)
{
descriptor = Apps.First(h => h.Name == hub.Name).Methods.First(m => m.Name == method);
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment