Guest User

Untitled

a guest
Jun 25th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. var namedInjector = ObjectFactory.GetNamedInstance<IInjectable>("Other");
  2.  
  3. .ForRequestedType<MementoType>()
  4. .AddConcreteType<ConcreteType>(instanceName)
  5.  
  6. class MyRegistry : Registry {
  7. public MyRegistry() {
  8. this.ForRequestedType<IFoo>()
  9. .TheDefaultIsConcreteType<Bar>()
  10. .AddInstances( x => {
  11. x.OfConcreteType<Blap>().WithName("abc");
  12. });
  13. }
  14. }
  15. ...
  16. ObjectFactory.Configure(x=>x.AddRegistry<MyRegistry>());
  17. IFoo test1 = ObjectFactory.GetInstance<IFoo>(); // Bar
  18. IFoo test2 = ObjectFactory.GetNamedInstance<IFoo>("abc"); // Blap
  19. ...
  20. interface IFoo {}
  21. public class Bar : IFoo {}
  22. public class Blap : IFoo {}
Add Comment
Please, Sign In to add comment