how to override core controller method - nopcommerce

I want to use core controller method which is "product" action method and non action prepareProductDetailMethod in my plugin but I want to only override this method in my plugin
not implement again in my plugin
So.How to call core controller method?
Please give me steps as well as example.

You can't use it,because all that methods are protected,if you want it from another controller in nopcommerce then you can do it but you need to declare this protected methods as a public, but from plugin you can declare them public, so just copy that method in your plugin.

Related

Inject custom service into Behat context

Is it possible to build and inject my own, custom services into a Behat Context class?
I'm integrating Behat with Symfony2, and I can inject Symfony's services into my contexts like so:
contexts:
- Meeebu\MyBundle\Features\Security\Context\SecurityContext:
session: '#session'
provided that the Behat\Symfony2Extension is registered.
I'm also using Behat Page Object Extension that injects Page objects into Context constructor directly, so my constructo currently looks like this:
public function __construct(Session $session, Homepage $homepage, WelcomeAdmin $welcomeAdminPage)
Now, I'd like to use my owe custom services in the Context class.
How can I create, register, and inject them in Behat?
you need to create and register a behat extension: https://github.com/Behat/Behat/blob/2.5/src/Behat/Behat/Extension/ExtensionInterface.php
and then register your service (or load an yml/xml/etc. file) in the load method.
and then add an extension class to the behat.yml, to the extensions section.

System.Web.Http.Authorize versus System.Web.Mvc.Authorize

Which Authorize Attribute ?
System.Web.Http.Authorize
System.Web.Mvc.Authorize
using System.Web.Mvc // or
using System.Web.Http
A typical controller
[Authorize]
public class SomeController : Controller
We have controllers Annotated with [Authorize]
I just noticed that due to using namespaces the annotations technically refer to different attribute classes.
The project contains MVC controllers and WEBAPI controllers.
Which one should I use and why ?
What issues might we have if I dont fix this ?
You must use System.Web.Http.Authorize against an ApiController (Web API controller) and System.Web.Mvc.Authorize against a Controller (MVC controller). Since the framework runs the filters as part of the pipeline processing and the controllers expect the right filter to be applied, if you don't use the corresponding filter, authorization will not work.

Can I have both a Controller and an ApiController for the same thing?

I've just started to use the VS 2012 RC, and I'm creating an ASP.NET MVC 4 web application in which I plan to provide both an HTML-based user interface and a WebApi-based programming interface.
For my HTML website, I have a controller and view for each of my models (MVC!), and the routing works "by convention" so that, for example, the URL /client hooks up to my ClientController. My ClientController derives from Controller.
For my API, I will create new controllers that derive from ApiController. I naturally want my API URLs to be similar to my HTML URLs, so I'd like the client info to be available at /api/client. However, with the by-convention routing, that would suggest that I need an ApiController named ClientController. And I already have a ClientController class.
How do I deal with this? Do I need custom routing? Do I put the API classes in different namespace so that I can give them the same name?
Update: this question seems to suggest that a different namespace for my API controllers is all I need: Mix web api controllers and site controllers
All it requires is for the controller classes to be in a different namespace, and all is well.
Using MVC areas would also work (as suggested in gordonml's comment), but this effectively puts the controllers in different namespaces, so it's a more formal way of achieving the same result.
You may take a look at the following blog post which illustrates how an Api controller could serve Razor views as well. Basically he uses the RazorEngine to parse the Razor view end serve it.
For anyone looking for step by step guidance on how to do this on WebApi project:
Create two folders / namespaces, namely: ControllersApi and ControllersWeb
Right click on ControllersWeb and go Add -> Controller and select MVC 5 Controller - Empty. This will add all other dependencies if you didn't have them in your WebApi project.
Your RouteConfig will now register those classes that inherit from Controller base class. You'll likely need to add link to default Controller, by editing defaults to say: defaults: new { action = "Index", controller = "Home", id = UrlParameter.Optional }
That's it, you can now run site and use both API and Web controllers.

Is is possible to programmatically change the resourceProviderFactoryType?

I have a custom implementation of IResourceProvider and ResourceProviderFactory. Now the default way of making sure ASP.NET uses these custom types is to use the web.config and specify the factory like so:
<globalization resourceProviderFactoryType="Product.Globalization.TranslationResourceProviderFactory" />
This works perfectly, except that in my resource provider I need database access. I want to use my IoC-container(Ninject) to inject the repositories needed to access this data into the CustomResourceProvider. But how am I going to do this? I have no control over the instantiation of the factory, so the factory can't get a reference to my IoC.
Is there any way to register a custom provider programmatically, in for example the Global.asax?
Your custom implementation of ResourceProviderFactory could use the DI framework to retrieve the instance of IResourceProvider.

Why are ASP.Net MVC2 area controller actions callable without including the area in the url path?

I've just installed Visual Studio 2010 and have created a new MVC2 project so that I can learn about the changes and updates and have discovered an issue with areas that I'm not sure what to make of.
I created a new EMPTY MVC2 project
I right clicked the project and, from the context menu, added a new area called "Test"
In the new test area, I added a controller called "Data".
The code is:
public class DataController : Controller
{
//
// GET: /Test/Data/
public ActionResult Index()
{
Response.Write("Hi");
return new EmptyResult();
}
}
Now, I compile and call this address:
http://localhost/mytest/test/data and get the output:
Hi
All good. Now I call this: http://localhost/mytest/data and get the same response! I thought routing was supposed to take care of this? Am I overlooking something? Or has the default project setup for MVC2 overlooked something?
This is intentional. The default route in Global.asax does not limit its search to a particular area or set of namespaces. There are overloads of MapRoute (see one example on MSDN) which take a namespaces parameter, which can be used to disambiguate which controller was meant by this request. But even so, the namespaces parameter is just a hint about which namespaces to search in first; it's not a restriction.
In short, in MVC, you have to be prepared for any of your controllers to be hit by any route. This is why all of the MVC documentation states that security and other logic should be done at the controller level, never at the route level.

Resources