Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,27 +61,3 @@ jobs:

- name: Run tests
run: dart test
test_catalyst_builder_container:
runs-on: ubuntu-latest
defaults:
run:
working-directory: packages/catalyst_builder_container

steps:
- uses: actions/checkout@v2

- uses: dart-lang/setup-dart@v1
with:
sdk: 'stable'

- name: Install dependencies
run: dart pub get

- name: Verify formatting
run: dart format --output=none --set-exit-if-changed lib

- name: Analyze project source
run: dart analyze lib

- name: Run tests
run: dart test
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@

# Catalyst Builder

A dependency injection provider builder for dart.
A dependency injection container builder for dart.

This is the workspace root, select a specific package for more details.

| Package | Description | Badges |
|-----------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [`catalyst_builder`](./packages/catalyst_builder) | The builder package. Use this in your root package or plugin package to generate the ServiceContainerPlugin. | [![Pub](https://img.shields.io/pub/v/catalyst_builder.svg)](https://pub.dartlang.org/packages/catalyst_builder)<br> ![Pub Points](https://img.shields.io/pub/points/catalyst_builder)<br> ![Pub Likes](https://img.shields.io/pub/likes/catalyst_builder)<br> ![Pub Monthly Downloads](https://img.shields.io/pub/dm/catalyst_builder) |
| [`catalyst_builder_container`](./packages/catalyst_builder_container) | The container package. Use this package to resolve services from the container. | [![Pub](https://img.shields.io/pub/v/catalyst_builder_container.svg)](https://pub.dartlang.org/packages/catalyst_builder_container) <br> ![Pub Points](https://img.shields.io/pub/points/catalyst_builder_container) <br> ![Pub Likes](https://img.shields.io/pub/likes/catalyst_builder_container) <br> ![Pub Monthly Downloads](https://img.shields.io/pub/dm/catalyst_builder_container) |
| [`catalyst_builder_contracts`](./packages/catalyst_builder_contracts) | The contracts package. Use this in packages that don't need to generate a service provider but provide services that can be resolved. | [![Pub](https://img.shields.io/pub/v/catalyst_builder_contracts.svg)](https://pub.dartlang.org/packages/catalyst_builder_contracts) <br> ![Pub Points](https://img.shields.io/pub/points/catalyst_builder_contracts) <br> ![Pub Likes](https://img.shields.io/pub/likes/catalyst_builder_contracts) <br> ![Pub Monthly Downloads](https://img.shields.io/pub/dm/catalyst_builder_contracts) |
| Package | Description | Badges |
|-----------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [`catalyst_builder`](./packages/catalyst_builder) | The builder package. Use this in your root package or plugin package to generate the ServiceContainerPlugin. | [![Pub](https://img.shields.io/pub/v/catalyst_builder.svg)](https://pub.dartlang.org/packages/catalyst_builder)<br> ![Pub Points](https://img.shields.io/pub/points/catalyst_builder)<br> ![Pub Likes](https://img.shields.io/pub/likes/catalyst_builder)<br> ![Pub Monthly Downloads](https://img.shields.io/pub/dm/catalyst_builder) |
| [`catalyst_builder_contracts`](./packages/catalyst_builder_contracts) | The contracts package. Use this in packages that don't need to generate a service container but provide services that can be resolved. | [![Pub](https://img.shields.io/pub/v/catalyst_builder_contracts.svg)](https://pub.dartlang.org/packages/catalyst_builder_contracts) <br> ![Pub Points](https://img.shields.io/pub/points/catalyst_builder_contracts) <br> ![Pub Likes](https://img.shields.io/pub/likes/catalyst_builder_contracts) <br> ![Pub Monthly Downloads](https://img.shields.io/pub/dm/catalyst_builder_contracts) |

## Roadmap

Expand All @@ -20,6 +19,6 @@ This is the workspace root, select a specific package for more details.
| Description | Status |
|---------------------------------------------------------------------------|--------|
| Remove the annotations inside the catalyst_builder_package | ☑️ |
| Remove the service provider subclasses | ☑️ |
| Remove the service container subclasses | ☑️ |
| Stop generating the ServiceProvider and create a default ServiceContainer | ☑️ |
| Add scope support | 🔲 |
3 changes: 2 additions & 1 deletion packages/catalyst_builder/.pubignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
run_tests.sh
run_tests.sh
**/*.g.dart
6 changes: 6 additions & 0 deletions packages/catalyst_builder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 5.0.0-rc.1

### Breaking Changes

- Removed the generation of the service container. Check the [GenerateServiceProvider](https://github.com/mintware-de/catalyst_builder/wiki/v5#generateserviceprovider) section for upgrade guidance.

## 5.0.0-dev.2

### Changes
Expand Down
6 changes: 3 additions & 3 deletions packages/catalyst_builder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# Catalyst Builder

A dependency injection provider builder for dart.
A dependency injection container builder for dart.

Click on the image for a video on YouTube:

Expand All @@ -24,9 +24,9 @@ Since [Catalyst](https://github.com/mintware-de/catalyst) is only for Dart
and [Flutter Catalyst](https://github.com/mintware-de/flutter_catalyst)
supports Flutter, but a mess to configure I decided to do something cooler.

Catalyst Builder is a dependency injection provider builder for both, Dart and Flutter. It's easy to use and dependency
Catalyst Builder is a dependency injection container builder for both, Dart and Flutter. It's easy to use and dependency
injection is almost done automatically. You only have to decorate your services with `@Service` and the build_runner
will create a service provider for you.
will create a service container for you.

## Installation

Expand Down
10 changes: 4 additions & 6 deletions packages/catalyst_builder/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ builders:
build_to: cache
auto_apply: root_package
runs_before:
- 'catalyst_builder:buildServiceProvider'
- 'catalyst_builder:buildServiceProviderPlugin'
- 'catalyst_builder:buildServiceContainerPlugin'
applies_builders:
- 'catalyst_builder:buildServiceProvider'
- 'catalyst_builder:buildServiceProviderPlugin'
- 'catalyst_builder:buildServiceContainerPlugin'

buildServiceProviderPlugin:
buildServiceContainerPlugin:
import: 'package:catalyst_builder/src/builder/builders.dart'
builder_factories:
- 'createServiceProviderPluginBuilder'
- 'createServiceContainerPluginBuilder'
build_extensions: { '.dart': [ '.catalyst_builder.plugin.g.dart' ] }
build_to: source
auto_apply: dependents
Expand Down
22 changes: 11 additions & 11 deletions packages/catalyst_builder/example/bin/catalyst_builder_example.dart
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import 'package:catalyst_builder_container/catalyst_builder_container.dart';
import 'package:catalyst_builder/catalyst_builder.dart';
import 'package:catalyst_builder_example/example.dart';

void main(List<String> arguments) {
var provider = ServiceContainer();
provider.useExampleProviderPlugin();
var container = ServiceContainer();
container.useExampleContainerPlugin();

provider.parameters['sender_username'] = 'Julian';
container.parameters['sender_username'] = 'Julian';

print('Post parameter set, pre boot');
provider.boot();
container.boot();
print('Post boot, pre resolve');

var chat = provider.resolve<ChatProvider>();
var chat = container.resolve<ChatProvider>();
print(chat.runtimeType);
chat.sendChatMessage('WTF, this is really cool!');

provider.register(
(provider) => MySelfRegisteredService(provider.resolve()),
container.register(
(container) => MySelfRegisteredService(container.resolve()),
);

var selfRegistered = provider.resolve<MySelfRegisteredService>();
var selfRegistered = container.resolve<MySelfRegisteredService>();
selfRegistered.sayHello();

// Contains CoolChatProvider and ConsoleTransport
var servicesByTag = provider.resolveByTag(#chat);
var servicesByTag = container.resolveByTag(#chat);
for (var svc in servicesByTag) {
print(svc);
}

var broadcaster = provider.resolve<Broadcaster>();
var broadcaster = container.resolve<Broadcaster>();
broadcaster.sendChatMessage('Hello Broadcast using injection tag.');
}
4 changes: 2 additions & 2 deletions packages/catalyst_builder/example/lib/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export './src/manually_wired_service.dart';
export 'example.catalyst_builder.plugin.g.dart';

@Preload()
@GenerateServiceProviderPlugin(
pluginClassName: 'ExampleProviderPlugin',
@GenerateServiceContainerPlugin(
pluginClassName: 'ExampleContainerPlugin',
)
@ServiceMap(services: {
ManuallyWiredServiceImplementation: Service(
Expand Down
8 changes: 2 additions & 6 deletions packages/catalyst_builder/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,15 @@ dependencies:
path: ../../catalyst_builder_contracts
third_party_dependency:
path: ../test/third_party_dependency
catalyst_builder_container:
path: ../../catalyst_builder_container
catalyst_builder:
path: ../

dev_dependencies:
lints: ^5.1.1
build_runner: ^2.0.1
catalyst_builder:
path: ../

dependency_overrides:
catalyst_builder:
path: ../
catalyst_builder_contracts:
path: ../../catalyst_builder_contracts
catalyst_builder_container:
path: ../../catalyst_builder_container
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
library;

export 'src/service_container.dart';
8 changes: 4 additions & 4 deletions packages/catalyst_builder/lib/src/builder/builders.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'package:build/build.dart';

import 'preflight_builder.dart';
import 'service_provider_plugin_builder.dart';
import 'service_container_plugin_builder.dart';

/// Creates the builder for the preflight step
Builder createPreflightBuilder(BuilderOptions options) => PreflightBuilder();

/// Creates the service provider plugin builder
Builder createServiceProviderPluginBuilder(BuilderOptions options) =>
ServiceProviderPluginBuilder();
/// Creates the service container plugin builder
Builder createServiceContainerPluginBuilder(BuilderOptions options) =>
ServiceContainerPluginBuilder();
4 changes: 2 additions & 2 deletions packages/catalyst_builder/lib/src/builder/constants.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const String preflightExtension = '.catalyst_builder.preflight.json';
const String serviceProviderExtension = '.catalyst_builder.g.dart';
const String oldAnnotationsPrefix = 'package:catalyst_builder/src/annotation/';
const String serviceProviderPluginExtension = '.catalyst_builder.plugin.g.dart';
const String serviceContainerPluginExtension =
'.catalyst_builder.plugin.g.dart';
const String annotationsPrefix =
'package:catalyst_builder_contracts/src/annotation/';
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import '../../symbols.dart';
cb.Method provideKnownServicesTemplate(List<ExtractedService> services) {
var serviceFactories = <cb.Reference, cb.Expression>{};

var pP = cb.refer('p');
var containerP = cb.refer('c');
for (var svc in services) {
var serviceType = cb.refer(svc.service.symbolName, svc.service.library);

Expand All @@ -22,7 +22,7 @@ cb.Method provideKnownServicesTemplate(List<ExtractedService> services) {
exposeAsReference,
serviceType,
svc,
pP,
containerP,
);
}

Expand All @@ -32,8 +32,8 @@ cb.Method provideKnownServicesTemplate(List<ExtractedService> services) {
..name = provideKnownServices$.symbol
..returns = mapOfT(typeT, serviceDescriptorT)
..requiredParameters.add(cb.Parameter((p) => p
..name = pP.symbol!
..type = serviceProviderT))
..name = containerP.symbol!
..type = abstractServiceContainerT))
..body = cb
.literalMap(serviceFactories, typeT, serviceDescriptorT)
.returned
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import '../../dto/dto.dart';
import '../symbols.dart';
import 'methods/methods.dart';

/// Generates the code for the service provider.
cb.Class buildServiceProviderPluginClass(
/// Generates the code for the service container.
cb.Class buildServiceContainerPluginClass(
String pluginClassName,
List<ExtractedService> services,
) {
return cb.Class((c) => c
..name = pluginClassName
..implements.addAll([serviceProviderPluginT])
..implements.addAll([serviceContainerPluginT])
..methods.addAll([
provideKnownServicesTemplate(services),
provideExposesTemplate(services),
Expand All @@ -23,7 +23,7 @@ cb.Class buildServiceProviderPluginClass(
cb.Extension buildExtension(String pluginClassName) {
return cb.Extension((e) => e
..name = "${pluginClassName}Extension"
..on = serviceProviderT
..on = abstractServiceContainerT
..methods.add(cb.Method((m) => m
..name = "use$pluginClassName"
..returns = voidT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cb.Expression buildServiceFactory(
cb.Reference? exposeAsReference,
cb.Reference serviceType,
ExtractedService svc,
cb.Reference providerP,
cb.Reference containerP,
) {
var factory = cb.MethodBuilder();

Expand All @@ -21,10 +21,10 @@ cb.Expression buildServiceFactory(
var namedArgs = <String, cb.Expression>{};

var tryResolveOrGetParameter_ =
providerP.property(tryResolveOrGetParameter$.symbol!);
var resolveByTag_ = providerP.property(resolveByTag$.symbol!);
containerP.property(tryResolveOrGetParameter$.symbol!);
var resolveByTag_ = containerP.property(resolveByTag$.symbol!);
var resolveOrGetParameter_ =
providerP.property(resolveOrGetParameter$.symbol!);
containerP.property(resolveOrGetParameter$.symbol!);

for (var param in svc.constructorArgs) {
var defaultValue = '';
Expand Down Expand Up @@ -61,7 +61,7 @@ cb.Expression buildServiceFactory(
return serviceDescriptorT.call([
serviceT.constInstance([], {
if (svc.lifetime != ServiceLifetime.singleton.toString())
'lifetime': cb.refer(svc.lifetime, rootPackage),
'lifetime': cb.refer(svc.lifetime, contractsPackage),
if (exposeAsReference != null) 'exposeAs': exposeAsReference
}),
constructor,
Expand Down
25 changes: 16 additions & 9 deletions packages/catalyst_builder/lib/src/builder/generator/symbols.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import 'package:code_builder/code_builder.dart' as cb;

/// The catalyst_builder root package.
const rootPackage =
const contractsPackage =
'package:catalyst_builder_contracts/catalyst_builder_contracts.dart';

const builderPackage = 'package:catalyst_builder/catalyst_builder.dart';

/// [Service]
final serviceT = cb.refer('Service', rootPackage);
final serviceT = cb.refer('Service', contractsPackage);

/// [ServiceDescriptor]
final serviceDescriptorT = cb.refer('ServiceDescriptor', rootPackage);
final serviceDescriptorT = cb.refer('ServiceDescriptor', contractsPackage);

/// [ServiceContainer]
final serviceContainerT = cb.refer('ServiceContainer', builderPackage);

/// [ServiceProvider]
final serviceProviderT = cb.refer('ServiceProvider', rootPackage);
/// [AbstractServiceContainer]
final abstractServiceContainerT =
cb.refer('AbstractServiceContainer', contractsPackage);

/// [ServiceProvider.resolveByTag]
/// [ServiceContainer.resolveByTag]
final resolveByTag$ = cb.refer('resolveByTag');

/// tryResolveOrGetParameter method
Expand Down Expand Up @@ -42,11 +48,12 @@ cb.Reference mapOfT(cb.Reference tKey, cb.Reference tValue) =>
..types.addAll([tKey, tValue]))
.build();

/// [ServiceProvider.applyPlugin] method
/// [ServiceContainer.applyPlugin] method
final applyPlugin$ = cb.refer('applyPlugin');

/// [ServiceProviderPlugin]
final serviceProviderPluginT = cb.refer('ServiceProviderPlugin', rootPackage);
/// [ServiceContainerPlugin]
final serviceContainerPluginT =
cb.refer('ServiceContainerPlugin', contractsPackage);

/// provideKnownServices method
final provideKnownServices$ = cb.refer('provideKnownServices');
Expand Down
Loading