I would like to supplement the endpoints which I subscribe too in my UnicastBusConfig section of my App.config file to add in another queue to subscribe to.
To do this ive added a custom configuration source as follows
public class MyConfigSource : IConfigurationSource
{
public T GetConfiguration<T>() where T : class, new()
{
// the part you are overriding
if (typeof(T) == typeof(UnicastBusConfig))
{
var config = ConfigurationManager.GetSection(typeof(T).Name) as UnicastBusConfig;
config.MessageEndpointMappings.Add(new MessageEndpointMapping() { Endpoint = "MyQueue", Messages = "MyMessageNamespace" });
}
// leaving the rest of the configuration as is:
return ConfigurationManager.GetSection(typeof(T).Name) as T;
}
}
however I get an exception when I call Add on the existing MessageEndpointMappings collection:
Exception when starting endpoint, error has been logged. Reason: The
configuration is read only.
Is there a better way to load an existing configuration and add bits to it in code?
Yes unfortunately the mappings collection is set as readonly!
Here is a workaround (sorry about the usage of reflection!) (and I’m also using the new way to override configuration settings
IProvideConfiguration<T>):BTW, I’ll make sure we fix this for the next major release of NServiceBus, see https://github.com/NServiceBus/NServiceBus/issues/952