You can easily access the requested type using ICMontext StructureMap.
ObjectFactory.Configure(
x => {
x.For<ILogger>().Use( context => new TestLogger( context.ParentType ) );
} );
In the above description, context.ParentType returns the type that StructureMap creates.
Jeremy Miller also covered this topic on his blog. This article uses outdated syntax, but it still matters: http://codebetter.com/jeremymiller/2009/01/15/using-the-build-session-in-structuremap/
IContext, :
ObjectFactory.Configure(
x => {
x.For<ILogger>()
.Use( context =>
{
return new TestLogger( context.ParentType );
} );
} );
Update:
.AlwaysUnique() ( .CacheBy(InstanceScope.Unique)), StructureMap ILogger, , ILogger GetInstance().
, , ILogger, ObjectFactory.GetInstance <ISomeClass> () ILogger , ILogger, , , .
, , :
x.For<ILogger>()
.AlwaysUnique()
.Use( c => new TestLogger( c.ParentType ?? c.BuildStack.Current.ConcreteType ) );