From 170aee31479fa7273187dc91fba19ddf0db12d6b Mon Sep 17 00:00:00 2001 From: Alexey Zimarev Date: Mon, 13 Nov 2023 10:56:59 +0100 Subject: [PATCH] Cleanup --- .github/workflows/preview.yml | 2 -- .github/workflows/publish.yml | 4 ++- .../EventStore/StoreFunctions.cs | 4 +-- .../RegistrationExtensions.cs | 18 +++++++++++-- .../MongoOperationBuilder.cs | 22 ++++++++-------- .../Operations/BulkBuilder.cs | 4 +-- .../Operations/UpdateBuilder.cs | 26 +++++-------------- 7 files changed, 41 insertions(+), 39 deletions(-) diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index d78092c5..5184c7b8 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -10,8 +10,6 @@ on: jobs: nuget: runs-on: self-hosted -# container: -# image: mcr.microsoft.com/dotnet/sdk:8.0 env: DOTNET_INSTALL_DIR: ~/.dotnet diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index eef322b6..58d49ff7 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -9,7 +9,9 @@ on: jobs: nuget: - runs-on: ubuntu-latest + runs-on: self-hosted + env: + DOTNET_INSTALL_DIR: ~/.dotnet steps: - uses: actions/checkout@v3 diff --git a/src/Core/src/Eventuous.Persistence/EventStore/StoreFunctions.cs b/src/Core/src/Eventuous.Persistence/EventStore/StoreFunctions.cs index 74c6717e..e9bf0aaa 100644 --- a/src/Core/src/Eventuous.Persistence/EventStore/StoreFunctions.cs +++ b/src/Core/src/Eventuous.Persistence/EventStore/StoreFunctions.cs @@ -17,7 +17,7 @@ public static class StoreFunctions { /// Cancellation token /// Append events result /// Any exception that occurred in the event store - /// Gets thrown if the expected stream version mismatches with + /// Gets thrown if the expected stream version mismatches with the given original stream version public static async Task Store( this IEventWriter eventWriter, StreamName streamName, @@ -65,7 +65,7 @@ StreamEvent ToStreamEvent(object evt, int position) { /// Cancellation token /// Aggregate type /// Append event result - /// + /// Gets thrown if the expected stream version mismatches with the given original stream version public static async Task Store( this IEventWriter eventWriter, StreamName streamName, diff --git a/src/Core/src/Eventuous.Producers/RegistrationExtensions.cs b/src/Core/src/Eventuous.Producers/RegistrationExtensions.cs index 35b11b4c..24675d92 100644 --- a/src/Core/src/Eventuous.Producers/RegistrationExtensions.cs +++ b/src/Core/src/Eventuous.Producers/RegistrationExtensions.cs @@ -11,7 +11,12 @@ namespace Microsoft.Extensions.DependencyInjection; [PublicAPI] public static class RegistrationExtensions { + [Obsolete("Use AddProducer instead")] public static void AddEventProducer(this IServiceCollection services, T producer) where T : class, IEventProducer { + services.AddProducer(producer); + } + + public static void AddProducer(this IServiceCollection services, T producer) where T : class, IEventProducer { services.TryAddSingleton(producer); services.TryAddSingleton(sp => sp.GetRequiredService()); @@ -20,13 +25,22 @@ public static void AddEventProducer(this IServiceCollection services, T produ } } - public static void AddEventProducer(this IServiceCollection services, Func getProducer) - where T : class, IEventProducer { + [Obsolete("Use AddProducer instead")] + public static void AddEventProducer(this IServiceCollection services, Func getProducer) where T : class, IEventProducer { + services.AddProducer(getProducer); + } + + public static void AddProducer(this IServiceCollection services, Func getProducer) where T : class, IEventProducer { services.TryAddSingleton(getProducer); AddCommon(services); } + [Obsolete("Use AddProducer instead")] public static void AddEventProducer(this IServiceCollection services) where T : class, IEventProducer { + services.AddProducer(); + } + + public static void AddProducer(this IServiceCollection services) where T : class, IEventProducer { services.TryAddSingleton(); AddCommon(services); } diff --git a/src/Mongo/src/Eventuous.Projections.MongoDB/MongoOperationBuilder.cs b/src/Mongo/src/Eventuous.Projections.MongoDB/MongoOperationBuilder.cs index befedacd..60045bff 100644 --- a/src/Mongo/src/Eventuous.Projections.MongoDB/MongoOperationBuilder.cs +++ b/src/Mongo/src/Eventuous.Projections.MongoDB/MongoOperationBuilder.cs @@ -15,27 +15,27 @@ public partial class MongoOperationBuilder public InsertManyBuilder InsertMany => new(); public DeleteOneBuilder DeleteOne => new(); public DeleteManyBuilder DeleteMany => new(); - public BulkWriteBuilder Bulk => new(); - + public BulkWriteBuilder Bulk => new(); + public class MongoBulkOperationBuilders { - MongoBulkOperationBuilders() {} + MongoBulkOperationBuilders() { } internal static MongoBulkOperationBuilders Instance { get; } = new(); // ReSharper disable once MemberCanBeMadeStatic.Global - public UpdateOneBuilder UpdateOne => new(); + public UpdateOneBuilder UpdateOne => new(); // ReSharper disable once MemberCanBeMadeStatic.Global - public UpdateManyBuilder UpdateMany => new(); + public UpdateManyBuilder UpdateMany => new(); // ReSharper disable once MemberCanBeMadeStatic.Global - public InsertOneBuilder InsertOne => new(); + public InsertOneBuilder InsertOne => new(); // ReSharper disable once MemberCanBeMadeStatic.Global - public DeleteOneBuilder DeleteOne => new(); + public DeleteOneBuilder DeleteOne => new(); // ReSharper disable once MemberCanBeMadeStatic.Global - public DeleteManyBuilder DeleteMany => new(); + public DeleteManyBuilder DeleteMany => new(); } - + public interface IMongoProjectorBuilder { ProjectTypedEvent Build(); } - + public interface IMongoBulkBuilderFactory { BuildWriteModel GetBuilder(); } @@ -46,7 +46,7 @@ public class FilterBuilder { public Func, FilterDefinition> GetFilter => Ensure.NotNull(_filterFunc, "Filter function"); public void Filter(BuildFilter buildFilter) - => _filterFunc = evt => buildFilter(evt, Builders.Filter); + => _filterFunc = evt => buildFilter(evt, Builders.Filter); public void Filter(Func, T, bool> filter) => _filterFunc = evt => new ExpressionFilterDefinition(x => filter(evt, x)); diff --git a/src/Mongo/src/Eventuous.Projections.MongoDB/Operations/BulkBuilder.cs b/src/Mongo/src/Eventuous.Projections.MongoDB/Operations/BulkBuilder.cs index 294535cc..8f373554 100644 --- a/src/Mongo/src/Eventuous.Projections.MongoDB/Operations/BulkBuilder.cs +++ b/src/Mongo/src/Eventuous.Projections.MongoDB/Operations/BulkBuilder.cs @@ -27,8 +27,8 @@ public BulkWriteBuilder Configure(Action configure) { ProjectTypedEvent IMongoProjectorBuilder.Build() => GetHandler(async (ctx, collection, token) => { var options = Options.New(_configureOptions); - var models = await _builders.Select(build => build(ctx)).WhenAll(); - await collection.BulkWriteAsync(models, options, token); + var models = await _builders.Select(build => build(ctx)).WhenAll().NoContext(); + await collection.BulkWriteAsync(models, options, token).NoContext(); }); } } \ No newline at end of file diff --git a/src/Mongo/src/Eventuous.Projections.MongoDB/Operations/UpdateBuilder.cs b/src/Mongo/src/Eventuous.Projections.MongoDB/Operations/UpdateBuilder.cs index ad62667f..018840df 100644 --- a/src/Mongo/src/Eventuous.Projections.MongoDB/Operations/UpdateBuilder.cs +++ b/src/Mongo/src/Eventuous.Projections.MongoDB/Operations/UpdateBuilder.cs @@ -25,7 +25,7 @@ public UpdateOneBuilder DefaultId() ProjectTypedEvent IMongoProjectorBuilder.Build() => GetHandler( async (ctx, collection, token) => { - var (update, options) = await GetUpdateWithOptions(ctx); + var (update, options) = await GetUpdateWithOptions(ctx).NoContext(); var filter = FilterBuilder.GetFilter(ctx); // TODO: Make this an option (idempotence based on commit position) // var filter = Builders.Filter.And( @@ -33,18 +33,12 @@ ProjectTypedEvent IMongoProjectorBuilder.Build() // FilterBuilder.GetFilter(ctx) // ); - await collection - .UpdateOneAsync( - filter, - update, - options, - token - ); + await collection.UpdateOneAsync(filter, update, options, token).NoContext(); } ); BuildWriteModel IMongoBulkBuilderFactory.GetBuilder() => async ctx => { - var (update, options) = await GetUpdateWithOptions(ctx); + var (update, options) = await GetUpdateWithOptions(ctx).NoContext(); return new UpdateOneModel(FilterBuilder.GetFilter(ctx), update) { Collation = options.Collation, @@ -59,20 +53,14 @@ public class UpdateManyBuilder : UpdateBuilder, IMongoProject ProjectTypedEvent IMongoProjectorBuilder.Build() => GetHandler( async (ctx, collection, token) => { - var (update, options) = await GetUpdateWithOptions(ctx); - - await collection.UpdateManyAsync( - FilterBuilder.GetFilter(ctx), - update, - options, - token - ) - .NoContext(); + var (update, options) = await GetUpdateWithOptions(ctx).NoContext(); + + await collection.UpdateManyAsync(FilterBuilder.GetFilter(ctx), update, options, token).NoContext(); } ); BuildWriteModel IMongoBulkBuilderFactory.GetBuilder() => async ctx => { - var (update, options) = await GetUpdateWithOptions(ctx); + var (update, options) = await GetUpdateWithOptions(ctx).NoContext(); return new UpdateManyModel(FilterBuilder.GetFilter(ctx), update) { Collation = options.Collation,