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

Service.registerService should enforce a service instance implements an interface #271

Open
leggetter opened this issue Dec 3, 2013 · 2 comments

Comments

@leggetter
Copy link
Contributor

Right now I can register as service as follows:

var br = require( 'br' );
var ServiceRegistry = require( 'br/ServiceRegistry' );

function MyService() {
}

MyService.prototype.doSomething = function() {
  console.log( 'something' );
};

ServiceRegistry.registerService( 'my.something-service', new MyService() );

But the purpose of the ServiceRegistry is (via @james-shaw-turner):

Services are supposed to hide away the implementation details behind a facade and conform to a contract (the interface) This enables us to swap out implementations for tests, workbenches etc. We should add enforcement.

We can do this (enforcement) via Topiarist, but it may need to be updated to expose a way of checking what interfaces a class implements in a more public way. It is possible, it does store a __interfaces__ property right now that we could use.

So, we need to perform a check when a service is registered that that instance provided does implement an interface.

More thought required.

@james-shaw-turner Would you class this as a feature enhancement or a bug?

@james-shaw-turner
Copy link
Contributor

I would say it is an enhancement.
As Adam points out if the service is defined as an alias then this is already covered. We could add checking for the case where services are added programmatically but this shouldn't be common usage. So this is relatively low priority

@janhancic
Copy link
Contributor

Yes, services registered trough aliases are already checked.

But how would you do the checking with registerService? How would you know which interface to check against?

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

No branches or pull requests

4 participants