-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract Store CompositionRoot to common project so Web and CLI can share
- Loading branch information
Showing
7 changed files
with
117 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/// TL;DR There is no secret plan to make a package out of this; | ||
/// it's infrastructure that makes sense solely in the context of this test rig | ||
/// ...depending on 3 stores is not a goal or achievement | ||
/// Yes, they live together here - that's because it's infrastructure that makes sense in the context of this test rig | ||
/// It also proves the point that the Domain and backend are not bound to the Store, which is important too | ||
/// IRL, it's unlikely you'd want to do storage switching in this manner | ||
module Store.CompositionRoot | ||
|
||
open System | ||
|
||
let serializationSettings = Newtonsoft.Json.Converters.FSharp.Settings.CreateCorrect() | ||
let inline genCodec<'Union when 'Union :> TypeShape.UnionContract.IUnionContract>() = Equinox.UnionCodec.JsonUtf8.Create<'Union>(serializationSettings) | ||
|
||
type private EsResolver(useCache) = | ||
member val Cache = | ||
if useCache then | ||
let c = Equinox.EventStore.Caching.Cache("Cli", sizeMb = 50) | ||
Equinox.EventStore.CachingStrategy.SlidingWindow (c, TimeSpan.FromMinutes 20.) |> Some | ||
else None | ||
member __.CreateAccessStrategy snapshot = | ||
match snapshot with | ||
| None -> None | ||
| Some snapshot -> Equinox.EventStore.AccessStrategy.RollingSnapshots snapshot |> Some | ||
type private CosmosResolver(useCache) = | ||
member val Cache = | ||
if useCache then | ||
let c = Equinox.Cosmos.Caching.Cache("Cli", sizeMb = 50) | ||
Equinox.Cosmos.CachingStrategy.SlidingWindow (c, TimeSpan.FromMinutes 20.) |> Some | ||
else None | ||
member __.CreateAccessStrategy snapshot = | ||
match snapshot with | ||
| None -> None | ||
| Some snapshot -> Equinox.Cosmos.AccessStrategy.Snapshot snapshot |> Some | ||
|
||
[<RequireQualifiedAccess; NoEquality; NoComparison>] | ||
type Store = | ||
| Mem of Equinox.MemoryStore.VolatileStore | ||
| Es of Equinox.EventStore.GesGateway | ||
| Cosmos of Equinox.Cosmos.EqxGateway * databaseId: string * collectionId: string | ||
|
||
type Builder(store, useCache, useUnfolds) = | ||
member __.ResolveStream | ||
( codec : Equinox.UnionCodec.IUnionEncoder<'event,byte[]>, | ||
fold: ('state -> 'event seq -> 'state), | ||
initial: 'state, | ||
snapshot: (('event -> bool) * ('state -> 'event))) = | ||
let snapshot = if useUnfolds then Some snapshot else None | ||
match store with | ||
| Store.Mem store -> | ||
Equinox.MemoryStore.MemoryStreamBuilder(store, fold, initial).Create | ||
| Store.Es gateway -> | ||
let resolver = EsResolver(useCache) | ||
Equinox.EventStore.GesStreamBuilder<'event,'state>(gateway, codec, fold, initial, ?access = resolver.CreateAccessStrategy(snapshot), ?caching = resolver.Cache).Create | ||
| Store.Cosmos (gateway, databaseId, connectionId) -> | ||
let resolver = CosmosResolver(useCache) | ||
let store = Equinox.Cosmos.EqxStore(gateway, Equinox.Cosmos.EqxCollections(databaseId, connectionId)) | ||
Equinox.Cosmos.EqxStreamBuilder<'event,'state>(store, codec, fold, initial, ?access = resolver.CreateAccessStrategy snapshot, ?caching = resolver.Cache).Create |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>netstandard2.0;net461</TargetFrameworks> | ||
<WarningLevel>5</WarningLevel> | ||
<IsTestProject>false</IsTestProject> | ||
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference> | ||
<DisableImplicitSystemValueTupleReference>true</DisableImplicitSystemValueTupleReference> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="CompositionRoot.fs" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\src\Equinox\Equinox.fsproj" /> | ||
<ProjectReference Include="..\..\..\src\Equinox.Cosmos\Equinox.Cosmos.fsproj" /> | ||
<ProjectReference Include="..\..\..\src\Equinox.EventStore\Equinox.EventStore.fsproj" /> | ||
<ProjectReference Include="..\..\..\src\Equinox.MemoryStore\Equinox.MemoryStore.fsproj" PrivateAssets="all" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<!--Handle TypeShape-restriction; would otherwise use 3.1.2.5--> | ||
<PackageReference Include="FSharp.Core" Version="4.0.0.1" Condition=" '$(TargetFramework)' == 'net461' " /> | ||
<PackageReference Include="FSharp.Core" Version="4.3.4" Condition=" '$(TargetFramework)' == 'netcoreapp2.1' " /> | ||
<PackageReference Include="Jet.JsonNet.Converters" Version="0.0.3-CI69140" /> | ||
<Reference Include="System.Runtime.Caching" Condition=" '$(TargetFramework)' != 'netstandard2.0' " /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters