negyedik gyakorlat megoldás javítva
This commit is contained in:
@@ -22,8 +22,9 @@
|
|||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@prisma/client": "^5.9.1",
|
"@prisma/client": "^5.9.1",
|
||||||
"bcrypt": "^5.1.1",
|
"bcryptjs": "^2.4.3",
|
||||||
"cookie-parser": "^1.4.6",
|
"cookie-parser": "^1.4.6",
|
||||||
|
"cors": "^2.8.5",
|
||||||
"dotenv": "^16.4.1",
|
"dotenv": "^16.4.1",
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"handlebars": "^4.7.8",
|
"handlebars": "^4.7.8",
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ container.registerTransient('UserController', (c) =>
|
|||||||
);
|
);
|
||||||
|
|
||||||
// ===== Middleware =====
|
// ===== Middleware =====
|
||||||
app.use(corsMiddleware()); // CORS with whitelist
|
app.use(corsMiddleware); // CORS with whitelist
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
app.use(express.urlencoded({ extended: true }));
|
app.use(express.urlencoded({ extended: true }));
|
||||||
app.use(cookieParser());
|
app.use(cookieParser());
|
||||||
|
|||||||
@@ -27,11 +27,41 @@ class Container {
|
|||||||
|
|
||||||
// Ha singleton, azonnal példányosítjuk
|
// Ha singleton, azonnal példányosítjuk
|
||||||
if (lifetime === 'singleton') {
|
if (lifetime === 'singleton') {
|
||||||
const instance = factory();
|
const instance = factory(this);
|
||||||
this.services.set(name, instance);
|
this.services.set(name, instance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Singleton service regisztráció (kényelmi függvény)
|
||||||
|
*
|
||||||
|
* @param {string} name - Service neve
|
||||||
|
* @param {Function} factory - Factory függvény ami az instance-t létrehozza
|
||||||
|
*/
|
||||||
|
registerSingleton(name, factory) {
|
||||||
|
this.register(name, factory, 'singleton');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transient service regisztráció (kényelmi függvény)
|
||||||
|
*
|
||||||
|
* @param {string} name - Service neve
|
||||||
|
* @param {Function} factory - Factory függvény ami az instance-t létrehozza
|
||||||
|
*/
|
||||||
|
registerTransient(name, factory) {
|
||||||
|
this.register(name, factory, 'transient');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scoped service regisztráció (kényelmi függvény)
|
||||||
|
*
|
||||||
|
* @param {string} name - Service neve
|
||||||
|
* @param {Function} factory - Factory függvény ami az instance-t létrehozza
|
||||||
|
*/
|
||||||
|
registerScoped(name, factory) {
|
||||||
|
this.register(name, factory, 'scoped');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service feloldás
|
* Service feloldás
|
||||||
*
|
*
|
||||||
@@ -52,7 +82,7 @@ class Container {
|
|||||||
if (scope.has(name)) {
|
if (scope.has(name)) {
|
||||||
return scope.get(name);
|
return scope.get(name);
|
||||||
}
|
}
|
||||||
const instance = this.factories.get(name)();
|
const instance = this.factories.get(name)(this);
|
||||||
scope.set(name, instance);
|
scope.set(name, instance);
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
@@ -64,7 +94,7 @@ class Container {
|
|||||||
|
|
||||||
// TRANSIENT: Mindig új instance
|
// TRANSIENT: Mindig új instance
|
||||||
if (lifetime === 'transient') {
|
if (lifetime === 'transient') {
|
||||||
return this.factories.get(name)();
|
return this.factories.get(name)(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default: singleton behavior
|
// Default: singleton behavior
|
||||||
@@ -123,4 +153,4 @@ class Container {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Container;
|
export { Container };
|
||||||
|
|||||||
@@ -154,5 +154,4 @@ class EmailService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
export { EmailService };
|
||||||
export default EmailService;
|
|
||||||
|
|||||||
Reference in New Issue
Block a user