views:

130

answers:

0

I'm trying to figure out a way of getting a particular piece of code called when a path is recognised. I'm going to be registering paths from different plugins. This allows them to fight over the paths that they want.

The idea being that the plugins say here are the paths that I'm interested in, when you get a match create an instance of this class and call this method on it to return a view.

I can figure out enough to be able to pass in a delegate and then call the appropriate code but that still leaves me holding a pointer to the class. I specifically don't want that. I want to instance the class required and then call the described method.

Here is an outline:

public class TestView : IView
{
 public void Render(ViewContext viewContext, System.IO.TextWriter writer) {}
}

class TestViewCreator
{
 public IView CreateView(object Arguments)
 {
  return new TestView();
 }
}

public class CentralStash
{
 // T = TestViewCreator
 // How do I describe the method I want to call (CreateView)?
 public void RegisterPath<T>(string url, object Arguements)
 {

 }

 public IView GetView(string url)
 {
  var viewCreator = ObjectFactory.GetInstance<T>();
  //How do I call the method description on the type that I have jsut instanced?
  return null;
 }
}

I've got the feeling that I should probably be using routes here, or possibly an Expression? I know this is possible to do with delegates but I don't want loads of objects hanging round because of the pointers to them.

A nudge in the right direction woudl be appreciated.

Update:

I could of course just create the interface

public interface IViewCreator
{
 public IView CreateView(object Arguments);
}

And create one of them and call CreateView, I was hoping to make this more powerful that that though.