4.10 Plugin No constructor was found that had all the dependencies satisfied.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
5 years ago
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();
        }      
    }
}
5 years ago
RandomSQLObjectContext.cs  

public class RandomSQLObjectContext : DbContext, IDbContext
    {
        public RandomSQLObjectContext(DbContextOptions<RandomSQLObjectContext> options) : base(options)
        {
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.ApplyConfiguration(new RandomSQLMap());
            base.OnModelCreating(modelBuilder);
        }
        public virtual string GenerateCreateScript()
        {
            return this.Database.GenerateCreateScript();
        }

        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();

                return result;
            }
        }
    }
5 years ago
Hello,

May be pluginsdbstartup.cs file is missing.

Can you please recheck?
5 years ago
thats exactly what it was the file was missing. I copied it over from Shipping By Weight and change the content now the plugin installed.

thanks for the help!!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.