Plugin Development

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
4 years ago
I am writing a custom plugin and slowly try to extend its functionality.

This constructor works great
public BlankObjectContext(DbContextOptions<BlankObjectContext> options) : base(options)
        {
        }



This overloaded constructor
public OverloadObjectContext(DbContextOptions<OverloadObjectContext> options, IDbContext dbContext, INopFileProvider fileProvider) : base(options)
        {
            this._dbContext = dbContext;
            this._fileProvider = fileProvider;
        }


Gives me an error at
public static void RegisterPluginDataContext<TContext>(this ContainerBuilder builder, string contextName) where TContext : DbContext, IDbContext
        {
            //register named context
            builder.Register(context => (IDbContext)Activator.CreateInstance(typeof(TContext), new[] { context.Resolve<DbContextOptions<TContext>>() }))
                .Named<IDbContext>(contextName).InstancePerLifetimeScope();
        }


System.MissingMethodException: 'Constructor on type 'Nop.Plugin.Fanolli.Journal.Data.OverloadObjectContext' not found.'

any idea why?
4 years ago
I think it could be that your Activator.CreateInstance() parameter   new[] { ... }   is an array of only one object, and your overloaded constructor has four parameters.  I.e. it can't find a matching constructor.
4 years ago
you are right...

I ended up doing it like this
public MyPluginObjectContext(DbContextOptions<MyPluginObjectContext> options) : base(options)
        {
            _dbContext = EngineContext.Current.Resolve<IDbContext>();
            _fileProvider = EngineContext.Current.Resolve<INopFileProvider>();
        }
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.