zoukankan      html  css  js  c++  java
  • 项目学习——后台事件监听并触发相应操作

    NopCommerce项目学习——后台事件监听并触发相应操作

     

    1、Nop.Services.Customers. CustomerService 中操作数据时,调用事件发布者泛型扩展类Nop.Services.Events.EventPublisherExtensions中的扩展方法

    _eventPublisher.EntityUpdated(customer);

    public virtual void UpdateCustomer(Customer customer)

            {

                if (customer == null)

                    throw new ArgumentNullException("customer");

     

                _customerRepository.Update(customer);

     

                //event notification

                _eventPublisher.EntityUpdated(customer);

            }

    2、Nop.Services.Events.EventPublisherExtensions中的扩展方法调用EventPublisher : IEventPublisher 事件发布者及接口

    public virtual void Publish<T>(T eventMessage)

            {

                var subscriptions = _subscriptionService.GetSubscriptions<T>();

                subscriptions.ToList().ForEach(x => PublishToConsumer(x, eventMessage));

            }

    (1)   public IList<IConsumer<T>> GetSubscriptions<T>()

            {

    //获取所有实现<IConsumer<T>的消费者,其中T为InsertEntity<Order>类似的具体对象

                return EngineContext.Current.ResolveAll<IConsumer<T>>();

            }

    (2)PublishToConsumer(x, eventMessage))

    x.HandleEvent(eventMessage);调用Consumer的HandleEvent方法 如Nop.Services.Catalog.Cache. PriceCacheEventConsumer

  • 相关阅读:
    miragejs 学习
    json-server学习
    react-redux
    webpack4知识汇总2
    webpack4知识汇总1
    vue跳转当前页面
    redux初识
    react知识补漏2
    vue ssr
    状态码
  • 原文地址:https://www.cnblogs.com/taoshengyujiu/p/6273481.html
Copyright © 2011-2022 走看看