No parameterless constructor defined for this object even when Mapping for Interface and Method class are there.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 years ago
Hello Fellow developers,

Little bit new to NopCommerce MVC (Working on 2.40) and having problems with a newly created plugin (though already did some work on Plugins and never had this problem earlier).

No parameterless constructor defined for this object.


Trying to create a new plugin for NopCommerce 2.40 which will be responsible to keep the information for the images to show on the Home page for web application.

two tables are involved. All the Controllers, services and other stuff created but having the above error.

Also added the Interface and class mapping in Dependency registrar as :

//define the dependency between the Service And Interface Register.

            builder.RegisterType<RotatorService>().As<IRotatorService>().InstancePerHttpRequest();

            //data layer
            var dataSettingsManager = new DataSettingsManager();
            var dataProviderSettings = dataSettingsManager.LoadSettings();

            if (dataProviderSettings != null && dataProviderSettings.IsValid())
            {
                //register named context
                builder.Register<IDbContext>(c => new RotatorObjectContext(dataProviderSettings.DataConnectionString))
                    .Named<IDbContext>("nop_object_context_Rotator")
                    .InstancePerHttpRequest();

                builder.Register(c => new RotatorObjectContext(dataProviderSettings.DataConnectionString))
                    .InstancePerHttpRequest();
            }
            else
            {
                //register named context
                builder.Register<IDbContext>(c => new RotatorObjectContext(c.Resolve<DataSettings>().DataConnectionString))
                    .Named<IDbContext>("nop_object_context_Rotator")
                    .InstancePerHttpRequest();

                builder.Register(c => new RotatorObjectContext(c.Resolve<DataSettings>().DataConnectionString))
                    .InstancePerHttpRequest();
            }

            //override required repository with our custom context
            builder.RegisterType<EfRepository<RotatorManager>>()
                .As<IRepository<RotatorManager>>()
                .WithParameter(ResolvedParameter.ForNamed<IDbContext>("nop_object_context_Rotator"))
                .InstancePerHttpRequest();

            builder.RegisterType<EfRepository<RotatorSlidesManager>>()
                .As<IRepository<RotatorSlidesManager>>()
                .WithParameter(ResolvedParameter.ForNamed<IDbContext>("nop_object_context_Rotator"))
                .InstancePerHttpRequest();

Here RotatorService and IRotatorService are class and Interface respectivelly.

my controller's constructor code is as:

public HomePageRotatorAdminController(IRotatorService rotatorService, ILocalizationService localizationService)
        {
            this._rotatorService = rotatorService;
            this._localizationService = localizationService;
        }

Already did this in other new plugins but never struck but might be there is something wrong in the code and i am not able to track that.

error is coming when i am adding the Parametrized constructor in the controller.

Any type of help will be appriciated.

Thanks and regards
11 years ago
Does RotatorService have any dependencies?
11 years ago
No, as i wrote there are two tables Rotator and RotatorSlides and just normal function for CURD operations, Following is the Constructor for the Rotator Service class:


Definition for the Rotator Class:

public class RotatorService : IRotatorService


and here is the Constructor for the class:

private readonly IRepository<RotatorManager> _rotatorManager;
        private readonly IRepository<RotatorSlidesManager> _rotatorSlideManager;

        private RotatorService(IRepository<RotatorManager> rotatorManager, IRepository<RotatorSlidesManager> rotatorSlideManager)
        {
            this._rotatorManager = rotatorManager;
            this._rotatorSlideManager = rotatorSlideManager;
        }
11 years ago
Oh i did everything again but still no luck.
11 years ago
vikas227 wrote:
private RotatorService(IRepository<RotatorManager> rotatorManager, IRepository<RotatorSlidesManager> rotatorSlideManager)
{
    this._rotatorManager = rotatorManager;
    this._rotatorSlideManager = rotatorSlideManager;
}

The constructor for your service is private, it should be public.

.
11 years ago
Good catch
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.