c# - Use a Nop Service outside of a controller? -


i'm writing custom validation attribute validating zip\postal codes. work absolutely need know selected country. turns out surprisingly difficult do.

in view models nop passes country using id, means need decipher it. way use countryservice since can translate id country name, problem how that.

if create new countryservice object have create , pass number of dependencies (cacheservice object etc.) , sounds wrong way of achieving result. how use nop service outside controller (in case inside custom validation attribute)?

you don't need create object instance service locator.

something this:

var countryservice= enginecontext.current.resolve<icountryservice>(); 

you can check attribute in nopcommerce wwwrequirementattribute , check how uses locator pattern.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -