我希望通过它实现的接口访问我的聚合根:
repository.GetById[[IMyInterface]](id); 要做到这一点,我需要告诉CommonDomain或EventStore什么?我相信我的IConstructAggregates接收存储事件的聚合的实现类型。我需要保留我自己的身份证地图吗。
例如,假设我有这些agg的根:
class AggRoot1 : IInterface1, IInterface2 {}
class AggRoot2 : IInterface1, IInterface2 {}我已经保存了一个具有“idFromAggRoot1 1”的aggregate1实例。现在我想这样做:
repository.GetById<IInterface1>(idFromAggRoot1);既然有两个IInterface1实现者,我怎么知道以后应该创建什么?AggRoot1?AggRoot2?IInterface1?激活器会在这里爆炸,所以我知道我需要实现IConstructAggregates,但不知道是否还有其他描述符来告诉我原始提交agg根类型是什么。
发布于 2011-09-22 11:22:55
可以实现IConstructAggregates.Build()方法以返回所需的任何类型。
在Common.AggregateFactory中,默认实现通过Activator.CreateInstance(type) as IAggregate创建聚合实例。
自己的实现可能如下所示:
public class MyAggregateFactory : IConstructAggregates
{
public IAggregate Build(Type type, Guid id, IMemento snapshot)
{
if (type == typeof(IMyInterface))
return new MyAggregate();
else
return Activator.CreateInstance(type) as IAggregate;
}
}编辑:聚合类型以EventMessage.Header[EventStoreRepository.AggregateTypeHeader]的形式存储在事件消息的标题中
https://stackoverflow.com/questions/7500068
复制相似问题