private CreateIndex(IndexKeysDefinition <TDto> definition, CreateIndexOptions options) { Precondition.For(definition, nameof(definition)).NotNull(); Definition = definition; Options = options; }
protected override async Task <CommandBusResult> EnqueueInternalAsync(ICommand cmd) { Precondition.For(cmd, nameof(cmd)).IsValidCommand(); CommandBusResult result = await HandleCommand(cmd); return(result); }
public async Task InvokeAndSaveAsync(Type domainObjectType, ICommand cmd, IEnumerable <CommandMethodMapping> commandMapping) { Precondition.For(domainObjectType, nameof(domainObjectType)).NotNull("Type has to be set!"); Precondition.For(cmd, nameof(cmd)).IsValidCommand(); Precondition.For(commandMapping, nameof(commandMapping)).NotNull(); var type = cmd.GetType(); logger.LogTrace("Invoking Command \"{type}\" for \"{domainObjectType}\"", domainObjectType); var currentTry = 0; while (currentTry < retryCount) { if (currentTry > 0) { logger.LogTrace("Retrying Command \"{type}\" for \"{domainObjectType}\"..."); } AppendResult result = await InvokeAndSaveInternalAsync(domainObjectType, cmd, commandMapping); if (result.HadWrongVersion) { currentTry++; } else { break; } } }
public async Task <AppendResult> SaveAsync <T>(T domainObject, bool preventVersionCheck) where T : class, IDomainObject { Precondition.For(domainObject, nameof(domainObject)) .NotNull("The domainObject to be saved must not be null!"); string type = typeof(T).FullName; if (!domainObject.HasUncommittedEvents) { string id = domainObject.Id; logger.LogDebug("\"{type}\"-{id} had no events to save", type, id); return(AppendResult.NoUpdate); } int count = domainObject.GetUncommittedEvents().Count; logger.LogTrace("Saving \"{type}\" with {count} events...", type, count); Stopwatch watch = Stopwatch.StartNew(); bool check = domainObject.CheckVersionOnSave && !preventVersionCheck; AppendResult result = await SaveUncomittedEventsAsync(domainObject, check); watch.Stop(); if (string.IsNullOrWhiteSpace(result.CommitId) || result.HadWrongVersion) { string reason = result.Message; logger.LogWarning("{count} events not saved for \"{type}\" reason; {reason}", count, type, reason); } else { var ms = watch.ElapsedMilliseconds; logger.LogTrace("Saved {count} events for \"{type}\" in {ms}ms", count, type, ms); //especially for direct denormalizer its important to continue on the state that wasreally persisted. //e.g. in case of persistance errors. otherweise we don't have a real projection of persisted events /auditlog List <IEvent> persistedEvents = await ByAppendResult(result); if (!result.HadWrongVersion) { foreach (IEvent @event in persistedEvents) { configuration.PostSavePipeline?.Invoke(@event); if (denormalizerPipeline != null) { await denormalizerPipeline.HandleAsync(@event); } } } domainObject.CommitChanges(result.CurrentVersion); } return(result); }
protected EventSourcedControllerBase(ICommandBus bus, IDomainObjectRepository domainObjectRepository) { Precondition.For(() => bus).NotNull(); CommandBus = bus; DomainObjectRepository = domainObjectRepository; }
protected UserCommandBase(string domainObjectId, string userId) : base(domainObjectId) { Precondition.For(domainObjectId, nameof(domainObjectId)).NotNullOrWhiteSpace(); Precondition.For(userId, nameof(userId)).NotNullOrWhiteSpace(); UserId = userId; }
public void WithCondition(Predicate <ICommand> condition) { Precondition.For(condition, nameof(condition)) .NotNull("When a condition has to be set it should not be null"); this.condition = condition; }
public InMemoryCommandBus(ICommandPipeline handler) { Precondition.For(() => handler).NotNull(); this.handler = handler; subject.Subscribe(async msg => await HandleCommand(msg)); }
public EventMapper(IEventSerializer serializer, IEventHash hash) { Precondition.For(hash, nameof(hash)).NotNull(); Precondition.For(serializer, nameof(serializer)).NotNull(); this.serializer = serializer; this.eventHash = hash; }
public MongoXmlRepository(IMongoDatabase db, string collectionName) { Precondition.For(() => db).NotNull(); Precondition.For(() => collectionName).NotNullOrWhiteSpace(); Collection = db.GetCollection <MongoStoredKey>(collectionName); }
public MongoEventSubscriber(IMongoDatabase db, ILoggerFactory loggerFactory) { Precondition.For(db, nameof(db)).NotNull(); Precondition.For(loggerFactory, nameof(loggerFactory)).NotNull(); logger = loggerFactory.CreateLogger <MongoEventSubscriber>(); repo = new MongoCommitRepository(db); }
public static DenormalizerConfiguration SetMongoDbEventSubscriber(this DenormalizerConfiguration config, IMongoDatabase db) { Precondition.For(() => config).NotNull(); Precondition.For(() => db).NotNull(); config.Subscriber = new MongoEventSubscriber(db); return(config); }
public static DenormalizerConfiguration SetMongoEventPositionGateway(this DenormalizerConfiguration config, IMongoDatabase db) { Precondition.For(() => config).NotNull(); Precondition.For(() => db).NotNull(); config.StreamPositionGateway = new MongoStreamPositionGateway(db, null); return(config); }
public ConventionCommandInvoker(IDomainObjectRepository repository, ILoggerFactory loggerFactory) { Precondition.For(() => repository).NotNull("Repository has to be set!"); Precondition.For(() => loggerFactory).NotNull("loggerFactory has to be set!"); logger = loggerFactory.CreateLogger <ConventionCommandInvoker>(); this.repository = repository; }
public void ItSucceedsWhenRequirementsAreFullfilled() { var model = new Model { Foo = "aaa" }; Precondition.For(model, nameof(model)).IsValidModel(); }
public void ApplyEvents(ICollection <IEvent> eventsToCommit) { Precondition.For(eventsToCommit, nameof(eventsToCommit)).NotNull().True(i => i.Count > 0); ApplyCommitId(eventsToCommit); committedEvents.AddRange(eventsToCommit); }
public static DenormalizerConfiguration SetServiceProviderDenormalizerActivator(this DenormalizerConfiguration config) { Precondition.For(() => config).NotNull(); config.Activator = new ServiceCollectionActivator(); return(config); }
public EventsourceDIContext(IDomainObjectActivator domainObjectActivator, IStateActivator stateActivator) { Precondition.For(domainObjectActivator, nameof(domainObjectActivator)).NotNull(); Precondition.For(stateActivator, nameof(stateActivator)).NotNull(); DomainObjectActivator = domainObjectActivator; StateActivator = stateActivator; }
public string Resolve(Type domainObject, string id, string @namespace = null) { Precondition.For(id, nameof(id)).NotNullOrWhiteSpace(); string result = BuildKey(domainObject, id, @namespace); return(result); }
protected MongoRepositoryBase(IMongoDatabase database, string collectionName) { Precondition.For(database, nameof(database)).NotNull(); Precondition.For(collectionName, nameof(collectionName)).NotNullOrWhiteSpace().MinLength(3); Database = database; Collection = database.GetCollection <TDto>(collectionName); }
protected DomainObjectRepositoryBase(EventSourceConfiguration configuration) { Precondition.For(configuration, nameof(configuration)) .NotNull("Configuration for domainobject repository must not be null!"); this.configuration = configuration; logger = configuration.LoggerFactory.CreateLogger(GetType()); }
public InMemoryCommandBus(ICommandPipeline handler, ILoggerFactory loggerFactory) : base(loggerFactory) { Precondition.For(() => handler).NotNull(); logger = loggerFactory.CreateLogger <InMemoryCommandBus>(); this.handler = handler; subject.Subscribe(async msg => await HandleCommand(msg)); }
public static EventSourceConfiguration SetDefaultActivator(this EventSourceConfiguration config) { Precondition.For(() => config).NotNull(); var activator = new ActivatorDomainObjectActivator(); config.Activator = activator; config.StateActivator = activator; return(config); }
public static EventSourceConfiguration SetDomainObjectAssemblies(this EventSourceConfiguration config, params Assembly[] assembliesWithDomainObjects) { Precondition.For(() => config).NotNull(); Precondition.For(() => assembliesWithDomainObjects).NotNull().True(x => x.Any()); config.DomainObjectAssemblies = assembliesWithDomainObjects; return(config); }
public string Resolve <T>(T domainObject) where T : class, IDomainObject { Precondition.For(domainObject, nameof(domainObject)).NotNull(); Precondition.For(domainObject.Id, nameof(domainObject.Id)).NotNullOrWhiteSpace(); string result = BuildKey(domainObject.GetType(), domainObject.Id, domainObject.Namespace); return(result); }
public static DenormalizerConfiguration SetDenormalizerAssemblies(this DenormalizerConfiguration config, params Assembly[] assemblies) { Precondition.For(() => config).NotNull(); Precondition.For(() => assemblies).NotNull().True(x => x.Any()); config.DenormalizerAssemblies = assemblies; return(config); }
public static IServiceCollection AddMongoEventPositionGateway(this IServiceCollection services, IMongoDatabase db) { Precondition.For(() => db).NotNull(); services.AddSingleton <IStreamPositionGateway, MongoStreamPositionGateway>(); return(services); }
protected Task <string> CreateIndexAsync(CreateIndex <TDto> index) { Precondition.For(index, nameof(index)).NotNull(); Task <string> task = index.Options == null ? Collection.Indexes.CreateOneAsync(index.Definition) : Collection.Indexes.CreateOneAsync(index.Definition, index.Options); return(task); }
public IDomainObject Resolve(Type domainObjectType, string id) { Precondition.For(domainObjectType, nameof(domainObjectType)) .NotNull() .True(i => DomainObjectInfo.IsAssignableFrom(i.GetTypeInfo())); Precondition.For(id, nameof(id)).NotNullOrWhiteSpace(); return((IDomainObject)Activator.CreateInstance(domainObjectType, id)); }
public IMongoCollection <EventCommit> GetCollectionByAggregateType(string streamName) { Precondition.For(streamName, nameof(streamName)).NotNullOrWhiteSpace(); string name = GetCollectionNameByCommit(streamName); IMongoCollection <EventCommit> collection = cache.GetOrAdd(name, x => ResolveNew(name).Result); return(collection); }