Skip to content

Commit

Permalink
refactor(OutboxDeliveryOptions): abstract base class and method signa…
Browse files Browse the repository at this point in the history
…ture changes

- Changed `OutboxDeliveryOptions<TDbContext>` to an abstract base class `OutboxDeliveryOptions`.
- Moved the property `MessageTypes` from `OutboxDeliveryOptions<TDbContext>` to the new base class.
- Created a derived class `OutboxDeliveryOptions<TDbContext>` with specific database provider details.
- Updated method signatures in `OutboxExtensions.cs` to use the new base class, removing DbContext dependency where not needed.
  • Loading branch information
winromulus committed Sep 19, 2024
1 parent 382d30b commit 6f89a19
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
namespace ES.FX.TransactionalOutbox.EntityFrameworkCore;

/// <summary>
/// Options used by the <see cref="OutboxDeliveryService{TDbContext}" />
/// Base class for the options used by the <see cref="OutboxDeliveryService{TDbContext}" />
/// </summary>
/// <typeparam name="TDbContext">The <see cref="OutboxDeliveryService{TDbContext}" /></typeparam>
public class OutboxDeliveryOptions<TDbContext> where TDbContext : DbContext, IOutboxDbContext
public abstract class OutboxDeliveryOptions
{
/// <summary>
/// The interval between polling for new messages. This will be interrupted by the signalling mechanism of new messages
Expand Down Expand Up @@ -38,13 +37,19 @@ public class OutboxDeliveryOptions<TDbContext> where TDbContext : DbContext, IOu
public bool DeliveryServiceEnabled { get; set; } = true;

/// <summary>
/// The provider that will be used to acquire the outbox. This should be provided by the specific database provider.
/// List of known message types. This is used to determine the <see cref="Type" /> of the payload.
/// </summary>
public IOutboxProvider<TDbContext> OutboxProvider { get; set; } = new DefaultOutboxProvider<TDbContext>();

public List<Type> MessageTypes { get; } = [];
}

/// <summary>
/// Options used by the <see cref="OutboxDeliveryService{TDbContext}" />
/// </summary>
/// <typeparam name="TDbContext">The <see cref="OutboxDeliveryService{TDbContext}" /></typeparam>
public class OutboxDeliveryOptions<TDbContext> : OutboxDeliveryOptions where TDbContext : DbContext, IOutboxDbContext
{
/// <summary>
/// List of known message types. This is used to determine the <see cref="Type" /> of the payload.
/// The provider that will be used to acquire the outbox. This should be provided by the specific database provider.
/// </summary>
public List<Type> MessageTypes { get; } = [];
public IOutboxProvider<TDbContext> OutboxProvider { get; set; } = new DefaultOutboxProvider<TDbContext>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ public static void AddOutboxMessage<TOutboxDbContext, TMessage>(this TOutboxDbCo
/// <summary>
/// Registers a message type as a known type. This is used to determine the <see cref="Type" /> of the payload.
/// </summary>
public static void AddMessageType<TDbContext, TMessageType>(this OutboxDeliveryOptions<TDbContext> options)
where TDbContext : DbContext, IOutboxDbContext
public static void AddMessageType<TMessageType>(this OutboxDeliveryOptions options)
where TMessageType : class, IOutboxMessage
{
options.MessageTypes.Add(typeof(TMessageType));
Expand All @@ -91,8 +90,8 @@ public static void AddMessageType<TDbContext, TMessageType>(this OutboxDeliveryO
/// <summary>
/// Registers known message types. This is used to determine the <see cref="Type" /> of the payload.
/// </summary>
public static void AddMessageType<TDbContext>(this OutboxDeliveryOptions<TDbContext> options,
params Type[] messageTypes) where TDbContext : DbContext, IOutboxDbContext
public static void AddMessageType(this OutboxDeliveryOptions options,
params Type[] messageTypes)
{
foreach (var messageType in messageTypes) options.AddMessageType(messageType);
}
Expand All @@ -101,9 +100,8 @@ public static void AddMessageType<TDbContext>(this OutboxDeliveryOptions<TDbCont
/// <summary>
/// Registers known message types. This is used to determine the <see cref="Type" /> of the payload.
/// </summary>
public static void AddMessageTypes<TDbContext>(this OutboxDeliveryOptions<TDbContext> options,
Func<Type, bool> filter,
params Assembly[] assemblies) where TDbContext : DbContext, IOutboxDbContext
public static void AddMessageTypes(this OutboxDeliveryOptions options,
Func<Type, bool> filter, params Assembly[] assemblies)
{
foreach (var assembly in assemblies)
{
Expand All @@ -119,8 +117,8 @@ public static void AddMessageTypes<TDbContext>(this OutboxDeliveryOptions<TDbCon
/// <summary>
/// Registers known message types. This is used to determine the <see cref="Type" /> of the payload.
/// </summary>
public static void AddMessageTypes<TDbContext>(this OutboxDeliveryOptions<TDbContext> options,
params Assembly[] assemblies) where TDbContext : DbContext, IOutboxDbContext
public static void AddMessageTypes(this OutboxDeliveryOptions options,
params Assembly[] assemblies)
{
options.AddMessageTypes(_ => true, assemblies);
}
Expand All @@ -129,9 +127,8 @@ public static void AddMessageTypes<TDbContext>(this OutboxDeliveryOptions<TDbCon
/// <summary>
/// Registers known message types. This is used to determine the <see cref="Type" /> of the payload.
/// </summary>
public static void AddMessageTypesFromAssemblyContaining<TDbContext>(
this OutboxDeliveryOptions<TDbContext> options, Type type, Func<Type, bool>? filter = null)
where TDbContext : DbContext, IOutboxDbContext
public static void AddMessageTypesFromAssemblyContaining(this OutboxDeliveryOptions options,
Type type, Func<Type, bool>? filter = null)
{
options.AddMessageTypes(filter ?? (_ => true), type.Assembly);
}
Expand All @@ -140,18 +137,16 @@ public static void AddMessageTypesFromAssemblyContaining<TDbContext>(
/// <summary>
/// Registers known message types. This is used to determine the <see cref="Type" /> of the payload.
/// </summary>
public static void AddMessageTypesFromAssemblyContaining<TDbContext, TType>(
this OutboxDeliveryOptions<TDbContext> options, Func<Type, bool>? filter = null)
where TDbContext : DbContext, IOutboxDbContext
public static void AddMessageTypesFromAssemblyContaining<TType>(
this OutboxDeliveryOptions options, Func<Type, bool>? filter = null)
{
options.AddMessageTypes(filter ?? (_ => true), typeof(Type).Assembly);
}

/// <summary>
/// Registers a message type as a known type. This is used to determine the <see cref="Type" /> of the payload.
/// </summary>
public static void AddMessageType<TDbContext>(this OutboxDeliveryOptions<TDbContext> options,
Type messageType) where TDbContext : DbContext, IOutboxDbContext
public static void AddMessageType(this OutboxDeliveryOptions options, Type messageType)
{
if (!messageType.IsClass || messageType.IsAbstract)
throw new ArgumentException($"Cannot use {messageType}. Messages must be non-abstract classes.",
Expand Down

0 comments on commit 6f89a19

Please sign in to comment.