Skip to content

Commit

Permalink
Add netstandard support to unity integration
Browse files Browse the repository at this point in the history
  • Loading branch information
gjunge committed Feb 25, 2018
1 parent 27d9537 commit 62baf17
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 31 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The easiest way to get going is to use our NuGet packages:
|[SolrNet.Microsoft.DependencyInjection](https://www.nuget.org/packages/SolrNet.Microsoft.DependencyInjection/)|[Microsoft Core Dependency Injection](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection) | 4.6.1 | 2.0 |
|[SolrNet.StructureMap](https://www.nuget.org/packages/SolrNet.StructureMap/)|[StructureMap](http://structuremap.github.io/) | 4.6 | 2.0 |
|[SolrNet.Ninject](https://www.nuget.org/packages/SolrNet.Ninject/)| [Ninject](http://www.ninject.org/) | 4.6 | 2.0 |
|[SolrNet.Unity](https://www.nuget.org/packages/SolrNet.Unity/)| [Unity](https://github.com/unitycontainer/unity) | 4.6 | - |
|[SolrNet.Unity](https://www.nuget.org/packages/SolrNet.Unity/)| [Unity](https://github.com/unitycontainer/unity) | 4.6 | 2.0 |
|[SolrNet.Autofac](https://www.nuget.org/packages/SolrNet.Autofac/)| [Autofac](https://autofac.org/) | 4.6 | 2.0 |
|[SolrNet.NHibernate](https://www.nuget.org/packages/SolrNet.NHibernate/)| [NHibernate](http://nhibernate.info/) | 4.6 | - |

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net46</TargetFramework>
<TargetFramework>net462</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
Expand All @@ -15,4 +15,9 @@
<Name>Unity.SolrNetIntegration</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Update="App.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
6 changes: 2 additions & 4 deletions Unity.SolrNetIntegration.Tests/UnityMultiCoreFixture.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Configuration;
using System.Configuration;
using Xunit;
using SolrNet;
using Unity.SolrNetIntegration.Config;
Expand All @@ -16,8 +16,6 @@ public UnityMultiCoreFixture() {
new SolrNetContainerConfiguration().ConfigureContainer(solrConfig.SolrServers, container);
}



[Fact]
public void Get_SolrOperations_for_Entity() {
var solrOperations = container.Resolve<ISolrOperations<Entity>>();
Expand Down Expand Up @@ -68,4 +66,4 @@ public void Dispose()
container.Dispose();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Reflection;
using Unity.Builder;
using Unity.Builder.Strategy;
using Microsoft.Practices.EnterpriseLibrary.Common.Utility;

namespace Unity.SolrNetIntegration.Collections
{
Expand All @@ -14,9 +13,9 @@ public class CollectionResolutionStrategy : BuilderStrategy

private delegate object CollectionResolver(IBuilderContext context);

public override void PreBuildUp(IBuilderContext context)
public override object PreBuildUp(IBuilderContext context)
{
Guard.ArgumentNotNull(context, "context");
if (context == null) throw new ArgumentNullException(nameof(context));

Type typeToBuild = context.BuildKey.Type;

Expand All @@ -37,7 +36,9 @@ public override void PreBuildUp(IBuilderContext context)
context.Existing = resolver(context);
context.BuildComplete = true;
}
}
}

return null;
}

private static object ResolveCollection<T>(IBuilderContext context)
Expand All @@ -53,4 +54,4 @@ private static object ResolveCollection<T>(IBuilderContext context)
return results;
}
}
}
}
4 changes: 2 additions & 2 deletions Unity.SolrNetIntegration/Config/SolrServerElement.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Configuration;

namespace Unity.SolrNetIntegration.Config {
public class SolrServerElement : ConfigurationElement {
public class SolrServerElement : ConfigurationElement, ISolrServer {
private const string ID = "id";
private const string URL = "url";
private const string DOCUMENT_TYPE = "documentType";
Expand All @@ -28,4 +28,4 @@ public override string ToString() {
return string.Format("Id: {0} Url: {1} DocType: {2}", Id, Url, DocumentType);
}
}
}
}
6 changes: 3 additions & 3 deletions Unity.SolrNetIntegration/Config/SolrServers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Configuration;

namespace Unity.SolrNetIntegration.Config {
public class SolrServers : ConfigurationElementCollection, IEnumerable<SolrServerElement> {
public class SolrServers : ConfigurationElementCollection, IEnumerable<ISolrServer> {
public override ConfigurationElementCollectionType CollectionType {
get { return ConfigurationElementCollectionType.BasicMap; }
}
Expand All @@ -24,11 +24,11 @@ protected override object GetElementKey(ConfigurationElement element) {
return solrServerElement.Url + solrServerElement.DocumentType;
}

IEnumerator<SolrServerElement> IEnumerable<SolrServerElement>.GetEnumerator() {
IEnumerator<ISolrServer> IEnumerable<ISolrServer>.GetEnumerator() {
var c = (ConfigurationElementCollection) this;
foreach (SolrServerElement e in c) {
yield return e;
}
}
}
}
}
9 changes: 9 additions & 0 deletions Unity.SolrNetIntegration/ISolrServer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Unity.SolrNetIntegration
{
public interface ISolrServer
{
string Id { get; set; }
string Url { get; set; }
string DocumentType { get; set; }
}
}
21 changes: 10 additions & 11 deletions Unity.SolrNetIntegration/SolrNetContainerConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
using SolrNet.Mapping.Validation.Rules;
using SolrNet.Schema;
using SolrNet.Utils;
using Unity.SolrNetIntegration.Config;
using Unity.Injection;

namespace Unity.SolrNetIntegration {
public class SolrNetContainerConfiguration {
public IUnityContainer ConfigureContainer(SolrServers solrServers, IUnityContainer container) {
public IUnityContainer ConfigureContainer(IEnumerable<ISolrServer> solrServers, IUnityContainer container) {

//add Collections support
container.AddNewExtension<Collections.CollectionResolutionExtension>();
Expand Down Expand Up @@ -146,7 +145,7 @@ private static string GetCoreConnectionId(string coreId) {
return coreId + typeof (SolrConnection);
}

private void AddCoresFromConfig(IEnumerable<SolrServerElement> solrServers, IUnityContainer container) {
private void AddCoresFromConfig(IEnumerable<ISolrServer> solrServers, IUnityContainer container) {
if (solrServers == null) {
return;
}
Expand All @@ -158,41 +157,41 @@ private void AddCoresFromConfig(IEnumerable<SolrServerElement> solrServers, IUni
}
}

private static SolrCore GetCore(SolrServerElement server) {
private static SolrCore GetCore(ISolrServer server) {
var id = server.Id ?? Guid.NewGuid().ToString();
var documentType = GetCoreDocumentType(server);
var coreUrl = GetCoreUrl(server);
UriValidator.ValidateHTTP(coreUrl);
return new SolrCore(id, documentType, coreUrl);
}

private static string GetCoreUrl(SolrServerElement server) {
private static string GetCoreUrl(ISolrServer server) {
var url = server.Url;
if (string.IsNullOrEmpty(url)) {
throw new ConfigurationErrorsException("Core url missing in SolrNet core configuration");
throw new ArgumentNullException("Core url missing in SolrNet core configuration");
}
return url;
}

private static Type GetCoreDocumentType(SolrServerElement server) {
private static Type GetCoreDocumentType(ISolrServer server) {
var documentType = server.DocumentType;

if (string.IsNullOrEmpty(documentType)) {
throw new ConfigurationErrorsException("Document type missing in SolrNet core configuration");
throw new ArgumentNullException("Document type missing in SolrNet core configuration");
}

Type type;

try {
type = Type.GetType(documentType);
} catch (Exception e) {
throw new ConfigurationErrorsException(string.Format("Error getting document type '{0}'", documentType), e);
throw new InvalidOperationException(string.Format("Error getting document type '{0}'", documentType), e);
}

if (type == null)
throw new ConfigurationErrorsException(string.Format("Error getting document type '{0}'", documentType));
throw new InvalidOperationException(string.Format("Error getting document type '{0}'", documentType));

return type;
}
}
}
}
23 changes: 23 additions & 0 deletions Unity.SolrNetIntegration/SolrServer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace Unity.SolrNetIntegration
{

public class SolrServer : ISolrServer
{
public SolrServer() { }

public SolrServer(string id, string url, string documentType)
{
this.Id = id;
this.Url = url;
this.DocumentType = documentType;
}

public string Id { get; set; }

public string Url { get; set; }

public string DocumentType { get; set; }

public override string ToString() => $"Id: {Id} Url: {Url} DocType: {DocumentType}";
}
}
14 changes: 10 additions & 4 deletions Unity.SolrNetIntegration/Unity.SolrNetIntegration.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net46</TargetFrameworks>
<TargetFrameworks>net46;netstandard2.0</TargetFrameworks>

<Version>1.0.6</Version>
<RepositoryUrl>https://github.com/solrnet/solrnet</RepositoryUrl>
<PackageLicenseUrl>https://raw.githubusercontent.com/SolrNet/SolrNet/master/license.txt</PackageLicenseUrl>
Expand All @@ -17,10 +18,15 @@
<ProjectReference Include="..\SolrNet\SolrNet.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="EnterpriseLibrary.Common" Version="6.0.1304.0" />
<PackageReference Include="Unity" Version="5.0.0" />
<!--<PackageReference Include="EnterpriseLibrary.Common" Version="6.0.1304.0" />-->
<PackageReference Include="Unity" Version="5.5.0" />
</ItemGroup>
<ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net46'">
<Reference Include="System.Configuration" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<Compile Remove="Config\SolrConfigurationSection.cs" />
<Compile Remove="Config\SolrServerElement.cs" />
<Compile Remove="Config\SolrServers.cs" />
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 1.0.6
- New: `AutoSolrConnection`, automatically uses `GET` or `POST` depending on uri length. Improved performance when using `async` methods.
- Add `netstandard 2.0` support to `Unity.SolrNetIntegration`

## 1.0.5
- SolrNet Cloud: add checks if Zookeeper connection is valid
Expand Down

0 comments on commit 62baf17

Please sign in to comment.