Skip to content

Commit

Permalink
Merge pull request #686 from jbogard/contracts-assembly
Browse files Browse the repository at this point in the history
Contracts assembly separated out into separate package
  • Loading branch information
jbogard authored Jan 6, 2022
2 parents 802e4a4 + b2b0222 commit b152d92
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 2 deletions.
34 changes: 34 additions & 0 deletions BuildContracts.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Taken from psake https://github.com/psake/psake

<#
.SYNOPSIS
This is a helper function that runs a scriptblock and checks the PS variable $lastexitcode
to see if an error occcured. If an error is detected then an exception is thrown.
This function allows you to run command-line programs without having to
explicitly check the $lastexitcode variable.
.EXAMPLE
exec { svn info $repository_trunk } "Error executing SVN. Please verify SVN command-line client is installed"
#>
function Exec
{
[CmdletBinding()]
param(
[Parameter(Position=0,Mandatory=1)][scriptblock]$cmd,
[Parameter(Position=1,Mandatory=0)][string]$errorMessage = ($msgs.error_bad_command -f $cmd)
)
& $cmd
if ($lastexitcode -ne 0) {
throw ("Exec: " + $errorMessage)
}
}

$artifacts = ".\artifacts"
$contracts = ".\src\MediatR.Contracts\MediatR.Contracts.csproj"

if(Test-Path $artifacts) { Remove-Item $artifacts -Force -Recurse }

exec { & dotnet clean $contracts -c Release }

exec { & dotnet build $contracts -c Release -p:ContinuousIntegrationBuild=true }

exec { & dotnet pack $contracts -c Release -o $artifacts --no-build }
12 changes: 10 additions & 2 deletions MediatR.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{962C5ACA-A
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{95CFF0CD-87A6-4CB6-A99F-42EAD0829E37}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediatR", "src\MediatR\MediatR.csproj", "{12DA3F16-060B-467A-993F-2DF25EE6E6A8}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MediatR", "src\MediatR\MediatR.csproj", "{12DA3F16-060B-467A-993F-2DF25EE6E6A8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediatR.Tests", "test\MediatR.Tests\MediatR.Tests.csproj", "{4FB0CFC4-90E3-467F-9704-6FBF637F9B4B}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MediatR.Tests", "test\MediatR.Tests\MediatR.Tests.csproj", "{4FB0CFC4-90E3-467F-9704-6FBF637F9B4B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MediatR.Examples", "samples\MediatR.Examples\MediatR.Examples.csproj", "{18AB74EF-6E32-42C5-B6C4-159624CEDC5D}"
EndProject
Expand All @@ -33,6 +33,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
Build.ps1 = Build.ps1
BuildContracts.ps1 = BuildContracts.ps1
.github\workflows\ci.yml = .github\workflows\ci.yml
Directory.Build.props = Directory.Build.props
Push.ps1 = Push.ps1
Expand All @@ -50,6 +51,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MediatR.Benchmarks", "test\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MediatR.Examples.Stashbox", "samples\MediatR.Examples.Stashbox\MediatR.Examples.Stashbox.csproj", "{575EC49E-BEC8-4DFF-BD22-8464844093FE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MediatR.Contracts", "src\MediatR.Contracts\MediatR.Contracts.csproj", "{87F5A238-44B5-4769-82E5-E68B712D6E6D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -116,6 +119,10 @@ Global
{575EC49E-BEC8-4DFF-BD22-8464844093FE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{575EC49E-BEC8-4DFF-BD22-8464844093FE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{575EC49E-BEC8-4DFF-BD22-8464844093FE}.Release|Any CPU.Build.0 = Release|Any CPU
{87F5A238-44B5-4769-82E5-E68B712D6E6D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{87F5A238-44B5-4769-82E5-E68B712D6E6D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{87F5A238-44B5-4769-82E5-E68B712D6E6D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{87F5A238-44B5-4769-82E5-E68B712D6E6D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -136,6 +143,7 @@ Global
{867EBA13-62F4-4525-8F92-B0AD828EE6D4} = {95CFF0CD-87A6-4CB6-A99F-42EAD0829E37}
{1FA62162-F8F1-4CAD-B08E-8DCA603395AD} = {962C5ACA-AB2B-4E9B-9EBB-7E7EE28CDBB1}
{575EC49E-BEC8-4DFF-BD22-8464844093FE} = {95CFF0CD-87A6-4CB6-A99F-42EAD0829E37}
{87F5A238-44B5-4769-82E5-E68B712D6E6D} = {6267E2ED-942C-497D-BFC9-B3CE0AFC276F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D58286E3-878B-4ACB-8E76-F61E708D4339}
Expand Down
6 changes: 6 additions & 0 deletions src/MediatR.Contracts/INotification.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace MediatR;

/// <summary>
/// Marker interface to represent a notification
/// </summary>
public interface INotification { }
17 changes: 17 additions & 0 deletions src/MediatR.Contracts/IRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace MediatR;

/// <summary>
/// Marker interface to represent a request with a void response
/// </summary>
public interface IRequest : IRequest<Unit> { }

/// <summary>
/// Marker interface to represent a request with a response
/// </summary>
/// <typeparam name="TResponse">Response type</typeparam>
public interface IRequest<out TResponse> : IBaseRequest { }

/// <summary>
/// Allows for generic type constraints of objects implementing IRequest or IRequest{TResponse}
/// </summary>
public interface IBaseRequest { }
7 changes: 7 additions & 0 deletions src/MediatR.Contracts/IStreamRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace MediatR;

/// <summary>
/// Marker interface to represent a request with a streaming response
/// </summary>
/// <typeparam name="TResponse">Response type</typeparam>
public interface IStreamRequest<out TResponse> { }
36 changes: 36 additions & 0 deletions src/MediatR.Contracts/MediatR.Contracts.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable>
<Authors>Jimmy Bogard</Authors>
<Description>Contracts package for requests, responses, and notifications</Description>
<Copyright>Copyright Jimmy Bogard</Copyright>
<TargetFrameworks>netstandard2.1</TargetFrameworks>
<Nullable>enable</Nullable>
<Features>strict</Features>
<PackageTags>mediator;request;response;queries;commands;notifications</PackageTags>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\MediatR.snk</AssemblyOriginatorKeyFile>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageIcon>gradient_128x128.png</PackageIcon>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<Deterministic>true</Deterministic>
<Version>1.0.0</Version>
<RootNamespace>MediatR</RootNamespace>

</PropertyGroup>

<ItemGroup>
<None Include="..\..\assets\logo\gradient_128x128.png" Pack="true" PackagePath="" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>

</Project>
96 changes: 96 additions & 0 deletions src/MediatR.Contracts/Unit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
namespace MediatR;

using System;
using System.Threading.Tasks;

/// <summary>
/// Represents a void type, since <see cref="System.Void"/> is not a valid return type in C#.
/// </summary>
public readonly struct Unit : IEquatable<Unit>, IComparable<Unit>, IComparable
{
private static readonly Unit _value = new();

/// <summary>
/// Default and only value of the <see cref="Unit"/> type.
/// </summary>
public static ref readonly Unit Value => ref _value;

/// <summary>
/// Task from a <see cref="Unit"/> type.
/// </summary>
public static Task<Unit> Task { get; } = System.Threading.Tasks.Task.FromResult(_value);

/// <summary>
/// Compares the current object with another object of the same type.
/// </summary>
/// <param name="other">An object to compare with this object.</param>
/// <returns>
/// A value that indicates the relative order of the objects being compared.
/// The return value has the following meanings:
/// - Less than zero: This object is less than the <paramref name="other" /> parameter.
/// - Zero: This object is equal to <paramref name="other" />.
/// - Greater than zero: This object is greater than <paramref name="other" />.
/// </returns>
public int CompareTo(Unit other) => 0;

/// <summary>
/// Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
/// </summary>
/// <param name="obj">An object to compare with this instance.</param>
/// <returns>
/// A value that indicates the relative order of the objects being compared.
/// The return value has these meanings:
/// - Less than zero: This instance precedes <paramref name="obj" /> in the sort order.
/// - Zero: This instance occurs in the same position in the sort order as <paramref name="obj" />.
/// - Greater than zero: This instance follows <paramref name="obj" /> in the sort order.
/// </returns>
int IComparable.CompareTo(object? obj) => 0;

/// <summary>
/// Returns a hash code for this instance.
/// </summary>
/// <returns>
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
/// </returns>
public override int GetHashCode() => 0;

/// <summary>
/// Determines whether the current object is equal to another object of the same type.
/// </summary>
/// <param name="other">An object to compare with this object.</param>
/// <returns>
/// <c>true</c> if the current object is equal to the <paramref name="other" /> parameter; otherwise, <c>false</c>.
/// </returns>
public bool Equals(Unit other) => true;

/// <summary>
/// Determines whether the specified <see cref="System.Object" /> is equal to this instance.
/// </summary>
/// <param name="obj">The object to compare with the current instance.</param>
/// <returns>
/// <c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.
/// </returns>
public override bool Equals(object? obj) => obj is Unit;

/// <summary>
/// Determines whether the <paramref name="first"/> object is equal to the <paramref name="second"/> object.
/// </summary>
/// <param name="first">The first object.</param>
/// <param name="second">The second object.</param>
/// <c>true</c> if the <paramref name="first"/> object is equal to the <paramref name="second" /> object; otherwise, <c>false</c>.
public static bool operator ==(Unit first, Unit second) => true;

/// <summary>
/// Determines whether the <paramref name="first"/> object is not equal to the <paramref name="second"/> object.
/// </summary>
/// <param name="first">The first object.</param>
/// <param name="second">The second object.</param>
/// <c>true</c> if the <paramref name="first"/> object is not equal to the <paramref name="second" /> object; otherwise, <c>false</c>.
public static bool operator !=(Unit first, Unit second) => false;

/// <summary>
/// Returns a <see cref="System.String" /> that represents this instance.
/// </summary>
/// <returns>A <see cref="System.String" /> that represents this instance.</returns>
public override string ToString() => "()";
}

0 comments on commit b152d92

Please sign in to comment.