Static helper methods for Revenj.NET server libraries
Kobus-Smit opened this issue · comments
Kobus Smit commented
The client libraries have the option to generate static helper methods. Would it be possible to do the same for the server libraries?
public partial class MyAggregate: global::System.IEquatable<MyAggregate>, global::System.ICloneable, global::Revenj.DomainPatterns.IEntity, global::Revenj.DomainPatterns.ICacheable, global::Revenj.DomainPatterns.IAggregateRoot, global::Revenj.DomainPatterns.IChangeTracking<MyAggregate>
{
public MyAggregate Create(IDataContext context)
{
context.Create(this);
return this;
}
}
Usage will result in less code and would feel consistent with client libraries:
var ma = new MyAggregate { Abc = 1, Xyz= "Hello" }.Create(context);
//versus
var ma = new MyAggregate { Abc = 1, Xyz= "Hello" };
context.Create(ma);
zapov commented
Server code patterns are optimized for concurrency and bulk operations, while client libraries don't have concepts of transactions and such patterns.
But you should be able to do such APIs by writing extension methods, eg:
public static class Helpers
{
public static T Create<T>(this T aggregate, IDataContext context) where T: IAggregateRoot
{
context.Create(aggregate);
return aggregate;
}
}
Kobus Smit commented
Of course! 😊