Chad,
Thanks for the example; what I want to do next is instantiate an
object as shown below.
Guid anotherGuid = anotherObject.GuidProperty;
var fooBasedOnAnotherObject =
ObjectFactory.With<Guid>(anotherGuid ).GetInstance<IFoo>();
Unfortunately it is not possible to do the above when using the
example you supplied. The way I am doing it currently is to to wrap
the Guid type with an object
public class WrappedGuid
{
public Guid InnerGuid { get; private set;}
public WrappedGuid (Guid innerGuid) { InnerGuid = innerGuid;}
}
public class Foo : IFoo
{
public Guid UniqueId {get; private set;};
public Foo(WrappedGuid wrappedId) { UniqueId =
wrappedId.InnerGuid;}
}
StructureMapConfiguration
.ForRequestedType<IFoo>()
.TheDefaultIs(
new ConfiguredInstance()
Instance<Foo>()
.Child<WrappedGuid>("wrappedId").Is(new
WrappedGuid(Guid.NewGuid()))
);
To instantiate Foo based on a Guid value supplied from another object
I would do the following
WrappedGuid anotherGuid = new WrappedGuid(anotherObject.GuidProperty);
var fooBasedOnAnotherObject =
ObjectFactory.With<WrappedGuid>(anotherGuid ).GetInstance<IFoo>();
Assert.IsTrue(anotherGuid.InnerGuid.Equals(fooBasedOnAnotherObject.UniqueId));
You can see I am taking an involved and a long way around. I hope
there would be a more direct way when using struct types.
-p