public SingleUseAggregateCachedRepository( IRepositoryExFactory repositoryFactory, IIdentity id) { _repositoryFactory = repositoryFactory; _wrappedRepository = _repositoryFactory.Create(); _aggregate = _wrappedRepository.GetById <TAggregate>(id); }
/// <summary> /// /// </summary> /// <param name="repositoryFactory"></param> /// <param name="cacheDisabled">If True cache is not used, and each time an instance of /// <see cref="IAggregateCachedRepository{TAggregate}"/> is requested, a non caceable /// entities is returned. /// <br /> /// If this value is true this class also do not try to have a lock on aggregate id thus /// it does not prevent two thread to execute at the same moment on the same aggregateId. /// </param> public AggregateCachedRepositoryFactory( IRepositoryExFactory repositoryFactory, Boolean cacheDisabled = false) { _repositoryFactory = repositoryFactory; _cacheDisabled = cacheDisabled; _cachePolicy = new CacheItemPolicy() { SlidingExpiration = TimeSpan.FromMinutes(10), RemovedCallback = RemovedCallback }; }
public void repository_command_handler_should_set_context() { var cmd = new TouchSampleAggregate(new SampleAggregateId(1)); cmd.SetContextData("key", "value"); IRepositoryExFactory factory = NSubstitute.Substitute.For <IRepositoryExFactory>(); factory.Create().Returns(_sut); var handler = new TouchSampleAggregateHandler { Repository = _sut, AggregateFactory = _aggregateFactory, AggregateCachedRepositoryFactory = new AggregateCachedRepositoryFactory(factory) }; handler.Handle(cmd); var context = handler.Aggregate.ExposeContext; Assert.NotNull(context); Assert.AreEqual("TouchSampleAggregate", context["command.name"]); Assert.AreEqual("value", context["key"]); }