/// <summary>
 /// Initializes a new instance of the <see cref="UnitSystemDependencies"/> class.
 /// </summary>
 /// <param name="unitRegistry">The unit registry.</param>
 /// <param name="lexicalAnalyzer">The lexical analyzer.</param>
 /// <param name="expressionParser">The expression parser.</param>
 /// <param name="quantityParser">The quantity parser.</param>
 /// <param name="unitFactory">The unit factory.</param>
 /// <param name="quantityOperations">The quantity operations.</param>
 public UnitSystemDependencies(
     UnitRegistry unitRegistry,
     ILexicalAnalyzer lexicalAnalyzer,
     IExpressionParser expressionParser,
     IQuantityParser quantityParser,
     IUnitFactory unitFactory,
     IQuantityOperations quantityOperations)
 {
     this.UnitRegistry = unitRegistry;
     this.LexicalAnalyzer = lexicalAnalyzer;
     this.ExpressionParser = expressionParser;
     this.QuantityParser = quantityParser;
     this.UnitFactory = unitFactory;
     this.QuantityOperations = quantityOperations;
 }
        /// <summary>
        /// Initializes the unit system.
        /// </summary>
        /// <param name="unitSystemDependencyFactory">The unit system dependency factory.</param>
        /// <param name="registerUnitAction">The register unit action.</param>
        public UnitSystemDependencies InitializeUnitSystem(
            IUnitSystemDependencyFactory unitSystemDependencyFactory,
            Action<IUnitRegistrar> registerUnitAction)
        {
            this.LockedAction(
                () =>
                    {
                        if (!this.isInitialized)
                        {
                            unitSystemDependencyFactory = unitSystemDependencyFactory
                                                          ?? new UnitSystemDependencyFactory(
                                                                 new ExpressionToFlatRepresentationConverter());
                            this.unitRegistry = unitSystemDependencyFactory.CreateUnitRegistry();
                            registerUnitAction?.Invoke(this.unitRegistry);
                            this.expressionParser = unitSystemDependencyFactory.CreateParser(this.unitRegistry);
                            this.lexicalAnalyzer =
                                unitSystemDependencyFactory.CreateLexicalAnalyzer(TokenMatching.CompositeUnit);
                            this.unitFactory = unitSystemDependencyFactory.CreateUnitFactory(this.unitRegistry);
                            this.quantityParser = unitSystemDependencyFactory.CreateParser(
                                this.expressionParser,
                                this.unitFactory);
                            this.quantityOperations =
                                unitSystemDependencyFactory.CreateQuantityOperations(this.unitFactory);
                            this.Dependencies = new UnitSystemDependencies(
                                this.unitRegistry,
                                this.lexicalAnalyzer,
                                this.expressionParser,
                                this.quantityParser,
                                this.unitFactory,
                                this.quantityOperations);
                            this.isInitialized = true;
                        }
                    });

            return this.Dependencies;
        }