Error on Dependency Registeration

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
6 anni tempo fa
I've two plugin and a single service.

Service write in first plugin and I want to use it in second plugin.

in first plugin I'm not registered service in DependencyRegister because I'm not using it in first plugin.

In second plugin I'm registering it in dependency Register by

   builder.RegisterType<MyService>().As<IMyService>().InstancePerLifetimeScope();


But it throwing below exception.

The requested service 'Nop.Plugin.Misc.MyPlugin.Service.MyService' has not been registered. To avoid this exception, either register a component to provide the service, check for service registration using IsRegistered(), or use the ResolveOptional() method to resolve an optional dependency.


Here is my service constructor


public partial class MyService: IMyService
    {
        private readonly HttpContextBase _httpContext;  
      
        public SolrWebHelper(HttpContextBase httpContext)
        {
            this._httpContext = httpContext;
        }
   }


Any Idea about this error?
6 anni tempo fa
Also I tried with

1.
builder.RegisterAssemblyTypes(typeof(IMyService).Assembly)
   //.Where(t => t.Name.EndsWith("Service"))
   .AsImplementedInterfaces()
   .InstancePerRequest();



2.
builder.RegisterType<MyService>().AsSelf();



3.
builder.Register(x => new MyService(x.Resolve<HttpContextBase>())).As<IMyService>().InstancePerLifetimeScope();


But it not working .
6 anni tempo fa
Hi Raju

Did you implement IDependencyRegistrar on your registrar class?
6 anni tempo fa
janus007 wrote:
Hi Raju

Did you implement IDependencyRegistrar on your registrar class?


yes, I registered it.

I moved service in second plugin but still face same error.

But issue was in constructor.
I was using "HttpContextBase" which comes from System.Web. I searched and found System.Web is not supported in Asp.Net Core.


I replaced it with "IHttpContextAccessor" and it's working now.


public partial class MyService: IMyService
    {
        private readonly IHttpContextAccessor _httpContextAccessor;

        
        public MyService(IHttpContextAccessor httpContextAccessor)
        {
            //this._httpContext = httpContext;
            this._httpContextAccessor = httpContextAccessor;
        }
    }

5 anni tempo fa
Has this been fix yet? i am having same problem while updating the API's plugin to 4.10
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.