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
Post a Comment