Beispiel #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AsyncCommandServiceParallelTap{TRoot,TKey}"/> class.
 /// </summary>
 /// <param name="inner">The <see cref="IAsyncCommandService{TRoot, TIdentity}"/> to be decorated.</param>
 /// <param name="tap">The tap <see cref="IAsyncCommandService{TRoot, TIdentity}"/>, where commands will be duplicated.</param>
 /// <param name="logger">The logger where tap exceptions should be written.</param>
 /// <exception cref="ArgumentNullException"><paramref name="inner"/> is <c>null</c>.
 /// -or- <paramref name="tap"/> is <c>null</c>.</exception>
 public AsyncCommandServiceParallelTap(IAsyncCommandService <TRoot, TIdentity> inner, IAsyncCommandService <TRoot, TIdentity> tap, ILogger logger)
     : base(inner)
 {
     Logger = logger;
     Tap    = (tap ?? throw new ArgumentNullException(nameof(tap)))
              .Catch((Exception ex) =>
     {
         Logger?.LogWarning(0, ex, "An exception ocurred in the 'tap' command service.");
         return(true);
     });
 }
        public void ToSync_ShouldValidateParameter()
        {
            // Arrange
            IAsyncCommandService <FakeEntity <int>, int> inner = null;

            // Act
            Action action = () => inner.ToSync();

            // Assert
            action.Should().Throw <ArgumentNullException>();
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ComposedAsyncRepository{TRoot,TKey}"/> class.
 /// </summary>
 /// <param name="queryService">The <see cref="IAsyncQueryService{TRoot, TIdentity}"/> to be joined.</param>
 /// <param name="commandService">The <see cref="IAsyncCommandService{TRoot, TIdentity}"/>to be joined.</param>
 /// <exception cref="ArgumentNullException"><paramref name="queryService"/> is <c>null</c>.
 /// -or- <paramref name="commandService"/> is <c>null</c>.</exception>
 public ComposedAsyncRepository(IAsyncQueryService <TRoot, TIdentity> queryService, IAsyncCommandService <TRoot, TIdentity> commandService)
 {
     QueryService   = queryService ?? throw new ArgumentNullException(nameof(queryService));
     CommandService = commandService ?? throw new ArgumentNullException(nameof(commandService));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AsyncCommandServiceDecorator{TRoot, TIdentity}"/> class,
 /// decorating the given <see cref="IAsyncCommandService{TRoot, TIdentity}"/>.
 /// </summary>
 /// <param name="inner">The <see cref="IAsyncCommandService{TRoot, TIdentity}"/> to be decorated.</param>
 /// <exception cref="ArgumentNullException"><paramref name="inner"/> is <c>null</c>.</exception>
 public AsyncCommandServiceDecorator(IAsyncCommandService <TRoot, TIdentity> inner)
 {
     Inner = inner ?? throw new ArgumentNullException(nameof(inner));
 }
Beispiel #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AsyncCommandServiceParallelTap{TRoot,TKey}"/> class.
 /// </summary>
 /// <param name="inner">The <see cref="IAsyncCommandService{TRoot, TIdentity}"/> to be decorated.</param>
 /// <param name="tap">The tap <see cref="IAsyncCommandService{TRoot, TIdentity}"/>, where commands will be duplicated.</param>
 /// <exception cref="ArgumentNullException"><paramref name="inner"/> is <c>null</c>.
 /// -or- <paramref name="tap"/> is <c>null</c>.</exception>
 public AsyncCommandServiceParallelTap(IAsyncCommandService <TRoot, TIdentity> inner, IAsyncCommandService <TRoot, TIdentity> tap)
     : this(inner, tap, null)
 {
 }
 /// <summary>
 /// Wraps the given <see cref="IAsyncCommandService{TRoot, TIdentity}"/> in a sequential <see cref="AsyncCommandServiceTap{TRoot, TIdentity}"/>,
 /// mirroring all commands to the other given <see cref="IAsyncCommandService{TRoot, TIdentity}"/>.
 /// </summary>
 /// <typeparam name="TRoot">The type of entities in the data store.</typeparam>
 /// <typeparam name="TIdentity">The type of the unique identity value of the entitites in the data store.</typeparam>
 /// <param name="inner">The <see cref="IAsyncCommandService{TRoot, TIdentity}"/> to be wrapped.</param>
 /// <param name="tap">The tap <see cref="IAsyncCommandService{TRoot, TIdentity}"/>, where commands will be mirrored.</param>
 /// <returns>A new <see cref="AsyncCommandServiceTap{TRoot, TIdentity}"/> wrapping the two given <see cref="IAsyncCommandService{TRoot, TIdentity}"/> instances.</returns>
 /// <exception cref="ArgumentNullException"><paramref name="inner"/> is <c>null</c>.
 /// -or- <paramref name="tap"/> is <c>null</c>.</exception>
 public static IAsyncCommandService <TRoot, TIdentity> WithSequentialTap <TRoot, TIdentity>(this IAsyncCommandService <TRoot, TIdentity> inner, IAsyncCommandService <TRoot, TIdentity> tap)
     where TRoot : IAggregateRoot <TIdentity>
     where TIdentity : IEquatable <TIdentity>, IComparable <TIdentity>
 {
     return(new AsyncCommandServiceTap <TRoot, TIdentity>(inner, tap));
 }
 /// <summary>
 /// Wraps the given <see cref="IAsyncCommandService{TRoot, TIdentity}"/> in a parallel <see cref="AsyncCommandServiceTap{TRoot, TIdentity}"/>,
 /// mirroring all commands to the other given <see cref="IAsyncCommandService{TRoot, TIdentity}"/>.
 /// </summary>
 /// <typeparam name="TRoot">The type of entities in the data store.</typeparam>
 /// <typeparam name="TIdentity">The type of the unique identity value of the entitites in the data store.</typeparam>
 /// <param name="inner">The <see cref="IAsyncCommandService{TRoot, TIdentity}"/> to be wrapped.</param>
 /// <param name="tap">The tap <see cref="IAsyncCommandService{TRoot, TIdentity}"/>, where commands will be mirrored.</param>
 /// <param name="logger">The <see cref="ILogger"/> to which any tap exceptions should be written.</param>
 /// <returns>A new <see cref="AsyncCommandServiceTap{TRoot, TIdentity}"/> wrapping the two given <see cref="IAsyncCommandService{TRoot, TIdentity}"/> instances.</returns>
 /// <exception cref="ArgumentNullException"><paramref name="inner"/> is <c>null</c>.
 /// -or- <paramref name="tap"/> is <c>null</c>.</exception>
 public static IAsyncCommandService <TRoot, TIdentity> WithParallelTap <TRoot, TIdentity>(this IAsyncCommandService <TRoot, TIdentity> inner, IAsyncCommandService <TRoot, TIdentity> tap, ILogger logger)
     where TRoot : IAggregateRoot <TIdentity>
     where TIdentity : IEquatable <TIdentity>, IComparable <TIdentity>
 {
     return(new AsyncCommandServiceParallelTap <TRoot, TIdentity>(inner, tap, logger));
 }
 /// <summary>
 /// Wraps the given <see cref="IAsyncCommandService{TRoot, TIdentity}"/> in a <see cref="AsyncCommandServiceExceptionHandler{TRoot, TIdentity, TException}"/>.
 /// </summary>
 /// <typeparam name="TRoot">The type of entities in the data store.</typeparam>
 /// <typeparam name="TIdentity">The type of the unique identity value of the entities in the data store.</typeparam>
 /// <typeparam name="TException">"The type of exception to be handled.</typeparam>
 /// <param name="inner">The <see cref="IAsyncCommandService{TRoot, TIdentity}"/> to be wrapped.</param>
 /// <param name="handler">The handler that will be called when an exception is caught.
 /// This delegate must return a flag indicating if the exception was handled.
 /// If it wasn't, it will be re-thrown after processing.</param>
 /// <returns>A new <see cref="AsyncCommandServiceExceptionHandler{TRoot, TIdentity, TException}"/> wrapping the given <see cref="IAsyncCommandService{TRoot, TIdentity}"/>.</returns>
 /// <exception cref="ArgumentNullException"><paramref name="inner"/> is <c>null</c>.
 /// -or- <paramref name="handler"/> is <c>null</c>.</exception>
 public static IAsyncCommandService <TRoot, TIdentity> Catch <TRoot, TIdentity, TException>(this IAsyncCommandService <TRoot, TIdentity> inner, Func <TException, bool> handler)
     where TRoot : IAggregateRoot <TIdentity>
     where TIdentity : IEquatable <TIdentity>, IComparable <TIdentity>
     where TException : Exception
 {
     return(new AsyncCommandServiceExceptionHandler <TRoot, TIdentity, TException>(inner, handler));
 }
 /// <summary>
 /// Joins the given <see cref="IAsyncQueryService{TRoot, TIdentity}"/> and <see cref="IAsyncCommandService{TRoot, TIdentity}"/> into a single <see cref="ComposedAsyncRepository{TRoot, TIdentity}"/>.
 /// </summary>
 /// <typeparam name="TRoot">The type of entities in the data store.</typeparam>
 /// <typeparam name="TIdentity">The type of the unique identity value of the entities in the data store.</typeparam>
 /// <param name="commandService">The <see cref="IAsyncCommandService{TRoot, TIdentity}"/>to be joined.</param>
 /// <param name="queryService">The <see cref="IAsyncQueryService{TRoot, TIdentity}"/> to be joined.</param>
 /// <returns>A new <see cref="ComposedAsyncRepository{TRoot, TIdentity}"/> joining the given <see cref="IAsyncQueryService{TRoot, TIdentity}"/> and <see cref="IAsyncCommandService{TRoot, TIdentity}"/>.</returns>
 /// <exception cref="ArgumentNullException"><paramref name="commandService"/> is <c>null</c>.
 /// -or- <paramref name="queryService"/> is <c>null</c>.</exception>
 public static IAsyncRepository <TRoot, TIdentity> Join <TRoot, TIdentity>(this IAsyncCommandService <TRoot, TIdentity> commandService, IAsyncQueryService <TRoot, TIdentity> queryService)
     where TRoot : IAggregateRoot <TIdentity>
     where TIdentity : IEquatable <TIdentity>, IComparable <TIdentity>
 {
     return(new ComposedAsyncRepository <TRoot, TIdentity>(queryService, commandService));
 }
 /// <summary>
 /// Wraps the given <see cref="IAsyncCommandService{TRoot, TIdentity}"/> in a <see cref="SyncCommandServiceAdapter{TRoot, TIdentity}"/>.
 /// </summary>
 /// <typeparam name="TRoot">The type of entities in the data store.</typeparam>
 /// <typeparam name="TIdentity">The type of the unique identity value of the entities in the data store.</typeparam>
 /// <param name="inner">The <see cref="IAsyncCommandService{TRoot, TIdentity}"/> to be wrapped.</param>
 /// <returns>A new <see cref="SyncCommandServiceAdapter{TRoot, TIdentity}"/> wrapping the given <see cref="IAsyncCommandService{TRoot, TIdentity}"/>.</returns>
 /// <exception cref="ArgumentNullException"><paramref name="inner"/> is <c>null</c>.</exception>
 public static ICommandService <TRoot, TIdentity> ToSync <TRoot, TIdentity>(this IAsyncCommandService <TRoot, TIdentity> inner)
     where TRoot : IAggregateRoot <TIdentity>
     where TIdentity : IEquatable <TIdentity>, IComparable <TIdentity>
 {
     return(new SyncCommandServiceAdapter <TRoot, TIdentity>(inner));
 }
Beispiel #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SyncCommandServiceAdapter{TRoot, TIdentity}"/> class,
 /// wrapping the given <see cref="IAsyncCommandService{TRoot, TIdentity}"/>.
 /// </summary>
 /// <param name="inner">The <see cref="IAsyncCommandService{TRoot, TIdentity}"/> to be wrapped.</param>
 /// <exception cref="ArgumentNullException"><paramref name="inner"/> is <c>null</c>.</exception>
 public SyncCommandServiceAdapter(IAsyncCommandService <TRoot, TIdentity> inner)
     : base(inner)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AsyncCommandServiceExceptionHandler{TRoot, TIdentity, TException}"/> class,
 /// decorating the given <see cref="IAsyncCommandService{TRoot, TIdentity}"/>.
 /// </summary>
 /// <param name="inner">The <see cref="IAsyncCommandService{TRoot, TIdentity}"/> to be decorated.</param>
 /// <param name="handler">The handler that will be called when an exception is caught.
 /// This delegate must return a flag indicating if the exception was handled.
 /// If it wasn't, it will be re-thrown after processing.</param>
 /// <exception cref="ArgumentNullException"><paramref name="inner"/> is <c>null</c>.
 /// -or- <paramref name="handler"/> is <c>null</c>.</exception>
 public AsyncCommandServiceExceptionHandler(IAsyncCommandService <TRoot, TIdentity> inner, Func <TException, bool> handler)
     : base(inner)
 {
     Handler = handler ?? throw new ArgumentNullException(nameof(handler));
 }