@barfittc/vue-service-provider
v0.1.3
Published
in tsconfig ```json { "compilerOptions": { "emitDecoratorMetadata": true } }
Downloads
6
Readme
in tsconfig
{
"compilerOptions": {
"emitDecoratorMetadata": true
}
}
or
{
"references": [{ "path": "node_modules/@barfittc/vue-service-provider/tsconfig.json" }]
}
To use
In your main.
createApp(App)
.use(addServiceProvider())
.use(addServiceProviderConsumer())
.mount('#app')
in your Vue Plugin, register your services
export class TestConsumerTwo {
hello;
constructor (hello:string) {
this.hello = hello;
}
}
export class TestConsumerOne {
@service(TestConsumerTwo)
test!: TestConsumerTwo;
/** gets called after creation and injection */
setup() {
console.log(this.test.hello)
};
}
export function addServiceProviderConsumer ():Plugin {
return function(app:App){
getRegistry(app)
.AddSingleton(TestConsumerOne) // 1 instance ever created
.AddTransiant(TestConsumerTwo, "world"); // new instance created every request, you can also pass arguments to the contructor
}
}
inside your <script setup lang="ts">
const one = getService(TestConsumerOne);
console.log(one.test.hello);