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.
Related
I'm using Spring MVC through Spring boot starters (1.3.2) and i saw a difference of behavior regarding which template engine i'm using.
#Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
#Override
public void addViewControllers(ViewControllerRegistry registry) {
// template file
registry.addViewController("/index").setViewName("index");
// static file
registry.addViewController("/login").setViewName("login.html");
}
}
If i used Freemarker as template engine, Spring mvc will take the file from resources/static for /login and in resources/templates for /index
Whereas, if i used Thymeleaf as template engine, Spring will take all the files (login and index) from resources/templates.
As far as I know, this paths depends of application properties. By default:
#for freemaker
spring.freemarker.template-loader-path=classpath:/templates/
#for thymeleaf
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
Full list of common application properties you can find here.
View controller does not change behavior. When you entered url, Spring looking for method of Controller or ViewController, which has suitable request mapping. If method found, Spring invoke it. After that, controller's method returns view name as string, and Spring ask for special bean, named ViewResolver, to find view with this name.
Since every template engine has own ViewResolver, and any ViewResolver has it's own setings (as I said above), they're looking for templates in different places.
For example, you're using Thymeleaf and entered as url something like: localhost:8080/index. First, spring will find controller method or view-controller mapped with index. After that, controller will return string index. Spring will ask for Teamleaf view resolver to find this view. According to default settings, view resolver will add classpath:/templates/ before view name, and .html after view name, and after that will try to open file with this name.
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.
I made a custom Document Manager for my project implementing some new low level functions (following this post).
Now I would like to inject a custom configuration in my new Document Manager (I suppose it would be the same with an Entity Manager). I have no idea of how to do this...
I want this config in my yaml files to set my custom Document Manager's parameters. The only way I found until now is to write a static function returning a hardcoded array of configuration, but it's a little dirty...)
Is there a proper way or an alternative to do this?
For defining custom configuration in the conig.yml file, use this symfony docs. You can access those configurations easily in a controller:
$this->container->getParameter(name_of_bundle_here)
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.
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.