No parameterless constructor defined for this object.

Posted: August 13, 2012 at 6:10 PM Quote #76635
Hi,

Here is my error:

[InvalidOperationException: An error occurred when trying to create a controller of type 'Nop.Plugin.Misc.LicenseKeyGenerator.Controllers.LicenseKeyGeneratorController'. Make sure that the controller has a parameterless public constructor.]


I have registered my custom type here:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Nop.Core.Infrastructure.DependencyManagement;
using Nop.Core.Data;
using Autofac;
using Nop.Core;
using Nop.Data;

namespace Nop.Plugin.Misc.LicenseKeyGenerator
{
    public class LicenseKeyDependencyRegistrar : IDependencyRegistrar
    {

        public int Order
        {
            get { return 0; }
        }

        public void Register(Autofac.ContainerBuilder builder, Core.Infrastructure.ITypeFinder typeFinder)
        {
            builder.RegisterType<LicenseKeyProcessor>().As<ILicenseKeyProcessor>();
        }
    }
}


ILicenseKeyProcessor has no methods. Here is my code:

namespace Nop.Plugin.Misc.LicenseKeyGenerator
{
    public class LicenseKeyProcessor : BasePlugin, IAdminMenuPlugin, ILicenseKeyProcessor
    {
        ISettingService _settingService;
        
        public LicenseKeyProcessor(ISettingService settingService)
        {
            _settingService = settingService;
        }

        public override void Install()
        {
            var settings = new LicenseKeyGeneratorSettings()
            {
                OrderIDQueryString = "OrderId"
            };

            _settingService.SaveSetting(settings);

            base.Install();
        }

        public void BuildMenuItem(Telerik.Web.Mvc.UI.MenuItemBuilder menuItemBuilder)
        {
            menuItemBuilder.Text("License Key Generator");
            menuItemBuilder.Url("/Admin/Plugin/LicenseKeyGenerator/Admin/Configure");
            menuItemBuilder.Route("Admin.Plugin.LicenseKeyGenerator.Configure");

        }

        public string MakeLicenseKey()
        {
            return "abcf";
        }
    }
}


namespace Nop.Plugin.Misc.LicenseKeyGenerator.Controllers
{
    [AdminAuthorize]
    public class LicenseKeyGeneratorController : BaseNopController
    {
        LicenseKeyGeneratorSettings licenseKeyGeneratorSettings;
        ISettingService settingService;
        ILicenseKeyProcessor licenseKeyProcessor;

        public LicenseKeyGeneratorController(LicenseKeyGeneratorSettings licenseKeyGeneratorSettings, SettingService settingService, ILicenseKeyProcessor licenseKeyProcessor)
        {
            this.licenseKeyGeneratorSettings = licenseKeyGeneratorSettings;
            this.settingService = settingService;
            this.licenseKeyProcessor = licenseKeyProcessor;
        }

        [AdminAuthorize]
        public ActionResult Configure()
        {
            var model = new LicenseKeyGeneratorModel();
            model.OrderIDQueryString = licenseKeyGeneratorSettings.OrderIDQueryString;
            return View("Nop.Plugin.Misc.LicenseKeyGenerator.Views.LicenseKeyGenerator.Configure", model);
        }

        /// <summary>
        /// saves settings to nopCommerce in admin
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost, ActionName("Configure")]
        [FormValueRequired("save")]
        public ActionResult ConfigurePOST(LicenseKeyGeneratorModel model)
        {
            if (!ModelState.IsValid)
            {
                return Configure();
            }

            licenseKeyGeneratorSettings.OrderIDQueryString = model.OrderIDQueryString;
            settingService.SaveSetting(licenseKeyGeneratorSettings);

            return View("Nop.Plugin.Misc.LicenseKeyGenerator.Views.LicenseKeyGenerator.Configure", model);
        }

    }
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: August 13, 2012 at 6:48 PM Quote #76637
The other dependencies in the core code have .InstancePerHttpRequest(); on the end of the RegisterType function.  Try that.  

Does LicenseKeyGeneratorSettings implement ISettings?
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
StackOverflow - http://stackoverflow.com/users/113988/andymckenna
http://bitshiftweb.com - FirstData payment plugin and contract development services
Posted: August 13, 2012 at 8:20 PM Quote #76640
Hi,

Found out the issue. You must use ISettingService:


        public LicenseKeyGeneratorController(LicenseKeyGeneratorSettings licenseKeyGeneratorSettings, ISettingService settingService)
        {
            this.licenseKeyGeneratorSettings = licenseKeyGeneratorSettings;
            this.settingService = settingService;
            //this.licenseKeyProcessor = licenseKeyProcessor;
        }

I used SettingService.
This post/answer is useful
2
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Premium support services
  • Dedicated premium support services provided by core developers are intended for persons who run mission critical websites, work on projects with tight deadlines, or want to get dedicated support.
Professional services
  • Want to open a new store? Want to take your store to the next level? Need a custom extension? We can customize nopCommerce to fit your store perfectly. Request a quote to get started.