-
-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
985 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
# Configure EventFlow | ||
|
||
To get EventFlow up and running, you need an instance of `IEventFlowOptions` | ||
which is created using the `EventFlowOptions.New` static property. From here | ||
you use extension methods and extension methods to setup EventFlow to your | ||
needs. | ||
|
||
## Basic example | ||
|
||
Here's the very minimum that you will need to get EventFlow up and running | ||
with a in-memory configuration. | ||
|
||
```csharp | ||
using (var resolver = EventFlowOptions.New | ||
.AddDefaults(typeof(YouApplication).Assembly) | ||
.CreateResolver()) | ||
{ | ||
// Do stuff | ||
// Don't dispose the 'resolver' until application shutdown! | ||
} | ||
``` | ||
|
||
First the default types and services are registered from your application using | ||
the `AddDefaults(...)` method. | ||
|
||
Versioned types, types that might exist in multiple versions as the application | ||
evolves, are loaded into EventFlow. | ||
|
||
* [Event types](./ValueObjects.md) are loaded into the `IEventDefinitionService` | ||
* [Command types](./Commands.md) are loaded into the `ICommandDefinitionService` | ||
* [Job types](./Jobs.md) are loaded into the `IJobDefinitionService` | ||
|
||
Services with known interfaces are registered in the built-in IoC container. | ||
|
||
* Command handlers, i.e., `ICommandHandler<,,>` implementations | ||
* Meta data providers, i.e., `IMetadataProvider` implementations | ||
* Subscribers, i.e., `ISubscribeSynchronousTo<,,>` and `ISubscribeSynchronousToAll` implementations | ||
* Event upgraders, i.e., `IEventUpgrader<,>` implementations | ||
* Query handlers, i.e., `IQueryHandler<,>` implementations | ||
|
||
Note that you can use another IoC container, e.g. Autofac using the | ||
`EventFlow.Autofac` NuGet package. If using this package, you can even skip | ||
the `CreateResolver()` call, as EventFlow will automatically configure itself | ||
when the container is ready. | ||
|
||
The final step of configuring EventFlow, is to call `CreateResolver()` which | ||
configures the IoC container and its through this that you can access e.g. | ||
the `ICommandBus` which allows you to publish commands. | ||
|
||
## Configuration methods | ||
|
||
Note that almost every single one of the configuration methods on | ||
`IEventFlowOptions` is implemented as extension methods and you will need | ||
to add the appropriate namespace, e.g. `EventFlow.Extensions`. | ||
|
||
### Versioned types | ||
|
||
* `AddEvents` | ||
* `AddCommands` | ||
* `AddJobs` | ||
|
||
### Services | ||
|
||
**General** | ||
* `RegisterServices`, configure other services or override existing | ||
* `UseServiceRegistration`, use an alternative IoC container | ||
* `UseAutofacContainerBuilder` in NuGet package `EventFlow.Autofac` | ||
* `RegisterModule`, register modules | ||
|
||
**Aggregates** | ||
* `UseResolverAggregateRootFactory` | ||
* `UseAutofacAggregateRootFactory` in the NuGet package `EventFlow.Autofac` | ||
|
||
* `AddAggregateRoots`, add aggregates if using the | ||
`UseResolverAggregateRootFactory` or `UseAutofacAggregateRootFactory` | ||
**Command handlers** | ||
* `AddCommandHandlers` | ||
|
||
**Subscribers** | ||
* `AddSubscribers` | ||
|
||
**Event upgraders** | ||
* `AddEventUpgraders` | ||
|
||
**Metadata providers** | ||
* `AddMetadataProviders` | ||
|
||
**Event stores** | ||
* `UseEventStore` | ||
* `UseFilesEventStore` | ||
* `UseEventStoreEventStore` in NuGet package `EventFlow.EventStores.EventStore` | ||
* `UseMssqlEventStore` in NuGet package `EventFlow.EventStores.MsSql` | ||
|
||
**Read models and stores** | ||
* `UseReadStoreFor<TReadStore, TReadModel>` | ||
* `UseReadStoreFor<TReadStore, TReadModel, TReadModelLocator>>` | ||
* `UseInMemoryReadStoreFor<TReadModel>` | ||
* `UseInMemoryReadStoreFor<TReadModel, TReadModelLocator>` | ||
|
||
**Jobs and schedulers** | ||
* `UseHangfireJobScheduler` in the NuGet package `EventFlow.Hangfire` | ||
|
||
**Queries and handlers** | ||
* `AddQueryHandlers` |
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
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
58 changes: 58 additions & 0 deletions
58
Source/EventFlow.Tests/UnitTests/Provided/Specifications/AtLeastSpecificationTests.cs
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,58 @@ | ||
// The MIT License (MIT) | ||
// | ||
// Copyright (c) 2015 Rasmus Mikkelsen | ||
// https://github.com/rasmus/EventFlow | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
// this software and associated documentation files (the "Software"), to deal in | ||
// the Software without restriction, including without limitation the rights to | ||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
// the Software, and to permit persons to whom the Software is furnished to do so, | ||
// subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
using EventFlow.Extensions; | ||
using EventFlow.Tests.UnitTests.Specifications; | ||
using FluentAssertions; | ||
using NUnit.Framework; | ||
|
||
namespace EventFlow.Tests.UnitTests.Provided.Specifications | ||
{ | ||
public class AtLeastSpecificationTests | ||
{ | ||
[TestCase(1, 1, false)] | ||
[TestCase(1, 2, true)] | ||
[TestCase(1, 3, true)] | ||
[TestCase(1, 4, true)] | ||
[TestCase(1, 5, true)] | ||
[TestCase(3, 1, false)] | ||
[TestCase(3, 2, false)] | ||
[TestCase(3, 3, false)] | ||
[TestCase(3, 4, true)] | ||
[TestCase(3, 5, true)] | ||
public void AtLeast_Returns_Correctly(int requiredSpecifications, int obj, bool expectedIsSatisfiedBy) | ||
{ | ||
// Arrange | ||
var isAbove1 = new TestSpecifications.IsAboveSpecification(1); | ||
var isAbove2 = new TestSpecifications.IsAboveSpecification(2); | ||
var isAbove3 = new TestSpecifications.IsAboveSpecification(3); | ||
var isAbove4 = new TestSpecifications.IsAboveSpecification(4); | ||
var atLeast = new[] { isAbove1, isAbove2, isAbove3, isAbove4 }.AtLeast(requiredSpecifications); | ||
|
||
// Act | ||
var isSatisfiedBy = atLeast.IsSatisfiedBy(obj); | ||
|
||
// Assert | ||
isSatisfiedBy.Should().Be(expectedIsSatisfiedBy, string.Join(", ", atLeast.WhyIsNotStatisfiedBy(obj))); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.