public static IUses PipelineContributor <TArg1, TArg2, TArg3, TArg4, TPipeline>(
     this IUses anchor,
     Expression <Func <TArg1, TArg2, TArg3, TArg4, TPipeline> > factory) where TPipeline : class, IPipelineContributor
 {
     anchor.Dependency(d => d.Singleton(factory).As <IPipelineContributor>());
     return(anchor);
 }
        /// <summary>
        /// Adds a URI decorator to process incoming URIs.
        /// </summary>
        /// <typeparam name="TDecorator">The type of the URI decorator.</typeparam>
        /// <param name="anchor"></param>
        public static void UriDecorator <TDecorator>(this IUses anchor) where TDecorator : class, IUriDecorator
        {
            var fluentTarget = (IFluentTarget)anchor;

            fluentTarget.Repository.CustomRegistrations.Add(
                new DependencyRegistrationModel(typeof(IUriDecorator),
                                                typeof(TDecorator), DependencyLifetime.Transient));
        }
예제 #3
0
        /// <summary>
        /// Registers a custom dependency that can be used for leveraging dependency injection.
        /// </summary>
        /// <typeparam name="TService">The type of the service to register</typeparam>
        /// <typeparam name="TConcrete">The concrete type used when the service type is requested</typeparam>
        /// <param name="anchor"></param>
        /// <param name="lifetime">The lifetime of the object.</param>
        public static void CustomDependency <TService, TConcrete>(this IUses anchor,
                                                                  DependencyLifetime lifetime = DependencyLifetime.Singleton) where TConcrete : TService
        {
            var fluentTarget = (IFluentTarget)anchor;

            fluentTarget.Repository.CustomRegistrations.Add(
                new DependencyRegistrationModel(typeof(TService), typeof(TConcrete), lifetime));
        }
        protected override void SetUp()
        {
            base.SetUp();
            Resolver = new InternalDependencyResolver();
            Resolver.AddDependency <ITypeSystem, ReflectionBasedTypeSystem>();
            MetaModel         = new MetaModelRepository(Resolver);
            ResourceSpaceHas  = new FluentTarget(Resolver, MetaModel);
            ResourceSpaceUses = new FluentTarget(Resolver, MetaModel);

            DependencyManager.SetResolver(Resolver);
        }
        protected override void SetUp()
        {
            base.SetUp();
            Resolver = new InternalDependencyResolver();
            Resolver.AddDependency<ITypeSystem, ReflectionBasedTypeSystem>();
            MetaModel = new MetaModelRepository(Resolver);
            ResourceSpaceHas = new FluentTarget(Resolver, MetaModel);
            ResourceSpaceUses = new FluentTarget(Resolver, MetaModel);

            DependencyManager.SetResolver(Resolver);
        }
        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);
        }
예제 #7
0
        public static void SparkCodec(this IUses uses)
        {
            IDependencyResolver resolver = DependencyManager.GetService <IDependencyResolver>();

            resolver.AddDependency <ISparkConfiguration, SparkConfiguration>();
            resolver.AddDependency <ISparkCodecNamespacesConfiguration, SparkCodecNamespacesConfiguration>();

            // new stuff
            resolver.AddDependency <ISparkServiceContainerFactory, SparkServiceContainerFactory>();
            resolver.AddDependency <ISparkRenderer, SparkRenderer>();
            resolver.AddDependency <ISparkViewResolver, SparkViewResolverWithServiceContainerWrapper>();
            resolver.AddDependency <ISparkServiceContainerFactory, SparkServiceContainerFactory>();
        }
        public static void LinkingXmlDataContract(this IUses uses)
        {
            var config = (IFluentTarget)uses;

            config.Repository.ResourceRegistrations.Add(
                new ResourceModel
            {
                ResourceKey = config.TypeSystem.FromClr <object>(),
                Codecs      =
                {
                    new CodecModel(typeof(LinkingXmlDataContractCodec))
                }
            });
        }
예제 #9
0
        public static void OpenDocuments(this IUses uses)
        {
            ResourceSpace.Uses
            .PipelineContributor <AddDocumentBookmarkContributor>();
            ResourceSpace.Has.Resource <DocumentInfo>()
            .Uri("/documents/{id}")
            .Handler <DocumentInfoHandler>()
            .OpenEverythingDoc()
            .And
            .JsonDataContract();

            ResourceSpace.Has.Resource <DocumentData>()
            .Uri("/documents/{id}/raw")
            .Handler <DocumentDataHandler>();

            ResourceSpace.Has.Resource <DocumentLibrary>()
            .Uri("/documents")
            .Handler <DocumentLibraryHandler>()
            .OpenEverythingDoc();
        }
예제 #10
0
        public static void ConventionsFrom(this IUses uses, object source)
        {
            var assembly = source.GetType().Assembly;
            // try to find a base namespace that has a child Handlers and a child Resources namespace
            var allTypes = assembly.GetExportedTypes();
            var allNamespaces = allTypes.Select(x => x.Namespace).ToList();
            var rootNamespace =
                    (
                            from @namespace in allNamespaces
                            let resourcesLocation = @namespace.IndexOf(RESOURCES_MIDDLE)
                            where resourcesLocation != -1
                            let root = @namespace.Substring(0, resourcesLocation)
                            // root is Blah whe Blah.Resources exists
                            where allNamespaces.Any(x => x.StartsWith(root + ".Handlers."))
                            select root
                    ).Union(
                            from @namespace in allNamespaces
                            where @namespace.EndsWith(RESOURCES_SUFFIX)
                            let root = @namespace.Substring(0, @namespace.Length - RESOURCES_SUFFIX.Length)

                            where allNamespaces.Any(x => x.StartsWith(root + ".Handlers"))
                            select root
                            ).FirstOrDefault();

            if (rootNamespace == null) return;

            var resourcesToRegister = from resourceType in allTypes
                                      where resourceType.Namespace.StartsWith(rootNamespace + RESOURCES_SUFFIX)
                                      select new
                                      {
                                          Path = resourceType.Namespace.Length == rootNamespace.Length
                                                         ? Enumerable.Empty<string>()
                                                         : resourceType.Namespace.Substring(rootNamespace.Length + RESOURCES_SUFFIX.Length).Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries),
                                          Type = resourceType,
                                          Handler =
                                          (
                                                  from handlerType in allTypes
                                                  where handlerType.Namespace.StartsWith(rootNamespace + ".Handlers") &&
                                                        handlerType.Name.StartsWith(resourceType.Name + "Handler")
                                                  select handlerType
                                          ).FirstOrDefault()
                                      };
            var registrar = (IFluentTarget)uses;
            foreach (var resource in resourcesToRegister)
            {
                var resourceModel = new ResourceModel
                {
                        ResourceKey = registrar.TypeSystem.FromClr(resource.Type),
                        Uris =
                                { 
                                        new UriModel
                                        { 
                                                Uri =
                                                        (resource.Path.Count() > 0 ? string.Join("/",resource.Path.Select(x=>x.ToLowerInvariant()).ToArray()) : string.Empty) +
                                                        "/" +
                                                        ConvertResourceNameToUri(resource.Type.Name)
                                        }
                                }
                };
                if (resource.Handler != null)
                    resourceModel.Handlers.Add(registrar.TypeSystem.FromClr(resource.Handler));
                registrar.Repository.ResourceRegistrations.Add(resourceModel);
            }
        }
예제 #11
0
 /// <summary>
 /// Registers embedded view provider.
 /// </summary>
 /// <param name="uses"></param>
 /// <param name="assembly">Assembly containing views.</param>
 /// <param name="baseNamespace">Base namespace containing views.</param>
 public static void ViewsEmbeddedInTheAssembly(this IUses uses, Assembly assembly, string baseNamespace)
 {
     uses.Resolver.AddDependencyInstance(typeof(IViewProvider), new EmbeddedViewProvider(assembly, baseNamespace));
 }
예제 #12
0
 /// <summary>
 /// Adds a contributor to the pipeline.
 /// </summary>
 /// <typeparam name="TPipeline">The type of the pipeline contributor to register.</typeparam>
 /// <param name="anchor"></param>
 public static void PipelineContributor <TPipeline>(this IUses anchor) where TPipeline : class, IPipelineContributor
 {
     anchor.Resolver.AddDependency <IPipelineContributor, TPipeline>();
 }
예제 #13
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);
        }
예제 #14
0
        /// <summary>
        /// Registers SharpView in OpenRasta.
        /// </summary>
        /// <param name="src"></param>
        public static void SharpView(this IUses src)
        {
            var builder = (IFluentTarget)src;

            builder.Repository.CustomRegistrations.Add(new DependencyRegistrationModel(typeof(ICodeSnippetModifier), typeof(SharpViewSnippetModifier), DependencyLifetime.Singleton));
        }
 public ContentEncodingDefinition(string scheme, IUses anchor)
 {
     _anchor = anchor;
     _scheme = scheme;
 }