AddDB.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. 
  2. using AspectCore.Configuration;
  3. using AspectCore.Extensions.DependencyInjection;
  4. using Microsoft.AspNetCore.Builder;
  5. using Microsoft.Extensions.DependencyInjection;
  6. using System;
  7. using System.Data;
  8. using System.Linq;
  9. using System.Reflection;
  10. namespace XYY.Core.Standard.Data.Infrastructure
  11. {
  12. public static class AddDBEx
  13. {
  14. /// <summary>
  15. /// 数据服务注册
  16. /// </summary>
  17. /// <param name="services"></param>
  18. /// <param name="connection"></param>
  19. public static void AddDB(this IServiceCollection services, string connection)
  20. {
  21. Console.WriteLine("数据服务注册" );
  22. services.AddScoped<IUnitOfWork>(x => new UnitOfWork(ConnectionHelper.BuildDbConnection(connection), connection));
  23. //AddTransactionProcessing(services);
  24. }
  25. public static void ConfigAspectCore(this IServiceCollection services, string serviceEndName)
  26. {
  27. services.ConfigureDynamicProxy(config =>
  28. {
  29. config.Interceptors.AddTyped<ConnectionInterceptorAttribute>(
  30. Predicates.ForService("*" + serviceEndName + "*"));
  31. }
  32. ); ;
  33. }
  34. }
  35. }