IocHelper.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System;
  2. using System.Configuration;
  3. using System.IO;
  4. using System.Net;
  5. using System.Reflection;
  6. using LeaRun.Util.Ioc;
  7. namespace LeaRun.Data.Repository
  8. {
  9. public class IocHelper
  10. {
  11. private readonly TinyIoCContainer _container;
  12. private static readonly IocHelper instance = new IocHelper();
  13. public IocHelper()
  14. {
  15. //接口dll路径
  16. string assembleFileName1 = Assembly.GetExecutingAssembly().CodeBase.Replace("LeaRun.Data.Repository.DLL", "LeaRun.Data.dll").Replace("file:///", "");
  17. //实现dll路径
  18. string assembleFileName2 = Assembly.GetExecutingAssembly().CodeBase.Replace("LeaRun.Data.Repository.DLL", "LeaRun.Data.EF.dll").Replace("file:///", "");
  19. _container = new TinyIoCContainer();
  20. _container.AutoRegister(new[] { Assembly.LoadFrom(assembleFileName1) },
  21. DuplicateImplementationActions.RegisterSingle);
  22. _container.AutoRegister(new[] { Assembly.LoadFrom(assembleFileName2) },
  23. DuplicateImplementationActions.RegisterSingle);
  24. }
  25. public static IocHelper Instance
  26. {
  27. get { return instance; }
  28. }
  29. /// <summary>
  30. /// Ioc容器
  31. /// </summary>
  32. public TinyIoCContainer Container
  33. {
  34. get { return _container; }
  35. }
  36. }
  37. }