Skip to content

Commit

Permalink
Allow rebinding ISolrConnection when using multiple cores.
Browse files Browse the repository at this point in the history
  • Loading branch information
zzapal committed Apr 12, 2012
1 parent 3d22dc5 commit 0f64ad0
Showing 1 changed file with 66 additions and 66 deletions.
132 changes: 66 additions & 66 deletions Ninject.Integration.SolrNet/SolrNetModule.cs
@@ -1,63 +1,63 @@
#region license
// Copyright (c) 2007-2010 Mauricio Scheffer
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#region license
// Copyright (c) 2007-2010 Mauricio Scheffer
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#endregion

using System;
using System.Collections.Generic;
using System.Configuration;
using Ninject.Integration.SolrNet.Config;
using Ninject.Modules;
using SolrNet;
using SolrNet.Impl;
using SolrNet.Impl.DocumentPropertyVisitors;
using SolrNet.Impl.FacetQuerySerializers;
using SolrNet.Impl.FieldParsers;
using SolrNet.Impl.FieldSerializers;
using SolrNet.Impl.QuerySerializers;
using SolrNet.Impl.ResponseParsers;
using SolrNet.Mapping;
using SolrNet.Mapping.Validation;
using SolrNet.Mapping.Validation.Rules;
using Ninject.Modules;
using SolrNet;
using SolrNet.Impl;
using SolrNet.Impl.DocumentPropertyVisitors;
using SolrNet.Impl.FacetQuerySerializers;
using SolrNet.Impl.FieldParsers;
using SolrNet.Impl.FieldSerializers;
using SolrNet.Impl.QuerySerializers;
using SolrNet.Impl.ResponseParsers;
using SolrNet.Mapping;
using SolrNet.Mapping.Validation;
using SolrNet.Mapping.Validation.Rules;
using SolrNet.Schema;
using SolrNet.Utils;

namespace Ninject.Integration.SolrNet {
namespace Ninject.Integration.SolrNet {
/// <summary>
/// Configures SolrNet in a Ninject kernel
/// </summary>
public class SolrNetModule : NinjectModule {
/// </summary>
public class SolrNetModule : NinjectModule {
private readonly string serverURL;
private readonly List<SolrCore> cores = new List<SolrCore>();

private readonly List<SolrCore> cores = new List<SolrCore>();

/// <summary>
/// Optional override for document mapper
/// </summary>
public IReadOnlyMappingManager Mapper { get; set; }

/// </summary>
public IReadOnlyMappingManager Mapper { get; set; }

/// <summary>
/// Configures SolrNet in a Ninject kernel
/// </summary>
/// <param name="serverURL"></param>
/// <param name="serverURL"></param>
public SolrNetModule(string serverURL) {
this.serverURL = serverURL;
}

}

/// <summary>
/// Configures SolrNet in a Ninject kernel with multiple servers/cores
/// </summary>
/// <param name="solrServers"></param>
/// <param name="solrServers"></param>
public SolrNetModule(SolrServers solrServers) {
AddCoresFromConfig(solrServers);
}
Expand Down Expand Up @@ -128,38 +128,38 @@ private static Type GetCoreDocumentType(SolrServerElement server)

Bind<ISolrConnection>().ToConstant(new SolrConnection(core.Url)).Named(coreConnectionId);
Bind(solrOperations).To(solrServer).Named(core.Id)
.WithConstructorArgument("connection", Kernel.Get<ISolrConnection>(coreConnectionId));
.WithConstructorArgument("connection", ctx => ctx.Kernel.Get<ISolrConnection>(coreConnectionId));
Bind(solrReadOnlyOperations).To(solrServer).Named(core.Id)
.WithConstructorArgument("connection", Kernel.Get<ISolrConnection>(coreConnectionId));
.WithConstructorArgument("connection", ctx => ctx.Kernel.Get<ISolrConnection>(coreConnectionId));
Bind(solrBasicOperations).To(solrBasicServer).Named(core.Id)
.WithConstructorArgument("connection", Kernel.Get<ISolrConnection>(coreConnectionId));
.WithConstructorArgument("connection", ctx => ctx.Kernel.Get<ISolrConnection>(coreConnectionId));
Bind(solrBasicReadOnlyOperations).To(solrBasicServer).Named(core.Id)
.WithConstructorArgument("connection", Kernel.Get<ISolrConnection>(coreConnectionId));
.WithConstructorArgument("connection", ctx => ctx.Kernel.Get<ISolrConnection>(coreConnectionId));
Bind(iSolrQueryExecuter).To(solrQueryExecuter).Named(core.Id)
.WithConstructorArgument("connection", Kernel.Get<ISolrConnection>(coreConnectionId));
.WithConstructorArgument("connection", ctx => ctx.Kernel.Get<ISolrConnection>(coreConnectionId));
}


public override void Load() {
var mapper = Mapper ?? new MemoizingMappingManager(new AttributesMappingManager());
Bind<IReadOnlyMappingManager>().ToConstant(mapper);
//Bind<ISolrCache>().To<HttpRuntimeCache>();
Bind<ISolrDocumentPropertyVisitor>().To<DefaultDocumentVisitor>();
Bind<ISolrFieldParser>().To<DefaultFieldParser>();
Bind(typeof (ISolrDocumentActivator<>)).To(typeof (SolrDocumentActivator<>));
Bind(typeof(ISolrDocumentResponseParser<>)).To(typeof(SolrDocumentResponseParser<>));
Bind<ISolrFieldSerializer>().To<DefaultFieldSerializer>();
Bind<ISolrQuerySerializer>().To<DefaultQuerySerializer>();


public override void Load() {
var mapper = Mapper ?? new MemoizingMappingManager(new AttributesMappingManager());
Bind<IReadOnlyMappingManager>().ToConstant(mapper);
//Bind<ISolrCache>().To<HttpRuntimeCache>();
Bind<ISolrDocumentPropertyVisitor>().To<DefaultDocumentVisitor>();
Bind<ISolrFieldParser>().To<DefaultFieldParser>();
Bind(typeof (ISolrDocumentActivator<>)).To(typeof (SolrDocumentActivator<>));
Bind(typeof(ISolrDocumentResponseParser<>)).To(typeof(SolrDocumentResponseParser<>));
Bind<ISolrFieldSerializer>().To<DefaultFieldSerializer>();
Bind<ISolrQuerySerializer>().To<DefaultQuerySerializer>();
Bind<ISolrFacetQuerySerializer>().To<DefaultFacetQuerySerializer>();
Bind(typeof (ISolrAbstractResponseParser<>)).To(typeof (DefaultResponseParser<>));
Bind<ISolrHeaderResponseParser>().To<HeaderResponseParser<string>>();
Bind<ISolrExtractResponseParser>().To<ExtractResponseParser>();
foreach (var p in new[] {
typeof(MappedPropertiesIsInSolrSchemaRule),
typeof(RequiredFieldsAreMappedRule),
typeof(UniqueKeyMatchesMappingRule),
})
Bind<IValidationRule>().To(p);
Bind(typeof (ISolrAbstractResponseParser<>)).To(typeof (DefaultResponseParser<>));
Bind<ISolrHeaderResponseParser>().To<HeaderResponseParser<string>>();
Bind<ISolrExtractResponseParser>().To<ExtractResponseParser>();
foreach (var p in new[] {
typeof(MappedPropertiesIsInSolrSchemaRule),
typeof(RequiredFieldsAreMappedRule),
typeof(UniqueKeyMatchesMappingRule),
})
Bind<IValidationRule>().To(p);
Bind(typeof(ISolrMoreLikeThisHandlerQueryResultsParser<>)).To(typeof(SolrMoreLikeThisHandlerQueryResultsParser<>));
Bind(typeof(ISolrDocumentSerializer<>)).To(typeof(SolrDocumentSerializer<>));

Expand All @@ -183,6 +183,6 @@ private static Type GetCoreDocumentType(SolrServerElement server)
Bind(typeof (ISolrOperations<>)).To(typeof (SolrServer<>));
Bind(typeof (ISolrReadOnlyOperations<>)).To(typeof (SolrServer<>));
}
}
}
}
}
}

0 comments on commit 0f64ad0

Please sign in to comment.