Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

StructureMap: How to register the same instance for all its interfaces

StructureMap newbie question.

public class SomeClass: IInterface1, IInterface2 {
}

I would like the following test to pass:

Assert.AreSameInstance(
    container.GetInstance<IInterface1>(), 
    container.GetInstance<IInterface2>());

How would I do an explicit registration of this?

I know in Castle Windsor I would do something like

kernel.Register(Component.For(typeof(IInterface1), typeof(IInterface2))
    .ImplementedBy(typeof(SomeClass));

But I don't see any equivalent API

like image 409
George Mauer Avatar asked Mar 29 '10 00:03

George Mauer


1 Answers

ObjectFactory.Initialize(x => 
{ 
    x.For<IInterface1>().Singleton().Use<MyClass>(); 
    x.Forward<IInterface1, IInterface2>(); 
}); 
like image 133
Phil Sandler Avatar answered Oct 30 '22 08:10

Phil Sandler