Skip to content

Commit

Permalink
strongly-typed core collection
Browse files Browse the repository at this point in the history
  • Loading branch information
mausch committed May 2, 2012
1 parent b8cf0c1 commit 7f77e96
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
12 changes: 10 additions & 2 deletions 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<SolrServerElement> {
public override ConfigurationElementCollectionType CollectionType {
get { return ConfigurationElementCollectionType.BasicMap; }
}
Expand All @@ -22,5 +23,12 @@ public class SolrServers : ConfigurationElementCollection {
var solrServerElement = (SolrServerElement) element;
return solrServerElement.Url + solrServerElement.DocumentType;
}

IEnumerator<SolrServerElement> IEnumerable<SolrServerElement>.GetEnumerator() {
var c = (ConfigurationElementCollection) this;
foreach (SolrServerElement e in c) {
yield return e;
}
}
}
}
8 changes: 3 additions & 5 deletions Unity.SolrNetIntegration/SolrNetContainerConfiguration.cs
Expand Up @@ -140,21 +140,19 @@ public class SolrNetContainerConfiguration {
return coreId + typeof (SolrConnection);
}

private void AddCoresFromConfig(SolrServers solrServers, IUnityContainer container) {
private void AddCoresFromConfig(IEnumerable<SolrServerElement> solrServers, IUnityContainer container) {
if (solrServers == null) {
return;
}

var cores =
from server in solrServers.Cast<SolrServerElement>()
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);
Expand Down

0 comments on commit 7f77e96

Please sign in to comment.