EventStoreRepository GetById with Type at Runtime #19

Open
wants to merge 1 commit into
from

Conversation

Projects
None yet
1 participant

cbaxter commented Jan 4, 2012

In order to better facilitate loading an IAggregate with a type at Runtime (without using reflection) I added two new methods to the EventStoreRepository as shown below.

public virtual IAggregate GetById(Type aggregateType, Guid id)
public virtual IAggregate GetById(Type aggregateType, Guid id, int versionToLoad)

In order to keep the IRepository interface clean, I chose to push the prior implementations of GetById below in to the RepositoryExtensions class. The downside to the latter change is that it is a breaking change for those who may have overriden the EventStoreRepository class to extend either of the origional GetById methods. Of course the latter change is not required, but I felt that it was the clean choice given that the generic type paramter was only used for typeof(TAggregate) inside the private GetAggregate method.

The parameter Type aggregateType is validated inside of private GetAggregate method to ensure the IAggregate interface has been implemented by the type and will throw an ArgumentException if missing.

Modified IRepository to accept Runtime type for GetById.
* Converted IRepository interface to use Type parameter.
* Added IRepository extensions for GetById<TAggregate>.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment