Adding an existing instance - via non-generic methods

8 views
Skip to first unread message

James Crowley

unread,
Dec 23, 2009, 2:21:02 PM12/23/09
to structure...@googlegroups.com
Hi guys,

A quick question for you :) I need to add a type to StructureMap that has been created externally - and for which I don't know the exact type until runtime. I've used this before when I've known the type:

container.Configure(t=>t.ForRequestedType<T>().TheDefault.Is.Object(instance));

but the non-generic version of ForRequestedType doesn't have "TheDefault.Is" available as properties? In Windsor I'd just do

container.Kernel.AddComponentInstance(key, type, instance);

What can I use instead? Any input would be much appreciated!

With thanks,

James

Josh Flanagan

unread,
Dec 23, 2009, 2:35:32 PM12/23/09
to structure...@googlegroups.com
You'll probably have to upgrade to the trunk (or wait for the
"soonish" release) and do:

container.Configure(t => t.For(typeof(TypeToRequest)).Use(instance));

> --
>
> You received this message because you are subscribed to the Google Groups
> "structuremap-users" group.
> To post to this group, send email to structure...@googlegroups.com.
> To unsubscribe from this group, send email to
> structuremap-us...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/structuremap-users?hl=en.
>

Jeremy D. Miller

unread,
Dec 23, 2009, 2:36:41 PM12/23/09
to structure...@googlegroups.com
In the trunk (which will be released in the next couple days) it's:

var container = new Container(x => {
  x.For(type).Use(instance).WithName(key);
});
 
Jeremy D. Miller
The Shade Tree Developer
jeremy...@yahoo.com



From: James Crowley <james....@gmail.com>
To: structure...@googlegroups.com
Sent: Wed, December 23, 2009 1:21:02 PM
Subject: [sm-users] Adding an existing instance - via non-generic methods

--

James Crowley

unread,
Dec 23, 2009, 7:02:03 PM12/23/09
to structure...@googlegroups.com
Ah, brilliant! Thanks guys.

2009/12/23 Jeremy D. Miller <jeremy...@yahoo.com>
Reply all
Reply to author
Forward
0 new messages