Totally new to MVP and Spring, and I have what seems to be typical MVP application that uses Spring, where the presenter is instantiated like:
IApplicationContext ctx = ContextRegistry.GetContext();
presenter = (clsPresenter)ctx.GetObject("clsPresenter");
I hate using strings to call code, really, I hate it. So I'm thinking of putting something like
static private readonly string _clsName = typeof(ClsPresenter).Name.ToCamelCase();
public static ClsPresenter getNewPresenterFromSpring()
{
IApplicationContext ctx = ContextRegistry.GetContext();
return (ClsPresenter)ctx.GetObject(_clsName);
}
into all of the presenters. So that instead of the the two lines above which use a string to find the presenter, it would be one line using the static method:
presenter = ClsPresenter.getNewPresenterFromSpring();
I know this violates the SRP, and it might look to be introducing some coupling between the Presenter classes and Spring, but it seems to me that it's not really coupled any more than it was before, it's just now type (and typo) safe, while living in a somewhat weird place. If I stop using Spring, I simply replace this call with whatever else gets used instead.
Am I missing something that makes this a really bad idea? Is there a better way of avoiding the usage of strings? Should I just suck it and make sure I don't spell "clsPresenter" as "classPresenter"?