This file contains hidden or 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
CompanyFixture.factory().makeJsonArray(10) | |
CompanyFixture.factory().empty("EmptyCompany").makeJsonObject(); | |
CompanyFixture.factory().empty("EmptyCompany").makeJsonArray(10); |
This file contains hidden or 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
CompanyFixture.factory(0.makeMany(10); |
This file contains hidden or 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
import 'company_model.dart'; | |
extension CompanyFixture on Company { | |
static _CompanyFixtureFactory factory() => | |
_CompanyFixtureFactory(); | |
} | |
class _CompanyFixtureFactory extends | |
JsonFixtureFactory<Company> { | |
@override |
This file contains hidden or 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
import 'company_model.dart'; | |
extension CompanyFixture on Company{ | |
static _CompanyFixtureFactory factory() => _CompanyFixtureFactory(); | |
} | |
class _CompanyFixtureFactory extends FixtureFactory<Company>{ | |
@override | |
FixtureDefinition<Company> defintion() => define( | |
(faker) => Company( |
This file contains hidden or 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
import 'package:equatable/equatable.dart'; | |
import 'package:uuid/uuid.dart'; | |
import 'domain_model.dart'; | |
class Company with DomainModel, Equatable{ | |
final String name; | |
final Ktlist<Person> employees; | |
Company({this.id - Uuuid().v4(), this.name, | |
this.employees}); |
This file contains hidden or 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
mixin DomainModel { | |
late String id; | |
} |
This file contains hidden or 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
main() async { | |
final cqrs = Cqrs() | |
..registerAggregate(AccountAggregate()) | |
..registerRepository(InMemoryRepository<Account>(forAggregate: "account")); | |
cqrs.events.listen(print); | |
await cqrs.submitCommand(CreateAccountCmd(owner: "Teja", modelId: "1")); | |
await cqrs.submitCommand(DepositCmd(modelId: "1", amount: 200.0)); | |
await cqrs.submitCommand(DepositCmd(modelId: "1", amount: 200.0)); |
This file contains hidden or 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
class AccountAggregate extends Aggregate<Account> { | |
final String name = 'account'; | |
@override | |
Account initializeModel() => Account(); | |
@override | |
Future<void> apply(Account model, DomainEvent event) async { | |
if (event is AccountCreatedEvent) { | |
model.id = event.id; |
This file contains hidden or 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
class AccountCreatedEvent implements Event { | |
String get forAggregate => "account"; | |
final String id; | |
final String owner; | |
AccountCreatedEvent({@required this.id, @required this.owner}); | |
String toString() => "Created account ($id) for $owner."; |
This file contains hidden or 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
abstract class ForAccount { | |
final String forAggregate = "account"; | |
} | |
class CreateAccountCmd extends Command with ForAccount { | |
final String modelId; | |
final String owner; | |
CreateAccountCmd({@required this.owner, @required this.modelId}); |