code_junkie

How to get StructureMap to return a specific instance for a requested type

Nov 13th, 2011
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. var myObj = ObjectFactory.GetInstance(typeof(MyAbstractClass));
  2.  
  3. var myClass = new MyConcreteClass("bla"); // MyConcreteClass : MyAbstractClass
  4.  
  5. myObj == myClass
  6.  
  7. ObjectFactory.Initialize(x =>
  8. {
  9. x.ForRequestedType<MyAbstractClass>().TheDefault.IsThis(myClass);
  10. });
  11.  
  12. ObjectFactory.Inject(typeof(MyAbstractClass), myClass);
Add Comment
Please, Sign In to add comment