Skip to content

Commit

Permalink
Tweaks after zarusz#307
Browse files Browse the repository at this point in the history
Signed-off-by: Tomasz Maruszak <[email protected]>
  • Loading branch information
zarusz committed Sep 22, 2024
1 parent 55547bd commit 698a9a2
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/Host.Plugin.Properties.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Import Project="Common.NuGet.Properties.xml" />

<PropertyGroup>
<Version>2.5.3</Version>
<Version>2.5.4-rc1</Version>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public MessageBusBuilder Produce<T>(Action<ProducerBuilder<T>> builder)
/// <returns></returns>
public MessageBusBuilder Produce(Type messageType, Action<ProducerBuilder<object>> builder)
{
if (builder == null) throw new ArgumentNullException(nameof(builder));
if (builder == null) throw new ArgumentNullException(nameof(builder));

var item = new ProducerSettings();
builder(new ProducerBuilder<object>(item, messageType));
Expand Down Expand Up @@ -109,7 +109,7 @@ public MessageBusBuilder Consume<TMessage>(Action<ConsumerBuilder<TMessage>> bui
/// <returns></returns>
public MessageBusBuilder Consume(Type messageType, Action<ConsumerBuilder<object>> builder)
{
if (builder == null) throw new ArgumentNullException(nameof(builder));
if (builder == null) throw new ArgumentNullException(nameof(builder));

builder(new ConsumerBuilder<object>(Settings, messageType));
return this;
Expand Down Expand Up @@ -314,11 +314,18 @@ public MessageBusBuilder AutoStartConsumersEnabled(bool enabled)
Settings.AutoStartConsumers = enabled;
return this;
}


/// <summary>
/// Adds a child bus with the given name <paramref name="busName"/>.
/// If the child bus with the given name already exists, it will be reused and only the <paramref name="builderAction"/> will be invoked to configure it.
/// </summary>
/// <param name="busName"></param>
/// <param name="builderAction"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
public MessageBusBuilder AddChildBus(string busName, Action<MessageBusBuilder> builderAction)
{
if (busName is null) throw new ArgumentNullException(nameof(busName));
if (builderAction is null) throw new ArgumentNullException(nameof(builderAction));

if (!Children.TryGetValue(busName, out var child))
{
Expand All @@ -334,7 +341,7 @@ public MessageBusBuilder AddChildBus(string busName, Action<MessageBusBuilder> b
child.MergeFrom(Settings);
}

builderAction.Invoke(child);
builderAction?.Invoke(child);

return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public IServiceProvider ServiceProvider

public MessageBusSettings(MessageBusSettings parent = null)
{
_children = new List<MessageBusSettings>();
Producers = new List<ProducerSettings>();
Consumers = new List<ConsumerSettings>();
_children = [];
Producers = [];
Consumers = [];
SerializerType = typeof(IMessageSerializer);
AutoStartConsumers = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Description>Core configuration interfaces of SlimMessageBus</Description>
<PackageTags>SlimMessageBus</PackageTags>
<RootNamespace>SlimMessageBus.Host</RootNamespace>
<Version>2.5.1</Version>
<Version>2.5.2-rc1</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public static IServiceCollection AddSlimMessageBus(this IServiceCollection servi
configure(mbb);

// Execute post config actions for the master bus and its children
foreach (var action in mbb.PostConfigurationActions.Concat(mbb.Children.Values.SelectMany(x => x.PostConfigurationActions)))
foreach (var postConfigure in mbb.PostConfigurationActions.Concat(mbb.Children.Values.SelectMany(x => x.PostConfigurationActions)))
{
action(services);
postConfigure(services);
}
}
}
Expand All @@ -55,6 +55,9 @@ public static IServiceCollection AddSlimMessageBus(this IServiceCollection servi
}

// MessageBusSettings
services.TryAddTransient(svp => svp.GetRequiredService<MessageBusBuilder>().Settings);

// IMasterMessageBus - Single master bus that holds the defined consumers and message processing pipelines
services.TryAddSingleton(svp =>
{
var mbb = svp.GetRequiredService<MessageBusBuilder>();
Expand All @@ -66,15 +69,6 @@ public static IServiceCollection AddSlimMessageBus(this IServiceCollection servi
postProcessor.Run(mbb.Settings);
}

return mbb.Settings;
});

// IMasterMessageBus - Single master bus that holds the defined consumers and message processing pipelines
services.TryAddSingleton(svp =>
{
var mbb = svp.GetRequiredService<MessageBusBuilder>();
var messageBusSettings = svp.GetRequiredService<MessageBusSettings>();

// Set the MessageBus.Current
var currentBusProvider = svp.GetRequiredService<ICurrentMessageBusProvider>();
MessageBus.SetProvider(currentBusProvider.GetCurrent);
Expand Down
5 changes: 2 additions & 3 deletions src/SlimMessageBus.Host/MessageBusBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,10 @@ public virtual IMessageSerializer Serializer

protected MessageBusBase(MessageBusSettings settings)
{
if (settings is null) throw new ArgumentNullException(nameof(settings));
Settings = settings ?? throw new ArgumentNullException(nameof(settings));

if (settings.ServiceProvider is null) throw new ConfigurationMessageBusException($"The bus {Name} has no {nameof(settings.ServiceProvider)} configured");

Settings = settings;

// Try to resolve from DI. If not available, suppress logging by using the NullLoggerFactory
LoggerFactory = settings.ServiceProvider.GetService<ILoggerFactory>() ?? NullLoggerFactory.Instance;

Expand Down

0 comments on commit 698a9a2

Please sign in to comment.