DALModule.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Reflection;
  6. using System.Xml.Linq;
  7. using Autofac;
  8. using EMIS.DataLogic;
  9. using EMIS.Utility;
  10. using Bowin.Common.XML;
  11. namespace EMIS.CommonLogic
  12. {
  13. public class DALModule : Autofac.Module
  14. {
  15. protected override void Load(ContainerBuilder builder)
  16. {
  17. builder.RegisterType<UnitOfWork>().InstancePerLifetimeScope();
  18. builder.RegisterType<HRUnitOfWork>().InstancePerLifetimeScope();
  19. builder.RegisterType<LogUnitOfWork>().InstancePerLifetimeScope();
  20. builder.RegisterType<DataCenterUnitOfWork>().InstancePerLifetimeScope();
  21. builder.RegisterType<LYDataCenterUnitOfWork>().InstancePerLifetimeScope();
  22. var blAssembly = typeof(EMIS.DataLogic.UnitOfWork).Assembly;
  23. builder.RegisterAssemblyTypes(blAssembly)
  24. .Where(x => x.Name.EndsWith("Repository") && x.BaseType.GetGenericArguments()[0].FullName.StartsWith("EMIS.Entities"))
  25. .AsSelf()
  26. .WithParameter((pi, c) => pi.ParameterType == typeof(UnitOfWork),
  27. (pi, c) => c.Resolve<UnitOfWork>())
  28. .WithParameter((pi, c) => pi.ParameterType == typeof(HRUnitOfWork),
  29. (pi, c) => c.Resolve<HRUnitOfWork>())
  30. .WithParameter((pi, c) => pi.ParameterType == typeof(LogUnitOfWork),
  31. (pi, c) => c.Resolve<LogUnitOfWork>())
  32. .WithParameter((pi, c) => pi.ParameterType == typeof(DataCenterUnitOfWork),
  33. (pi, c) => c.Resolve<DataCenterUnitOfWork>())
  34. .WithParameter((pi, c) => pi.ParameterType == typeof(LYDataCenterUnitOfWork),
  35. (pi, c) => c.Resolve<LYDataCenterUnitOfWork>())
  36. .PropertiesAutowired()
  37. .InstancePerLifetimeScope();
  38. builder.RegisterAssemblyTypes(blAssembly)
  39. .Where(x => x.FullName.StartsWith("EMIS.DataLogic") && x.Name.EndsWith("DAL"))
  40. .AsSelf()
  41. .PropertiesAutowired()
  42. .InstancePerLifetimeScope();
  43. }
  44. }
  45. }