I have a windows console app (that will eventually be a windows service) that reads from queues (5 for each client). It needs to be able to read from a data store so that all of the client queues have the appropriate queue listeners set up. To make matters more complex we're using priority queues, so in some cases one listener will listen to two queues.
A previous programmer has implemented some kind of custom service locator to bind all of the assemblies together, but as the app gets bigger and more complex his code is proving to be more and more unmaintainable to the point that when we came to add a cache - it couldnt be wired up using an interceptor pattern, so the time has come to rewrite. The question is, how?
I've looked at:
Ninject dynamically bind to implementation
Runtime Binding: A simple task runner with ninject?
but I dont think they really match what I'm trying to achieve.
I've got something like this:
var clientRepo = kernel.Get<IRepository<IClient>>();
foreach (var client in clientRepo.GetEntities())
var clientJob = new ClientJob(client, serviceUrl, kernel);
I want to insert code in the line above with the new in it.
Should I be trying to do this using a factory, or can it be done with code similar to the above?
As far as i understand i see two problems in your code:
Obviously sometimes you can't create all of your object graph at app startup (as in your question) and this is the place when the factory extension becomes super handy.
Hope it helps!