Beispiel #1
0
        public void Add(Type paperType)
        {
            var spec = PaperSpec.GetSpec(paperType);

            typeIndex.Add(spec.Type, spec);
            pathIndex.Add(spec.Route, spec);
        }
Beispiel #2
0
        public PaperContext(IInjector injector, object paper, IPaperCatalog catalog, string requestUri)
        {
            requestUri = SanitizeRequestUri(requestUri);

            var paperSpec = PaperSpec.GetSpec(paper as Type ?? paper.GetType());
            var template  = paperSpec.UriTemplate;
            var prefix    = ApiPrefix ?? "";

            if (!prefix.StartsWith("/"))
            {
                prefix = "/" + prefix;
            }
            while (prefix.EndsWith("/"))
            {
                prefix = prefix.Substring(0, prefix.Length - 1);
            }

            if (!template.StartsWith("/"))
            {
                template = "/" + template;
            }
            while (template.EndsWith("/"))
            {
                template = template.Substring(0, template.Length - 1);
            }

            var composedTemplate = $"{prefix}{template}";

            var uriTemplate = new UriTemplate(template);

            uriTemplate.SetArgsFromUri(requestUri);

            var args = uriTemplate.CreateArgs();

            this.Injector     = injector;
            this.Paper        = paper;
            this.PaperCatalog = catalog;
            this.RequestUri   = requestUri;
            this.UriTemplate  = template;
            this.PathArgs     = args;
        }