Exemple #1
0
 public void Should_throw_exception_for_invalid_url() {
     var solrServers = new SolrServers {
         new SolrServerElement {
             Id = "test",
             Url = "http:/localhost:8893",
             DocumentType = typeof (Entity2).AssemblyQualifiedName,
         }
     };
     using (var container = new UnityContainer()) {
         new SolrNetContainerConfiguration().ConfigureContainer(solrServers, container);
         container.Resolve<ISolrConnection>();
     }
 }
        public IUnityContainer ConfigureContainer(SolrServers solrServers, IUnityContainer container) {
            container.RegisterType<IReadOnlyMappingManager, MemoizingMappingManager>(new InjectionConstructor(new ResolvedParameter(typeof (AttributesMappingManager))));
            container.RegisterType(typeof (ISolrDocumentActivator<>), typeof (SolrDocumentActivator<>));
            container.RegisterType(typeof (ISolrQueryExecuter<>), typeof (SolrQueryExecuter<>));
            container.RegisterType<ISolrDocumentPropertyVisitor, DefaultDocumentVisitor>();
            container.RegisterType<IMappingValidator, MappingValidator>();
            RegisterParsers(container);
            RegisterValidationRules(container);
            RegisterSerializers(container);

            AddCoresFromConfig(solrServers, container);

            return container;
        }
        public void Same_document_type_different_core_url() {
            var cores = new SolrServers {
                new SolrServerElement {
                    Id = "core1",
                    DocumentType = typeof (Entity).AssemblyQualifiedName,
                    Url = "http://localhost:8983/solr/entity1",
                },
                new SolrServerElement {
                    Id = "core2",
                    DocumentType = typeof (Entity).AssemblyQualifiedName,
                    Url = "http://localhost:8983/solr/entity2",
                }
            };

            container = new UnityContainer();
            new SolrNetContainerConfiguration().ConfigureContainer(cores, container);
            var core1 = container.Resolve<ISolrOperations<Entity>>("core1");
            var core2 = container.Resolve<ISolrOperations<Entity>>("core2");
        }
        private void AddCoresFromConfig(SolrServers solrServers, IUnityContainer container)
        {
            if (solrServers == null) {
            return;
              }

              var cores =
            from server in solrServers.Cast<SolrServerElement>()
            select GetCoreFrom(server);

              foreach (var core in cores) {
            RegisterCore(core, container);
              }
        }
Exemple #5
0
        public void DictionaryDocument_and_multi_core()
        {
            var cores = new SolrServers {
            new SolrServerElement {
              Id = "default",
              DocumentType = typeof (Entity).AssemblyQualifiedName,
              Url = "http://localhost:8983/solr/entity1",
            },
            new SolrServerElement {
              Id = "entity1dict",
              DocumentType = typeof (Dictionary<string, object>).AssemblyQualifiedName,
              Url = "http://localhost:8983/solr/entity1",
            },
            new SolrServerElement {
              Id = "another",
              DocumentType = typeof (Entity2).AssemblyQualifiedName,
              Url = "http://localhost:8983/solr/entity2",
            },
              };

              container = new UnityContainer();
              new SolrNetContainerConfiguration().ConfigureContainer(cores, container);
              container.Resolve<ISolrOperations<Entity>>();
              container.Resolve<ISolrOperations<Entity2>>();
              container.Resolve<ISolrOperations<Dictionary<string, object>>>();
        }