I m trying to implement new task during plugin installation.
So its look like^
public class ProductUpdatingServicePlugin : BasePlugin, IAdminMenuPlugin
{
private ProductUpdateLogRecordObjectContext _productUpdateLogRecordObjectContext;
private IRepository<ProductUpdateLogRecord> _productUpdateRepository;
public ProductUpdatingServiceSettings _productUpdatingServiceSettings { get; private set; }
public ISettingService _settingService { get; private set; }
public ScheduleTaskService _scheduleTaskService { get; private set; }
public ProductUpdatingServicePlugin(
ISettingService settingService,
ProductUpdatingServiceSettings productUpdatingServiceSettings,
ProductUpdateLogRecordObjectContext productUpdateLogRecordObjectContext,
ScheduleTaskService scheduleTaskService,
IRepository<ProductUpdateLogRecord> productUpdateRepository)
{
this._settingService = settingService;
this._productUpdatingServiceSettings = productUpdatingServiceSettings;
this._scheduleTaskService = scheduleTaskService;
this._productUpdateLogRecordObjectContext = productUpdateLogRecordObjectContext;
this._productUpdateRepository = productUpdateRepository;
}
public override void Install()
{
var settings = new ProductUpdatingServiceSettings()
{
ODBCName = "",
};
_settingService.SaveSetting(settings);
_scheduleTaskService.InsertTask(new ScheduleTask
{
Enabled = true,
Name = "Product sync log",
Seconds = 3600,
StopOnError = false,
Type = "Nop.Plugin.Misc.ProductUpdatingService, Nop.Plugin.Misc.ProductUpdatingService.Tasks",
});
//locales
this.AddOrUpdatePluginLocaleResource("Plugins.Misc.ProductUpdatingService.ODBCName", "ODBC connection Name");
this.AddOrUpdatePluginLocaleResource("Plugins.Misc.ProductUpdatingService.ODBCName.Hint", "Insert ODBC connection name");
_productUpdateLogRecordObjectContext.Install();
base.Install();
}
public override void Uninstall()
{
//locales
this.DeletePluginLocaleResource("Plugins.Misc.ProductUpdatingService.ODBCName");
this.DeletePluginLocaleResource("Plugins.Misc.ProductUpdatingService.ODBCName.Hint");
ScheduleTask task = _scheduleTaskService.GetTaskByType("Nop.Plugin.Misc.ProductUpdatingService, Nop.Plugin.Misc.ProductUpdatingService.Tasks");
if (task != null)
{
_scheduleTaskService.DeleteTask(task);
}
_productUpdateLogRecordObjectContext.Uninstall();
base.Uninstall();
}
but I receive an error.
An exception of type 'Autofac.Core.Registration.ComponentNotRegisteredException' occurred in Autofac.dll but was not handled in user code
Additional information: The requested service 'Nop.Services.Tasks.ScheduleTaskService' 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.
Could u please explain to me how ш can avoid it and get it works?