Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to "configureAop" within a service container #65

Closed
mpoiriert opened this issue Jun 30, 2013 · 7 comments
Closed

How to "configureAop" within a service container #65

mpoiriert opened this issue Jun 30, 2013 · 7 comments

Comments

@mpoiriert
Copy link

This is not really a bug but more of a question to help me integegrate your AOP framework. I don't know any other channel to ask you this kind of question...

I'm using the ServiceContainer of symfony for a framework that I'm building and I'm integrating your aop system built-in in the framework. Since I'm mainly basing my system on annotation, I need to parse all the class to being able to build the service container.

Within the service container, on the initialize method I'm registering all the services that have been mark as aspect to call the aspectContainer->registerAspect() method. The problem that I got is that since the file have been generated without the aspects being registered on the parsing phase the class are already generated without the aspect.

If I'm deleteting the aop cache folder (but keeping the generated ServiceContainer file) everything is working fine but only on the second call.

Do you have any suggestion of how to do this ? I could put a different configuration for the Aop service VS the regualr service but I would prefer everything to be transparent for the user... I though about generating the service container trough command line and deleting the aop/cache directory and than terminate the first call but I find this solution really hacky...

Also I would I do unit/integration testing efficiently with your system ?

Thanks !

@lisachenko
Copy link
Member

Thank you for the report! Very nice question )

I have been thinking a lot about this issue but have not found a good solution. You have chosen the correct technique for registering aspects in the AOP kernel by looking for the specific tags in the container. However this action should be the first during the cache initialization otherwise it will result in the classes are already generated without the aspects.

You are right that the configuration for AOP and DiC should be in the one place to be transparent for user. But this is not so easy. Maybe extracting of AOP kernel interface can solve this issue? There will be a way to implement this interface for custom application and use it instead of AspectKernel class. I need some time to investigate this possibility, because it's a major feature to implement.

CompilerPass+DI+IoC+AOP = cool ) But each part should be low coupled.

BTW, FLOW3 uses DiC with AOP, but this integration is so tight and hardcoded ( Don't want to make such a dependency on specific container in my framework

@mpoiriert
Copy link
Author

I did make a workaround in my framework for it... it's not beautiful but it does work...

The only requirement is to prefix your service name with "aspect." and obviously the aspect themself must not be dependant on aspect and cannot use the injection... I did a IServiceContainerAware interface so the Aspect class can receive the full container if needed. This is pretty much the impact on the user...

On the implementation part what I did is to register in the container all the Aspect during the compiler pass prior to any other service. When the service are loaded the aspect are already registerer. When the container is generated a real instance will be created. Since you are using a singleton for the AspectKernel and that the Aspect are already registered for this request, at the start of the service container I check all the registered Aspect and inject the service container into them (if needed).

It's a bit ugly for now but like the saying "Make it work, then make it pretty..." I'll work on the pretty part a bit later... I'll let you think about a solution.

@lisachenko
Copy link
Member

Thank you for feedback! I'm thinking about the solution for integration with DiC and have an initial implementation for this. Probably, I'll create a separate repository for this project, because I want to keep AOP component standalone.

Stay tuned )

lisachenko added a commit that referenced this issue Jul 7, 2013
@lisachenko
Copy link
Member

I succeeded in combining AOP and Symfony DIC ) Looks very promising: https://github.com/lisachenko/warlock. Need to make some cleaning and fixes.

lisachenko added a commit that referenced this issue Jul 16, 2013
@lisachenko
Copy link
Member

This issue is resolved in the Warlock framework. I have a cool ideas to create an amazing framework, based on DiC, AOP and annotations.

@mpoiriert
Copy link
Author

If you have the time look at my framework (nucleus)... it's not completed (and lack of documentation) but if it's going in the same direction has your idea I would be happy to have you as a contributor. I already have another great developper who's working on it

@lisachenko
Copy link
Member

I'm watching at nucleus framework to track changes in it, because it's very interesting. I'll try to look more deeper into your project later. Unfortunately, it's very complicated and has specific features for your application, so I want to develop a new components like in Symfony2, but they will be based on AOP technology and will use standard Symfony2 DI container and config to handle all the configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants