Skip to content

Commit

Permalink
fix: Fixed the missing services problem when enhancing the provider.
Browse files Browse the repository at this point in the history
  • Loading branch information
devtronic committed Jan 2, 2023
1 parent 276b8a9 commit 7e67cba
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 3.2.3

Fixes:
- Fixed the enhance method and overtake the expose map and the known services map.

## 3.2.2

Fixes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ cb.Method enhanceTemplate(String providerClassName) {
.property(serviceInstances$.symbol!)
.property('addAll')
.call([serviceInstances$]).statement,
enhancedV
.property(knownServices$.symbol!)
.property('addAll')
.call([knownServices$]).statement,
enhancedV
.property(exposeMap$.symbol!)
.property('addAll')
.call([exposeMap$]).statement,
ForEachBuilder(servicesP, serviceV)
.finalize(enhancedV.property(registerInternal$.symbol!).call([
serviceV.property('returnType'),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: catalyst_builder
description: A lightweight and easy to use dependency injection provider builder for dart.
version: 3.2.2
version: 3.2.3
homepage: 'https://github.com/mintware-de/catalyst_builder'
repository: 'https://github.com/mintware-de/catalyst_builder'

Expand Down
33 changes: 33 additions & 0 deletions test/integration/integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,39 @@ void main() {
expect(newProvider.resolve<String>(), 'This should also work');
});

test('enhance should contain previous manual registered services', () {
if (serviceProvider is! EnhanceableProvider) {
fail('Service provider is not a EnhanceableProvider');
}
expect(serviceProvider.has<SelfRegisteredService>(), isFalse);
expect(serviceProvider.has<String>(), isFalse);

var newProvider = (serviceProvider as EnhanceableProvider).enhance(
services: [
LazyServiceDescriptor<MySelfRegisteredService>(
(p) => MySelfRegisteredService(p.resolve()),
const Service(exposeAs: SelfRegisteredService),
),
],
);

expect(newProvider.has<SelfRegisteredService>(), isTrue);
expect(newProvider.has<String>(), isFalse);

var newProvider2 = (newProvider as EnhanceableProvider).enhance(
services: [
LazyServiceDescriptor<String>(
(p) => 'This should also work',
const Service(exposeAs: String),
),
],
);

expect(newProvider2.has<SelfRegisteredService>(), isTrue);
expect(newProvider2.has<String>(), isTrue);

});

test('resolveByTag', () {
var services = serviceProvider.resolveByTag(#chat);
expect(services, isNotEmpty);
Expand Down

0 comments on commit 7e67cba

Please sign in to comment.