Skip to content

Commit

Permalink
Add Mediatr functional extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
rungwiroon committed Nov 14, 2023
1 parent 92f06ce commit f497d83
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Codehard.Core.sln
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Codehard.Functional.Marten"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Codehard.Functional.Marten.Tests", "Codehard.Functional\Codehard.Functional.Marten.Tests\Codehard.Functional.Marten.Tests.csproj", "{BCB6D4C3-DD27-43AD-B0E9-6C8DE6821AD5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Codehard.Functional.Mediatr", "Codehard.Functional\Codehard.Functional.Mediatr\Codehard.Functional.Mediatr.csproj", "{8952083F-5A2A-4A37-9039-8588B08CA6EE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -143,6 +145,10 @@ Global
{BCB6D4C3-DD27-43AD-B0E9-6C8DE6821AD5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BCB6D4C3-DD27-43AD-B0E9-6C8DE6821AD5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BCB6D4C3-DD27-43AD-B0E9-6C8DE6821AD5}.Release|Any CPU.Build.0 = Release|Any CPU
{8952083F-5A2A-4A37-9039-8588B08CA6EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8952083F-5A2A-4A37-9039-8588B08CA6EE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8952083F-5A2A-4A37-9039-8588B08CA6EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8952083F-5A2A-4A37-9039-8588B08CA6EE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -173,5 +179,6 @@ Global
{6277AC9F-217C-4F89-8589-51FCB4E9BADF} = {2F98EF48-527C-44C5-8FC3-65F25C808AC9}
{8D62918D-C27F-45AF-B26A-437B594C0D5C} = {0C257E94-AD98-4AFB-93B7-B6F64EB7D2BA}
{BCB6D4C3-DD27-43AD-B0E9-6C8DE6821AD5} = {0C257E94-AD98-4AFB-93B7-B6F64EB7D2BA}
{8952083F-5A2A-4A37-9039-8588B08CA6EE} = {0C257E94-AD98-4AFB-93B7-B6F64EB7D2BA}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="LanguageExt.Core" Version="4.4.7" />
<PackageReference Include="MediatR" Version="12.1.1" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using LanguageExt;
using LanguageExt.Common;

using static LanguageExt.Prelude;

namespace Codehard.Functional.Mediatr;

public record ExpectedResultError : Expected
{
public ExpectedResultError(object errorObject, Error? inner)
: base(string.Empty, 0, Optional(inner))
{
this.ErrorObject = errorObject;
}

public ExpectedResultError(object errorObject, Exception? exception = null)
: base(string.Empty, 0, exception == null ? Option<Error>.None : Option<Error>.Some(ErrorException.New(exception)))
{
this.ErrorObject = errorObject;
}

public override ErrorException ToErrorException() => ErrorException.New(this.ErrorObject.ToString() ?? string.Empty);

public override string ToString() => this.ErrorObject.ToString() ?? string.Empty;

public object ErrorObject { get; init; }

public void Deconstruct(out object errorObject)
{
errorObject = this.ErrorObject;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using LanguageExt;
using MediatR;

namespace Codehard.Functional.Mediatr;

public interface ICommand<TCommandResult> : IRequest<Fin<TCommandResult>>
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using LanguageExt;
using MediatR;

namespace Codehard.Functional.Mediatr;

public interface ICommandHandler<in TCommand, TCommandResult> : IRequestHandler<TCommand, Fin<TCommandResult>>
where TCommand : ICommand<TCommandResult>
{
}
8 changes: 8 additions & 0 deletions src/Codehard.Functional/Codehard.Functional.Mediatr/IQuery.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using LanguageExt;
using MediatR;

namespace Codehard.Functional.Mediatr;

public interface IQuery<TQueryResult> : IRequest<Fin<TQueryResult>>
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using LanguageExt;
using MediatR;

namespace Codehard.Functional.Mediatr;

public interface IQueryHandler<in TQuery, TQueryResult> : IRequestHandler<TQuery, Fin<TQueryResult>>
where TQuery : IQuery<TQueryResult>
{
}

0 comments on commit f497d83

Please sign in to comment.