Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Untyped Save<T> when calling from Session #111

Open
meichhorn-conet opened this issue Jun 17, 2022 · 2 comments
Open

Untyped Save<T> when calling from Session #111

meichhorn-conet opened this issue Jun 17, 2022 · 2 comments

Comments

@meichhorn-conet
Copy link

meichhorn-conet commented Jun 17, 2022

The following line calls IRepository.Save untyped (T is always AggregateRoot)

await _repository.Save(descriptor.Aggregate, descriptor.Version, cancellationToken).ConfigureAwait(false);

I would suggest to use dynamic

dynamic aggregate = descriptor.Aggregate;
await _repository.Save(aggregate, descriptor.Version, cancellationToken).ConfigureAwait(false);

This calls Save with the concrete Type of the aggregate.

@gautema
Copy link
Owner

gautema commented Aug 8, 2022

Hi. Sorry for the late reply.

Can you please tell me what this would solve? Is there a bug happening the way it is now? Parsing to dynamic is very slow, so I'd like to have a good use case for it.

@meichhorn-conet
Copy link
Author

I think it's a bug. When you implement your own IRepository.Save<T>, typeof(T) is always AggregateRoot and not your specific AggregateRoot-Type.

Pseudo code:

var aggregate = new MyAggregate();
session.Add(aggregate);
await session.Commit();

public class MyRepository : IRepository
{
  public Task Save<T>(T aggregate, int? expectedVersion = null, CancellationToken cancellationToken = default) where T : AggregateRoot 
  {
    Console.WriteLine(typeof(T).Name); // -> AggregateRoot
    Console.WriteLine(aggregate.GetType().Name); // -> MyAggregate
    // ...
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants