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:
padreug 2025-09-05 16:32:42 +02:00
parent e8b9f04494
commit 30b9089829
2 changed files with 9 additions and 9 deletions

View file

@ -1,11 +1,11 @@
import { ref, computed } from 'vue' 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 { ChatService } from '../services/chat-service'
import type { ChatPeer } from '../types' import type { ChatPeer } from '../types'
import { useMultiAsyncOperation } from '@/core/composables/useAsyncOperation' import { useMultiAsyncOperation } from '@/core/composables/useAsyncOperation'
// Service token for chat service // Use standardized service token from DI container
export const CHAT_SERVICE_TOKEN = Symbol('chatService') export const CHAT_SERVICE_TOKEN = SERVICE_TOKENS.CHAT_SERVICE
export function useChat() { export function useChat() {
const chatService = injectService<ChatService>(CHAT_SERVICE_TOKEN) const chatService = injectService<ChatService>(CHAT_SERVICE_TOKEN)

View file

@ -1,13 +1,13 @@
import type { App } from 'vue' import type { App } from 'vue'
import type { ModulePlugin } from '@/core/types' import type { ModulePlugin } from '@/core/types'
import type { RouteRecordRaw } from 'vue-router' 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 { eventBus } from '@/core/event-bus'
// Import chat components and services // Import chat components and services
import ChatComponent from './components/ChatComponent.vue' import ChatComponent from './components/ChatComponent.vue'
import { ChatService } from './services/chat-service' import { ChatService } from './services/chat-service'
import { useChat, CHAT_SERVICE_TOKEN } from './composables/useChat' import { useChat } from './composables/useChat'
import type { ChatConfig } from './types' import type { ChatConfig } from './types'
/** /**
@ -33,7 +33,7 @@ export const chatModule: ModulePlugin = {
// Create and register chat service // Create and register chat service
const chatService = new ChatService(config) 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) // Initialize the service (will handle dependency injection)
await chatService.initialize({ await chatService.initialize({
@ -60,10 +60,10 @@ export const chatModule: ModulePlugin = {
console.log('🗑️ Uninstalling chat module...') console.log('🗑️ Uninstalling chat module...')
// Clean up chat service // Clean up chat service
const chatService = container.inject<ChatService>(CHAT_SERVICE_TOKEN) const chatService = container.inject<ChatService>(SERVICE_TOKENS.CHAT_SERVICE)
if (chatService) { if (chatService) {
chatService.destroy() chatService.destroy()
container.remove(CHAT_SERVICE_TOKEN) container.remove(SERVICE_TOKENS.CHAT_SERVICE)
} }
console.log('✅ Chat module uninstalled') console.log('✅ Chat module uninstalled')
@ -90,7 +90,7 @@ export const chatModule: ModulePlugin = {
}, },
services: { services: {
chatService: CHAT_SERVICE_TOKEN chatService: SERVICE_TOKENS.CHAT_SERVICE
} }
} }