Skip to content
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
1 change: 1 addition & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ jobs:
dotnet pack ./Email/Core/Odin.Email.csproj --configuration $CONFIGURATION --output $PACKAGE_DIR
dotnet pack ./Logging/Core/Odin.Logging.csproj --configuration $CONFIGURATION --output $PACKAGE_DIR
dotnet pack ./Messaging/RabbitMq/Odin.Messaging.RabbitMq.csproj --configuration $CONFIGURATION --output $PACKAGE_DIR
dotnet pack ./Patterns/Commands.Abstractions/Odin.Patterns.Commands.Abstractions.csproj --configuration $CONFIGURATION --output $PACKAGE_DIR
dotnet pack ./Patterns/Commands/Odin.Patterns.Commands.csproj --configuration $CONFIGURATION --output $PACKAGE_DIR
dotnet pack ./Patterns/Queries/Odin.Patterns.Queries.csproj --configuration $CONFIGURATION --output $PACKAGE_DIR
dotnet pack ./Patterns/Notifications/Odin.Patterns.Notifications.csproj --configuration $CONFIGURATION --output $PACKAGE_DIR
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Specialized;
using Odin.System;
using Odin.System;

namespace Odin.BackgroundProcessing
{
Expand Down
2 changes: 0 additions & 2 deletions DesignContracts/Core/ContractException.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Runtime.Serialization;

namespace Odin.DesignContracts
{
/// <summary>
Expand Down
124 changes: 59 additions & 65 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,67 +1,61 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Azure.Storage.Blobs" Version="12.27.0"/>
<PackageVersion Include="Hangfire.Core" Version="1.8.23" />
<PackageVersion Include="Hangfire.AspNetCore" Version="1.8.23" />
<PackageVersion Include="Hangfire.SqlServer" Version="1.8.23" />
<PackageVersion Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.3.9" />
<PackageVersion Include="Azure.Identity" Version="1.20.0" />
<PackageVersion Include="Microsoft.Graph" Version="5.103.0" />
<PackageVersion Include="Microsoft.Data.SqlClient" Version="7.0.0" />
<PackageVersion Include="Moq" Version="4.20.72" />
<PackageVersion Include="NUnit3TestAdapter" Version="6.2.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.4.0" />
<PackageVersion Include="NUnit" Version="4.5.1" />
<PackageVersion Include="NUnit.Analyzers" Version="4.12.0" />
<PackageVersion Include="Polly.Core" Version="8.6.6" />
<PackageVersion Include="SSH.NET" Version="2025.1.0" />
<PackageVersion Include="RazorLight" Version="2.3.1" />
<PackageVersion Include="dbup" Version="5.0.41" />
<PackageVersion Include="RabbitMQ.Client" Version="7.2.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="5.3.0"/>
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="5.3.0"/>
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0"/>
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="8.0.1"/>
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2"/>
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2"/>
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.1"/>
<PackageVersion Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.3.0"/>
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.3"/>
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.3"/>
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.25" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="8.0.25" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.11"/>
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.11"/>
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.11"/>
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="9.0.11"/>
<PackageVersion Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.3.0"/>
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.11"/>
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.11"/>
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="9.0.11"/>
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.14" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="9.0.14" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net10.0'">
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="10.0.5"/>
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="10.0.5"/>
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.5"/>
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="10.0.5"/>
<PackageVersion Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.3.9"/>
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.5"/>
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.5"/>
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="10.0.5"/>
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="10.0.5" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="9.0.14" />

</ItemGroup>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Azure.Storage.Blobs" Version="12.27.0" />
<PackageVersion Include="Hangfire.Core" Version="1.8.23" />
<PackageVersion Include="Hangfire.AspNetCore" Version="1.8.23" />
<PackageVersion Include="Hangfire.SqlServer" Version="1.8.23" />
<PackageVersion Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.3.9" />
<PackageVersion Include="Azure.Identity" Version="1.21.0" />
<PackageVersion Include="Microsoft.Graph" Version="5.103.0" />
<PackageVersion Include="Microsoft.Data.SqlClient" Version="7.0.0" />
<PackageVersion Include="Moq" Version="4.20.72" />
<PackageVersion Include="NUnit3TestAdapter" Version="6.2.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.4.0" />
<PackageVersion Include="NUnit" Version="4.5.1" />
<PackageVersion Include="NUnit.Analyzers" Version="4.12.0" />
<PackageVersion Include="Polly.Core" Version="8.6.6" />
<PackageVersion Include="SSH.NET" Version="2025.1.0" />
<PackageVersion Include="RazorLight" Version="2.3.1" />
<PackageVersion Include="dbup" Version="5.0.41" />
<PackageVersion Include="RabbitMQ.Client" Version="7.2.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="5.3.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="5.3.0" />
<PackageVersion Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.3.9" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.3" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="8.0.1" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.25" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="8.0.25" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.11" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.11" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.11" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="9.0.11" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.11" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="9.0.11" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="9.0.11" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.14" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="9.0.14" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net10.0'">
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="10.0.5" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="10.0.5" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.5" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="10.0.5" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.5" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="10.0.5" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="10.0.5" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="10.0.5" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="10.0.5" />
</ItemGroup>
</Project>
1 change: 0 additions & 1 deletion Domain/Core/WhereIdentityIsSpecification.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Linq.Expressions;
using System.Numerics;

namespace Odin.Domain;
Expand Down
3 changes: 1 addition & 2 deletions Email/Office365/Office365EmailSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Odin.DesignContracts;
using Odin.Logging;
using Odin.System;
using Contract = Odin.DesignContracts.Contract;

namespace Odin.Email;

Expand Down Expand Up @@ -134,7 +133,7 @@ public async Task<ResultValue<string>> SendEmail(IEmailMessage email)

static byte[] ToByteArray(Stream inputStream)
{
ArgumentNullException.ThrowIfNull(inputStream);
Precondition.RequiresNotNull(inputStream);

if (inputStream.CanSeek)
{
Expand Down
3 changes: 2 additions & 1 deletion Logging/Core/DependencyInjectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ namespace Microsoft.Extensions.DependencyInjection
public static class Logger2Extensions
{
/// <summary>
/// Sets up ILogger2 of T in dependency injection
/// Adds the Odin ILoggerWrapper of T implementation into dependency injection
/// </summary>
/// <param name="serviceCollection"></param>
/// <returns></returns>
public static void AddOdinLoggerWrapper(this IServiceCollection serviceCollection)
{
serviceCollection.AddLogging();
serviceCollection.TryAddSingleton(typeof(ILoggerWrapper<>), typeof(LoggerWrapper<>));
}
}
Expand Down
1 change: 1 addition & 0 deletions Logging/Core/Odin.Logging.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions"/>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions"/>
<PackageReference Include="Microsoft.Extensions.Logging"/>
</ItemGroup>

<ItemGroup>
Expand Down
23 changes: 23 additions & 0 deletions Odin.sln
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Odin.Patterns.Notifications
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Odin.Patterns.Queries", "Patterns\Queries\Odin.Patterns.Queries.csproj", "{FA79B472-DEDA-4BEE-B151-2B553A6528C2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests.Odin.Patterns", "Patterns\Tests\Tests.Odin.Patterns.csproj", "{1491A6A6-ED85-4AD0-A6EE-57F4CAF3192B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Testing", "Testing", "{51D0FF83-33F9-490F-A0CB-A32DC1CC48AF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Odin.Testing.NUnitUtility", "TestingUtility\Odin.Testing.NUnitUtility.csproj", "{46BCDE44-FA4E-4AE0-A6C0-9AFAE1BE09DF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Odin.Patterns.Commands.Abstractions", "Patterns\Commands.Abstractions\Odin.Patterns.Commands.Abstractions.csproj", "{7749636C-2D34-4E0B-81C9-9E89C5630858}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -260,6 +268,18 @@ Global
{FA79B472-DEDA-4BEE-B151-2B553A6528C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FA79B472-DEDA-4BEE-B151-2B553A6528C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FA79B472-DEDA-4BEE-B151-2B553A6528C2}.Release|Any CPU.Build.0 = Release|Any CPU
{1491A6A6-ED85-4AD0-A6EE-57F4CAF3192B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1491A6A6-ED85-4AD0-A6EE-57F4CAF3192B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1491A6A6-ED85-4AD0-A6EE-57F4CAF3192B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1491A6A6-ED85-4AD0-A6EE-57F4CAF3192B}.Release|Any CPU.Build.0 = Release|Any CPU
{46BCDE44-FA4E-4AE0-A6C0-9AFAE1BE09DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{46BCDE44-FA4E-4AE0-A6C0-9AFAE1BE09DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{46BCDE44-FA4E-4AE0-A6C0-9AFAE1BE09DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{46BCDE44-FA4E-4AE0-A6C0-9AFAE1BE09DF}.Release|Any CPU.Build.0 = Release|Any CPU
{7749636C-2D34-4E0B-81C9-9E89C5630858}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7749636C-2D34-4E0B-81C9-9E89C5630858}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7749636C-2D34-4E0B-81C9-9E89C5630858}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7749636C-2D34-4E0B-81C9-9E89C5630858}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{CE323D9C-635B-EFD3-5B3F-7CE371D8A86A} = {BF440C74-E223-3CBF-8FA7-83F7D164F7C3}
Expand Down Expand Up @@ -297,5 +317,8 @@ Global
{F0C4BEDA-4B20-4EC8-8265-EFF66D2B1B15} = {5B5DADD3-07F8-40E9-949A-82BEB18093CC}
{36D412FB-8A69-47A4-BABF-7B851603C9A1} = {605A7674-8EA4-458D-9FEB-A86C927AC0F0}
{FA79B472-DEDA-4BEE-B151-2B553A6528C2} = {605A7674-8EA4-458D-9FEB-A86C927AC0F0}
{1491A6A6-ED85-4AD0-A6EE-57F4CAF3192B} = {605A7674-8EA4-458D-9FEB-A86C927AC0F0}
{46BCDE44-FA4E-4AE0-A6C0-9AFAE1BE09DF} = {51D0FF83-33F9-490F-A0CB-A32DC1CC48AF}
{7749636C-2D34-4E0B-81C9-9E89C5630858} = {605A7674-8EA4-458D-9FEB-A86C927AC0F0}
EndGlobalSection
EndGlobal
33 changes: 33 additions & 0 deletions Patterns/Commands.Abstractions/ICommandDispatcher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
namespace Odin.Patterns.Commands;

/// <summary>
/// Dispatches commands to their registered command handlers.
/// </summary>
public interface ICommandDispatcher
{
/// <summary>
/// Dispatches a command that does not return a result
/// to its registered command handler.
/// </summary>
/// <typeparam name="TCommand"></typeparam>
/// <param name="command"></param>
/// <param name="ct"></param>
Task DispatchAsync<TCommand>(
TCommand command,
CancellationToken ct = default)
where TCommand : ICommand;

/// <summary>
/// Dispatches a command that returns a result
/// to its registered command handler.
/// </summary>
/// <typeparam name="TCommand"></typeparam>
/// <typeparam name="TCommandResult"></typeparam>
/// <param name="command"></param>
/// <param name="ct"></param>
/// <returns></returns>
Task<TCommandResult> DispatchAsync<TCommand, TCommandResult>(
TCommand command,
CancellationToken ct = default)
where TCommand : ICommand<TCommandResult>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
<ImplicitUsings>true</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageIcon>icon.png</PackageIcon>
<PackageReadmeFile>README.md</PackageReadmeFile>
<RootNamespace>Odin.Patterns.Commands</RootNamespace>
<Description>All abstractions for the command dispatch pattern.

</Description>
<WarningsAsErrors>1591;1573;</WarningsAsErrors> <!-- Not to be removed. Documentation is required. -->
</PropertyGroup>

<ItemGroup>
<None Include="../../Assets/icon.png" Pack="true" PackagePath=""/>
<None Include="..\README.md" Pack="true" PackagePath=""/>
</ItemGroup>
</Project>
80 changes: 80 additions & 0 deletions Patterns/Commands/DependencyInjectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System.Reflection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Odin.DesignContracts;
using Odin.Patterns.Commands;

// ReSharper disable once CheckNamespace
namespace Microsoft.Extensions.DependencyInjection;

/// <summary>
/// Dependency injection methods to support Odin command dispatching.
/// </summary>
public static class DependencyInjectionExtensions
{
/// <summary>
/// Registers the Odin implementation for ICommandDispatcher.
/// Does not auto register all ICommandHandler of TCommand implementations.
/// </summary>
/// <param name="serviceCollection">The service collection to update.</param>
/// <returns>The updated service collection.</returns>
public static IServiceCollection AddOdinCommandDispatcher(this IServiceCollection serviceCollection)
{
Precondition.RequiresNotNull(serviceCollection);
serviceCollection.AddOdinLoggerWrapper();
serviceCollection.TryAddTransient<ICommandDispatcher, ServiceProviderCommandDispatcher>();
return serviceCollection;
}

/// <summary>
/// Finds all implementations of ICommandHandler (of TCommand) and
/// ICommandHandler (of TCommand, TResult) in the specified assemblies,
/// and registers them as transient services.
/// </summary>
/// <param name="serviceCollection">The service collection to update.</param>
/// <param name="assemblies">The assemblies to scan for command handler implementations.</param>
/// <returns>The updated service collection.</returns>
public static IServiceCollection AddOdinCommandHandlers(
this IServiceCollection serviceCollection,
params Assembly[] assemblies)
{
Precondition.RequiresNotNull(serviceCollection);
Precondition.RequiresNotNull(assemblies);

foreach (Assembly assembly in assemblies.Distinct())
{
Precondition.RequiresNotNull(assembly);
RegisterCommandHandlers(serviceCollection, assembly);
}

return serviceCollection;
}

private static void RegisterCommandHandlers(IServiceCollection serviceCollection, Assembly assembly)
{
foreach (TypeInfo implementationType in assembly.DefinedTypes)
{
if (!implementationType.IsClass || implementationType.IsAbstract || implementationType.ContainsGenericParameters)
{
continue;
}

foreach (Type handlerInterfaceType in implementationType.ImplementedInterfaces.Where(IsCommandHandlerInterface))
{
serviceCollection.TryAddEnumerable(
ServiceDescriptor.Transient(handlerInterfaceType, implementationType.AsType()));
}
}
}

private static bool IsCommandHandlerInterface(Type type)
{
if (!type.IsGenericType)
{
return false;
}

Type genericTypeDefinition = type.GetGenericTypeDefinition();
return genericTypeDefinition == typeof(ICommandHandler<>) ||
genericTypeDefinition == typeof(ICommandHandler<,>);
}
}
Loading
Loading