Comments (3)
Yeah, this behavior should be supported. I thought I'd verified it was working. Can you provide some sample code that isn't working?
from cleanarchitecture.
Yeah, this behavior should be supported. I thought I'd verified it was working. Can you provide some sample code that isn't working?
@ardalis Yes,
In Core
public class Category : EntityBase<uint>, IAggregateRoot
{
public uint ParentId { get; private set; }
public string Name { get; private set; } = default!;
protected Category() { }
public Category(uint parentId, string name)
{
ParentId = parentId;
Name = Guard.Against.NullOrWhiteSpace(name, nameof(name));
RegisterDomainEvent(new CategoryCreatedEvent(parentId, name));
}
}
In UseCases
public record CreateCategoryCommand(uint ParentId, string Name) : ICommand<Result<uint>>;
public class CreateCategoryHandler(IRepository<Category> repository) : ICommandHandler<CreateCategoryCommand, Result<uint>>
{
public async Task<Result<uint>> Handle(CreateCategoryCommand request, CancellationToken cancellationToken)
{
var result = await repository.AddAsync(new Category(request.ParentId, request.Name), cancellationToken);
return result.Id;
}
}
In Infrastructure
public class AppDbContext(DbContextOptions<AppDbContext> options, IDomainEventDispatcher? dispatcher) : DbContext(options)
{
public override async Task<int> SaveChangesAsync(CancellationToken cancellationToken = new CancellationToken())
{
if (dispatcher == null) return await base.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
// bug here
// ChangeTracker.Entries<EntityBase>() cannot return instances of 'EntityBase<TId>'
// because there is no inheritance relationship between EntityBase<TId> and EntityBase
var entitiesWithEvents = ChangeTracker.Entries<EntityBase>()
.Select(e => e.Entity)
.Where(e => e.DomainEvents.Any())
.ToArray();
// Task DispatchAndClearEvents(IEnumerable<EntityBase> entitiesWithEvents);
// DispatchAndClearEvents method only accepts IEnumerable<EntityBase>
await dispatcher.DispatchAndClearEvents(entitiesWithEvents);
return await base.SaveChangesAsync(cancellationToken).ConfigureAwait(false);;
}
public override int SaveChanges()
{
return SaveChangesAsync().GetAwaiter().GetResult();
}
}
Maybe make DispatchAndClearEvents accept IEnumerable<HasDomainEventsBase>
from cleanarchitecture.
@ardalis just wanted to check in if you're planning to knock this off. This one is bugging me as well. Thanks...
from cleanarchitecture.
Related Issues (20)
- Api.Contracts project HOT 2
- Two sets of templates - Back end focused (Current [End Points]) and Front end focused (Blazor Web App) HOT 2
- Template Generated Solution Will not Build or Update HOT 2
- Template Doesn't Work and Breaks Other Projects HOT 1
- Open the Discussions area in Github area so people can discuss the template and the whys
- Why is this repo using AutoFac instead of .NET's own DI infrastructure? HOT 3
- Handling Third-Party Authentication and Role Synchronization in DDD and Clean Architecture HOT 1
- GetContributorByIdRequest - Filename should probably match the classname
- Why is the implementation of the DeleteContributorService in the core layer? HOT 2
- Test case ReturnsTwoContributors() fails HOT 6
- Replace Autofac with Vanilla dotnet DI HOT 3
- Renaming Enhacement in Web Project. HOT 3
- Update Sample to Latest Version of Template HOT 4
- 404 when launching the project HOT 2
- Error when launching the newly created project from template HOT 2
- Add More Warning as Error Checks
- Mixed SharedKernel : Clean.Architecture and Ardalis HOT 1
- ProjectItemMarkComplete test fails
- Support Microsoft.Identity in tenplate
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cleanarchitecture.