nopCommerce 4.2 Validation is not working while plugin assembly is not start with "Nop"

1 2 >
Posted: June 11, 2019 at 8:42 AM Quote #237505
Hi to all,
Currently I'm working with plugin for nopCommerce 4.20 and my plugin's assembly name is started with custom name instead of "Nop".

I found below code under Nop.Web > Presentation > Nop.Web.Framework > Infrastructure > Extensions > ServiceCollectionExtensions.cs which is inject FluentValidation which is shows that inject only those assembly which is start with "Nop" world.



          
 mvcBuilder.AddFluentValidation(configuration =>
            {
                //register all available validators from Nop assemblies
                var assemblies = mvcBuilder.PartManager.ApplicationParts
                    .OfType<AssemblyPart>()
                    .Where(part => part.Name.StartsWith("Nop", StringComparison.InvariantCultureIgnoreCase))
                    .Select(part => part.Assembly);
                configuration.RegisterValidatorsFromAssemblies(assemblies);

                //implicit/automatic validation of child properties
                configuration.ImplicitlyValidateChildProperties = true;
            });



I tried to add this code snippet in startup file with inherit INopStartup file with my assembly start word, but it not worked.

Any help would be appreciated.
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)
Up-vote the answer, if it helps you! :)


Thank You
Raju Paladiya
-------------------------------------------------------
nopAccelerate - Faster, Reliable & Scalable nopCommerce

sales(at)nopaccelerate.com
http://www.nopAccelerate.com | http://www.xcellence-it.com
Posted: June 12, 2019 at 9:18 AM Quote #237581
Is this a 3rd party plugin or one of your own?

If it is 3rd party could you not go back to them and say that it doesn't work?

If it is your own plugin (and whilst not ideal) could you not rename the plugin assembly to be Nop.Plugin.[Group].[Name] to work around the issue?

It does sound like an issue though.  If nopcommerce allows you register plugins with any name then it should also register the validation in those plugins.

What is the code that you have added in your own INopStartup that is not working correctly and are you sure that it is getting executed?
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: June 13, 2019 at 5:11 AM Quote #237692
davidandrewpowell wrote:
Is this a 3rd party plugin or one of your own?

My own custom plugin

davidandrewpowell wrote:
  
If it is your own plugin (and whilst not ideal) could you not rename the plugin assembly to be Nop.Plugin.[Group].[Name] to work around the issue?

My plugin assembly name like DemoNop.Plugin.Widgets.NivoSlider  (I have tried with change defult NivoSlider slider plugin for testing purpose)

davidandrewpowell wrote:
  
It does sound like an issue though.  If nopcommerce allows you register plugins with any name then it should also register the validation in those plugins.

I don't think nopCommerce 4.20 is suport  with my assembly name.

davidandrewpowell wrote:

What is the code that you have added in your own INopStartup that is not working correctly and are you sure that it is getting executed?


Here is code            
    
//add fluent validation
            services.AddNopMvc().AddFluentValidation(x =>
            {
                //register all available validators from Nop assemblies
                var assemblies = services.AddNopMvc().PartManager.ApplicationParts
                    .OfType<AssemblyPart>()
                    .Where(part => part.Name.StartsWith("DemoNop", StringComparison.InvariantCultureIgnoreCase))
                    .Select(part => part.Assembly);
                x.RegisterValidatorsFromAssemblies(assemblies);

                //implicit/automatic validation of child properties
                x.ImplicitlyValidateChildProperties = true;
            });
    
  

I am getting error during run application:

InvalidOperationException: Sequence contains more than one matching element
System.Linq.Enumerable.SingleOrDefault<TSource>(IEnumerable<TSource> source, Func<TSource, bool> predicate)

DependencyResolutionException: An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = IObjectModelValidator (DelegateActivator), Services = [Microsoft.AspNetCore.Mvc.ModelBinding.Validation.IObjectModelValidator], Lifetime = Autofac.Core.Lifetime.RootScopeLifetime, Sharing = Shared, Ownership = OwnedByLifetimeScope ---> Sequence contains more than one matching element (See inner exception for details.)
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)
Up-vote the answer, if it helps you! :)


Thank You
Raju Paladiya
-------------------------------------------------------
nopAccelerate - Faster, Reliable & Scalable nopCommerce

sales(at)nopaccelerate.com
http://www.nopAccelerate.com | http://www.xcellence-it.com
Posted: June 13, 2019 at 5:13 AM Quote #237694
I also followed this post but no luck.
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)
Up-vote the answer, if it helps you! :)


Thank You
Raju Paladiya
-------------------------------------------------------
nopAccelerate - Faster, Reliable & Scalable nopCommerce

sales(at)nopaccelerate.com
http://www.nopAccelerate.com | http://www.xcellence-it.com
Posted: June 14, 2019 at 7:55 AM Quote #237797
As I understand it, your plugin is named DemoNop.Plugin.Widgets.NivoSlider.

To create this plugin did you take a copy of Nop.Plugin.Widgets.NivoSlider?

If this is the case, when you are running nopcommerce are you running it with both Nop.Plugin.Widgets.NivoSlider and DemoNop.Plugin.Widgets.NivoSlider installed side by side or have you removed the original Nop.Plugin.Widgets.NivoSlider?

I guess I'm trying to establish from the error "Sequence contains more than one matching element" that there are no conflicts from duplicating the NivoSlider plugin.

Also, I still don't understand why you can't instead name the plugin "Nop.Plugin.Widgets.DemoNivoSlider" or similar and avoid the hassle of having to setup your own FluentValidation registration.
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: June 18, 2019 at 4:10 AM Quote #238089
any updates on this? i am also facing issue for the validator register at nopcommerce 4.2 for my custom plugin, anyone can help?
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: June 18, 2019 at 4:58 AM Quote #238093
Finally I am able to solve this, just add line below to your ConfigureServices where you inherit INopStartup in your custom plugin, it will solve the issue:

    //register validator
    services.AddTransient<IValidator<CustomRegisterModel>, RegisterValidator>();



overall code will be as below:

/// <summary>
        /// Add and configure any of the middleware
        /// </summary>
        /// <param name="services">Collection of service descriptors</param>
        /// <param name="configuration">Configuration root of the application</param>
        //public void ConfigureServices(IServiceCollection services, IConfigurationRoot configuration)
        public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
        {
          

            //register validator
            services.AddTransient<IValidator<CustomRegisterModel>, RegisterValidator>();


        }
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: June 18, 2019 at 5:00 AM Quote #238094
ysheah wrote:
any updates on this? i am also facing issue for the validator register at nopcommerce 4.2 for my custom plugin, anyone can help?


Are you also using a plugin name that does not follow nopcommerce convention? What name did you use for your plugin?

Can you provide any more information as to what you have done for someone to potentially recreate this issue?
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: June 18, 2019 at 5:03 AM Quote #238095
davidandrewpowell wrote:
any updates on this? i am also facing issue for the validator register at nopcommerce 4.2 for my custom plugin, anyone can help?

Are you also using a plugin name that does not follow nopcommerce convention? What name did you use for your plugin?

Can you provide any more information as to what you have done for someone to potentially recreate this issue?



Hi, davidandrewpowell, yes my plugin name is custom name that not following the nopcommerce standard which is Nop.Plugin.Misc... My Plugin name is like mycompanyname.plugin.misc.name. In nopcommerce 4.2, I believe we will need to register the validator ourself at our custom name plugin, the solution I have stated at previous reply.
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: June 18, 2019 at 5:14 AM Quote #238096
ysheah wrote:
Hi, davidandrewpowell, yes my plugin name is custom name that not following the nopcommerce standard which is Nop.Plugin.Misc... My Plugin name is like mycompanyname.plugin.misc.name. In nopcommerce 4.2, I believe we will need to register the validator ourself at our custom name plugin, the solution I have stated at previous reply.


I must have just missed your response with your solution. Glad you managed to get it working.
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)
1 2 >
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.