fquednau
unread,Dec 14, 2008, 1:59:05 PM12/14/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to structuremap-users
Hi Jeremy,
interesting posts here today - all have somehow to do with context,
schcontext and how to change instances based on that. Based on your
keyword "Instance" in "Is there a way to do context-driven selection
of registered instances?", I started experimenting. My first hope was
that one could get to an instance passed in with the "With" keyword,
hoping that I could get access to it in a custom instance.
public interface ICommand { }
public class CommandA : ICommand { }
public class Context { public string ID { get; set; } }
public class MyInstance : Instance { ... }
ObjectFactory.Initialize(
i => i.ForRequestedType<ICommand>().TheDefault.Is.Instance(new
MyInstance()));
var cmd = ObjectFactory.With(new Context() { ID =
"Hi" }).GetInstance<ICommand>();
I was surprised that this blew up with a null reference at
StructureMap.Graph.Constructor.Visit(IArgumentVisitor visitor)
More standard construction configuration does not lead to this issue.
It looks like in this specific scenario the "Constructor" is trying to
get the constructor of the *interface*, which is passed as
"Pluggedtype". _ctor is then left to be null, but is duly accessed
when wanting to iterate its parameters.
Maybe it is not a bug per se, but it seems unfair to your
"Constructor" to throw him into a situation of scanning an interface
type for its constructor :)
On a minor note, how do I get to the "With(obj)" obj from within a
custom instance, then? ;)