diff --git a/EventFlow.sln b/EventFlow.sln index 7752ed9b5..04312f60b 100644 --- a/EventFlow.sln +++ b/EventFlow.sln @@ -61,6 +61,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SQLite", "SQLite", "{74EFCD EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventFlow.SQLite", "Source\EventFlow.SQLite\EventFlow.SQLite.csproj", "{D2B5B5CA-57C2-4354-ADB7-47A6D81AD521}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventFlow.SQLite.Tests", "Source\EventFlow.SQLite.Tests\EventFlow.SQLite.Tests.csproj", "{8FAC191C-340D-47C6-B8AE-3D57783749C4}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -139,6 +141,10 @@ Global {D2B5B5CA-57C2-4354-ADB7-47A6D81AD521}.Debug|Any CPU.Build.0 = Debug|Any CPU {D2B5B5CA-57C2-4354-ADB7-47A6D81AD521}.Release|Any CPU.ActiveCfg = Release|Any CPU {D2B5B5CA-57C2-4354-ADB7-47A6D81AD521}.Release|Any CPU.Build.0 = Release|Any CPU + {8FAC191C-340D-47C6-B8AE-3D57783749C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8FAC191C-340D-47C6-B8AE-3D57783749C4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8FAC191C-340D-47C6-B8AE-3D57783749C4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8FAC191C-340D-47C6-B8AE-3D57783749C4}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -168,6 +174,7 @@ Global {B4247230-5289-4D17-BB0F-CB2FDBABA988} = {2E9CFB92-E8E5-4466-8410-CCB5BA5CB6D1} {74EFCDE2-CB0F-49B1-9CEC-BE748EB1FBF7} = {88359036-4F35-487C-BF2C-4F31C7BC92D8} {D2B5B5CA-57C2-4354-ADB7-47A6D81AD521} = {74EFCDE2-CB0F-49B1-9CEC-BE748EB1FBF7} + {8FAC191C-340D-47C6-B8AE-3D57783749C4} = {74EFCDE2-CB0F-49B1-9CEC-BE748EB1FBF7} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {17607E2C-4E8E-45A2-85BD-0A5808E1C0F3} diff --git a/README.md b/README.md index 989f02880..2cb70e55f 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ The following list key characteristics of each version as well as its related br - 💚 `EventFlow.Redis` - 🟠 `EventFlow.RabbitMQ` - 🟢 `EventFlow.Sql` - - 🟠 `EventFlow.SQLite` + - 🟢 `EventFlow.SQLite` - 🟢 `EventFlow.TestHelpers` ### Branches diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 08d55ecf3..5cbee06c5 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,5 +1,6 @@ ### New in 1.1.1 (working version, not released yet) +* New: NuGet `EventFlow.SQLite` is now released as part of v1 and enables support for SQLite * Fix: Invoking `UseEventPersistence` now removes any previously registered event persistence. This fixes a service ordering issue in the following event store configurations - MongoDB diff --git a/Source/EventFlow.SQLite.Tests/EventFlow.SQLite.Tests.csproj b/Source/EventFlow.SQLite.Tests/EventFlow.SQLite.Tests.csproj index 9e5dfca5a..66a337527 100644 --- a/Source/EventFlow.SQLite.Tests/EventFlow.SQLite.Tests.csproj +++ b/Source/EventFlow.SQLite.Tests/EventFlow.SQLite.Tests.csproj @@ -1,22 +1,20 @@  - - netcoreapp3.1 + netcoreapp3.1;net6.0;net8.0 False + - - - - - + - + + + diff --git a/Source/EventFlow.SQLite.Tests/IntegrationTests/EventStores/SQLiteEventStoreTests.cs b/Source/EventFlow.SQLite.Tests/IntegrationTests/EventStores/SQLiteEventStoreTests.cs index 37f1d4ae4..5c02cda10 100644 --- a/Source/EventFlow.SQLite.Tests/IntegrationTests/EventStores/SQLiteEventStoreTests.cs +++ b/Source/EventFlow.SQLite.Tests/IntegrationTests/EventStores/SQLiteEventStoreTests.cs @@ -23,8 +23,6 @@ using System; using System.IO; using System.Threading; -using System.Threading.Tasks; -using EventFlow.Configuration; using EventFlow.Core; using EventFlow.Extensions; using EventFlow.MetadataProviders; @@ -32,6 +30,7 @@ using EventFlow.SQLite.Extensions; using EventFlow.TestHelpers; using EventFlow.TestHelpers.Suites; +using Microsoft.Extensions.DependencyInjection; using NUnit.Framework; namespace EventFlow.SQLite.Tests.IntegrationTests.EventStores @@ -41,19 +40,20 @@ public class SQLiteEventStoreTests : TestSuiteForEventStore { private string _databasePath; - protected override IRootResolver CreateRootResolver(IEventFlowOptions eventFlowOptions) + protected override IServiceProvider Configure(IEventFlowOptions eventFlowOptions) { _databasePath = Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid():N}.sqlite"); using (File.Create(_databasePath)){ } - var resolver = eventFlowOptions + eventFlowOptions .AddMetadataProvider() .ConfigureSQLite(SQLiteConfiguration.New.SetConnectionString($"Data Source={_databasePath};Version=3;")) - .UseSQLiteEventStore() - .CreateResolver(); + .UseSQLiteEventStore(); - var connection = resolver.Resolve(); + var serviceProvider = base.Configure(eventFlowOptions); + + var connection = serviceProvider.GetRequiredService(); const string sqlCreateTable = @" CREATE TABLE [EventFlow]( [GlobalSequenceNumber] [INTEGER] PRIMARY KEY ASC NOT NULL, @@ -70,10 +70,10 @@ CREATE UNIQUE INDEX [IX_EventFlow_AggregateId_AggregateSequenceNumber] ON [Event [AggregateId] ASC, [AggregateSequenceNumber] ASC )"; - connection.ExecuteAsync(Label.Named("create-table"), CancellationToken.None, sqlCreateTable, null).Wait(); - connection.ExecuteAsync(Label.Named("create-index"), CancellationToken.None, sqlCreateIndex, null).Wait(); + connection.ExecuteAsync(Label.Named("create-table"), string.Empty, CancellationToken.None, sqlCreateTable, null).Wait(); + connection.ExecuteAsync(Label.Named("create-index"), string.Empty, CancellationToken.None, sqlCreateIndex, null).Wait(); - return resolver; + return serviceProvider; } [TearDown] diff --git a/Source/EventFlow.SQLite.Tests/IntegrationTests/ReadStores/QueryHandlers/SQLiteThingyGetMessagesQueryHandler.cs b/Source/EventFlow.SQLite.Tests/IntegrationTests/ReadStores/QueryHandlers/SQLiteThingyGetMessagesQueryHandler.cs index c6205167c..72ed16db8 100644 --- a/Source/EventFlow.SQLite.Tests/IntegrationTests/ReadStores/QueryHandlers/SQLiteThingyGetMessagesQueryHandler.cs +++ b/Source/EventFlow.SQLite.Tests/IntegrationTests/ReadStores/QueryHandlers/SQLiteThingyGetMessagesQueryHandler.cs @@ -47,6 +47,7 @@ public async Task> ExecuteQueryAsync(ThingyGe { var readModels = await _sqLiteConnection.QueryAsync( Label.Named("sqlite-fetch-thingy-message-read-model"), + string.Empty, cancellationToken, "SELECT * FROM [ReadModel-ThingyMessage] WHERE ThingyId = @ThingyId", new { ThingyId = query.ThingyId.Value }) diff --git a/Source/EventFlow.SQLite.Tests/IntegrationTests/ReadStores/QueryHandlers/SQLiteThingyGetQueryHandler.cs b/Source/EventFlow.SQLite.Tests/IntegrationTests/ReadStores/QueryHandlers/SQLiteThingyGetQueryHandler.cs index 81579da55..12eaed3cc 100644 --- a/Source/EventFlow.SQLite.Tests/IntegrationTests/ReadStores/QueryHandlers/SQLiteThingyGetQueryHandler.cs +++ b/Source/EventFlow.SQLite.Tests/IntegrationTests/ReadStores/QueryHandlers/SQLiteThingyGetQueryHandler.cs @@ -46,6 +46,7 @@ public async Task ExecuteQueryAsync(ThingyGetQuery query, CancellationTo { var readModels = await _sqLiteConnection.QueryAsync( Label.Named("sqlite-fetch-test-read-model"), + string.Empty, cancellationToken, "SELECT * FROM [ReadModel-ThingyAggregate] WHERE AggregateId = @AggregateId", new { AggregateId = query.ThingyId.Value }) diff --git a/Source/EventFlow.SQLite.Tests/IntegrationTests/ReadStores/QueryHandlers/SQLiteThingyGetVersionQueryHandler.cs b/Source/EventFlow.SQLite.Tests/IntegrationTests/ReadStores/QueryHandlers/SQLiteThingyGetVersionQueryHandler.cs index 37936861d..e5bbe5f7c 100644 --- a/Source/EventFlow.SQLite.Tests/IntegrationTests/ReadStores/QueryHandlers/SQLiteThingyGetVersionQueryHandler.cs +++ b/Source/EventFlow.SQLite.Tests/IntegrationTests/ReadStores/QueryHandlers/SQLiteThingyGetVersionQueryHandler.cs @@ -45,6 +45,7 @@ public SQLiteThingyGetVersionQueryHandler( { var readModels = await _sqLiteConnection.QueryAsync( Label.Named("sqlite-fetch-test-read-model"), + string.Empty, cancellationToken, "SELECT * FROM [ReadModel-ThingyAggregate] WHERE AggregateId = @AggregateId", new { AggregateId = query.ThingyId.Value }) diff --git a/Source/EventFlow.SQLite.Tests/IntegrationTests/ReadStores/ReadModels/SQLiteThingyMessageReadModel.cs b/Source/EventFlow.SQLite.Tests/IntegrationTests/ReadStores/ReadModels/SQLiteThingyMessageReadModel.cs index 4482e3dd6..a16cbab7d 100644 --- a/Source/EventFlow.SQLite.Tests/IntegrationTests/ReadStores/ReadModels/SQLiteThingyMessageReadModel.cs +++ b/Source/EventFlow.SQLite.Tests/IntegrationTests/ReadStores/ReadModels/SQLiteThingyMessageReadModel.cs @@ -22,6 +22,8 @@ using System.ComponentModel.DataAnnotations.Schema; using System.Linq; +using System.Threading; +using System.Threading.Tasks; using EventFlow.Aggregates; using EventFlow.ReadStores; using EventFlow.Sql.ReadModels.Attributes; @@ -43,19 +45,29 @@ public class SQLiteThingyMessageReadModel : IReadModel, public string Message { get; set; } - public void Apply(IReadModelContext context, IDomainEvent domainEvent) + public Task ApplyAsync( + IReadModelContext context, + IDomainEvent domainEvent, + CancellationToken cancellationToken) { ThingyId = domainEvent.AggregateIdentity.Value; Message = domainEvent.AggregateEvent.ThingyMessage.Message; + + return Task.CompletedTask; } - public void Apply(IReadModelContext context, IDomainEvent domainEvent) + public Task ApplyAsync( + IReadModelContext context, + IDomainEvent domainEvent, + CancellationToken cancellationToken) { ThingyId = domainEvent.AggregateIdentity.Value; var messageId = new ThingyMessageId(context.ReadModelId); var thingyMessage = domainEvent.AggregateEvent.ThingyMessages.Single(m => m.Id == messageId); Message = thingyMessage.Message; + + return Task.CompletedTask; } public ThingyMessage ToThingyMessage() diff --git a/Source/EventFlow.SQLite.Tests/IntegrationTests/ReadStores/ReadModels/SQliteThingyReadModel.cs b/Source/EventFlow.SQLite.Tests/IntegrationTests/ReadStores/ReadModels/SQliteThingyReadModel.cs index 9d6e500e6..db56a0e88 100644 --- a/Source/EventFlow.SQLite.Tests/IntegrationTests/ReadStores/ReadModels/SQliteThingyReadModel.cs +++ b/Source/EventFlow.SQLite.Tests/IntegrationTests/ReadStores/ReadModels/SQliteThingyReadModel.cs @@ -21,6 +21,8 @@ // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. using System.ComponentModel.DataAnnotations.Schema; +using System.Threading; +using System.Threading.Tasks; using EventFlow.Aggregates; using EventFlow.ReadStores; using EventFlow.Sql.ReadModels.Attributes; @@ -45,19 +47,34 @@ public class SQLiteThingyReadModel : IReadModel, [SqlReadModelVersionColumn] public int Version { get; set; } - public void Apply(IReadModelContext context, IDomainEvent domainEvent) + public Task ApplyAsync( + IReadModelContext context, + IDomainEvent domainEvent, + CancellationToken cancellationToken) { PingsReceived++; + + return Task.CompletedTask; } - public void Apply(IReadModelContext context, IDomainEvent domainEvent) + public Task ApplyAsync( + IReadModelContext context, + IDomainEvent domainEvent, + CancellationToken cancellationToken) { DomainErrorAfterFirstReceived = true; + + return Task.CompletedTask; } - public void Apply(IReadModelContext context, IDomainEvent domainEvent) + public Task ApplyAsync( + IReadModelContext context, + IDomainEvent domainEvent, + CancellationToken cancellationToken) { context.MarkForDeletion(); + + return Task.CompletedTask; } public Thingy ToThingy() diff --git a/Source/EventFlow.SQLite.Tests/IntegrationTests/ReadStores/SQLiteReadStoreTests.cs b/Source/EventFlow.SQLite.Tests/IntegrationTests/ReadStores/SQLiteReadStoreTests.cs index 27cc39a76..f4bac0801 100644 --- a/Source/EventFlow.SQLite.Tests/IntegrationTests/ReadStores/SQLiteReadStoreTests.cs +++ b/Source/EventFlow.SQLite.Tests/IntegrationTests/ReadStores/SQLiteReadStoreTests.cs @@ -23,7 +23,6 @@ using System; using System.IO; using System.Threading; -using EventFlow.Configuration; using EventFlow.Core; using EventFlow.Extensions; using EventFlow.SQLite.Connections; @@ -31,9 +30,9 @@ using EventFlow.SQLite.Tests.IntegrationTests.ReadStores.QueryHandlers; using EventFlow.SQLite.Tests.IntegrationTests.ReadStores.ReadModels; using EventFlow.TestHelpers; -using EventFlow.TestHelpers.Aggregates; using EventFlow.TestHelpers.Aggregates.Entities; using EventFlow.TestHelpers.Suites; +using Microsoft.Extensions.DependencyInjection; using NUnit.Framework; namespace EventFlow.SQLite.Tests.IntegrationTests.ReadStores @@ -45,24 +44,25 @@ public class SQLiteReadStoreTests : TestSuiteForReadModelStore private string _databasePath; - protected override IRootResolver CreateRootResolver(IEventFlowOptions eventFlowOptions) + protected override IServiceProvider Configure(IEventFlowOptions eventFlowOptions) { _databasePath = Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid():N}.sqlite"); using (File.Create(_databasePath)) { } - var resolver = eventFlowOptions - .RegisterServices(sr => sr.RegisterType(typeof(ThingyMessageLocator))) + eventFlowOptions + .RegisterServices(sr => sr.AddTransient(typeof(ThingyMessageLocator))) .ConfigureSQLite(SQLiteConfiguration.New.SetConnectionString($"Data Source={_databasePath};Version=3;")) .UseSQLiteReadModel() .UseSQLiteReadModel() .AddQueryHandlers( typeof(SQLiteThingyGetQueryHandler), typeof(SQLiteThingyGetVersionQueryHandler), - typeof(SQLiteThingyGetMessagesQueryHandler)) - .CreateResolver(); + typeof(SQLiteThingyGetMessagesQueryHandler)); - var connection = resolver.Resolve(); + var serviceProvider = base.Configure(eventFlowOptions); + + var connection = serviceProvider.GetRequiredService(); const string sqlThingyAggregate = @" CREATE TABLE [ReadModel-ThingyAggregate]( [Id] [INTEGER] PRIMARY KEY ASC, @@ -79,10 +79,10 @@ [ThingyId] [nvarchar](64) NOT NULL, [MessageId] [nvarchar](64) NOT NULL, [Message] [nvarchar](512) NOT NULL )"; - connection.ExecuteAsync(Label.Named("create-table"), CancellationToken.None, sqlThingyAggregate, null).Wait(); - connection.ExecuteAsync(Label.Named("create-table"), CancellationToken.None, sqlThingyMessage, null).Wait(); + connection.ExecuteAsync(Label.Named("create-table"), string.Empty, CancellationToken.None, sqlThingyAggregate, null).Wait(); + connection.ExecuteAsync(Label.Named("create-table"), string.Empty, CancellationToken.None, sqlThingyMessage, null).Wait(); - return resolver; + return serviceProvider; } [TearDown] diff --git a/Source/EventFlow.SQLite/EventFlow.SQLite.csproj b/Source/EventFlow.SQLite/EventFlow.SQLite.csproj index 68987452c..ed9480299 100644 --- a/Source/EventFlow.SQLite/EventFlow.SQLite.csproj +++ b/Source/EventFlow.SQLite/EventFlow.SQLite.csproj @@ -9,9 +9,9 @@ - + - +