Skip to content

Commit

Permalink
INeedInitialization not called early enough.
Browse files Browse the repository at this point in the history
This causes transport, conventions, endpointname and endpointversion not being picked up if configured in INeedInitialization.
Fixes #2530
  • Loading branch information
John Simons committed Oct 27, 2014
1 parent eec009b commit 23bab60
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
namespace NServiceBus.AcceptanceTests.Basic
{
using System;
using NServiceBus.AcceptanceTesting;
using NServiceBus.AcceptanceTests.EndpointTemplates;
using NUnit.Framework;

public class When_using_ineedinitialization : NServiceBusAcceptanceTest
{
[Test]
public void Should_be_able_to_set_endpoint_name()
{
var context = new Context();

Scenario.Define(context)
.WithEndpoint<Sender>()
.WithEndpoint<Receiver>()
.Done(c => c.WasCalled)
.Run();

Assert.True(context.WasCalled, "The message handler should be called");
}

public class Context : ScenarioContext
{
public bool WasCalled { get; set; }
}

public class Sender : EndpointConfigurationBuilder
{
public Sender()
{
EndpointSetup<DefaultServer>();
}
}

public class Receiver : EndpointConfigurationBuilder
{
public Receiver()
{
EndpointSetup<DefaultServer>()
.AddMapping<SendMessage>(typeof(Sender));
}

public class SetEndpointName : INeedInitialization
{
public void Customize(BusConfiguration config)
{
config.EndpointName("ineedinitialization_receiver");
}
}

public class SendMessageToSender: IWantToRunWhenBusStartsAndStops
{
public IBus Bus { get; set; }

public void Start()
{
Bus.Send(new SendMessage());
}

public void Stop()
{
}
}
}

[Serializable]
public class SendMessage : ICommand
{
}

[Serializable]
public class MyMessage : ICommand
{
public Guid Id { get; set; }
}

public class SendMessageHandler : IHandleMessages<SendMessage>
{
public IBus Bus { get; set; }

public void Handle(SendMessage message)
{
Bus.Send("ineedinitialization_receiver", new MyMessage());
}
}

public class MyMessageHandler : IHandleMessages<MyMessage>
{
public Context Context { get; set; }

public IBus Bus { get; set; }

public void Handle(MyMessage message)
{
Context.WasCalled = true;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
Expand Down Expand Up @@ -52,6 +52,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Audit\When_using_audit_message_is_received.cs" />
<Compile Include="Basic\When_using_ineedinitialization.cs" />
<Compile Include="Basic\When_using_callbacks_from_older_versions.cs" />
<Compile Include="Basic\When_sending_from_a_send_only.cs" />
<Compile Include="Basic\When_using_a_greedy_convention.cs" />
Expand Down
8 changes: 4 additions & 4 deletions src/NServiceBus.Core/BusConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,14 @@ internal Configure BuildConfiguration()
}
}

Settings.SetDefault("TypesToScan", scannedTypes);

Configure.ActivateAndInvoke<INeedInitialization>(scannedTypes, t => t.Customize(this));

UseTransportExtensions.SetupTransport(this);
var container = customBuilder ?? new AutofacObjectBuilder();

Settings.SetDefault<IConfigurationSource>(configurationSourceToUse);
Settings.SetDefault("TypesToScan", scannedTypes);

var endpointHelper = new EndpointHelper(new StackTrace());

Expand All @@ -221,7 +224,6 @@ internal Configure BuildConfiguration()
Settings.SetDefault("EndpointName", endpointName);
Settings.SetDefault("EndpointVersion", endpointVersion);


if (publicReturnAddress != null)
{
Settings.SetDefault("PublicReturnAddress", publicReturnAddress);
Expand All @@ -231,8 +233,6 @@ internal Configure BuildConfiguration()

Settings.SetDefault<Conventions>(conventionsBuilder.Conventions);

Configure.ActivateAndInvoke<INeedInitialization>(scannedTypes, t => t.Customize(this));

return new Configure(Settings, container, registrations, Pipeline);
}

Expand Down

0 comments on commit 23bab60

Please sign in to comment.