Skip to content

Commit

Permalink
Merge pull request #772 from dolittle/deps
Browse files Browse the repository at this point in the history
Maintenance release, upgrade dependencies
  • Loading branch information
mhelleborg authored Aug 20, 2024
2 parents 3bfcef5 + b98baff commit 26c4807
Show file tree
Hide file tree
Showing 14 changed files with 242 additions and 36 deletions.
2 changes: 1 addition & 1 deletion Integration/Benchmarks/Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.1" />
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
</ItemGroup>
</Project>
190 changes: 190 additions & 0 deletions Source/DependencyInversion/AssemblyFinder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Loader;

namespace Dolittle.Runtime.DependencyInversion;

/// <summary>
/// Utility to discover and load assemblies installed in your application
/// </summary>
static class AssemblyFinder
{
static readonly AssemblyLoadContextWrapper _loader = new(AssemblyLoadContext.Default);

/// <summary>
/// Find assemblies in the application's binary path
/// </summary>
/// <param name="logFailure">Take an action when an assembly file could not be loaded</param>
/// <param name="includeExeFiles">Optionally include *.exe files</param>
/// <returns></returns>
public static IEnumerable<Assembly> FindAssemblies(Action<string> logFailure, Func<AssemblyName, bool> filter,
bool includeExeFiles)
{
string path;
try
{
path = AppContext.BaseDirectory;
}
catch (Exception)
{
path = Directory.GetCurrentDirectory();
}

return FindAssemblies(filter, path, logFailure, includeExeFiles);
}

/// <summary>
/// Find assemblies in the given path
/// </summary>
/// <param name="assemblyPath">The path to probe for assembly files</param>
/// <param name="logFailure">Take an action when an assembly file could not be loaded</param>
/// <param name="includeExeFiles">Optionally include *.exe files</param>
/// <returns></returns>
public static IEnumerable<Assembly> FindAssemblies(Func<AssemblyName, bool> filter, string assemblyPath,
Action<string> logFailure, bool includeExeFiles)
{
var assemblies = FindAssemblies(assemblyPath, filter, logFailure, includeExeFiles)
.OrderBy(x => x.GetName().Name)
.ToArray();

return assemblies.TopologicalSort((Func<Assembly, Assembly[]>)FindDependencies, throwOnCycle: false);

Assembly[] FindDependencies(Assembly a) => assemblies
.Where(x => a.GetReferencedAssemblies().Any(_ => _.Name == x.GetName().Name)).ToArray();
}

static IEnumerable<Assembly> FindAssemblies(string assemblyPath, Func<AssemblyName, bool> filter,
Action<string> logFailure,
bool includeExeFiles)
{
var dllFiles = Directory.EnumerateFiles(assemblyPath, "*.dll", SearchOption.AllDirectories);
var files = dllFiles;

if (includeExeFiles)
{
var exeFiles = Directory.EnumerateFiles(assemblyPath, "*.exe", SearchOption.AllDirectories);
files = dllFiles.Concat(exeFiles);
}

foreach (var file in files)
{
var name = Path.GetFileNameWithoutExtension(file);
Assembly? assembly = null;
var assemblyName = new AssemblyName(name);
if (!filter(assemblyName))
{
continue;
}

try
{
assembly = _loader.LoadFromAssemblyName(assemblyName);
}
catch
{
try
{
assembly = _loader.LoadFromAssemblyPath(file);
}
catch
{
logFailure(file);
}
}

if (assembly != null)
{
yield return assembly;
}
}
}


/// <summary>
/// Find assembly files matching a given filter
/// </summary>
/// <param name="filter"></param>
/// <param name="includeExeFiles"></param>
/// <returns></returns>
public static IEnumerable<Assembly> FindAssemblies(Func<AssemblyName, bool> filter, bool includeExeFiles = false)
{
filter ??= a => true;

return FindAssemblies(file => { }, filter, includeExeFiles: includeExeFiles);
}
}


sealed class AssemblyLoadContextWrapper
{
readonly AssemblyLoadContext _ctx;

public AssemblyLoadContextWrapper(AssemblyLoadContext ctx)
{
_ctx = ctx;
}

public Assembly LoadFromStream(Stream assembly)
{
return _ctx.LoadFromStream(assembly);
}

public Assembly LoadFromAssemblyName(AssemblyName assemblyName)
{
return _ctx.LoadFromAssemblyName(assemblyName);
}

public Assembly LoadFromAssemblyPath(string assemblyName)
{
return _ctx.LoadFromAssemblyPath(assemblyName);
}
}

static class TopologicalSortExtensions
{
/// <summary>
/// Performs a topological sort on the enumeration based on dependencies
/// </summary>
/// <param name="source"></param>
/// <param name="dependencies"></param>
/// <param name="throwOnCycle"></param>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static IEnumerable<T> TopologicalSort<T>(this IEnumerable<T> source, Func<T, IEnumerable<T>> dependencies,
bool throwOnCycle = true)
{
var sorted = new List<T>();
var visited = new HashSet<T>();

foreach (var item in source)
{
Visit(item, visited, sorted, dependencies, throwOnCycle);
}

return sorted;
}

static void Visit<T>(T item, ISet<T> visited, ICollection<T> sorted, Func<T, IEnumerable<T>> dependencies,
bool throwOnCycle)
{
if (!visited.Add(item))
{
if (throwOnCycle && !sorted.Contains(item))
{
throw new Exception("Cyclic dependency found");
}
}
else
{
foreach (var dep in dependencies(item))
{
Visit(dep, visited, sorted, dependencies, throwOnCycle);
}

sorted.Add(item);
}
}
}
1 change: 0 additions & 1 deletion Source/DependencyInversion/DependencyInversion.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<ItemGroup>
<PackageReference Include="Autofac" Version="$(AutofacVersion)" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="$(AutofacExtensionsVersion)" />
<PackageReference Include="BaselineTypeDiscovery" Version="$(BaselineTypeDiscoveryVersion)" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="$(MicrosoftExtensionsVersion)" />
<PackageReference Include="Microsoft.Extensions.Options" Version="$(MicrosoftExtensionsVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(MicrosoftExtensionsVersion)" />
Expand Down
1 change: 0 additions & 1 deletion Source/DependencyInversion/Types/TypeScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using BaselineTypeDiscovery;
using Dolittle.Runtime.DependencyInversion.Lifecycle;
using Dolittle.Runtime.DependencyInversion.Scoping;

Expand Down
12 changes: 6 additions & 6 deletions Source/Diagnostics/Diagnostics.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
<PackageReference Include="Microsoft.Extensions.Logging" Version="$(MicrosoftExtensionsVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="$(MicrosoftExtensionsVersion)" />
<PackageReference Include="MongoDB.Driver" Version="$(MongoDBDriverVersion)" />
<PackageReference Include="MongoDB.Driver.Core.Extensions.OpenTelemetry" Version="$(MongoDBOpenTelemetryVersion)" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.8.1" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.8.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.8.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.GrpcNetClient" Version="1.8.0-beta.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.8.1" />
<PackageReference Include="MongoDB.Driver.Core.Extensions.DiagnosticSources" Version="$(MongoDBDiagnosticSourcesVersion)" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.GrpcNetClient" Version="1.9.0-beta.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.9.0" />
<PackageReference Include="Proto.OpenTelemetry" Version="$(ProtoActorVersion)" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ static void AddOpenTelemetryTracing(this IHostBuilder builder, ResourceBuilder r
.AddSource(RuntimeActivity.SourceName)
.AddHttpClientInstrumentation()
.AddAspNetCoreInstrumentation()
.AddMongoDBInstrumentation()
.AddSource("MongoDB.Driver.Core.Extensions.DiagnosticSources")
.AddGrpcClientInstrumentation()
.AddProtoActorInstrumentation()
.AddOtlpExporter(options => { options.Endpoint = otlpEndpoint; });
Expand Down
2 changes: 1 addition & 1 deletion Source/Events.Store.MongoDB/Events.Store.MongoDB.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<ItemGroup>
<PackageReference Include="Dolittle.Contracts" Version="$(ContractsVersion)" />
<PackageReference Include="MongoDB.Driver" Version="$(MongoDBDriverVersion)" />
<PackageReference Include="MongoDB.Driver.Core.Extensions.OpenTelemetry" Version="$(MongoDBOpenTelemetryVersion)" />
<PackageReference Include="MongoDB.Driver.Core.Extensions.DiagnosticSources" Version="$(MongoDBDiagnosticSourcesVersion)" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Source/Events/Events.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


<ItemGroup>
<PackageReference Include="OpenTelemetry.Api" Version="1.8.1" />
<PackageReference Include="OpenTelemetry.Api" Version="1.9.0" />
<PackageReference Include="Polly" Version="$(PollyVersion)" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="$(MicrosoftExtensionsVersion)" />
<PackageReference Include="Dolittle.Contracts" Version="$(ContractsVersion)" />
Expand Down
2 changes: 1 addition & 1 deletion Source/MongoDB/MongoDB.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

<ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="$(MongoDBDriverVersion)" />
<PackageReference Include="MongoDB.Driver.Core.Extensions.OpenTelemetry" Version="$(MongoDBOpenTelemetryVersion)" />
<PackageReference Include="MongoDB.Driver.Core.Extensions.DiagnosticSources" Version="$(MongoDBDiagnosticSourcesVersion)" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions Source/Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ static void VerifyConfiguration(IServiceProvider provider)
var config = provider.GetRequiredService<IOptions<TenantsConfiguration>>();
if (!config.Value.Any())
{
logger.LogWarning("No tenants are configured in the Runtime. Without any tenants the Runtime will not function properly.");
logger.LogWarning("No tenants are configured in the Runtime. Without any tenants the Runtime will not function properly");
}
}
catch (Exception e)
{
logger.LogError(e, "It seems like the Runtime is missing its 'tenants' configuration. Without any tenants the Runtime will no function properly.");
logger.LogError(e, "It seems like the Runtime is missing its 'tenants' configuration. Without any tenants the Runtime will no function properly");
throw;
}
}
18 changes: 18 additions & 0 deletions Source/Server/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
{
"dolittle": {
"runtime": {
"endpoints": {
"public": {
"port": 50052
},
"private": {
"port": 50053
},
"management": {
"port": 51052
},
"managementweb": {
"port": 51152
}
}
}
},
"Logging": {
"LogLevel": {
"Default": "Information",
Expand Down
2 changes: 1 addition & 1 deletion specs.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="$(CoverletVersion)" />
<PackageReference Include="Machine.Specifications" Version="1.0.0" />
<PackageReference Include="Machine.Specifications" Version="1.1.2" />
<PackageReference Include="Machine.Specifications.Should" Version="1.0.0" />
<PackageReference Include="FluentAssertions" Version="$(FluentAssertionsVersion)" />
<PackageReference Include="moq" Version="$(MoqVersion)" />
Expand Down
2 changes: 1 addition & 1 deletion tests.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<PackageReference Include="xunit" Version="$(XUnitVersion)"/>
<PackageReference Include="Grpc.Core.Testing" Version="$(GrpcTestingVersion)"/>
<PackageReference Include="Microsoft.Extensions.Logging" Version="$(MicrosoftExtensionsVersion)"/>
<PackageReference Include="xunit.runner.visualstudio" Version="$(XUnitVersion)">
<PackageReference Include="xunit.runner.visualstudio" Version="$(XUnitRunnerVersion)">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
38 changes: 19 additions & 19 deletions versions.props
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
<Project>
<PropertyGroup>
<AutofacVersion>6.3.0</AutofacVersion>
<AutofacExtensionsVersion>7.2.0</AutofacExtensionsVersion>
<BaselineTypeDiscoveryVersion>1.1.2</BaselineTypeDiscoveryVersion>
<ConsoleTablesVersion>2.4.2</ConsoleTablesVersion>
<AutofacVersion>8.0.0</AutofacVersion>
<AutofacExtensionsVersion>9.0.0</AutofacExtensionsVersion>
<ConsoleTablesVersion>2.6.1</ConsoleTablesVersion>
<ContractsVersion>7.8.0</ContractsVersion>
<CoverletVersion>3.1.0</CoverletVersion>
<CoverletVersion>6.0.2</CoverletVersion>
<DolittleCommonSpecsVersion>2.*</DolittleCommonSpecsVersion>
<GrpcVersion>2.63.0</GrpcVersion>
<GrpcVersion>2.65.0</GrpcVersion>
<GrpcTestingVersion>2.46.6</GrpcTestingVersion>
<GrpcToolsVersion>2.64.0</GrpcToolsVersion>
<GrpcToolsVersion>2.65.0</GrpcToolsVersion>
<MachineSpecificationsRunnerVersion>2.10.2</MachineSpecificationsRunnerVersion>
<MachineSpecificationsVersion>1.0.0</MachineSpecificationsVersion>
<MicrosoftDotNetTestVersion>17.9.0</MicrosoftDotNetTestVersion>
<MachineSpecificationsVersion>1.1.2</MachineSpecificationsVersion>
<MicrosoftDotNetTestVersion>17.10.0</MicrosoftDotNetTestVersion>
<MicrosoftExtensionsVersion>8.0.0</MicrosoftExtensionsVersion>
<MongoDBDriverVersion>2.25.0</MongoDBDriverVersion>
<MongoDBOpenTelemetryVersion>1.0.0</MongoDBOpenTelemetryVersion>
<MongoDBDriverVersion>2.28.0</MongoDBDriverVersion>
<MongoDBDiagnosticSourcesVersion>1.5.0</MongoDBDiagnosticSourcesVersion>
<MoqVersion>4.18.*</MoqVersion>
<FluentAssertionsVersion>6.12.0</FluentAssertionsVersion>
<NetEscapadesYaml>2.2.0</NetEscapadesYaml>
<NewtonsoftVersion>13.0.3</NewtonsoftVersion>
<NitoAsyncVersion>5.1.0</NitoAsyncVersion>
<PollyVersion>7.2.3</PollyVersion>
<PrometheusVersion>6.0.0</PrometheusVersion>
<PrometheusNetDotNetRuntimeVersion>4.2.4</PrometheusNetDotNetRuntimeVersion>
<NitoAsyncVersion>5.1.2</NitoAsyncVersion>
<PollyVersion>8.4.1</PollyVersion>
<PrometheusVersion>8.2.1</PrometheusVersion>
<PrometheusNetDotNetRuntimeVersion>4.4.0</PrometheusNetDotNetRuntimeVersion>
<ProtoActorVersion>1.6.0</ProtoActorVersion>
<ProtobufVersion>3.26.1</ProtobufVersion>
<SwashbuckleVersion>6.5.0</SwashbuckleVersion>
<SystemLinqAsyncVersion>5.1.0</SystemLinqAsyncVersion>
<ProtobufVersion>3.27.3</ProtobufVersion>
<SwashbuckleVersion>6.7.1</SwashbuckleVersion>
<SystemLinqAsyncVersion>6.0.1</SystemLinqAsyncVersion>
<SystemSecurityVersion>4.3.0</SystemSecurityVersion>
<XUnitVersion>2.5.3</XUnitVersion>
<XUnitVersion>2.9.0</XUnitVersion>
<XUnitRunnerVersion>2.8.2</XUnitRunnerVersion>
</PropertyGroup>
</Project>

0 comments on commit 26c4807

Please sign in to comment.