mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
refactor(core): Use an IoC container to manage singleton classes [Part-1] (no-changelog) (#5509)
* add typedi * convert ActiveWorkflowRunner into an injectable service * convert ExternalHooks into an injectable service * convert InternalHooks into an injectable service * convert LoadNodesAndCredentials into an injectable service * convert NodeTypes and CredentialTypes into an injectable service * convert ActiveExecutions into an injectable service * convert WaitTracker into an injectable service * convert Push into an injectable service * convert ActiveWebhooks and TestWebhooks into an injectable services * handle circular references, and log errors when a circular dependency is found
This commit is contained in:
committed by
GitHub
parent
aca94bb995
commit
52f740b9e8
@@ -24,6 +24,7 @@ import { ExternalHooks } from '@/ExternalHooks';
|
||||
import type { User } from '@db/entities/User';
|
||||
import type { CredentialRequest } from '@/requests';
|
||||
import { CredentialTypes } from '@/CredentialTypes';
|
||||
import { Container } from 'typedi';
|
||||
|
||||
export class CredentialsService {
|
||||
static async get(
|
||||
@@ -205,7 +206,7 @@ export class CredentialsService {
|
||||
credentialId: string,
|
||||
newCredentialData: ICredentialsDb,
|
||||
): Promise<ICredentialsDb | null> {
|
||||
await ExternalHooks().run('credentials.update', [newCredentialData]);
|
||||
await Container.get(ExternalHooks).run('credentials.update', [newCredentialData]);
|
||||
|
||||
// Update the credentials in DB
|
||||
await Db.collections.Credentials.update(credentialId, newCredentialData);
|
||||
@@ -224,7 +225,7 @@ export class CredentialsService {
|
||||
const newCredential = new CredentialsEntity();
|
||||
Object.assign(newCredential, credential, encryptedData);
|
||||
|
||||
await ExternalHooks().run('credentials.create', [encryptedData]);
|
||||
await Container.get(ExternalHooks).run('credentials.create', [encryptedData]);
|
||||
|
||||
const role = await Db.collections.Role.findOneByOrFail({
|
||||
name: 'owner',
|
||||
@@ -256,7 +257,7 @@ export class CredentialsService {
|
||||
}
|
||||
|
||||
static async delete(credentials: CredentialsEntity): Promise<void> {
|
||||
await ExternalHooks().run('credentials.delete', [credentials.id]);
|
||||
await Container.get(ExternalHooks).run('credentials.delete', [credentials.id]);
|
||||
|
||||
await Db.collections.Credentials.remove(credentials);
|
||||
}
|
||||
@@ -279,7 +280,7 @@ export class CredentialsService {
|
||||
): ICredentialDataDecryptedObject {
|
||||
const copiedData = deepCopy(data);
|
||||
|
||||
const credTypes = CredentialTypes();
|
||||
const credTypes = Container.get(CredentialTypes);
|
||||
let credType: ICredentialType;
|
||||
try {
|
||||
credType = credTypes.getByName(credential.type);
|
||||
|
||||
Reference in New Issue
Block a user