I have a console application in which you can specify parameters, based on the specified parameters various handlers will be loaded. For instance:
prgm.exe nyse
prgm.exe nasdaq
The goal is that in my code there is, INyseHandlersand INasdaqHandlers, in the first case, only all handlers distributing the first are loaded, similarly for the latter. The goal is to have one program that can listen to various or all sources, depending on how it starts. To do this, I installed my interfaces as described above. Then, configured in my configuration:
var configuration = new BusConfiguration();
configuration.InitializeStepBusConventions();
if (!Args.Contains("any") && Args.Length != 0)
{
List<Type> handlersToLoad = new List<Type>();
foreach (var argument in Args)
{
Console.WriteLine("Adding {0} subscribers to loaded handlers. . .", argument.ToUpper());
switch (argument)
{
case "nyse":
AddToHandlerList(handlersToLoad, typeof(INyseProcessor));
break;
case "nasdaq":
AddToHandlerList(handlersToLoad, typeof(INasdaqProcessor));
break;
}
}
configuration.TypesToScan(handlersToLoad);
}
configuration.UseContainer<NinjectBuilder>(c => c.ExistingKernel(Kernel));
configuration.EndpointName(ConfigurationManager.AppSettings[Defaults.Project.DefaultEndPointName]);
NServiceBus.Logging.LogManager.Use<NLogFactory>();
Bus.Create(configuration).Start();
And where:
private void AddToHandlerList(List<Type> handlersToLoad, Type interfaceType)
{
List<Type> classesWhichExtendInterface = Assembly.GetExecutingAssembly().GetTypes().Where(t => interfaceType.IsAssignableFrom(t)).ToList();
classesWhichExtendInterface.Remove(interfaceType);
handlersToLoad.AddRange(classesWhichExtendInterface);
}
Types load as expected, which is Listin order. But when I run this and get to the line Bus.Start, I get the following error:
The given key (NServiceBus.LocalAddress) was not present in the dictionary.
, . TypesToScan()?
EDIT: :
config.UseSerialization<JsonSerializer>();
config.UseTransport<RabbitMQTransport>();
config.UsePersistence<InMemoryPersistence>();
config.EnableInstallers();
return config;