Search code examples
servicestacknservicebusportable-class-library

Having NServiceBus messages in Portable Class Library PCL


Is there a way to create a PCL with NServiceBus messages (like you can for ServiceStack)? I tried to add the NuGet package but I doesn't seem to support Xamarin

Install-Package NServiceBus

Install failed. Rolling back...
Package 'NServiceBus 5.2.5' does not exist in project 'RZ.Services.ServiceModel'
Install-Package : Could not install package 'NServiceBus 5.2.5'. You are trying to install this package into a project that targets     '.NETPortable,Version=v4.5,Profile=Profile7', but the package does not contain     any assembly references or content files that are compatible with that framework. For more information, contact the package author.
At line:1 char:16
+ Install-Package <<<<  NServiceBus
    + CategoryInfo          : NotSpecified: (:) [Install-Package], Exception
    + FullyQualifiedErrorId :     NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand

Any work arounds of future plans to support this? We will indeed never use NServiceBus on other platforms, but we might want to use both NServiceBus and ServiceStack to support different scenario's, and since those will be sharing messages those must be placed in one class library.


Solution

  • It is probably best not to reference NServiceBus for your messages and better to use unobtrusive mode.

    See the documentation here: http://docs.particular.net/nservicebus/messaging/unobtrusive-mode

    This makes sure that your message do not have to inherit from any of the NServiceBus marker interfaces.

    To configure unobtrusive mode see the following example partially copied from the doco:

    BusConfiguration busConfiguration = new BusConfiguration();
    ConventionsBuilder conventions = busConfiguration.Conventions();
    conventions.DefiningCommandsAs(t => t.Namespace != null && t.Namespace == "MyNamespace" && t.Namespace.EndsWith("Commands"));
    conventions.DefiningEventsAs(t => t.Namespace != null && t.Namespace == "MyNamespace" && t.Namespace.EndsWith("Events"));
    conventions.DefiningMessagesAs(t => t.Namespace != null && t.Namespace == "Messages");