Skip to content

Commit

Permalink
Updated Obsolete Codes in Castle Windsor Configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
HesamKashefi committed Mar 4, 2019
1 parent 952c470 commit 0151e0b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
30 changes: 15 additions & 15 deletions Castle.Facilities.SolrNetIntegration.Tests/CastleFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,31 +72,31 @@ public void ReplacingMapper() {
public void Container_has_ISolrFieldParser() {
var solrFacility = new SolrNetFacility("http://localhost:8983/solr");
var container = new WindsorContainer();
container.AddFacility("solr", solrFacility);
container.AddFacility(solrFacility);
container.Resolve<ISolrFieldParser>();
}

[Fact]
public void Container_has_ISolrFieldSerializer() {
var solrFacility = new SolrNetFacility("http://localhost:8983/solr");
var container = new WindsorContainer();
container.AddFacility("solr", solrFacility);
container.AddFacility(solrFacility);
container.Resolve<ISolrFieldSerializer>();
}

[Fact]
public void Container_has_ISolrDocumentPropertyVisitor() {
var solrFacility = new SolrNetFacility("http://localhost:8983/solr");
var container = new WindsorContainer();
container.AddFacility("solr", solrFacility);
container.AddFacility(solrFacility);
container.Resolve<ISolrDocumentPropertyVisitor>();
}

[Fact]
public void Resolve_ISolrOperations() {
var solrFacility = new SolrNetFacility("http://localhost:8983/solr");
var container = new WindsorContainer();
container.AddFacility("solr", solrFacility);
container.AddFacility(solrFacility);
container.Resolve<ISolrOperations<Document>>();
}

Expand All @@ -107,17 +107,17 @@ public void MultiCore() {
const string core1url = "http://localhost:8983/solr/core1";
var solrFacility = new SolrNetFacility(core0url);
var container = new WindsorContainer();
container.AddFacility("solr", solrFacility);
container.AddFacility(solrFacility);

// override core1 components
const string core1Connection = "core1.connection";
container.Register(Component.For<ISolrConnection>().ImplementedBy<SolrConnection>().Named(core1Connection)
.Parameters(Parameter.ForKey("serverURL").Eq(core1url)));
.DependsOn(Dependency.OnValue("serverURL", core1url)));
container.Register(Component.For(typeof (ISolrBasicOperations<Core1Entity>), typeof (ISolrBasicReadOnlyOperations<Core1Entity>))
.ImplementedBy<SolrBasicServer<Core1Entity>>()
.ServiceOverrides(ServiceOverride.ForKey("connection").Eq(core1Connection)));
.DependsOn(Dependency.OnComponent("connection", core1Connection)));
container.Register(Component.For<ISolrQueryExecuter<Core1Entity>>().ImplementedBy<SolrQueryExecuter<Core1Entity>>()
.ServiceOverrides(ServiceOverride.ForKey("connection").Eq(core1Connection)));
.DependsOn(Dependency.OnComponent("connection", core1Connection)));

// assert that everything is correctly wired
container.Kernel.DependencyResolving += (client, model, dep) => {
Expand All @@ -142,7 +142,7 @@ public void AddCore() {
solrFacility.AddCore("core1-id", typeof(Document), core1url);
solrFacility.AddCore("core2-id", typeof(Core1Entity), core1url);
var container = new WindsorContainer();
container.AddFacility("solr", solrFacility);
container.AddFacility(solrFacility);

TestCores(container);
}
Expand Down Expand Up @@ -232,15 +232,15 @@ private void TestCoresWithPostConnections(IWindsorContainer container)
public void DictionaryDocument_Operations() {
var solrFacility = new SolrNetFacility("http://localhost:8983/solr");
var container = new WindsorContainer();
container.AddFacility("solr", solrFacility);
container.AddFacility(solrFacility);
container.Resolve<ISolrOperations<Dictionary<string, object>>>();
}

[Fact]
public void DictionaryDocument_ResponseParser() {
var solrFacility = new SolrNetFacility("http://localhost:8983/solr");
var container = new WindsorContainer();
container.AddFacility("solr", solrFacility);
container.AddFacility(solrFacility);
var parser = container.Resolve<ISolrDocumentResponseParser<Dictionary<string, object>>>();
Assert.IsType<SolrDictionaryDocumentResponseParser>(parser);
}
Expand All @@ -249,7 +249,7 @@ public void DictionaryDocument_ResponseParser() {
public void DictionaryDocument_Serializer() {
var solrFacility = new SolrNetFacility("http://localhost:8983/solr");
var container = new WindsorContainer();
container.AddFacility("solr", solrFacility);
container.AddFacility(solrFacility);
var serializer = container.Resolve<ISolrDocumentSerializer<Dictionary<string, object>>>();
Assert.IsType<SolrDictionarySerializer>(serializer);
}
Expand All @@ -258,7 +258,7 @@ public void DictionaryDocument_Serializer() {
public void MappingValidationManager() {
var solrFacility = new SolrNetFacility("http://localhost:8983/solr");
var container = new WindsorContainer();
container.AddFacility("solr", solrFacility);
container.AddFacility(solrFacility);
var validator = container.Resolve<IMappingValidator>();
}

Expand All @@ -275,7 +275,7 @@ public void SetConnectionTimeoutInMulticore() {
if (model.Implementation == typeof(SolrConnection))
model.Parameters.Add("Timeout", "2000");
};
container.AddFacility("solr", solrFacility);
container.AddFacility(solrFacility);
var allTimeouts = container.ResolveAll<ISolrConnection>().Cast<SolrConnection>().Select(x => x.Timeout);
foreach (var t in allTimeouts)
Assert.Equal(2000, t);
Expand All @@ -285,4 +285,4 @@ public class Document {}

public class Core1Entity {}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void DictionaryDocument()
{
var solrFacility = new SolrNetFacility("http://localhost:8983/solr");
var container = new WindsorContainer();
container.AddFacility("solr", solrFacility);
container.AddFacility(solrFacility);
var solr = container.Resolve<ISolrOperations<Dictionary<string, object>>>();
var results = solr.Query(SolrQuery.All);
Assert.True(results.Count> 0);
Expand All @@ -46,7 +46,7 @@ public void DictionaryDocument_add()
{
var solrFacility = new SolrNetFacility("http://localhost:8983/solr");
var container = new WindsorContainer();
container.AddFacility("solr", solrFacility);
container.AddFacility(solrFacility);
var solr = container.Resolve<ISolrOperations<Dictionary<string, object>>>();
solr.Add(new Dictionary<string, object> {
{"id", "ababa"},
Expand All @@ -56,4 +56,4 @@ public void DictionaryDocument_add()
});
}
}
}
}
15 changes: 8 additions & 7 deletions Castle.Facilities.SolrNetIntegration/SolrNetFacility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected override void Init()
Kernel.Register(Component.For<IReadOnlyMappingManager>().Instance(mapper));
//Kernel.Register(Component.For<ISolrCache>().ImplementedBy<HttpRuntimeCache>());
Kernel.Register(Component.For<ISolrConnection>().ImplementedBy<SolrConnection>()
.Parameters(Parameter.ForKey("serverURL").Eq(GetSolrUrl())));
.DependsOn(Dependency.OnValue("serverURL", GetSolrUrl())));

Kernel.Register(Component.For(typeof(ISolrDocumentActivator<>)).ImplementedBy(typeof(SolrDocumentActivator<>)));

Expand Down Expand Up @@ -161,35 +161,36 @@ private void RegisterCore(SolrCore core)
else
Kernel.Register(Component.For<ISolrConnection>().ImplementedBy<SolrConnection>()
.Named(coreConnectionId)
.Parameters(Parameter.ForKey("serverURL").Eq(core.Url)));
.DependsOn(Parameter.ForKey("serverURL").Eq(core.Url)));

var ISolrQueryExecuter = typeof(ISolrQueryExecuter<>).MakeGenericType(core.DocumentType);
var SolrQueryExecuter = typeof(SolrQueryExecuter<>).MakeGenericType(core.DocumentType);
Kernel.Register(Component.For(ISolrQueryExecuter).ImplementedBy(SolrQueryExecuter)
.Named(core.Id + SolrQueryExecuter)
.ServiceOverrides(ServiceOverride.ForKey("connection").Eq(coreConnectionId)));
.Named(core.Id + SolrQueryExecuter)
.DependsOn(Dependency.OnComponent("connection", coreConnectionId)));

var ISolrBasicOperations = typeof(ISolrBasicOperations<>).MakeGenericType(core.DocumentType);
var ISolrBasicReadOnlyOperations = typeof(ISolrBasicReadOnlyOperations<>).MakeGenericType(core.DocumentType);
var SolrBasicServer = typeof(SolrBasicServer<>).MakeGenericType(core.DocumentType);
Kernel.Register(Component.For(ISolrBasicOperations, ISolrBasicReadOnlyOperations)
.ImplementedBy(SolrBasicServer)
.Named(core.Id + SolrBasicServer)
.ServiceOverrides(ServiceOverride.ForKey("connection").Eq(coreConnectionId),
ServiceOverride.ForKey("queryExecuter").Eq(core.Id + SolrQueryExecuter)));
.DependsOn(Dependency.OnComponent("connection", coreConnectionId),
Dependency.OnComponent("queryExecuter", core.Id + SolrQueryExecuter)));

var ISolrOperations = typeof(ISolrOperations<>).MakeGenericType(core.DocumentType);
var SolrServer = typeof(SolrServer<>).MakeGenericType(core.DocumentType);
Kernel.Register(Component.For(ISolrOperations).ImplementedBy(SolrServer)
.Named(core.Id)
.ServiceOverrides(ServiceOverride.ForKey("basicServer").Eq(core.Id + SolrBasicServer)));
.DependsOn(Dependency.OnComponent("basicServer", core.Id + SolrBasicServer)));
}

/// <summary>
/// Adds a new core configuration to the facility
/// </summary>
/// <param name="documentType"></param>
/// <param name="coreUrl"></param>
/// <param name="postConnection"></param>
public void AddCore(Type documentType, string coreUrl, bool postConnection = false)
{
AddCore(Guid.NewGuid().ToString(), documentType, coreUrl, postConnection);
Expand Down

0 comments on commit 0151e0b

Please sign in to comment.