@mnapoli opened this Pull Request on March 10th 2015 Member

This introduces the ability to use dependency injection in API classes.

This also registers API classes in the container (so these classes can be injected), though they are still singletons. The problem is that the singleton pattern in Piwik also offers unsetInstance() and setSingletonInstance() and I think this would mess up with the container, but since those should only be used in tests (right?) we should be fine and be able to fix it easily.

@diosmosis commented on March 11th 2015 Member

Re: unsetInstance()/setSingletonInstance(), we could mark them as deprecated. I don't think anyone's supposed to use them anyway, and eventually we'll be able to remove them entirely.

@diosmosis commented on March 11th 2015 Member

:+1: for DI!

@mnapoli commented on March 11th 2015 Member

Good point! They are only used in tests except in the LanguagesManager to "clear the cache" basically so this could be replaced by something better.

I've added the deprecations.

@mattab commented on March 12th 2015 Owner

Looks good to me!

+1 to deprecate unsetInstance/ setSingletonInstance and remove it in couple months.

(I noticed there are protected constructors in InterSites and CustomAlerts maybe those can be changed after PR is merged)

This Pull Request was closed on March 17th 2015
Powered by GitHub Issue Mirror