I get an Autofac error that my plugin's serivce's constructor can't be found at run time.
Autofac.Core.DependencyResolutionException: An exception was thrown while activating WZ.Plugin.Widgets.SKUAllocationByOwner.Controllers.SKUAllocationController -> WZ.Plugin.Widgets.SKUAllocationByOwner.Factories.SKUAllocationModelFactory. ---> Autofac.Core.DependencyResolutionException: None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'WZ.Plugin.Widgets.SKUAllocationByOwner.Factories.SKUAllocationModelFactory' can be invoked with the available services and parameters: Cannot resolve parameter 'WZ.Plugin.Widgets.SKUAllocationByOwner.Services.SKUAllocationServic <snip>
Here is my plugin starup:
public class PluginNopStartup : INopStartup
{
public virtual void ConfigureServices(IServiceCollection services, IConfiguration configuration)
{
services.Configure<RazorViewEngineOptions>(options =>
{
options.ViewLocationExpanders.Add(new ViewLocationExpander());
});
//register services and interfaces
services.AddScoped<ISKUAllocationModelFactory, SKUAllocationModelFactory>();
services.AddScoped<ISKUAllocationService, SKUAllocationService>();
services.AddScoped<IWZImportManager, WZImportManager>();
}
public void Configure(IApplicationBuilder application)
{
}
public int Order => 3000;
}
Model:
public record SKUAllocationModel : BaseNopEntityModel
{
public string OwnerName { get; set; }
public string Sku { get; set; }
public int AllocationQuantity { get; set; }
public int UsedAllocationQuantity { get; set; }
public DateTime FromDateTime { get; set; }
public DateTime ToDateTime { get; set; }
}
Domain:
public partial class SkuAllocation : BaseEntity
{
public string OwnerName { get; set; }
public string Sku { get; set; }
public int AllocationQuantity { get; set; }
public int UsedAllocationQuantity { get; set; }
public DateTime FromDateTime { get; set; }
public DateTime ToDateTime { get; set; }
}
Plugin Builder:
public class PluginBuilder : NopEntityBuilder<SkuAllocation>
{
public override void MapEntity(CreateTableExpressionBuilder table)
{
table
.WithColumn(nameof(SKUAllocationModel.Id)).AsInt32().PrimaryKey()
.WithColumn(nameof(SKUAllocationModel.OwnerName)).AsString(400).NotNullable()
.WithColumn(nameof(SKUAllocationModel.Sku)).AsString(400).NotNullable()
.WithColumn(nameof(SKUAllocationModel.AllocationQuantity)).AsInt32().NotNullable()
.WithColumn(nameof(SKUAllocationModel.UsedAllocationQuantity)).AsInt32().NotNullable()
.WithColumn(nameof(SKUAllocationModel.FromDateTime)).AsDateTime().NotNullable()
.WithColumn(nameof(SKUAllocationModel.ToDateTime)).AsDateTime().NotNullable();
}
}
service:
public class SKUAllocationService : ISKUAllocationService
{
private readonly IRepository<SkuAllocation> _skuAllocationRepository;
private readonly ILogger _logger;
public SKUAllocationService(
IRepository<SkuAllocation> skuAllocationRepository, ILogger logger)
{
_skuAllocationRepository = skuAllocationRepository;
_logger = logger;
}
<more methods snipped>
Model Factory:
public partial class SKUAllocationModelFactory :ISKUAllocationModelFactory
{
private readonly IWorkContext _workContext;
private readonly VendorSettings _vendorSettings;
private readonly SKUAllocationService _skuAllocationService;
#endregion
public SKUAllocationModelFactory(VendorSettings vendorSettings,
IWorkContext workContext,
SKUAllocationService skuAllocationService)
{
_workContext= workContext;
_vendorSettings= vendorSettings;
_skuAllocationService = skuAllocationService;
}
#endregion
<more methods snipped>
I have tried registering my objects in my nop startup:
// Create the container builder.
var builder = new ContainerBuilder();
builder.RegisterType <IRepository<SkuAllocation>>().As<IRepository<SkuAllocation>>();
builder.RegisterType<ILogger>().As<ILogger>();
builder.RegisterType<SKUAllocationService>();
var container = builder.Build();
using (var scope = container.BeginLifetimeScope())
{
var component = scope.Resolve<SKUAllocationService>();
}
this just gets a a similar constructor not found error
Can anyone point me to where I'm going wrong