Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
warning-explosive committed Jul 19, 2023
1 parent 6d28836 commit 53ab1ee
Show file tree
Hide file tree
Showing 47 changed files with 628 additions and 397 deletions.
2 changes: 2 additions & 0 deletions Benchmarks/GenericHost.Benchmark/GenericHost.Benchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
<ProjectReference Include="..\..\Endpoints\GenericEndpoint.Authorization.Host\GenericEndpoint.Authorization.Host.csproj" />
<ProjectReference Include="..\..\Endpoints\GenericEndpoint.DataAccess.Sql.Host\GenericEndpoint.DataAccess.Sql.Host.csproj" />
<ProjectReference Include="..\..\Endpoints\GenericEndpoint.EventSourcing.Host\GenericEndpoint.EventSourcing.Host.csproj" />
<ProjectReference Include="..\..\Endpoints\GenericEndpoint.Telemetry.Host\GenericEndpoint.Telemetry.Host.csproj" />
<ProjectReference Include="..\..\Endpoints\GenericEndpoint.Telemetry\GenericEndpoint.Telemetry.csproj" />
<ProjectReference Include="..\..\Endpoints\IntegrationTransport.Host\IntegrationTransport.Host.csproj" />
<ProjectReference Include="..\..\Tests\Test.Api\Test.Api.csproj" />
<ProjectReference Include="..\Benchmark.Api\Benchmark.Api.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@ public void GlobalSetup()
.Concat(startupActions)
.ToArray();

var endpointIdentity = new EndpointIdentity(
nameof(DatabaseConnectionProviderBenchmarkSource),
Assembly.GetEntryAssembly() ?? throw new InvalidOperationException("Unable to get entry assembly"));

_host = hostBuilder
.UseIntegrationTransport((_, builder) => builder
.WithInMemoryIntegrationTransport(hostBuilder)
.WithInMemoryIntegrationTransport()
.BuildOptions())
.UseEndpoint(
new EndpointIdentity(nameof(DatabaseConnectionProviderBenchmarkSource)),
Assembly.GetEntryAssembly() !,
.UseEndpoint(endpointIdentity,
(_, builder) => builder
.WithPostgreSqlDataAccess(options => options
.ExecuteMigrations())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ namespace SpaceEngineers.Core.GenericHost.Benchmark.Sources
using GenericEndpoint.Authorization.Host;
using GenericEndpoint.Contract;
using GenericEndpoint.DataAccess.Sql.Host;
using GenericEndpoint.EventSourcing;
using GenericEndpoint.EventSourcing.Host;
using GenericEndpoint.Host;
using GenericEndpoint.Messaging;
using GenericEndpoint.Messaging.MessageHeaders;
using GenericEndpoint.Pipeline;
using GenericEndpoint.Telemetry;
using GenericEndpoint.Telemetry.Host;
using IntegrationTransport.Host;
using IntegrationTransport.RabbitMQ;
using JwtAuthentication;
Expand Down Expand Up @@ -56,8 +57,6 @@ public void GlobalSetup()
{
_cts = new CancellationTokenSource(TimeSpan.FromMinutes(5));

var hostBuilder = new TestFixture().CreateHostBuilder();

var solutionFileDirectory = SolutionExtensions.SolutionFile().Directory
?? throw new InvalidOperationException("Solution directory wasn't found");

Expand All @@ -67,19 +66,25 @@ public void GlobalSetup()
.StepInto("Settings")
.StepInto(nameof(MessageHandlerMiddlewareBenchmarkSource));

_host = hostBuilder
var endpointIdentity = new EndpointIdentity(
nameof(MessageHandlerMiddlewareBenchmarkSource),
Assembly.GetEntryAssembly() ?? throw new InvalidOperationException("Unable to get entry assembly"));

_host = new TestFixture()
.CreateHostBuilder()
.UseIntegrationTransport((context, builder) => builder
.WithInMemoryIntegrationTransport(hostBuilder)
.WithInMemoryIntegrationTransport()
.WithAuthorization(context.Configuration)
.WithOpenTelemetry()
.BuildOptions())
.UseEndpoint(
new EndpointIdentity(nameof(MessageHandlerMiddlewareBenchmarkSource)),
Assembly.GetEntryAssembly() !,
.UseOpenTelemetryLogger(endpointIdentity)
.UseEndpoint(endpointIdentity,
(context, builder) => builder
.WithPostgreSqlDataAccess(options => options
.ExecuteMigrations())
.WithSqlEventSourcing()
.WithAuthorization(context.Configuration)
.WithOpenTelemetry()
.ModifyContainerOptions(options => options
.WithAdditionalOurTypes(typeof(RecreatePostgreSqlDatabaseHostStartupAction)))
.BuildOptions())
Expand Down
13 changes: 13 additions & 0 deletions Common/Basics/AssembliesExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ public static class AssembliesExtensions
private static readonly Lazy<(Assembly[] OurAssemblies, Assembly[] AllAssemblies)> AllAssembliesLoadedInCurrentAppDomain
= new Lazy<(Assembly[] OurAssemblies, Assembly[] AllAssemblies)>(WarmUpAppDomain, LazyThreadSafetyMode.ExecutionAndPublication);

/// <summary>
/// Gets assembly version
/// </summary>
/// <param name="assembly">Assembly</param>
/// <returns>Assembly version</returns>
public static string GetAssemblyVersion(this Assembly assembly)
{
return assembly.GetCustomAttribute<AssemblyVersionAttribute>()?.Version
?? assembly.GetCustomAttribute<AssemblyFileVersionAttribute>()?.Version
?? assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion
?? "1.0.0.0";
}

/// <summary>
/// Build name
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface IAdvancedManualRegistrationsContainer : IManualRegistrationsCon
/// <summary>
/// Dependency container implementation
/// </summary>
IDependencyContainer Container { get; }
IDependencyContainer DependencyContainer { get; }

/// <summary> Registers instance producer </summary>
/// <param name="instanceProducer">Instance producer</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public ManualRegistrationsContainer(
DependencyContainer container,
ITypeProvider typeProvider)
{
Container = container;
DependencyContainer = container;
Types = typeProvider;

_instances = new List<InstanceRegistrationInfo>();
Expand All @@ -31,7 +31,7 @@ public ManualRegistrationsContainer(
_decorators = new List<DecoratorRegistrationInfo>();
}

public IDependencyContainer Container { get; }
public IDependencyContainer DependencyContainer { get; }

#region IRegistrationsContainer

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ private void VerifyConstructors(
var types = _registrations
.RegisteredComponents()
.Where(typeProvider.IsOurType)
.Where(type => !type.HasAttribute<ManuallyRegisteredComponentAttribute>())
.Where(HasWrongConstructor(initializableComponents, _options.ConstructorResolutionBehavior));

foreach (var type in types)
Expand Down
14 changes: 14 additions & 0 deletions Core.sln
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GenericEndpoint.EventSourci
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GenericEndpoint.Authorization", "Endpoints\GenericEndpoint.Authorization\GenericEndpoint.Authorization.csproj", "{4EC8E902-24D7-4EC0-B886-AC76E9C73A54}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GenericEndpoint.Telemetry", "Endpoints\GenericEndpoint.Telemetry\GenericEndpoint.Telemetry.csproj", "{29C52BD4-06D5-4C11-93AC-29E88351E05B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GenericEndpoint.Host", "Endpoints\GenericEndpoint.Host\GenericEndpoint.Host.csproj", "{13D73582-68CF-43A1-B340-59BDB56AF69F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GenericEndpoint.DataAccess.Sql.Host", "Endpoints\GenericEndpoint.DataAccess.Sql.Host\GenericEndpoint.DataAccess.Sql.Host.csproj", "{1FCF0008-7443-460A-9467-0C1214875405}"
Expand All @@ -71,6 +73,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GenericEndpoint.EventSourci
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GenericEndpoint.Authorization.Host", "Endpoints\GenericEndpoint.Authorization.Host\GenericEndpoint.Authorization.Host.csproj", "{C8EAFDC7-76E5-4022-9A23-795FD1C60027}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GenericEndpoint.Telemetry.Host", "Endpoints\GenericEndpoint.Telemetry.Host\GenericEndpoint.Telemetry.Host.csproj", "{948CF169-F8C6-45E5-AEEB-78973C82F203}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GenericEndpoint.TestExtensions", "Endpoints\GenericEndpoint.TestExtensions\GenericEndpoint.TestExtensions.csproj", "{8B3D2F61-04BF-422F-B466-FD74590412A0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IntegrationTransport.Api", "Endpoints\IntegrationTransport.Api\IntegrationTransport.Api.csproj", "{5BB27AD8-320C-4CB3-AEE5-707993A9488F}"
Expand Down Expand Up @@ -357,6 +361,14 @@ Global
{E6CD349F-A556-4F90-8382-77A4AA0EEA80}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E6CD349F-A556-4F90-8382-77A4AA0EEA80}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E6CD349F-A556-4F90-8382-77A4AA0EEA80}.Release|Any CPU.Build.0 = Release|Any CPU
{29C52BD4-06D5-4C11-93AC-29E88351E05B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{29C52BD4-06D5-4C11-93AC-29E88351E05B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{29C52BD4-06D5-4C11-93AC-29E88351E05B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{29C52BD4-06D5-4C11-93AC-29E88351E05B}.Release|Any CPU.Build.0 = Release|Any CPU
{948CF169-F8C6-45E5-AEEB-78973C82F203}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{948CF169-F8C6-45E5-AEEB-78973C82F203}.Debug|Any CPU.Build.0 = Debug|Any CPU
{948CF169-F8C6-45E5-AEEB-78973C82F203}.Release|Any CPU.ActiveCfg = Release|Any CPU
{948CF169-F8C6-45E5-AEEB-78973C82F203}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -418,6 +430,8 @@ Global
{4EC8E902-24D7-4EC0-B886-AC76E9C73A54} = {71BD7EAD-1AFD-4BFC-A38D-80BD47A31470}
{C8EAFDC7-76E5-4022-9A23-795FD1C60027} = {71BD7EAD-1AFD-4BFC-A38D-80BD47A31470}
{E6CD349F-A556-4F90-8382-77A4AA0EEA80} = {CAB2EF9F-1D44-4B12-AA3D-BE2E508E0351}
{29C52BD4-06D5-4C11-93AC-29E88351E05B} = {71BD7EAD-1AFD-4BFC-A38D-80BD47A31470}
{948CF169-F8C6-45E5-AEEB-78973C82F203} = {71BD7EAD-1AFD-4BFC-A38D-80BD47A31470}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4714F856-F59A-40D3-BC6D-D2316FA86A03}
Expand Down
8 changes: 7 additions & 1 deletion Endpoints/AuthEndpoint.Contract/Identity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespace SpaceEngineers.Core.AuthEndpoint.Contract
{
using System.Reflection;
using Basics;
using GenericEndpoint.Contract;

/// <summary>
/// Identity
Expand All @@ -16,10 +17,15 @@ public static class Identity
/// <summary>
/// AuthEndpoint assembly
/// </summary>
public static readonly Assembly Assembly = AssembliesExtensions.FindRequiredAssembly(
public static Assembly Assembly { get; } = AssembliesExtensions.FindRequiredAssembly(
AssembliesExtensions.BuildName(
nameof(SpaceEngineers),
nameof(Core),
nameof(AuthEndpoint)));

/// <summary>
/// AuthEndpoint identity
/// </summary>
public static EndpointIdentity EndpointIdentity { get; } = new EndpointIdentity(LogicalName, Assembly);
}
}
4 changes: 1 addition & 3 deletions Endpoints/AuthEndpoint.Host/HostExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace SpaceEngineers.Core.AuthEndpoint.Host
using GenericEndpoint.Host;
using GenericEndpoint.Host.Builder;
using Microsoft.Extensions.Hosting;
using SpaceEngineers.Core.GenericEndpoint.Contract;

/// <summary>
/// HostExtensions
Expand All @@ -32,8 +31,7 @@ public static IHostBuilder UseAuthEndpoint(
};

return hostBuilder.UseEndpoint(
new EndpointIdentity(Identity.LogicalName),
Identity.Assembly,
Identity.EndpointIdentity,
(context, endpointBuilder) => optionsFactory(endpointBuilder
.WithEndpointPluginAssemblies(assemblies)
.WithAuthorization(context.Configuration)));
Expand Down
31 changes: 27 additions & 4 deletions Endpoints/GenericEndpoint.Contract/EndpointIdentity.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace SpaceEngineers.Core.GenericEndpoint.Contract
{
using System;
using System.Reflection;
using System.Text.Json.Serialization;
using AutoRegistration.Api.Abstractions;
using AutoRegistration.Api.Attributes;
using Basics;
Expand All @@ -13,12 +15,24 @@ public class EndpointIdentity : IEquatable<EndpointIdentity>,
ISafelyEquatable<EndpointIdentity>,
IResolvable<EndpointIdentity>
{
/// <summary> .cctor </summary>
[JsonConstructor]
[Obsolete("serialization constructor")]
public EndpointIdentity()
{
LogicalName = default!;
InstanceName = default!;
Version = default!;
}

/// <summary> .cctor </summary>
/// <param name="logicalName">Endpoint logical name</param>
public EndpointIdentity(string logicalName)
/// <param name="assembly">Assembly</param>
public EndpointIdentity(string logicalName, Assembly assembly)
{
LogicalName = logicalName;
InstanceName = Guid.NewGuid().ToString();
Version = assembly.GetAssemblyVersion();
}

/// <summary>
Expand All @@ -31,6 +45,11 @@ public EndpointIdentity(string logicalName)
/// </summary>
public string InstanceName { get; init; }

/// <summary>
/// Endpoint version
/// </summary>
public string Version { get; init; }

#region IEquatable

/// <summary>
Expand Down Expand Up @@ -59,7 +78,8 @@ public EndpointIdentity(string logicalName)
public bool SafeEquals(EndpointIdentity other)
{
return LogicalName.Equals(other.LogicalName, StringComparison.OrdinalIgnoreCase)
&& InstanceName.Equals(other.InstanceName, StringComparison.OrdinalIgnoreCase);
&& InstanceName.Equals(other.InstanceName, StringComparison.OrdinalIgnoreCase)
&& Version.Equals(other.Version, StringComparison.OrdinalIgnoreCase);
}

/// <inheritdoc />
Expand All @@ -77,15 +97,18 @@ public override bool Equals(object? obj)
/// <inheritdoc />
public override int GetHashCode()
{
return HashCode.Combine(LogicalName, InstanceName);
return HashCode.Combine(
LogicalName.GetHashCode(StringComparison.OrdinalIgnoreCase),
InstanceName.GetHashCode(StringComparison.OrdinalIgnoreCase),
Version.GetHashCode(StringComparison.OrdinalIgnoreCase));
}

#endregion

/// <inheritdoc />
public override string ToString()
{
return $"{LogicalName}:{InstanceName}";
return $"{LogicalName}:{InstanceName}:{Version}";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,6 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Text.Json" Version="7.0.3" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion Endpoints/GenericEndpoint.Host/Builder/EndpointBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal EndpointBuilder(EndpointIdentity endpointIdentity)

public IReadOnlyCollection<Func<DependencyContainerOptions, DependencyContainerOptions>> Modifiers { get; protected set; }

protected EndpointIdentity EndpointIdentity { get; }
public EndpointIdentity EndpointIdentity { get; }

public IEndpointBuilder WithEndpointPluginAssemblies(params Assembly[] assemblies)
{
Expand Down
6 changes: 6 additions & 0 deletions Endpoints/GenericEndpoint.Host/Builder/IEndpointBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@ namespace SpaceEngineers.Core.GenericEndpoint.Host.Builder
using System;
using System.Reflection;
using CompositionRoot;
using Contract;

/// <summary>
/// IEndpointBuilder
/// </summary>
public interface IEndpointBuilder
{
/// <summary>
/// Endpoint identity
/// </summary>
EndpointIdentity EndpointIdentity { get; }

/// <summary>
/// With endpoint plugin assemblies
/// </summary>
Expand Down
2 changes: 0 additions & 2 deletions Endpoints/GenericEndpoint.Host/GenericEndpoint.Host.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="OpenTelemetry" Version="1.5.1" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.5.1" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Loading

0 comments on commit 53ab1ee

Please sign in to comment.