Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ namespace NServiceBus
}
public class ConversationIdStrategyContext
{
public ConversationIdStrategyContext(NServiceBus.Pipeline.OutgoingLogicalMessage message, System.Collections.Generic.IReadOnlyDictionary<string, string> headers) { }
public System.Collections.Generic.IReadOnlyDictionary<string, string> Headers { get; }
public ConversationIdStrategyContext(NServiceBus.Pipeline.OutgoingLogicalMessage message, System.Collections.Generic.IReadOnlyDictionary<string, string?> headers) { }
public System.Collections.Generic.IReadOnlyDictionary<string, string?> Headers { get; }
public NServiceBus.Pipeline.OutgoingLogicalMessage Message { get; }
}
public static class ConversationRoutingExtensions
Expand Down Expand Up @@ -358,8 +358,8 @@ namespace NServiceBus
}
public static class HeaderOptionExtensions
{
public static System.Collections.Generic.IReadOnlyDictionary<string, string> GetHeaders(this NServiceBus.Extensibility.ExtendableOptions options) { }
public static void SetHeader(this NServiceBus.Extensibility.ExtendableOptions options, string key, string value) { }
public static System.Collections.Generic.IReadOnlyDictionary<string, string?> GetHeaders(this NServiceBus.Extensibility.ExtendableOptions options) { }
public static void SetHeader(this NServiceBus.Extensibility.ExtendableOptions options, string key, string? value) { }
}
public static class Headers
{
Expand Down Expand Up @@ -1761,19 +1761,19 @@ namespace NServiceBus.MessageMutator
}
public class MutateOutgoingMessageContext : NServiceBus.ICancellableContext
{
public MutateOutgoingMessageContext(object outgoingMessage, System.Collections.Generic.Dictionary<string, string> outgoingHeaders, object? incomingMessage, System.Collections.Generic.IReadOnlyDictionary<string, string>? incomingHeaders, System.Threading.CancellationToken cancellationToken = default) { }
public MutateOutgoingMessageContext(object outgoingMessage, System.Collections.Generic.Dictionary<string, string?> outgoingHeaders, object? incomingMessage, System.Collections.Generic.IReadOnlyDictionary<string, string>? incomingHeaders, System.Threading.CancellationToken cancellationToken = default) { }
public System.Threading.CancellationToken CancellationToken { get; }
public System.Collections.Generic.Dictionary<string, string> OutgoingHeaders { get; }
public System.Collections.Generic.Dictionary<string, string?> OutgoingHeaders { get; }
public object OutgoingMessage { get; set; }
public bool TryGetIncomingHeaders([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out System.Collections.Generic.IReadOnlyDictionary<string, string>? incomingHeaders) { }
public bool TryGetIncomingMessage([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out object? incomingMessage) { }
}
public class MutateOutgoingTransportMessageContext : NServiceBus.ICancellableContext
{
public MutateOutgoingTransportMessageContext(System.ReadOnlyMemory<byte> outgoingBody, object outgoingMessage, System.Collections.Generic.Dictionary<string, string> outgoingHeaders, object? incomingMessage, System.Collections.Generic.IReadOnlyDictionary<string, string>? incomingHeaders, System.Threading.CancellationToken cancellationToken = default) { }
public MutateOutgoingTransportMessageContext(System.ReadOnlyMemory<byte> outgoingBody, object outgoingMessage, System.Collections.Generic.Dictionary<string, string?> outgoingHeaders, object? incomingMessage, System.Collections.Generic.IReadOnlyDictionary<string, string>? incomingHeaders, System.Threading.CancellationToken cancellationToken = default) { }
public System.Threading.CancellationToken CancellationToken { get; }
public System.ReadOnlyMemory<byte> OutgoingBody { get; set; }
public System.Collections.Generic.Dictionary<string, string> OutgoingHeaders { get; }
public System.Collections.Generic.Dictionary<string, string?> OutgoingHeaders { get; }
public object OutgoingMessage { get; }
public bool TryGetIncomingHeaders([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out System.Collections.Generic.IReadOnlyDictionary<string, string>? incomingHeaders) { }
public bool TryGetIncomingMessage([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out object? incomingMessage) { }
Expand Down Expand Up @@ -1931,7 +1931,7 @@ namespace NServiceBus.Pipeline
}
public interface IOutgoingContext : NServiceBus.Extensibility.IExtendable, NServiceBus.ICancellableContext, NServiceBus.IPipelineContext, NServiceBus.Pipeline.IBehaviorContext
{
System.Collections.Generic.Dictionary<string, string> Headers { get; }
System.Collections.Generic.Dictionary<string, string?> Headers { get; }
string MessageId { get; }
}
public interface IOutgoingLogicalMessageContext : NServiceBus.Extensibility.IExtendable, NServiceBus.ICancellableContext, NServiceBus.IPipelineContext, NServiceBus.Pipeline.IBehaviorContext, NServiceBus.Pipeline.IOutgoingContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ConversationIdStrategyContext
/// <summary>
/// Creates a new context.
/// </summary>
public ConversationIdStrategyContext(OutgoingLogicalMessage message, IReadOnlyDictionary<string, string> headers)
public ConversationIdStrategyContext(OutgoingLogicalMessage message, IReadOnlyDictionary<string, string?> headers)
{
ArgumentNullException.ThrowIfNull(message);
ArgumentNullException.ThrowIfNull(headers);
Expand All @@ -32,5 +32,5 @@ public ConversationIdStrategyContext(OutgoingLogicalMessage message, IReadOnlyDi
/// <summary>
/// The headers attached to the outgoing message.
/// </summary>
public IReadOnlyDictionary<string, string> Headers { get; }
public IReadOnlyDictionary<string, string?> Headers { get; }
}
2 changes: 1 addition & 1 deletion src/NServiceBus.Core/Extensibility/ExtendableOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ protected ExtendableOptions()

internal string? UserDefinedMessageId { get; set; }

internal Dictionary<string, string> OutgoingHeaders { get; }
internal Dictionary<string, string?> OutgoingHeaders { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class MutateOutgoingMessageContext : ICancellableContext
/// <summary>
/// Initializes the context.
/// </summary>
public MutateOutgoingMessageContext(object outgoingMessage, Dictionary<string, string> outgoingHeaders, object? incomingMessage, IReadOnlyDictionary<string, string>? incomingHeaders, CancellationToken cancellationToken = default)
public MutateOutgoingMessageContext(object outgoingMessage, Dictionary<string, string?> outgoingHeaders, object? incomingMessage, IReadOnlyDictionary<string, string>? incomingHeaders, CancellationToken cancellationToken = default)
{
ArgumentNullException.ThrowIfNull(outgoingHeaders);
ArgumentNullException.ThrowIfNull(outgoingMessage);
Expand Down Expand Up @@ -43,7 +43,7 @@ public object OutgoingMessage
/// <summary>
/// The current outgoing headers.
/// </summary>
public Dictionary<string, string> OutgoingHeaders { get; }
public Dictionary<string, string?> OutgoingHeaders { get; }

/// <summary>
/// A <see cref="CancellationToken"/> to observe.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class MutateOutgoingTransportMessageContext : ICancellableContext
/// <summary>
/// Initializes a new instance of <see cref="MutateOutgoingTransportMessageContext" />.
/// </summary>
public MutateOutgoingTransportMessageContext(ReadOnlyMemory<byte> outgoingBody, object outgoingMessage, Dictionary<string, string> outgoingHeaders, object? incomingMessage, IReadOnlyDictionary<string, string>? incomingHeaders, CancellationToken cancellationToken = default)
public MutateOutgoingTransportMessageContext(ReadOnlyMemory<byte> outgoingBody, object outgoingMessage, Dictionary<string, string?> outgoingHeaders, object? incomingMessage, IReadOnlyDictionary<string, string>? incomingHeaders, CancellationToken cancellationToken = default)
{
ArgumentNullException.ThrowIfNull(outgoingHeaders);
ArgumentNullException.ThrowIfNull(outgoingMessage);
Expand Down Expand Up @@ -51,7 +51,7 @@ public ReadOnlyMemory<byte> OutgoingBody
/// <summary>
/// The current outgoing headers.
/// </summary>
public Dictionary<string, string> OutgoingHeaders { get; }
public Dictionary<string, string?> OutgoingHeaders { get; }

/// <summary>
/// A <see cref="CancellationToken"/> to observe.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static class HeaderOptionExtensions
/// <param name="options">The options to extend.</param>
/// <param name="key">The header key.</param>
/// <param name="value">The header value.</param>
public static void SetHeader(this ExtendableOptions options, string key, string value)
public static void SetHeader(this ExtendableOptions options, string key, string? value)
{
ArgumentNullException.ThrowIfNull(options);
ArgumentException.ThrowIfNullOrWhiteSpace(key);
Expand All @@ -29,10 +29,10 @@ public static void SetHeader(this ExtendableOptions options, string key, string
/// <summary>
/// Returns all headers set by <see cref="SetHeader" /> on the outgoing message.
/// </summary>
public static IReadOnlyDictionary<string, string> GetHeaders(this ExtendableOptions options)
public static IReadOnlyDictionary<string, string?> GetHeaders(this ExtendableOptions options)
{
ArgumentNullException.ThrowIfNull(options);

return new ReadOnlyDictionary<string, string>(options.OutgoingHeaders);
return new ReadOnlyDictionary<string, string?>(options.OutgoingHeaders);
}
}
2 changes: 1 addition & 1 deletion src/NServiceBus.Core/Pipeline/Outgoing/IOutgoingContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ public interface IOutgoingContext : IBehaviorContext, IPipelineContext
/// <summary>
/// The headers of the outgoing message.
/// </summary>
Dictionary<string, string> Headers { get; }
Dictionary<string, string?> Headers { get; }
}
4 changes: 2 additions & 2 deletions src/NServiceBus.Core/Pipeline/Outgoing/OutgoingContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace NServiceBus;

abstract class OutgoingContext : BehaviorContext, IOutgoingContext
{
protected OutgoingContext(string messageId, Dictionary<string, string> headers, IBehaviorContext parentContext)
protected OutgoingContext(string messageId, Dictionary<string, string?> headers, IBehaviorContext parentContext)
: base(parentContext)
{
Headers = headers;
Expand All @@ -21,7 +21,7 @@ protected OutgoingContext(string messageId, Dictionary<string, string> headers,

public string MessageId { get; }

public Dictionary<string, string> Headers { get; }
public Dictionary<string, string?> Headers { get; }

public Task Send(object message, SendOptions options)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace NServiceBus;

class OutgoingLogicalMessageContext : OutgoingContext, IOutgoingLogicalMessageContext
{
public OutgoingLogicalMessageContext(string messageId, Dictionary<string, string> headers, OutgoingLogicalMessage message, IReadOnlyCollection<RoutingStrategy> routingStrategies, IBehaviorContext parentContext)
public OutgoingLogicalMessageContext(string messageId, Dictionary<string, string?> headers, OutgoingLogicalMessage message, IReadOnlyCollection<RoutingStrategy> routingStrategies, IBehaviorContext parentContext)
: base(messageId, headers, parentContext)
{
Message = message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace NServiceBus;

class OutgoingPublishContext : OutgoingContext, IOutgoingPublishContext
{
public OutgoingPublishContext(OutgoingLogicalMessage message, string messageId, Dictionary<string, string> headers, ContextBag extensions, IBehaviorContext parentContext)
public OutgoingPublishContext(OutgoingLogicalMessage message, string messageId, Dictionary<string, string?> headers, ContextBag extensions, IBehaviorContext parentContext)
: base(messageId, headers, parentContext)
{
ArgumentNullException.ThrowIfNull(parentContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace NServiceBus;

class OutgoingReplyContext : OutgoingContext, IOutgoingReplyContext
{
public OutgoingReplyContext(OutgoingLogicalMessage message, string messageId, Dictionary<string, string> headers, ContextBag extensions, IBehaviorContext parentContext)
public OutgoingReplyContext(OutgoingLogicalMessage message, string messageId, Dictionary<string, string?> headers, ContextBag extensions, IBehaviorContext parentContext)
: base(messageId, headers, parentContext)
{
ArgumentNullException.ThrowIfNull(parentContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace NServiceBus;

class OutgoingSendContext : OutgoingContext, IOutgoingSendContext
{
public OutgoingSendContext(OutgoingLogicalMessage message, string messageId, Dictionary<string, string> headers, ContextBag extensions, IBehaviorContext parentContext)
public OutgoingSendContext(OutgoingLogicalMessage message, string messageId, Dictionary<string, string?> headers, ContextBag extensions, IBehaviorContext parentContext)
: base(messageId, headers, parentContext)
{
ArgumentNullException.ThrowIfNull(parentContext);
Expand Down
20 changes: 11 additions & 9 deletions src/NServiceBus.Core/Unicast/MessageOperations.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#nullable enable

namespace NServiceBus;

using System;
Expand Down Expand Up @@ -39,20 +41,20 @@ public MessageOperations(

public Task Publish<[DynamicallyAccessedMembers(IMessageCreator.CreatorMembersRequired)] T>(IBehaviorContext context, Action<T> messageConstructor, PublishOptions options)
{
return Publish(context, typeof(T), messageMapper.CreateInstance(messageConstructor), options);
return Publish(context, typeof(T), messageMapper.CreateInstance(messageConstructor)!, options);
}

public Task Publish(IBehaviorContext context, object message, PublishOptions options)
{
var messageType = messageMapper.GetMappedTypeFor(message.GetType());
var messageType = messageMapper.GetMappedTypeFor(message.GetType()) ?? message.GetType();

return Publish(context, messageType, message, options);
}

async Task Publish(IBehaviorContext context, Type messageType, object message, PublishOptions options)
{
var messageId = options.UserDefinedMessageId ?? CombGuid.Generate().ToString();
var headers = new Dictionary<string, string>(options.OutgoingHeaders)
var headers = new Dictionary<string, string?>(options.OutgoingHeaders)
{
[Headers.MessageId] = messageId
};
Expand Down Expand Up @@ -106,20 +108,20 @@ public async Task Unsubscribe(IBehaviorContext context, Type eventType, Unsubscr

public Task Send<[DynamicallyAccessedMembers(IMessageCreator.CreatorMembersRequired)] T>(IBehaviorContext context, Action<T> messageConstructor, SendOptions options)
{
return SendMessage(context, typeof(T), messageMapper.CreateInstance(messageConstructor), options);
return SendMessage(context, typeof(T), messageMapper.CreateInstance(messageConstructor)!, options);
}

public Task Send(IBehaviorContext context, object message, SendOptions options)
{
var messageType = messageMapper.GetMappedTypeFor(message.GetType());
var messageType = messageMapper.GetMappedTypeFor(message.GetType()) ?? message.GetType();

return SendMessage(context, messageType, message, options);
}

async Task SendMessage(IBehaviorContext context, Type messageType, object message, SendOptions options)
{
var messageId = options.UserDefinedMessageId ?? CombGuid.Generate().ToString();
var headers = new Dictionary<string, string>(options.OutgoingHeaders)
var headers = new Dictionary<string, string?>(options.OutgoingHeaders)
{
[Headers.MessageId] = messageId
};
Expand All @@ -140,20 +142,20 @@ async Task SendMessage(IBehaviorContext context, Type messageType, object messag

public Task Reply(IBehaviorContext context, object message, ReplyOptions options)
{
var messageType = messageMapper.GetMappedTypeFor(message.GetType());
var messageType = messageMapper.GetMappedTypeFor(message.GetType()) ?? message.GetType();

return ReplyMessage(context, messageType, message, options);
}

public Task Reply<[DynamicallyAccessedMembers(IMessageCreator.CreatorMembersRequired)] T>(IBehaviorContext context, Action<T> messageConstructor, ReplyOptions options)
{
return ReplyMessage(context, typeof(T), messageMapper.CreateInstance(messageConstructor), options);
return ReplyMessage(context, typeof(T), messageMapper.CreateInstance(messageConstructor)!, options);
}

async Task ReplyMessage(IBehaviorContext context, Type messageType, object message, ReplyOptions options)
{
var messageId = options.UserDefinedMessageId ?? CombGuid.Generate().ToString();
var headers = new Dictionary<string, string>(options.OutgoingHeaders)
var headers = new Dictionary<string, string?>(options.OutgoingHeaders)
{
[Headers.MessageId] = messageId
};
Expand Down
8 changes: 5 additions & 3 deletions src/NServiceBus.Testing.Fakes/TestableOutgoingContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace NServiceBus.Testing;
#nullable enable

namespace NServiceBus.Testing;

using System;
using System.Collections.Generic;
Expand All @@ -18,7 +20,7 @@ public partial class TestableOutgoingContext : TestablePipelineContext, IOutgoin

IServiceProvider IBehaviorContext.Builder => GetBuilder();

IServiceProvider builder = null;
IServiceProvider? builder = null;

/// <summary>
/// Selects the builder returned by <see cref="IBehaviorContext.Builder" />. Override this method to provide your custom
Expand All @@ -38,5 +40,5 @@ protected virtual IServiceProvider GetBuilder()
/// <summary>
/// The headers of the outgoing message.
/// </summary>
public Dictionary<string, string> Headers { get; set; } = [];
public Dictionary<string, string?> Headers { get; set; } = [];
}