|
|
@@ -6,49 +6,9 @@ using Astralis;
|
|
|
|
|
|
namespace Spry {
|
|
|
|
|
|
- public class ComponentUriProvider : Object {
|
|
|
-
|
|
|
- private Dictionary<string, Type> type_mapping = new Dictionary<string, Type>();
|
|
|
- private Dictionary<string, string> name_mapping = new Dictionary<string, string>();
|
|
|
- private Container container = inject<Container>();
|
|
|
-
|
|
|
- public Component? get_component_instance(string id, Scope scope) throws Error {
|
|
|
- Type type;
|
|
|
- if(type_mapping.try_get(id, out type)) {
|
|
|
- return (Component)scope.resolve_type(type);
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- public string get_action_uri(string type_name, string action_name) throws Error {
|
|
|
- var component_id = upsert(type_name);
|
|
|
- return @"/_spry/$(component_id)/$action_name";
|
|
|
- }
|
|
|
-
|
|
|
- private string upsert(string type_name) throws Error {
|
|
|
- if(name_mapping.has(type_name)) {
|
|
|
- return name_mapping[type_name];
|
|
|
- }
|
|
|
-
|
|
|
- var registration = container.get_all_registrations()
|
|
|
- .where(r => r.implementation_type.is_a(typeof(Component)))
|
|
|
- .first_or_default(r => r.implementation_type.name() == type_name);
|
|
|
-
|
|
|
- if(registration == null) {
|
|
|
- throw new ContainerError.NOT_REGISTERED(@"Could not find registered component with name $(type_name)");
|
|
|
- }
|
|
|
-
|
|
|
- var uuid = Uuid.string_random();
|
|
|
- type_mapping[uuid] = registration.implementation_type;
|
|
|
- name_mapping[type_name] = uuid;
|
|
|
- return uuid;
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
public class ComponentEndpoint : Object, Endpoint {
|
|
|
|
|
|
- private ComponentUriProvider component_uri_provider = inject<ComponentUriProvider>();
|
|
|
+ private PathProvider component_uri_provider = inject<PathProvider>();
|
|
|
private Scope scope = inject<Scope>();
|
|
|
|
|
|
public async Astralis.HttpResult handle_request (HttpContext http_context, RouteContext route_context) throws Error {
|