/// <summary>
        /// Defines a new use case in which the given <see cref="AggregateConfiguration"/> will be turned into an SQL query and used to generate rows
        /// that will be released into the pipeline.  The source is fixed the destination and middle components are open.
        /// </summary>
        /// <param name="aggregateConfiguration">The aggregate query that will be run to generate the rows</param>
        /// <param name="constrainByCohort">Only applies if <see cref="AggregateConfiguration"/> is a patient index table, specifying a cohort will only commit rows
        /// in which the patient id appears in the cohort</param>
        /// <param name="table">The destination table in which to put the matched records.
        /// <para> (table does not have to exist yet, you can use <see cref="DiscoveredDatabase.ExpectTable"/> to obtain a reference to a non existant table)</para></param>
        public CreateTableFromAggregateUseCase(AggregateConfiguration aggregateConfiguration, ExtractableCohort constrainByCohort, DiscoveredTable table)
        {
            if (constrainByCohort == null)
            {
                var src = new AggregateConfigurationTableSource();
                src.PreInitialize(aggregateConfiguration, new ThrowImmediatelyDataLoadEventListener());
                src.TableName  = table.GetRuntimeName();
                ExplicitSource = src;
            }
            else
            {
                AddInitializationObject(constrainByCohort);

                var src = new PatientIndexTableSource();
                src.PreInitialize(aggregateConfiguration, new ThrowImmediatelyDataLoadEventListener());
                src.PreInitialize(constrainByCohort, new ThrowImmediatelyDataLoadEventListener());
                src.TableName  = table.GetRuntimeName();
                ExplicitSource = src;
            }

            AddInitializationObject(aggregateConfiguration);
            AddInitializationObject(aggregateConfiguration.Repository);
            AddInitializationObject(table.Database);

            GenerateContext();
        }
 /// <summary>
 /// Design time types
 /// </summary>
 private CreateTableFromAggregateUseCase()
     : base(new[] { typeof(AggregateConfiguration),
                    typeof(ExtractableCohort),
                    typeof(DiscoveredDatabase),
                    typeof(ICatalogueRepository) })
 {
     ExplicitSource = new AggregateConfigurationTableSource();
     GenerateContext();
 }