-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add and expose resolveServiceDeactivations instead of res…
…olveBindingDeactivations
- Loading branch information
1 parent
cbd2b27
commit 8dc32c4
Showing
11 changed files
with
545 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
"@inversifyjs/core": minor | ||
--- | ||
|
||
Added `resolveBindingDeactivations`. | ||
Added `resolveServiceDeactivations`. |
70 changes: 70 additions & 0 deletions
70
packages/container/libraries/core/src/binding/calculations/isScopedBinding.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { beforeAll, describe, expect, it } from '@jest/globals'; | ||
|
||
import { bindingScopeValues } from '../models/BindingScope'; | ||
import { bindingTypeValues } from '../models/BindingType'; | ||
import { ConstantValueBinding } from '../models/ConstantValueBinding'; | ||
import { ServiceRedirectionBinding } from '../models/ServiceRedirectionBinding'; | ||
import { isScopedBinding } from './isScopedBinding'; | ||
|
||
describe(isScopedBinding.name, () => { | ||
describe('having a ServiceRedirectionBinding', () => { | ||
let serviceRedirectionBindingFixture: ServiceRedirectionBinding<unknown>; | ||
|
||
beforeAll(() => { | ||
serviceRedirectionBindingFixture = { | ||
id: 1, | ||
isSatisfiedBy: () => true, | ||
moduleId: undefined, | ||
serviceIdentifier: 'service-id', | ||
targetServiceIdentifier: 'target-service-id', | ||
type: bindingTypeValues.ServiceRedirection, | ||
}; | ||
}); | ||
|
||
describe('when called', () => { | ||
let result: unknown; | ||
|
||
beforeAll(() => { | ||
result = isScopedBinding(serviceRedirectionBindingFixture); | ||
}); | ||
|
||
it('should return false', () => { | ||
expect(result).toBe(false); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('having a ConstantValueBinding', () => { | ||
let constantValueBindingFixture: ConstantValueBinding<unknown>; | ||
|
||
beforeAll(() => { | ||
constantValueBindingFixture = { | ||
cache: { | ||
isRight: false, | ||
value: undefined, | ||
}, | ||
id: 1, | ||
isSatisfiedBy: () => true, | ||
moduleId: undefined, | ||
onActivation: undefined, | ||
onDeactivation: undefined, | ||
scope: bindingScopeValues.Singleton, | ||
serviceIdentifier: 'service-id', | ||
type: bindingTypeValues.ConstantValue, | ||
value: 'foo', | ||
}; | ||
}); | ||
|
||
describe('when called', () => { | ||
let result: unknown; | ||
|
||
beforeAll(() => { | ||
result = isScopedBinding(constantValueBindingFixture); | ||
}); | ||
|
||
it('should return true', () => { | ||
expect(result).toBe(true); | ||
}); | ||
}); | ||
}); | ||
}); |
15 changes: 15 additions & 0 deletions
15
packages/container/libraries/core/src/binding/calculations/isScopedBinding.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { | ||
Binding, | ||
BindingScope, | ||
BindingType, | ||
ScopedBinding, | ||
} from '@inversifyjs/core'; | ||
|
||
export function isScopedBinding<T>( | ||
binding: Binding<T>, | ||
): binding is Binding<T> & ScopedBinding<BindingType, BindingScope, T> { | ||
return ( | ||
(binding as Partial<ScopedBinding<BindingType, BindingScope, T>>).scope !== | ||
undefined | ||
); | ||
} |
43 changes: 43 additions & 0 deletions
43
packages/container/libraries/core/src/binding/fixtures/ConstantValueBindingFixtures.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { bindingScopeValues } from '../models/BindingScope'; | ||
import { bindingTypeValues } from '../models/BindingType'; | ||
import { ConstantValueBinding } from '../models/ConstantValueBinding'; | ||
|
||
export class ConstantValueBindingFixtures { | ||
public static get any(): ConstantValueBinding<unknown> { | ||
return { | ||
cache: { | ||
isRight: false, | ||
value: undefined, | ||
}, | ||
id: 1, | ||
isSatisfiedBy: () => true, | ||
moduleId: undefined, | ||
onActivation: undefined, | ||
onDeactivation: undefined, | ||
scope: bindingScopeValues.Singleton, | ||
serviceIdentifier: 'service-id', | ||
type: bindingTypeValues.ConstantValue, | ||
value: Symbol.for('constant-value-binding-fixture-value'), | ||
}; | ||
} | ||
|
||
public static get withCacheWithIsRightFalse(): ConstantValueBinding<unknown> { | ||
return { | ||
...ConstantValueBindingFixtures.any, | ||
cache: { | ||
isRight: false, | ||
value: undefined, | ||
}, | ||
}; | ||
} | ||
|
||
public static get withCacheWithIsRightTrue(): ConstantValueBinding<unknown> { | ||
return { | ||
...ConstantValueBindingFixtures.any, | ||
cache: { | ||
isRight: true, | ||
value: Symbol.for('constant-value-binding-fixture-value'), | ||
}, | ||
}; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
packages/container/libraries/core/src/binding/fixtures/InstanceBindingFixtures.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { bindingScopeValues } from '../models/BindingScope'; | ||
import { bindingTypeValues } from '../models/BindingType'; | ||
import { InstanceBinding } from '../models/InstanceBinding'; | ||
|
||
export class InstanceBindingFixtures { | ||
public static get any(): InstanceBinding<unknown> { | ||
return { | ||
cache: { | ||
isRight: false, | ||
value: undefined, | ||
}, | ||
id: 1, | ||
implementationType: class Foo {}, | ||
isSatisfiedBy: () => true, | ||
moduleId: undefined, | ||
onActivation: undefined, | ||
onDeactivation: undefined, | ||
scope: bindingScopeValues.Singleton, | ||
serviceIdentifier: 'service-id', | ||
type: bindingTypeValues.Instance, | ||
}; | ||
} | ||
|
||
public static get withCacheWithScopeSingleton(): InstanceBinding<unknown> { | ||
return { | ||
...InstanceBindingFixtures.any, | ||
scope: bindingScopeValues.Singleton, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.