In my object factory initialization, I have something like this:
ObjectFactory.Initialize(factory=>
{
factory.For<User>().Add((IContext context) =>
(User)Session["Current"]).Named("CurrentUser");
factory.For<User>().Add((IContext context) =>
new User()).Named("NewUser");
});
Then in my controllers, I want to be able to do something like this:
public MyController(User CurrentUser) { ... }
public MyOthercontroller(User NewUser) { ... }
Where some aspect of definition of the constructor tells StructureMap which named instance to use. I've been looking around to see if I can somehow get the name of the parameter out of the IContext (doesn't seem to be possible), or use the name of the parameter as the name of the instance (doesn't seem to be possible).
this question seems to describe a way of doing this by setting up the mapping for each controller as part of initializing the object factory. I'd prefer something a bit more convention-oriented, rather than having to explicitly configure it.
Is such a thing possible?