Refactored the factory types into helpers to add services to IServiceCollection
Removed the old factory types :
CqlFactoryBase (in Hl7.Cql.Abstractions)
CqlAbstractionsFactory (in Hl7.Cql.Abstractions)
CqlCompilerFactory (in Hl7.Cql.Compiler)
CqlPackagerFactory (in Hl7.Cql.Packaging)
ProgramCqlPackagerFactory (in Hl7.Cql.Packager)
New types to simplify service construction
The following projects (see diagram below) contains services that can be added to a service collection, typically as part of a hosting environment. These projects all have a new sub-namespace called Hosting.
Diagram of project hierarchy containing CQL services
The Cql.Runtime project doesn't have any services of its own that is used for the elm to c# pipeline, so its Hosting namespace only contains utility extensions needed by the other projects, such as ServiceCollectionExtensions and ServiceProviderExtensions.
For the other projects, their Hosting namespace have two types each, one to construct services into a IServiceCollection, and another to access services from IServiceProvider (which is primarily only used for unit testing). A consistent naming convention is used for types between all these projects: Cql*ServicesInitializer and Cql*Services.
Cql*ServicesInitialzer contains methods such as AddCql*Services and GetCql*Services.
Runtime Usage
To add services to IServiceCollection at runtime, just call any of the following
services.AddCqlPackagerServices() - adds services for packager, code generation and compiler
services.AddCqlCodeGenerationServices() - adds services for code generation and compiler
services.AddCqlCompilerServices() - adds services for compiler
services.AddCqlToElmServices() - adds services for cql to elm
Test Usage
The CqlServicesInitializer is a helper to create services for the compiler or packager services.
// Create a context to which services will be registered to for disposal
using DisposeContext disposeContext = new DisposeContext();
// Get all the services for CQL code generation
CqlCodeGenerationServices cqlCodeGenerationServices = CqlServicesInitializer.CreateCqlCodeGenerationServices(disposeContext.Token);
// Get the CSharpLibrarySetToStreamsWriter
CSharpLibrarySetToStreamsWriter writer = cqlCodeGenerationServices.CSharpLibrarySetToStreamsWriter;
// Direct access to services from dependency libraries possible with GetCqlCompilerServices()
LibraryExpressionBuilder libraryExpressionBuilder = cqlCodeGenerationServices.GetCqlCompilerServices().LibraryExpressionBuilder;
Cql-to-Elm
The same dependency injection pattern is used for cql to elm.
Work for #406
Refactored the factory types into helpers to add services to
IServiceCollection
Removed the old factory types :
CqlFactoryBase
(in Hl7.Cql.Abstractions)CqlAbstractionsFactory
(in Hl7.Cql.Abstractions)CqlCompilerFactory
(in Hl7.Cql.Compiler)CqlPackagerFactory
(in Hl7.Cql.Packaging)ProgramCqlPackagerFactory
(in Hl7.Cql.Packager)New types to simplify service construction
The following projects (see diagram below) contains services that can be added to a service collection, typically as part of a hosting environment. These projects all have a new sub-namespace called
Hosting
.Diagram of project hierarchy containing CQL services
The
Cql.Runtime
project doesn't have any services of its own that is used for the elm to c# pipeline, so itsHosting
namespace only contains utility extensions needed by the other projects, such asServiceCollectionExtensions
andServiceProviderExtensions
.For the other projects, their
Hosting
namespace have two types each, one to construct services into aIServiceCollection
, and another to access services fromIServiceProvider
(which is primarily only used for unit testing). A consistent naming convention is used for types between all these projects:Cql*ServicesInitializer
andCql*Services
.Cql*ServicesInitialzer
contains methods such asAddCql*Services
andGetCql*Services
.Runtime Usage
To add services to
IServiceCollection
at runtime, just call any of the followingservices.AddCqlPackagerServices()
- adds services for packager, code generation and compilerservices.AddCqlCodeGenerationServices()
- adds services for code generation and compilerservices.AddCqlCompilerServices()
- adds services for compilerservices.AddCqlToElmServices()
- adds services for cql to elmTest Usage
The
CqlServicesInitializer
is a helper to create services for the compiler or packager services.Cql-to-Elm
The same dependency injection pattern is used for cql to elm.