From 7f77e9619fede93197f393af846ef64266c8e1f7 Mon Sep 17 00:00:00 2001 From: mausch Date: Wed, 2 May 2012 20:26:02 -0300 Subject: [PATCH] strongly-typed core collection --- Unity.SolrNetIntegration/Config/SolrServers.cs | 12 ++++++++++-- .../SolrNetContainerConfiguration.cs | 8 +++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Unity.SolrNetIntegration/Config/SolrServers.cs b/Unity.SolrNetIntegration/Config/SolrServers.cs index f11d142cf..f931cbf99 100644 --- a/Unity.SolrNetIntegration/Config/SolrServers.cs +++ b/Unity.SolrNetIntegration/Config/SolrServers.cs @@ -1,7 +1,8 @@ -using System.Configuration; +using System.Collections.Generic; +using System.Configuration; namespace Unity.SolrNetIntegration.Config { - public class SolrServers : ConfigurationElementCollection { + public class SolrServers : ConfigurationElementCollection, IEnumerable { public override ConfigurationElementCollectionType CollectionType { get { return ConfigurationElementCollectionType.BasicMap; } } @@ -22,5 +23,12 @@ public class SolrServers : ConfigurationElementCollection { var solrServerElement = (SolrServerElement) element; return solrServerElement.Url + solrServerElement.DocumentType; } + + IEnumerator IEnumerable.GetEnumerator() { + var c = (ConfigurationElementCollection) this; + foreach (SolrServerElement e in c) { + yield return e; + } + } } } \ No newline at end of file diff --git a/Unity.SolrNetIntegration/SolrNetContainerConfiguration.cs b/Unity.SolrNetIntegration/SolrNetContainerConfiguration.cs index 8d666ddd0..303891e75 100644 --- a/Unity.SolrNetIntegration/SolrNetContainerConfiguration.cs +++ b/Unity.SolrNetIntegration/SolrNetContainerConfiguration.cs @@ -140,21 +140,19 @@ public class SolrNetContainerConfiguration { return coreId + typeof (SolrConnection); } - private void AddCoresFromConfig(SolrServers solrServers, IUnityContainer container) { + private void AddCoresFromConfig(IEnumerable solrServers, IUnityContainer container) { if (solrServers == null) { return; } - var cores = - from server in solrServers.Cast() - select GetCoreFrom(server); + var cores = solrServers.Select(GetCore); foreach (var core in cores) { RegisterCore(core, container); } } - private static SolrCore GetCoreFrom(SolrServerElement server) { + private static SolrCore GetCore(SolrServerElement server) { var id = server.Id ?? Guid.NewGuid().ToString(); var documentType = GetCoreDocumentType(server); var coreUrl = GetCoreUrl(server);