Closed paulvanbladel closed 9 years ago
I'm not clear on what the problem/question is.
Sorry, I'll summarize the questions?
Gotcha.
The value converter name is not derived from the file, but from the export name of the class, with "ValueConverter" stripped and then camel cased. You can always explicitly name the value converter by applying a decorator like this @valueConverter('foo')
You can have multiple value converters exported from a single module.
Using globalizeResources
is the proper way to make plugin resources globally available to the view system.
Thanks Rob. Appreciated. I'm just trying to apply the most aesthetic way of working with plugins. Ok, so a value converter is seen as a real resource , like an html template.
What confuses me, is what is the actual use case for adding something in the aurelia container via aurelia.container.registerSingleton or the other methods. (i understand in general the use case for containers, like MEF and others)
In case i want to expose a simple class (e.g. a service) from the plugin to the consuming app I could simply write in the index.js file of the plugin .
export {MyClass} from './myClass';
and the consuming app could use it as follows:s
import {MyClass} from 'my plugin package name';
Could you please indicate how in this scenario registering MyClass in the aurelia container would be useful?
Thanks in advance.
You register your class in the container if you want consumers to able to inject instances of it into their classes...or if your class has dependencies that you want it to receive from the container. It's the same as any DI use case.
(Incidentally, your value converter is actually instantiated by the DI container. It just needs to be registered as a resource because that tells the compiler how to map various identifiers it finds while compiling views to actual classes that get instanced by the DI.)
I have a plugin with exposes a value converter in the following manner I'm assuming here that I'm doing it in the way it should be done, I'm using the aurelia.globalizeResources.
Now, the file authFilter contains the actual valueConverter class named AuthFilterValueConverter, so starting with a capital letter and ending with ValueConverter.
The way I need to use it as global resource inside a piece of html is:
So,, as authFilter starting with a lower case letter.
Is there not a way to register the the value converter in a more transparant way with aurelia.container.registerSingleton ?
I tried things, but didn't work. Note, that the technique above aurelia.globalizeResources works. I think that the convention that ValueConverter is stripped off is ok, but it feels like the name authFilter refers in the first place to the name of file rather than the class AuthFilterValueConverter.