How to use plugin services in theme views in nopCommerce version 4.50

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
1 year ago
@using Nop.Plugin.PLUGINNAME.Service

Added this to the view like any other service namespace but the build fail with "The type or namespace name 'Plugin' does not exist in the namespace 'Nop' (are you missing an assembly reference?)".
We need to use one of the services from our custom plugin in our custom theme. nopCommerce version 4.50.1. pls help
1 year ago
try like this from theme views:

@inject IServiceCollection  serviceCollection
@inject IHttpContextAccessor httpContextAccessor

@{
var services = serviceCollection.ToList();
    var service = services.Where(s => s.ServiceType.Name == "IYourService").FirstOrDefault();
    if(service  != null){
         var instance = (dynamic) httpContextAccessor.HttpContext.RequestServices.GetService(service
          .ServiceType);
           var value = instance.YourMethod();
   }
}
1 year ago
Thanks a lot.
Isn't there any other way to get multiple plugin services easily?
1 year ago
Chamila1026 wrote:

Isn't there any other way to get multiple plugin services easily?

your plugin take reference of Nop.Web project that's why you get any service easily from your plugin view page. but Nop.Web project doesn't take reference of your plugin project. that's why we can not know this at initially and take this on runtime by reflection from Nop.Web themes view
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.