Complete LnbitsAPI migration to dependency injection pattern
- Convert LnbitsAPI from singleton to BaseService extension - Add LNBITS_API service token to DI container - Register LnbitsAPI service in base module with proper initialization order - Update AuthService to depend on injected LnbitsAPI instead of singleton - Fix BaseService to properly track LnbitsAPI dependency in getMissingDependencies - Update events API functions to use dependency injection - Resolve initialization timing issue preventing application startup 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
093846b351
commit
4a3d2012be
6 changed files with 69 additions and 18 deletions
|
|
@ -61,16 +61,33 @@ interface User {
|
|||
}
|
||||
}
|
||||
|
||||
import { BaseService } from '@/core/base/BaseService'
|
||||
import { getApiUrl, getAuthToken, setAuthToken, removeAuthToken } from '@/lib/config/lnbits'
|
||||
|
||||
class LnbitsAPI {
|
||||
export class LnbitsAPI extends BaseService {
|
||||
// Service metadata
|
||||
protected readonly metadata = {
|
||||
name: 'LnbitsAPI',
|
||||
version: '1.0.0',
|
||||
dependencies: [] // No dependencies - this is a core infrastructure service
|
||||
}
|
||||
|
||||
private accessToken: string | null = null
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
// Try to load token from localStorage
|
||||
this.accessToken = getAuthToken()
|
||||
}
|
||||
|
||||
/**
|
||||
* Service-specific initialization (called by BaseService)
|
||||
*/
|
||||
protected async onInitialize(): Promise<void> {
|
||||
this.debug('LnbitsAPI initialized')
|
||||
// Service is ready to use
|
||||
}
|
||||
|
||||
private async request<T>(
|
||||
endpoint: string,
|
||||
options: RequestInit = {}
|
||||
|
|
@ -183,5 +200,5 @@ class LnbitsAPI {
|
|||
}
|
||||
}
|
||||
|
||||
export const lnbitsAPI = new LnbitsAPI()
|
||||
// Service is now registered in the DI container
|
||||
export type { LoginCredentials, RegisterData, AuthResponse, User }
|
||||
Loading…
Add table
Add a link
Reference in a new issue