i'm trying to practice as im new to development in nopcommerce plugin. I'm trying to make a plugin to add/edit record to a sql table fiels: ID, RecordName
When I open up the admin interface and plugins and click Install I get the error No constructor was found that had all the dependencies satisfied.
DependencyRegistrar.cs
public class DependencyRegistrar : IDependencyRegistrar { private const string CONTEXT_NAME = "nop_object_context_random_sql"; public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, NopConfig config) { builder.RegisterType<RandomSQLService>().As<RandomSQLService>().InstancePerLifetimeScope(); builder.RegisterPluginDataContext<RandomSQLObjectContext>(CONTEXT_NAME);
builder.RegisterType<EfRepository<RandomSQLRecord>>().As<IRepository<RandomSQLRecord>>() .WithParameter(ResolvedParameter.ForNamed<IDbContext>(CONTEXT_NAME)) .InstancePerLifetimeScope(); } public int Order => 1; }
RandomSQLPlugin.cs (in the root of the plugin solution)
namespace Nop.Plugin.Widgets.RandomSQL { public class RandomSQLPlugin : BasePlugin { private RandomSQLObjectContext _context;
public RandomSQLPlugin(RandomSQLObjectContext context) { _context = context; }
public override void Install() { _context.Install(); base.Install(); }
public override void Uninstall() { _context.Uninstall(); base.Uninstall(); } } }
public class RandomSQLObjectContext : DbContext, IDbContext { public RandomSQLObjectContext(DbContextOptions<RandomSQLObjectContext> options) : base(options) { }
public void Install() { this.ExecuteSqlScript(this.GenerateCreateScript()); }
public void Uninstall() { this.DropPluginTable("RandomSQL"); } public virtual new DbSet<TEntity> Set<TEntity>() where TEntity : BaseEntity { return base.Set<TEntity>(); }
Microsoft.EntityFrameworkCore.DbSet<TEntity> IDbContext.Set<TEntity>() { throw new System.NotImplementedException(); }
public IQueryable<TQuery> QueryFromSql<TQuery>(string sql) where TQuery : class { throw new System.NotImplementedException(); }
public IQueryable<TEntity> EntityFromSql<TEntity>(string sql, params object[] parameters) where TEntity : BaseEntity { throw new System.NotImplementedException(); }
public void Detach<TEntity>(TEntity entity) where TEntity : BaseEntity { throw new System.NotImplementedException(); }
public int ExecuteSqlCommand(RawSqlString sql, bool doNotEnsureTransaction = false, int? timeout = null, params object[] parameters) { using (var transaction = this.Database.BeginTransaction()) { var result = this.Database.ExecuteSqlCommand(sql, parameters); transaction.Commit();