Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#984 single file publish works with Service connectors #1237

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/Common/src/Common/Reflection/ReflectionHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,13 @@ private static void TryLoadAssembliesWithAttribute<T>()
where T : AssemblyContainsTypeAttribute
{
var runtimeAssemblies = Directory.GetFiles(RuntimeEnvironment.GetRuntimeDirectory(), "*.dll");
using var loadContext = new MetadataLoadContext(new PathAssemblyResolver(AllRelevantPaths(runtimeAssemblies, typeof(T))));
var allKnownAssemblyPaths = AllRelevantPaths(runtimeAssemblies, typeof(T));
if (!allKnownAssemblyPaths.Any())
{
return;
}

using var loadContext = new MetadataLoadContext(new PathAssemblyResolver(allKnownAssemblyPaths));
var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies();
var assemblypaths = Directory.EnumerateFiles(AppDomain.CurrentDomain.BaseDirectory).Where(f => f.EndsWith("dll", StringComparison.InvariantCultureIgnoreCase));
foreach (var assembly in assemblypaths)
Expand Down Expand Up @@ -338,26 +344,20 @@ private static void TryLoadAssembliesWithAttribute<T>()
/// <returns>A list of paths to the runtime, assembly and requested assembly type</returns>
private static List<string> AllRelevantPaths(string[] runtimeAssemblies, Type attributeType)
{
var toReturn = new List<string>(runtimeAssemblies);
var executingAssemblyLocation = Assembly.GetExecutingAssembly().Location;
var typeAssemblyLocation = attributeType.Assembly.Location;
if (string.IsNullOrEmpty(executingAssemblyLocation) || string.IsNullOrEmpty(typeAssemblyLocation))
{
var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
if (baseDirectory.EndsWith("\\"))
{
baseDirectory = baseDirectory.Substring(0, baseDirectory.Length - 1);
}

toReturn.Add(baseDirectory);
Console.WriteLine("File path path information for the assembly containing {0} is missing. Some Steeltoe functionality may not work with PublishSingleFile=true", attributeType.Name);
return new List<string>();
}
else
{
toReturn.Add(executingAssemblyLocation);
toReturn.Add(attributeType.Assembly.Location);
return new List<string>(runtimeAssemblies)
{
executingAssemblyLocation,
attributeType.Assembly.Location
};
}

return toReturn;
}
}
2 changes: 1 addition & 1 deletion src/Connectors/src/CloudFoundry/CloudFoundryConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Steeltoe.Connector.CloudFoundry;
public static class CloudFoundryConnector
{
/// <summary>
/// Use this method to ensure Steeltoe.Connector.CloudFoundry is loaded
/// Use this method to prevent Steeltoe.Connector.CloudFoundry from being optimized out of the build
/// </summary>
public static void EnsureAssemblyIsLoaded()
{
Expand Down
8 changes: 8 additions & 0 deletions src/Discovery/src/Consul/Discovery/ConsulDiscoveryClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ internal ConsulDiscoveryOptions Options
}
}

/// <summary>
/// Use this method to prevent Steeltoe.Discovery.Consul from being optimized out of the build
/// </summary>
public static void EnsureAssemblyIsLoaded()
{
// no-op
}

/// <summary>
/// Initializes a new instance of the <see cref="ConsulDiscoveryClient"/> class.
/// </summary>
Expand Down
8 changes: 8 additions & 0 deletions src/Discovery/src/Eureka/EurekaDiscoveryClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ public EurekaHttpClientInternal(IOptionsMonitor<EurekaClientOptions> config, ILo
private readonly IOptionsMonitor<EurekaClientOptions> _configOptions;
private readonly IServiceInstance _thisInstance;

/// <summary>
/// Use this method to prevent Steeltoe.Discovery.Eureka from being optimized out of the build
/// </summary>
public static void EnsureAssemblyIsLoaded()
{
// no-op
}

public override IEurekaClientConfig ClientConfig => _configOptions.CurrentValue;

public EurekaDiscoveryClient(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ public class KubernetesDiscoveryClient : IDiscoveryClient
private readonly IOptionsMonitor<KubernetesDiscoveryOptions> _discoveryOptions;
private readonly DefaultIsServicePortSecureResolver _isServicePortSecureResolver;

/// <summary>
/// Use this method to prevent Steeltoe.Discovery.Kubernetes from being optimized out of the build
/// </summary>
public static void EnsureAssemblyIsLoaded()
{
// no-op
}

public string Description => "Steeltoe provided Kubernetes native service discovery client";

public IList<string> Services => GetServices(null);
Expand Down
Loading