Example #1
0
        // Note this method's dependency on the ICarBlueprintLibrary Domain Service as mentioned in BTW Podcast Episode 14
        public void ProduceACar(string employeeName, string carModel, ICarBlueprintLibrary carBlueprintLibrary)
        {
            ThrowExceptionIfFactoryIsNotOpen();

            if (!_aggregateState.ListOfEmployeeNames.Contains(employeeName))
                throw DomainError.Named("unknown-employee", ":> '{0}' not assigned to factory", employeeName);

            if (_aggregateState.EmployeesWhoHaveProducedACarToday.Contains(employeeName))
                throw DomainError.Named("employee-already-produced-car-today", ":> '{0}' not assigned to factory", employeeName);

            var design = carBlueprintLibrary.TryToGetBlueprintForModelOrNull(carModel);

            if (design == null)
                throw DomainError.Named("car-model-not-found", "Model '{0}' not found", carModel);

            var partsUsedToBuildCar = new List<CarPart>();

            foreach (var part in design.RequiredParts)
            {
                if (_aggregateState.GetNumberOfAvailablePartsQuantity(part.Name) < part.Quantity)
                    throw DomainError.Named("required-part-not-found", ":> {0} not found", part.Name);

                // remeber the CarPart that will be used to build the specififed carModel
                partsUsedToBuildCar.Add(new CarPart(part.Name, part.Quantity));
            }

            DoRealWork("produce a car - " +  "'" + employeeName + "'" + " is building a '" + carModel + "'");

            // As mentioned in Episode 12 of the BTW podcast, this code below is wrong.
            // The ICarBlueprintLibrary passed in, is not used.  Hard coded "parts" was ALWAYS used.
            // Tried to fix with the partsUsedToBuildCar approach but needs to be tested.
            // var parts = new[] { new CarPart("chassis", 1), new CarPart("wheels", 4), new CarPart("engine", 1) };

            RecordAndRealizeThat(new CarProduced(_aggregateState.Id, employeeName, carModel, partsUsedToBuildCar.ToArray()));
        }
Example #2
0
        public void ProduceCar(string employeeName, string carModel, ICarBlueprintLibrary library)
        {
            ThrowExceptionIfNotOpenFactory();

            if (!_state.ListOfEmployeeNames.Contains(employeeName))
            {
                throw DomainError.Named("unknown-employee", ":> '{0}' not assigned to factory", employeeName);
            }

            var design = library.TryGetBlueprintForModelOrNull(carModel);

            if (design == null)
            {
                throw DomainError.Named("car-model-not-found", "Model '{0}' not found", carModel);
            }

            foreach (var part in design.RequiredParts)
            {
                if (_state.GetNumberOfAvailablePartsQuantity(part.Name) < part.Quantity)
                {
                    throw DomainError.Named("part-not-found", ":> {0} not found", part.Name);
                }
            }


            DoRealWork("produce car");

            // TODO: As mentioned in Episode 12 of the BTW podcast, this code below is wrong.
            // TODO: The ICarBlueprintLibrary passed in, is not used.  Hard coded "parts" are ALWAYS used.

            var parts = new[] { new CarPart("chassis", 1), new CarPart("wheels", 4), new CarPart("engine", 1) };

            Apply(new CarProduced(_state.Id, employeeName, carModel, parts));
        }
Example #3
0
        public void ProduceCar(string employeeName, string carModel, ICarBlueprintLibrary library)
        {
            ThrowExceptionIfNotOpenFactory();

            if (!_state.ListOfEmployeeNames.Contains(employeeName))
                throw DomainError.Named("unknown-employee", ":> '{0}' not assigned to factory", employeeName);

            var design = library.TryGetBlueprintForModelOrNull(carModel);

            if (design == null)
                throw DomainError.Named("car-model-not-found", "Model '{0}' not found", carModel);

            foreach (var part in design.RequiredParts)
            {
                if (_state.GetNumberOfAvailablePartsQuantity(part.Name) < part.Quantity)
                    throw DomainError.Named("part-not-found", ":> {0} not found", part.Name);
            }

            DoRealWork("produce car");

            // TODO: As mentioned in Episode 12 of the BTW podcast, this code below is wrong.
            // TODO: The ICarBlueprintLibrary passed in, is not used.  Hard coded "parts" are ALWAYS used.

            var parts = new[] { new CarPart("chassis", 1), new CarPart("wheels", 4), new CarPart("engine", 1) };
            Apply(new CarProduced(_state.Id, employeeName, carModel, parts));
        }
        // pass dependencies that are needed for this application service via its constructor
        public FactoryApplicationService(IEventStore eventStore, ICarBlueprintLibrary carBlueprintLibrary)
        {
            if (null == eventStore)
                throw new ArgumentNullException("eventStore");
            if (null == carBlueprintLibrary)
                throw new ArgumentNullException("carBlueprintLibrary");

            _eventStore = eventStore;
            _carBlueprintLibrary = carBlueprintLibrary;
        }
Example #5
0
        // pass dependencies that are needed for this application service via its constructor
        public FactoryApplicationService(IEventStore eventStore, ICarBlueprintLibrary carBlueprintLibrary)
        {
            if (null == eventStore)
            {
                throw new ArgumentNullException("eventStore");
            }
            if (null == carBlueprintLibrary)
            {
                throw new ArgumentNullException("carBlueprintLibrary");
            }

            _eventStore          = eventStore;
            _carBlueprintLibrary = carBlueprintLibrary;
        }
Example #6
0
        public void ProduceACar(string employeeName, string carModel, ICarBlueprintLibrary carBlueprintLibrary)
        {
            ThrowExceptionIfFactoryIsNotOpen();

            if (!_aggregateState.ListOfEmployeeNames.Contains(employeeName))
            {
                throw DomainError.Named("unknown-employee", ":> '{0}' not assigned to factory", employeeName);
            }

            if (_aggregateState.EmployeesWhoHaveProducedACarToday.Contains(employeeName))
            {
                throw DomainError.Named("employee-already-produced-car-today", ":> '{0}' not assigned to factory", employeeName);
            }


            var design = carBlueprintLibrary.TryToGetBlueprintForModelOrNull(carModel);

            if (design == null)
            {
                throw DomainError.Named("car-model-not-found", "Model '{0}' not found", carModel);
            }


            var partsUsedToBuildCar = new List <CarPart>();

            foreach (var part in design.RequiredParts)
            {
                if (_aggregateState.GetNumberOfAvailablePartsQuantity(part.Name) < part.Quantity)
                {
                    throw DomainError.Named("required-part-not-found", ":> {0} not found", part.Name);
                }

                // remeber the CarPart that will be used to build the specififed carModel
                partsUsedToBuildCar.Add(new CarPart(part.Name, part.Quantity));
            }

            DoRealWork("produce a car - " + "'" + employeeName + "'" + " is building a '" + carModel + "'");

            // As mentioned in Episode 12 of the BTW podcast, this code below is wrong.
            // The ICarBlueprintLibrary passed in, is not used.  Hard coded "parts" was ALWAYS used.
            // Tried to fix with the partsUsedToBuildCar approach but needs to be tested.
            // var parts = new[] { new CarPart("chassis", 1), new CarPart("wheels", 4), new CarPart("engine", 1) };

            RecordAndRealizeThat(new CarProduced(_aggregateState.Id, employeeName, carModel, partsUsedToBuildCar.ToArray()));
        }
 // pass dependencies that are needed for this application service via its constructor
 public FactoryApplicationService(IEventStore eventStore, ICarBlueprintLibrary carBlueprintLibrary)
 {
     _eventStore = eventStore;
     _carBlueprintLibrary = carBlueprintLibrary;
 }
 // pass dependencies for this application service via constructor
 public FactoryApplicationService(IEventStore eventStore, ICarBlueprintLibrary library)
 {
     _eventStore = eventStore;
     _library    = library;
 }