Skip to content

Commit

Permalink
Tested MediatR support with a sample
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesRandall committed Jan 11, 2020
1 parent 9921519 commit 42fe8a1
Show file tree
Hide file tree
Showing 18 changed files with 511 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<CommonPackageVersion>4.0.37-beta.3</CommonPackageVersion>
<CommonPackageVersion>4.0.38-beta.4</CommonPackageVersion>
</PropertyGroup>
</Project>
7 changes: 7 additions & 0 deletions FunctionMonkey.sln
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FunctionMonkey.Tests.Integr
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FunctionMonkey.MediatR", "Source\FunctionMonkey.MediatR\FunctionMonkey.MediatR.csproj", "{39738BA3-AA8F-4F6D-9864-2C0839584CC0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediatRSample", "Samples\DocumentationSamples\MediatRSample\MediatRSample.csproj", "{C693B34C-DA5E-4C49-8016-5E94F4FA43B1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -232,6 +234,10 @@ Global
{39738BA3-AA8F-4F6D-9864-2C0839584CC0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{39738BA3-AA8F-4F6D-9864-2C0839584CC0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{39738BA3-AA8F-4F6D-9864-2C0839584CC0}.Release|Any CPU.Build.0 = Release|Any CPU
{C693B34C-DA5E-4C49-8016-5E94F4FA43B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C693B34C-DA5E-4C49-8016-5E94F4FA43B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C693B34C-DA5E-4C49-8016-5E94F4FA43B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C693B34C-DA5E-4C49-8016-5E94F4FA43B1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -259,6 +265,7 @@ Global
{FFC8BE94-890B-422D-BB64-6CCCAD515B0C} = {4C5AD0FE-C42D-46CD-ADF3-D51356E04F6B}
{BD36C0F8-2A2F-4A95-A8BA-D7D5F2C9808A} = {68C555D0-6537-4D5B-B36C-E62F34F5E890}
{B61847C6-76D3-43D9-B640-F62DD20905DB} = {68C555D0-6537-4D5B-B36C-E62F34F5E890}
{C693B34C-DA5E-4C49-8016-5E94F4FA43B1} = {CB492EF3-6255-4528-8978-0D0974B7F081}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C9ABA812-671D-4486-B9D8-4F16D4BE11BD}
Expand Down
264 changes: 264 additions & 0 deletions Samples/DocumentationSamples/MediatRSample/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# Azure Functions localsettings file
local.settings.json

# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/

# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

# NUNIT
*.VisualState.xml
TestResult.xml

# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c

# DNX
project.lock.json
project.fragment.lock.json
artifacts/

*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc

# Chutzpah Test files
_Chutzpah*

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb

# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap

# TFS 2012 Local Workspace
$tf/

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user

# JustCode is a .NET coding add-in
.JustCode

# TeamCity is a build add-in
_TeamCity*

# DotCover is a Code Coverage Tool
*.dotCover

# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*

# MightyMoose
*.mm.*
AutoTest.Net/

# Web workbench (sass)
.sass-cache/

# Installshield output folder
[Ee]xpress/

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish/

# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
#*.pubxml
*.publishproj

# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/

# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# NuGet v3's project.json files produces more ignoreable files
*.nuget.props
*.nuget.targets

# Microsoft Azure Build Output
csx/
*.build.csdef

# Microsoft Azure Emulator
ecf/
rcf/

# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt

# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/

# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
node_modules/
orleans.codegen.cs

# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/

# RIA/Silverlight projects
Generated_Code/

# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm

# SQL Server files
*.mdf
*.ldf

# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings

# Microsoft Fakes
FakesAssemblies/

# GhostDoc plugin setting file
*.GhostDoc.xml

# Node.js Tools for Visual Studio
.ntvs_analysis.dat

# Visual Studio 6 build log
*.plg

# Visual Studio 6 workspace options file
*.opt

# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions

# Paket dependency manager
.paket/paket.exe
paket-files/

# FAKE - F# Make
.fake/

# JetBrains Rider
.idea/
*.sln.iml

# CodeRush
.cr/

# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using MediatR;
using MediatRSample.Models;

namespace ToDo.Application.Commands
{
public class CreateToDoItemCommand : IRequest<ToDoItem>
{
public string Title { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Collections.Generic;
using MediatR;
using MediatRSample.Models;

namespace ToDo.Application.Commands
{
public class GetAllToDoItemsQuery : IRequest<IReadOnlyCollection<ToDoItem>>
{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
using MediatR;

namespace ToDo.Application.Commands
{
public class MarkToDoItemCompleteCommand : INotification
{
public Guid Id { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Net.Http;
using FunctionMonkey.Abstractions;
using FunctionMonkey.Abstractions.Builders;
using FunctionMonkey.MediatR;
using MediatR;
using MediatRSample.Services;
using Microsoft.Extensions.DependencyInjection;
using ToDo.Application.Commands;
using ToDo.Application.Services;

namespace MediatRSample
{
public class FunctionAppConfiguration : IFunctionAppConfiguration
{
public void Build(IFunctionHostBuilder builder)
{
builder
.Setup(sc => sc
.AddMediatR(typeof(FunctionAppConfiguration).Assembly)
.AddSingleton<IRepository, Repository>()
)
.UseMediatR()
.Functions(functions => functions
.HttpRoute("todo", route => route
.HttpFunction<GetAllToDoItemsQuery>(HttpMethod.Get)
.HttpFunction<MarkToDoItemCompleteCommand>("complete", HttpMethod.Put)
.HttpFunction<CreateToDoItemCommand>(HttpMethod.Post)
)
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Threading;
using System.Threading.Tasks;
using MediatR;
using MediatRSample.Models;
using MediatRSample.Services;
using ToDo.Application.Commands;

namespace MediatRSample.Handlers
{
internal class CreateToDoItemCommandHandler : IRequestHandler<CreateToDoItemCommand, ToDoItem>
{
private readonly IRepository _repository;

public CreateToDoItemCommandHandler(IRepository repository)
{
_repository = repository;
}

public Task<ToDoItem> Handle(CreateToDoItemCommand request, CancellationToken cancellationToken)
{
return _repository.Create(request.Title);
}
}
}
Loading

0 comments on commit 42fe8a1

Please sign in to comment.