【问题标题】:Problem with plugins during NopCommerce developmentNopCommerce 开发过程中的插件问题
【发布时间】:2019-01-26 07:30:41
【问题描述】:

我将在 NopCommerce 4.0 上进行一些开发。 我已将 NopCommerce 4.0 源代码导入 VS 2019。当我尝试运行我的项目时,所有插件都会在 Resolve 方法 NopEngine.cs 中生成类似这样的异常:

public object Resolve(Type type)
{
    return GetServiceProvider().GetRequiredService(type);
}

例如例外之一是:

'Nop.Plugin.Payments.CheckMoneyOrder.CheckMoneyOrderPaymentProcessor' 尚未注册。为避免此异常,请注册一个 提供服务的组件,检查服务注册使用 IsRegistered(),或使用 ResolveOptional() 方法来解决 可选依赖。

这里是完整的异常细节:

Autofac.Core.Registration.ComponentNotRegisteredException
HResult=0x80131500 Message=请求的服务 'Nop.Plugin.Payments.CheckMoneyOrder.CheckMoneyOrderPaymentProcessor' 尚未注册。为避免此异常,请注册一个 提供服务的组件,检查服务注册使用 IsRegistered(),或使用 ResolveOptional() 方法来解决 可选依赖。来源=Autofac StackTrace:在 Autofac.ResolutionExtensions.ResolveService(IComponentContext 上下文, 服务服务,IEnumerable`1 参数)在 Autofac.Extensions.DependencyInjection.AutofacServiceProvider.GetRequiredService(类型 serviceType) 在 Nop.Core.Infrastructure.NopEngine.Resolve(Type 输入 V:\nopCommerce_4.00_Source\Libraries\Nop.Core\Infrastructure\NopEngine.cs:line 254

【问题讨论】:

    标签: c# .net-core nopcommerce


    【解决方案1】:

    这似乎是 nop v4.0 的问题,因为它正在将卸载的插件加载到内存中,并且已在 v4.10 中得到解决。您可以升级到更新版本或检查以下修复,如果它可以工作!

    改变

    public object Resolve(Type type)
    {
        return GetServiceProvider().GetRequiredService(type);
    }
    

    public object Resolve(Type type)
    {
        if (type.IsSubclassOf(typeof(BasePlugin))) {
            return null;
        }
        return GetServiceProvider().GetRequiredService(type);
    }
    

    【讨论】:

    • 问题是我有这个插件,但是我不知道为什么不能正确加载它们以避免异常。可能是我没有将它们正确地包含在我的项目中,但我不知道这样做的正确方法是什么。你知道吗?
    • @VSB:如果您使用随源代码提供的默认插件运行,那么这似乎更像是他们使用的代码或方法的问题。如果其他插件存在此问题,那么这可能是您添加这些插件的原因。
    • 默认插件和已编译的外部插件存在此问题。
    【解决方案2】:

    当我忘记使用它的接口注册服务时出现此错误

    例如:

    public class DependencyRegistrar : IDependencyRegistrar
    {
       /// <summary>
       /// Register services and interfaces
       /// </summary>
       /// <param name="builder">Container builder</param>
       /// <param name="typeFinder">Type finder</param>
       /// <param name="config">Config</param>
       public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, NopConfig config)
       {
          //register service manager
          builder.RegisterType<SearchFilterService>().As<ISearchFilterService>().InstancePerLifetimeScope();
          builder.RegisterType<ElasticSearchService>().As<IElasticSearchService>().InstancePerLifetimeScope();          
       }
    
       /// <summary>
       /// Gets order of this dependency registrar implementation
       /// </summary>
       public int Order => 1;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多