DALModule.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using Autofac;
  6. using System.Reflection;
  7. using EMISOnline.DataLogic;
  8. using EMISOnline.Utility;
  9. namespace EMISOnline.CommonLogic
  10. {
  11. public class DALModule : Autofac.Module
  12. {
  13. protected override void Load(ContainerBuilder builder)
  14. {
  15. builder.RegisterType<UnitOfWork>().InstancePerLifetimeScope();
  16. var blAssembly = typeof(EMISOnline.DataLogic.UnitOfWork).Assembly;
  17. builder.RegisterAssemblyTypes(blAssembly)
  18. .Where(x => x.Name.EndsWith("Repository") && x.BaseType.GetGenericArguments()[0].FullName.StartsWith("EMISOnline.Entities"))
  19. .AsSelf()
  20. .WithParameter((pi, c) => pi.ParameterType == typeof(UnitOfWork),
  21. (pi, c) => c.Resolve<UnitOfWork>())
  22. .PropertiesAutowired()
  23. .InstancePerLifetimeScope();
  24. builder.RegisterAssemblyTypes(blAssembly)
  25. .Where(x => x.FullName.StartsWith("EMISOnline.DataLogic") && x.Name.EndsWith("DAL"))
  26. .AsSelf()
  27. .PropertiesAutowired()
  28. .InstancePerLifetimeScope();
  29. }
  30. }
  31. }