/// <summary>Sets up the factory to use <see cref="BaseUriResolutionStrategyComposition" /> for resolving external resources.</summary>
        /// <remarks>
        /// This implementation checks if a resource's identifier matches given <paramref name="baseUris" />
        /// and then resolves by making a <see cref="WebRequest" /> to resource's identifier.
        /// </remarks>
        /// <param name="factory">Target factory to be configured.</param>
        /// <param name="baseUris">Base Uris to match for external resources.</param>
        /// <returns>Given <paramref name="factory" />.</returns>
        public static EntityContextFactory WithUriMatchingResourceResulutionStrategy(this EntityContextFactory factory, IEnumerable <Uri> baseUris)
        {
            factory.WithDependencies <BaseUriResolutionStrategyComposition>();
            var resolutionStrategy = new UrlMatchingResourceResolutionStrategy(
                factory.Ontologies,
                factory.MappingModelVisitors.OfType <BaseUriMappingModelVisitor>().First().MappingAssemblies,
                baseUris);

            return(factory.WithResourceResolutionStrategy(resolutionStrategy));
        }
Beispiel #2
0
        private static IEntityContext CreateEntityContext()
        {
            var entityContextFactory = new EntityContextFactory()
                                       .WithMetaGraphUri(MetaGraphUri)
                                       .WithMappings(builder => builder.FromAssemblyOf <IKnowSomething>())
                                       .WithDefaultOntologies()
                                       .WithOntology(new IntegrationTestsBase.ChemOntology())
                                       .WithOntology(new IntegrationTestsBase.LifeOntology())
                                       .WithOntology(new TestOntologyProvider(false))
                                       .WithNamedGraphSelector(new NamedGraphSelector())
                                       .WithDependenciesInternal <BaseUriResolutionStrategyComposition>()
                                       .WithDotNetRDF(CreateTripleStore());
            var resolutionStrategy = new UrlMatchingResourceResolutionStrategy(
                entityContextFactory.Ontologies,
                entityContextFactory.MappingModelVisitors.OfType <BaseUriMappingModelVisitor>().First().MappingAssemblies,
                BaseUris,
                CreateWebRequest);

            return(entityContextFactory
                   .WithResourceResolutionStrategy(resolutionStrategy)
                   .CreateContext());
        }