Refactor chat module to utilize standardized service tokens for improved dependency management
- Update chat module to use SERVICE_TOKENS for chat service registration and injection, enhancing consistency across the application. - Modify useChat composable to reference the standardized service token, ensuring alignment with the new DI container structure. - Clean up references to the previous CHAT_SERVICE_TOKEN, streamlining the codebase and improving maintainability.
This commit is contained in:
parent
e8b9f04494
commit
30b9089829
2 changed files with 9 additions and 9 deletions
|
|
@ -1,11 +1,11 @@
|
|||
import { ref, computed } from 'vue'
|
||||
import { injectService } from '@/core/di-container'
|
||||
import { injectService, SERVICE_TOKENS } from '@/core/di-container'
|
||||
import type { ChatService } from '../services/chat-service'
|
||||
import type { ChatPeer } from '../types'
|
||||
import { useMultiAsyncOperation } from '@/core/composables/useAsyncOperation'
|
||||
|
||||
// Service token for chat service
|
||||
export const CHAT_SERVICE_TOKEN = Symbol('chatService')
|
||||
// Use standardized service token from DI container
|
||||
export const CHAT_SERVICE_TOKEN = SERVICE_TOKENS.CHAT_SERVICE
|
||||
|
||||
export function useChat() {
|
||||
const chatService = injectService<ChatService>(CHAT_SERVICE_TOKEN)
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import type { App } from 'vue'
|
||||
import type { ModulePlugin } from '@/core/types'
|
||||
import type { RouteRecordRaw } from 'vue-router'
|
||||
import { container } from '@/core/di-container'
|
||||
import { container, SERVICE_TOKENS } from '@/core/di-container'
|
||||
import { eventBus } from '@/core/event-bus'
|
||||
|
||||
// Import chat components and services
|
||||
import ChatComponent from './components/ChatComponent.vue'
|
||||
import { ChatService } from './services/chat-service'
|
||||
import { useChat, CHAT_SERVICE_TOKEN } from './composables/useChat'
|
||||
import { useChat } from './composables/useChat'
|
||||
import type { ChatConfig } from './types'
|
||||
|
||||
/**
|
||||
|
|
@ -33,7 +33,7 @@ export const chatModule: ModulePlugin = {
|
|||
|
||||
// Create and register chat service
|
||||
const chatService = new ChatService(config)
|
||||
container.provide(CHAT_SERVICE_TOKEN, chatService)
|
||||
container.provide(SERVICE_TOKENS.CHAT_SERVICE, chatService)
|
||||
|
||||
// Initialize the service (will handle dependency injection)
|
||||
await chatService.initialize({
|
||||
|
|
@ -60,10 +60,10 @@ export const chatModule: ModulePlugin = {
|
|||
console.log('🗑️ Uninstalling chat module...')
|
||||
|
||||
// Clean up chat service
|
||||
const chatService = container.inject<ChatService>(CHAT_SERVICE_TOKEN)
|
||||
const chatService = container.inject<ChatService>(SERVICE_TOKENS.CHAT_SERVICE)
|
||||
if (chatService) {
|
||||
chatService.destroy()
|
||||
container.remove(CHAT_SERVICE_TOKEN)
|
||||
container.remove(SERVICE_TOKENS.CHAT_SERVICE)
|
||||
}
|
||||
|
||||
console.log('✅ Chat module uninstalled')
|
||||
|
|
@ -90,7 +90,7 @@ export const chatModule: ModulePlugin = {
|
|||
},
|
||||
|
||||
services: {
|
||||
chatService: CHAT_SERVICE_TOKEN
|
||||
chatService: SERVICE_TOKENS.CHAT_SERVICE
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue