Plugin Development

Posted: May 25, 2019 at 10:58 AM Quote #232466
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?
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: May 25, 2019 at 3:57 PM Quote #233510
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.
This post/answer is useful
1
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
www.noptools.com
Posted: May 26, 2019 at 10:45 AM Quote #233524
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 post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Premium support services
  • Dedicated premium support services provided by core developers are intended for persons who run mission critical websites, work on projects with tight deadlines, or want to get dedicated support.
Professional services
  • Want to open a new store? Want to take your store to the next level? Need a custom extension? We can customize nopCommerce to fit your store perfectly. Request a quote to get started.
eCommerce CONFERENCE 2019
Learn more