public static IUses Hydra(this IUses uses, Action <HydraOptions> hydraOptions = null)
        {
            var fluent = (IFluentTarget)uses;
            var has    = (IHas)uses;

            var opts = new HydraOptions
            {
                Curies =
                {
                    Vocabularies.Hydra,
                    Vocabularies.SchemaDotOrg,
                    Vocabularies.Rdf,
                    Vocabularies.XmlSchema
                }
            };

            hydraOptions?.Invoke(opts);

            fluent.Repository.CustomRegistrations.Add(opts);

            has.ResourcesOfType <object>()
            .WithoutUri
            .TranscodedBy <JsonLdCodec>()
            .ForMediaType("application/ld+json");

            has
            .ResourcesOfType <EntryPoint>()
            .Vocabulary(Vocabularies.Hydra)
            .AtUri("/")
            .HandledBy <EntryPointHandler>();

            has
            .ResourcesOfType <Context>()
            .Vocabulary(Vocabularies.Hydra)
            .AtUri("/.hydra/context.jsonld")
            .HandledBy <ContextHandler>();

            has
            .ResourcesOfType <ApiDocumentation>()
            .Vocabulary(Vocabularies.Hydra)
            .AtUri("/.hydra/documentation.jsonld")
            .HandledBy <ApiDocumentationHandler>();

            has.ResourcesOfType <Collection>().Vocabulary(Vocabularies.Hydra);
            has.ResourcesOfType <Class>().Vocabulary(Vocabularies.Hydra);
            has.ResourcesOfType <SupportedProperty>().Vocabulary(Vocabularies.Hydra);
            has.ResourcesOfType <IriTemplate>().Vocabulary(Vocabularies.Hydra);
            has.ResourcesOfType <IriTemplateMapping>().Vocabulary(Vocabularies.Hydra);
            has.ResourcesOfType <Operation>().Vocabulary(Vocabularies.Hydra);

            return(uses);
        }
Beispiel #2
0
        public static IUses Hydra(this IUses uses, Action <HydraOptions> hydraOptions = null)
        {
            var fluent = (IFluentTarget)uses;
            var has    = (IHas)uses;

            var opts = new HydraOptions
            {
                Curies =
                {
                    Vocabularies.Hydra,
                    Vocabularies.SchemaDotOrg,
                    Vocabularies.Rdf,
                    Vocabularies.XmlSchema
                }
            };

            hydraOptions?.Invoke(opts);

            fluent.Repository.CustomRegistrations.Add(opts);

            has.ResourcesOfType <object>()
            .WithoutUri
            .TranscodedBy <JsonLdCodecWriter>().ForMediaType("application/ld+json")
            .And.TranscodedBy <JsonLdCodecReader>().ForMediaType("application/ld+json");

            has
            .ResourcesOfType <EntryPoint>()
            .Vocabulary(Vocabularies.Hydra)
            .AtUri(r => "/")
            .HandledBy <EntryPointHandler>();

            has
            .ResourcesOfType <Context>()
            .Vocabulary(Vocabularies.Hydra)
            .AtUri(r => "/.hydra/context.jsonld")
            .HandledBy <ContextHandler>();

            has
            .ResourcesOfType <ApiDocumentation>()
            .Vocabulary(Vocabularies.Hydra)
            .AtUri(r => "/.hydra/documentation.jsonld")
            .HandledBy <ApiDocumentationHandler>();

            has.ResourcesOfType <Collection>().Vocabulary(Vocabularies.Hydra);
            has.ResourcesOfType <Class>().Vocabulary(Vocabularies.Hydra);
            has.ResourcesOfType <SupportedProperty>().Vocabulary(Vocabularies.Hydra);
            has.ResourcesOfType <IriTemplate>().Vocabulary(Vocabularies.Hydra);
            has.ResourcesOfType <IriTemplateMapping>().Vocabulary(Vocabularies.Hydra);
            has.ResourcesOfType <Operation>().Vocabulary(Vocabularies.Hydra);
            has.ResourcesOfType <Rdf.Property>().Vocabulary(Vocabularies.Rdf);

            if (opts.Serializer != null)
            {
                uses.Dependency(opts.Serializer);
            }
            else
            {
                uses.CustomDependency <IMetaModelHandler, JsonNetMetaModelHandler>(DependencyLifetime.Transient);
            }

            uses.Dependency(ctx => ctx.Singleton <FastUriGenerator>());
            uses.CustomDependency <IMetaModelHandler, JsonNetApiDocumentationMetaModelHandler>(DependencyLifetime.Transient);
            uses.CustomDependency <IMetaModelHandler, ClassDefinitionHandler>(DependencyLifetime.Transient);

            return(uses);
        }