AbpStartupConfigurationExtensions.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using Abp.Dependency;
  3. namespace Abp.Configuration.Startup
  4. {
  5. /// <summary>
  6. /// Extension methods for <see cref="IAbpStartupConfiguration"/>.
  7. /// </summary>
  8. public static class AbpStartupConfigurationExtensions
  9. {
  10. /// <summary>
  11. /// Used to replace a service type.
  12. /// </summary>
  13. /// <param name="configuration">The configuration.</param>
  14. /// <param name="type">Type.</param>
  15. /// <param name="impl">Implementation.</param>
  16. /// <param name="lifeStyle">Life style.</param>
  17. public static void ReplaceService(this IAbpStartupConfiguration configuration, Type type, Type impl, DependencyLifeStyle lifeStyle = DependencyLifeStyle.Singleton)
  18. {
  19. configuration.ReplaceService(type, () =>
  20. {
  21. configuration.IocManager.Register(type, impl, lifeStyle);
  22. });
  23. }
  24. /// <summary>
  25. /// Used to replace a service type.
  26. /// </summary>
  27. /// <typeparam name="TType">Type of the service.</typeparam>
  28. /// <typeparam name="TImpl">Type of the implementation.</typeparam>
  29. /// <param name="configuration">The configuration.</param>
  30. /// <param name="lifeStyle">Life style.</param>
  31. public static void ReplaceService<TType, TImpl>(this IAbpStartupConfiguration configuration, DependencyLifeStyle lifeStyle = DependencyLifeStyle.Singleton)
  32. where TType : class
  33. where TImpl : class, TType
  34. {
  35. configuration.ReplaceService(typeof(TType), () =>
  36. {
  37. configuration.IocManager.Register<TType, TImpl>(lifeStyle);
  38. });
  39. }
  40. /// <summary>
  41. /// Used to replace a service type.
  42. /// </summary>
  43. /// <typeparam name="TType">Type of the service.</typeparam>
  44. /// <param name="configuration">The configuration.</param>
  45. /// <param name="replaceAction">Replace action.</param>
  46. public static void ReplaceService<TType>(this IAbpStartupConfiguration configuration, Action replaceAction)
  47. where TType : class
  48. {
  49. configuration.ReplaceService(typeof(TType), replaceAction);
  50. }
  51. }
  52. }