Skip to content

Commit

Permalink
Rename Discovery Client/Extension Packages as they're no longer the b…
Browse files Browse the repository at this point in the history
…ase (#393)

- Rename Discovery Client/Extension Packages as they're no longer the base
- split DiscoveryClientCore into two packages to isolate ASP.NET code
  • Loading branch information
TimHess authored Aug 6, 2020
1 parent 3e44c16 commit 5dd60d0
Show file tree
Hide file tree
Showing 174 changed files with 368 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal class ConfigServerDiscoveryService
protected internal ILoggerFactory _logFactory;
protected internal ILogger _logger;

private static readonly string[] _discoveryServiceAssemblies = new string[] { "Steeltoe.Discovery.EurekaBase" };
private static readonly string[] _discoveryServiceAssemblies = new string[] { "Steeltoe.Discovery.Eureka" };
private static readonly string[] _discoveryServiceTypeNames = new string[] { "Steeltoe.Discovery.Eureka.EurekaClientService" };

internal ConfigServerDiscoveryService(IConfiguration configuration, ConfigServerClientSettings settings, ILoggerFactory logFactory = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<ItemGroup>
<ProjectReference Include="..\..\..\Common\src\Common.Security\Steeltoe.Common.Security.csproj" />
<ProjectReference Include="..\..\..\Discovery\src\EurekaBase\Steeltoe.Discovery.EurekaBase.csproj" />
<ProjectReference Include="..\..\..\Discovery\src\Eureka\Steeltoe.Discovery.Eureka.csproj" />
<ProjectReference Include="..\..\src\ConfigServerBase\Steeltoe.Extensions.Configuration.ConfigServerBase.csproj" />
<ProjectReference Include="..\..\src\PlaceholderBase\Steeltoe.Extensions.Configuration.PlaceholderBase.csproj" />
</ItemGroup>
Expand Down
42 changes: 36 additions & 6 deletions src/Discovery/Discovery.sln
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Steeltoe.Discovery.ClientCo
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Steeltoe.Discovery.ClientCore.Test", "test\ClientCore.Test\Steeltoe.Discovery.ClientCore.Test.csproj", "{ECC9CBE1-67CC-42CB-995C-BCC313C98D29}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Steeltoe.Discovery.EurekaBase", "src\EurekaBase\Steeltoe.Discovery.EurekaBase.csproj", "{096E523C-1D78-4EA8-906A-D9091917AE62}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Steeltoe.Discovery.Eureka", "src\Eureka\Steeltoe.Discovery.Eureka.csproj", "{096E523C-1D78-4EA8-906A-D9091917AE62}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Steeltoe.Discovery.EurekaBase.Test", "test\EurekaBase.Test\Steeltoe.Discovery.EurekaBase.Test.csproj", "{0AEC0A63-75CB-45C4-9CC7-9E0340EF851E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Steeltoe.Discovery.Eureka.Test", "test\Eureka.Test\Steeltoe.Discovery.Eureka.Test.csproj", "{0AEC0A63-75CB-45C4-9CC7-9E0340EF851E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Steeltoe.Discovery.ConsulBase", "src\ConsulBase\Steeltoe.Discovery.ConsulBase.csproj", "{3448F914-3C5C-442D-95F9-0B3D627B8CB4}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Steeltoe.Discovery.Consul", "src\Consul\Steeltoe.Discovery.Consul.csproj", "{3448F914-3C5C-442D-95F9-0B3D627B8CB4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Steeltoe.Discovery.ConsulBase.Test", "test\ConsulBase.Test\Steeltoe.Discovery.ConsulBase.Test.csproj", "{22449AEF-D579-40D1-B7FC-6871DFCD635B}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Steeltoe.Discovery.Consul.Test", "test\Consul.Test\Steeltoe.Discovery.Consul.Test.csproj", "{22449AEF-D579-40D1-B7FC-6871DFCD635B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "dependencies", "dependencies", "{26A62999-E553-40B7-B393-2195557F6D8B}"
EndProject
Expand All @@ -57,12 +57,16 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Steeltoe.Common.Net", "..\C
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Steeltoe.Common.Security", "..\Common\src\Common.Security\Steeltoe.Common.Security.csproj", "{A90F4766-BDBE-4509-9C6D-F362A8ADD770}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Steeltoe.Discovery.KubernetesBase", "src\KubernetesBase\Steeltoe.Discovery.KubernetesBase.csproj", "{A27FBAC2-73B1-41A8-AC29-AAFE2DDAFE6F}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Steeltoe.Discovery.Kubernetes", "src\Kubernetes\Steeltoe.Discovery.Kubernetes.csproj", "{A27FBAC2-73B1-41A8-AC29-AAFE2DDAFE6F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Steeltoe.Discovery.KubernetesBase.Test", "test\KubernetesBase.Test\Steeltoe.Discovery.KubernetesBase.Test.csproj", "{6911713F-9BE5-4EAE-B959-9EB273049738}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Steeltoe.Discovery.Kubernetes.Test", "test\Kubernetes.Test\Steeltoe.Discovery.Kubernetes.Test.csproj", "{6911713F-9BE5-4EAE-B959-9EB273049738}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Steeltoe.Common.Kubernetes", "..\Common\src\Common.Kubernetes\Steeltoe.Common.Kubernetes.csproj", "{181EB169-96B0-4291-911E-E4FD372A0760}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Steeltoe.Discovery.ClientBase", "src\ClientBase\Steeltoe.Discovery.ClientBase.csproj", "{15242715-2B64-44F4-936C-D0954CF5E8C4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Steeltoe.Discovery.ClientBase.Test", "test\ClientBase.Test\Steeltoe.Discovery.ClientBase.Test.csproj", "{EB232992-9F47-48EA-9776-EC7DD94ECC09}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -313,6 +317,30 @@ Global
{181EB169-96B0-4291-911E-E4FD372A0760}.Release|x64.Build.0 = Release|Any CPU
{181EB169-96B0-4291-911E-E4FD372A0760}.Release|x86.ActiveCfg = Release|Any CPU
{181EB169-96B0-4291-911E-E4FD372A0760}.Release|x86.Build.0 = Release|Any CPU
{15242715-2B64-44F4-936C-D0954CF5E8C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{15242715-2B64-44F4-936C-D0954CF5E8C4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{15242715-2B64-44F4-936C-D0954CF5E8C4}.Debug|x64.ActiveCfg = Debug|Any CPU
{15242715-2B64-44F4-936C-D0954CF5E8C4}.Debug|x64.Build.0 = Debug|Any CPU
{15242715-2B64-44F4-936C-D0954CF5E8C4}.Debug|x86.ActiveCfg = Debug|Any CPU
{15242715-2B64-44F4-936C-D0954CF5E8C4}.Debug|x86.Build.0 = Debug|Any CPU
{15242715-2B64-44F4-936C-D0954CF5E8C4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{15242715-2B64-44F4-936C-D0954CF5E8C4}.Release|Any CPU.Build.0 = Release|Any CPU
{15242715-2B64-44F4-936C-D0954CF5E8C4}.Release|x64.ActiveCfg = Release|Any CPU
{15242715-2B64-44F4-936C-D0954CF5E8C4}.Release|x64.Build.0 = Release|Any CPU
{15242715-2B64-44F4-936C-D0954CF5E8C4}.Release|x86.ActiveCfg = Release|Any CPU
{15242715-2B64-44F4-936C-D0954CF5E8C4}.Release|x86.Build.0 = Release|Any CPU
{EB232992-9F47-48EA-9776-EC7DD94ECC09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EB232992-9F47-48EA-9776-EC7DD94ECC09}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EB232992-9F47-48EA-9776-EC7DD94ECC09}.Debug|x64.ActiveCfg = Debug|Any CPU
{EB232992-9F47-48EA-9776-EC7DD94ECC09}.Debug|x64.Build.0 = Debug|Any CPU
{EB232992-9F47-48EA-9776-EC7DD94ECC09}.Debug|x86.ActiveCfg = Debug|Any CPU
{EB232992-9F47-48EA-9776-EC7DD94ECC09}.Debug|x86.Build.0 = Debug|Any CPU
{EB232992-9F47-48EA-9776-EC7DD94ECC09}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EB232992-9F47-48EA-9776-EC7DD94ECC09}.Release|Any CPU.Build.0 = Release|Any CPU
{EB232992-9F47-48EA-9776-EC7DD94ECC09}.Release|x64.ActiveCfg = Release|Any CPU
{EB232992-9F47-48EA-9776-EC7DD94ECC09}.Release|x64.Build.0 = Release|Any CPU
{EB232992-9F47-48EA-9776-EC7DD94ECC09}.Release|x86.ActiveCfg = Release|Any CPU
{EB232992-9F47-48EA-9776-EC7DD94ECC09}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -338,6 +366,8 @@ Global
{A27FBAC2-73B1-41A8-AC29-AAFE2DDAFE6F} = {A0CD0464-8E5B-42DD-8464-13FC8E6F35FF}
{6911713F-9BE5-4EAE-B959-9EB273049738} = {482BD4E0-A909-403B-B83A-D1D6377E0022}
{181EB169-96B0-4291-911E-E4FD372A0760} = {26A62999-E553-40B7-B393-2195557F6D8B}
{15242715-2B64-44F4-936C-D0954CF5E8C4} = {A0CD0464-8E5B-42DD-8464-13FC8E6F35FF}
{EB232992-9F47-48EA-9776-EC7DD94ECC09} = {482BD4E0-A909-403B-B83A-D1D6377E0022}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {09301AE1-862F-43FC-9E71-732151D4CDDF}
Expand Down
30 changes: 30 additions & 0 deletions src/Discovery/src/ClientBase/DiscoveryClientService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.

using Microsoft.Extensions.Hosting;
using System.Threading;
using System.Threading.Tasks;

namespace Steeltoe.Discovery.Client
{
internal class DiscoveryClientService : IHostedService
{
private readonly IDiscoveryLifecycle _applicationLifetime;

internal DiscoveryClientService(IDiscoveryLifecycle applicationLifetime)
{
_applicationLifetime = applicationLifetime;
}

public Task StartAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}

public Task StopAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
}
}
35 changes: 35 additions & 0 deletions src/Discovery/src/ClientBase/DiscoveryHostBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Steeltoe.Connector;
using System;
using System.Reflection;

namespace Steeltoe.Discovery.Client
{
public static class DiscoveryHostBuilderExtensions
{
/// <summary>
/// Adds service discovery to your application. This method can be used in place of configuration via your Startup class.<para />
/// If <paramref name="optionsAction"/> is not provided, a <see cref="NoOpDiscoveryClient"/> will be configured
/// </summary>
/// <param name="hostBuilder">Your HostBuilder</param>
/// <param name="optionsAction">Select the discovery client implementation</param>
/// <remarks>Also configures named HttpClients "DiscoveryRandom" and "DiscoveryRoundRobin" for automatic injection</remarks>
/// <exception cref="AmbiguousMatchException">Thrown if multiple IDiscoveryClient implementations are configured</exception>
/// <exception cref="ConnectorException">Thrown if no service info with expected name or type are found or when multiple service infos are found and a single was expected</exception>
public static IHostBuilder AddServiceDiscovery(this IHostBuilder hostBuilder, Action<DiscoveryClientBuilder> optionsAction)
{
return hostBuilder.ConfigureServices((context, collection) => AddServices(collection, optionsAction));
}

private static void AddServices(IServiceCollection collection, Action<DiscoveryClientBuilder> optionsAction)
{
collection.AddServiceDiscovery(optionsAction);
collection.AddHostedService(services => new DiscoveryClientService(services.GetRequiredService<IDiscoveryLifecycle>()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,37 @@ namespace Steeltoe.Discovery.Client
{
public static class DiscoveryServiceCollectionExtensions
{
/// <summary>
/// Adds service discovery to your application. Uses reflection to determine which clients are available and configured.
/// If no clients are available or configured, a <see cref="NoOpDiscoveryClient"/> will be configured
/// </summary>
/// <param name="services"><see cref="IServiceCollection"/> to configure</param>
/// <param name="config">Application configuration</param>
public static IServiceCollection AddDiscoveryClient(this IServiceCollection services, IConfiguration config = null)
{
return services.AddDiscoveryClient(config, null);
}

/// <summary>
/// Adds service discovery to your application. Uses reflection to determine which clients are available and configured.
/// If no clients are available or configured, a <see cref="NoOpDiscoveryClient"/> will be configured
/// </summary>
/// <param name="services"><see cref="IServiceCollection"/> to configure</param>
/// <param name="config">Application configuration</param>
/// <param name="lifecycle">Add custom code for app shutdown events</param>
public static IServiceCollection AddDiscoveryClient(this IServiceCollection services, IConfiguration config, IDiscoveryLifecycle lifecycle = null)
{
return services.AddDiscoveryClient(config, null, lifecycle);
}

/// <summary>
/// Adds service discovery to your application. Uses reflection to determine which clients are available and configured.
/// If no clients are available or configured, a <see cref="NoOpDiscoveryClient"/> will be configured
/// </summary>
/// <param name="services"><see cref="IServiceCollection"/> to configure</param>
/// <param name="config">Application configuration</param>
/// <param name="serviceName">Specify the name of a service binding to use</param>
/// <param name="lifecycle">Add custom code for app shutdown events</param>
public static IServiceCollection AddDiscoveryClient(this IServiceCollection services, IConfiguration config, string serviceName = null, IDiscoveryLifecycle lifecycle = null)
{
Action<DiscoveryClientBuilder> builderAction = null;
Expand Down Expand Up @@ -180,7 +201,10 @@ public ApplicationLifecycle(IHostApplicationLifetime lifeCycle, IDiscoveryClient
ApplicationStopping = lifeCycle.ApplicationStopping;

// hook things up so that that things are unregistered when the application terminates
ApplicationStopping.Register(() => { client.ShutdownAsync().GetAwaiter().GetResult(); });
ApplicationStopping.Register(() =>
{
client.ShutdownAsync().GetAwaiter().GetResult();
});
}

public CancellationToken ApplicationStopping { get; set; }
Expand Down
7 changes: 7 additions & 0 deletions src/Discovery/src/ClientBase/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.

using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Steeltoe.Discovery.ClientBase.Test")]
25 changes: 25 additions & 0 deletions src/Discovery/src/ClientBase/Steeltoe.Discovery.ClientBase.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<Description>Base package for using Steeltoe Service Discovery</Description>
<PackageTags>service discovery;service registry;Spring Cloud;eureka;consul;kubernetes</PackageTags>
<RootNamespace>Steeltoe.Discovery.Client</RootNamespace>
</PropertyGroup>

<Import Project="..\..\..\..\versions.props" />
<Import Project="..\..\..\..\sharedproject.props" />

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="$(ExtensionsVersion)" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="$(ExtensionsVersion)" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Common\src\Common.Http\Steeltoe.Common.Http.csproj" />
<ProjectReference Include="..\..\..\Connectors\src\ConnectorBase\Steeltoe.Connector.ConnectorBase.csproj" />
<ProjectReference Include="..\Abstractions\Steeltoe.Discovery.Abstractions.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,23 @@

namespace Steeltoe.Discovery.Client
{
public static class DiscoveryHostBuilderExtensions
public static class DiscoveryWebHostBuilderExtensions
{
/// <summary>
/// Adds service discovery to your application. This method can be used in place of configuration via your Startup class.<para />
/// If <paramref name="optionsAction"/> is not provided, a <see cref="NoOpDiscoveryClient"/> will be configured
/// If is no discovery client package reference is used, a <see cref="NoOpDiscoveryClient"/> will be configured
/// </summary>
/// <param name="hostBuilder">Your HostBuilder</param>
/// <param name="optionsAction">Select the discovery client implementation</param>
/// <remarks>Also configures named HttpClients "DiscoveryRandom" and "DiscoveryRoundRobin" for automatic injection</remarks>
/// <exception cref="AmbiguousMatchException">Thrown if multiple IDiscoveryClient implementations are configured</exception>
/// <exception cref="ConnectorException">Thrown if no service info with expected name or type are found or when multiple service infos are found and a single was expected</exception>
public static IWebHostBuilder AddServiceDiscovery(this IWebHostBuilder hostBuilder, Action<DiscoveryClientBuilder> optionsAction)
public static IWebHostBuilder AddDiscoveryClient(this IWebHostBuilder hostBuilder)
{
return hostBuilder.ConfigureServices((context, collection) => AddServices(collection, optionsAction));
return hostBuilder
.ConfigureServices((context, collection) =>
collection
.AddDiscoveryClient()
.AddTransient<IStartupFilter, DiscoveryClientStartupFilter>());
}

/// <summary>
Expand All @@ -36,15 +39,13 @@ public static IWebHostBuilder AddServiceDiscovery(this IWebHostBuilder hostBuild
/// <remarks>Also configures named HttpClients "DiscoveryRandom" and "DiscoveryRoundRobin" for automatic injection</remarks>
/// <exception cref="AmbiguousMatchException">Thrown if multiple IDiscoveryClient implementations are configured</exception>
/// <exception cref="ConnectorException">Thrown if no service info with expected name or type are found or when multiple service infos are found and a single was expected</exception>
public static IHostBuilder AddServiceDiscovery(this IHostBuilder hostBuilder, Action<DiscoveryClientBuilder> optionsAction)
{
return hostBuilder.ConfigureServices((context, collection) => AddServices(collection, optionsAction));
}

private static void AddServices(IServiceCollection collection, Action<DiscoveryClientBuilder> optionsAction)
public static IWebHostBuilder AddServiceDiscovery(this IWebHostBuilder hostBuilder, Action<DiscoveryClientBuilder> optionsAction)
{
collection.AddServiceDiscovery(optionsAction);
collection.AddTransient<IStartupFilter, DiscoveryClientStartupFilter>();
return hostBuilder
.ConfigureServices((context, collection) =>
collection
.AddServiceDiscovery(optionsAction)
.AddTransient<IStartupFilter, DiscoveryClientStartupFilter>());
}
}
}
1 change: 0 additions & 1 deletion src/Discovery/src/ClientCore/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Steeltoe.Discovery.ClientCore.Test")]
[assembly: InternalsVisibleTo("Pivotal.Discovery.ClientCore.Test")]
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Common\src\Common.Http\Steeltoe.Common.Http.csproj" />
<ProjectReference Include="..\..\..\Connectors\src\ConnectorBase\Steeltoe.Connector.ConnectorBase.csproj" />
<ProjectReference Include="..\Abstractions\Steeltoe.Discovery.Abstractions.csproj" />
<ProjectReference Include="..\ClientBase\Steeltoe.Discovery.ClientBase.csproj" />
</ItemGroup>
</Project>
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Steeltoe.Discovery.ConsulBase.Test")]
[assembly: InternalsVisibleTo("Steeltoe.Discovery.Consul.Test")]
[assembly: InternalsVisibleTo("Steeltoe.Discovery.ClientCore.Test")]
Loading

0 comments on commit 5dd60d0

Please sign in to comment.