I solved my own problem. For future reference (in case anyone finds
this via Google)
This problem came about when I tried to tell StructureMap that when it
resolves the IMyService instance (a WCF service), it needs to use the
proxy that WCF creates. I did that with this code:
IMyService myService = myServiceFactory.CreateChannel();
StructureMapConfiguration.ForRequestedType<IMyService >().AddInstance
(myService);
Doing this will throw some sort of PluginFamily error. StructureMap is
basically saying that the myService instance isn't an acceptable
plugin for the IMyService type, even though it implements the
interface. This is, I believe, because WCF has created a runtime proxy
with weird namespace characteristics, or something.
The solution, in the StructureMap documentation, for this type of
exception, is to configure your own PluginFamily (useful for when you
don't control the 3rd party classes). However, I REALLY don't control
the 3rd party class int this case. WCF does, and I don't even know the
namespace it generates at runtime for this proxy. Creating my own
PluginFamily config seems like it won't solve the problem (I didn't
actually try, I came up with a different solution faster).
What I ended up doing is writing my own proxy class, which ended up
being nothing more than a facade over the WCF proxy. My own proxy
exposes a public method called OpenConnection, which performs the WCF
calls to the ChannelFactories (or DuplexChannelFactories, for two-way
channels). The WCF service proxy gets instantiated and my proxy facade
just passes method calls on to the wcf proxy.
So then, with StructureMap, I'm able to setup the dependency like so:
StructureMapConfiguration.ForRequestedType<IMyService >
().TheDefaultIsConcreteType<MyServiceProxy>().CacheBy
(InstanceScope.Singleton);
And then after all the dependencies are setup, I make a call to
OpenConnection, like so:
var myServiceProxy= ObjectFactory.GetInstance<IMyService >();
((IServiceProxy<IMyService >) myServiceProxy).OpenConnection();
It's not totally elegent, because I've got to now maintain my own
proxy class, but it got rid of the exception.
-Chris