Skip to content

Commit

Permalink
Add removed
Browse files Browse the repository at this point in the history
  • Loading branch information
ackava committed Jul 11, 2023
1 parent b19c5f4 commit b7e389d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
14 changes: 7 additions & 7 deletions src/di/di.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ export class ServiceProvider implements IDisposable {
this[parentServiceProvider] = parent;
}

add<T1, T extends T1>(type: IAbstractClassOf<T1> | IClassOf<T1>, instance: T) {
this.getRegistration(type, true);
this.map.set(type, instance);
instance[serviceProvider] = this;
return instance;
}
// add<T1, T extends T1>(type: IAbstractClassOf<T1> | IClassOf<T1>, instance: T) {
// this.getRegistration(type, true);
// this.map.set(type, instance);
// instance[serviceProvider] = this;
// return instance;
// }


createScope() {
Expand Down Expand Up @@ -117,7 +117,7 @@ export class ServiceProvider implements IDisposable {
if (!sd) {

if (add) {
const registration: IServiceDescriptor = { key: type, kind: "Scoped"};
const registration: IServiceDescriptor = { key: type, kind: this[parentServiceProvider] ? "Scoped" : "Singleton" };
registrations.set(type, registration);
return registration;
}
Expand Down
18 changes: 9 additions & 9 deletions src/tests/security/tests/place-order.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assert from "assert";
import Logger from "../../../common/Logger.js";
import { ServiceProvider } from "../../../di/di.js";
import { ServiceCollection, ServiceProvider } from "../../../di/di.js";
import { BaseDriver } from "../../../drivers/base/BaseDriver.js";
import ContextEvents from "../../../model/events/ContextEvents.js";
import { TestConfig } from "../../TestConfig.js";
Expand Down Expand Up @@ -31,10 +31,10 @@ async function getNewOrders(this: TestConfig) {
try {
const user = new UserInfo();
user.userID = 2;
scope.add(Logger, Logger.instance);
scope.add(BaseDriver, this.driver);
scope.add(UserInfo, user);
scope.add(ContextEvents, new ShoppingContextEvents());
ServiceCollection.register("Singleton", Logger, () => Logger.instance);
ServiceCollection.register("Singleton", BaseDriver, () => this.driver);
ServiceCollection.register("Scoped", UserInfo, () => user);
ServiceCollection.register("Singleton", ContextEvents, () => new ShoppingContextEvents());
const context = scope.create(ShoppingContext);
context.verifyFilters = true;

Expand All @@ -53,10 +53,10 @@ async function addNewOrder(this: TestConfig, customer: User, userID?) {
try {
const user = new UserInfo();
user.userID = userID ?? customer.userID;
scope.add(Logger, Logger.instance);
scope.add(BaseDriver, this.driver);
scope.add(UserInfo, user);
scope.add(ContextEvents, new ShoppingContextEvents());
ServiceCollection.register("Singleton", Logger, () => Logger.instance);
ServiceCollection.register("Singleton", BaseDriver, () => this.driver);
ServiceCollection.register("Scoped", UserInfo, () => user);
ServiceCollection.register("Singleton", ContextEvents, () => new ShoppingContextEvents());
const context = scope.create(ShoppingContext);
context.verifyFilters = true;

Expand Down

0 comments on commit b7e389d

Please sign in to comment.