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

Dependency injection in API classes #7407

Merged
merged 2 commits into from Mar 17, 2015
Merged

Dependency injection in API classes #7407

merged 2 commits into from Mar 17, 2015

Conversation

mnapoli
Copy link
Contributor

@mnapoli mnapoli commented Mar 10, 2015

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.

@mnapoli mnapoli added Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc. Needs Review PRs that need a code review labels Mar 10, 2015
@mnapoli mnapoli added this to the Piwik 2.12.0 milestone Mar 10, 2015
@diosmosis
Copy link
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
Copy link
Member

👍 for DI!

@mnapoli
Copy link
Contributor Author

mnapoli commented Mar 11, 2015

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
Copy link
Member

mattab commented Mar 12, 2015

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)

mnapoli added a commit that referenced this pull request Mar 17, 2015
Dependency injection in API classes
@mnapoli mnapoli merged commit f76ec24 into master Mar 17, 2015
@mnapoli mnapoli deleted the di-api branch March 17, 2015 03:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc. Needs Review PRs that need a code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants