public async Task CreateAggregationAsync(IndexDefinition indexDefinition)
		{
			var dynamicViewCompiler = new DynamicViewCompiler(indexDefinition.Name, indexDefinition, Path.Combine(_path, "Generators"));
			var generator = dynamicViewCompiler.GenerateInstance();

			var writeBatch = new WriteBatch();
			var memoryStream = SmallObjectToMemoryStream(indexDefinition);
			writeBatch.Put("aggregators/" + indexDefinition.Name, memoryStream);
			await _storage.Writer.WriteAsync(writeBatch);

			var aggregator = new Aggregator(this, indexDefinition.Name, generator);
			_aggregations.AddOrUpdate(indexDefinition.Name, aggregator, (s, viewGenerator) => aggregator);
			Background.Work(aggregator.StartAggregation);
		}
		private void ReadAllAggregations(DbIterator it)
		{
			Slice prefix = "aggregators/";
			it.Seek(prefix);
			while(it.WithPrefix(prefix))
			{
				string name = Encoding.UTF8.GetString(it.Key.Array, it.Key.Offset, it.Key.Count);
				using (var stream = it.CreateValueStream())
				{
					var indexDefinition =
						new JsonSerializer().Deserialize<IndexDefinition>(new JsonTextReader(new StreamReader(stream)));
					_log.Info("Reading aggregator {0}", indexDefinition.Name);
					AbstractViewGenerator generator = null;
					try
					{
						var dynamicViewCompiler = new DynamicViewCompiler(indexDefinition.Name, indexDefinition,
																		  Path.Combine(_path, "Generators"));
						generator = dynamicViewCompiler.GenerateInstance();
					}
					catch (Exception e)
					{
						_log.WarnException("Could not create instance of aggregator " + indexDefinition.Name, e);
						// could not create generator, ignoring this and deleting the generator
						RemoveAggregation(name);
					}

					if (generator != null)
					{
						var aggregator = new Aggregator(this, indexDefinition.Name, generator);
						_aggregations.TryAdd(indexDefinition.Name, aggregator);
						Background.Work(aggregator.StartAggregation);
					}
				}
				it.Next();
			}
		}