Skip to content

Commit

Permalink
register default core to resolve without a name
Browse files Browse the repository at this point in the history
  • Loading branch information
serbrech committed Apr 24, 2012
1 parent 56571bc commit 9aa2d38
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 25 deletions.
2 changes: 2 additions & 0 deletions Unity.SolrNetIntegration.Tests/MultiCoreTests.cs
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using MbUnit.Framework;
Expand All @@ -22,6 +23,7 @@ public class MultiCoreTests {
public void Get_SolrOperations_for_Entity() {
var solrOperations = container.Resolve<ISolrOperations<Entity>>();
Assert.IsNotNull(solrOperations);

}

[Test]
Expand Down
57 changes: 32 additions & 25 deletions Unity.SolrNetIntegration/SolrNetContainerConfiguration.cs
Expand Up @@ -71,38 +71,44 @@ public class SolrNetContainerConfiguration {
}

private void RegisterCore(SolrCore core, IUnityContainer container) {
GetCoreConnectionId(core);
container.RegisterType<ISolrConnection, SolrConnection>(GetCoreConnectionId(core), new InjectionConstructor(core.Url));
string connectionId = GetCoreConnectionId(core.Id);
container.RegisterType<ISolrConnection, SolrConnection>(connectionId, new InjectionConstructor(core.Url));
if (!container.IsRegistered(typeof (ISolrOperations<>).MakeGenericType(core.DocumentType))) {
RegisterSolrQueryExecuter(core, container, isNamed : false);
RegisterBasicOperations(core, container, isNamed : false);
RegisterSolrOperations(core, container, isNamed : false);
}
RegisterSolrQueryExecuter(core, container);
RegisterBasicOperations(core, container);
RegisterSolrOperations(core, container);
}

private static void RegisterSolrOperations(SolrCore core, IUnityContainer container) {
var ISolrReadOnlyOperations = typeof(ISolrReadOnlyOperations<>).MakeGenericType(core.DocumentType);
var ISolrBasicOperations = typeof(ISolrBasicOperations<>).MakeGenericType(core.DocumentType);
var ISolrOperations = typeof(ISolrOperations<>).MakeGenericType(core.DocumentType);
private static void RegisterSolrOperations(SolrCore core, IUnityContainer container, bool isNamed = true) {
var ISolrReadOnlyOperations = typeof (ISolrReadOnlyOperations<>).MakeGenericType(core.DocumentType);
var ISolrBasicOperations = typeof (ISolrBasicOperations<>).MakeGenericType(core.DocumentType);
var ISolrOperations = typeof (ISolrOperations<>).MakeGenericType(core.DocumentType);
var SolrServer = typeof (SolrServer<>).MakeGenericType(core.DocumentType);
var registrationId = isNamed ? core.Id : null;
var injectionConstructor = new InjectionConstructor(
new ResolvedParameter(ISolrBasicOperations, core.Id),
new ResolvedParameter(ISolrBasicOperations, registrationId),
new ResolvedParameter(typeof (IReadOnlyMappingManager)),
new ResolvedParameter(typeof (IMappingValidator)));
container.RegisterType(ISolrOperations, SolrServer, core.Id,injectionConstructor);
container.RegisterType(ISolrReadOnlyOperations, SolrServer, core.Id, injectionConstructor);
container.RegisterType(ISolrOperations, SolrServer, registrationId, injectionConstructor);
container.RegisterType(ISolrReadOnlyOperations, SolrServer, registrationId, injectionConstructor);
}

private static void RegisterBasicOperations(SolrCore core, IUnityContainer container) {
var ISolrBasicReadOnlyOperations = typeof(ISolrBasicReadOnlyOperations<>).MakeGenericType(core.DocumentType);
private static void RegisterBasicOperations(SolrCore core, IUnityContainer container, bool isNamed = true) {
var ISolrBasicReadOnlyOperations = typeof (ISolrBasicReadOnlyOperations<>).MakeGenericType(core.DocumentType);
var SolrBasicServer = typeof (SolrBasicServer<>).MakeGenericType(core.DocumentType);
var ISolrBasicOperations = typeof(ISolrBasicOperations<>).MakeGenericType(core.DocumentType);
var ISolrQueryExecuter = typeof(ISolrQueryExecuter<>).MakeGenericType(core.DocumentType);

string coreConnectionId = GetCoreConnectionId(core);
var ISolrBasicOperations = typeof (ISolrBasicOperations<>).MakeGenericType(core.DocumentType);
var ISolrQueryExecuter = typeof (ISolrQueryExecuter<>).MakeGenericType(core.DocumentType);
var registrationId = isNamed ? core.Id : null;
string coreConnectionId = GetCoreConnectionId(core.Id);
container.RegisterType(
ISolrBasicOperations, SolrBasicServer, core.Id,
ISolrBasicOperations, SolrBasicServer, registrationId,
new InjectionConstructor(
new ResolvedParameter(typeof (ISolrConnection), coreConnectionId),
new ResolvedParameter(ISolrQueryExecuter, core.Id),
new ResolvedParameter(ISolrQueryExecuter, registrationId),
new ResolvedParameter(typeof (ISolrDocumentSerializer<>).MakeGenericType(core.DocumentType)),
new ResolvedParameter(typeof (ISolrSchemaParser)),
new ResolvedParameter(typeof (ISolrHeaderResponseParser)),
Expand All @@ -111,10 +117,10 @@ public class SolrNetContainerConfiguration {
new ResolvedParameter(typeof (ISolrExtractResponseParser))));

container.RegisterType(
ISolrBasicReadOnlyOperations, SolrBasicServer, core.Id,
ISolrBasicReadOnlyOperations, SolrBasicServer, registrationId,
new InjectionConstructor(
new ResolvedParameter(typeof (ISolrConnection), coreConnectionId),
new ResolvedParameter(ISolrQueryExecuter, core.Id),
new ResolvedParameter(ISolrQueryExecuter, registrationId),
new ResolvedParameter(typeof (ISolrDocumentSerializer<>).MakeGenericType(core.DocumentType)),
new ResolvedParameter(typeof (ISolrSchemaParser)),
new ResolvedParameter(typeof (ISolrHeaderResponseParser)),
Expand All @@ -123,12 +129,13 @@ public class SolrNetContainerConfiguration {
new ResolvedParameter(typeof (ISolrExtractResponseParser))));
}

private static void RegisterSolrQueryExecuter(SolrCore core, IUnityContainer container) {
var ISolrQueryExecuter = typeof(ISolrQueryExecuter<>).MakeGenericType(core.DocumentType);
private static void RegisterSolrQueryExecuter(SolrCore core, IUnityContainer container, bool isNamed = true) {
var ISolrQueryExecuter = typeof (ISolrQueryExecuter<>).MakeGenericType(core.DocumentType);
var SolrQueryExecuter = typeof (SolrQueryExecuter<>).MakeGenericType(core.DocumentType);
string coreConnectionId = GetCoreConnectionId(core);
string coreConnectionId = GetCoreConnectionId(core.Id);
var registrationId = isNamed ? core.Id : null;
container.RegisterType(
ISolrQueryExecuter, SolrQueryExecuter, core.Id,
ISolrQueryExecuter, SolrQueryExecuter, registrationId,
new InjectionConstructor(
new ResolvedParameter(typeof (ISolrAbstractResponseParser<>).MakeGenericType(core.DocumentType)),
new ResolvedParameter(typeof (ISolrConnection), coreConnectionId),
Expand All @@ -137,8 +144,8 @@ public class SolrNetContainerConfiguration {
new ResolvedParameter(typeof (ISolrMoreLikeThisHandlerQueryResultsParser<>).MakeGenericType(core.DocumentType))));
}

private static string GetCoreConnectionId(SolrCore core) {
return core.Id + typeof (SolrConnection);
private static string GetCoreConnectionId(string coreId) {
return coreId + typeof (SolrConnection);
}

private void AddCoresFromConfig(SolrServers solrServers, IUnityContainer container) {
Expand Down

0 comments on commit 9aa2d38

Please sign in to comment.