How can I find a specific Specification Attribute Option by name?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
6 years ago
Adam,

I'm sorry.  I should have given more details about what I am trying to accomplish.

I developed a plugin that gives an input screen similar to the product import screen with a file browse option to import an Excel file.

In the plugin, I have a class that inherits the Nop.Services.ExportImport.ImportManager and overrides the ImportProductsFromXlsx method of ImportManager.

That actually works and I can import an excel file from my plugin.

In that class, I need the ability to get SpecificationAttributes by Id or some of the other methods in SpecificationAttributeService.

Thanks,
Tony
6 years ago
If I understand correctly, you simply need to use SpecificationAttributeService!  Check out other services and how they use other repository / service via constructor injection.
6 years ago
(agree)

You don't need to inherit ISpecificationAttributeService just to use it.

    public class LakesideImportManager : ImportManager, ISpecificationAttributeService

And you don't need to do this either:

       "I also put this in the DependencyRegistrar class:
               builder.RegisterType<SpecificationAttributeService>().As<ISpecificationAttributeService>();
6 years ago
Adam,

AdamK wrote:
If I understand correctly, you simply need to use SpecificationAttributeService!  Check out other services and how they use other repository / service via constructor injection.


Here is what I did in response to what I think you mean by constructor injection.

I did a solution search for the method GetSpecificationAttributes.

One of the places that it is used is: Nop.Web\Administration\Controllers\ProductController.cs.  It calls the method this way: foreach (var sa in _specificationAttributeService.GetSpecificationAttributes())

In ProductController, "_specificationAttributeService" is defined this way:
private readonly ISpecificationAttributeService _specificationAttributeService;


In ProductController, "_specificationAttributeService" is initialized in the constructor body this way:
this._specificationAttributeService = specificationAttributeService;


"specificationAttributeService" is a parameter being passed in to the ProductController constructor.

How those 44 parameters are being passed to ProductController, I have no idea.  I can only assume it is being done by what you call "constructor injection" considering this line in the Nop.Web\Administration\Infrastructure\DependencyRegistrar:
builder.RegisterType<ProductController>()
                .WithParameter(ResolvedParameter.ForNamed<ICacheManager>("nop_cache_static"));


If I try to code my class with that type of coding, I get all kinds of errors.

I thank you and everyone else for your continued effort and time in trying to help my stupid brain understand how to use SpecificationAttributeService methods in my class.

Tony
6 years ago
Thanks for your help.

New York wrote:

You don't need to inherit ISpecificationAttributeService just to use it.


I'm not sure of why you say that.  I'm not trying to inherit it, I tried implementing that interface.

New York wrote:

    public class LakesideImportManager : ImportManager, ISpecificationAttributeService


If I implement ISpecidicationAttributeService in my class, it gives the error "'LakesideImportManager' does not implement interface member ISpecidicationAttributeService.GetSpecificationAttributeById".

It gives that error for every method in the ISpecidicationAttributeService interface.

If I try to use the Visual Studio Show Potential Fixes option, it puts all of the method definitions in my class, but I still can't use them.

New York wrote:

And you don't need to do this either:

       "I also put this in the DependencyRegistrar class:
               builder.RegisterType<SpecificationAttributeService>().As<ISpecificationAttributeService>();


I put that in there because I was trying to follow the instructions I got from here.

I thought I needed Dependency Injection to accomplish what I want to do.

Thanks,
Tony
6 years ago
Carneno wrote:
  I'm not trying to inherit it, I tried implementing that interface. ...


You previously said "I need the ability to get SpecificationAttributes by Id or some of the other methods in SpecificationAttributeService".   "get" = "using", not implementing.
6 years ago
New York wrote:
You previously said "I need the ability to get SpecificationAttributes by Id or some of the other methods in SpecificationAttributeService".   "get" = "using", not implementing.


Oh, I see.  I apologize if I seem contrary in my statements.  Using appropriate terminology to describe  a situation is an area of communication I need to improve in.

Thanks for all of the guidance and knowledge that you and others provide in these forums to help people solve problems.

Tony
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.