TYPO3 Extbase - Does Dependency Injection work in Service Classes? - typo3

I'm using a Service of type auth for adding an API based login.
I tried to add a User with the FrontendUserRepository of Extbase via #inject.
But this doesn't work.
Am i doing something wrong or is this to early to use the Dependency Injection?
P.S.: I know i can use the repository the following way:
$objectManager = GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
$this->frontendUserRepository = $objectManager->get('TYPO3\\CMS\\Extbase\\Domain\\Repository\\FrontendUserRepository');

DI with the #Inject annotation works only for objects loaded by a TYPO3\CMS\Extbase\Object\ObjectManager instance. The auth services are beeing instantiated using GeneralUtility::makeInstanceService() which in turn uses GeneralUtility::makeInstance() (see TYPO3\CMS\Core\Authentication\AbstractUserAuthentication::checkAuthentication()), so the #Inject annotation has no effect.
You must use the workaround mentioned already by yourself.

[typo3 7.6]
I think in the auth service all the extbase stuff in not proper loaded. I have lots of errors while trying to use extbase repos in a auth service (which are running great in context of controller). I found one link about a possible init of the missing parts: Extbase innerhalb eines TYPO3 Authentication Services verwenden

Related

Sails js :: How to add custom validation error

Like Rails is there any way to add custom error message to validator?
Like:
if(this.password != this.passwordConfirmation){
this.errors.add('password', {rule: 'invalid'})
}
You can create custom validations on your models. Or create custom objects and inject them into your models to resusable code. Its actually in the docs!
http://sailsjs.org/#/documentation/concepts/ORM/Validations.html?q=custom-validation-rules
You can create a custom config file for error handling. You can reach that global config object by sails.config.error for example. Advantage of this solution is, that you can access this object in services and other places, where you have no access to the res object.
Next step would be creating a policy which would pass this config error object to res.locals. Or it could be handled in a response file, but I have no experience with that.
Out of the box, Sails.js does not support custom validation messages. But there's a workaround, using hooks.
http://sailsjs.org/documentation/concepts/models-and-orm/validations#?custom-validation-rules
Says the official site.

How to get the doctrine event manager in bootstrap?

I am using zf-boilerplate for my zend framework project. I am using the Gedmo extensions and need to get an instance of the doctrine event manager in the bootstrap.
ie. I would like to be able to do the following:
$evm = $this->getDoctrine()->getEventManager()
How can I do this?
You can access the entity manager by calling
Zend_Registry::get('em');
If you're in the middle of bootsrap, then make sure you bootstrap entity manager before accessing it.
Just like resource methods, you use the bootstrap() method to execute resource plugins. Just like with resource methods, you can specify either a single resource plugin, multiple plugins (via an array), or all plugins. Additionally, you can mix and match to execute resource methods as well.
(Zend Framework manual)
i.e. execute the code below first
// Execute all resource methods and plugins:
$bootstrap->bootstrap('doctrine');
UPDATE
Didn't notice the question was about EventManager. Use the code below in order to get access to it
Zend_Registry::get('doctrine')->getEventManager ();

IoC, MVC4 Web API & HttpParameterBinding/ParameterBindingAttribute

I'm using ASP.Net MVC 4 RTM Web API. I have a controller action with a parameter that I'd like to populate via custom model binding. To achieve this, I created a class that derives from System.Web.Http.Controllers.HttpParameterBinding that sets the value of this parameter. I then created an attribute class that derives from System.Web.Http.ParameterBindingAttribute which I use to decorate the parameter on my controller action.
This is all working great, my HttpParameterBinding class is populating the action parameter correctly. The problem I have is that my custom parameter binding class has a dependency that I'd like resolved via my IoC container (Unity). Is there a way to override how Web API creates HttpParameterBinding instances so that I can build up my custom binding class dependency from Unity? I was able to do something similar for a filter attribute by creating a custom filter provider that uses Unity's BuildUp method to populate dependencies, however I'm not seeing anything similar for Web API's HttpParameterBindings.
In general: to use IoC / Unity in the Web API you need to set it up seperately.
Try downloading the nuget package Unity.WebApi and see if that helps!
Take a look at this article: Parameter Binding in WebAPI
It walks through a couple different options from Converters to Binders to BinderProviders. It sounds like you may be able to write a custom ModelBinderProvider which knows how to provide your dependency. If that isn't high enough in the chain you can look at replacing the default IActionValueBinder service. It's a DefaultActionValueBinder instance, which you can extend or simply re-implement.
I also highly recommend downloading the WebAPI source code, as it's been an incredible help for these issues as I've run into them. Here's the WebAPI source code. I recommend downloading it so you can open it in VS for easy navigation.
Feel free to check out FlitBit too (It's very modular, don't let the number of packages scare you off)! I'm working on a WebAPI package for supporting FlitBit, specifically FlitBit.IoC and FlitBit.Dto. I'll add an update if I work out my IoC issue, since it's very similar to yours.

pimcore: How to enable zend's automatic routing

I read through the Zend Controller doco and it says that it can do routing as follows:
example.com/controller/action
But in Pimcore this seems to be disabled. I have to define static routes.
I don't mind defining the routes, but the thing is my regular expressions aren't very good.
Can someone explain to me if it is possible to enable the normal zend controller style routing as above and stop having to make use of the pimcore's built in static routes?
Thanks
It's not possible to enable the normal zend controller style routing, without breaking pimcore. There are 2 possibilities:
use example.org/?controller=controllername&action=actionname for direct access to a controller-action (as described in the Pimcore Documentation - Magic Parameters)
use the built in static routes. For example:
pattern: |/news/list|, controller: news, action: list
have a look at pimcore plugins for that. /pugin/name/controller/action/ ...

Wicket 1.4 EJB Support

I tried implementing the JavaEE Inject jar from Wicket Stuff. (glassfish v3, wicket 1.4)
- however, the code given in the tutorial doesn't work
method
addComponentInstantiationListener in
class org.apache.wicket.Application
cannot be applied to given types
required:
org.apache.wicket.application.IComponentInstantiationListener
found:
org.wicketstuff.javaee.injection.JavaEEComponentInjector
looks to me like the API has changed. The JIRA link inside
http://wicketstuff.org/confluence/display/STUFFWIKI/JavaEE+Inject
and the Repository link are both broken. Is it still maintained?
Another short question: Is it possible to populate ListView directly with entity beans? I'd like to avoid too many proxy classes.
Thanks in advance
Yes, you can inject a ListView with entity beans. You should do so by creating an implementation of IDataProvider (or one of it's sub-interfaces) for the iterator and have it wrap the entities with LoadableDetachableModel so they can be reloaded instead of serialized as a part of the session.
Figured it out: I didn't expect there to be a difference between 1.4.13 and 1.4.14 but apparently the API changed there significantly.