AutofacIocManager.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using Autofac.Core;
  2. namespace OASystem.API.OAMethodLib
  3. {
  4. public class AutofacIocManager
  5. {
  6. public static AutofacIocManager Instance = new AutofacIocManager();
  7. public ILifetimeScope Container { get; set; }
  8. public T GetService<T>()
  9. {
  10. return ResolutionExtensions.Resolve<T>((IComponentContext)(object)this.Container);
  11. }
  12. public T GetService<T>(string serviceKey)
  13. {
  14. return ResolutionExtensions.ResolveKeyed<T>((IComponentContext)(object)this.Container, (object)serviceKey);
  15. }
  16. public T GetService<T>(string serviceKey, params Parameter[] parameters)
  17. {
  18. return ResolutionExtensions.ResolveKeyed<T>((IComponentContext)(object)this.Container, (object)serviceKey, parameters);
  19. }
  20. public object GetService(Type serviceType)
  21. {
  22. return ResolutionExtensions.Resolve((IComponentContext)(object)this.Container, serviceType);
  23. }
  24. public object GetService(string serviceKey, Type serviceType)
  25. {
  26. return ResolutionExtensions.ResolveKeyed((IComponentContext)(object)this.Container, (object)serviceKey, serviceType);
  27. }
  28. public bool IsRegistered<T>()
  29. {
  30. return ResolutionExtensions.IsRegistered<T>((IComponentContext)(object)this.Container);
  31. }
  32. public bool IsRegistered<T>(string serviceKey)
  33. {
  34. return ResolutionExtensions.IsRegisteredWithKey<T>((IComponentContext)(object)this.Container, (object)serviceKey);
  35. }
  36. public bool IsRegistered(Type serviceType)
  37. {
  38. return ResolutionExtensions.IsRegistered((IComponentContext)(object)this.Container, serviceType);
  39. }
  40. public bool IsRegisteredWithKey(string serviceKey, Type serviceType)
  41. {
  42. return ResolutionExtensions.IsRegisteredWithKey((IComponentContext)(object)this.Container, (object)serviceKey, serviceType);
  43. }
  44. }
  45. }