code_junkie

Abstracting IoC Container Behind a Singleton - Doing it wrong?

Nov 12th, 2011
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. public static class IoC
  2. {
  3. private static IDependencyResolver inner;
  4.  
  5. public static void InitWith(IDependencyResolver container)
  6. {
  7. inner = container;
  8. }
  9.  
  10. /// <exception cref="InvalidOperationException">Container has not been initialized. Please supply an instance if IWindsorContainer.</exception>
  11. public static T Resolve<T>()
  12. {
  13. if ( inner == null)
  14. throw new InvalidOperationException("Container has not been initialized. Please supply an instance if IWindsorContainer.");
  15.  
  16. return inner.Resolve<T>();
  17. }
  18.  
  19. public static T[] ResolveAll<T>()
  20. {
  21. return inner.ResolveAll<T>();
  22. }
  23. }
  24.  
  25. public interface IDependencyResolver
  26. {
  27. T Resolve<T>();
  28. T[] ResolveAll<T>();
  29. }
Add Comment
Please, Sign In to add comment